Skip to content

Hdrp/fix/shader stack normals #852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 11, 2020
Merged
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 @@ -674,6 +674,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed issue with blue line in prefabs for volume mode.
- Fixing the internsity being applied to RTAO too early leading to unexpected results (1254626).
- Fix issue that caused sky to incorrectly render when using a custom projection matrix.
- Fixed null reference exception when using depth pre/post pass in shadergraph with alpha clip in the material.

### Changed
- Improve MIP selection for decals on Transparents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void CreateEyeGraph()
BlockFields.VertexDescription.Tangent,
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescription.NormalTS,
HDBlockFields.SurfaceDescription.IrisNormal,
HDBlockFields.SurfaceDescription.IrisNormalTS,
HDBlockFields.SurfaceDescription.BentNormal,
BlockFields.SurfaceDescription.Smoothness,
HDBlockFields.SurfaceDescription.IOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@ public bool subsurfaceScattering
get => m_SubsurfaceScattering;
set => m_SubsurfaceScattering = value;
}

[SerializeField]
bool m_IrisNormal = false;
public bool irisNormal
{
get => m_IrisNormal;
set => m_IrisNormal = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,15 @@ Pass

$SurfaceDescription.SubsurfaceMask: surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask;

// tangent-space normal
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
$SurfaceDescription.NormalTS: normalTS = surfaceDescription.NormalTS;

// compute world space normal
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);

float3 irisNormalTS = normalTS; // By default Iris normal is same as normal
$SurfaceDescription.IrisNormal: irisNormalTS = surfaceDescription.IrisNormal;

// compute world space normal
GetNormalWS(fragInputs, irisNormalTS, surfaceData.irisNormalWS, doubleSidedConstants);
// normal delivered to master node
$SurfaceDescription.NormalOS: surfaceData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
$SurfaceDescription.NormalTS: GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
$SurfaceDescription.NormalWS: surfaceData.normalWS = surfaceDescription.NormalWS;

surfaceData.irisNormalWS = surfaceData.normalWS;
$SurfaceDescription.IrisNormalOS: surfaceData.irisNormalWS = TransformObjectToWorldNormal(surfaceDescription.IrisNormalOS);
$SurfaceDescription.IrisNormalTS: GetNormalWS(fragInputs, surfaceDescription.IrisNormalTS, surfaceData.irisNormalWS, doubleSidedConstants);
$SurfaceDescription.IrisNormalWS: surfaceData.irisNormalWS = surfaceDescription.IrisNormalWS;

surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
{ EyeMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor },
{ EyeMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion },
{ EyeMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS },
{ EyeMasterNode1.SlotMask.IrisNormal, HDBlockFields.SurfaceDescription.IrisNormal },
{ EyeMasterNode1.SlotMask.IrisNormal, HDBlockFields.SurfaceDescription.IrisNormalTS },
{ EyeMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal },
{ EyeMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness },
{ EyeMasterNode1.SlotMask.IOR, HDBlockFields.SurfaceDescription.IOR },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context)
base.GetActiveBlocks(ref context);

// Eye specific blocks
context.AddBlock(HDBlockFields.SurfaceDescription.IrisNormal);
context.AddBlock(HDBlockFields.SurfaceDescription.IrisNormalOS, eyeData.irisNormal && lightingData.normalDropOffSpace == NormalDropOffSpace.Object);
context.AddBlock(HDBlockFields.SurfaceDescription.IrisNormalTS, eyeData.irisNormal && lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent);
context.AddBlock(HDBlockFields.SurfaceDescription.IrisNormalWS, eyeData.irisNormal && lightingData.normalDropOffSpace == NormalDropOffSpace.World);

context.AddBlock(HDBlockFields.SurfaceDescription.IOR);
context.AddBlock(HDBlockFields.SurfaceDescription.Mask);
context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, eyeData.subsurfaceScattering);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class EyeSurfaceOptionPropertyBlock : SurfaceOptionPropertyBlock
class Styles
{
public static GUIContent materialType = new GUIContent("Material Type", "TODO");
public static GUIContent irisNormalType = new GUIContent("Iris Normal", "Override the iris normal");
}

EyeData eyeData;
Expand All @@ -34,6 +35,7 @@ protected override void CreatePropertyGUI()

