VignetteShader.js 867 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * Vignette shader
  3. * based on PaintEffect postprocess from ro.me
  4. * http://code.google.com/p/3-dreams-of-black/source/browse/deploy/js/effects/PaintEffect.js
  5. */
  6. const VignetteShader = {
  7. uniforms: {
  8. 'tDiffuse': { value: null },
  9. 'offset': { value: 1.0 },
  10. 'darkness': { value: 1.0 }
  11. },
  12. vertexShader: /* glsl */`
  13. varying vec2 vUv;
  14. void main() {
  15. vUv = uv;
  16. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  17. }`,
  18. fragmentShader: /* glsl */`
  19. uniform float offset;
  20. uniform float darkness;
  21. uniform sampler2D tDiffuse;
  22. varying vec2 vUv;
  23. void main() {
  24. // Eskil's vignette
  25. vec4 texel = texture2D( tDiffuse, vUv );
  26. vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );
  27. gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );
  28. }`
  29. };
  30. export { VignetteShader };