BrightnessContrastShader.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/#manual/en/introduction/Installation." );
  2. /**
  3. * Brightness and contrast adjustment
  4. * https://github.com/evanw/glfx.js
  5. * brightness: -1 to 1 (-1 is solid black, 0 is no change, and 1 is solid white)
  6. * contrast: -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast)
  7. */
  8. THREE.BrightnessContrastShader = {
  9. uniforms: {
  10. "tDiffuse": { value: null },
  11. "brightness": { value: 0 },
  12. "contrast": { value: 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 float brightness;",
  24. "uniform float contrast;",
  25. "varying vec2 vUv;",
  26. "void main() {",
  27. " gl_FragColor = texture2D( tDiffuse, vUv );",
  28. " gl_FragColor.rgb += brightness;",
  29. " if (contrast > 0.0) {",
  30. " gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) / (1.0 - contrast) + 0.5;",
  31. " } else {",
  32. " gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) * (1.0 + contrast) + 0.5;",
  33. " }",
  34. "}"
  35. ].join( "\n" )
  36. };