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

Commit a471ecc

Browse files
authored
Merge branch 'v2' into v2-bloom
2 parents 9ac4dfd + 317608b commit a471ecc

24 files changed

+317
-145
lines changed

PostProcessing/Editor/Effects/ScreenSpaceReflectionsEditor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public sealed class ScreenSpaceReflectionsEditor : PostProcessEffectEditor<Scree
1212
SerializedParameterOverride m_Resolution;
1313
SerializedParameterOverride m_MaximumMarchDistance;
1414
SerializedParameterOverride m_DistanceFade;
15-
SerializedParameterOverride m_Attenuation;
15+
SerializedParameterOverride m_Vignette;
1616

1717
public override void OnEnable()
1818
{
@@ -22,7 +22,7 @@ public override void OnEnable()
2222
m_Resolution = FindParameterOverride(x => x.resolution);
2323
m_MaximumMarchDistance = FindParameterOverride(x => x.maximumMarchDistance);
2424
m_DistanceFade = FindParameterOverride(x => x.distanceFade);
25-
m_Attenuation = FindParameterOverride(x => x.attenuation);
25+
m_Vignette = FindParameterOverride(x => x.vignette);
2626
}
2727

2828
public override void OnInspectorGUI()
@@ -52,7 +52,7 @@ public override void OnInspectorGUI()
5252

5353
PropertyField(m_MaximumMarchDistance);
5454
PropertyField(m_DistanceFade);
55-
PropertyField(m_Attenuation);
55+
PropertyField(m_Vignette);
5656
}
5757
}
5858
}

PostProcessing/Editor/PostProcessLayerEditor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ public override void OnInspectorGUI()
116116

117117
var camera = m_Target.GetComponent<Camera>();
118118

119+
#if !UNITY_2017_2_OR_NEWER
120+
if (RuntimeUtilities.isSinglePassStereoSelected)
121+
EditorGUILayout.HelpBox("Unity 2017.2+ required for full Single-pass stereo rendering support.", MessageType.Warning);
122+
#endif
123+
119124
DoVolumeBlending();
120125
DoAntialiasing();
121126
DoFog(camera);
@@ -175,8 +180,10 @@ void DoAntialiasing()
175180

176181
if (m_AntialiasingMode.intValue == (int)PostProcessLayer.Antialiasing.TemporalAntialiasing)
177182
{
178-
if (RuntimeUtilities.isSinglePassStereoEnabled)
183+
#if !UNITY_2017_3_OR_NEWER
184+
if (RuntimeUtilities.isSinglePassStereoSelected)
179185
EditorGUILayout.HelpBox("TAA requires Unity 2017.3+ for Single-pass stereo rendering support.", MessageType.Warning);
186+
#endif
180187

181188
EditorGUILayout.PropertyField(m_TaaJitterSpread);
182189
EditorGUILayout.PropertyField(m_TaaStationaryBlending);
@@ -185,7 +192,7 @@ void DoAntialiasing()
185192
}
186193
else if (m_AntialiasingMode.intValue == (int)PostProcessLayer.Antialiasing.SubpixelMorphologicalAntialiasing)
187194
{
188-
if (RuntimeUtilities.isSinglePassStereoEnabled)
195+
if (RuntimeUtilities.isSinglePassStereoSelected)
189196
EditorGUILayout.HelpBox("SMAA doesn't work with Single-pass stereo rendering.", MessageType.Warning);
190197
}
191198
else if (m_AntialiasingMode.intValue == (int)PostProcessLayer.Antialiasing.FastApproximateAntialiasing)

PostProcessing/Editor/PostProcessProfileEditor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ void OnEnable()
1515

1616
void OnDisable()
1717
{
18-
m_EffectList.Clear();
18+
if (m_EffectList != null)
19+
m_EffectList.Clear();
1920
}
2021

2122
public override void OnInspectorGUI()

PostProcessing/Editor/PostProcessVolumeEditor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ void OnEnable()
3030

3131
void OnDisable()
3232
{
33-
m_EffectList.Clear();
33+
if (m_EffectList != null)
34+
m_EffectList.Clear();
3435
}
3536

3637
void RefreshEffectListEditor(PostProcessProfile asset)

