Unity-NorthStar / data /Packages /com.unity.render-pipelines.universal /Shaders /PostProcessing /ScalingSetup.shader
| Shader "Hidden/Universal Render Pipeline/Scaling Setup" | |
| { | |
| HLSLINCLUDE | |
| float4 _SourceSize; | |
| float4 _HDROutputLuminanceParams; | |
| half4 FragScalingSetup(Varyings input) : SV_Target | |
| { | |
| UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); | |
| float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord); | |
| float2 positionNDC = uv; | |
| int2 positionSS = uv * _SourceSize.xy; | |
| half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_PointClamp, uv); | |
| // When alpha processing is enabled, FXAA should not affect pixels with zero alpha | |
| UNITY_BRANCH | |
| if(color.a > 0) | |
| color.rgb = ApplyFXAA(color.rgb, positionNDC, positionSS, _SourceSize, _BlitTexture, PaperWhite, OneOverPaperWhite); | |
| color.rgb = ApplyFXAA(color.rgb, positionNDC, positionSS, _SourceSize, _BlitTexture, PaperWhite, OneOverPaperWhite); | |
| // In HDR output mode, the colors are expressed in nits, which can go up to 10k nits. | |
| // We divide by the display max nits to get a max value closer to 1.0 but it could still be > 1.0. | |
| // Finally, use FastTonemap() to squash everything < 1.0. | |
| color = half4(FastTonemap(color.rgb * OneOverPaperWhite), color.a); | |
| // EASU expects perceptually encoded color data so either encode to gamma 2.0 here if the input | |
| // data is linear, or let it pass through unchanged if it's already gamma encoded. | |
| color = LinearToGamma20(color); | |
| // Alpha will lose precision and band due to low bits in alpha. | |
| // Should be fine for alpha test mask. | |
| // Or a simple 2-bit dither can be done. | |
| // uint2 b = positionSS & 1; | |
| // uint dp = b.y ? (b.x ? 1 : 3) : (b.x ? 2 : 0); | |
| // half d = ((dp / 3.0) - 0.5) * 0.25; | |
| // color.a += d; | |
| return color; | |
| return half4(color.rgb, 1.0); | |
| } | |
| ENDHLSL | |
| /// | |
| /// Scaling Setup Shader | |
| /// | |
| /// This shader is used to perform any operations that need to place before image scaling occurs. | |
| /// It is not expected to be executed unless image scaling is active. | |
| /// | |
| /// Supported Operations: | |
| /// | |
| /// FXAA | |
| /// The FXAA shader does not support mismatched input and output dimensions so it must be run before any image | |
| /// scaling takes place. | |
| /// | |
| SubShader | |
| { | |
| Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"} | |
| LOD 100 | |
| ZTest Always ZWrite Off Cull Off | |
| Pass | |
| { | |
| Name "ScalingSetup" | |
| HLSLPROGRAM | |
| ENDHLSL | |
| } | |
| } | |
| } | |