No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XRMirrorView.hlsl 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  2. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  3. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
  4. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/HDROutput.hlsl"
  5. #if SRC_TEXTURE2D_X_ARRAY
  6. TEXTURE2D_ARRAY(_SourceTex);
  7. #else
  8. TEXTURE2D(_SourceTex);
  9. #endif
  10. uniform uint _SourceTexArraySlice;
  11. uniform uint _SRGBRead;
  12. uniform uint _SRGBWrite;
  13. uniform float _MaxNits;
  14. uniform float _SourceMaxNits;
  15. uniform int _SourceHDREncoding;
  16. uniform float4x4 _ColorTransform;
  17. struct Attributes
  18. {
  19. uint vertexID : SV_VertexID;
  20. };
  21. struct Varyings
  22. {
  23. float4 positionCS : SV_POSITION;
  24. float2 texcoord : TEXCOORD0;
  25. };
  26. Varyings VertQuad(Attributes input)
  27. {
  28. Varyings output;
  29. output.positionCS = GetQuadVertexPosition(input.vertexID) * float4(_ScaleBiasRt.x, _ScaleBiasRt.y, 1, 1) + float4(_ScaleBiasRt.z, _ScaleBiasRt.w, 0, 0);
  30. output.positionCS.xy = output.positionCS.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f); //convert to -1..1
  31. //Using temporary as writing to global _ScaleBias.w is prohibited when compiling with DXC
  32. float scaleBiasW = _ScaleBias.w;
  33. #if UNITY_UV_STARTS_AT_TOP
  34. // Unity viewport convention is bottom left as origin. Adjust Scalebias to read the correct region.
  35. scaleBiasW = 1 - _ScaleBias.w - _ScaleBias.y;
  36. #endif
  37. output.texcoord = GetQuadTexCoord(input.vertexID) * _ScaleBias.xy + float2(_ScaleBias.z, scaleBiasW);
  38. return output;
  39. }
  40. float4 FragBilinear(Varyings input) : SV_Target
  41. {
  42. float4 outColor;
  43. float2 uv = input.texcoord.xy;
  44. #if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  45. UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  46. {
  47. // We use stereo eye index to sample the correct slice when resolving foveated targets.
  48. // Since MirrorView is not a stereo shader we have to populate unity_StereoEyeIndex ourselves.
  49. unity_StereoEyeIndex = _SourceTexArraySlice;
  50. uv = RemapFoveatedRenderingLinearToNonUniform(input.texcoord.xy);
  51. }
  52. #endif // SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER
  53. #if SRC_TEXTURE2D_X_ARRAY
  54. outColor = SAMPLE_TEXTURE2D_ARRAY(_SourceTex, sampler_LinearClamp, uv, _SourceTexArraySlice);
  55. #else
  56. outColor = SAMPLE_TEXTURE2D(_SourceTex, sampler_LinearClamp, uv);
  57. #endif
  58. #if HDR_COLORSPACE_CONVERSION_AND_ENCODING
  59. // Currently this will case any values in the source color space that go outside of the destination to most likley get clamped
  60. // the same will be true for any luminance values in the source range outside the destination range. This will lead to hue shifts
  61. // and over saturated display, e.g. a red value of (1000, 100, 100) if converted to SDR would get clamped at (80,80,80) generating white.
  62. // TODO: The solution here is to add a hue preserving tonemap operator in as part of the conversion process but this will add quite a bit of extra expense.
  63. // Convert the encoded output image into linear
  64. outColor.rgb = InverseOETF(outColor.rgb, _SourceMaxNits, _SourceHDREncoding);
  65. // Now we need to convert the color space from source to destination;
  66. outColor.rgb = mul((float3x3)_ColorTransform, outColor.rgb);
  67. // Convert the linear image into the correct encoded output for the display
  68. outColor.rgb = OETF(outColor.rgb, _MaxNits);
  69. #else
  70. if (_SRGBRead && _SRGBWrite)
  71. return outColor;
  72. if (_SRGBRead)
  73. outColor = SRGBToLinear(outColor);
  74. if (_SRGBWrite)
  75. outColor = LinearToSRGB(outColor);
  76. #endif
  77. return outColor;
  78. }