OutputShader.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 = CineonToneMapping( 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. #elif defined( CUSTOM_TONE_MAPPING )
  40. gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );
  41. #endif
  42. // color space
  43. #ifdef SRGB_TRANSFER
  44. gl_FragColor = sRGBTransferOETF( gl_FragColor );
  45. #endif
  46. }`
  47. };
  48. export { OutputShader };
粤ICP备19079148号