compute-cascade-fragment-shader.glsl 962 B

123456789101112131415161718192021222324252627282930313233
  1. varying vec2 vUv;
  2. uniform sampler2D sceneTexture;
  3. uniform sampler2D sdfTexture;
  4. uniform vec2 sceneResolution;
  5. uniform int cascadeLevel;
  6. // #define DEBUG
  7. void main() {
  8. vec2 pixelIndex = (gl_FragCoord.xy - 0.5);
  9. // Grab info about the current cascade level
  10. CascadeInfo info = Cascade_GetInfo(cascadeLevel);
  11. ProbeIndex cascadeIndex = ProbeIndex_Create(pixelIndex, info);
  12. ProbeAABB aabb = ProbeAABB_Create(cascadeIndex, info);
  13. // Angle of the ray from the center of the cascade
  14. CascadePixelIndex coordsInCascade = CascadePixelIndex(ivec2(pixelIndex - aabb.min));
  15. float angleRadians = Angle_FromCascadeIndex(coordsInCascade, info);
  16. // Sample the scene to get radiance
  17. vec2 rayDirection = vec2(cos(angleRadians), sin(angleRadians));
  18. vec2 rayOrigin = aabb.center * sceneResolution / cascadeResolution;
  19. vec4 radiance = SampleRadiance_SDF(
  20. sdfTexture, sceneResolution, rayOrigin, rayDirection, info);
  21. gl_FragColor = radiance;
  22. }