BrightnessContrastShader.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /** @module BrightnessContrastShader */
  2. /**
  3. * Brightness and contrast adjustment {@link 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. * @constant
  8. * @type {Object}
  9. */
  10. const BrightnessContrastShader = {
  11. name: 'BrightnessContrastShader',
  12. uniforms: {
  13. 'tDiffuse': { value: null },
  14. 'brightness': { value: 0 },
  15. 'contrast': { value: 0 }
  16. },
  17. vertexShader: /* glsl */`
  18. varying vec2 vUv;
  19. void main() {
  20. vUv = uv;
  21. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  22. }`,
  23. fragmentShader: /* glsl */`
  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. };
  38. export { BrightnessContrastShader };
粤ICP备19079148号