| 1 | import { |
| 2 | Color |
| 3 | } from 'three'; |
| 4 | |
| 5 | /** |
| 6 | * Luminosity |
| 7 | * http://en.wikipedia.org/wiki/Luminosity |
| 8 | */ |
| 9 | |
| 10 | const LuminosityHighPassShader = { |
| 11 | |
| 12 | name: 'LuminosityHighPassShader', |
| 13 | |
| 14 | shaderID: 'luminosityHighPass', |
| 15 | |
| 16 | uniforms: { |
| 17 | |
| 18 | 'tDiffuse': { value: null }, |
| 19 | 'luminosityThreshold': { value: 1.0 }, |
| 20 | 'smoothWidth': { value: 1.0 }, |
| 21 | 'defaultColor': { value: new Color( 0x000000 ) }, |
| 22 | 'defaultOpacity': { value: 0.0 } |
| 23 | |
| 24 | }, |
| 25 | |
| 26 | vertexShader: /* glsl */` |
| 27 | |
| 28 | varying vec2 vUv; |
| 29 | |
| 30 | void main() { |
| 31 | |
| 32 | vUv = uv; |
| 33 | |
| 34 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); |
| 35 | |
| 36 | }`, |
| 37 | |
| 38 | fragmentShader: /* glsl */` |
| 39 | |
| 40 | uniform sampler2D tDiffuse; |
| 41 | uniform vec3 defaultColor; |
| 42 | uniform float defaultOpacity; |
| 43 | uniform float luminosityThreshold; |
| 44 | uniform float smoothWidth; |
| 45 | |
| 46 | varying vec2 vUv; |
| 47 | |
| 48 | void main() { |
| 49 | |
| 50 | vec4 texel = texture2D( tDiffuse, vUv ); |
| 51 | |
| 52 | vec3 luma = vec3( 0.299, 0.587, 0.114 ); |
| 53 | |
| 54 | float v = dot( texel.xyz, luma ); |
| 55 | |
| 56 | vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity ); |
| 57 | |
| 58 | float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v ); |
| 59 | |
| 60 | gl_FragColor = mix( outputColor, texel, alpha ); |
| 61 | |
| 62 | }` |
| 63 | |
| 64 | }; |
| 65 | |
| 66 | export { LuminosityHighPassShader }; |