PostProcessing/Runtime/Effects/AutoExposure.cs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,28 @@ public override bool IsEnabledAndSupported(PostProcessRenderContext context)
4646

4747
public sealed class AutoExposureRenderer : PostProcessEffectRenderer<AutoExposure>
4848
{
49-
readonly RenderTexture[] m_AutoExposurePool = new RenderTexture[2];
50-
int m_AutoExposurePingPong;
49+
const int k_NumEyes = 2;
50+
const int k_NumAutoExposureTextures = 2;
51+
52+
readonly RenderTexture[][] m_AutoExposurePool = new RenderTexture[k_NumEyes][];
53+
int[] m_AutoExposurePingPong = new int[k_NumEyes];
5154
RenderTexture m_CurrentAutoExposure;
5255

53-
void CheckTexture(int id)
56+
public AutoExposureRenderer()
57+
{
58+
for (int eye = 0; eye < k_NumEyes; eye++)
59+
{
60+
m_AutoExposurePool[eye] = new RenderTexture[k_NumAutoExposureTextures];
61+
m_AutoExposurePingPong[eye] = 0;
62+
}
63+
}
64+
65+
void CheckTexture(int eye, int id)
5466
{
55-
if (m_AutoExposurePool[id] == null || !m_AutoExposurePool[id].IsCreated())
67+
if (m_AutoExposurePool[eye][id] == null || !m_AutoExposurePool[eye][id].IsCreated())
5668
{
57-
m_AutoExposurePool[id] = new RenderTexture(1, 1, 0, RenderTextureFormat.RFloat);
58-
m_AutoExposurePool[id].Create();
69+
m_AutoExposurePool[eye][id] = new RenderTexture(1, 1, 0, RenderTextureFormat.RFloat);
70+
m_AutoExposurePool[eye][id].Create();
5971
}
6072
}
6173

@@ -68,8 +80,8 @@ public override void Render(PostProcessRenderContext context)
6880
sheet.ClearKeywords();
6981

7082
// Prepare autoExpo texture pool
71-
CheckTexture(0);
72-
CheckTexture(1);
83+
CheckTexture(context.xrActiveEye, 0);
84+
CheckTexture(context.xrActiveEye, 1);
7385

7486
// Make sure filtering values are correct to avoid apocalyptic consequences
7587
float lowPercent = settings.filtering.value.x;
@@ -95,21 +107,21 @@ public override void Render(PostProcessRenderContext context)
95107
{
96108
// We don't want eye adaptation when not in play mode because the GameView isn't
97109
// animated, thus making it harder to tweak. Just use the final audo exposure value.
98-
m_CurrentAutoExposure = m_AutoExposurePool[0];
110+
m_CurrentAutoExposure = m_AutoExposurePool[context.xrActiveEye][0];
99111
cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, m_CurrentAutoExposure, sheet, (int)EyeAdaptation.Fixed);
100112

101113
// Copy current exposure to the other pingpong target to avoid adapting from black
102-
RuntimeUtilities.CopyTexture(cmd, m_AutoExposurePool[0], m_AutoExposurePool[1]);
114+
RuntimeUtilities.CopyTexture(cmd, m_AutoExposurePool[context.xrActiveEye][0], m_AutoExposurePool[context.xrActiveEye][1]);
103115

104116
m_ResetHistory = false;
105117
}
106118
else
107119
{
108-
int pp = m_AutoExposurePingPong;
109-
var src = m_AutoExposurePool[++pp % 2];
110-
var dst = m_AutoExposurePool[++pp % 2];
120+
int pp = m_AutoExposurePingPong[context.xrActiveEye];
121+
var src = m_AutoExposurePool[context.xrActiveEye][++pp % 2];
122+
var dst = m_AutoExposurePool[context.xrActiveEye][++pp % 2];
111123
cmd.BlitFullscreenTriangle(src, dst, sheet, (int)settings.eyeAdaptation.value);
112-
m_AutoExposurePingPong = ++pp % 2;
124+
m_AutoExposurePingPong[context.xrActiveEye] = ++pp % 2;
113125
m_CurrentAutoExposure = dst;
114126
}
115127

@@ -121,8 +133,11 @@ public override void Render(PostProcessRenderContext context)
121133

