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
+37
View File
@@ -0,0 +1,37 @@
// MinecraftPT — Held Light
// Torch in hand / flashlight illumination.
#ifndef HELDLIGHT_GLSL
#define HELDLIGHT_GLSL
// Physical held light: torches held in hand or flashlight
vec3 GetHeldLight(vec3 worldPos, vec3 worldNormal, out float heldLightShadow){
vec3 result = vec3(0.0);
heldLightShadow = 1.0;
#ifdef HELDLIGHT_MODE
#if HELDLIGHT_MODE >= 1
// Torch in hand position (roughly 0.4, -0.4, 0.6 relative to camera)
vec3 heldPos = gbufferModelViewInverse[3].xyz + cameraPosition;
vec3 toLight = heldPos - worldPos;
float dist = length(toLight);
vec3 dir = toLight / max(dist, 1e-4);
float intensity = exp(-dist * dist * HELDLIGHT_FALLOFF) * HELDLIGHT_BRIGHTNESS;
float NdotL = max(dot(worldNormal, dir), 0.0);
vec3 color = pow(vec3(COLOR_TORCH_R, COLOR_TORCH_G, COLOR_TORCH_B), vec3(2.2));
result = color * intensity * NdotL;
#ifdef HELDLIGHT_SHADOW
// Simple ray shadow for held light (short distance)
heldLightShadow = SimpleShadowTracing(WorldToVoxel(worldPos + worldNormal * 0.1), dir);
#endif
#endif
#endif
return result;
}
#endif