#include "/Lib/BasicFunctions/LightingConstants.glsl" // MinecraftPT — SampleIRC // Sampling the irradiance cache: a 3D grid of pre-computed diffuse irradiance // used to cheaply evaluate indirect diffuse light. #ifndef SAMPLE_IRC_GLSL #define SAMPLE_IRC_GLSL // Sample irradiance cache at a world position (trilinear) vec3 SampleIRC(vec3 worldPos){ vec3 voxelPos = WorldToVoxel(worldPos); vec3 coord = voxelPos / float(ircResolution); if (clamp(coord, vec3(0.0), vec3(1.0)) == coord){ coord *= float(ircResolution) - 1.0; vec3 base = floor(coord); vec3 frac = coord - base; ivec3 i0 = ivec3(base); ivec3 i1 = min(i0 + 1, ivec3(ircResolution - 1)); vec3 c000 = texelFetch(irradianceCache3D, i0, 0).rgb; vec3 c100 = texelFetch(irradianceCache3D, ivec3(i1.x, i0.y, i0.z), 0).rgb; vec3 c010 = texelFetch(irradianceCache3D, ivec3(i0.x, i1.y, i0.z), 0).rgb; vec3 c110 = texelFetch(irradianceCache3D, ivec3(i1.x, i1.y, i0.z), 0).rgb; vec3 c001 = texelFetch(irradianceCache3D, ivec3(i0.x, i0.y, i1.z), 0).rgb; vec3 c101 = texelFetch(irradianceCache3D, ivec3(i1.x, i0.y, i1.z), 0).rgb; vec3 c011 = texelFetch(irradianceCache3D, ivec3(i0.x, i1.y, i1.z), 0).rgb; vec3 c111 = texelFetch(irradianceCache3D, i1, 0).rgb; vec3 x00 = mix(c000, c100, frac.x); vec3 x10 = mix(c010, c110, frac.x); vec3 x01 = mix(c001, c101, frac.x); vec3 x11 = mix(c011, c111, frac.x); vec3 y0 = mix(x00, x10, frac.y); vec3 y1 = mix(x01, x11, frac.y); return mix(y0, y1, frac.z); } // Outside the cache — fall back to sky ambient return GetCelestialIrradiance() + GetAtmoIrradiance(); } // Normal-aware IRC sampling (bias by surface normal facing) vec3 SampleIRCNormal(vec3 worldPos, vec3 normal){ vec3 irc = SampleIRC(worldPos); // Simple hemisphere shading via normal alignment with up float upFactor = normal.y * 0.5 + 0.5; return irc * (0.5 + 0.5 * upFactor); } #endif