grain.fragment.fx 613 B

12345678910111213141516171819202122232425
  1. #include<helperFunctions>
  2. // samplers
  3. uniform sampler2D textureSampler; // original color
  4. // uniforms
  5. uniform float intensity;
  6. uniform float animatedSeed;
  7. // varyings
  8. varying vec2 vUV;
  9. void main(void)
  10. {
  11. gl_FragColor = texture2D(textureSampler, vUV);
  12. vec2 seed = vUV*(animatedSeed);
  13. float grain = dither(seed, intensity);
  14. // Add less grain when luminance is high or low
  15. float lum = getLuminance(gl_FragColor.rgb);
  16. float grainAmount = (cos(-PI + (lum*PI*2.))+1.)/2.;
  17. gl_FragColor.rgb += grain * grainAmount;
  18. gl_FragColor.rgb = max(gl_FragColor.rgb, 0.0);
  19. }