Skip to content

Commit efc295b

Browse files
KarlBKentpastasfuture
authored andcommitted
Shadergraph/custom shaders support for HDRP Decals spawned by VFXgraph (#100)
* Shadergraph/custom shaders support for HDRP Decals spawned by VFXgraph PBR properties complete : UV Flipbook untested & samplerstates * fixed UV error that was occurring in some of the vfx decal passes This was to pass the test load, but may change after I get user feedback * vfxgraph shader debug hacks removed * fixed decal normals Note: SG normals needs to be tested, I suspect the generartor will fail due to the texcoord limit being hit, in the decal ps_Input, wont allow for Tangents
1 parent 530c180 commit efc295b

File tree

16 files changed

+722
-292
lines changed

16 files changed

+722
-292
lines changed

com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXDecalHDRPOutput.cs

Lines changed: 71 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,14 @@ namespace UnityEditor.VFX.HDRP
1010
[VFXInfo(experimental = true)]
1111
class VFXDecalHDRPOutput : VFXAbstractParticleHDRPOutput
1212
{
13-
public override string name
14-
{
15-
get { return "Output Particle HDRP Lit Decal"; }
16-
}
13+
public override string name { get { return "Output Particle HDRP Lit Decal"; } }
1714

18-
public override string codeGeneratorTemplate
19-
{
20-
get { return RenderPipeTemplate("VFXParticleHDRPDecal"); }
21-
}
15+
public override string codeGeneratorTemplate { get { return RenderPipeTemplate("VFXParticleHDRPDecal"); } }
2216

23-
public override VFXTaskType taskType
24-
{
25-
get { return VFXTaskType.ParticleHexahedronOutput; }
26-
}
17+
public override VFXTaskType taskType { get { return VFXTaskType.ParticleHexahedronOutput; } }
18+
19+
public override bool isLitDecalShader { get => true; }
20+
protected override RPInfo currentRP { get => hdrpLitDecalInfo; }
2721

2822
public override void OnEnable()
2923
{
@@ -59,7 +53,6 @@ public override IEnumerable<VFXAttributeInfo> attributes
5953
}
6054
}
6155

62-
6356
public enum BlendSource
6457
{
6558
BaseColorMapAlpha,
@@ -93,12 +86,9 @@ public enum BlendSource
9386
"When enabled, modifies the smoothness of the surface it projects onto using the (A) channel of the Mask Map if one is provided.")]
9487
private bool affectSmoothness = true;
9588

96-
9789
private bool supportDecals => HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.supportDecals &&
9890
HDRenderPipeline.defaultAsset.GetDefaultFrameSettings(FrameSettingsRenderType.Camera).IsEnabled(FrameSettingsField.Decals);
99-
10091
private bool enableDecalLayers =>
101-
10292
supportDecals
10393
&& HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.supportDecalLayers
10494
&& HDRenderPipeline.defaultAsset.GetDefaultFrameSettings(FrameSettingsRenderType.Camera).IsEnabled(FrameSettingsField.DecalLayers);
@@ -112,7 +102,7 @@ public enum BlendSource
112102
Tooltip("Specifies the layer mask of the decal.")]
113103
private DecalLayerEnum decalLayer = DecalLayerEnum.DecalLayerDefault;
114104

115-
public override bool supportsUV { get { return GetOrRefreshShaderGraphObject() == null; } }
105+
public override bool supportsUV => true;
116106

117107

