OutputShader.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const OutputShader = {
  2. name: 'OutputShader',
  3. uniforms: {
  4. 'tDiffuse': { value: null },
  5. 'toneMappingExposure': { value: 1 }
  6. },
  7. vertexShader: /* glsl */`
  8. precision highp float;
  9. uniform mat4 modelViewMatrix;
  10. uniform mat4 projectionMatrix;
  11. attribute vec3 position;
  12. attribute vec2 uv;
  13. varying vec2 vUv;
  14. void main() {
  15. vUv = uv;
  16. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  17. }`,
  18. fragmentShader: /* glsl */`
  19. precision highp float;
  20. uniform sampler2D tDiffuse;
  21. #include <tonemapping_pars_fragment>
  22. #include <colorspace_pars_fragment>
  23. varying vec2 vUv;
  24. void main() {
  25. gl_FragColor = texture2D( tDiffuse, vUv );
  26. // tone mapping
  27. #ifdef LINEAR_TONE_MAPPING
  28. gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );
  29. #elif defined( REINHARD_TONE_MAPPING )
  30. gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );
  31. #elif defined( CINEON_TONE_MAPPING )
  32. gl_FragColor.rgb = OptimizedCineonToneMapping( gl_FragColor.rgb );
  33. #elif defined( ACES_FILMIC_TONE_MAPPING )
  34. gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );
  35. #elif defined( AGX_TONE_MAPPING )
  36. gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );
  37. #endif
  38. // color space
  39. #ifdef SRGB_TRANSFER
  40. gl_FragColor = sRGBTransferOETF( gl_FragColor );
  41. #endif
  42. }`
  43. };
  44. export { OutputShader };