VignetteShader.js 945 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /** @module VignetteShader */
  2. /**
  3. * Based on [PaintEffect postprocess from ro.me]{@link http://code.google.com/p/3-dreams-of-black/source/browse/deploy/js/effects/PaintEffect.js}.
  4. *
  5. * @constant
  6. * @type {Object}
  7. */
  8. const VignetteShader = {
  9. name: 'VignetteShader',
  10. uniforms: {
  11. 'tDiffuse': { value: null },
  12. 'offset': { value: 1.0 },
  13. 'darkness': { value: 1.0 }
  14. },
  15. vertexShader: /* glsl */`
  16. varying vec2 vUv;
  17. void main() {
  18. vUv = uv;
  19. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  20. }`,
  21. fragmentShader: /* glsl */`
  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. };
  33. export { VignetteShader };
粤ICP备19079148号