// Eye specific properties:
AddProperty(subsurfaceEnableText, () => eyeData.subsurfaceScattering, (newValue) => eyeData.subsurfaceScattering = newValue);
AddProperty(Styles.irisNormalType, () => eyeData.irisNormal, (newValue) => eyeData.irisNormal = newValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,10 @@ Pass
float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
#endif

// tangent-space normal
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
$SurfaceDescription.NormalTS: normalTS = surfaceDescription.NormalTS;

// compute world space normal
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
// normal delivered to master node
$SurfaceDescription.NormalOS: surfaceData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
$SurfaceDescription.NormalTS: GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
$SurfaceDescription.NormalWS: surfaceData.normalWS = surfaceDescription.NormalWS;

surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,10 @@ Pass

surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];

// tangent-space normal
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
$SurfaceDescription.NormalTS: normalTS = surfaceDescription.NormalTS;

// compute world space (user-provided) normal
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
// normal delivered to master node
$SurfaceDescription.NormalOS: surfaceData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
$SurfaceDescription.NormalTS: GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
$SurfaceDescription.NormalWS: surfaceData.normalWS = surfaceDescription.NormalWS;

#if HAVE_DECALS
if (_EnableDecals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ Pass
$TransparentWritesMotionVec: #define _WRITE_TRANSPARENT_MOTION_VECTOR 1
$DepthOffset: #define _DEPTHOFFSET_ON 1
$BlendMode.PreserveSpecular: #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1
$NormalDropOffTS: #define _NORMAL_DROPOFF_TS 1
$NormalDropOffOS: #define _NORMAL_DROPOFF_OS 1
$NormalDropOffWS: #define _NORMAL_DROPOFF_WS 1
$AttributesMesh.normalOS: #define ATTRIBUTES_NEED_NORMAL
Copy link
Contributor

@sebastienlagarde sebastienlagarde Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to also remove all the

        // Normal dropoff space
        context.AddField(Fields.NormalDropOffOS,                        lightingData.normalDropOffSpace == NormalDropOffSpace.Object);
        context.AddField(Fields.NormalDropOffTS,                        lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent);
        context.AddField(Fields.NormalDropOffWS,                        lightingData.normalDropOffSpace == NormalDropOffSpace.World);

$AttributesMesh.tangentOS: #define ATTRIBUTES_NEED_TANGENT
$AttributesMesh.uv0: #define ATTRIBUTES_NEED_TEXCOORD0
Expand Down Expand Up @@ -225,19 +222,9 @@ Pass
#endif

// normal delivered to master node
float3 normalSrc = float3(0.0f, 0.0f, 1.0f);
$SurfaceDescription.NormalOS: normalSrc = surfaceDescription.NormalOS;
$SurfaceDescription.NormalTS: normalSrc = surfaceDescription.NormalTS;
$SurfaceDescription.NormalWS: normalSrc = surfaceDescription.NormalWS;

// compute world space normal
#if _NORMAL_DROPOFF_TS
GetNormalWS(fragInputs, normalSrc, surfaceData.normalWS, doubleSidedConstants);
#elif _NORMAL_DROPOFF_OS
surfaceData.normalWS = TransformObjectToWorldNormal(normalSrc);
#elif _NORMAL_DROPOFF_WS
surfaceData.normalWS = normalSrc;
#endif
$SurfaceDescription.NormalOS: surfaceData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
$SurfaceDescription.NormalTS: GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
$SurfaceDescription.NormalWS: surfaceData.normalWS = surfaceDescription.NormalWS;

surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ public override void GetFields(ref TargetFieldContext context)
// Common properties to all Lit master nodes
var descs = context.blocks.Select(x => x.descriptor);

// Normal dropoff space
context.AddField(Fields.NormalDropOffOS, lightingData.normalDropOffSpace == NormalDropOffSpace.Object);
context.AddField(Fields.NormalDropOffTS, lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent);
context.AddField(Fields.NormalDropOffWS, lightingData.normalDropOffSpace == NormalDropOffSpace.World);

// Misc
context.AddField(HDFields.BlendPreserveSpecular, systemData.surfaceType != SurfaceType.Opaque && lightingData.blendPreserveSpecular);
context.AddField(HDFields.DisableDecals, !lightingData.receiveDecals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ Pass
$StackLitDebug: #define _STACKLIT_DEBUG
$DepthOffset: #define _DEPTHOFFSET_ON 1
$BlendMode.PreserveSpecular: #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1
$NormalDropOffTS: #define _NORMAL_DROPOFF_TS 1
$NormalDropOffOS: #define _NORMAL_DROPOFF_OS 1
$NormalDropOffWS: #define _NORMAL_DROPOFF_WS 1

// StackLit.hlsl config defines (direct, no feature keywords):
// _SCREENSPACE_SPECULAROCCLUSION_METHOD, _SCREENSPACE_SPECULAROCCLUSION_VISIBILITY_FROM_AO_WEIGHT, _SCREENSPACE_SPECULAROCCLUSION_VISIBILITY_DIR
Expand Down Expand Up @@ -391,22 +388,14 @@ Pass
surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];

// normal delivered to master node
float3 normalSrc = float3(0.0f, 0.0f, 1.0f);
$SurfaceDescription.NormalOS: normalSrc = surfaceDescription.NormalOS;
$SurfaceDescription.NormalTS: normalSrc = surfaceDescription.NormalTS;
$SurfaceDescription.NormalWS: normalSrc = surfaceDescription.NormalWS;

// compute world space normal
#if _NORMAL_DROPOFF_TS
GetNormalWS(fragInputs, normalSrc, surfaceData.normalWS, doubleSidedConstants);
#elif _NORMAL_DROPOFF_OS
surfaceData.normalWS = TransformObjectToWorldNormal(normalSrc);
#elif _NORMAL_DROPOFF_WS
surfaceData.normalWS = normalSrc;
#endif
$SurfaceDescription.NormalOS: surfaceData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
$SurfaceDescription.NormalTS: GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
$SurfaceDescription.NormalWS: surfaceData.normalWS = surfaceDescription.NormalWS;

surfaceData.coatNormalWS = surfaceData.geomNormalWS;
$Material.CoatNormal: GetNormalWS(fragInputs, surfaceDescription.CoatNormal, surfaceData.coatNormalWS, doubleSidedConstants);
$SurfaceDescription.CoatNormalOS: surfaceData.coatNormalWS = TransformObjectToWorldNormal(surfaceDescription.CoatNormalOS);
$SurfaceDescription.CoatNormalTS: GetNormalWS(fragInputs, surfaceDescription.CoatNormalTS, surfaceData.coatNormalWS, doubleSidedConstants);
$SurfaceDescription.CoatNormalWS: surfaceData.coatNormalWS = surfaceDescription.CoatNormalWS;

// surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);
// ...We don't need to normalize if we're going to call Orthonormalize anyways as long as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo

if (stackLitData.coatNormal)
{
blockMap.Add(HDBlockFields.SurfaceDescription.CoatNormal, StackLitMasterNode1.CoatNormalSlotId);
blockMap.Add(HDBlockFields.SurfaceDescription.CoatNormalTS, StackLitMasterNode1.CoatNormalSlotId);
}

blockMap.Add(HDBlockFields.SurfaceDescription.CoatMask, StackLitMasterNode1.CoatMaskSlotId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public override void GetFields(ref TargetFieldContext context)
// FindSlot<Vector1MaterialSlot>(CoatMaskSlotId).value == 0.0f),
// context.AddField(HDFields.CoatMaskOne, coat.isOn && pass.pixelBlocks.Contains(CoatMaskSlotId) &&
// FindSlot<Vector1MaterialSlot>(CoatMaskSlotId).value == 1.0f),
context.AddField(HDFields.CoatNormal, stackLitData.coatNormal && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatNormal));
context.AddField(HDFields.CoatNormal, stackLitData.coatNormal
&& (context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatNormalOS)
|| context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatNormalTS)
|| context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatNormalWS)));
context.AddField(HDFields.Iridescence, stackLitData.iridescence);
context.AddField(HDFields.SubsurfaceScattering, stackLitData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent);
context.AddField(HDFields.Transmission, stackLitData.transmission);
Expand Down Expand Up @@ -215,7 +218,9 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context)
context.AddBlock(HDBlockFields.SurfaceDescription.CoatIor, stackLitData.coat);
context.AddBlock(HDBlockFields.SurfaceDescription.CoatThickness, stackLitData.coat);
context.AddBlock(HDBlockFields.SurfaceDescription.CoatExtinction, stackLitData.coat);
context.AddBlock(HDBlockFields.SurfaceDescription.CoatNormal, stackLitData.coat && stackLitData.coatNormal);
context.AddBlock(HDBlockFields.SurfaceDescription.CoatNormalOS, stackLitData.coat && stackLitData.coatNormal && lightingData.normalDropOffSpace == NormalDropOffSpace.Object);
context.AddBlock(HDBlockFields.SurfaceDescription.CoatNormalTS, stackLitData.coat && stackLitData.coatNormal && lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent);
context.AddBlock(HDBlockFields.SurfaceDescription.CoatNormalWS, stackLitData.coat && stackLitData.coatNormal && lightingData.normalDropOffSpace == NormalDropOffSpace.World);
context.AddBlock(HDBlockFields.SurfaceDescription.CoatMask, stackLitData.coat);

