Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ScalingSetup.shader 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Shader "Hidden/Universal Render Pipeline/Scaling Setup"
  2. {
  3. HLSLINCLUDE
  4. #pragma multi_compile_local_fragment _ _FXAA
  5. #pragma multi_compile_local_fragment _ _GAMMA_20 _GAMMA_20_AND_HDR_INPUT
  6. #pragma multi_compile_local_fragment _ _ENABLE_ALPHA_OUTPUT
  7. #if defined(_GAMMA_20_AND_HDR_INPUT)
  8. #define _GAMMA_20 1
  9. #define HDR_INPUT 1
  10. #endif
  11. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  12. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  13. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  14. #include "Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/Common.hlsl"
  15. float4 _SourceSize;
  16. float4 _HDROutputLuminanceParams;
  17. #define PaperWhite _HDROutputLuminanceParams.z
  18. #define OneOverPaperWhite _HDROutputLuminanceParams.w
  19. half4 FragScalingSetup(Varyings input) : SV_Target
  20. {
  21. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  22. float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
  23. float2 positionNDC = uv;
  24. int2 positionSS = uv * _SourceSize.xy;
  25. half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_PointClamp, uv);
  26. #if _FXAA
  27. #if _ENABLE_ALPHA_OUTPUT
  28. // When alpha processing is enabled, FXAA should not affect pixels with zero alpha
  29. UNITY_BRANCH
  30. if(color.a > 0)
  31. color.rgb = ApplyFXAA(color.rgb, positionNDC, positionSS, _SourceSize, _BlitTexture, PaperWhite, OneOverPaperWhite);
  32. #else
  33. color.rgb = ApplyFXAA(color.rgb, positionNDC, positionSS, _SourceSize, _BlitTexture, PaperWhite, OneOverPaperWhite);
  34. #endif
  35. #endif
  36. #if _GAMMA_20 && !UNITY_COLORSPACE_GAMMA
  37. #ifdef HDR_INPUT
  38. // In HDR output mode, the colors are expressed in nits, which can go up to 10k nits.
  39. // We divide by the display max nits to get a max value closer to 1.0 but it could still be > 1.0.
  40. // Finally, use FastTonemap() to squash everything < 1.0.
  41. color = FastTonemap(color * OneOverPaperWhite);
  42. #endif
  43. // EASU expects perceptually encoded color data so either encode to gamma 2.0 here if the input
  44. // data is linear, or let it pass through unchanged if it's already gamma encoded.
  45. color = LinearToGamma20(color);
  46. #endif
  47. #if _ENABLE_ALPHA_OUTPUT
  48. // Alpha will lose precision and band due to low bits in alpha.
  49. // Should be fine for alpha test mask.
  50. // Or a simple 2-bit dither can be done.
  51. // uint2 b = positionSS & 1;
  52. // uint dp = b.y ? (b.x ? 1 : 3) : (b.x ? 2 : 0);
  53. // half d = ((dp / 3.0) - 0.5) * 0.25;
  54. // color.a += d;
  55. return color;
  56. #else
  57. return half4(color.rgb, 1.0);
  58. #endif
  59. }
  60. ENDHLSL
  61. ///
  62. /// Scaling Setup Shader
  63. ///
  64. /// This shader is used to perform any operations that need to place before image scaling occurs.
  65. /// It is not expected to be executed unless image scaling is active.
  66. ///
  67. /// Supported Operations:
  68. ///
  69. /// FXAA
  70. /// The FXAA shader does not support mismatched input and output dimensions so it must be run before any image
  71. /// scaling takes place.
  72. ///
  73. SubShader
  74. {
  75. Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
  76. LOD 100
  77. ZTest Always ZWrite Off Cull Off
  78. Pass
  79. {
  80. Name "ScalingSetup"
  81. HLSLPROGRAM
  82. #pragma vertex Vert
  83. #pragma fragment FragScalingSetup
  84. ENDHLSL
  85. }
  86. }
  87. }