VignetteShader.js 1.2 KB

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