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

Commit ac8dfc8

Browse files
committed
Merge branch 'blit-copy-fix' into v2
2 parents c472db4 + d2ce68a commit ac8dfc8

7 files changed

Lines changed: 123 additions & 48 deletions

File tree

108 Bytes
Binary file not shown.

PostProcessing/Runtime/PostProcessLayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ void OnPreCull()
352352
// tiled GPUs
353353
int tempRt = m_TargetPool.Get();
354354
m_LegacyCmdBuffer.GetTemporaryRT(tempRt, context.width, context.height, 24, FilterMode.Bilinear, sourceFormat);
355-
m_LegacyCmdBuffer.Blit(cameraTarget, tempRt, RuntimeUtilities.copyMaterial, stopNaNPropagation ? 3 : 2);
355+
m_LegacyCmdBuffer.Blit(cameraTarget, tempRt, RuntimeUtilities.copyStdMaterial, stopNaNPropagation ? 1 : 0);
356356
m_NaNKilled = stopNaNPropagation;
357357

358358
context.command = m_LegacyCmdBuffer;

PostProcessing/Runtime/PostProcessResources.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public sealed class Shaders
1313
public Shader autoExposure;
1414
public Shader bloom;
1515
public Shader copy;
16+
public Shader copyStd;
1617
public Shader discardAlpha;
1718
public Shader depthOfField;
1819
public Shader finalPass;

PostProcessing/Runtime/Utils/RuntimeUtilities.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ public static Mesh fullscreenTriangle
9292
}
9393
}
9494

95+
static Material s_CopyStdMaterial;
96+
public static Material copyStdMaterial
97+
{
98+
get
99+
{
100+
if (s_CopyStdMaterial != null)
101+
return s_CopyStdMaterial;
102+
103+
var shader = Shader.Find("Hidden/PostProcessing/CopyStd");
104+
s_CopyStdMaterial = new Material(shader)
105+
{
106+
name = "PostProcess - CopyStd",
107+
hideFlags = HideFlags.HideAndDontSave
108+
};
109+
110+
return s_CopyStdMaterial;
111+
}
112+
}
113+
95114
static Material s_CopyMaterial;
96115
public static Material copyMaterial
97116
{
Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
Shader "Hidden/PostProcessing/Copy"
22
{
3-
Properties
4-
{
5-
_MainTex ("", 2D) = "white" {}
6-
}
7-
83
HLSLINCLUDE
94

105
#include "../StdLib.hlsl"
116

12-
struct AttributesClassic
13-
{
14-
float4 vertex : POSITION;
15-
float2 texcoord : TEXCOORD0;
16-
};
17-
187
TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
19-
float4 _MainTex_ST;
20-
21-
VaryingsDefault VertClassic(AttributesClassic v)
22-
{
23-
VaryingsDefault o;
24-
o.vertex = float4(v.vertex.xy * 2.0 - 1.0, 0.0, 1.0);
25-
o.texcoord = v.texcoord * _MainTex_ST.xy + _MainTex_ST.zw; // We need this for VR
26-
27-
#if UNITY_UV_STARTS_AT_TOP
28-
o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
29-
#endif
30-
31-
return o;
32-
}
338

349
float4 Frag(VaryingsDefault i) : SV_Target
3510
{
@@ -78,27 +53,5 @@ Shader "Hidden/PostProcessing/Copy"
7853

7954
ENDHLSL
8055
}
81-
82-
// 2 - Classic copy
83-
Pass
84-
{
85-
HLSLPROGRAM
86-
87-
#pragma vertex VertClassic
88-
#pragma fragment Frag
89-
90-
ENDHLSL
91-
}
92-
93-
// 3 - Classic copy + NaN killer
94-
Pass
95-
{
96-
HLSLPROGRAM
97-
98-
#pragma vertex VertClassic
99-
#pragma fragment FragKillNaN
100-
101-
ENDHLSL
102-
}
10356
}
10457
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Shader "Hidden/PostProcessing/CopyStd"
2+
{
3+
//
4+
// We need this shader for the very first RT blit using the internal CommandBuffer.Blit() method
5+
// so it can handle AAResolve properly. We also need it to be separate because of VR and the
6+
// need for a Properties block. If we were to add this block to the other Copy shader it would
7+
// not allow us to manually bind _MainTex, thus breaking a few other things in the process...
8+
//
9+
10+
Properties
11+
{
12+
_MainTex ("", 2D) = "white" {}
13+
}
14+
15+
CGINCLUDE
16+
17+
struct Attributes
18+
{
19+
float4 vertex : POSITION;
20+
float2 texcoord : TEXCOORD0;
21+
};
22+
23+
struct Varyings
24+
{
25+
float4 vertex : SV_POSITION;
26+
float2 texcoord : TEXCOORD0;
27+
};
28+
29+
sampler2D _MainTex;
30+
float4 _MainTex_ST;
31+
32+
Varyings Vert(Attributes v)
33+
{
34+
Varyings o;
35+
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
37+
38+
#if UNITY_UV_STARTS_AT_TOP
39+
o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
40+
#endif
41+
42+
return o;
43+
}
44+
45+
float4 Frag(Varyings i) : SV_Target
46+
{
47+
float4 color = tex2D(_MainTex, i.texcoord);
48+
return color;
49+
}
50+
51+
float4 FragKillNaN(Varyings i) : SV_Target
52+
{
53+
float4 color = tex2D(_MainTex, i.texcoord);
54+
55+
#if !SHADER_API_GLES
56+
if (any(isnan(color)) || any(isinf(color)))
57+
{
58+
color = (0.0).xxxx;
59+
}
60+
#endif
61+
62+
return color;
63+
}
64+
65+
ENDCG
66+
67+
SubShader
68+
{
69+
Cull Off ZWrite Off ZTest Always
70+
71+
// 0 - Copy
72+
Pass
73+
{
74+
CGPROGRAM
75+
76+
#pragma vertex Vert
77+
#pragma fragment Frag
78+
79+
ENDCG
80+
}
81+
82+
// 1 - Copy + NaN killer
83+
Pass
84+
{
85+
CGPROGRAM
86+
87+
#pragma vertex Vert
88+
#pragma fragment FragKillNaN
89+
90+
ENDCG
91+
}
92+
}
93+
}

PostProcessing/Shaders/Builtins/CopyStd.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)