Shader "Hidden/Shader/UTSTonemapping" { Properties { // This property is necessary to make the CommandBuffer.Blit bind the source texture to _MainTex _MainTex("Main Texture", 2DArray) = "grey" {} } HLSLINCLUDE #pragma target 4.5 #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl" struct Attributes { uint vertexID : SV_VertexID; UNITY_VERTEX_INPUT_INSTANCE_ID }; struct Varyings { float4 positionCS : SV_POSITION; float2 texcoord : TEXCOORD0; UNITY_VERTEX_OUTPUT_STEREO }; Varyings Vert(Attributes input) { Varyings output; UNITY_SETUP_INSTANCE_ID(input); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID); output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID); return output; } TEXTURE2D_X(_MainTex); inline float3 UTSToonmap(float3 x) { #if 1 // GT Tonemap, see https://www.desmos.com/calculator/gslcdxvipg float p = 1.0; float a = 1.0; float m = 0.22; float l = 0.4; float c = 1.33; float b = 0.0; float l0 = (l * (p - m)) / a; float L0 = m - m / a; float L1 = m + (1 - m) / a; float3 Lx = m + a * (x - m); float3 Tx = m * pow(x / m, c) + b; float S0 = m + l0; float S1 = m + a * l0; float C2 = (a * p) / (p - S1); float3 Sx = p - (p - S1) * exp(-(C2 * (x - S0)) / p); float3 w0 = 1.0 - smoothstep( 0.0, m, x); float3 w2 = smoothstep(m + l0, m + l0, x); float3 w1 = 1.0 - w0 - w2; return Tx * w0 + Lx * w1 + Sx * w2; #else // Modified ACES, see https://www.desmos.com/calculator/j4tpqazyfw return (x * (2.63 * x + 0.03)) / (x * (2.11 * x + 0.72) + 0.31); #endif } float4 CustomPostProcess(Varyings input) : SV_Target { UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); // Note that if HDUtils.DrawFullScreen is not used to render the post process, you don't need to call ClampAndScaleUVForBilinearPostProcessTexture. float3 sourceColor = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, ClampAndScaleUVForBilinearPostProcessTexture(input.texcoord.xy)).rgb; #if 1 float3 color = UTSToonmap(sourceColor); #else float whiteScale = 1.0 / UTSToonmap(5.3); float3 color = UTSToonmap(sourceColor * whiteScale); color *= whiteScale; #endif return float4(color, 1); } ENDHLSL SubShader { Tags{ "RenderPipeline" = "HDRenderPipeline" } Pass { Name "UTSToonmapping" ZWrite Off ZTest Always Blend Off Cull Off HLSLPROGRAM #pragma fragment CustomPostProcess #pragma vertex Vert ENDHLSL } } Fallback Off }