FilmShader.js 923 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const FilmShader = {
  2. name: 'FilmShader',
  3. uniforms: {
  4. 'tDiffuse': { value: null },
  5. 'time': { value: 0.0 },
  6. 'intensity': { value: 0.5 },
  7. 'grayscale': { value: false }
  8. },
  9. vertexShader: /* glsl */`
  10. varying vec2 vUv;
  11. void main() {
  12. vUv = uv;
  13. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  14. }`,
  15. fragmentShader: /* glsl */`
  16. #include <common>
  17. uniform float intensity;
  18. uniform bool grayscale;
  19. uniform float time;
  20. uniform sampler2D tDiffuse;
  21. varying vec2 vUv;
  22. void main() {
  23. vec4 base = texture2D( tDiffuse, vUv );
  24. float noise = rand( fract( vUv + time ) );
  25. vec3 color = base.rgb + base.rgb * clamp( 0.1 + noise, 0.0, 1.0 );
  26. color = mix( base.rgb, color, intensity );
  27. if ( grayscale ) {
  28. color = vec3( luminance( color ) ); // assuming linear-srgb
  29. }
  30. gl_FragColor = vec4( color, base.a );
  31. }`,
  32. };
  33. export { FilmShader };