浏览代码
Merge remote-tracking branch 'origin/master' into HDRP_GraphicTests
Merge remote-tracking branch 'origin/master' into HDRP_GraphicTests
# Conflicts: # Tests/Scripts/Editor/GraphicTests/HDRenderPipeline/DebugViewController_Editor.cs.meta/main
Remy
7 年前
当前提交
2289f880
共有 54 个文件被更改,包括 2685 次插入 和 2683 次删除
-
1001ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl
-
80ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/CommonLighting.hlsl
-
406ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Debug.hlsl
-
14ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/Shadow.hlsl
-
44ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/ShadowAlgorithms.hlsl
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
-
616ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MaterialDebug.cs
-
35ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/LayeredLit/LayeredLitUI.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/BaseLitUI.cs
-
41ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
-
7ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Deferred.shader
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/HDAdditionalLightData.cs
-
76ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightEvaluation.hlsl
-
25ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/Deferred.compute
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
-
12ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/Shadow.hlsl
-
22ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/Resources/VolumetricLighting.compute
-
7ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLit.shader
-
1001ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitData.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitTessellation.shader
-
290ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader
-
540ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitData.hlsl
-
520ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitProperties.hlsl
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitReference.hlsl
-
10ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader
-
19ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.compute
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Unlit/Unlit.shader
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/DefaultHDMaterial.mat
-
1ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPass.cs
-
17ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPass.cs.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassForward.hlsl
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassLightTransport.hlsl
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/TessellationShare.hlsl
-
23ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/VaryingMesh.hlsl
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/VertMesh.hlsl
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/OpaqueAtmosphericScattering.shader
-
2Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/3DObjects/CornelBox/Cornell Box.fbx.meta
-
2Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/3DObjects/Sphere/Sphere.fbx.meta
-
3Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/Materials/HDRP_Default_Material.mat
-
3Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1210_Lit_BentNormal/BentNormal_Tangent.mat
-
3Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1210_Lit_BentNormal/Green_Emissive.mat
-
3Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1210_Lit_BentNormal/Red_Emissive.mat
-
2Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Assets/CommonAssets/Cornell Box.fbx.meta
-
2Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/040_UpgradeScene/Models/Environment/Floor.fbx.meta
-
11Tests/Scripts/Editor.meta
-
2Tests/Scripts/Editor/GraphicTests/HDRenderPipeline/DebugViewController_Editor.cs.meta
-
342ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/UnityInstancing.hlsl
-
9ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/UnityInstancing.hlsl.meta
-
86ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitBuiltinData.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitBuiltinData.hlsl.meta
1001
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
namespace Attributes |
|||
{ |
|||
// 0 is reserved!
|
|||
[GenerateHLSL] |
|||
public enum DebugViewVarying |
|||
{ |
|||
None = 0, |
|||
Texcoord0 = 1, |
|||
Texcoord1, |
|||
Texcoord2, |
|||
Texcoord3, |
|||
VertexTangentWS, |
|||
VertexBitangentWS, |
|||
VertexNormalWS, |
|||
VertexColor, |
|||
VertexColorAlpha, |
|||
Last, |
|||
}; |
|||
|
|||
// Number must be contiguous
|
|||
[GenerateHLSL] |
|||
public enum DebugViewGbuffer |
|||
{ |
|||
None = 0, |
|||
Depth = DebugViewVarying.Last, |
|||
BakeDiffuseLightingWithAlbedoPlusEmissive, |
|||
BakeShadowMask0, |
|||
BakeShadowMask1, |
|||
BakeShadowMask2, |
|||
BakeShadowMask3, |
|||
Last, |
|||
} |
|||
|
|||
// Number must be contiguous
|
|||
[GenerateHLSL] |
|||
public enum DebugViewProperties |
|||
{ |
|||
None = 0, |
|||
Tessellation = DebugViewGbuffer.Last, |
|||
PixelDisplacement, |
|||
VertexDisplacement, |
|||
TessellationDisplacement, |
|||
DepthOffset, |
|||
Lightmap, |
|||
Last, |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class MaterialDebugSettings |
|||
{ |
|||
private static bool isDebugViewMaterialInit = false; |
|||
|
|||
public static GUIContent[] debugViewMaterialStrings = null; |
|||
public static int[] debugViewMaterialValues = null; |
|||
public static GUIContent[] debugViewEngineStrings = null; |
|||
public static int[] debugViewEngineValues = null; |
|||
public static GUIContent[] debugViewMaterialVaryingStrings = null; |
|||
public static int[] debugViewMaterialVaryingValues = null; |
|||
public static GUIContent[] debugViewMaterialPropertiesStrings = null; |
|||
public static int[] debugViewMaterialPropertiesValues = null; |
|||
public static GUIContent[] debugViewMaterialTextureStrings = null; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
namespace Attributes |
|||
{ |
|||
// 0 is reserved!
|
|||
[GenerateHLSL] |
|||
public enum DebugViewVarying |
|||
{ |
|||
None = 0, |
|||
Texcoord0 = 1, |
|||
Texcoord1, |
|||
Texcoord2, |
|||
Texcoord3, |
|||
VertexTangentWS, |
|||
VertexBitangentWS, |
|||
VertexNormalWS, |
|||
VertexColor, |
|||
VertexColorAlpha, |
|||
Last, |
|||
}; |
|||
|
|||
// Number must be contiguous
|
|||
[GenerateHLSL] |
|||
public enum DebugViewGbuffer |
|||
{ |
|||
None = 0, |
|||
Depth = DebugViewVarying.Last, |
|||
BakeDiffuseLightingWithAlbedoPlusEmissive, |
|||
BakeShadowMask0, |
|||
BakeShadowMask1, |
|||
BakeShadowMask2, |
|||
BakeShadowMask3, |
|||
Last, |
|||
} |
|||
|
|||
// Number must be contiguous
|
|||
[GenerateHLSL] |
|||
public enum DebugViewProperties |
|||
{ |
|||
None = 0, |
|||
Tessellation = DebugViewGbuffer.Last, |
|||
PixelDisplacement, |
|||
VertexDisplacement, |
|||
TessellationDisplacement, |
|||
DepthOffset, |
|||
Lightmap, |
|||
Last, |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class MaterialDebugSettings |
|||
{ |
|||
private static bool isDebugViewMaterialInit = false; |
|||
|
|||
public static GUIContent[] debugViewMaterialStrings = null; |
|||
public static int[] debugViewMaterialValues = null; |
|||
public static GUIContent[] debugViewEngineStrings = null; |
|||
public static int[] debugViewEngineValues = null; |
|||
public static GUIContent[] debugViewMaterialVaryingStrings = null; |
|||
public static int[] debugViewMaterialVaryingValues = null; |
|||
public static GUIContent[] debugViewMaterialPropertiesStrings = null; |
|||
public static int[] debugViewMaterialPropertiesValues = null; |
|||
public static GUIContent[] debugViewMaterialTextureStrings = null; |
|||
public static GUIContent[] debugViewMaterialGBufferStrings = null; |
|||
public static int[] debugViewMaterialGBufferValues = null; |
|||
|
|||
public MaterialDebugSettings() |
|||
{ |
|||
BuildDebugRepresentation(); |
|||
} |
|||
|
|||
// className include the additional "/"
|
|||
void FillWithProperties(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, string className, ref int index) |
|||
{ |
|||
var attributes = type.GetCustomAttributes(true); |
|||
// Get attribute to get the start number of the value for the enum
|
|||
var attr = attributes[0] as GenerateHLSL; |
|||
|
|||
if (!attr.needParamDebug) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var fields = type.GetFields(); |
|||
|
|||
var localIndex = 0; |
|||
foreach (var field in fields) |
|||
{ |
|||
var fieldName = field.Name; |
|||
|
|||
// Check if the display name have been override by the users
|
|||
if (Attribute.IsDefined(field, typeof(SurfaceDataAttributes))) |
|||
{ |
|||
var propertyAttr = (SurfaceDataAttributes[])field.GetCustomAttributes(typeof(SurfaceDataAttributes), false); |
|||
if (propertyAttr[0].displayName != "") |
|||
{ |
|||
fieldName = propertyAttr[0].displayName; |
|||
} |
|||
} |
|||
|
|||
fieldName = className + fieldName; |
|||
|
|||
debugViewMaterialStrings[index] = new GUIContent(fieldName); |
|||
debugViewMaterialValues[index] = attr.paramDefinesStart + (int)localIndex; |
|||
index++; |
|||
localIndex++; |
|||
} |
|||
} |
|||
|
|||
void FillWithPropertiesEnum(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, string prefix, ref int index) |
|||
{ |
|||
var names = Enum.GetNames(type); |
|||
|
|||
var localIndex = 0; |
|||
foreach (var value in Enum.GetValues(type)) |
|||
{ |
|||
var valueName = prefix + names[localIndex]; |
|||
|
|||
debugViewMaterialStrings[index] = new GUIContent(valueName); |
|||
debugViewMaterialValues[index] = (int)value; |
|||
index++; |
|||
localIndex++; |
|||
} |
|||
} |
|||
|
|||
public class MaterialItem |
|||
{ |
|||
public String className; |
|||
public Type surfaceDataType; |
|||
public Type bsdfDataType; |
|||
}; |
|||
|
|||
void BuildDebugRepresentation() |
|||
{ |
|||
if (!isDebugViewMaterialInit) |
|||
{ |
|||
List<RenderPipelineMaterial> materialList = HDUtils.GetRenderPipelineMaterialList(); |
|||
|
|||
// TODO: Share this code to retrieve deferred material with HDRenderPipeline
|
|||
// Find first material that have non 0 Gbuffer count and assign it as deferredMaterial
|
|||
Type bsdfDataDeferredType = null; |
|||
foreach (RenderPipelineMaterial material in materialList) |
|||
{ |
|||
if (material.GetMaterialGBufferCount() > 0) |
|||
{ |
|||
bsdfDataDeferredType = material.GetType().GetNestedType("BSDFData"); |
|||
} |
|||
} |
|||
|
|||
// TODO: Handle the case of no Gbuffer material
|
|||
Debug.Assert(bsdfDataDeferredType != null); |
|||
|
|||
List<MaterialItem> materialItems = new List<MaterialItem>(); |
|||
|
|||
int numSurfaceDataFields = 0; |
|||
int numBSDFDataFields = 0; |
|||
foreach (RenderPipelineMaterial material in materialList) |
|||
{ |
|||
MaterialItem item = new MaterialItem(); |
|||
|
|||
item.className = material.GetType().Name + "/"; |
|||
|
|||
item.surfaceDataType = material.GetType().GetNestedType("SurfaceData"); |
|||
numSurfaceDataFields += item.surfaceDataType.GetFields().Length; |
|||
|
|||
item.bsdfDataType = material.GetType().GetNestedType("BSDFData"); |
|||
numBSDFDataFields += item.bsdfDataType.GetFields().Length; |
|||
|
|||
materialItems.Add(item); |
|||
} |
|||
|
|||
// Material properties debug
|
|||
var num = typeof(Builtin.BuiltinData).GetFields().Length * materialList.Count // BuildtinData are duplicated for each material
|
|||
+ numSurfaceDataFields + 1; // +1 for None case
|
|||
|
|||
debugViewMaterialStrings = new GUIContent[num]; |
|||
debugViewMaterialValues = new int[num]; |
|||
// Special case for None since it cannot be inferred from SurfaceData/BuiltinData
|
|||
debugViewMaterialStrings[0] = new GUIContent("None"); |
|||
debugViewMaterialValues[0] = 0; |
|||
var index = 1; |
|||
// 0 is a reserved number and should not be used (allow to track error)
|
|||
foreach (MaterialItem item in materialItems) |
|||
{ |
|||
// BuiltinData are duplicated for each material
|
|||
FillWithProperties(typeof(Builtin.BuiltinData), debugViewMaterialStrings, debugViewMaterialValues, item.className, ref index); |
|||
FillWithProperties(item.surfaceDataType, debugViewMaterialStrings, debugViewMaterialValues, item.className, ref index); |
|||
} |
|||
|
|||
// Engine properties debug
|
|||
num = numBSDFDataFields + 1; // +1 for None case
|
|||
debugViewEngineStrings = new GUIContent[num]; |
|||
debugViewEngineValues = new int[num]; |
|||
// 0 is a reserved number and should not be used (allow to track error)
|
|||
debugViewEngineStrings[0] = new GUIContent("None"); |
|||
debugViewEngineValues[0] = 0; |
|||
index = 1; |
|||
foreach (MaterialItem item in materialItems) |
|||
{ |
|||
FillWithProperties(item.bsdfDataType, debugViewEngineStrings, debugViewEngineValues, item.className, ref index); |
|||
} |
|||
|
|||
// Attributes debug
|
|||
var varyingNames = Enum.GetNames(typeof(Attributes.DebugViewVarying)); |
|||
debugViewMaterialVaryingStrings = new GUIContent[varyingNames.Length]; |
|||
debugViewMaterialVaryingValues = new int[varyingNames.Length]; |
|||
index = 0; |
|||
FillWithPropertiesEnum(typeof(Attributes.DebugViewVarying), debugViewMaterialVaryingStrings, debugViewMaterialVaryingValues, "", ref index); |
|||
|
|||
// Properties debug
|
|||
var propertiesNames = Enum.GetNames(typeof(Attributes.DebugViewProperties)); |
|||
debugViewMaterialPropertiesStrings = new GUIContent[propertiesNames.Length]; |
|||
debugViewMaterialPropertiesValues = new int[propertiesNames.Length]; |
|||
index = 0; |
|||
FillWithPropertiesEnum(typeof(Attributes.DebugViewProperties), debugViewMaterialPropertiesStrings, debugViewMaterialPropertiesValues, "", ref index); |
|||
|
|||
// Gbuffer debug
|
|||
var gbufferNames = Enum.GetNames(typeof(Attributes.DebugViewGbuffer)); |
|||
debugViewMaterialGBufferStrings = new GUIContent[gbufferNames.Length + bsdfDataDeferredType.GetFields().Length]; |
|||
debugViewMaterialGBufferValues = new int[gbufferNames.Length + bsdfDataDeferredType.GetFields().Length]; |
|||
index = 0; |
|||
FillWithPropertiesEnum(typeof(Attributes.DebugViewGbuffer), debugViewMaterialGBufferStrings, debugViewMaterialGBufferValues, "", ref index); |
|||
FillWithProperties(typeof(Lit.BSDFData), debugViewMaterialGBufferStrings, debugViewMaterialGBufferValues, "", ref index); |
|||
|
|||
isDebugViewMaterialInit = true; |
|||
} |
|||
} |
|||
|
|||
public int debugViewMaterial { get { return m_DebugViewMaterial; } } |
|||
public int debugViewEngine { get { return m_DebugViewEngine; } } |
|||
public Attributes.DebugViewVarying debugViewVarying { get { return m_DebugViewVarying; } } |
|||
public Attributes.DebugViewProperties debugViewProperties { get { return m_DebugViewProperties; } } |
|||
public int debugViewGBuffer { get { return m_DebugViewGBuffer; } } |
|||
|
|||
int m_DebugViewMaterial = 0; // No enum there because everything is generated from materials.
|
|||
int m_DebugViewEngine = 0; // No enum there because everything is generated from BSDFData
|
|||
Attributes.DebugViewVarying m_DebugViewVarying = Attributes.DebugViewVarying.None; |
|||
Attributes.DebugViewProperties m_DebugViewProperties = Attributes.DebugViewProperties.None; |
|||
int m_DebugViewGBuffer = 0; // Can't use GBuffer enum here because the values are actually split between this enum and values from Lit.BSDFData
|
|||
|
|||
public int GetDebugMaterialIndex() |
|||
{ |
|||
// This value is used in the shader for the actual debug display.
|
|||
// There is only one uniform parameter for that so we just add all of them
|
|||
// They are all mutually exclusive so return the sum will return the right index.
|
|||
return m_DebugViewGBuffer + m_DebugViewMaterial + m_DebugViewEngine + (int)m_DebugViewVarying + (int)m_DebugViewProperties; |
|||
} |
|||
|
|||
public void DisableMaterialDebug() |
|||
{ |
|||
m_DebugViewMaterial = 0; |
|||
m_DebugViewEngine = 0; |
|||
m_DebugViewVarying = Attributes.DebugViewVarying.None; |
|||
m_DebugViewProperties = Attributes.DebugViewProperties.None; |
|||
m_DebugViewGBuffer = 0; |
|||
} |
|||
|
|||
public void SetDebugViewMaterial(int value) |
|||
{ |
|||
if (value != 0) |
|||
DisableMaterialDebug(); |
|||
m_DebugViewMaterial = value; |
|||
} |
|||
|
|||
public void SetDebugViewEngine(int value) |
|||
{ |
|||
if (value != 0) |
|||
DisableMaterialDebug(); |
|||
m_DebugViewEngine = value; |
|||
} |
|||
|
|||
public void SetDebugViewVarying(Attributes.DebugViewVarying value) |
|||
{ |
|||
if (value != 0) |
|||
DisableMaterialDebug(); |
|||
m_DebugViewVarying = value; |
|||
} |
|||
public void SetDebugViewProperties(Attributes.DebugViewProperties value) |
|||
{ |
|||
if (value != 0) |
|||
DisableMaterialDebug(); |
|||
m_DebugViewProperties = value; |
|||
} |
|||
|
|||
public void SetDebugViewGBuffer(int value) |
|||
{ |
|||
if (value != 0) |
|||
DisableMaterialDebug(); |
|||
m_DebugViewGBuffer = value; |
|||
} |
|||
|
|||
|
|||
public bool IsDebugGBufferEnabled() |
|||
{ |
|||
return m_DebugViewGBuffer != 0; |
|||
} |
|||
|
|||
public bool IsDebugDisplayEnabled() |
|||
{ |
|||
return (m_DebugViewEngine != 0 || m_DebugViewMaterial != 0 || m_DebugViewVarying != Attributes.DebugViewVarying.None || m_DebugViewProperties != Attributes.DebugViewProperties.None || m_DebugViewGBuffer != 0); |
|||
} |
|||
} |
|||
} |
|||
public static GUIContent[] debugViewMaterialGBufferStrings = null; |
|||
public static int[] debugViewMaterialGBufferValues = null; |
|||
|
|||
public MaterialDebugSettings() |
|||
{ |
|||
BuildDebugRepresentation(); |
|||
} |
|||
|
|||
// className include the additional "/"
|
|||
void FillWithProperties(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, string className, ref int index) |
|||
{ |
|||
var attributes = type.GetCustomAttributes(true); |
|||
// Get attribute to get the start number of the value for the enum
|
|||
var attr = attributes[0] as GenerateHLSL; |
|||
|
|||
if (!attr.needParamDebug) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var fields = type.GetFields(); |
|||
|
|||
var localIndex = 0; |
|||
foreach (var field in fields) |
|||
{ |
|||
var fieldName = field.Name; |
|||
|
|||
// Check if the display name have been override by the users
|
|||
if (Attribute.IsDefined(field, typeof(SurfaceDataAttributes))) |
|||
{ |
|||
var propertyAttr = (SurfaceDataAttributes[])field.GetCustomAttributes(typeof(SurfaceDataAttributes), false); |
|||
if (propertyAttr[0].displayName != "") |
|||
{ |
|||
fieldName = propertyAttr[0].displayName; |
|||
} |
|||
} |
|||
|
|||
fieldName = className + fieldName; |
|||
|
|||
debugViewMaterialStrings[index] = new GUIContent(fieldName); |
|||
debugViewMaterialValues[index] = attr.paramDefinesStart + (int)localIndex; |
|||
index++; |
|||
localIndex++; |
|||
} |
|||
} |
|||
|
|||
void FillWithPropertiesEnum(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, string prefix, ref int index) |
|||
{ |
|||
var names = Enum.GetNames(type); |
|||
|
|||
var localIndex = 0; |
|||
foreach (var value in Enum.GetValues(type)) |
|||
{ |
|||
var valueName = prefix + names[localIndex]; |
|||
|
|||
debugViewMaterialStrings[index] = new GUIContent(valueName); |
|||
debugViewMaterialValues[index] = (int)value; |
|||
index++; |
|||
localIndex++; |
|||
} |
|||
} |
|||
|
|||
public class MaterialItem |
|||
{ |
|||
public String className; |
|||
public Type surfaceDataType; |
|||
public Type bsdfDataType; |
|||
}; |
|||
|
|||
void BuildDebugRepresentation() |
|||
{ |
|||
if (!isDebugViewMaterialInit) |
|||
{ |
|||
List<RenderPipelineMaterial> materialList = HDUtils.GetRenderPipelineMaterialList(); |
|||
|
|||
// TODO: Share this code to retrieve deferred material with HDRenderPipeline
|
|||
// Find first material that have non 0 Gbuffer count and assign it as deferredMaterial
|
|||
Type bsdfDataDeferredType = null; |
|||
foreach (RenderPipelineMaterial material in materialList) |
|||
{ |
|||
if (material.GetMaterialGBufferCount() > 0) |
|||
{ |
|||
bsdfDataDeferredType = material.GetType().GetNestedType("BSDFData"); |
|||
} |
|||
} |
|||
|
|||
// TODO: Handle the case of no Gbuffer material
|
|||
Debug.Assert(bsdfDataDeferredType != null); |
|||
|
|||
List<MaterialItem> materialItems = new List<MaterialItem>(); |
|||
|
|||
int numSurfaceDataFields = 0; |
|||
int numBSDFDataFields = 0; |
|||
foreach (RenderPipelineMaterial material in materialList) |
|||
{ |
|||
MaterialItem item = new MaterialItem(); |
|||
|
|||
item.className = material.GetType().Name + "/"; |
|||
|
|||
item.surfaceDataType = material.GetType().GetNestedType("SurfaceData"); |
|||
numSurfaceDataFields += item.surfaceDataType.GetFields().Length; |
|||
|
|||
item.bsdfDataType = material.GetType().GetNestedType("BSDFData"); |
|||
numBSDFDataFields += item.bsdfDataType.GetFields().Length; |
|||
|
|||
materialItems.Add(item); |
|||
} |
|||
|
|||
// Material properties debug
|
|||
var num = typeof(Builtin.BuiltinData).GetFields().Length * materialList.Count // BuildtinData are duplicated for each material
|
|||
+ numSurfaceDataFields + 1; // +1 for None case
|
|||
|
|||
debugViewMaterialStrings = new GUIContent[num]; |
|||
debugViewMaterialValues = new int[num]; |
|||
// Special case for None since it cannot be inferred from SurfaceData/BuiltinData
|
|||
debugViewMaterialStrings[0] = new GUIContent("None"); |
|||
debugViewMaterialValues[0] = 0; |
|||
var index = 1; |
|||
// 0 is a reserved number and should not be used (allow to track error)
|
|||
foreach (MaterialItem item in materialItems) |
|||
{ |
|||
// BuiltinData are duplicated for each material
|
|||
FillWithProperties(typeof(Builtin.BuiltinData), debugViewMaterialStrings, debugViewMaterialValues, item.className, ref index); |
|||
FillWithProperties(item.surfaceDataType, debugViewMaterialStrings, debugViewMaterialValues, item.className, ref index); |
|||
} |
|||
|
|||
// Engine properties debug
|
|||
num = numBSDFDataFields + 1; // +1 for None case
|
|||
debugViewEngineStrings = new GUIContent[num]; |
|||
debugViewEngineValues = new int[num]; |
|||
// 0 is a reserved number and should not be used (allow to track error)
|
|||
debugViewEngineStrings[0] = new GUIContent("None"); |
|||
debugViewEngineValues[0] = 0; |
|||
index = 1; |
|||
foreach (MaterialItem item in materialItems) |
|||
{ |
|||
FillWithProperties(item.bsdfDataType, debugViewEngineStrings, debugViewEngineValues, item.className, ref index); |
|||
} |
|||
|
|||
// Attributes debug
|
|||
var varyingNames = Enum.GetNames(typeof(Attributes.DebugViewVarying)); |
|||
debugViewMaterialVaryingStrings = new GUIContent[varyingNames.Length]; |
|||
debugViewMaterialVaryingValues = new int[varyingNames.Length]; |
|||
index = 0; |
|||
FillWithPropertiesEnum(typeof(Attributes.DebugViewVarying), debugViewMaterialVaryingStrings, debugViewMaterialVaryingValues, "", ref index); |
|||
|
|||
// Properties debug
|
|||
var propertiesNames = Enum.GetNames(typeof(Attributes.DebugViewProperties)); |
|||
debugViewMaterialPropertiesStrings = new GUIContent[propertiesNames.Length]; |
|||
debugViewMaterialPropertiesValues = new int[propertiesNames.Length]; |
|||
index = 0; |
|||
FillWithPropertiesEnum(typeof(Attributes.DebugViewProperties), debugViewMaterialPropertiesStrings, debugViewMaterialPropertiesValues, "", ref index); |
|||
|
|||
// Gbuffer debug
|
|||
var gbufferNames = Enum.GetNames(typeof(Attributes.DebugViewGbuffer)); |
|||
debugViewMaterialGBufferStrings = new GUIContent[gbufferNames.Length + bsdfDataDeferredType.GetFields().Length]; |
|||
debugViewMaterialGBufferValues = new int[gbufferNames.Length + bsdfDataDeferredType.GetFields().Length]; |
|||
index = 0; |
|||
FillWithPropertiesEnum(typeof(Attributes.DebugViewGbuffer), debugViewMaterialGBufferStrings, debugViewMaterialGBufferValues, "", ref index); |
|||
FillWithProperties(typeof(Lit.BSDFData), debugViewMaterialGBufferStrings, debugViewMaterialGBufferValues, "", ref index); |
|||
|
|||
isDebugViewMaterialInit = true; |
|||
} |
|||
} |
|||
|
|||
public int debugViewMaterial { get { return m_DebugViewMaterial; } } |
|||
public int debugViewEngine { get { return m_DebugViewEngine; } } |
|||
public Attributes.DebugViewVarying debugViewVarying { get { return m_DebugViewVarying; } } |
|||
public Attributes.DebugViewProperties debugViewProperties { get { return m_DebugViewProperties; } } |
|||
public int debugViewGBuffer { get { return m_DebugViewGBuffer; } } |
|||
|
|||
int m_DebugViewMaterial = 0; // No enum there because everything is generated from materials.
|
|||
int m_DebugViewEngine = 0; // No enum there because everything is generated from BSDFData
|
|||
Attributes.DebugViewVarying m_DebugViewVarying = Attributes.DebugViewVarying.None; |
|||
Attributes.DebugViewProperties m_DebugViewProperties = Attributes.DebugViewProperties.None; |
|||
int m_DebugViewGBuffer = 0; // Can't use GBuffer enum here because the values are actually split between this enum and values from Lit.BSDFData
|
|||
|
|||
public int GetDebugMaterialIndex() |
|||
{ |
|||
// This value is used in the shader for the actual debug display.
|
|||
// There is only one uniform parameter for that so we just add all of them
|
|||
// They are all mutually exclusive so return the sum will return the right index.
|
|||
return m_DebugViewGBuffer + m_DebugViewMaterial + m_DebugViewEngine + (int)m_DebugViewVarying + (int)m_DebugViewProperties; |
|||
} |
|||
|
|||
public void DisableMaterialDebug() |
|||
{ |
|||
m_DebugViewMaterial = 0; |
|||
m_DebugViewEngine = 0; |
|||
m_DebugViewVarying = Attributes.DebugViewVarying.None; |
|||
m_DebugViewProperties = Attributes.DebugViewProperties.None; |
|||
m_DebugViewGBuffer = 0; |
|||
} |
|||
|
|||
public void SetDebugViewMaterial(int value) |
|||
{ |
|||
if (value != 0) |
|||
DisableMaterialDebug(); |
|||
m_DebugViewMaterial = value; |
|||
} |
|||
|
|||
public void SetDebugViewEngine(int value) |
|||
{ |
|||
if (value != 0) |
|||
DisableMaterialDebug(); |
|||
m_DebugViewEngine = value; |
|||
} |
|||
|
|||
public void SetDebugViewVarying(Attributes.DebugViewVarying value) |
|||
{ |
|||
if (value != 0) |
|||
DisableMaterialDebug(); |
|||
m_DebugViewVarying = value; |
|||
} |
|||
public void SetDebugViewProperties(Attributes.DebugViewProperties value) |
|||
{ |
|||
if (value != 0) |
|||
DisableMaterialDebug(); |
|||
m_DebugViewProperties = value; |
|||
} |
|||
|
|||
public void SetDebugViewGBuffer(int value) |
|||
{ |
|||
if (value != 0) |
|||
DisableMaterialDebug(); |
|||
m_DebugViewGBuffer = value; |
|||
} |
|||
|
|||
|
|||
public bool IsDebugGBufferEnabled() |
|||
{ |
|||
return m_DebugViewGBuffer != 0; |
|||
} |
|||
|
|||
public bool IsDebugDisplayEnabled() |
|||
{ |
|||
return (m_DebugViewEngine != 0 || m_DebugViewMaterial != 0 || m_DebugViewVarying != Attributes.DebugViewVarying.None || m_DebugViewProperties != Attributes.DebugViewProperties.None || m_DebugViewGBuffer != 0); |
|||
} |
|||
} |
|||
} |
1001
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitData.hlsl
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Builtin data function |
|||
//------------------------------------------------------------------------------------- |
|||
#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl" |
|||
#include "../MaterialUtilities.hlsl" |
|||
#include "../Decal/DecalUtilities.hlsl" |
|||
|
|||
// TODO: move this function to commonLighting.hlsl once validated it work correctly |
|||
float GetSpecularOcclusionFromBentAO(float3 V, float3 bentNormalWS, SurfaceData surfaceData) |
|||
{ |
|||
// Retrieve cone angle |
|||
// Ambient occlusion is cosine weighted, thus use following equation. See slide 129 |
|||
float cosAv = sqrt(1.0 - surfaceData.ambientOcclusion); |
|||
float roughness = max(PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness), 0.01); // Clamp to 0.01 to avoid edge cases |
|||
float cosAs = exp2((-log(10.0)/log(2.0)) * Sq(roughness)); |
|||
float cosB = dot(bentNormalWS, reflect(-V, surfaceData.normalWS)); |
|||
|
|||
return SphericalCapIntersectionSolidArea(cosAv, cosAs, cosB) / (TWO_PI * (1.0 - cosAs)); |
|||
} |
|||
|
|||
void GetBuiltinData(FragInputs input, SurfaceData surfaceData, float alpha, float3 bentNormalWS, float depthOffset, out BuiltinData builtinData) |
|||
{ |
|||
// Builtin Data |
|||
builtinData.opacity = alpha; |
|||
|
|||
// TODO: Sample lightmap/lightprobe/volume proxy |
|||
// This should also handle projective lightmap |
|||
builtinData.bakeDiffuseLighting = SampleBakedGI(input.positionWS, bentNormalWS, input.texCoord1, input.texCoord2); |
|||
|
|||
// It is safe to call this function here as surfaceData have been filled |
|||
// We want to know if we must enable transmission on GI for SSS material, if the material have no SSS, this code will be remove by the compiler. |
|||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData); |
|||
if (HasMaterialFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION)) |
|||
{ |
|||
// For now simply recall the function with inverted normal, the compiler should be able to optimize the lightmap case to not resample the directional lightmap |
|||
// however it will not optimize the lightprobe case due to the proxy volume relying on dynamic if (we rely must get right of this dynamic if), not a problem for SH9, but a problem for proxy volume. |
|||
// TODO: optimize more this code. |
|||
// Add GI transmission contribution by resampling the GI for inverted vertex normal |
|||
builtinData.bakeDiffuseLighting += SampleBakedGI(input.positionWS, -input.worldToTangent[2], input.texCoord1, input.texCoord2) * bsdfData.transmittance; |
|||
} |
|||
|
|||
#ifdef SHADOWS_SHADOWMASK |
|||
float4 shadowMask = SampleShadowMask(input.positionWS, input.texCoord1); |
|||
builtinData.shadowMask0 = shadowMask.x; |
|||
builtinData.shadowMask1 = shadowMask.y; |
|||
builtinData.shadowMask2 = shadowMask.z; |
|||
builtinData.shadowMask3 = shadowMask.w; |
|||
#else |
|||
builtinData.shadowMask0 = 0.0; |
|||
builtinData.shadowMask1 = 0.0; |
|||
builtinData.shadowMask2 = 0.0; |
|||
builtinData.shadowMask3 = 0.0; |
|||
#endif |
|||
|
|||
// Emissive Intensity is only use here, but is part of BuiltinData to enforce UI parameters as we want the users to fill one color and one intensity |
|||
builtinData.emissiveIntensity = _EmissiveIntensity; // We still store intensity here so we can reuse it with debug code |
|||
|
|||
builtinData.emissiveColor = _EmissiveColor * builtinData.emissiveIntensity * lerp(float3(1.0, 1.0, 1.0), surfaceData.baseColor.rgb, _AlbedoAffectEmissive); |
|||
#ifdef _EMISSIVE_COLOR_MAP |
|||
builtinData.emissiveColor *= SAMPLE_TEXTURE2D(_EmissiveColorMap, sampler_EmissiveColorMap, TRANSFORM_TEX(input.texCoord0, _EmissiveColorMap)).rgb; |
|||
#endif |
|||
|
|||
builtinData.velocity = float2(0.0, 0.0); |
|||
|
|||
#if (SHADERPASS == SHADERPASS_DISTORTION) || defined(DEBUG_DISPLAY) |
|||
float3 distortion = SAMPLE_TEXTURE2D(_DistortionVectorMap, sampler_DistortionVectorMap, input.texCoord0).rgb; |
|||
distortion.rg = distortion.rg * _DistortionVectorScale.xx + _DistortionVectorBias.xx; |
|||
builtinData.distortion = distortion.rg * _DistortionScale; |
|||
builtinData.distortionBlur = clamp(distortion.b * _DistortionBlurScale, 0.0, 1.0) * (_DistortionBlurRemapMax - _DistortionBlurRemapMin) + _DistortionBlurRemapMin; |
|||
#else |
|||
builtinData.distortion = float2(0.0, 0.0); |
|||
builtinData.distortionBlur = 0.0; |
|||
#endif |
|||
|
|||
builtinData.depthOffset = depthOffset; |
|||
} |
|||
|
|||
// Struct that gather UVMapping info of all layers + common calculation |
|||
// This is use to abstract the mapping that can differ on layers |
|||
struct LayerTexCoord |
|||
{ |
|||
#ifndef LAYERED_LIT_SHADER |
|||
UVMapping base; |
|||
UVMapping details; |
|||
#else |
|||
// Regular texcoord |
|||
UVMapping base0; |
|||
UVMapping base1; |
|||
UVMapping base2; |
|||
UVMapping base3; |
|||
|
|||
UVMapping details0; |
|||
UVMapping details1; |
|||
UVMapping details2; |
|||
UVMapping details3; |
|||
|
|||
// Dedicated for blend mask |
|||
UVMapping blendMask; |
|||
#endif |
|||
|
|||
// Store information that will be share by all UVMapping |
|||
float3 vertexNormalWS; // TODO: store also object normal map for object triplanar |
|||
float3 triplanarWeights; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
// tangent basis for each UVSet - up to 4 for now |
|||
float3 vertexTangentWS0, vertexBitangentWS0; |
|||
float3 vertexTangentWS1, vertexBitangentWS1; |
|||
float3 vertexTangentWS2, vertexBitangentWS2; |
|||
float3 vertexTangentWS3, vertexBitangentWS3; |
|||
#endif |
|||
}; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
void GenerateLayerTexCoordBasisTB(FragInputs input, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
float3 vertexNormalWS = input.worldToTangent[2]; |
|||
|
|||
layerTexCoord.vertexTangentWS0 = input.worldToTangent[0]; |
|||
layerTexCoord.vertexBitangentWS0 = input.worldToTangent[1]; |
|||
|
|||
// TODO: We should use relative camera position here - This will be automatic when we will move to camera relative space. |
|||
float3 dPdx = ddx_fine(input.positionWS); |
|||
float3 dPdy = ddy_fine(input.positionWS); |
|||
|
|||
float3 sigmaX = dPdx - dot(dPdx, vertexNormalWS) * vertexNormalWS; |
|||
float3 sigmaY = dPdy - dot(dPdy, vertexNormalWS) * vertexNormalWS; |
|||
//float flipSign = dot(sigmaY, cross(vertexNormalWS, sigmaX) ) ? -1.0 : 1.0; |
|||
float flipSign = dot(dPdy, cross(vertexNormalWS, dPdx)) < 0.0 ? -1.0 : 1.0; // gives same as the commented out line above |
|||
|
|||
// TODO: Optimize! The compiler will not be able to remove the tangent space that are not use because it can't know due to our UVMapping constant we use for both base and details |
|||
// To solve this we should track which UVSet is use for normal mapping... Maybe not as simple as it sounds |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord1, layerTexCoord.vertexTangentWS1, layerTexCoord.vertexBitangentWS1); |
|||
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord2, layerTexCoord.vertexTangentWS2, layerTexCoord.vertexBitangentWS2); |
|||
#endif |
|||
#if defined(_REQUIRE_UV3) |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord3, layerTexCoord.vertexTangentWS3, layerTexCoord.vertexBitangentWS3); |
|||
#endif |
|||
} |
|||
#endif |
|||
|
|||
#ifndef LAYERED_LIT_SHADER |
|||
|
|||
// Want to use only one sampler for normalmap/bentnormalmap either we use OS or TS. And either we have normal map or bent normal or both. |
|||
#ifdef _NORMALMAP_TANGENT_SPACE |
|||
#if defined(_NORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_NormalMap |
|||
#elif defined(_BENTNORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_BentNormalMap |
|||
#endif |
|||
#else |
|||
#if defined(_NORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_NormalMapOS |
|||
#elif defined(_BENTNORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_BentNormalMapOS |
|||
#endif |
|||
#endif |
|||
|
|||
#define SAMPLER_DETAILMAP_IDX sampler_DetailMap |
|||
#define SAMPLER_MASKMAP_IDX sampler_MaskMap |
|||
#define SAMPLER_HEIGHTMAP_IDX sampler_HeightMap |
|||
|
|||
#define SAMPLER_SUBSURFACE_MASKMAP_IDX sampler_SubsurfaceMaskMap |
|||
#define SAMPLER_THICKNESSMAP_IDX sampler_ThicknessMap |
|||
|
|||
// include LitDataIndividualLayer to define GetSurfaceData |
|||
#define LAYER_INDEX 0 |
|||
#define ADD_IDX(Name) Name |
|||
#define ADD_ZERO_IDX(Name) Name |
|||
#ifdef _NORMALMAP |
|||
#define _NORMALMAP_IDX |
|||
#endif |
|||
#ifdef _NORMALMAP_TANGENT_SPACE |
|||
#define _NORMALMAP_TANGENT_SPACE_IDX |
|||
#endif |
|||
#ifdef _DETAIL_MAP |
|||
#define _DETAIL_MAP_IDX |
|||
#endif |
|||
#ifdef _SUBSURFACE_MASK_MAP |
|||
#define _SUBSURFACE_MASK_MAP_IDX |
|||
#endif |
|||
#ifdef _THICKNESSMAP |
|||
#define _THICKNESSMAP_IDX |
|||
#endif |
|||
#ifdef _MASKMAP |
|||
#define _MASKMAP_IDX |
|||
#endif |
|||
#ifdef _BENTNORMALMAP |
|||
#define _BENTNORMALMAP_IDX |
|||
#endif |
|||
#include "LitDataIndividualLayer.hlsl" |
|||
|
|||
// This maybe call directly by tessellation (domain) shader, thus all part regarding surface gradient must be done |
|||
// in function with FragInputs input as parameters |
|||
// layerTexCoord must have been initialize to 0 outside of this function |
|||
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3, |
|||
float3 positionWS, float3 vertexNormalWS, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
layerTexCoord.vertexNormalWS = vertexNormalWS; |
|||
layerTexCoord.triplanarWeights = ComputeTriplanarWeights(vertexNormalWS); |
|||
|
|||
int mappingType = UV_MAPPING_UVSET; |
|||
#if defined(_MAPPING_PLANAR) |
|||
mappingType = UV_MAPPING_PLANAR; |
|||
#elif defined(_MAPPING_TRIPLANAR) |
|||
mappingType = UV_MAPPING_TRIPLANAR; |
|||
#endif |
|||
|
|||
// Be sure that the compiler is aware that we don't use UV1 to UV3 for main layer so it can optimize code |
|||
ComputeLayerTexCoord( texCoord0, texCoord1, texCoord2, texCoord3, float4(1.0, 0.0, 0.0, 0.0), _UVDetailsMappingMask, |
|||
_BaseColorMap_ST.xy, _BaseColorMap_ST.zw, _DetailMap_ST.xy, _DetailMap_ST.zw, 1.0, _LinkDetailsWithBase, |
|||
positionWS, _TexWorldScale, |
|||
mappingType, layerTexCoord); |
|||
} |
|||
|
|||
// This is call only in this file |
|||
// layerTexCoord must have been initialize to 0 outside of this function |
|||
void GetLayerTexCoord(FragInputs input, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
#ifdef SURFACE_GRADIENT |
|||
GenerateLayerTexCoordBasisTB(input, layerTexCoord); |
|||
#endif |
|||
|
|||
GetLayerTexCoord( input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3, |
|||
input.positionWS, input.worldToTangent[2].xyz, layerTexCoord); |
|||
} |
|||
|
|||
#include "LitDataDisplacement.hlsl" |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group |
|||
LODDitheringTransition(posInput.positionSS, unity_LODFade.x); |
|||
#endif |
|||
|
|||
ApplyDoubleSidedFlipOrMirror(input); // Apply double sided flip on the vertex normal |
|||
|
|||
LayerTexCoord layerTexCoord; |
|||
ZERO_INITIALIZE(LayerTexCoord, layerTexCoord); |
|||
GetLayerTexCoord(input, layerTexCoord); |
|||
|
|||
float depthOffset = ApplyPerPixelDisplacement(input, V, layerTexCoord); |
|||
|
|||
#ifdef _DEPTHOFFSET_ON |
|||
ApplyDepthOffsetPositionInput(V, depthOffset, GetWorldToHClipMatrix(), posInput); |
|||
#endif |
|||
|
|||
// We perform the conversion to world of the normalTS outside of the GetSurfaceData |
|||
// so it allow us to correctly deal with detail normal map and optimize the code for the layered shaders |
|||
float3 normalTS; |
|||
float3 bentNormalTS; |
|||
float3 bentNormalWS; |
|||
float alpha = GetSurfaceData(input, layerTexCoord, surfaceData, normalTS, bentNormalTS); |
|||
GetNormalWS(input, V, normalTS, surfaceData.normalWS); |
|||
|
|||
// Ensure that the normal is front-facing. |
|||
float NdotV; |
|||
surfaceData.normalWS = GetViewReflectedNormal(surfaceData.normalWS, V, NdotV); |
|||
|
|||
// Use bent normal to sample GI if available |
|||
#ifdef _BENTNORMALMAP |
|||
GetNormalWS(input, V, bentNormalTS, bentNormalWS); |
|||
#else |
|||
bentNormalWS = surfaceData.normalWS; |
|||
#endif |
|||
|
|||
// By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. |
|||
// If user provide bent normal then we process a better term |
|||
#if defined(_BENTNORMALMAP) && defined(_ENABLESPECULAROCCLUSION) |
|||
// If we have bent normal and ambient occlusion, process a specular occlusion |
|||
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData); |
|||
#elif defined(_MASKMAP) |
|||
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(NdotV, surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); |
|||
#else |
|||
surfaceData.specularOcclusion = 1.0; |
|||
#endif |
|||
|
|||
// This is use with anisotropic material |
|||
surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); |
|||
|
|||
AddDecalContribution(posInput.positionSS, surfaceData); |
|||
|
|||
#if defined(DEBUG_DISPLAY) |
|||
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) |
|||
{ |
|||
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, layerTexCoord.base.uv, _BaseColorMap, _BaseColorMap_TexelSize, _BaseColorMap_MipInfo, surfaceData.baseColor); |
|||
surfaceData.metallic = 0; |
|||
} |
|||
#endif |
|||
|
|||
// Caution: surfaceData must be fully initialize before calling GetBuiltinData |
|||
GetBuiltinData(input, surfaceData, alpha, bentNormalWS, depthOffset, builtinData); |
|||
} |
|||
|
|||
#include "LitDataMeshModification.hlsl" |
|||
|
|||
#endif // #ifndef LAYERED_LIT_SHADER |
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Builtin data function |
|||
//------------------------------------------------------------------------------------- |
|||
#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl" |
|||
#include "../MaterialUtilities.hlsl" |
|||
#include "../Decal/DecalUtilities.hlsl" |
|||
|
|||
// TODO: move this function to commonLighting.hlsl once validated it work correctly |
|||
float GetSpecularOcclusionFromBentAO(float3 V, float3 bentNormalWS, SurfaceData surfaceData) |
|||
{ |
|||
// Retrieve cone angle |
|||
// Ambient occlusion is cosine weighted, thus use following equation. See slide 129 |
|||
float cosAv = sqrt(1.0 - surfaceData.ambientOcclusion); |
|||
float roughness = max(PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness), 0.01); // Clamp to 0.01 to avoid edge cases |
|||
float cosAs = exp2((-log(10.0)/log(2.0)) * Sq(roughness)); |
|||
float cosB = dot(bentNormalWS, reflect(-V, surfaceData.normalWS)); |
|||
|
|||
return SphericalCapIntersectionSolidArea(cosAv, cosAs, cosB) / (TWO_PI * (1.0 - cosAs)); |
|||
} |
|||
|
|||
// Struct that gather UVMapping info of all layers + common calculation |
|||
// This is use to abstract the mapping that can differ on layers |
|||
struct LayerTexCoord |
|||
{ |
|||
#ifndef LAYERED_LIT_SHADER |
|||
UVMapping base; |
|||
UVMapping details; |
|||
#else |
|||
// Regular texcoord |
|||
UVMapping base0; |
|||
UVMapping base1; |
|||
UVMapping base2; |
|||
UVMapping base3; |
|||
|
|||
UVMapping details0; |
|||
UVMapping details1; |
|||
UVMapping details2; |
|||
UVMapping details3; |
|||
|
|||
// Dedicated for blend mask |
|||
UVMapping blendMask; |
|||
#endif |
|||
|
|||
// Store information that will be share by all UVMapping |
|||
float3 vertexNormalWS; // TODO: store also object normal map for object triplanar |
|||
float3 triplanarWeights; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
// tangent basis for each UVSet - up to 4 for now |
|||
float3 vertexTangentWS0, vertexBitangentWS0; |
|||
float3 vertexTangentWS1, vertexBitangentWS1; |
|||
float3 vertexTangentWS2, vertexBitangentWS2; |
|||
float3 vertexTangentWS3, vertexBitangentWS3; |
|||
#endif |
|||
}; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
void GenerateLayerTexCoordBasisTB(FragInputs input, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
float3 vertexNormalWS = input.worldToTangent[2]; |
|||
|
|||
layerTexCoord.vertexTangentWS0 = input.worldToTangent[0]; |
|||
layerTexCoord.vertexBitangentWS0 = input.worldToTangent[1]; |
|||
|
|||
// TODO: We should use relative camera position here - This will be automatic when we will move to camera relative space. |
|||
float3 dPdx = ddx_fine(input.positionWS); |
|||
float3 dPdy = ddy_fine(input.positionWS); |
|||
|
|||
float3 sigmaX = dPdx - dot(dPdx, vertexNormalWS) * vertexNormalWS; |
|||
float3 sigmaY = dPdy - dot(dPdy, vertexNormalWS) * vertexNormalWS; |
|||
//float flipSign = dot(sigmaY, cross(vertexNormalWS, sigmaX) ) ? -1.0 : 1.0; |
|||
float flipSign = dot(dPdy, cross(vertexNormalWS, dPdx)) < 0.0 ? -1.0 : 1.0; // gives same as the commented out line above |
|||
|
|||
// TODO: Optimize! The compiler will not be able to remove the tangent space that are not use because it can't know due to our UVMapping constant we use for both base and details |
|||
// To solve this we should track which UVSet is use for normal mapping... Maybe not as simple as it sounds |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord1, layerTexCoord.vertexTangentWS1, layerTexCoord.vertexBitangentWS1); |
|||
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord2, layerTexCoord.vertexTangentWS2, layerTexCoord.vertexBitangentWS2); |
|||
#endif |
|||
#if defined(_REQUIRE_UV3) |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord3, layerTexCoord.vertexTangentWS3, layerTexCoord.vertexBitangentWS3); |
|||
#endif |
|||
} |
|||
#endif |
|||
|
|||
#ifndef LAYERED_LIT_SHADER |
|||
|
|||
// Want to use only one sampler for normalmap/bentnormalmap either we use OS or TS. And either we have normal map or bent normal or both. |
|||
#ifdef _NORMALMAP_TANGENT_SPACE |
|||
#if defined(_NORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_NormalMap |
|||
#elif defined(_BENTNORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_BentNormalMap |
|||
#endif |
|||
#else |
|||
#if defined(_NORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_NormalMapOS |
|||
#elif defined(_BENTNORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_BentNormalMapOS |
|||
#endif |
|||
#endif |
|||
|
|||
#define SAMPLER_DETAILMAP_IDX sampler_DetailMap |
|||
#define SAMPLER_MASKMAP_IDX sampler_MaskMap |
|||
#define SAMPLER_HEIGHTMAP_IDX sampler_HeightMap |
|||
|
|||
#define SAMPLER_SUBSURFACE_MASKMAP_IDX sampler_SubsurfaceMaskMap |
|||
#define SAMPLER_THICKNESSMAP_IDX sampler_ThicknessMap |
|||
|
|||
// include LitDataIndividualLayer to define GetSurfaceData |
|||
#define LAYER_INDEX 0 |
|||
#define ADD_IDX(Name) Name |
|||
#define ADD_ZERO_IDX(Name) Name |
|||
#ifdef _NORMALMAP |
|||
#define _NORMALMAP_IDX |
|||
#endif |
|||
#ifdef _NORMALMAP_TANGENT_SPACE |
|||
#define _NORMALMAP_TANGENT_SPACE_IDX |
|||
#endif |
|||
#ifdef _DETAIL_MAP |
|||
#define _DETAIL_MAP_IDX |
|||
#endif |
|||
#ifdef _SUBSURFACE_MASK_MAP |
|||
#define _SUBSURFACE_MASK_MAP_IDX |
|||
#endif |
|||
#ifdef _THICKNESSMAP |
|||
#define _THICKNESSMAP_IDX |
|||
#endif |
|||
#ifdef _MASKMAP |
|||
#define _MASKMAP_IDX |
|||
#endif |
|||
#ifdef _BENTNORMALMAP |
|||
#define _BENTNORMALMAP_IDX |
|||
#endif |
|||
#include "LitDataIndividualLayer.hlsl" |
|||
|
|||
// This maybe call directly by tessellation (domain) shader, thus all part regarding surface gradient must be done |
|||
// in function with FragInputs input as parameters |
|||
// layerTexCoord must have been initialize to 0 outside of this function |
|||
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3, |
|||
float3 positionWS, float3 vertexNormalWS, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
layerTexCoord.vertexNormalWS = vertexNormalWS; |
|||
layerTexCoord.triplanarWeights = ComputeTriplanarWeights(vertexNormalWS); |
|||
|
|||
int mappingType = UV_MAPPING_UVSET; |
|||
#if defined(_MAPPING_PLANAR) |
|||
mappingType = UV_MAPPING_PLANAR; |
|||
#elif defined(_MAPPING_TRIPLANAR) |
|||
mappingType = UV_MAPPING_TRIPLANAR; |
|||
#endif |
|||
|
|||
// Be sure that the compiler is aware that we don't use UV1 to UV3 for main layer so it can optimize code |
|||
ComputeLayerTexCoord( texCoord0, texCoord1, texCoord2, texCoord3, float4(1.0, 0.0, 0.0, 0.0), _UVDetailsMappingMask, |
|||
_BaseColorMap_ST.xy, _BaseColorMap_ST.zw, _DetailMap_ST.xy, _DetailMap_ST.zw, 1.0, _LinkDetailsWithBase, |
|||
positionWS, _TexWorldScale, |
|||
mappingType, layerTexCoord); |
|||
} |
|||
|
|||
// This is call only in this file |
|||
// layerTexCoord must have been initialize to 0 outside of this function |
|||
void GetLayerTexCoord(FragInputs input, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
#ifdef SURFACE_GRADIENT |
|||
GenerateLayerTexCoordBasisTB(input, layerTexCoord); |
|||
#endif |
|||
|
|||
GetLayerTexCoord( input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3, |
|||
input.positionWS, input.worldToTangent[2].xyz, layerTexCoord); |
|||
} |
|||
|
|||
#include "LitDataDisplacement.hlsl" |
|||
#include "LitBuiltinData.hlsl" |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group |
|||
LODDitheringTransition(posInput.positionSS, unity_LODFade.x); |
|||
#endif |
|||
|
|||
ApplyDoubleSidedFlipOrMirror(input); // Apply double sided flip on the vertex normal |
|||
|
|||
LayerTexCoord layerTexCoord; |
|||
ZERO_INITIALIZE(LayerTexCoord, layerTexCoord); |
|||
GetLayerTexCoord(input, layerTexCoord); |
|||
|
|||
float depthOffset = ApplyPerPixelDisplacement(input, V, layerTexCoord); |
|||
|
|||
#ifdef _DEPTHOFFSET_ON |
|||
ApplyDepthOffsetPositionInput(V, depthOffset, GetWorldToHClipMatrix(), posInput); |
|||
#endif |
|||
|
|||
// We perform the conversion to world of the normalTS outside of the GetSurfaceData |
|||
// so it allow us to correctly deal with detail normal map and optimize the code for the layered shaders |
|||
float3 normalTS; |
|||
float3 bentNormalTS; |
|||
float3 bentNormalWS; |
|||
float alpha = GetSurfaceData(input, layerTexCoord, surfaceData, normalTS, bentNormalTS); |
|||
GetNormalWS(input, V, normalTS, surfaceData.normalWS); |
|||
|
|||
// Ensure that the normal is front-facing. |
|||
float NdotV; |
|||
surfaceData.normalWS = GetViewReflectedNormal(surfaceData.normalWS, V, NdotV); |
|||
|
|||
// Use bent normal to sample GI if available |
|||
#ifdef _BENTNORMALMAP |
|||
GetNormalWS(input, V, bentNormalTS, bentNormalWS); |
|||
#else |
|||
bentNormalWS = surfaceData.normalWS; |
|||
#endif |
|||
|
|||
// By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. |
|||
// If user provide bent normal then we process a better term |
|||
#if defined(_BENTNORMALMAP) && defined(_ENABLESPECULAROCCLUSION) |
|||
// If we have bent normal and ambient occlusion, process a specular occlusion |
|||
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData); |
|||
#elif defined(_MASKMAP) |
|||
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(NdotV, surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); |
|||
#else |
|||
surfaceData.specularOcclusion = 1.0; |
|||
#endif |
|||
|
|||
// This is use with anisotropic material |
|||
surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); |
|||
|
|||
AddDecalContribution(posInput.positionSS, surfaceData); |
|||
|
|||
#if defined(DEBUG_DISPLAY) |
|||
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) |
|||
{ |
|||
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, layerTexCoord.base.uv, _BaseColorMap, _BaseColorMap_TexelSize, _BaseColorMap_MipInfo, surfaceData.baseColor); |
|||
surfaceData.metallic = 0; |
|||
} |
|||
#endif |
|||
|
|||
// Caution: surfaceData must be fully initialize before calling GetBuiltinData |
|||
GetBuiltinData(input, surfaceData, alpha, bentNormalWS, depthOffset, builtinData); |
|||
} |
|||
|
|||
#include "LitDataMeshModification.hlsl" |
|||
|
|||
#endif // #ifndef LAYERED_LIT_SHADER |
|
|||
// =========================================================================== |
|||
// WARNING: |
|||
// On PS4, texture/sampler declarations need to be outside of CBuffers |
|||
// Otherwise those parameters are not bound correctly at runtime. |
|||
// =========================================================================== |
|||
|
|||
TEXTURE2D(_DistortionVectorMap); |
|||
SAMPLER(sampler_DistortionVectorMap); |
|||
|
|||
TEXTURE2D(_EmissiveColorMap); |
|||
SAMPLER(sampler_EmissiveColorMap); |
|||
|
|||
#ifndef LAYERED_LIT_SHADER |
|||
|
|||
TEXTURE2D(_DiffuseLightingMap); |
|||
SAMPLER(sampler_DiffuseLightingMap); |
|||
|
|||
TEXTURE2D(_BaseColorMap); |
|||
SAMPLER(sampler_BaseColorMap); |
|||
|
|||
TEXTURE2D(_MaskMap); |
|||
SAMPLER(sampler_MaskMap); |
|||
TEXTURE2D(_BentNormalMap); // Reuse sampler from normal map |
|||
SAMPLER(sampler_BentNormalMap); |
|||
|
|||
TEXTURE2D(_NormalMap); |
|||
SAMPLER(sampler_NormalMap); |
|||
TEXTURE2D(_NormalMapOS); |
|||
SAMPLER(sampler_NormalMapOS); |
|||
|
|||
TEXTURE2D(_DetailMap); |
|||
SAMPLER(sampler_DetailMap); |
|||
|
|||
TEXTURE2D(_HeightMap); |
|||
SAMPLER(sampler_HeightMap); |
|||
|
|||
TEXTURE2D(_TangentMap); |
|||
SAMPLER(sampler_TangentMap); |
|||
TEXTURE2D(_TangentMapOS); |
|||
SAMPLER(sampler_TangentMapOS); |
|||
|
|||
TEXTURE2D(_AnisotropyMap); |
|||
SAMPLER(sampler_AnisotropyMap); |
|||
|
|||
TEXTURE2D(_SubsurfaceMaskMap); |
|||
SAMPLER(sampler_SubsurfaceMaskMap); |
|||
TEXTURE2D(_ThicknessMap); |
|||
SAMPLER(sampler_ThicknessMap); |
|||
|
|||
TEXTURE2D(_SpecularColorMap); |
|||
SAMPLER(sampler_SpecularColorMap); |
|||
|
|||
TEXTURE2D(_TransmittanceColorMap); |
|||
SAMPLER(sampler_TransmittanceColorMap); |
|||
|
|||
#else |
|||
|
|||
// Set of users variables |
|||
#define PROP_DECL(type, name) type name##0, name##1, name##2, name##3 |
|||
// sampler are share by texture type inside a layered material but we need to support that a particualr layer have no texture, so we take the first sampler of available texture as the share one |
|||
// mean we must declare all sampler |
|||
#define PROP_DECL_TEX2D(name)\ |
|||
TEXTURE2D(MERGE_NAME(name, 0)); \ |
|||
SAMPLER(MERGE_NAME(MERGE_NAME(sampler, name), 0)); \ |
|||
TEXTURE2D(MERGE_NAME(name, 1)); \ |
|||
SAMPLER(MERGE_NAME(MERGE_NAME(sampler, name), 1)); \ |
|||
TEXTURE2D(MERGE_NAME(name, 2)); \ |
|||
SAMPLER(MERGE_NAME(MERGE_NAME(sampler, name), 2)); \ |
|||
TEXTURE2D(MERGE_NAME(name, 3)); \ |
|||
SAMPLER(MERGE_NAME(MERGE_NAME(sampler, name), 3)) |
|||
|
|||
|
|||
PROP_DECL_TEX2D(_BaseColorMap); |
|||
PROP_DECL_TEX2D(_MaskMap); |
|||
PROP_DECL_TEX2D(_BentNormalMap); |
|||
PROP_DECL_TEX2D(_NormalMap); |
|||
PROP_DECL_TEX2D(_NormalMapOS); |
|||
PROP_DECL_TEX2D(_DetailMap); |
|||
PROP_DECL_TEX2D(_HeightMap); |
|||
|
|||
PROP_DECL_TEX2D(_SubsurfaceMaskMap); |
|||
PROP_DECL_TEX2D(_ThicknessMap); |
|||
|
|||
TEXTURE2D(_LayerMaskMap); |
|||
SAMPLER(sampler_LayerMaskMap); |
|||
TEXTURE2D(_LayerInfluenceMaskMap); |
|||
SAMPLER(sampler_LayerInfluenceMaskMap); |
|||
|
|||
#endif |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
|
|||
// shared constant between lit and layered lit |
|||
float _AlphaCutoff; |
|||
float _AlphaCutoffPrepass; |
|||
float _AlphaCutoffPostpass; |
|||
float4 _DoubleSidedConstants; |
|||
float _DistortionScale; |
|||
float _DistortionVectorScale; |
|||
float _DistortionVectorBias; |
|||
float _DistortionBlurScale; |
|||
float _DistortionBlurRemapMin; |
|||
float _DistortionBlurRemapMax; |
|||
|
|||
float _PPDMaxSamples; |
|||
float _PPDMinSamples; |
|||
float _PPDLodThreshold; |
|||
|
|||
float3 _EmissiveColor; |
|||
float _EmissiveIntensity; |
|||
float _AlbedoAffectEmissive; |
|||
|
|||
float _EnableSpecularOcclusion; |
|||
|
|||
// Transparency |
|||
float3 _TransmittanceColor; |
|||
float _IOR; |
|||
float _ATDistance; |
|||
float _ThicknessMultiplier; |
|||
|
|||
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor" |
|||
// value that exist to identify if the GI emission need to be enabled. |
|||
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it. |
|||
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI |
|||
float3 _EmissionColor; |
|||
float4 _EmissiveColorMap_ST; |
|||
|
|||
float4 _InvPrimScale; // Only XY are used |
|||
|
|||
// Wind |
|||
float _InitialBend; |
|||
float _Stiffness; |
|||
float _Drag; |
|||
float _ShiverDrag; |
|||
float _ShiverDirectionality; |
|||
|
|||
#ifndef LAYERED_LIT_SHADER |
|||
|
|||
// Set of users variables |
|||
float4 _BaseColor; |
|||
float4 _BaseColorMap_ST; |
|||
float4 _BaseColorMap_TexelSize; |
|||
// =========================================================================== |
|||
// WARNING: |
|||
// On PS4, texture/sampler declarations need to be outside of CBuffers |
|||
// Otherwise those parameters are not bound correctly at runtime. |
|||
// =========================================================================== |
|||
|
|||
TEXTURE2D(_DistortionVectorMap); |
|||
SAMPLER(sampler_DistortionVectorMap); |
|||
|
|||
TEXTURE2D(_EmissiveColorMap); |
|||
SAMPLER(sampler_EmissiveColorMap); |
|||
|
|||
#ifndef LAYERED_LIT_SHADER |
|||
|
|||
TEXTURE2D(_DiffuseLightingMap); |
|||
SAMPLER(sampler_DiffuseLightingMap); |
|||
|
|||
TEXTURE2D(_BaseColorMap); |
|||
SAMPLER(sampler_BaseColorMap); |
|||
|
|||
TEXTURE2D(_MaskMap); |
|||
SAMPLER(sampler_MaskMap); |
|||
TEXTURE2D(_BentNormalMap); // Reuse sampler from normal map |
|||
SAMPLER(sampler_BentNormalMap); |
|||
|
|||
TEXTURE2D(_NormalMap); |
|||
SAMPLER(sampler_NormalMap); |
|||
TEXTURE2D(_NormalMapOS); |
|||
SAMPLER(sampler_NormalMapOS); |
|||
|
|||
TEXTURE2D(_DetailMap); |
|||
SAMPLER(sampler_DetailMap); |
|||
|
|||
TEXTURE2D(_HeightMap); |
|||
SAMPLER(sampler_HeightMap); |
|||
|
|||
TEXTURE2D(_TangentMap); |
|||
SAMPLER(sampler_TangentMap); |
|||
TEXTURE2D(_TangentMapOS); |
|||
SAMPLER(sampler_TangentMapOS); |
|||
|
|||
TEXTURE2D(_AnisotropyMap); |
|||
SAMPLER(sampler_AnisotropyMap); |
|||
|
|||
TEXTURE2D(_SubsurfaceMaskMap); |
|||
SAMPLER(sampler_SubsurfaceMaskMap); |
|||
TEXTURE2D(_ThicknessMap); |
|||
SAMPLER(sampler_ThicknessMap); |
|||
|
|||
TEXTURE2D(_SpecularColorMap); |
|||
SAMPLER(sampler_SpecularColorMap); |
|||
|
|||
TEXTURE2D(_TransmittanceColorMap); |
|||
SAMPLER(sampler_TransmittanceColorMap); |
|||
|
|||
#else |
|||
|
|||
// Set of users variables |
|||
#define PROP_DECL(type, name) type name##0, name##1, name##2, name##3 |
|||
// sampler are share by texture type inside a layered material but we need to support that a particualr layer have no texture, so we take the first sampler of available texture as the share one |
|||
// mean we must declare all sampler |
|||
#define PROP_DECL_TEX2D(name)\ |
|||
TEXTURE2D(MERGE_NAME(name, 0)); \ |
|||
SAMPLER(MERGE_NAME(MERGE_NAME(sampler, name), 0)); \ |
|||
TEXTURE2D(MERGE_NAME(name, 1)); \ |
|||
SAMPLER(MERGE_NAME(MERGE_NAME(sampler, name), 1)); \ |
|||
TEXTURE2D(MERGE_NAME(name, 2)); \ |
|||
SAMPLER(MERGE_NAME(MERGE_NAME(sampler, name), 2)); \ |
|||
TEXTURE2D(MERGE_NAME(name, 3)); \ |
|||
SAMPLER(MERGE_NAME(MERGE_NAME(sampler, name), 3)) |
|||
|
|||
|
|||
PROP_DECL_TEX2D(_BaseColorMap); |
|||
PROP_DECL_TEX2D(_MaskMap); |
|||
PROP_DECL_TEX2D(_BentNormalMap); |
|||
PROP_DECL_TEX2D(_NormalMap); |
|||
PROP_DECL_TEX2D(_NormalMapOS); |
|||
PROP_DECL_TEX2D(_DetailMap); |
|||
PROP_DECL_TEX2D(_HeightMap); |
|||
|
|||
PROP_DECL_TEX2D(_SubsurfaceMaskMap); |
|||
PROP_DECL_TEX2D(_ThicknessMap); |
|||
|
|||
TEXTURE2D(_LayerMaskMap); |
|||
SAMPLER(sampler_LayerMaskMap); |
|||
TEXTURE2D(_LayerInfluenceMaskMap); |
|||
SAMPLER(sampler_LayerInfluenceMaskMap); |
|||
|
|||
#endif |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
|
|||
// shared constant between lit and layered lit |
|||
float _AlphaCutoff; |
|||
float _AlphaCutoffPrepass; |
|||
float _AlphaCutoffPostpass; |
|||
float4 _DoubleSidedConstants; |
|||
float _DistortionScale; |
|||
float _DistortionVectorScale; |
|||
float _DistortionVectorBias; |
|||
float _DistortionBlurScale; |
|||
float _DistortionBlurRemapMin; |
|||
float _DistortionBlurRemapMax; |
|||
|
|||
float _PPDMaxSamples; |
|||
float _PPDMinSamples; |
|||
float _PPDLodThreshold; |
|||
|
|||
float3 _EmissiveColor; |
|||
float _EmissiveIntensity; |
|||
float _AlbedoAffectEmissive; |
|||
|
|||
float _EnableSpecularOcclusion; |
|||
|
|||
// Transparency |
|||
float3 _TransmittanceColor; |
|||
float _IOR; |
|||
float _ATDistance; |
|||
float _ThicknessMultiplier; |
|||
|
|||
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor" |
|||
// value that exist to identify if the GI emission need to be enabled. |
|||
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it. |
|||
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI |
|||
float3 _EmissionColor; |
|||
float4 _EmissiveColorMap_ST; |
|||
float _TexWorldScaleEmissive; |
|||
float4 _UVMappingMaskEmissive; |
|||
|
|||
float4 _InvPrimScale; // Only XY are used |
|||
|
|||
// Wind |
|||
float _InitialBend; |
|||
float _Stiffness; |
|||
float _Drag; |
|||
float _ShiverDrag; |
|||
float _ShiverDirectionality; |
|||
|
|||
#ifndef LAYERED_LIT_SHADER |
|||
|
|||
// Set of users variables |
|||
float4 _BaseColor; |
|||
float4 _BaseColorMap_ST; |
|||
float4 _BaseColorMap_TexelSize; |
|||
|
|||
float _Metallic; |
|||
float _Smoothness; |
|||
float _SmoothnessRemapMin; |
|||
float _SmoothnessRemapMax; |
|||
float _AORemapMin; |
|||
float _AORemapMax; |
|||
|
|||
float _NormalScale; |
|||
|
|||
float4 _DetailMap_ST; |
|||
float _DetailAlbedoScale; |
|||
float _DetailNormalScale; |
|||
float _DetailSmoothnessScale; |
|||
|
|||
float4 _HeightMap_TexelSize; // Unity facility. This will provide the size of the heightmap to the shader |
|||
|
|||
float _HeightAmplitude; |
|||
float _HeightCenter; |
|||
|
|||
float _Anisotropy; |
|||
|
|||
int _DiffusionProfile; |
|||
float _SubsurfaceMask; |
|||
float _Thickness; |
|||
float4 _ThicknessRemap; |
|||
|
|||
float _CoatMask; |
|||
|
|||
float4 _SpecularColor; |
|||
|
|||
float _TexWorldScale; |
|||
float _InvTilingScale; |
|||
float4 _UVMappingMask; |
|||
float4 _UVDetailsMappingMask; |
|||
float _LinkDetailsWithBase; |
|||
|
|||
#else // LAYERED_LIT_SHADER |
|||
|
|||
// Set of users variables |
|||
PROP_DECL(float4, _BaseColor); |
|||
float4 _BaseColorMap0_ST; |
|||
float4 _BaseColorMap1_ST; |
|||
float4 _BaseColorMap2_ST; |
|||
float4 _BaseColorMap3_ST; |
|||
|
|||
|
|||
float _Metallic; |
|||
float _Smoothness; |
|||
float _SmoothnessRemapMin; |
|||
float _SmoothnessRemapMax; |
|||
float _AORemapMin; |
|||
float _AORemapMax; |
|||
|
|||
float _NormalScale; |
|||
|
|||
float4 _DetailMap_ST; |
|||
float _DetailAlbedoScale; |
|||
float _DetailNormalScale; |
|||
float _DetailSmoothnessScale; |
|||
|
|||
float4 _HeightMap_TexelSize; // Unity facility. This will provide the size of the heightmap to the shader |
|||
|
|||
float _HeightAmplitude; |
|||
float _HeightCenter; |
|||
|
|||
float _Anisotropy; |
|||
|
|||
int _DiffusionProfile; |
|||
float _SubsurfaceMask; |
|||
float _Thickness; |
|||
float4 _ThicknessRemap; |
|||
|
|||
float _CoatMask; |
|||
|
|||
float4 _SpecularColor; |
|||
|
|||
float _TexWorldScale; |
|||
float _InvTilingScale; |
|||
float4 _UVMappingMask; |
|||
float4 _UVDetailsMappingMask; |
|||
float _LinkDetailsWithBase; |
|||
|
|||
#else // LAYERED_LIT_SHADER |
|||
|
|||
// Set of users variables |
|||
PROP_DECL(float4, _BaseColor); |
|||
float4 _BaseColorMap0_ST; |
|||
float4 _BaseColorMap1_ST; |
|||
float4 _BaseColorMap2_ST; |
|||
float4 _BaseColorMap3_ST; |
|||
|
|||
|
|||
PROP_DECL(float, _Metallic); |
|||
PROP_DECL(float, _Smoothness); |
|||
PROP_DECL(float, _SmoothnessRemapMin); |
|||
PROP_DECL(float, _SmoothnessRemapMax); |
|||
PROP_DECL(float, _AORemapMin); |
|||
PROP_DECL(float, _AORemapMax); |
|||
|
|||
PROP_DECL(float, _NormalScale); |
|||
float4 _NormalMap0_TexelSize; // Unity facility. This will provide the size of the base normal to the shader |
|||
|
|||
float4 _HeightMap0_TexelSize; |
|||
float4 _HeightMap1_TexelSize; |
|||
float4 _HeightMap2_TexelSize; |
|||
float4 _HeightMap3_TexelSize; |
|||
|
|||
float4 _DetailMap0_ST; |
|||
float4 _DetailMap1_ST; |
|||
float4 _DetailMap2_ST; |
|||
float4 _DetailMap3_ST; |
|||
PROP_DECL(float, _UVDetail); |
|||
PROP_DECL(float, _DetailAlbedoScale); |
|||
PROP_DECL(float, _DetailNormalScale); |
|||
PROP_DECL(float, _DetailSmoothnessScale); |
|||
|
|||
PROP_DECL(float, _HeightAmplitude); |
|||
PROP_DECL(float, _HeightCenter); |
|||
|
|||
PROP_DECL(int, _DiffusionProfile); |
|||
PROP_DECL(float, _SubsurfaceMask); |
|||
PROP_DECL(float, _Thickness); |
|||
PROP_DECL(float4, _ThicknessRemap); |
|||
|
|||
PROP_DECL(float, _OpacityAsDensity); |
|||
float _InheritBaseNormal1; |
|||
float _InheritBaseNormal2; |
|||
float _InheritBaseNormal3; |
|||
float _InheritBaseHeight1; |
|||
float _InheritBaseHeight2; |
|||
float _InheritBaseHeight3; |
|||
float _InheritBaseColor1; |
|||
float _InheritBaseColor2; |
|||
float _InheritBaseColor3; |
|||
PROP_DECL(float, _HeightOffset); |
|||
float _HeightTransition; |
|||
|
|||
float4 _LayerMaskMap_ST; |
|||
float _TexWorldScaleBlendMask; |
|||
PROP_DECL(float, _TexWorldScale); |
|||
PROP_DECL(float, _InvTilingScale); |
|||
float4 _UVMappingMaskBlendMask; |
|||
PROP_DECL(float4, _UVMappingMask); |
|||
PROP_DECL(float4, _UVDetailsMappingMask); |
|||
PROP_DECL(float, _LinkDetailsWithBase); |
|||
|
|||
#endif // LAYERED_LIT_SHADER |
|||
|
|||
// Tessellation specific |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
float _TessellationFactor; |
|||
float _TessellationFactorMinDistance; |
|||
float _TessellationFactorMaxDistance; |
|||
float _TessellationFactorTriangleSize; |
|||
float _TessellationShapeFactor; |
|||
float _TessellationBackFaceCullEpsilon; |
|||
float _TessellationObjectScale; |
|||
float _TessellationTilingScale; |
|||
#endif |
|||
|
|||
CBUFFER_END |
|||
|
|||
PROP_DECL(float, _Metallic); |
|||
PROP_DECL(float, _Smoothness); |
|||
PROP_DECL(float, _SmoothnessRemapMin); |
|||
PROP_DECL(float, _SmoothnessRemapMax); |
|||
PROP_DECL(float, _AORemapMin); |
|||
PROP_DECL(float, _AORemapMax); |
|||
|
|||
PROP_DECL(float, _NormalScale); |
|||
float4 _NormalMap0_TexelSize; // Unity facility. This will provide the size of the base normal to the shader |
|||
|
|||
float4 _HeightMap0_TexelSize; |
|||
float4 _HeightMap1_TexelSize; |
|||
float4 _HeightMap2_TexelSize; |
|||
float4 _HeightMap3_TexelSize; |
|||
|
|||
float4 _DetailMap0_ST; |
|||
float4 _DetailMap1_ST; |
|||
float4 _DetailMap2_ST; |
|||
float4 _DetailMap3_ST; |
|||
PROP_DECL(float, _UVDetail); |
|||
PROP_DECL(float, _DetailAlbedoScale); |
|||
PROP_DECL(float, _DetailNormalScale); |
|||
PROP_DECL(float, _DetailSmoothnessScale); |
|||
|
|||
PROP_DECL(float, _HeightAmplitude); |
|||
PROP_DECL(float, _HeightCenter); |
|||
|
|||
PROP_DECL(int, _DiffusionProfile); |
|||
PROP_DECL(float, _SubsurfaceMask); |
|||
PROP_DECL(float, _Thickness); |
|||
PROP_DECL(float4, _ThicknessRemap); |
|||
|
|||
PROP_DECL(float, _OpacityAsDensity); |
|||
float _InheritBaseNormal1; |
|||
float _InheritBaseNormal2; |
|||
float _InheritBaseNormal3; |
|||
float _InheritBaseHeight1; |
|||
float _InheritBaseHeight2; |
|||
float _InheritBaseHeight3; |
|||
float _InheritBaseColor1; |
|||
float _InheritBaseColor2; |
|||
float _InheritBaseColor3; |
|||
PROP_DECL(float, _HeightOffset); |
|||
float _HeightTransition; |
|||
|
|||
float4 _LayerMaskMap_ST; |
|||
float _TexWorldScaleBlendMask; |
|||
PROP_DECL(float, _TexWorldScale); |
|||
PROP_DECL(float, _InvTilingScale); |
|||
float4 _UVMappingMaskBlendMask; |
|||
PROP_DECL(float4, _UVMappingMask); |
|||
PROP_DECL(float4, _UVDetailsMappingMask); |
|||
PROP_DECL(float, _LinkDetailsWithBase); |
|||
|
|||
#endif // LAYERED_LIT_SHADER |
|||
|
|||
// Tessellation specific |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
float _TessellationFactor; |
|||
float _TessellationFactorMinDistance; |
|||
float _TessellationFactorMaxDistance; |
|||
float _TessellationFactorTriangleSize; |
|||
float _TessellationShapeFactor; |
|||
float _TessellationBackFaceCullEpsilon; |
|||
float _TessellationObjectScale; |
|||
float _TessellationTilingScale; |
|||
#endif |
|||
|
|||
CBUFFER_END |
|
|||
fileFormatVersion: 2 |
|||
guid: 0f6887a1ff514ed690ada3786867d216 |
|||
timeCreated: 1512986333 |
|||
fileFormatVersion: 2 |
|||
guid: 2ea8802fb7f2fa641a567a661fb6a58e |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_INSTANCING_INCLUDED |
|||
#define UNITY_INSTANCING_INCLUDED |
|||
|
|||
#ifndef UNITY_SHADER_VARIABLES_INCLUDED |
|||
// We will redefine some built-in shader params e.g. unity_ObjectToWorld and unity_WorldToObject. |
|||
#error "Please include ShaderVariables.hlsl first." |
|||
#endif |
|||
|
|||
#if SHADER_TARGET >= 35 && (defined(SHADER_API_D3D11) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_XBOXONE) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN) || defined(SHADER_API_METAL)) |
|||
#define UNITY_SUPPORT_INSTANCING |
|||
#endif |
|||
|
|||
#if defined(SHADER_API_SWITCH) |
|||
#define UNITY_SUPPORT_INSTANCING |
|||
#endif |
|||
|
|||
#if defined(SHADER_API_D3D11) |
|||
#define UNITY_SUPPORT_STEREO_INSTANCING |
|||
#endif |
|||
|
|||
#if defined(SHADER_API_D3D11) || defined(SHADER_API_GLCORE) || defined(SHADER_API_GLES3) || defined(SHADER_API_VULKAN) || defined(SHADER_API_XBOXONE) || defined(SHADER_API_PSSL) || defined(SHADER_API_METAL) || defined(SHADER_API_SWITCH) |
|||
#define UNITY_INSTANCING_AOS |
|||
#endif |
|||
|
|||
// These platforms support dynamically adjusting the instancing CB size according to the current batch. |
|||
#if defined(SHADER_API_D3D11) || defined(SHADER_API_GLCORE) || defined(SHADER_API_GLES3) || defined(SHADER_API_METAL) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN) |
|||
#define UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE |
|||
#endif |
|||
|
|||
#if defined(SHADER_TARGET_SURFACE_ANALYSIS) && defined(UNITY_SUPPORT_INSTANCING) |
|||
#undef UNITY_SUPPORT_INSTANCING |
|||
#endif |
|||
|
|||
//////////////////////////////////////////////////////// |
|||
// instancing paths |
|||
// - UNITY_INSTANCING_ENABLED Defined if instancing path is taken. |
|||
// - UNITY_PROCEDURAL_INSTANCING_ENABLED Defined if procedural instancing path is taken. |
|||
// - UNITY_STEREO_INSTANCING_ENABLED Defined if stereo instancing path is taken. |
|||
#if defined(UNITY_SUPPORT_INSTANCING) && defined(INSTANCING_ON) |
|||
#define UNITY_INSTANCING_ENABLED |
|||
#endif |
|||
#if defined(UNITY_SUPPORT_INSTANCING) && defined(PROCEDURAL_INSTANCING_ON) |
|||
#define UNITY_PROCEDURAL_INSTANCING_ENABLED |
|||
#endif |
|||
#if defined(UNITY_SUPPORT_STEREO_INSTANCING) && defined(STEREO_INSTANCING_ON) |
|||
#define UNITY_STEREO_INSTANCING_ENABLED |
|||
#endif |
|||
|
|||
#if defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN) |
|||
// These platforms have constant buffers disabled normally, but not here (see CBUFFER_START/CBUFFER_END in HLSLSupport.cginc). |
|||
#define UNITY_INSTANCING_CBUFFER_SCOPE_BEGIN(name) cbuffer name { |
|||
#define UNITY_INSTANCING_CBUFFER_SCOPE_END } |
|||
#else |
|||
#define UNITY_INSTANCING_CBUFFER_SCOPE_BEGIN(name) CBUFFER_START(name) |
|||
#define UNITY_INSTANCING_CBUFFER_SCOPE_END CBUFFER_END |
|||
#endif |
|||
|
|||
//////////////////////////////////////////////////////// |
|||
// basic instancing setups |
|||
// - UNITY_VERTEX_INPUT_INSTANCE_ID Declare instance ID field in vertex shader input / output struct. |
|||
// - UNITY_GET_INSTANCE_ID (Internal) Get the instance ID from input struct. |
|||
#if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED) |
|||
|
|||
// A global instance ID variable that functions can directly access. |
|||
static uint unity_InstanceID; |
|||
|
|||
// Don't make UnityDrawCallInfo an actual CB on GL |
|||
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE) |
|||
UNITY_INSTANCING_CBUFFER_SCOPE_BEGIN(UnityDrawCallInfo) |
|||
#endif |
|||
int unity_BaseInstanceID; |
|||
int unity_InstanceCount; |
|||
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE) |
|||
UNITY_INSTANCING_CBUFFER_SCOPE_END |
|||
#endif |
|||
|
|||
#ifdef SHADER_API_PSSL |
|||
#define DEFAULT_UNITY_VERTEX_INPUT_INSTANCE_ID uint instanceID; |
|||
#define UNITY_GET_INSTANCE_ID(input) _GETINSTANCEID(input) |
|||
#else |
|||
#define DEFAULT_UNITY_VERTEX_INPUT_INSTANCE_ID uint instanceID : SV_InstanceID; |
|||
#define UNITY_GET_INSTANCE_ID(input) input.instanceID |
|||
#endif |
|||
|
|||
#else |
|||
#define DEFAULT_UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
#endif // UNITY_INSTANCING_ENABLED || UNITY_PROCEDURAL_INSTANCING_ENABLED || UNITY_STEREO_INSTANCING_ENABLED |
|||
|
|||
#if !defined(UNITY_VERTEX_INPUT_INSTANCE_ID) |
|||
# define UNITY_VERTEX_INPUT_INSTANCE_ID DEFAULT_UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
#endif |
|||
|
|||
//////////////////////////////////////////////////////// |
|||
// basic stereo instancing setups |
|||
// - UNITY_VERTEX_OUTPUT_STEREO Declare stereo target eye field in vertex shader output struct. |
|||
// - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO Assign the stereo target eye. |
|||
// - UNITY_TRANSFER_VERTEX_OUTPUT_STEREO Copy stero target from input struct to output struct. Used in vertex shader. |
|||
// - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX |
|||
#ifdef UNITY_STEREO_INSTANCING_ENABLED |
|||
#define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO uint stereoTargetEyeIndex : SV_RenderTargetArrayIndex; |
|||
#define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) output.stereoTargetEyeIndex = unity_StereoEyeIndex |
|||
#define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) output.stereoTargetEyeIndex = input.stereoTargetEyeIndex; |
|||
#define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) unity_StereoEyeIndex = input.stereoTargetEyeIndex; |
|||
#elif defined(UNITY_STEREO_MULTIVIEW_ENABLED) |
|||
#define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO float stereoTargetEyeIndex : BLENDWEIGHT0; |
|||
// HACK: Workaround for Mali shader compiler issues with directly using GL_ViewID_OVR (GL_OVR_multiview). This array just contains the values 0 and 1. |
|||
#define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) output.stereoTargetEyeIndex = unity_StereoEyeIndices[unity_StereoEyeIndex].x; |
|||
#define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) output.stereoTargetEyeIndex = input.stereoTargetEyeIndex; |
|||
#if defined(SHADER_STAGE_VERTEX) |
|||
#define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) |
|||
#else |
|||
#define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) unity_StereoEyeIndex = (uint) input.stereoTargetEyeIndex; |
|||
#endif |
|||
#else |
|||
#define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO |
|||
#define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) |
|||
#define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) |
|||
#define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) |
|||
#endif |
|||
|
|||
|
|||
#if !defined(UNITY_VERTEX_OUTPUT_STEREO) |
|||
# define UNITY_VERTEX_OUTPUT_STEREO DEFAULT_UNITY_VERTEX_OUTPUT_STEREO |
|||
#endif |
|||
#if !defined(UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO) |
|||
# define UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) |
|||
#endif |
|||
#if !defined(UNITY_TRANSFER_VERTEX_OUTPUT_STEREO) |
|||
# define UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) |
|||
#endif |
|||
#if !defined(UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX) |
|||
# define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) |
|||
#endif |
|||
|
|||
//////////////////////////////////////////////////////// |
|||
// - UNITY_SETUP_INSTANCE_ID Should be used at the very beginning of the vertex shader / fragment shader, |
|||
// so that succeeding code can have access to the global unity_InstanceID. |
|||
// Also procedural function is called to setup instance data. |
|||
// - UNITY_TRANSFER_INSTANCE_ID Copy instance ID from input struct to output struct. Used in vertex shader. |
|||
|
|||
#if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED) |
|||
void UnitySetupInstanceID(uint inputInstanceID) |
|||
{ |
|||
#ifdef UNITY_STEREO_INSTANCING_ENABLED |
|||
// stereo eye index is automatically figured out from the instance ID |
|||
unity_StereoEyeIndex = inputInstanceID & 0x01; |
|||
unity_InstanceID = unity_BaseInstanceID + (inputInstanceID >> 1); |
|||
#else |
|||
unity_InstanceID = inputInstanceID + unity_BaseInstanceID; |
|||
#endif |
|||
} |
|||
void UnitySetupCompoundMatrices(); |
|||
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED |
|||
#ifndef UNITY_INSTANCING_PROCEDURAL_FUNC |
|||
#error "UNITY_INSTANCING_PROCEDURAL_FUNC must be defined." |
|||
#else |
|||
void UNITY_INSTANCING_PROCEDURAL_FUNC(); // forward declaration of the procedural function |
|||
#define DEFAULT_UNITY_SETUP_INSTANCE_ID(input) { UnitySetupInstanceID(UNITY_GET_INSTANCE_ID(input)); UNITY_INSTANCING_PROCEDURAL_FUNC(); UnitySetupCompoundMatrices(); } |
|||
#endif |
|||
#else |
|||
#define DEFAULT_UNITY_SETUP_INSTANCE_ID(input) { UnitySetupInstanceID(UNITY_GET_INSTANCE_ID(input)); UnitySetupCompoundMatrices(); } |
|||
#endif |
|||
#define UNITY_TRANSFER_INSTANCE_ID(input, output) output.instanceID = UNITY_GET_INSTANCE_ID(input) |
|||
#else |
|||
#define DEFAULT_UNITY_SETUP_INSTANCE_ID(input) |
|||
#define UNITY_TRANSFER_INSTANCE_ID(input, output) |
|||
#endif |
|||
|
|||
#if !defined(UNITY_SETUP_INSTANCE_ID) |
|||
# define UNITY_SETUP_INSTANCE_ID(input) DEFAULT_UNITY_SETUP_INSTANCE_ID(input) |
|||
#endif |
|||
|
|||
//////////////////////////////////////////////////////// |
|||
// instanced property arrays |
|||
#if defined(UNITY_INSTANCING_ENABLED) |
|||
|
|||
#ifdef UNITY_FORCE_MAX_INSTANCE_COUNT |
|||
#define UNITY_INSTANCED_ARRAY_SIZE UNITY_FORCE_MAX_INSTANCE_COUNT |
|||
#elif defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE) |
|||
#define UNITY_INSTANCED_ARRAY_SIZE 2 // minimum array size that ensures dynamic indexing |
|||
#elif defined(UNITY_MAX_INSTANCE_COUNT) |
|||
#define UNITY_INSTANCED_ARRAY_SIZE UNITY_MAX_INSTANCE_COUNT |
|||
#else |
|||
#if defined(SHADER_API_VULKAN) && defined(SHADER_API_MOBILE) |
|||
#define UNITY_INSTANCED_ARRAY_SIZE 250 |
|||
#else |
|||
#define UNITY_INSTANCED_ARRAY_SIZE 500 |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef UNITY_INSTANCING_AOS |
|||
#define UNITY_INSTANCING_BUFFER_START(buf) UNITY_INSTANCING_CBUFFER_SCOPE_BEGIN(UnityInstancing_##buf) struct { |
|||
#define UNITY_INSTANCING_BUFFER_END(arr) } arr##Array[UNITY_INSTANCED_ARRAY_SIZE]; UNITY_INSTANCING_CBUFFER_SCOPE_END |
|||
#define UNITY_DEFINE_INSTANCED_PROP(type, var) type var; |
|||
#define UNITY_ACCESS_INSTANCED_PROP(arr, var) arr##Array[unity_InstanceID].var |
|||
#else |
|||
#define UNITY_INSTANCING_BUFFER_START(buf) UNITY_INSTANCING_CBUFFER_SCOPE_BEGIN(UnityInstancing_##buf) |
|||
#define UNITY_INSTANCING_BUFFER_END(arr) UNITY_INSTANCING_CBUFFER_SCOPE_END |
|||
#define UNITY_DEFINE_INSTANCED_PROP(type, var) type var[UNITY_INSTANCED_ARRAY_SIZE]; |
|||
#define UNITY_ACCESS_INSTANCED_PROP(arr, var) var[unity_InstanceID] |
|||
#endif |
|||
|
|||
// Put worldToObject array to a separate CB if UNITY_ASSUME_UNIFORM_SCALING is defined. Most of the time it will not be used. |
|||
#ifdef UNITY_ASSUME_UNIFORM_SCALING |
|||
#define UNITY_WORLDTOOBJECTARRAY_CB 1 |
|||
#else |
|||
#define UNITY_WORLDTOOBJECTARRAY_CB 0 |
|||
#endif |
|||
|
|||
#if defined(UNITY_INSTANCED_LOD_FADE) && (defined(LOD_FADE_PERCENTAGE) || defined(LOD_FADE_CROSSFADE)) |
|||
#define UNITY_USE_LODFADE_ARRAY |
|||
#endif |
|||
|
|||
#ifdef UNITY_INSTANCED_LIGHTMAPSTS |
|||
#ifdef LIGHTMAP_ON |
|||
#define UNITY_USE_LIGHTMAPST_ARRAY |
|||
#endif |
|||
#ifdef DYNAMICLIGHTMAP_ON |
|||
#define UNITY_USE_DYNAMICLIGHTMAPST_ARRAY |
|||
#endif |
|||
#endif |
|||
|
|||
#if defined(UNITY_INSTANCED_SH) && !defined(LIGHTMAP_ON) |
|||
#if UNITY_SHOULD_SAMPLE_SH |
|||
#define UNITY_USE_SHCOEFFS_ARRAYS |
|||
#endif |
|||
#if defined(UNITY_PASS_DEFERRED) && defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) |
|||
#define UNITY_USE_PROBESOCCLUSION_ARRAY |
|||
#endif |
|||
#endif |
|||
|
|||
UNITY_INSTANCING_BUFFER_START(PerDraw0) |
|||
UNITY_DEFINE_INSTANCED_PROP(float4x4, unity_ObjectToWorldArray) |
|||
#if UNITY_WORLDTOOBJECTARRAY_CB == 0 |
|||
UNITY_DEFINE_INSTANCED_PROP(float4x4, unity_WorldToObjectArray) |
|||
#endif |
|||
#if defined(UNITY_USE_LODFADE_ARRAY) && defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE) |
|||
UNITY_DEFINE_INSTANCED_PROP(float, unity_LODFadeArray) |
|||
// the quantized fade value (unity_LODFade.y) is automatically used for cross-fading instances |
|||
#define unity_LODFade UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_LODFadeArray).xxxx |
|||
#endif |
|||
UNITY_INSTANCING_BUFFER_END(unity_Builtins0) |
|||
|
|||
UNITY_INSTANCING_BUFFER_START(PerDraw1) |
|||
#if UNITY_WORLDTOOBJECTARRAY_CB == 1 |
|||
UNITY_DEFINE_INSTANCED_PROP(float4x4, unity_WorldToObjectArray) |
|||
#endif |
|||
#if defined(UNITY_USE_LODFADE_ARRAY) && !defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE) |
|||
UNITY_DEFINE_INSTANCED_PROP(float, unity_LODFadeArray) |
|||
// the quantized fade value (unity_LODFade.y) is automatically used for cross-fading instances |
|||
#define unity_LODFade UNITY_ACCESS_INSTANCED_PROP(unity_Builtins1, unity_LODFadeArray).xxxx |
|||
#endif |
|||
UNITY_INSTANCING_BUFFER_END(unity_Builtins1) |
|||
|
|||
UNITY_INSTANCING_BUFFER_START(PerDraw2) |
|||
#ifdef UNITY_USE_LIGHTMAPST_ARRAY |
|||
UNITY_DEFINE_INSTANCED_PROP(float4, unity_LightmapSTArray) |
|||
#define unity_LightmapST UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_LightmapSTArray) |
|||
#endif |
|||
#ifdef UNITY_USE_DYNAMICLIGHTMAPST_ARRAY |
|||
UNITY_DEFINE_INSTANCED_PROP(float4, unity_DynamicLightmapSTArray) |
|||
#define unity_DynamicLightmapST UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_DynamicLightmapSTArray) |
|||
#endif |
|||
#ifdef UNITY_USE_SHCOEFFS_ARRAYS |
|||
UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHArArray) |
|||
UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHAgArray) |
|||
UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHAbArray) |
|||
UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHBrArray) |
|||
UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHBgArray) |
|||
UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHBbArray) |
|||
UNITY_DEFINE_INSTANCED_PROP(half4, unity_SHCArray) |
|||
#define unity_SHAr UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHArArray) |
|||
#define unity_SHAg UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHAgArray) |
|||
#define unity_SHAb UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHAbArray) |
|||
#define unity_SHBr UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHBrArray) |
|||
#define unity_SHBg UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHBgArray) |
|||
#define unity_SHBb UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHBbArray) |
|||
#define unity_SHC UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_SHCArray) |
|||
#endif |
|||
#ifdef UNITY_USE_PROBESOCCLUSION_ARRAY |
|||
UNITY_DEFINE_INSTANCED_PROP(half4, unity_ProbesOcclusionArray) |
|||
#define unity_ProbesOcclusion UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_ProbesOcclusionArray) |
|||
#endif |
|||
UNITY_INSTANCING_BUFFER_END(unity_Builtins2) |
|||
|
|||
#define unity_ObjectToWorld UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray) |
|||
|
|||
#define MERGE_UNITY_BUILTINS_INDEX(X) unity_Builtins##X |
|||
|
|||
#define unity_WorldToObject UNITY_ACCESS_INSTANCED_PROP(MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray) |
|||
|
|||
inline float4 UnityObjectToClipPosInstanced(in float3 pos) |
|||
{ |
|||
return mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorld, float4(pos, 1.0))); |
|||
} |
|||
inline float4 UnityObjectToClipPosInstanced(float4 pos) |
|||
{ |
|||
return UnityObjectToClipPosInstanced(pos.xyz); |
|||
} |
|||
#define UnityObjectToClipPos UnityObjectToClipPosInstanced |
|||
|
|||
#else // UNITY_INSTANCING_ENABLED |
|||
|
|||
// in procedural mode we don't need cbuffer, and properties are not uniforms |
|||
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED |
|||
#define UNITY_INSTANCING_BUFFER_START(buf) |
|||
#define UNITY_INSTANCING_BUFFER_END(arr) |
|||
#define UNITY_DEFINE_INSTANCED_PROP(type, var) static type var; |
|||
#else |
|||
#define UNITY_INSTANCING_BUFFER_START(buf) CBUFFER_START(buf) |
|||
#define UNITY_INSTANCING_BUFFER_END(arr) CBUFFER_END |
|||
#define UNITY_DEFINE_INSTANCED_PROP(type, var) type var; |
|||
#endif |
|||
|
|||
#define UNITY_ACCESS_INSTANCED_PROP(arr, var) var |
|||
|
|||
#endif // UNITY_INSTANCING_ENABLED |
|||
|
|||
#if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED) |
|||
// The following matrix evaluations depend on the static var unity_InstanceID & unity_StereoEyeIndex. They need to be initialized after UnitySetupInstanceID. |
|||
static float4x4 unity_MatrixMVP_Instanced; |
|||
static float4x4 unity_MatrixMV_Instanced; |
|||
static float4x4 unity_MatrixTMV_Instanced; |
|||
static float4x4 unity_MatrixITMV_Instanced; |
|||
void UnitySetupCompoundMatrices() |
|||
{ |
|||
unity_MatrixMVP_Instanced = mul(UNITY_MATRIX_VP, unity_ObjectToWorld); |
|||
unity_MatrixMV_Instanced = mul(UNITY_MATRIX_V, unity_ObjectToWorld); |
|||
unity_MatrixTMV_Instanced = transpose(unity_MatrixMV_Instanced); |
|||
unity_MatrixITMV_Instanced = transpose(mul(unity_WorldToObject, unity_MatrixInvV)); |
|||
} |
|||
#undef UNITY_MATRIX_MVP |
|||
#undef UNITY_MATRIX_MV |
|||
#undef UNITY_MATRIX_T_MV |
|||
#undef UNITY_MATRIX_IT_MV |
|||
#define UNITY_MATRIX_MVP unity_MatrixMVP_Instanced |
|||
#define UNITY_MATRIX_MV unity_MatrixMV_Instanced |
|||
#define UNITY_MATRIX_T_MV unity_MatrixTMV_Instanced |
|||
#define UNITY_MATRIX_IT_MV unity_MatrixITMV_Instanced |
|||
#endif |
|||
|
|||
#endif // UNITY_INSTANCING_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: e1cfc5ca61db3d448825f316ff92cb0b |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
void GetBuiltinData(FragInputs input, SurfaceData surfaceData, float alpha, float3 bentNormalWS, float depthOffset, out BuiltinData builtinData) |
|||
{ |
|||
// Builtin Data |
|||
builtinData.opacity = alpha; |
|||
|
|||
// TODO: Sample lightmap/lightprobe/volume proxy |
|||
// This should also handle projective lightmap |
|||
builtinData.bakeDiffuseLighting = SampleBakedGI(input.positionWS, bentNormalWS, input.texCoord1, input.texCoord2); |
|||
|
|||
// It is safe to call this function here as surfaceData have been filled |
|||
// We want to know if we must enable transmission on GI for SSS material, if the material have no SSS, this code will be remove by the compiler. |
|||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData); |
|||
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION)) |
|||
{ |
|||
// For now simply recall the function with inverted normal, the compiler should be able to optimize the lightmap case to not resample the directional lightmap |
|||
// however it will not optimize the lightprobe case due to the proxy volume relying on dynamic if (we rely must get right of this dynamic if), not a problem for SH9, but a problem for proxy volume. |
|||
// TODO: optimize more this code. |
|||
// Add GI transmission contribution by resampling the GI for inverted vertex normal |
|||
builtinData.bakeDiffuseLighting += SampleBakedGI(input.positionWS, -input.worldToTangent[2], input.texCoord1, input.texCoord2) * bsdfData.transmittance; |
|||
} |
|||
|
|||
#ifdef SHADOWS_SHADOWMASK |
|||
float4 shadowMask = SampleShadowMask(input.positionWS, input.texCoord1); |
|||
builtinData.shadowMask0 = shadowMask.x; |
|||
builtinData.shadowMask1 = shadowMask.y; |
|||
builtinData.shadowMask2 = shadowMask.z; |
|||
builtinData.shadowMask3 = shadowMask.w; |
|||
#else |
|||
builtinData.shadowMask0 = 0.0; |
|||
builtinData.shadowMask1 = 0.0; |
|||
builtinData.shadowMask2 = 0.0; |
|||
builtinData.shadowMask3 = 0.0; |
|||
#endif |
|||
|
|||
// Emissive Intensity is only use here, but is part of BuiltinData to enforce UI parameters as we want the users to fill one color and one intensity |
|||
builtinData.emissiveIntensity = _EmissiveIntensity; // We still store intensity here so we can reuse it with debug code |
|||
|
|||
builtinData.emissiveColor = _EmissiveColor * builtinData.emissiveIntensity * lerp(float3(1.0, 1.0, 1.0), surfaceData.baseColor.rgb, _AlbedoAffectEmissive); |
|||
#ifdef _EMISSIVE_COLOR_MAP |
|||
|
|||
// Use layer0 of LayerTexCoord to retrieve emissive color mapping information |
|||
LayerTexCoord layerTexCoord; |
|||
ZERO_INITIALIZE(LayerTexCoord, layerTexCoord); |
|||
layerTexCoord.vertexNormalWS = input.worldToTangent[2].xyz; |
|||
layerTexCoord.triplanarWeights = ComputeTriplanarWeights(layerTexCoord.vertexNormalWS); |
|||
|
|||
int mappingType = UV_MAPPING_UVSET; |
|||
#if defined(_EMISSIVE_MAPPING_PLANAR) |
|||
mappingType = UV_MAPPING_PLANAR; |
|||
#elif defined(_EMISSIVE_MAPPING_TRIPLANAR) |
|||
mappingType = UV_MAPPING_TRIPLANAR; |
|||
#endif |
|||
|
|||
// Be sure that the compiler is aware that we don't use UV1 to UV3 for main layer so it can optimize code |
|||
#ifndef LAYERED_LIT_SHADER |
|||
ComputeLayerTexCoord(input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3, float4(1.0, 0.0, 0.0, 0.0), float4(1.0, 0.0, 0.0, 0.0), |
|||
#else |
|||
ComputeLayerTexCoord0(input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3, _UVMappingMaskEmissive, _UVMappingMaskEmissive, |
|||
#endif |
|||
_EmissiveColorMap_ST.xy, _EmissiveColorMap_ST.zw, float2(0.0, 0.0), float2(0.0, 0.0), 1.0, false, |
|||
input.positionWS, _TexWorldScaleEmissive, |
|||
mappingType, layerTexCoord); |
|||
|
|||
#ifndef LAYERED_LIT_SHADER |
|||
UVMapping emissiveMapMapping = layerTexCoord.base; |
|||
#else |
|||
UVMapping emissiveMapMapping = layerTexCoord.base0; |
|||
#endif |
|||
|
|||
builtinData.emissiveColor *= SAMPLE_UVMAPPING_TEXTURE2D(_EmissiveColorMap, sampler_EmissiveColorMap, emissiveMapMapping).rgb; |
|||
#endif // _EMISSIVE_COLOR_MAP |
|||
|
|||
builtinData.velocity = float2(0.0, 0.0); |
|||
|
|||
#if (SHADERPASS == SHADERPASS_DISTORTION) || defined(DEBUG_DISPLAY) |
|||
float3 distortion = SAMPLE_TEXTURE2D(_DistortionVectorMap, sampler_DistortionVectorMap, input.texCoord0).rgb; |
|||
distortion.rg = distortion.rg * _DistortionVectorScale.xx + _DistortionVectorBias.xx; |
|||
builtinData.distortion = distortion.rg * _DistortionScale; |
|||
builtinData.distortionBlur = clamp(distortion.b * _DistortionBlurScale, 0.0, 1.0) * (_DistortionBlurRemapMax - _DistortionBlurRemapMin) + _DistortionBlurRemapMin; |
|||
#else |
|||
builtinData.distortion = float2(0.0, 0.0); |
|||
builtinData.distortionBlur = 0.0; |
|||
#endif |
|||
|
|||
builtinData.depthOffset = depthOffset; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b18343016003d0c4aaa0dd7778d3b816 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue