// 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