// Dual Specular Lobe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,14 @@ void DrawAlphaCutoffGUI()
{
if (transparentDepthPrepassEnable != null && transparentDepthPrepassEnable.floatValue == 1.0f)
{
materialEditor.ShaderProperty(alphaCutoffPrepass, Styles.alphaCutoffPrepassText);
if (alphaCutoffPrepass != null)
materialEditor.ShaderProperty(alphaCutoffPrepass, Styles.alphaCutoffPrepassText);
}

if (transparentDepthPostpassEnable != null && transparentDepthPostpassEnable.floatValue == 1.0f)
{
materialEditor.ShaderProperty(alphaCutoffPostpass, Styles.alphaCutoffPostpassText);
if (alphaCutoffPostpass != null)
materialEditor.ShaderProperty(alphaCutoffPostpass, Styles.alphaCutoffPostpassText);
}
}
EditorGUI.indentLevel--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ public struct SurfaceDescription
// --------------------------------------------------
// Eye

public static BlockFieldDescriptor IrisNormal = new BlockFieldDescriptor(SurfaceDescription.name, "IrisNormal", "Iris Normal", "SURFACEDESCRIPTION_IRISNORMAL",
public static BlockFieldDescriptor IrisNormalTS = new BlockFieldDescriptor(SurfaceDescription.name, "IrisNormalTS", "Iris Normal (Tangent Space)", "SURFACEDESCRIPTION_IRISNORMALTS",
new NormalControl(CoordinateSpace.Tangent), ShaderStage.Fragment);
public static BlockFieldDescriptor IrisNormalOS = new BlockFieldDescriptor(SurfaceDescription.name, "IrisNormalOS", "Iris Normal (Object Space)", "SURFACEDESCRIPTION_IRISNORMALOS",
new NormalControl(CoordinateSpace.Object), ShaderStage.Fragment);
public static BlockFieldDescriptor IrisNormalWS = new BlockFieldDescriptor(SurfaceDescription.name, "IrisNormalWS", "Iris Normal (World Space)", "SURFACEDESCRIPTION_IRISNORMALWS",
new NormalControl(CoordinateSpace.World), ShaderStage.Fragment);
public static BlockFieldDescriptor IOR = new BlockFieldDescriptor(SurfaceDescription.name, "IOR", "SURFACEDESCRIPTION_IOR",
new FloatControl(1.4f), ShaderStage.Fragment);
public static BlockFieldDescriptor Mask = new BlockFieldDescriptor(SurfaceDescription.name, "Mask", "SURFACEDESCRIPTION_MASK",
Expand Down Expand Up @@ -108,7 +112,11 @@ public struct SurfaceDescription
// --------------------------------------------------
// StackLit

public static BlockFieldDescriptor CoatNormal = new BlockFieldDescriptor(SurfaceDescription.name, "CoatNormal", "Coat Normal", "SURFACEDESCRIPTION_COATNORMAL",
public static BlockFieldDescriptor CoatNormalOS = new BlockFieldDescriptor(SurfaceDescription.name, "CoatNormalOS", "Coat Normal (Object Space)", "SURFACEDESCRIPTION_COATNORMALOS",
new NormalControl(CoordinateSpace.Tangent), ShaderStage.Fragment);
public static BlockFieldDescriptor CoatNormalTS = new BlockFieldDescriptor(SurfaceDescription.name, "CoatNormalTS", "Coat Normal (Tangent Space)", "SURFACEDESCRIPTION_COATNORMALTS",
new NormalControl(CoordinateSpace.Tangent), ShaderStage.Fragment);
public static BlockFieldDescriptor CoatNormalWS = new BlockFieldDescriptor(SurfaceDescription.name, "CoatNormalWS", "Coat Normal (World Space)", "SURFACEDESCRIPTION_COATNORMALWS",
new NormalControl(CoordinateSpace.Tangent), ShaderStage.Fragment);
public static BlockFieldDescriptor DielectricIor = new BlockFieldDescriptor(SurfaceDescription.name, "DielectricIor", "Dielectric IOR", "SURFACEDESCRIPTION_DIELECTRICIOR",
new FloatControl(1.5f), ShaderStage.Fragment);
Expand Down