final-compose-fragment-shader.glsl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. varying vec2 vUv;
  2. uniform sampler2D radianceTexture;
  3. uniform sampler2D sceneTexture;
  4. uniform sampler2D sdfTexture;
  5. uniform vec2 resolution;
  6. vec3 BackgroundColour() {
  7. return col3(1.0);
  8. }
  9. vec3 drawGrid(vec2 pixelCoords, vec3 colour, vec3 lineColour, float cellSpacing, float lineWidth, float pixelSize) {
  10. vec2 cellPosition = abs(fract(pixelCoords / vec2(cellSpacing)) - 0.5);
  11. float distToEdge = (0.5 - max(cellPosition.x, cellPosition.y)) * cellSpacing;
  12. float lines = smoothstep(lineWidth - pixelSize, lineWidth, distToEdge);
  13. colour = mix(lineColour, colour, lines);
  14. return colour;
  15. }
  16. vec3 drawGraphBackground_Ex(vec2 pixelCoords, float scale) {
  17. float pixelSize = 1.0 / scale;
  18. vec2 cellPosition = floor(pixelCoords / vec2(100.0));
  19. vec2 cellID = vec2(floor(cellPosition.x), floor(cellPosition.y));
  20. vec3 checkerboard = col3(mod(cellID.x + cellID.y, 2.0));
  21. vec3 colour = BackgroundColour();
  22. colour = mix(colour, checkerboard, 0.05);
  23. colour = drawGrid(pixelCoords, colour, col3(0.5), 10.0, 1.0, pixelSize);
  24. colour = drawGrid(pixelCoords, colour, col3(0.25), 100.0, 2.5, pixelSize);
  25. colour = (col3(0.95) + hash(pixelCoords) * 0.01) * colour;
  26. return colour;
  27. }
  28. vec3 drawGraphBackground(vec2 pixelCoords) {
  29. return drawGraphBackground_Ex(pixelCoords, 1.0);
  30. }
  31. void main() {
  32. vec2 pixelCoords = (vUv - 0.5) * resolution;
  33. vec2 uv = vUv;
  34. vec4 radiance = texture(radianceTexture, uv);
  35. vec4 scene = texture2D(sceneTexture, uv);
  36. vec4 sdf = texture2D(sdfTexture, uv);
  37. vec3 bg = drawGraphBackground(pixelCoords);
  38. vec3 colour = mix(bg, col3(sdf.xyz), smoothstep(1.0, 0.0, sdf.w));
  39. #if defined(USE_OKLAB)
  40. colour = oklabToRGB(colour);
  41. #endif
  42. colour *= radiance.xyz;
  43. colour = aces_tonemap(colour);
  44. gl_FragColor = vec4(colour, 1.0);
  45. }