Variable toneMappingUtilsConst
toneMappingUtils: "\n// linear <-> sRGB conversions\nfn linearTosRGB(linear: vec3f) -> vec3f {\n return vec3( mix( pow( linear.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), linear.rgb * 12.92, vec3( lessThan3( linear.rgb, vec3( 0.0031308 ) ) ) ) );\n}\n\nfn linearTosRGB_4(linear: vec4f) -> vec4f {\n return vec4( linearTosRGB(linear.rgb), linear.a );\n}\n\nfn sRGBToLinear(srgb: vec3f) -> vec3f {\n if (all(srgb <= vec3(0.04045))) {\n return srgb / vec3(12.92);\n }\n return pow((srgb + vec3(0.055)) / vec3(1.055), vec3(2.4));\n}\n\nfn sRGBToLinear_4(srgb: vec4f) -> vec4f {\n return vec4( sRGBToLinear(srgb.rgb), srgb.a );\n}\n\n// source: https://www.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf\nfn ReinhardToneMapping( color: vec3f ) -> vec3f {\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\n\n// source: http://filmicworlds.com/blog/filmic-tonemapping-operators/\nfn CineonToneMapping( color: vec3f ) -> vec3f {\n\t// filmic operator by Jim Hejl and Richard Burgess-Dawson\n\tlet maxColor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( maxColor * ( 6.2 * maxColor + 0.5 ) ) / ( maxColor * ( 6.2 * maxColor + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n\n}\n\n// https://modelviewer.dev/examples/tone-mapping\nfn KhronosToneMapping( color: vec3f ) -> vec3f {\n var toneMapColor = color; \n const startCompression: f32 = 0.8 - 0.04;\n const desaturation: f32 = 0.15;\n var x: f32 = min(toneMapColor.r, min(toneMapColor.g, toneMapColor.b));\n var offset: f32 = select(0.04, x - 6.25 * x * x, x < 0.08);\n toneMapColor = toneMapColor - offset;\n var peak: f32 = max(toneMapColor.r, max(toneMapColor.g, toneMapColor.b));\n if (peak < startCompression) {\n return toneMapColor;\n }\n const d: f32 = 1. - startCompression;\n let newPeak: f32 = 1. - d * d / (peak + d - startCompression);\n toneMapColor *= newPeak / peak;\n let g: f32 = 1. - 1. / (desaturation * (peak - newPeak) + 1.);\n return mix(toneMapColor, newPeak * vec3(1, 1, 1), g);\n}\n" = ...
Tone mapping utils chunks.