118108
public class FadeFactorProperty
@@ -132,29 +122,32 @@ protected IEnumerable<VFXPropertyWithValue> materialProperties
132122
{
133123
get
134124
{
135-
if (affectMetal)
136-
yield return new VFXPropertyWithValue(new VFXProperty(typeof(float),
137-
"metallic",
138-
new TooltipAttribute(useMaskMap
139-
? "Controls the scale factor for the particle’s metallic."
140-
: "Controls the metallic of the decal."),
141-
new RangeAttribute(0, 1)), 0.0f);
125+
if (GetOrRefreshShaderGraphObject() == null)
126+
{
127+
if (affectMetal)
128+
yield return new VFXPropertyWithValue(new VFXProperty(typeof(float),
129+
"metallic",
130+
new TooltipAttribute(useMaskMap
131+
? "Controls the scale factor for the particle’s metallic."
132+
: "Controls the metallic of the decal."),
133+
new RangeAttribute(0, 1)), 0.0f);
142134

143-
if (affectAmbientOcclusion)
144-
yield return new VFXPropertyWithValue(new VFXProperty(typeof(float),
145-
"ambientOcclusion",
146-
new TooltipAttribute(useMaskMap
147-
? "Controls the scale factor for the particle’s ambient occlusion."
148-
: "Controls the ambient occlusion of the decal."),
149-
new RangeAttribute(0, 1)), 1.0f);
135+
if (affectAmbientOcclusion)
136+
yield return new VFXPropertyWithValue(new VFXProperty(typeof(float),
137+
"ambientOcclusion",
138+
new TooltipAttribute(useMaskMap
139+
? "Controls the scale factor for the particle’s ambient occlusion."
140+
: "Controls the ambient occlusion of the decal."),
141+
new RangeAttribute(0, 1)), 1.0f);
150142

151-
if (affectSmoothness)
152-
yield return new VFXPropertyWithValue(new VFXProperty(typeof(float),
153-
"smoothness",
154-
new TooltipAttribute(useMaskMap
155-
? "Controls the scale factor for the particle’s smoothness."
156-
: "Controls the smoothness of the decal."),
157-
new RangeAttribute(0, 1)), 0.5f);
143+
if (affectSmoothness)
144+
yield return new VFXPropertyWithValue(new VFXProperty(typeof(float),
145+
"smoothness",
146+
new TooltipAttribute(useMaskMap
147+
? "Controls the scale factor for the particle’s smoothness."
148+
: "Controls the smoothness of the decal."),
149+
new RangeAttribute(0, 1)), 0.5f);
150+
}
158151
}
159152
}
160153

@@ -179,21 +172,19 @@ protected override IEnumerable<VFXNamedExpression> CollectGPUExpressions(
179172
{
180173
foreach (var exp in base.CollectGPUExpressions(slotExpressions))
181174
yield return exp;
175+
yield return slotExpressions.First(o => o.name == "fadeFactor");
176+
var angleFadeExp = slotExpressions.First(o => o.name == "angleFade");
177+
yield return new VFXNamedExpression(AngleFadeSimplification(angleFadeExp.exp), "angleFade");
178+
yield return new VFXNamedExpression(VFXValue.Constant((uint)decalLayer), "decalLayerMask");
182179

183180
if (GetOrRefreshShaderGraphObject() == null)
184181
{
185-
yield return slotExpressions.First(o => o.name == "fadeFactor");
186182
if (affectMetal)
187183
yield return slotExpressions.First(o => o.name == "metallic");
188184
if (affectAmbientOcclusion)
189185
yield return slotExpressions.First(o => o.name == "ambientOcclusion");
190186
if (affectSmoothness)
191187
yield return slotExpressions.First(o => o.name == "smoothness");
192-
193-
194-
var angleFadeExp = slotExpressions.First(o => o.name == "angleFade");
195-
yield return new VFXNamedExpression(AngleFadeSimplification(angleFadeExp.exp), "angleFade");
196-
yield return new VFXNamedExpression(VFXValue.Constant((uint)decalLayer), "decalLayerMask");
197188
}
198189
}
199190

@@ -234,9 +225,9 @@ protected override IEnumerable<string> filteredOutSettings
234225
yield return "cullMode";
235226
yield return "blendMode";
236227
yield return "doubleSided";
237-
yield return "shaderGraph";
238228
yield return "zTestMode";
239229
yield return "zWriteMode";
230+
yield return "zWriteMode";
240231
yield return "castShadows";
241232
yield return "materialType";
242233
yield return "sort";
@@ -254,6 +245,25 @@ public override IEnumerable<string> additionalDefines
254245
{
255246
foreach (var def in base.additionalDefines)
256247
yield return def;
248+
249+
// if (GetOrRefreshShaderGraphObject() != null)
250+
// {
251+
// if (maskOpacityChannel == BlendSource.BaseColorMapAlpha)
252+
// yield return "VFX_MASK_BLEND_BASE_COLOR_ALPHA";
253+
// else
254+
// yield return "VFX_MASK_BLEND_MASK_BLUE";
255+
//
256+
// if (normalOpacityChannel == BlendSource.BaseColorMapAlpha)
257+
// yield return "VFX_NORMAL_BLEND_BASE_COLOR_ALPHA";
258+
// else
259+
// yield return "VFX_NORMAL_BLEND_MASK_BLUE";
260+
//
261+
// // yield return "AFFECT_METALLIC";
262+
// // yield return "AFFECT_AMBIENT_OCCLUSION";
263+
// // yield return "AFFECT_SMOOTHNESS";
264+
// // yield return "NEEDS_FORWARD_EMISSIVE_PASS";
265+
// }
266+
257267
if (maskOpacityChannel == BlendSource.BaseColorMapAlpha)
258268
yield return "VFX_MASK_BLEND_BASE_COLOR_ALPHA";
259269
else
@@ -264,14 +274,23 @@ public override IEnumerable<string> additionalDefines
264274
else
265275
yield return "VFX_NORMAL_BLEND_MASK_BLUE";
266276

267-
if (affectMetal)
268-
yield return "AFFECT_METALLIC";
269-
if (affectAmbientOcclusion)
270-
yield return "AFFECT_AMBIENT_OCCLUSION";
271-
if (affectSmoothness)
272-
yield return "AFFECT_SMOOTHNESS";
273-
if (useEmissive || useEmissiveMap)
277+
if (GetOrRefreshShaderGraphObject() == null)
278+
{
279+
if (affectMetal)
280+
yield return "AFFECT_METALLIC";
281+
if (affectAmbientOcclusion)
282+
yield return "AFFECT_AMBIENT_OCCLUSION";
283+
if (affectSmoothness)
284+
yield return "AFFECT_SMOOTHNESS";
285+
if (useEmissive || useEmissiveMap)
286+
yield return "NEEDS_FORWARD_EMISSIVE_PASS";
287+
}
288+
else
289+
{
290+
//HACK KARL: ADD EMISIVE CALLS BACK
291+
//TODO
274292
yield return "NEEDS_FORWARD_EMISSIVE_PASS";
293+
}
275294
}
276295
}
277296

