OutputShader.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * @module OutputShader
  3. * @three_import import { OutputShader } from 'three/addons/shaders/OutputShader.js';
  4. */
  5. /**
  6. * Performs tone mapping and color space conversion for
  7. * FX workflows.
  8. *
  9. * Used by {@link OutputPass}.
  10. *
  11. * @constant
  12. * @type {ShaderMaterial~Shader}
  13. */
  14. const OutputShader = {
  15. name: 'OutputShader',
  16. uniforms: {
  17. 'tDiffuse': { value: null },
  18. 'toneMappingExposure': { value: 1 }
  19. },
  20. vertexShader: /* glsl */`
  21. precision highp float;
  22. uniform mat4 modelViewMatrix;
  23. uniform mat4 projectionMatrix;
  24. attribute vec3 position;
  25. attribute vec2 uv;
  26. varying vec2 vUv;
  27. void main() {
  28. vUv = uv;
  29. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  30. }`,
  31. fragmentShader: /* glsl */`
  32. precision highp float;
  33. uniform sampler2D tDiffuse;
  34. #include <tonemapping_pars_fragment>
  35. #include <colorspace_pars_fragment>
  36. varying vec2 vUv;
  37. void main() {
  38. gl_FragColor = texture2D( tDiffuse, vUv );
  39. // tone mapping
  40. #ifdef LINEAR_TONE_MAPPING
  41. gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );
  42. #elif defined( REINHARD_TONE_MAPPING )
  43. gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );
  44. #elif defined( CINEON_TONE_MAPPING )
  45. gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );
  46. #elif defined( ACES_FILMIC_TONE_MAPPING )
  47. gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );
  48. #elif defined( AGX_TONE_MAPPING )
  49. gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );
  50. #elif defined( NEUTRAL_TONE_MAPPING )
  51. gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );
  52. #elif defined( CUSTOM_TONE_MAPPING )
  53. gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );
  54. #endif
  55. // color space
  56. #ifdef SRGB_TRANSFER
  57. gl_FragColor = sRGBTransferOETF( gl_FragColor );
  58. #endif
  59. }`
  60. };
  61. export { OutputShader };