Files
minecraft-pt/shaders/Lib/PathTracing/Tracer/TracingNoise.glsl
T

33 lines
1.2 KiB
GLSL

// MinecraftPT — Tracing Noise
// Noise functions for ray tracing (hash-based, temporally stable).
#ifndef TRACING_NOISE_GLSL
#define TRACING_NOISE_GLSL
// Per-pixel temporal noise, stable across frames
float GetTracingNoise(vec2 screenPos, int frame, int offset){
// Blue noise from texture + temporal interleave
vec2 coord = (screenPos + 0.5) / screenSize;
coord = fract(coord * vec2(128.0, 128.0) + 0.5);
vec2 texel = coord * vec2(127.0 / 128.0) + vec2(0.5 / 128.0);
float noise = textureLod(noisetex, texel, 0.0).r;
return fract(noise + (frame + offset) * 0.03125);
}
vec2 GetTracingNoise2(vec2 screenPos, int frame, int offset){
// 2D noise for ray directions
vec2 coord = (screenPos + 0.5) / screenSize;
coord = fract(coord * vec2(128.0, 128.0) + 0.5);
vec2 texel = coord * vec2(127.0 / 128.0) + vec2(0.5 / 128.0);
vec2 noise = textureLod(noisetex, texel, 0.0).rg;
return fract(noise + (frame + offset) * 0.03125);
}
// Golden-ratio based sample rotation (for progressive sampling)
vec2 RotateNoise(vec2 uv, int sampleIndex, int totalSamples){
float angle = 6.28318 * float(sampleIndex) / float(totalSamples);
mat2 rot = mat2(cos(angle), sin(angle), -sin(angle), cos(angle));
return rot * uv;
}
#endif