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

Commit 7d00cbb

Browse files
committed
Create and use screen w/h props in PostProcessRenderContext
There is a difference between the logical w/h of a screen and the texture size being allocated. So I started to formalize the difference with the addition of the screen size tracking.
1 parent 8942782 commit 7d00cbb

6 files changed

Lines changed: 21 additions & 19 deletions

File tree

PostProcessing/Runtime/Effects/Bloom.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public override void Render(PostProcessRenderContext context)
104104
int th = context.height / 2;
105105

106106
// Determine the iteration count
107-
int s = Mathf.Max((Mathf.FloorToInt(context.xrSingleEyeWidth / (2f - rw))), (Mathf.FloorToInt(context.height / (2f - rh))));
107+
int s = Mathf.Max((Mathf.FloorToInt(context.screenWidth / (2f - rw))), (Mathf.FloorToInt(context.screenHeight / (2f - rh))));
108108
float logs = Mathf.Log(s, 2f) + Mathf.Min(settings.diffusion.value, 10f) - 10f;
109109
int logs_i = Mathf.FloorToInt(logs);
110110
int iterations = Mathf.Clamp(logs_i, 1, k_MaxPyramidSize);
@@ -173,7 +173,7 @@ public override void Render(PostProcessRenderContext context)
173173
: settings.dirtTexture.value;
174174

175175
var dirtRatio = (float)dirtTexture.width / (float)dirtTexture.height;
176-
var screenRatio = (float)context.xrSingleEyeWidth / (float)context.height;
176+
var screenRatio = (float)context.screenWidth / (float)context.screenHeight;
177177
var dirtTileOffset = new Vector4(1f, 1f, 0f, 0f);
178178

179179
if (dirtRatio > screenRatio)

PostProcessing/Runtime/Effects/DepthOfField.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ public override void Render(PostProcessRenderContext context)
128128
// Material setup
129129
var f = settings.focalLength.value / 1000f;
130130
var s1 = Mathf.Max(settings.focusDistance.value, f);
131-
var aspect = (float)context.xrSingleEyeWidth / (float)context.height; // TODO: this might change if we get rid of singleEyeWidth
131+
var aspect = (float)context.screenWidth / (float)context.screenHeight;
132132
var coeff = f * f / (settings.aperture.value * (s1 - f) * k_FilmHeight * 2);
133-
var maxCoC = CalculateMaxCoCRadius(context.height);
133+
var maxCoC = CalculateMaxCoCRadius(context.screenHeight);
134134

135135
var sheet = context.propertySheets.Get(context.resources.shaders.depthOfField);
136136
sheet.properties.Clear();

PostProcessing/Runtime/Effects/Dithering.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ internal void Render(PostProcessRenderContext context)
3030

3131
uberSheet.properties.SetTexture(ShaderIDs.DitheringTex, noiseTex);
3232
uberSheet.properties.SetVector(ShaderIDs.Dithering_Coords, new Vector4(
33-
(float)context.xrSingleEyeWidth / (float)noiseTex.width,
34-
(float)context.height / (float)noiseTex.height,
33+
(float)context.screenWidth / (float)noiseTex.width,
34+
(float)context.screenHeight / (float)noiseTex.height,
3535
rndOffsetX,
3636
rndOffsetY
3737
));

PostProcessing/Runtime/Effects/TemporalAntialiasing.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void ConfigureStereoJitteredProjectionMatrices(PostProcessRenderContext c
130130

131131
// jitter has to be scaled for the actual eye texture size, not just the intermediate texture size
132132
// which could be double-wide in certain stereo rendering scenarios
133-
jitter = new Vector2(jitter.x / context.xrSingleEyeWidth, jitter.y / context.height);
133+
jitter = new Vector2(jitter.x / context.screenWidth, jitter.y / context.screenHeight);
134134
camera.useJitteredProjectionMatrixForTransparentRendering = false;
135135
#endif
136136
}

PostProcessing/Runtime/PostProcessRenderContext.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public Camera camera
4343
if (camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right)
4444
xrActiveEye = (int)Camera.StereoscopicEye.Right;
4545

46-
xrSingleEyeWidth = XRSettings.eyeTextureWidth;
47-
xrSingleEyeHeight = XRSettings.eyeTextureHeight;
46+
screenWidth = XRSettings.eyeTextureWidth;
47+
screenHeight = XRSettings.eyeTextureHeight;
4848
}
4949
else
5050
{
@@ -55,8 +55,8 @@ public Camera camera
5555
m_sourceDescriptor.width = width;
5656
m_sourceDescriptor.height = height;
5757
#endif
58-
xrSingleEyeWidth = width;
59-
xrSingleEyeHeight = height;
58+
screenWidth = width;
59+
screenHeight = height;
6060
}
6161
}
6262
}
@@ -102,6 +102,9 @@ public Camera camera
102102
// Current camera height in pixels
103103
public int height { get; private set; }
104104

105+
// TODO: Change w/h name to texture w/h in order to make
106+
// size usages explicit
107+
105108
#if UNITY_2017_2_OR_NEWER
106109
private RenderTextureDescriptor m_sourceDescriptor;
107110
private RenderTextureDescriptor GetDescriptor(int depthBufferBits = 0, RenderTextureFormat colorFormat = RenderTextureFormat.Default, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default)
@@ -179,11 +182,10 @@ public RenderTexture GetScreenSpaceTemporaryRT(int depthBufferBits = 0, RenderTe
179182
// Current active rendering eye (for XR)
180183
public int xrActiveEye { get; private set; }
181184

182-
// Current single eye width in pixels (for XR)
183-
public int xrSingleEyeWidth { get; private set; }
185+
// Pixel dimensions of logical screen size
186+
public int screenWidth { get; private set; }
184187

185-
// Current single eye height in pixels (for XR)
186-
public int xrSingleEyeHeight { get; private set; }
188+
public int screenHeight { get; private set; }
187189

188190
// Are we currently rendering in the scene view?
189191
public bool isSceneView { get; internal set; }
@@ -206,8 +208,8 @@ public void Reset()
206208
#endif
207209

208210
xrActiveEye = (int)Camera.StereoscopicEye.Left;
209-
xrSingleEyeWidth = 0;
210-
xrSingleEyeHeight = 0;
211+
screenWidth = 0;
212+
screenHeight = 0;
211213

212214
command = null;
213215
source = 0;

PostProcessing/Runtime/Utils/RuntimeUtilities.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ public static Matrix4x4 GenerateJitteredProjectionMatrixFromOriginal(PostProcess
425425
float vertFov = Math.Abs(planes.top) + Math.Abs(planes.bottom);
426426
float horizFov = Math.Abs(planes.left) + Math.Abs(planes.right);
427427

428-
var planeJitter = new Vector2(jitter.x * horizFov / context.xrSingleEyeWidth,
429-
jitter.y * vertFov / context.height);
428+
var planeJitter = new Vector2(jitter.x * horizFov / context.screenWidth,
429+
jitter.y * vertFov / context.screenHeight);
430430

431431
planes.left += planeJitter.x;
432432
planes.right += planeJitter.x;

0 commit comments

Comments
 (0)