BrightnessContrastShader.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Brightness and contrast adjustment
  3. * https://github.com/evanw/glfx.js
  4. * brightness: -1 to 1 (-1 is solid black, 0 is no change, and 1 is solid white)
  5. * contrast: -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast)
  6. */
  7. THREE.BrightnessContrastShader = {
  8. uniforms: {
  9. 'tDiffuse': { value: null },
  10. 'brightness': { value: 0 },
  11. 'contrast': { value: 0 }
  12. },
  13. vertexShader: [
  14. 'varying vec2 vUv;',
  15. 'void main() {',
  16. ' vUv = uv;',
  17. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  18. '}'
  19. ].join( '\n' ),
  20. fragmentShader: [
  21. 'uniform sampler2D tDiffuse;',
  22. 'uniform float brightness;',
  23. 'uniform float contrast;',
  24. 'varying vec2 vUv;',
  25. 'void main() {',
  26. ' gl_FragColor = texture2D( tDiffuse, vUv );',
  27. ' gl_FragColor.rgb += brightness;',
  28. ' if (contrast > 0.0) {',
  29. ' gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) / (1.0 - contrast) + 0.5;',
  30. ' } else {',
  31. ' gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) * (1.0 + contrast) + 0.5;',
  32. ' }',
  33. '}'
  34. ].join( '\n' )
  35. };