46 lines
1.6 KiB
GLSL
46 lines
1.6 KiB
GLSL
// MinecraftPT — RTWSM Backward Analysis
|
|
// Computes the importance map from the shadow map depth: which shadow map texels
|
|
// need more resolution (near-field geometry, steep normals).
|
|
|
|
#include "/Lib/Settings.glsl"
|
|
#include "/Lib/Utilities.glsl"
|
|
#include "/Lib/PathTracing/Voxelizer/VoxelProfile.glsl"
|
|
|
|
const ivec3 workGroups = ivec3(32, 16, 1);
|
|
layout (local_size_x = 32, local_size_y = 32) in;
|
|
|
|
layout (r32f) uniform writeonly image2D img_rtwImportance2D;
|
|
|
|
uniform sampler2D shadowcolor0;
|
|
|
|
void main(){
|
|
ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
|
|
vec2 uv = (vec2(texel) + 0.5) / vec2(RTW_RESOLUTION, RTW_RESOLUTION_Y);
|
|
|
|
// Sample shadow map depth (in the shadow region)
|
|
vec2 shadowUv = vec2(uv.x * 0.5 + 0.5, uv.y * 0.5); // map to right region
|
|
vec2 shadowTexel = shadowUv * shadowSize;
|
|
|
|
vec4 shadowData = texelFetch(shadowcolor0, ivec2(shadowTexel), 0);
|
|
|
|
float depth = shadowData.a;
|
|
float importance = 0.0;
|
|
|
|
if (depth < 1.0){
|
|
// Depth-based importance: closer = more important
|
|
float dist = 1.0 - depth;
|
|
importance = pow(dist, 2.0) * RTW_BACKWARD_DIST_FACTOR;
|
|
|
|
// Depth gradient importance (edges)
|
|
float dLeft = texelFetch(shadowcolor0, ivec2(shadowTexel) + ivec2(-1, 0), 0).a;
|
|
float dRight = texelFetch(shadowcolor0, ivec2(shadowTexel) + ivec2(1, 0), 0).a;
|
|
float dUp = texelFetch(shadowcolor0, ivec2(shadowTexel) + ivec2(0, -1), 0).a;
|
|
float dDown = texelFetch(shadowcolor0, ivec2(shadowTexel) + ivec2(0, 1), 0).a;
|
|
|
|
float gradient = abs(dLeft - dRight) + abs(dUp - dDown);
|
|
importance += gradient * 0.5 * RTW_BACKWARD_NORMAL_FACTOR;
|
|
}
|
|
|
|
imageStore(img_rtwImportance2D, texel, vec4(importance));
|
|
}
|