VignetteShader.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/#manual/en/introduction/Installation." );
  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. THREE.VignetteShader = {
  8. uniforms: {
  9. "tDiffuse": { value: null },
  10. "offset": { value: 1.0 },
  11. "darkness": { value: 1.0 }
  12. },
  13. vertexShader: [
  14. "varying vec2 vUv;",
  15. "void main() {",
  16. " vUv = uv;",
  17. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  18. "}"
  19. ].join( "\n" ),
  20. fragmentShader: [
  21. "uniform float offset;",
  22. "uniform float darkness;",
  23. "uniform sampler2D tDiffuse;",
  24. "varying vec2 vUv;",
  25. "void main() {",
  26. // Eskil's vignette
  27. " vec4 texel = texture2D( tDiffuse, vUv );",
  28. " vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );",
  29. " gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );",
  30. /*
  31. // alternative version from glfx.js
  32. // this one makes more "dusty" look (as opposed to "burned")
  33. " vec4 color = texture2D( tDiffuse, vUv );",
  34. " float dist = distance( vUv, vec2( 0.5 ) );",
  35. " color.rgb *= smoothstep( 0.8, offset * 0.799, dist *( darkness + offset ) );",
  36. " gl_FragColor = color;",
  37. */
  38. "}"
  39. ].join( "\n" )
  40. };