Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
40 changes: 40 additions & 0 deletions com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,46 @@ real Pow4(real x)

TEMPLATE_3_FLT(RangeRemap, min, max, t, return saturate((t - min) / (max - min)))

float4x4 Inverse(float4x4 m)
{
float n11 = m[0][0], n12 = m[1][0], n13 = m[2][0], n14 = m[3][0];
float n21 = m[0][1], n22 = m[1][1], n23 = m[2][1], n24 = m[3][1];
float n31 = m[0][2], n32 = m[1][2], n33 = m[2][2], n34 = m[3][2];
float n41 = m[0][3], n42 = m[1][3], n43 = m[2][3], n44 = m[3][3];

float t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
float t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
float t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
float t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;

float det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
float idet = 1.0f / det;

float4x4 ret;

ret[0][0] = t11 * idet;
ret[0][1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * idet;
ret[0][2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * idet;
ret[0][3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * idet;

ret[1][0] = t12 * idet;
ret[1][1] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * idet;
ret[1][2] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * idet;
ret[1][3] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * idet;

ret[2][0] = t13 * idet;
ret[2][1] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * idet;
ret[2][2] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * idet;
ret[2][3] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * idet;

ret[3][0] = t14 * idet;
ret[3][1] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * idet;
ret[3][2] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * idet;
ret[3][3] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * idet;

return ret;
}

// ----------------------------------------------------------------------------
// Texture utilities
// ----------------------------------------------------------------------------
Expand Down
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 @@ -52,6 +52,7 @@ The version number for this package has increased due to a version update of a r
- Fixed issue when null parameters in a volume component would spam null reference errors. Produce a warning instead.
- Fix volument component creation via script.
- Fixed GC allocs in render graph.
- Fixed scene picking passes.

### Changed
- Combined occlusion meshes into one to reduce draw calls and state changes with XR single-pass.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ From 10.x, HDRP uses range remapping for the metallic property when using a mask
In the Lit, LitTessellation, LayeredLit and LayeredLitTesselation shaders, two new properties have been added: `_MetallicRemapMin` and `_MetallicRemapMax`.
In the Decal shader, the property `_MetallicRemapMin` have been added, and `_MetallicScale` has been renamed as `_MetallicRemapMax`.

From 10.x, a new pass ScenePickingPass have been added to all the shader and master node to allow the editor to correctly handle the picking with tesselated objects and backfaced objects.

## Raytracing

From Unity 2020.2, the Raytracing Node in shader graph now apply the raytraced path (previously low path) to all raytraced effects but path tracing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shade

// Remove editor only pass
bool isSceneSelectionPass = snippet.passName == "SceneSelectionPass";
if (isSceneSelectionPass)
bool isScenePickingPass = snippet.passName == "ScenePickingPass";
if (isSceneSelectionPass || isScenePickingPass)
return true;

// CAUTION: We can't identify transparent material in the stripped in a general way.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ Pass

$splice(HybridV1InjectedBuiltinProperties)

// -- Properties used by ScenePickingPass
#ifdef SCENEPICKINGPASS
float4 _SelectionID;
#endif

// Includes
$splice(PreGraphIncludes)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ 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,
Expand All @@ -206,6 +207,7 @@ static class SubShaders
{ DecalPasses.DecalProjectorForwardEmissive, new FieldCondition(AffectsEmission, true) },
{ DecalPasses.DBufferMesh, new FieldCondition(DecalDefault, true) },
{ DecalPasses.DecalMeshForwardEmissive, new FieldCondition(AffectsEmission, true) },
{ DecalPasses.ScenePicking, new FieldCondition(DecalDefault, true) },
{ DecalPasses.Preview, new FieldCondition(Fields.IsPreview, 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 ScenePicking = new PassDescriptor()
{
// Definition
displayName = "ScenePickingPass",
referenceName = "SHADERPASS_DEPTH_ONLY",
lightMode = "Picking",
useInPreview = false,

// Collections
renderStates = DecalRenderStates.ScenePicking,
pragmas = DecalPragmas.Instanced,
defines = CoreDefines.ScenePicking,
includes = DecalIncludes.ScenePicking,
};

public static PassDescriptor DBufferProjector = new PassDescriptor()
{
// Definition
Expand Down Expand Up @@ -385,6 +402,11 @@ static class DecalRenderStates
readonly static string s_DecalColorMask = "ColorMask [_DecalColorMask0]\n\tColorMask [_DecalColorMask1] 1\n\tColorMask [_DecalColorMask2] 2\n\tColorMask [_DecalColorMask3] 3";
readonly static string s_DecalBlend = "Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha \n\tBlend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha \n\tBlend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha \n\tBlend 3 Zero OneMinusSrcColor";

public static RenderStateCollection ScenePicking = new RenderStateCollection
{
{ RenderState.Cull(Cull.Back) },
};

public static RenderStateCollection DBufferProjector = new RenderStateCollection
{
{ RenderState.Blend(s_DecalBlend) },
Expand Down Expand Up @@ -536,6 +558,17 @@ static class DecalIncludes
{ kDecal, IncludeLocation.Pregraph },
{ kPassDecal, IncludeLocation.Postgraph },
};

public static IncludeCollection ScenePicking = new IncludeCollection
{
{ kPacking, IncludeLocation.Pregraph },
{ kColor, IncludeLocation.Pregraph },
{ kFunctions, IncludeLocation.Pregraph },
{ CoreIncludes.MinimalCorePregraph },
{ kDecal, IncludeLocation.Pregraph },
{ CoreIncludes.kPickingSpaceTransforms, IncludeLocation.Pregraph },
{ kPassDecal, IncludeLocation.Postgraph },
};
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,42 @@ IncludeCollection GenerateIncludes()

#endregion

#region Scene Picking Pass

public static PassDescriptor GenerateScenePicking()
{
return new PassDescriptor
{
// Definition
displayName = "ScenePickingPass",
referenceName = "SHADERPASS_DEPTH_ONLY",
lightMode = "Picking",
useInPreview = false,

// Collections
renderStates = CoreRenderStates.ScenePicking,
pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync,
defines = CoreDefines.ScenePicking,
includes = GenerateIncludes(),
};

IncludeCollection GenerateIncludes()
{
var includes = new IncludeCollection();

includes.Add(CoreIncludes.CorePregraph);
includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph);
includes.Add(CoreIncludes.CoreUtility);
includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph);
includes.Add(CoreIncludes.kPickingSpaceTransforms, IncludeLocation.Pregraph);
includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph);

return includes;
}
}

#endregion

#region Scene Selection Pass

public static PassDescriptor GenerateSceneSelection(bool supportLighting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@ public static class Uniforms
{ RenderState.ColorMask("ColorMask 0") },
};

public static RenderStateCollection ScenePicking = new RenderStateCollection
{
{ RenderState.Cull(Uniforms.cullMode) },
};

public static RenderStateCollection SceneSelection = new RenderStateCollection
{
{ RenderState.Cull(Cull.Off) },
Expand Down Expand Up @@ -800,6 +805,11 @@ static class CoreKeywords
#region Defines
static class CoreDefines
{
public static DefineCollection ScenePicking = new DefineCollection
{
{ CoreKeywordDescriptors.ScenePickingPass, 1 },
};

public static DefineCollection SceneSelection = new DefineCollection
{
{ RayTracingQualityNode.GetRayTracingQualityKeyword(), 0 },
Expand Down Expand Up @@ -860,6 +870,7 @@ static class CoreIncludes
public const string kFragInputs = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl";
public const string kMaterial = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl";
public const string kDebugDisplay = "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl";
public const string kPickingSpaceTransforms = "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl";

// CoreUtility
public const string kBuiltInUtilities = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl";
Expand Down Expand Up @@ -1160,6 +1171,15 @@ static class CoreKeywordDescriptors
scope = KeywordScope.Local,
};

public static KeywordDescriptor ScenePickingPass = new KeywordDescriptor()
{
displayName = "Scene Picking Pass",
referenceName = "SCENEPICKINGPASS",
type = KeywordType.Boolean,
definition = KeywordDefinition.ShaderFeature,
scope = KeywordScope.Local,
};

public static KeywordDescriptor SceneSelectionPass = new KeywordDescriptor()
{
displayName = "Scene Selection Pass",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ PassCollection GetPasses()
// Common "surface" passes
HDShaderPasses.GenerateShadowCaster(supportLighting),
HDShaderPasses.GenerateMETA(supportLighting),
HDShaderPasses.GenerateScenePicking(),
HDShaderPasses.GenerateSceneSelection(supportLighting),
HDShaderPasses.GenerateMotionVectors(supportLighting, supportForward),
{ HDShaderPasses.GenerateBackThenFront(supportLighting), new FieldCondition(HDFields.TransparentBackFace, true)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ Pass
// -- Graph Properties
$splice(GraphProperties)

// -- Property used by ScenePickingPass
#ifdef SCENEPICKINGPASS
float4 _SelectionID;
#endif

// -- Properties used by SceneSelectionPass
#ifdef SCENESELECTIONPASS
int _ObjectId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,35 @@ Shader "HDRP/AxF"
// This tags allow to use the shader replacement features
Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" }

Pass
{
Name "ScenePickingPass"
Tags { "LightMode" = "Picking" }

Cull [_CullMode]

HLSLPROGRAM

// Note: Require _SelectionID variable

// 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 SCENEPICKINGPASS
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/ShaderPass/AxFDepthPass.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFData.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"

#pragma vertex Vert
#pragma fragment Frag

#pragma editor_sync_compilation

ENDHLSL
}

Pass
{
Name "SceneSelectionPass"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ float _SpecularAAThreshold;
// TODO: Fix the code in legacy unity so we can customize the behavior for GI
float3 _EmissionColor;

// Following two variables are feeded by the C++ Editor for Scene selection
// Following three variables are feeded by the C++ Editor for Scene selection
int _ObjectId;
int _PassValue;
float4 _SelectionID;

CBUFFER_END
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ 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
// Caution: passes stripped in builds (like the scene picking pass) need to be put last to have consistent indices

Pass // 0
{
Expand Down Expand Up @@ -257,6 +259,40 @@ Shader "HDRP/Decal"
ENDHLSL
}

Pass // 4
{
Name "ScenePickingPass"
Tags { "LightMode" = "Picking" }

Cull Back

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 _SelectionID variable

// 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 SCENEPICKINGPASS
#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/ShaderLibrary/PickingSpaceTransforms.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl"

#pragma editor_sync_compilation

ENDHLSL
}

}
CustomEditor "Rendering.HighDefinition.DecalUI"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ float _Smoothness;
float _AO;
float _Metallic;

#ifdef SCENEPICKINGPASS
float4 _SelectionID;
#endif

#endif
Loading