Initial commit: Minecraft 光追着色器包(从零实现的 path tracing)

This commit is contained in:
WpyQwq
2026-09-19 12:06:22 +08:00
commit 59e30822f8
314 changed files with 9259 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
// 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));
}
}
}