diff options
Diffstat (limited to 'servers/rendering/renderer_rd/shaders')
-rw-r--r-- | servers/rendering/renderer_rd/shaders/effects/vrs.glsl | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/servers/rendering/renderer_rd/shaders/effects/vrs.glsl b/servers/rendering/renderer_rd/shaders/effects/vrs.glsl index 23b0373eef..7ed3fa3348 100644 --- a/servers/rendering/renderer_rd/shaders/effects/vrs.glsl +++ b/servers/rendering/renderer_rd/shaders/effects/vrs.glsl @@ -19,6 +19,14 @@ layout(location = 0) out vec3 uv_interp; layout(location = 0) out vec2 uv_interp; #endif +layout(push_constant, std430) uniform Params { + float max_texel_factor; + float res1; + float res2; + float res3; +} +params; + void main() { vec2 base_arr[3] = vec2[](vec2(-1.0, -1.0), vec2(-1.0, 3.0), vec2(3.0, -1.0)); gl_Position = vec4(base_arr[gl_VertexIndex], 0.0, 1.0); @@ -53,6 +61,14 @@ layout(set = 0, binding = 0) uniform sampler2D source_color; layout(location = 0) out uint frag_color; +layout(push_constant, std430) uniform Params { + float max_texel_factor; + float res1; + float res2; + float res3; +} +params; + void main() { #ifdef USE_MULTIVIEW vec3 uv = uv_interp; @@ -60,20 +76,22 @@ void main() { vec2 uv = uv_interp; #endif -#ifdef USE_MULTIVIEW + // Input is standardised. R for X, G for Y, 0.0 (0) = 1, 0.33 (85) = 2, 0.66 (170) = 3, 1.0 (255) = 8 vec4 color = textureLod(source_color, uv, 0.0); - frag_color = uint(color.r * 255.0); -#else /* USE_MULTIVIEW */ - vec4 color = textureLod(source_color, uv, 0.0); - - // for user supplied VRS map we do a color mapping - color.r *= 3.0; - frag_color = int(color.r) << 2; - color.g *= 3.0; - frag_color += int(color.g); - - // note 1x4, 4x1, 1x8, 8x1, 2x8 and 8x2 are not supported - // 4x8, 8x4 and 8x8 are only available on some GPUs -#endif /* USE_MULTIVIEW */ + // Output image shading rate image for VRS according to VK_KHR_fragment_shading_rate. + color.r = clamp(floor(color.r * params.max_texel_factor + 0.1), 0.0, params.max_texel_factor); + color.g = clamp(floor(color.g * params.max_texel_factor + 0.1), 0.0, params.max_texel_factor); + + // Note 1x4, 4x1, 1x8, 8x1, 2x8 and 8x2 are not supported: + if (color.r < (color.g - 1.0)) { + color.r = color.g - 1.0; + } + if (color.g < (color.r - 1.0)) { + color.g = color.r - 1.0; + } + + // Encode to frag_color; + frag_color = int(color.r + 0.1) << 2; + frag_color += int(color.g + 0.1); } |