Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 4969e03

Browse files
committed
Support RenderViewportScale
Traditional screen-space RenderViewportScale support is done through _MainTex_ST. However, we don't use Graphics.Blit or CommandBuffer.Blit for most blits, so we can't rely on that infrastructure. Instead, we can wrap our usage of unity_StereoScaleOffset/TransformStereoScreenSpaceTex with an RVS scaler. This works pretty well, and makes the RenderViewportScale management very explicit and obvious. There might be an issue with WindowsMR, as it doesn't guarantee the RenderViewportScale value will actually be used (yeah...), but we'll cross that bridge when we get there.
1 parent fb9d5d4 commit 4969e03

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

PostProcessing/Runtime/PostProcessLayer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,14 @@ void OnPreCull()
273273
m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
274274

275275
if (XRSettings.isDeviceActive)
276+
{
276277
m_Camera.ResetStereoProjectionMatrices();
278+
Shader.SetGlobalFloat("rvsGlobal", XRSettings.renderViewportScale);
279+
}
280+
else
281+
{
282+
Shader.SetGlobalFloat("rvsGlobal", 1.0f);
283+
}
277284

278285
BuildCommandBuffers();
279286
}

PostProcessing/Shaders/Builtins/CopyStd.shader

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ Shader "Hidden/PostProcessing/CopyStd"
3333
{
3434
Varyings o;
3535
o.vertex = float4(v.vertex.xy * 2.0 - 1.0, 0.0, 1.0);
36-
o.texcoord = v.texcoord * _MainTex_ST.xy + _MainTex_ST.zw; // We need this for VR
36+
o.texcoord = v.texcoord;
3737

3838
#if UNITY_UV_STARTS_AT_TOP
3939
o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
4040
#endif
4141

42+
o.texcoord = o.texcoord * _MainTex_ST.xy + _MainTex_ST.zw; // We need this for VR
43+
44+
4245
return o;
4346
}
4447

PostProcessing/Shaders/xRLib.hlsl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ CBUFFER_START(UnityStereoEyeIndex)
2424
CBUFFER_END
2525
#endif
2626

27+
float rvsGlobal;
28+
2729
float2 UnityStereoScreenSpaceUVAdjust(float2 uv, float4 scaleAndOffset)
2830
{
2931
return uv.xy * scaleAndOffset.xy + scaleAndOffset.zw;
@@ -38,6 +40,7 @@ float4 UnityStereoScreenSpaceUVAdjust(float4 uv, float4 scaleAndOffset)
3840
float2 TransformStereoScreenSpaceTex(float2 uv, float w)
3941
{
4042
float4 scaleOffset = unity_StereoScaleOffset[unity_StereoEyeIndex];
43+
scaleOffset.xy *= rvsGlobal;
4144
return uv.xy * scaleOffset.xy + scaleOffset.zw * w;
4245
}
4346

@@ -58,11 +61,20 @@ float2 UnityStereoClampScaleOffset(float2 uv, float4 scaleAndOffset)
5861

5962
float2 UnityStereoClamp(float2 uv)
6063
{
64+
// TODO: Factor in RVS?
6165
return UnityStereoClampScaleOffset(uv, unity_StereoScaleOffset[unity_StereoEyeIndex]);
6266
}
6367
#else
64-
#define TransformStereoScreenSpaceTex(uv, w) uv
65-
#define UnityStereoTransformScreenSpaceTex(uv) uv
68+
float2 TransformStereoScreenSpaceTex(float2 uv, float w)
69+
{
70+
return uv * rvsGlobal;
71+
}
72+
73+
float2 UnityStereoTransformScreenSpaceTex(float2 uv)
74+
{
75+
return TransformStereoScreenSpaceTex(saturate(uv), 1.0);
76+
}
77+
6678
#define UnityStereoClampScaleOffset(uv, scaleAndOffset) uv
6779
#define UnityStereoClamp(uv) uv
6880
#endif

0 commit comments

Comments
 (0)