SepiaShader.js 913 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Sepia tone shader
  3. * based on glfx.js sepia shader
  4. * https://github.com/evanw/glfx.js
  5. */
  6. const SepiaShader = {
  7. uniforms: {
  8. 'tDiffuse': { value: null },
  9. 'amount': { value: 1.0 }
  10. },
  11. vertexShader: /* glsl */`
  12. varying vec2 vUv;
  13. void main() {
  14. vUv = uv;
  15. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  16. }`,
  17. fragmentShader: /* glsl */`
  18. uniform float amount;
  19. uniform sampler2D tDiffuse;
  20. varying vec2 vUv;
  21. void main() {
  22. vec4 color = texture2D( tDiffuse, vUv );
  23. vec3 c = color.rgb;
  24. color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) );
  25. color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) );
  26. color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) );
  27. gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a );
  28. }`
  29. };
  30. export { SepiaShader };