SepiaShader.js 974 B

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