VignetteShader.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. *
  4. * Vignette shader
  5. * based on PaintEffect postprocess from ro.me
  6. * http://code.google.com/p/3-dreams-of-black/source/browse/deploy/js/effects/PaintEffect.js
  7. */
  8. THREE.VignetteShader = {
  9. uniforms: {
  10. "tDiffuse": { value: null },
  11. "offset": { value: 1.0 },
  12. "darkness": { value: 1.0 }
  13. },
  14. vertexShader: [
  15. "varying vec2 vUv;",
  16. "void main() {",
  17. "vUv = uv;",
  18. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  19. "}"
  20. ].join( "\n" ),
  21. fragmentShader: [
  22. "uniform float offset;",
  23. "uniform float darkness;",
  24. "uniform sampler2D tDiffuse;",
  25. "varying vec2 vUv;",
  26. "void main() {",
  27. // Eskil's vignette
  28. "vec4 texel = texture2D( tDiffuse, vUv );",
  29. "vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );",
  30. "gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );",
  31. /*
  32. // alternative version from glfx.js
  33. // this one makes more "dusty" look (as opposed to "burned")
  34. "vec4 color = texture2D( tDiffuse, vUv );",
  35. "float dist = distance( vUv, vec2( 0.5 ) );",
  36. "color.rgb *= smoothstep( 0.8, offset * 0.799, dist *( darkness + offset ) );",
  37. "gl_FragColor = color;",
  38. */
  39. "}"
  40. ].join( "\n" )
  41. };