SepiaShader.js 999 B

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