122134
public override void Release()
123135
{
124-
foreach (var rt in m_AutoExposurePool)
125-
RuntimeUtilities.Destroy(rt);
136+
foreach (var rtEyeSet in m_AutoExposurePool)
137+
{
138+
foreach (var rt in rtEyeSet)
139+
RuntimeUtilities.Destroy(rt);
140+
}
126141
}
127142
}
128143
}

PostProcessing/Runtime/Effects/Bloom.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ public override void Render(PostProcessRenderContext context)
100100

101101
// Do bloom on a half-res buffer, full-res doesn't bring much and kills performances on
102102
// fillrate limited platforms
103-
int tw = Mathf.FloorToInt(context.width / (2f - rw));
104-
int th = Mathf.FloorToInt(context.height / (2f - rh));
103+
int tw = context.width / 2;
104+
int th = context.height / 2;
105105

106106
// Determine the iteration count
107-
int s = Mathf.Max(tw, th);
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);
@@ -129,8 +129,8 @@ public override void Render(PostProcessRenderContext context)
129129
? (int)Pass.Prefilter13 + qualityOffset
130130
: (int)Pass.Downsample13 + qualityOffset;
131131

132-
cmd.GetTemporaryRT(mipDown, tw, th, 0, FilterMode.Bilinear, context.sourceFormat);
133-
cmd.GetTemporaryRT(mipUp, tw, th, 0, FilterMode.Bilinear, context.sourceFormat);
132+
context.GetScreenSpaceTemporaryRT(cmd, mipDown, 0, context.sourceFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, tw, th);
133+
context.GetScreenSpaceTemporaryRT(cmd, mipUp, 0, context.sourceFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, tw, th);
134134
cmd.BlitFullscreenTriangle(lastDown, mipDown, sheet, pass);
135135

136136
lastDown = mipDown;
@@ -172,7 +172,7 @@ public override void Render(PostProcessRenderContext context)
172172
: settings.dirtTexture.value;
173173

174174
var dirtRatio = (float)dirtTexture.width / (float)dirtTexture.height;
175-
var screenRatio = (float)context.width / (float)context.height;
175+
var screenRatio = (float)context.screenWidth / (float)context.screenHeight;
176176
var dirtTileOffset = new Vector4(1f, 1f, 0f, 0f);
177177

178178
if (dirtRatio > screenRatio)

PostProcessing/Runtime/Effects/DepthOfField.cs

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,24 @@ enum Pass
5050

5151
// Ping-pong between two history textures as we can't read & write the same target in the
5252
// same pass
53-
readonly RenderTexture[] m_CoCHistoryTextures = new RenderTexture[2];
54-
int m_HistoryPingPong;
53+
const int k_NumEyes = 2;
54+
const int k_NumCoCHistoryTextures = 2;
55+
readonly RenderTexture[][] m_CoCHistoryTextures = new RenderTexture[k_NumEyes][];
56+
int[] m_HistoryPingPong = new int[k_NumEyes];
5557

5658
// Height of the 35mm full-frame format (36mm x 24mm)
5759
// TODO: Should be set by a physical camera
5860
const float k_FilmHeight = 0.024f;
5961

62+
public DepthOfFieldRenderer()
63+
{
64+
for (int eye = 0; eye < k_NumEyes; eye++)
65+
{
66+
m_CoCHistoryTextures[eye] = new RenderTexture[k_NumCoCHistoryTextures];
67+
m_HistoryPingPong[eye] = 0;
68+
}
69+
}
70+
6071
public override DepthTextureMode GetCameraFlags()
6172
{
6273
return DepthTextureMode.Depth;
@@ -84,19 +95,20 @@ float CalculateMaxCoCRadius(int screenHeight)
8495
return Mathf.Min(0.05f, radiusInPixels / screenHeight);
8596
}
8697

