FilmShader.js 1.0 KB

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