LuminosityHighPassShader.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. console.warn( "THREE.LuminosityHighPassShader: 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. * Luminosity
  4. * http://en.wikipedia.org/wiki/Luminosity
  5. */
  6. THREE.LuminosityHighPassShader = {
  7. shaderID: "luminosityHighPass",
  8. uniforms: {
  9. "tDiffuse": { value: null },
  10. "luminosityThreshold": { value: 1.0 },
  11. "smoothWidth": { value: 1.0 },
  12. "defaultColor": { value: new THREE.Color( 0x000000 ) },
  13. "defaultOpacity": { value: 0.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 sampler2D tDiffuse;",
  24. "uniform vec3 defaultColor;",
  25. "uniform float defaultOpacity;",
  26. "uniform float luminosityThreshold;",
  27. "uniform float smoothWidth;",
  28. "varying vec2 vUv;",
  29. "void main() {",
  30. " vec4 texel = texture2D( tDiffuse, vUv );",
  31. " vec3 luma = vec3( 0.299, 0.587, 0.114 );",
  32. " float v = dot( texel.xyz, luma );",
  33. " vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );",
  34. " float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );",
  35. " gl_FragColor = mix( outputColor, texel, alpha );",
  36. "}"
  37. ].join( "\n" )
  38. };