87-
RenderTexture CheckHistory(int id, int width, int height, RenderTextureFormat format)
98+
RenderTexture CheckHistory(int eye, int id, PostProcessRenderContext context, RenderTextureFormat format)
8899
{
89-
var rt = m_CoCHistoryTextures[id];
100+
var rt = m_CoCHistoryTextures[eye][id];
90101

91-
if (m_ResetHistory || rt == null || !rt.IsCreated() || rt.width != width || rt.height != height)
102+
if (m_ResetHistory || rt == null || !rt.IsCreated() || rt.width != context.width || rt.height != context.height)
92103
{
93104
RenderTexture.ReleaseTemporary(rt);
94105

95-
rt = RenderTexture.GetTemporary(width, height, 0, format);
96-
rt.name = "CoC History";
106+
// TODO: The CoCCalculation CoCTex uses RenderTextureReadWrite.Linear, why isn't this?
107+
rt = context.GetScreenSpaceTemporaryRT(0, format);
108+
rt.name = "CoC History, Eye: " + eye + ", ID: " + id;
97109
rt.filterMode = FilterMode.Bilinear;
98110
rt.Create();
99-
m_CoCHistoryTextures[id] = rt;
111+
m_CoCHistoryTextures[eye][id] = rt;
100112
}
101113

102114
return rt;
@@ -116,9 +128,9 @@ public override void Render(PostProcessRenderContext context)
116128
// Material setup
117129
var f = settings.focalLength.value / 1000f;
118130
var s1 = Mathf.Max(settings.focusDistance.value, f);
119-
var aspect = (float)context.width / (float)context.height;
131+
var aspect = (float)context.screenWidth / (float)context.screenHeight;
120132
var coeff = f * f / (settings.aperture.value * (s1 - f) * k_FilmHeight * 2);
121-
var maxCoC = CalculateMaxCoCRadius(context.height);
133+
var maxCoC = CalculateMaxCoCRadius(context.screenHeight);
122134

123135
var sheet = context.propertySheets.Get(context.resources.shaders.depthOfField);
124136
sheet.properties.Clear();
@@ -132,7 +144,7 @@ public override void Render(PostProcessRenderContext context)
132144
cmd.BeginSample("DepthOfField");
133145

134146
// CoC calculation pass
135-
cmd.GetTemporaryRT(ShaderIDs.CoCTex, context.width, context.height, 0, FilterMode.Bilinear, cocFormat, RenderTextureReadWrite.Linear);
147+
context.GetScreenSpaceTemporaryRT(cmd, ShaderIDs.CoCTex, 0, cocFormat, RenderTextureReadWrite.Linear);
136148
cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, ShaderIDs.CoCTex, sheet, (int)Pass.CoCCalculation);
137149

138150
// CoC temporal filter pass when TAA is enabled
@@ -144,22 +156,22 @@ public override void Render(PostProcessRenderContext context)
144156

145157
sheet.properties.SetVector(ShaderIDs.TaaParams, new Vector3(jitter.x, jitter.y, blend));
146158

147-
int pp = m_HistoryPingPong;
148-
var historyRead = CheckHistory(++pp % 2, context.width, context.height, cocFormat);
149-
var historyWrite = CheckHistory(++pp % 2, context.width, context.height, cocFormat);
150-
m_HistoryPingPong = ++pp % 2;
159+
int pp = m_HistoryPingPong[context.xrActiveEye];
160+
var historyRead = CheckHistory(context.xrActiveEye, ++pp % 2, context, cocFormat);
161+
var historyWrite = CheckHistory(context.xrActiveEye, ++pp % 2, context, cocFormat);
162+
m_HistoryPingPong[context.xrActiveEye] = ++pp % 2;
151163

152164
cmd.BlitFullscreenTriangle(historyRead, historyWrite, sheet, (int)Pass.CoCTemporalFilter);
153165
cmd.ReleaseTemporaryRT(ShaderIDs.CoCTex);
154166
cmd.SetGlobalTexture(ShaderIDs.CoCTex, historyWrite);
155167
}
156168

157169
// Downsampling and prefiltering pass
158-
cmd.GetTemporaryRT(ShaderIDs.DepthOfFieldTex, context.width / 2, context.height / 2, 0, FilterMode.Bilinear, colorFormat);
170+
context.GetScreenSpaceTemporaryRT(cmd, ShaderIDs.DepthOfFieldTex, 0, colorFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, context.width / 2, context.height / 2);
159171
cmd.BlitFullscreenTriangle(context.source, ShaderIDs.DepthOfFieldTex, sheet, (int)Pass.DownsampleAndPrefilter);
160172

