downsample.fragment.fx 794 B

1234567891011121314151617181920212223242526272829
  1. #ifdef GL_ES
  2. precision mediump float;
  3. #endif
  4. // Samplers
  5. varying vec2 vUV;
  6. uniform sampler2D textureSampler;
  7. // Parameters
  8. uniform vec2 screenSize;
  9. uniform float highlightThreshold;
  10. float highlights(vec3 color)
  11. {
  12. return smoothstep(highlightThreshold, 1.0, dot(color, vec3(0.3, 0.59, 0.11)));
  13. }
  14. void main(void)
  15. {
  16. vec2 texelSize = vec2(1.0 / screenSize.x, 1.0 / screenSize.y);
  17. vec4 baseColor = texture2D(textureSampler, vUV + vec2(-1.0, -1.0) * texelSize) * 0.25;
  18. baseColor += texture2D(textureSampler, vUV + vec2(1.0, -1.0) * texelSize) * 0.25;
  19. baseColor += texture2D(textureSampler, vUV + vec2(1.0, 1.0) * texelSize) * 0.25;
  20. baseColor += texture2D(textureSampler, vUV + vec2(-1.0, 1.0) * texelSize) * 0.25;
  21. baseColor.a = highlights(baseColor.rgb);
  22. gl_FragColor = baseColor;
  23. }