OutputShader.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #endif
  36. // color space
  37. #ifdef SRGB_TRANSFER
  38. gl_FragColor = sRGBTransferOETF( gl_FragColor );
  39. #endif
  40. }`
  41. };
  42. export { OutputShader };