Files
minecraft-pt/shaders/Lib/RTWSM/CollapseImportance.glsl

34 lines
1.1 KiB
GLSL

// MinecraftPT — RTWSM Collapse Importance
// Collapses the 2D importance map into a 1D cumulative curve per row.
#include "/Lib/Settings.glsl"
#include "/Lib/Utilities.glsl"
const ivec3 workGroups = ivec3(RTW_RESOLUTION, 1, 1);
layout (local_size_x = 1) in;
layout (r32f) uniform writeonly image2D img_rtwImportance2D;
layout (rg16) uniform writeonly image2D img_rtwWarp1D;
uniform sampler2D rtwImportance2D;
void main(){
int y = int(gl_GlobalInvocationID.y);
// Sum importance across rows -> 1D profile
float sum = 0.0;
for (int x = 0; x < RTW_RESOLUTION; x++){
sum += textureLod(rtwImportance2D, vec2(float(x) / float(RTW_RESOLUTION), float(y) / float(RTW_RESOLUTION_Y)), 0.0).r;
}
// Build cumulative distribution
float cumulative = 0.0;
for (int x = 0; x < RTW_RESOLUTION; x++){
float imp = textureLod(rtwImportance2D, vec2(float(x) / float(RTW_RESOLUTION), float(y) / float(RTW_RESOLUTION_Y)), 0.0).r;
cumulative += imp;
float normalized = sum > 0.0 ? cumulative / sum : float(x) / float(RTW_RESOLUTION);
imageStore(img_rtwWarp1D, ivec2(x, y), vec4(normalized, 1.0 - normalized, 0.0, 0.0));
}
}