scene-fragment-shader.glsl 954 B

12345678910111213141516171819202122232425262728293031323334353637
  1. uniform vec2 resolution;
  2. varying vec3 vWorldPosition;
  3. varying vec3 vWorldNormal;
  4. varying vec2 vUv;
  5. uniform float time;
  6. uniform sampler2D sdfTexture;
  7. uniform vec2 brushPos;
  8. uniform float brushRadius;
  9. uniform vec3 brushColour;
  10. void main() {
  11. vec2 uv = gl_FragCoord.xy / resolution.xy;
  12. vec2 pixelCoords = gl_FragCoord.xy - resolution.xy / 2.0;
  13. vec4 texel = texture2D(sdfTexture, uv);
  14. vec3 lightColour = vec3(0.0, 0.0, 1.0);
  15. float lightDist = sdfBox(pixelCoords - vec2(0.0), vec2(20.0));
  16. vec3 colour = mix(texel.xyz, lightColour, smoothstep(0.0, 1.0, texel.w));
  17. float dist = min(texel.w, lightDist);
  18. // Draw temporary brush
  19. vec2 brushCoords = (brushPos - 0.5) * resolution;
  20. float brushDist = sdfCircle((pixelCoords - brushCoords), brushRadius * 0.5);
  21. colour = mix(colour, brushColour, smoothstep(1.0, 0.0, brushDist));
  22. dist = min(dist, brushDist);
  23. gl_FragColor = vec4(colour, dist);
  24. }