LuminosityHighPassShader.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. ( function () {
  2. /**
  3. * Luminosity
  4. * http://en.wikipedia.org/wiki/Luminosity
  5. */
  6. var LuminosityHighPassShader = {
  7. shaderID: 'luminosityHighPass',
  8. uniforms: {
  9. 'tDiffuse': {
  10. value: null
  11. },
  12. 'luminosityThreshold': {
  13. value: 1.0
  14. },
  15. 'smoothWidth': {
  16. value: 1.0
  17. },
  18. 'defaultColor': {
  19. value: new THREE.Color( 0x000000 )
  20. },
  21. 'defaultOpacity': {
  22. value: 0.0
  23. }
  24. },
  25. vertexShader: [ 'varying vec2 vUv;', 'void main() {', ' vUv = uv;', ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}' ].join( '\n' ),
  26. fragmentShader: [ 'uniform sampler2D tDiffuse;', 'uniform vec3 defaultColor;', 'uniform float defaultOpacity;', 'uniform float luminosityThreshold;', 'uniform float smoothWidth;', 'varying vec2 vUv;', 'void main() {', ' vec4 texel = texture2D( tDiffuse, vUv );', ' vec3 luma = vec3( 0.299, 0.587, 0.114 );', ' float v = dot( texel.xyz, luma );', ' vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );', ' float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );', ' gl_FragColor = mix( outputColor, texel, alpha );', '}' ].join( '\n' )
  27. };
  28. THREE.LuminosityHighPassShader = LuminosityHighPassShader;
  29. } )();