BrightnessContrastShader.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. console.warn( "THREE.BrightnessContrastShader: 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/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author tapio / http://tapio.github.com/
  4. *
  5. * Brightness and contrast adjustment
  6. * https://github.com/evanw/glfx.js
  7. * brightness: -1 to 1 (-1 is solid black, 0 is no change, and 1 is solid white)
  8. * contrast: -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast)
  9. */
  10. THREE.BrightnessContrastShader = {
  11. uniforms: {
  12. "tDiffuse": { value: null },
  13. "brightness": { value: 0 },
  14. "contrast": { value: 0 }
  15. },
  16. vertexShader: [
  17. "varying vec2 vUv;",
  18. "void main() {",
  19. " vUv = uv;",
  20. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  21. "}"
  22. ].join( "\n" ),
  23. fragmentShader: [
  24. "uniform sampler2D tDiffuse;",
  25. "uniform float brightness;",
  26. "uniform float contrast;",
  27. "varying vec2 vUv;",
  28. "void main() {",
  29. " gl_FragColor = texture2D( tDiffuse, vUv );",
  30. " gl_FragColor.rgb += brightness;",
  31. " if (contrast > 0.0) {",
  32. " gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) / (1.0 - contrast) + 0.5;",
  33. " } else {",
  34. " gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) * (1.0 + contrast) + 0.5;",
  35. " }",
  36. "}"
  37. ].join( "\n" )
  38. };