ACESFilmicToneMappingShader.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. console.warn( "THREE.ACESFilmicToneMappingShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author WestLangley / http://github.com/WestLangley
  4. *
  5. * ACES Filmic Tone Mapping Shader by Stephen Hill
  6. * source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
  7. *
  8. * this implementation of ACES is modified to accommodate a brighter viewing environment.
  9. * the scale factor of 1/0.6 is subjective. see discussion in #19621.
  10. */
  11. THREE.ACESFilmicToneMappingShader = {
  12. uniforms: {
  13. 'tDiffuse': { value: null },
  14. 'exposure': { value: 1.0 }
  15. },
  16. vertexShader: [
  17. 'varying vec2 vUv;',
  18. 'void main() {',
  19. ' vUv = uv;',
  20. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  21. '}'
  22. ].join( '\n' ),
  23. fragmentShader: [
  24. '#define saturate(a) clamp( a, 0.0, 1.0 )',
  25. 'uniform sampler2D tDiffuse;',
  26. 'uniform float exposure;',
  27. 'varying vec2 vUv;',
  28. 'vec3 RRTAndODTFit( vec3 v ) {',
  29. ' vec3 a = v * ( v + 0.0245786 ) - 0.000090537;',
  30. ' vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;',
  31. ' return a / b;',
  32. '}',
  33. 'vec3 ACESFilmicToneMapping( vec3 color ) {',
  34. // sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
  35. ' const mat3 ACESInputMat = mat3(',
  36. ' vec3( 0.59719, 0.07600, 0.02840 ),', // transposed from source
  37. ' vec3( 0.35458, 0.90834, 0.13383 ),',
  38. ' vec3( 0.04823, 0.01566, 0.83777 )',
  39. ' );',
  40. // ODT_SAT => XYZ => D60_2_D65 => sRGB
  41. ' const mat3 ACESOutputMat = mat3(',
  42. ' vec3( 1.60475, -0.10208, -0.00327 ),', // transposed from source
  43. ' vec3( -0.53108, 1.10813, -0.07276 ),',
  44. ' vec3( -0.07367, -0.00605, 1.07602 )',
  45. ' );',
  46. ' color = ACESInputMat * color;',
  47. // Apply RRT and ODT
  48. ' color = RRTAndODTFit( color );',
  49. ' color = ACESOutputMat * color;',
  50. // Clamp to [0, 1]
  51. ' return saturate( color );',
  52. '}',
  53. 'void main() {',
  54. ' vec4 tex = texture2D( tDiffuse, vUv );',
  55. ' tex.rgb *= exposure / 0.6;', // pre-exposed, outside of the tone mapping function
  56. ' gl_FragColor = vec4( ACESFilmicToneMapping( tex.rgb ), tex.a );',
  57. '}'
  58. ].join( '\n' )
  59. };