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

Commit fb9d5d4

Browse files
committed
Merge remote-tracking branch 'origin/v2' into xr_update
2 parents 76dd39b + 354ff17 commit fb9d5d4

6 files changed

Lines changed: 117 additions & 107 deletions

File tree

PostProcessing/Runtime/Effects/ScreenSpaceReflections.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class QualityPreset
6969
public ScreenSpaceReflectionResolution downsampling;
7070
}
7171

72-
QualityPreset[] m_Presets =
72+
readonly QualityPreset[] m_Presets =
7373
{
7474
new QualityPreset { maximumIterationCount = 10, thickness = 32, downsampling = ScreenSpaceReflectionResolution.Downsampled }, // Lower
7575
new QualityPreset { maximumIterationCount = 16, thickness = 32, downsampling = ScreenSpaceReflectionResolution.Downsampled }, // Low
@@ -143,13 +143,6 @@ public override void Render(PostProcessRenderContext context)
143143
lodCount = Mathf.Min(lodCount, kMaxLods);
144144

145145
CheckRT(ref m_Resolve, size, size, context.sourceFormat, FilterMode.Trilinear, true);
146-
CheckRT(ref m_History, size, size, context.sourceFormat, FilterMode.Bilinear, false);
147-
148-
if (m_ResetHistory)
149-
{
150-
context.command.BlitFullscreenTriangle(context.source, m_History);
151-
m_ResetHistory = false;
152-
}
153146

154147
var noiseTex = context.resources.blueNoise256[0];
155148
var sheet = context.propertySheets.Get(context.resources.shaders.screenSpaceReflections);
@@ -174,16 +167,32 @@ public override void Render(PostProcessRenderContext context)
174167
cmd.GetTemporaryRT(ShaderIDs.Test, size, size, 0, FilterMode.Point, context.sourceFormat);
175168
cmd.BlitFullscreenTriangle(context.source, ShaderIDs.Test, sheet, (int)Pass.Test);
176169

177-
cmd.GetTemporaryRT(ShaderIDs.SSRResolveTemp, size, size, 0, FilterMode.Bilinear, context.sourceFormat);
178-
cmd.BlitFullscreenTriangle(context.source, ShaderIDs.SSRResolveTemp, sheet, (int)Pass.Resolve);
170+
if (context.isSceneView)
171+
{
172+
cmd.BlitFullscreenTriangle(context.source, m_Resolve, sheet, (int)Pass.Resolve);
173+
}
174+
else
175+
{
176+
CheckRT(ref m_History, size, size, context.sourceFormat, FilterMode.Bilinear, false);
179177

180-
sheet.properties.SetTexture(ShaderIDs.History, m_History);
181-
cmd.BlitFullscreenTriangle(ShaderIDs.SSRResolveTemp, m_Resolve, sheet, (int)Pass.Reproject);
178+
if (m_ResetHistory)
179+
{
180+
context.command.BlitFullscreenTriangle(context.source, m_History);
181+
m_ResetHistory = false;
182+
}
182183

183-
cmd.ReleaseTemporaryRT(ShaderIDs.Test);
184-
cmd.ReleaseTemporaryRT(ShaderIDs.SSRResolveTemp);
184+
cmd.GetTemporaryRT(ShaderIDs.SSRResolveTemp, size, size, 0, FilterMode.Bilinear, context.sourceFormat);
185+
cmd.BlitFullscreenTriangle(context.source, ShaderIDs.SSRResolveTemp, sheet, (int)Pass.Resolve);
186+
187+
sheet.properties.SetTexture(ShaderIDs.History, m_History);
188+
cmd.BlitFullscreenTriangle(ShaderIDs.SSRResolveTemp, m_Resolve, sheet, (int)Pass.Reproject);
189+
190+
cmd.CopyTexture(m_Resolve, 0, 0, m_History, 0, 0);
185191

186-
cmd.CopyTexture(m_Resolve, 0, 0, m_History, 0, 0);
192+
cmd.ReleaseTemporaryRT(ShaderIDs.SSRResolveTemp);
193+
}
194+
195+
cmd.ReleaseTemporaryRT(ShaderIDs.Test);
187196

188197
// Pre-cache mipmaps ids
189198
if (m_MipIDs == null || m_MipIDs.Length == 0)

PostProcessing/Runtime/PostProcessRenderContext.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Collections.Generic;
2+
13
namespace UnityEngine.Rendering.PostProcessing
24
{
35
#if UNITY_2017_2_OR_NEWER
@@ -82,10 +84,9 @@ public Camera camera
8284
// Property sheet factory handled by the currently active PostProcessLayer
8385
public PropertySheetFactory propertySheets { get; internal set; }
8486

85-
// Custom user data object (unused by builtin effects, feel free to store whatever you want
86-
// in this object)
87-
// TODO: Make this more useful
88-
public object userData { get; set; }
87+
// Custom user data objects (unused by builtin effects, feel free to store whatever you want
88+
// in this dictionary)
89+
public Dictionary<string, object> userData { get; private set; }
8990

9091
// Reference to the internal debug layer
9192
public PostProcessDebugLayer debugLayer { get; internal set; }
@@ -169,6 +170,11 @@ public void Reset()
169170
autoExposureTexture = null;
170171
logLut = null;
171172
autoExposure = null;
173+
174+
if (userData == null)
175+
userData = new Dictionary<string, object>();
176+
177+
userData.Clear();
172178
}
173179

174180
// Checks if TAA is enabled & supported

PostProcessing/Runtime/Utils/RuntimeUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public static bool isSinglePassStereoEnabled
237237
&& UnityEditor.PlayerSettings.stereoRenderingPath == UnityEditor.StereoRenderingPath.SinglePass
238238
&& Application.isPlaying;
239239
#elif UNITY_2017_2_OR_NEWER
240-
return UnityEngine.XRSettings.eyeTextureDesc.vrUsage == VRTextureUsage.TwoEyes;
240+
return UnityEngine.XR.XRSettings.eyeTextureDesc.vrUsage == VRTextureUsage.TwoEyes;
241241
#else
242242
return false;
243243
#endif

PostProcessing/Runtime/Utils/TextureFormatUtilities.cs

Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,87 @@
11
using System;
2+
using System.Collections.Generic;
3+
using UnityEngine.Assertions;
24

35
namespace UnityEngine.Rendering.PostProcessing
46
{
57
// Temporary code dump until the texture format refactor goes into trunk...
68
public static class TextureFormatUtilities
79
{
10+
static Dictionary<TextureFormat, RenderTextureFormat> m_FormatMap;
11+
12+
static TextureFormatUtilities()
13+
{
14+
m_FormatMap = new Dictionary<TextureFormat, RenderTextureFormat>
15+
{
16+
{ TextureFormat.Alpha8, RenderTextureFormat.ARGB32 },
17+
{ TextureFormat.ARGB4444, RenderTextureFormat.ARGB4444 },
18+
{ TextureFormat.RGB24, RenderTextureFormat.ARGB32 },
19+
{ TextureFormat.RGBA32, RenderTextureFormat.ARGB32 },
20+
{ TextureFormat.ARGB32, RenderTextureFormat.ARGB32 },
21+
{ TextureFormat.RGB565, RenderTextureFormat.RGB565 },
22+
{ TextureFormat.R16, RenderTextureFormat.RHalf },
23+
{ TextureFormat.DXT1, RenderTextureFormat.ARGB32 },
24+
{ TextureFormat.DXT5, RenderTextureFormat.ARGB32 },
25+
{ TextureFormat.RGBA4444, RenderTextureFormat.ARGB4444 },
26+
{ TextureFormat.BGRA32, RenderTextureFormat.ARGB32 },
27+
{ TextureFormat.RHalf, RenderTextureFormat.RHalf },
28+
{ TextureFormat.RGHalf, RenderTextureFormat.RGHalf },
29+
{ TextureFormat.RGBAHalf, RenderTextureFormat.ARGBHalf },
30+
{ TextureFormat.RFloat, RenderTextureFormat.RFloat },
31+
{ TextureFormat.RGFloat, RenderTextureFormat.RGFloat },
32+
{ TextureFormat.RGBAFloat, RenderTextureFormat.ARGBFloat },
33+
{ TextureFormat.RGB9e5Float, RenderTextureFormat.ARGBHalf },
34+
{ TextureFormat.BC4, RenderTextureFormat.R8 },
35+
{ TextureFormat.BC5, RenderTextureFormat.RGHalf },
36+
{ TextureFormat.BC6H, RenderTextureFormat.ARGBHalf },
37+
{ TextureFormat.BC7, RenderTextureFormat.ARGB32 },
38+
#if !UNITY_IOS
39+
{ TextureFormat.DXT1Crunched, RenderTextureFormat.ARGB32 },
40+
{ TextureFormat.DXT5Crunched, RenderTextureFormat.ARGB32 },
41+
#endif
42+
{ TextureFormat.PVRTC_RGB2, RenderTextureFormat.ARGB32 },
43+
{ TextureFormat.PVRTC_RGBA2, RenderTextureFormat.ARGB32 },
44+
{ TextureFormat.PVRTC_RGB4, RenderTextureFormat.ARGB32 },
45+
{ TextureFormat.PVRTC_RGBA4, RenderTextureFormat.ARGB32 },
46+
{ TextureFormat.ETC_RGB4, RenderTextureFormat.ARGB32 },
47+
{ TextureFormat.ATC_RGB4, RenderTextureFormat.ARGB32 },
48+
{ TextureFormat.ATC_RGBA8, RenderTextureFormat.ARGB32 },
49+
{ TextureFormat.ETC2_RGB, RenderTextureFormat.ARGB32 },
50+
{ TextureFormat.ETC2_RGBA1, RenderTextureFormat.ARGB32 },
51+
{ TextureFormat.ETC2_RGBA8, RenderTextureFormat.ARGB32 },
52+
{ TextureFormat.ASTC_RGB_4x4, RenderTextureFormat.ARGB32 },
53+
{ TextureFormat.ASTC_RGB_5x5, RenderTextureFormat.ARGB32 },
54+
{ TextureFormat.ASTC_RGB_6x6, RenderTextureFormat.ARGB32 },
55+
{ TextureFormat.ASTC_RGB_8x8, RenderTextureFormat.ARGB32 },
56+
{ TextureFormat.ASTC_RGB_10x10, RenderTextureFormat.ARGB32 },
57+
{ TextureFormat.ASTC_RGB_12x12, RenderTextureFormat.ARGB32 },
58+
{ TextureFormat.ASTC_RGBA_4x4, RenderTextureFormat.ARGB32 },
59+
{ TextureFormat.ASTC_RGBA_5x5, RenderTextureFormat.ARGB32 },
60+
{ TextureFormat.ASTC_RGBA_6x6, RenderTextureFormat.ARGB32 },
61+
{ TextureFormat.ASTC_RGBA_8x8, RenderTextureFormat.ARGB32 },
62+
{ TextureFormat.ASTC_RGBA_10x10, RenderTextureFormat.ARGB32 },
63+
{ TextureFormat.ASTC_RGBA_12x12, RenderTextureFormat.ARGB32 },
64+
{ TextureFormat.ETC_RGB4_3DS, RenderTextureFormat.ARGB32 },
65+
{ TextureFormat.ETC_RGBA8_3DS, RenderTextureFormat.ARGB32 }
66+
};
67+
}
68+
869
public static RenderTextureFormat GetUncompressedRenderTextureFormat(Texture texture)
970
{
71+
Assert.IsNotNull(texture);
72+
1073
if (texture is RenderTexture)
1174
return (texture as RenderTexture).format;
1275

1376
if (texture is Texture2D)
1477
{
15-
switch ((texture as Texture2D).format)
16-
{
17-
case TextureFormat.Alpha8: return RenderTextureFormat.ARGB32;
18-
case TextureFormat.ARGB4444: return RenderTextureFormat.ARGB4444;
19-
case TextureFormat.RGB24: return RenderTextureFormat.ARGB32;
20-
case TextureFormat.RGBA32: return RenderTextureFormat.ARGB32;
21-
case TextureFormat.ARGB32: return RenderTextureFormat.ARGB32;
22-
case TextureFormat.RGB565: return RenderTextureFormat.RGB565;
23-
case TextureFormat.R16: return RenderTextureFormat.RHalf; // ???
24-
case TextureFormat.DXT1: return RenderTextureFormat.ARGB32;
25-
case TextureFormat.DXT5: return RenderTextureFormat.ARGB32;
26-
case TextureFormat.RGBA4444: return RenderTextureFormat.ARGB4444;
27-
case TextureFormat.BGRA32: return RenderTextureFormat.ARGB32;
28-
case TextureFormat.RHalf: return RenderTextureFormat.RHalf;
29-
case TextureFormat.RGHalf: return RenderTextureFormat.RGHalf;
30-
case TextureFormat.RGBAHalf: return RenderTextureFormat.ARGBHalf;
31-
case TextureFormat.RFloat: return RenderTextureFormat.RFloat;
32-
case TextureFormat.RGFloat: return RenderTextureFormat.RGFloat;
33-
case TextureFormat.RGBAFloat: return RenderTextureFormat.ARGBFloat;
34-
case TextureFormat.RGB9e5Float: return RenderTextureFormat.ARGBHalf;
35-
case TextureFormat.BC4: return RenderTextureFormat.R8;
36-
case TextureFormat.BC5: return RenderTextureFormat.RGHalf;
37-
case TextureFormat.BC6H: return RenderTextureFormat.ARGBHalf;
38-
case TextureFormat.BC7: return RenderTextureFormat.ARGB32;
39-
#if !UNITY_IOS
40-
case TextureFormat.DXT1Crunched: return RenderTextureFormat.ARGB32;
41-
case TextureFormat.DXT5Crunched: return RenderTextureFormat.ARGB32;
42-
#endif
43-
case TextureFormat.PVRTC_RGB2: return RenderTextureFormat.ARGB32;
44-
case TextureFormat.PVRTC_RGBA2: return RenderTextureFormat.ARGB32;
45-
case TextureFormat.PVRTC_RGB4: return RenderTextureFormat.ARGB32;
46-
case TextureFormat.PVRTC_RGBA4: return RenderTextureFormat.ARGB32;
47-
case TextureFormat.ETC_RGB4: return RenderTextureFormat.ARGB32;
48-
case TextureFormat.ATC_RGB4: return RenderTextureFormat.ARGB32;
49-
case TextureFormat.ATC_RGBA8: return RenderTextureFormat.ARGB32;
50-
case TextureFormat.ETC2_RGB: return RenderTextureFormat.ARGB32;
51-
case TextureFormat.ETC2_RGBA1: return RenderTextureFormat.ARGB32;
52-
case TextureFormat.ETC2_RGBA8: return RenderTextureFormat.ARGB32;
53-
case TextureFormat.ASTC_RGB_4x4: return RenderTextureFormat.ARGB32;
54-
case TextureFormat.ASTC_RGB_5x5: return RenderTextureFormat.ARGB32;
55-
case TextureFormat.ASTC_RGB_6x6: return RenderTextureFormat.ARGB32;
56-
case TextureFormat.ASTC_RGB_8x8: return RenderTextureFormat.ARGB32;
57-
case TextureFormat.ASTC_RGB_10x10: return RenderTextureFormat.ARGB32;
58-
case TextureFormat.ASTC_RGB_12x12: return RenderTextureFormat.ARGB32;
59-
case TextureFormat.ASTC_RGBA_4x4: return RenderTextureFormat.ARGB32;
60-
case TextureFormat.ASTC_RGBA_5x5: return RenderTextureFormat.ARGB32;
61-
case TextureFormat.ASTC_RGBA_6x6: return RenderTextureFormat.ARGB32;
62-
case TextureFormat.ASTC_RGBA_8x8: return RenderTextureFormat.ARGB32;
63-
case TextureFormat.ASTC_RGBA_10x10: return RenderTextureFormat.ARGB32;
64-
case TextureFormat.ASTC_RGBA_12x12: return RenderTextureFormat.ARGB32;
65-
case TextureFormat.ETC_RGB4_3DS: return RenderTextureFormat.ARGB32;
66-
case TextureFormat.ETC_RGBA8_3DS: return RenderTextureFormat.ARGB32;
67-
case TextureFormat.EAC_R: goto default;
68-
case TextureFormat.EAC_R_SIGNED: goto default;
69-
case TextureFormat.EAC_RG: goto default;
70-
case TextureFormat.EAC_RG_SIGNED: goto default;
71-
case TextureFormat.YUY2: goto default;
72-
default:
73-
throw new NotSupportedException("Texture format not supported");
74-
}
78+
var inFormat = ((Texture2D)texture).format;
79+
RenderTextureFormat outFormat;
80+
81+
if (!m_FormatMap.TryGetValue(inFormat, out outFormat))
82+
throw new NotSupportedException("Texture format not supported");
83+
84+
return outFormat;
7585
}
7686

7787
return RenderTextureFormat.Default;

PostProcessing/Shaders/Builtins/MultiScaleVO.shader

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,6 @@ Shader "Hidden/PostProcessing/MultiScaleVO"
99
TEXTURE2D_SAMPLER2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture);
1010
float3 _AOColor;
1111

12-
VaryingsDefault Vert(AttributesDefault v)
13-
{
14-
VaryingsDefault o;
15-
o.vertex = float4(v.vertex.xy, 0.0, 1.0);
16-
o.texcoord = TransformTriangleVertexToUV(v.vertex.xy);
17-
18-
#if UNITY_UV_STARTS_AT_TOP
19-
o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
20-
#endif
21-
22-
o.texcoord = TransformStereoScreenSpaceTex(o.texcoord, 1);
23-
return o;
24-
}
25-
2612
ENDHLSL
2713

2814
SubShader
@@ -34,12 +20,12 @@ Shader "Hidden/PostProcessing/MultiScaleVO"
3420
{
3521
HLSLPROGRAM
3622

37-
#pragma vertex Vert
23+
#pragma vertex VertDefault
3824
#pragma fragment Frag
3925

4026
float4 Frag(VaryingsDefault i) : SV_Target
4127
{
42-
return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoord);
28+
return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo);
4329
}
4430

4531
ENDHLSL
@@ -52,7 +38,7 @@ Shader "Hidden/PostProcessing/MultiScaleVO"
5238

5339
HLSLPROGRAM
5440

55-
#pragma vertex Vert
41+
#pragma vertex VertDefault
5642
#pragma fragment Frag
5743

5844
struct Output
@@ -63,7 +49,7 @@ Shader "Hidden/PostProcessing/MultiScaleVO"
6349

6450
Output Frag(VaryingsDefault i)
6551
{
66-
float ao = 1.0 - SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, i.texcoord).r;
52+
float ao = 1.0 - SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, i.texcoordStereo).r;
6753
Output o;
6854
o.gbuffer0 = float4(0.0, 0.0, 0.0, ao);
6955
o.gbuffer3 = float4(ao * _AOColor, 0.0);
@@ -82,17 +68,16 @@ Shader "Hidden/PostProcessing/MultiScaleVO"
8268

8369
#pragma multi_compile _ APPLY_FORWARD_FOG
8470
#pragma multi_compile _ FOG_LINEAR FOG_EXP FOG_EXP2
85-
#pragma vertex Vert
71+
#pragma vertex VertDefault
8672
#pragma fragment Frag
8773

8874
float4 Frag(VaryingsDefault i) : SV_Target
8975
{
90-
float2 texcoord = TransformStereoScreenSpaceTex(i.texcoord, 1);
91-
half ao = 1.0 - SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, texcoord).r;
76+
half ao = 1.0 - SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, i.texcoordStereo).r;
9277

