2
0

ACESFilmicToneMappingShader.js 2.2 KB

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