Initial commit: Minecraft 光追着色器包(从零实现的 path tracing)
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#include "/Lib/Settings.glsl"
|
||||
#include "/Lib/Utilities.glsl"
|
||||
// MinecraftPT — RTWSM SampleWarp
|
||||
// Samples the warp map to redistribute shadow map coordinates.
|
||||
|
||||
#ifndef SAMPLE_WARP_GLSL
|
||||
uniform sampler2D rtwWarp1D;
|
||||
#define SAMPLE_WARP_GLSL
|
||||
|
||||
// Warp curve sampling: rtwWarp1D is a RG16 texture, RTW_RESOLUTION x 2
|
||||
// Row 0: warp curve (cumulative importance), Row 1: inverse warp curve
|
||||
vec2 SampleWarp(float value){
|
||||
vec2 coord = vec2(value * (RTW_RESOLUTION - 1.0) + 0.5, 0.5) / vec2(RTW_RESOLUTION, 2.0);
|
||||
return textureLod(rtwWarp1D, coord, 0.0).rg;
|
||||
}
|
||||
|
||||
// Smooth warp sampling with lerp
|
||||
vec2 SampleRTWWarpSmooth(vec2 shadowScreenPos){
|
||||
// The warp is 1D along the shadow map's X axis (sun direction)
|
||||
float u = saturate(shadowScreenPos.x);
|
||||
|
||||
// Sample warp curve
|
||||
vec2 warp = SampleWarp(u);
|
||||
|
||||
// Apply warp: remap x based on cumulative importance
|
||||
float warpedX = warp.x;
|
||||
|
||||
// Also apply to y for 2D warping (using second channel)
|
||||
float warpedY = warp.y;
|
||||
|
||||
return vec2(warpedX - u, warpedY - shadowScreenPos.y);
|
||||
}
|
||||
|
||||
// Full warp application for shadow map sampling
|
||||
vec2 WarpShadowCoord(vec2 shadowScreenPos){
|
||||
float u = saturate(shadowScreenPos.x);
|
||||
vec2 warp = SampleWarp(u);
|
||||
|
||||
vec2 warped = vec2(warp.x, warp.y);
|
||||
|
||||
// The warp curve maps [0,1] -> [0,1] cumulative
|
||||
// Inverse: sample with the inverse curve
|
||||
return warped;
|
||||
}
|
||||
|
||||
// Unwarp (for reconstructing world positions)
|
||||
vec2 UnwarpShadowCoord(vec2 warpedCoord){
|
||||
// Binary search on the warp curve (forward map)
|
||||
float low = 0.0;
|
||||
float high = 1.0;
|
||||
|
||||
for (int i = 0; i < 8; i++){
|
||||
float mid = (low + high) * 0.5;
|
||||
vec2 sample = SampleWarp(mid);
|
||||
if (sample.x < warpedCoord.x){
|
||||
low = mid;
|
||||
}else{
|
||||
high = mid;
|
||||
}
|
||||
}
|
||||
|
||||
return vec2((low + high) * 0.5, warpedCoord.y);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user