9378
// Apply fog when enabled (forward-only)
9479
#if (APPLY_FORWARD_FOG)
95-
float d = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, texcoord));
80+
float d = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo));
9681
d = ComputeFogDistance(d);
9782
ao *= ComputeFog(d);
9883
#endif
@@ -108,12 +93,12 @@ Shader "Hidden/PostProcessing/MultiScaleVO"
10893
{
10994
HLSLPROGRAM
11095

111-
#pragma vertex Vert
96+
#pragma vertex VertDefault
11297
#pragma fragment Frag
11398

11499
float4 Frag(VaryingsDefault i) : SV_Target
115100
{
116-
half ao = SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, i.texcoord).r;
101+
half ao = SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, i.texcoordStereo).r;
117102
return float4(ao.rrr, 1.0);
118103
}
119104

PostProcessing/Shaders/xRLib.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ float4 UnityStereoTransformScreenSpaceTex(float4 uv)
5151
return float4(UnityStereoTransformScreenSpaceTex(uv.xy), UnityStereoTransformScreenSpaceTex(uv.zw));
5252
}
5353

54-
float2 UnityStereoClamp(float2 uv, float4 scaleAndOffset)
54+
float2 UnityStereoClampScaleOffset(float2 uv, float4 scaleAndOffset)
5555
{
5656
return float2(clamp(uv.x, scaleAndOffset.z, scaleAndOffset.z + scaleAndOffset.x), uv.y);
5757
}
5858

5959
float2 UnityStereoClamp(float2 uv)
6060
{
61-
return UnityStereoClamp(uv, unity_StereoScaleOffset[unity_StereoEyeIndex]);
61+
return UnityStereoClampScaleOffset(uv, unity_StereoScaleOffset[unity_StereoEyeIndex]);
6262
}
6363
#else
6464
#define TransformStereoScreenSpaceTex(uv, w) uv
6565
#define UnityStereoTransformScreenSpaceTex(uv) uv
66-
#define UnityStereoClamp(uv, scaleAndOffset) uv
66+
#define UnityStereoClampScaleOffset(uv, scaleAndOffset) uv
6767
#define UnityStereoClamp(uv) uv
6868
#endif
6969

0 commit comments

Comments
 (0)