OutputShader.js 1.3 KB

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