161173
// Bokeh simulation pass
162-
cmd.GetTemporaryRT(ShaderIDs.DepthOfFieldTemp, context.width / 2, context.height / 2, 0, FilterMode.Bilinear, colorFormat);
174+
context.GetScreenSpaceTemporaryRT(cmd, ShaderIDs.DepthOfFieldTemp, 0, colorFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, context.width / 2, context.height / 2);
163175
cmd.BlitFullscreenTriangle(ShaderIDs.DepthOfFieldTex, ShaderIDs.DepthOfFieldTemp, sheet, (int)Pass.BokehSmallKernel + (int)settings.kernelSize.value);
164176

165177
// Postfilter pass
@@ -184,13 +196,16 @@ public override void Render(PostProcessRenderContext context)
184196

185197
public override void Release()
186198
{
187-
for (int i = 0; i < m_CoCHistoryTextures.Length; i++)
199+
for (int eye = 0; eye < k_NumEyes; eye++)
188200
{
189-
RenderTexture.ReleaseTemporary(m_CoCHistoryTextures[i]);
190-
m_CoCHistoryTextures[i] = null;
201+
for (int i = 0; i < m_CoCHistoryTextures[eye].Length; i++)
202+
{
203+
RenderTexture.ReleaseTemporary(m_CoCHistoryTextures[eye][i]);
204+
m_CoCHistoryTextures[eye][i] = null;
205+
}
206+
m_HistoryPingPong[eye] = 0;
191207
}
192208

193-
m_HistoryPingPong = 0;
194209
ResetHistory();
195210
}
196211
}

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.width / (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/ScalableAO.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ void DoLazyInitialization(PostProcessRenderContext context)
4949
if (m_Result == null || !m_Result.IsCreated())
5050
{
5151
// Initial allocation
52-
m_Result = new RenderTexture(context.width, context.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear)
53-
{
54-
hideFlags = HideFlags.DontSave,
55-
filterMode = FilterMode.Bilinear
56-
};
52+
m_Result = context.GetScreenSpaceTemporaryRT(0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
53+
m_Result.hideFlags = HideFlags.DontSave;
54+
m_Result.filterMode = FilterMode.Bilinear;
55+
5756
reset = true;
5857
}
5958
else if (m_Result.width != context.width || m_Result.height != context.height)
@@ -100,23 +99,23 @@ void Render(PostProcessRenderContext context, CommandBuffer cmd, int occlusionSo
10099
}
101100

102101
// Texture setup
103-
int tw = context.width;
104-
int th = context.height;
105102
int ts = downsampling ? 2 : 1;
106103
const RenderTextureFormat kFormat = RenderTextureFormat.ARGB32;
107104
const RenderTextureReadWrite kRWMode = RenderTextureReadWrite.Linear;
108105
const FilterMode kFilter = FilterMode.Bilinear;
109106

110107
// AO buffer
111108
var rtMask = ShaderIDs.OcclusionTexture1;
112-
cmd.GetTemporaryRT(rtMask, tw / ts, th / ts, 0, kFilter, kFormat, kRWMode);
109+
int scaledWidth = context.width / ts;
110+
int scaledHeight = context.height / ts;
111+
context.GetScreenSpaceTemporaryRT(cmd, rtMask, 0, kFormat, kRWMode, kFilter, scaledWidth, scaledHeight);
113112

114113
// AO estimation
115114
cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, rtMask, sheet, (int)Pass.OcclusionEstimationForward + occlusionSource);
116115

117116
// Blur buffer
118117
var rtBlur = ShaderIDs.OcclusionTexture2;
119-
cmd.GetTemporaryRT(rtBlur, tw, th, 0, kFilter, kFormat, kRWMode);
118+
context.GetScreenSpaceTemporaryRT(cmd, rtBlur, 0, kFormat, kRWMode, kFilter);
120119

121120
// Separable blur (horizontal pass)
122121
cmd.BlitFullscreenTriangle(rtMask, rtBlur, sheet, (int)Pass.HorizontalBlurForward + occlusionSource);

0 commit comments

Comments
 (0)