OutputShader.js 1.7 KB

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