com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/HDRPDecal/PassDBuffer.template

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@ Pass
33
Name "DBufferMesh"
44
Tags {"LightMode"="DBufferVFX"}
55

6-
76
Cull Front
87
ZWrite Off
98
ZTest Greater
109

11-
1210
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html
1311
Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
1412
Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
1513
Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
1614
Blend 3 Zero OneMinusSrcColor
1715

18-
1916
ColorMask ${VFXDecalColorMask0}
2017
ColorMask ${VFXDecalColorMask1} 1
2118
ColorMask ${VFXDecalColorMask2} 2
@@ -35,8 +32,6 @@ Pass
3532
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl"
3633
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
3734

38-
39-
4035
struct ps_input
4136
{
4237
float4 pos : SV_POSITION;
@@ -50,15 +45,24 @@ Pass
5045
${VFXHDRPDecalFillVaryings}
5146
${VFXEnd}
5247

48+
${VFXInclude("Shaders/ParticleHexahedron/Pass.template")}
49+
#define SHADERPASS SHADERPASS_DBUFFER_PROJECTOR
5350

54-
${VFXInclude("Shaders/ParticleHexahedron/Pass.template")}
55-
#define SHADERPASS SHADERPASS_VFX_DBUFFER_PROJECTOR
56-
${VFXIncludeRP("VFXDecal.template")}
51+
//shadergraph code functions, defined before Template, so to use them in template
52+
${SHADERGRAPH_PIXEL_CODE_DBUFFER_PROJECTOR}
53+
54+
${VFXIncludeRP("VFXDecal.template")}
5755

5856
#pragma fragment frag
5957
void frag(ps_input i, OUTPUT_DBUFFER(outDBuffer))
6058
{
6159
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
60+
61+
${VFXComputeNormalWS}
62+
63+
DecalSurfaceData decalSurfaceData;
64+
ZERO_INITIALIZE(DecalSurfaceData, decalSurfaceData);
65+
6266
VFXComputePixelOutputToDBuffer(i,outDBuffer);
6367
}
6468
ENDHLSL

com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/HDRPDecal/PassForwardEmissive.template

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ Pass
2020
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.hlsl"
2121
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl"
2222

23-
24-
2523
struct ps_input
2624
{
2725
float4 pos : SV_POSITION;
@@ -38,17 +36,20 @@ Pass
3836

3937
${VFXInclude("Shaders/ParticleHexahedron/Pass.template")}
4038
#define SHADERPASS SHADERPASS_VFX_DECAL_FORWARD_EMISSIVE
41-
${VFXIncludeRP("VFXDecal.template")}
4239

40+
//shadergraph code functions, defined before Template, so to use them in template
41+
${SHADERGRAPH_PIXEL_CODE_DBUFFER_PROJECTOR}
42+
43+
${VFXIncludeRP("VFXDecal.template")}
4344

4445
#pragma fragment frag
4546
void frag(ps_input i, out float4 outEmissive : SV_Target0)
4647
{
4748
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
48-
DecalSurfaceData surfaceData;
49-
ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
50-
VFXGetSurfaceDecalData(surfaceData,i);
51-
outEmissive.rgb = surfaceData.emissive * GetCurrentExposureMultiplier();
49+
DecalSurfaceData decalSurfaceData;
50+
ZERO_INITIALIZE(DecalSurfaceData, decalSurfaceData);
51+
VFXGetSurfaceDecalData(decalSurfaceData,i);
52+
outEmissive.rgb = decalSurfaceData.emissive * GetCurrentExposureMultiplier();
5253
outEmissive.a = 1.0f;
5354
}
5455
ENDHLSL

com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassForward.template

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
// Forward pass
22
Pass
3-
{
3+
{
44
Tags { "LightMode"="${VFXHDRPForwardPassName}"}
5-
5+
66
${VFXStencilForward}
77

88
HLSLPROGRAM
99
#pragma target 4.5
10-
10+
1111
#define UNITY_MATERIAL_LIT
1212
#define LIGHTLOOP_TILE_PASS
1313
${VFXHDRPForwardDefines}
14-
#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
14+
#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
1515
#pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH
1616
#pragma multi_compile _ DEBUG_DISPLAY
1717
//#pragma enable_d3d11_debug_symbols
18-
19-
${VFXIncludeRP("VFXLitVaryings.template")}
20-
18+
19+
${VFXIncludeRP("VFXLitVaryings.template")}
20+
2121
struct ps_input
2222
{
2323
float4 pos : SV_POSITION;
24-
24+
2525
${VFXHDRPLitDeclareVaryings}
26-
26+
2727
#if USE_FLIPBOOK_INTERPOLATION
2828
float4 uv : TEXCOORD1;
2929
#else
30-
float2 uv : TEXCOORD1;
30+
float2 uv : TEXCOORD1;
3131
#endif
3232
#if USE_SOFT_PARTICLE || USE_ALPHA_TEST || USE_FLIPBOOK_INTERPOLATION || WRITE_MOTION_VECTOR_IN_FORWARD
3333
// x: inverse soft particles fade distance
@@ -54,16 +54,16 @@ Pass
5454
float4 cPosPrevious : TEXCOORD7;
5555
float4 cPosNonJiterred : TEXCOORD8;
5656
#endif
57-
57+
5858
float3 posWS : TEXCOOR9; // Needed for fog
59-
59+
6060
${VFXAdditionalInterpolantsDeclaration}
61-
61+
6262
UNITY_VERTEX_OUTPUT_STEREO
6363
};
64-
65-
${VFXHDRPLitVaryingsMacros}
66-
64+
65+
${VFXHDRPLitVaryingsMacros}
66+
6767
#define VFX_VARYING_PS_INPUTS ps_input
6868
#define VFX_VARYING_POSCS pos
6969
#define VFX_VARYING_INVSOFTPARTICLEFADEDISTANCE builtInInterpolants.x
@@ -88,13 +88,13 @@ ${VFXHDRPLitVaryingsMacros}
8888
${VFXBegin:VFXVertexAdditionalProcess}
8989
${VFXHDRPLitFillVaryings}
9090
${VFXEnd}
91-
91+
9292
${VFXInclude("Shaders/ParticlePlanarPrimitives/Pass.template")}
9393
#define SHADERPASS SHADERPASS_FORWARD
9494
${VFXIncludeRP("VFXLit.template")}
95-
95+
9696
${SHADERGRAPH_PIXEL_CODE_FORWARD}
97-
97+
9898
#pragma fragment frag
9999
void frag(ps_input i
100100
, out float4 outColor : SV_Target0
@@ -109,7 +109,7 @@ ${VFXEnd}
109109
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
110110
VFXTransformPSInputs(i);
111111
${VFXComputeNormalWS}
112-
112+
113113
#ifdef VFX_SHADERGRAPH
114114
${VFXAdditionalInterpolantsPreparation}
115115
${SHADERGRAPH_PIXEL_CALL_FORWARD}
@@ -119,7 +119,7 @@ ${VFXEnd}
119119
#else
120120
outColor = VFXGetPixelOutputForward(i, normalWS, uvData);
121121
#endif
122-
122+
123123
#if WRITE_MOTION_VECTOR_IN_FORWARD
124124
${VFXComputeOutputMotionVector}
125125
outMotionVector = encodedMotionVector;

0 commit comments

Comments
 (0)