VignetteShader.js 939 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const 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:
  20. /* glsl */
  21. `
  22. varying vec2 vUv;
  23. void main() {
  24. vUv = uv;
  25. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  26. }`,
  27. fragmentShader:
  28. /* glsl */
  29. `
  30. uniform float offset;
  31. uniform float darkness;
  32. uniform sampler2D tDiffuse;
  33. varying vec2 vUv;
  34. void main() {
  35. // Eskil's vignette
  36. vec4 texel = texture2D( tDiffuse, vUv );
  37. vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );
  38. gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );
  39. }`
  40. };
  41. THREE.VignetteShader = VignetteShader;
  42. } )();