Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed profiling scope for quality RTGI.
- Fixed the denoising and multi-sample not being used for smooth multibounce RTReflections.
- Fixed after post process rendering pass options not showing for unlit ShaderGraphs.
- Fixed scene selection pass for decal materials

### Changed
- Preparation pass for RTSSShadows to be supported by render graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ Pass

$splice(HybridV1InjectedBuiltinProperties)

// -- Properties used by SceneSelectionPass
#ifdef SCENESELECTIONPASS
int _ObjectId;
int _PassValue;
#endif

// Includes
$splice(PreGraphIncludes)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,13 @@ void AddColorMaskProperty(string referenceName)
#region SubShaders
static class SubShaders
{
// Relies on the order shader passes are declared in DecalSystem.cs
public static SubShaderDescriptor Decal = new SubShaderDescriptor()
{
generatesPreview = true,
passes = new PassCollection
{
{ DecalPasses.SceneSelection, new FieldCondition(DecalDefault, true) },
{ DecalPasses.DBufferProjector, new FieldCondition(DecalDefault, true) },
{ DecalPasses.DecalProjectorForwardEmissive, new FieldCondition(AffectsEmission, true) },
{ DecalPasses.DBufferMesh, new FieldCondition(DecalDefault, true) },
Expand All @@ -215,8 +217,23 @@ static class SubShaders
#region Passes
public static class DecalPasses
{
// CAUTION: c# code relies on the order in which the passes are declared, any change will need to be reflected in Decalsystem.cs - s_MaterialDecalNames array
// and DecalSet.InitializeMaterialValues()
// CAUTION: c# code relies on the order in which the passes are declared, any change will need to be reflected in Decalsystem.cs - enum MaterialDecalPass

public static PassDescriptor SceneSelection = new PassDescriptor()
{
// Definition
displayName = "SceneSelectionPass",
referenceName = "SHADERPASS_DEPTH_ONLY",
lightMode = "SceneSelectionPass",
useInPreview = false,

// Collections
renderStates = CoreRenderStates.SceneSelection,
pragmas = DecalPragmas.Instanced,
defines = DecalDefines.SceneSelection,
includes = DecalIncludes.SceneSelection,
};

public static PassDescriptor DBufferProjector = new PassDescriptor()
{
// Definition
Expand Down Expand Up @@ -504,12 +521,22 @@ static class Descriptors
definition = KeywordDefinition.ShaderFeature,
scope = KeywordScope.Global,
};

public static KeywordDescriptor SceneSelection = new KeywordDescriptor()
{
displayName = "Scene selection pass",
referenceName = "SCENESELECTIONPASS",
type = KeywordType.Boolean,
definition = KeywordDefinition.Predefined,
scope = KeywordScope.Global,
};
}

public static KeywordCollection Albedo = new KeywordCollection { { Descriptors.AffectsAlbedo, new FieldCondition(AffectsAlbedo, true) } };
public static KeywordCollection Normal = new KeywordCollection { { Descriptors.AffectsNormal, new FieldCondition(AffectsNormal, true) } };
public static KeywordCollection Maskmap = new KeywordCollection { { Descriptors.AffectsMaskmap, new FieldCondition(AffectsMaskMap, true) } };
public static DefineCollection Emission = new DefineCollection { { Descriptors.AffectsEmission, 1 } };
public static DefineCollection SceneSelection = new DefineCollection { { Descriptors.SceneSelection, 1 } };

public static KeywordCollection Decals = new KeywordCollection { { Descriptors.Decals } };
}
Expand All @@ -533,6 +560,13 @@ static class DecalIncludes
{ kDecal, IncludeLocation.Pregraph },
{ kPassDecal, IncludeLocation.Postgraph },
};

public static IncludeCollection SceneSelection = new IncludeCollection
{
{ CoreIncludes.MinimalCorePregraph },
{ kDecal, IncludeLocation.Pregraph },
{ kPassDecal, IncludeLocation.Postgraph },
};
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,45 @@ Shader "HDRP/Decal"
{
Tags{ "RenderPipeline" = "HDRenderPipeline"}

// c# code relies on the order in which the passes are declared, any change will need to be reflected in Decalsystem.cs - s_MaterialDecalNames and s_MaterialDecalSGNames array
// and DecalSet.InitializeMaterialValues()
// c# code relies on the order in which the passes are declared, any change will need to be reflected in
// DecalSystem.cs - enum MaterialDecalPass
// DecalSubTarget.cs - class SubShaders

Pass // 0
// The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declared.
Pass // 0
{
Name "SceneSelectionPass"
Tags { "LightMode" = "SceneSelectionPass" }

Cull Off

HLSLPROGRAM

#pragma only_renderers d3d11 playstation xboxone vulkan metal switch

//enable GPU instancing support
#pragma instancing_options renderinglayer
#pragma multi_compile _ DOTS_INSTANCING_ON
// enable dithering LOD crossfade
#pragma multi_compile _ LOD_FADE_CROSSFADE

// Note: Require _ObjectId and _PassValue variables

// We reuse depth prepass for the scene selection, allow to handle alpha correctly as well as tessellation and vertex animation
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#define SCENESELECTIONPASS // This will drive the output of the scene selection shader
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/ShaderPass/DecalSharePass.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl"

#pragma editor_sync_compilation

ENDHLSL
}

Pass // 1
{
Name "DBufferProjector"
Tags{"LightMode" = "DBufferProjector"} // Metalness
Expand Down Expand Up @@ -143,7 +178,7 @@ Shader "HDRP/Decal"
ENDHLSL
}

Pass // 1
Pass // 2
{
Name "DecalProjectorForwardEmissive"
Tags{ "LightMode" = "DecalProjectorForwardEmissive" }
Expand Down Expand Up @@ -177,7 +212,7 @@ Shader "HDRP/Decal"
ENDHLSL
}

Pass // 2
Pass // 3
{
Name "DBufferMesh"
Tags{"LightMode" = "DBufferMesh"}
Expand Down Expand Up @@ -221,7 +256,7 @@ Shader "HDRP/Decal"
ENDHLSL
}

Pass // 3
Pass // 4
{
Name "DecalMeshForwardEmissive"
Tags{ "LightMode" = "DecalMeshForwardEmissive" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ float _Smoothness;
float _AO;
float _Metallic;

#ifdef SCENESELECTIONPASS
int _ObjectId;
int _PassValue;
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class DecalSystem
// Caution: Enum num must match pass name for s_MaterialDecalPassNames array
public enum MaterialDecalPass
{
DBufferProjector = 0,
DecalProjectorForwardEmissive = 1,
DBufferMesh = 2,
DecalMeshForwardEmissive = 3,
SceneSelectionPass = 0,
DBufferProjector = 1,
DecalProjectorForwardEmissive = 2,
DBufferMesh = 3,
DecalMeshForwardEmissive = 4,
};

public static readonly string[] s_MaterialDecalPassNames = Enum.GetNames(typeof(MaterialDecalPass));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ Shader "HDRP/Lit"
ENDHLSL
}

// Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not bethe meta pass.
// Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not be the meta pass.
Pass
{
Name "GBuffer"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if (SHADERPASS != SHADERPASS_DBUFFER_PROJECTOR) && (SHADERPASS != SHADERPASS_DBUFFER_MESH) && (SHADERPASS != SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) && (SHADERPASS != SHADERPASS_FORWARD_EMISSIVE_MESH) && (SHADERPASS != SHADERPASS_FORWARD_PREVIEW)
#if (SHADERPASS != SHADERPASS_DEPTH_ONLY) && (SHADERPASS != SHADERPASS_DBUFFER_PROJECTOR) && (SHADERPASS != SHADERPASS_DBUFFER_MESH) && (SHADERPASS != SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) && (SHADERPASS != SHADERPASS_FORWARD_EMISSIVE_MESH) && (SHADERPASS != SHADERPASS_FORWARD_PREVIEW)
#error SHADERPASS_is_not_correctly_define
#endif

Expand Down Expand Up @@ -27,13 +27,16 @@ PackedVaryingsType Vert(AttributesMesh inputMesh)
void Frag( PackedVaryingsToPS packedInput,
#if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH)
OUTPUT_DBUFFER(outDBuffer)
#elif (SHADERPASS == SHADERPASS_FORWARD_PREVIEW) // Only used for preview in shader graph
#elif (SHADERPASS == SHADERPASS_DEPTH_ONLY) || (SHADERPASS == SHADERPASS_FORWARD_PREVIEW) // Only used for preview in shader graph
out float4 outColor : SV_Target0
#else
out float4 outEmissive : SV_Target0
#endif
)
{
#if (SHADERPASS == SHADERPASS_DEPTH_ONLY)
outColor = float4(_ObjectId, _PassValue, 1.0, 1.0);
#else
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
DecalSurfaceData surfaceData;
Expand Down Expand Up @@ -147,4 +150,5 @@ void Frag( PackedVaryingsToPS packedInput,
outEmissive.rgb = surfaceData.emissive * GetCurrentExposureMultiplier();
outEmissive.a = 1.0;
#endif
#endif
}