OutputShader.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #elif defined( NEUTRAL_TONE_MAPPING )
  38. gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );
  39. #endif
  40. // color space
  41. #ifdef SRGB_TRANSFER
  42. gl_FragColor = sRGBTransferOETF( gl_FragColor );
  43. #endif
  44. }`
  45. };
  46. export { OutputShader };