53 lines
1.8 KiB
GLSL
53 lines
1.8 KiB
GLSL
// MinecraftPT — RTWSM Building Warp
|
|
// Builds the final warp curve (cumulative importance) from the importance map.
|
|
|
|
#include "/Lib/Settings.glsl"
|
|
#include "/Lib/Utilities.glsl"
|
|
|
|
const ivec3 workGroups = ivec3(32, 1, 1);
|
|
layout (local_size_x = 32) in;
|
|
|
|
layout (rg16) uniform writeonly image2D img_rtwWarp1D;
|
|
|
|
uniform sampler2D rtwImportance2D;
|
|
|
|
void main(){
|
|
int y = int(gl_GlobalInvocationID.y);
|
|
|
|
// Compute the cumulative importance curve for this row
|
|
float total = 0.0;
|
|
for (int x = 0; x < RTW_RESOLUTION; x++){
|
|
total += textureLod(rtwImportance2D, vec2(float(x) / float(RTW_RESOLUTION), float(y) / float(RTW_RESOLUTION_Y)), 0.0).r;
|
|
}
|
|
|
|
// Write warp curve: row 0 = cumulative, row 1 = inverse
|
|
if (total > 0.0){
|
|
float cum = 0.0;
|
|
for (int x = 0; x < RTW_RESOLUTION; x++){
|
|
cum += textureLod(rtwImportance2D, vec2(float(x) / float(RTW_RESOLUTION), float(y) / float(RTW_RESOLUTION_Y)), 0.0).r;
|
|
imageStore(img_rtwWarp1D, ivec2(x, 0), vec4(cum / total, 0.0, 0.0, 0.0));
|
|
}
|
|
|
|
// Inverse: for each output position find input position
|
|
for (int x = 0; x < RTW_RESOLUTION; x++){
|
|
float target = float(x) / float(RTW_RESOLUTION - 1);
|
|
int lo = 0;
|
|
int hi = RTW_RESOLUTION - 1;
|
|
for (int i = 0; i < 10; i++){
|
|
int mid = (lo + hi) / 2;
|
|
float v = textureLod(rtwImportance2D, vec2(float(mid) / float(RTW_RESOLUTION), float(y) / float(RTW_RESOLUTION_Y)), 0.0).r;
|
|
if (v < target) lo = mid; else hi = mid;
|
|
}
|
|
float inv = float(lo) / float(RTW_RESOLUTION);
|
|
imageStore(img_rtwWarp1D, ivec2(x, 1), vec4(inv, 0.0, 0.0, 0.0));
|
|
}
|
|
}else{
|
|
// Identity warp
|
|
for (int x = 0; x < RTW_RESOLUTION; x++){
|
|
float v = float(x) / float(RTW_RESOLUTION);
|
|
imageStore(img_rtwWarp1D, ivec2(x, 0), vec4(v, 0.0, 0.0, 0.0));
|
|
imageStore(img_rtwWarp1D, ivec2(x, 1), vec4(v, 0.0, 0.0, 0.0));
|
|
}
|
|
}
|
|
}
|