BrightnessContrastShader.js 1.1 KB

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