| 1 |
// This file is part of the FidelityFX SDK. |
| 2 |
// |
| 3 |
// Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. |
| 4 |
// |
| 5 |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 |
// of this software and associated documentation files (the "Software"), to deal |
| 7 |
// in the Software without restriction, including without limitation the rights |
| 8 |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
// copies of the Software, and to permit persons to whom the Software is |
| 10 |
// furnished to do so, subject to the following conditions: |
| 11 |
// The above copyright notice and this permission notice shall be included in |
| 12 |
// all copies or substantial portions of the Software. |
| 13 |
// |
| 14 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 |
// THE SOFTWARE. |
| 21 |
|
| 22 |
//#version 450 |
| 23 |
|
| 24 |
#extension GL_GOOGLE_include_directive : require |
| 25 |
#extension GL_EXT_samplerless_texture_functions : require |
| 26 |
|
| 27 |
#define FSR2_BIND_SRV_INPUT_OPAQUE_ONLY 0 |
| 28 |
#define FSR2_BIND_SRV_INPUT_COLOR 1 |
| 29 |
#define FSR2_BIND_UAV_AUTOREACTIVE 2 |
| 30 |
#define FSR2_BIND_CB_REACTIVE 3 |
| 31 |
#define FSR2_BIND_CB_FSR2 4 |
| 32 |
|
| 33 |
#include "ffx_fsr2_callbacks_glsl.h" |
| 34 |
#include "ffx_fsr2_common.h" |
| 35 |
|
| 36 |
// layout (set = 1, binding = FSR2_BIND_SRV_PRE_ALPHA_COLOR) uniform texture2D r_input_color_pre_alpha; |
| 37 |
// layout (set = 1, binding = FSR2_BIND_SRV_POST_ALPHA_COLOR) uniform texture2D r_input_color_post_alpha; |
| 38 |
// layout (set = 1, binding = FSR2_BIND_UAV_REACTIVE, r8) uniform image2D rw_output_reactive_mask; |
| 39 |
|
| 40 |
|
| 41 |
#ifndef FFX_FSR2_THREAD_GROUP_WIDTH |
| 42 |
#define FFX_FSR2_THREAD_GROUP_WIDTH 8 |
| 43 |
#endif // #ifndef FFX_FSR2_THREAD_GROUP_WIDTH |
| 44 |
#ifndef FFX_FSR2_THREAD_GROUP_HEIGHT |
| 45 |
#define FFX_FSR2_THREAD_GROUP_HEIGHT 8 |
| 46 |
#endif // FFX_FSR2_THREAD_GROUP_HEIGHT |
| 47 |
#ifndef FFX_FSR2_THREAD_GROUP_DEPTH |
| 48 |
#define FFX_FSR2_THREAD_GROUP_DEPTH 1 |
| 49 |
#endif // #ifndef FFX_FSR2_THREAD_GROUP_DEPTH |
| 50 |
#ifndef FFX_FSR2_NUM_THREADS |
| 51 |
#define FFX_FSR2_NUM_THREADS layout (local_size_x = FFX_FSR2_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR2_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR2_THREAD_GROUP_DEPTH) in; |
| 52 |
#endif // #ifndef FFX_FSR2_NUM_THREADS |
| 53 |
|
| 54 |
#if defined(FSR2_BIND_CB_REACTIVE) |
| 55 |
layout (set = 1, binding = FSR2_BIND_CB_REACTIVE, std140) uniform cbGenerateReactive_t |
| 56 |
{ |
| 57 |
float scale; |
| 58 |
float threshold; |
| 59 |
float binaryValue; |
| 60 |
uint flags; |
| 61 |
} cbGenerateReactive; |
| 62 |
#endif |
| 63 |
|
| 64 |
FFX_FSR2_NUM_THREADS |
| 65 |
void main() |
| 66 |
{ |
| 67 |
FfxUInt32x2 uDispatchThreadId = gl_GlobalInvocationID.xy; |
| 68 |
|
| 69 |
FfxFloat32x3 ColorPreAlpha = LoadOpaqueOnly(FFX_MIN16_I2(uDispatchThreadId)).rgb; |
| 70 |
FfxFloat32x3 ColorPostAlpha = LoadInputColor(FFX_MIN16_I2(uDispatchThreadId)).rgb; |
| 71 |
|
| 72 |
if ((cbGenerateReactive.flags & FFX_FSR2_AUTOREACTIVEFLAGS_APPLY_TONEMAP) != 0) |
| 73 |
{ |
| 74 |
ColorPreAlpha = Tonemap(ColorPreAlpha); |
| 75 |
ColorPostAlpha = Tonemap(ColorPostAlpha); |
| 76 |
} |
| 77 |
|
| 78 |
if ((cbGenerateReactive.flags & FFX_FSR2_AUTOREACTIVEFLAGS_APPLY_INVERSETONEMAP) != 0) |
| 79 |
{ |
| 80 |
ColorPreAlpha = InverseTonemap(ColorPreAlpha); |
| 81 |
ColorPostAlpha = InverseTonemap(ColorPostAlpha); |
| 82 |
} |
| 83 |
|
| 84 |
FfxFloat32 out_reactive_value = 0.f; |
| 85 |
FfxFloat32x3 delta = abs(ColorPostAlpha - ColorPreAlpha); |
| 86 |
|
| 87 |
out_reactive_value = ((cbGenerateReactive.flags & FFX_FSR2_AUTOREACTIVEFLAGS_USE_COMPONENTS_MAX)!=0) ? max(delta.x, max(delta.y, delta.z)) : length(delta); |
| 88 |
out_reactive_value *= cbGenerateReactive.scale; |
| 89 |
|
| 90 |
out_reactive_value = ((cbGenerateReactive.flags & FFX_FSR2_AUTOREACTIVEFLAGS_APPLY_THRESHOLD)!=0) ? ((out_reactive_value < cbGenerateReactive.threshold) ? 0 : cbGenerateReactive.binaryValue) : out_reactive_value; |
| 91 |
|
| 92 |
imageStore(rw_output_autoreactive, FfxInt32x2(uDispatchThreadId), vec4(out_reactive_value)); |
| 93 |
} |