rj-action-library/Runtime/Rendering/Compositor/CompositorEffects/DepthView/DepthViewShader.glsl

52 lines
1.1 KiB
Plaintext
Raw Normal View History

2025-04-23 12:00:43 +00:00
#[compute]
#version 450
layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in;
layout( rgba16f, set = 0, binding = 0)
2025-05-07 12:18:01 +00:00
uniform image2D colorImage;
2025-04-23 12:00:43 +00:00
layout( set = 1, binding = 0)
2025-05-07 12:18:01 +00:00
uniform sampler2D depthSampler;
2025-04-23 12:00:43 +00:00
layout(push_constant, std430)
2025-05-07 12:18:01 +00:00
uniform Parameters
2025-04-23 12:00:43 +00:00
{
2025-05-07 12:18:01 +00:00
float depthAmount;
float depthPower;
float grayAmount;
2025-04-23 12:00:43 +00:00
2025-05-07 12:18:01 +00:00
} parameters;
2025-04-23 12:00:43 +00:00
2025-05-07 12:18:01 +00:00
float sampleDepth( ivec2 coord, ivec2 size )
2025-04-23 12:00:43 +00:00
{
2025-05-07 12:18:01 +00:00
coord = clamp( coord, ivec2( 0 ), size - ivec2( 1 ) );
2025-04-23 12:00:43 +00:00
2025-05-07 12:18:01 +00:00
vec2 uv = ( vec2( coord ) + 0.5 ) / size;
return texture( depthSampler, uv ).r;
2025-04-23 12:00:43 +00:00
}
void main()
{
ivec2 uv = ivec2( gl_GlobalInvocationID.xy );
2025-05-07 12:18:01 +00:00
ivec2 size = imageSize( colorImage );
2025-04-23 12:00:43 +00:00
if ( uv.x >= size.x || uv.y >= size.y )
{
return;
}
2025-05-07 12:18:01 +00:00
vec4 color = imageLoad( colorImage, uv );
float depth = sampleDepth( uv, size );
float gray = color.r * 0.2 + color.g * 0.7 + color.b * 0.1;
float depthValue = pow( parameters.depthAmount * depth, parameters.depthPower );
2025-04-23 12:00:43 +00:00
2025-05-07 12:18:01 +00:00
depthValue = mix( depthValue, depthValue * gray, parameters.grayAmount );
2025-04-23 12:00:43 +00:00
2025-05-07 12:18:01 +00:00
color.rgb = vec3( depthValue, depthValue, depthValue );
2025-04-23 12:00:43 +00:00
2025-05-07 12:18:01 +00:00
imageStore( colorImage, uv, color );
2025-04-23 12:00:43 +00:00
}