2
0

LuminosityHighPassShader.js 1.1 KB

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