VignetteShader.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. console.warn( "THREE.VignetteShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author alteredq / http://alteredqualia.com/
  4. *
  5. * Vignette shader
  6. * based on PaintEffect postprocess from ro.me
  7. * http://code.google.com/p/3-dreams-of-black/source/browse/deploy/js/effects/PaintEffect.js
  8. */
  9. THREE.VignetteShader = {
  10. uniforms: {
  11. "tDiffuse": { value: null },
  12. "offset": { value: 1.0 },
  13. "darkness": { value: 1.0 }
  14. },
  15. vertexShader: [
  16. "varying vec2 vUv;",
  17. "void main() {",
  18. " vUv = uv;",
  19. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  20. "}"
  21. ].join( "\n" ),
  22. fragmentShader: [
  23. "uniform float offset;",
  24. "uniform float darkness;",
  25. "uniform sampler2D tDiffuse;",
  26. "varying vec2 vUv;",
  27. "void main() {",
  28. // Eskil's vignette
  29. " vec4 texel = texture2D( tDiffuse, vUv );",
  30. " vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );",
  31. " gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );",
  32. /*
  33. // alternative version from glfx.js
  34. // this one makes more "dusty" look (as opposed to "burned")
  35. " vec4 color = texture2D( tDiffuse, vUv );",
  36. " float dist = distance( vUv, vec2( 0.5 ) );",
  37. " color.rgb *= smoothstep( 0.8, offset * 0.799, dist *( darkness + offset ) );",
  38. " gl_FragColor = color;",
  39. */
  40. "}"
  41. ].join( "\n" )
  42. };