You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
8.7 KiB
194 lines
8.7 KiB
Pass
|
|
{
|
|
$splice(PassName)
|
|
Tags
|
|
{
|
|
$splice(LightMode)
|
|
}
|
|
|
|
// Render State
|
|
$splice(RenderState)
|
|
|
|
// Debug
|
|
$splice(Debug)
|
|
|
|
// --------------------------------------------------
|
|
// Pass
|
|
|
|
HLSLPROGRAM
|
|
|
|
// Pragmas
|
|
$splice(PassPragmas)
|
|
|
|
// Keywords
|
|
$splice(PassKeywords)
|
|
$splice(GraphKeywords)
|
|
|
|
#define FORCE_VIRTUAL_TEXTURING_OFF 1
|
|
|
|
// For custom interpolators to inject a substruct definition before FragInputs definition,
|
|
// allowing for FragInputs to capture CI's intended for ShaderGraph's SDI.
|
|
$splice(CustomInterpolatorPreInclude)
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Decals do not support VT but we need to include it to avoid compilation error
|
|
|
|
// Defines
|
|
$AttributesMesh.normalOS: #define ATTRIBUTES_NEED_NORMAL
|
|
$AttributesMesh.tangentOS: #define ATTRIBUTES_NEED_TANGENT
|
|
$AttributesMesh.uv0: #define ATTRIBUTES_NEED_TEXCOORD0
|
|
$AttributesMesh.uv1: #define ATTRIBUTES_NEED_TEXCOORD1
|
|
$AttributesMesh.uv2: #define ATTRIBUTES_NEED_TEXCOORD2
|
|
$AttributesMesh.uv3: #define ATTRIBUTES_NEED_TEXCOORD3
|
|
$AttributesMesh.color: #define ATTRIBUTES_NEED_COLOR
|
|
$AttributesMesh.instanceID: #define ATTRIBUTES_NEED_INSTANCEID
|
|
$VaryingsMeshToPS.positionRWS: #define VARYINGS_NEED_POSITION_WS
|
|
$VaryingsMeshToPS.normalWS: #define VARYINGS_NEED_TANGENT_TO_WORLD
|
|
$VaryingsMeshToPS.texCoord0: #define VARYINGS_NEED_TEXCOORD0
|
|
$VaryingsMeshToPS.texCoord1: #define VARYINGS_NEED_TEXCOORD1
|
|
$VaryingsMeshToPS.texCoord2: #define VARYINGS_NEED_TEXCOORD2
|
|
$VaryingsMeshToPS.texCoord3: #define VARYINGS_NEED_TEXCOORD3
|
|
$VaryingsMeshToPS.color: #define VARYINGS_NEED_COLOR
|
|
$VaryingsMeshToPS.instanceID: #define VARYINGS_NEED_INSTANCEID
|
|
$FragInputs.instanceID: #define FRAG_INPUTS_USE_INSTANCEID
|
|
|
|
$features.graphVertex: #define HAVE_MESH_MODIFICATION
|
|
|
|
$SurfaceDescriptionInputs.FaceSign: // Define when IsFontFaceNode is included in ShaderGraph
|
|
$SurfaceDescriptionInputs.FaceSign: #define VARYINGS_NEED_CULLFACE
|
|
|
|
$splice(GraphDefines)
|
|
|
|
// -- Properties used by ScenePickingPass
|
|
#ifdef SCENEPICKINGPASS
|
|
float4 _SelectionID;
|
|
#endif
|
|
|
|
// Includes
|
|
$splice(PreGraphIncludes)
|
|
|
|
// --------------------------------------------------
|
|
// Structs and Packing
|
|
|
|
$splice(PassStructs)
|
|
|
|
$splice(InterpolatorPack)
|
|
|
|
// --------------------------------------------------
|
|
// Graph
|
|
|
|
// Graph Properties
|
|
$splice(GraphProperties)
|
|
|
|
// Graph Includes
|
|
$splice(GraphIncludes)
|
|
|
|
// Graph Functions
|
|
$splice(GraphFunctions)
|
|
|
|
// Graph Vertex
|
|
$splice(GraphVertex)
|
|
|
|
// Graph Pixel
|
|
$splice(GraphPixel)
|
|
|
|
// --------------------------------------------------
|
|
// Build Graph Inputs
|
|
|
|
$features.graphVertex: $include("Vertex.template.hlsl")
|
|
$features.graphPixel: $include("Pixel.template.hlsl")
|
|
|
|
// --------------------------------------------------
|
|
// Build Surface Data
|
|
|
|
void GetSurfaceData(FragInputs fragInputs, float3 V, PositionInputs posInput, float angleFadeFactor, out DecalSurfaceData surfaceData)
|
|
{
|
|
#if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR)
|
|
float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld);
|
|
float fadeFactor = clamp(normalToWorld[0][3], 0.0f, 1.0f) * angleFadeFactor;
|
|
float2 scale = float2(normalToWorld[3][0], normalToWorld[3][1]);
|
|
float2 offset = float2(normalToWorld[3][2], normalToWorld[3][3]);
|
|
fragInputs.texCoord0.xy = fragInputs.texCoord0.xy * scale + offset;
|
|
fragInputs.texCoord1.xy = fragInputs.texCoord1.xy * scale + offset;
|
|
fragInputs.texCoord2.xy = fragInputs.texCoord2.xy * scale + offset;
|
|
fragInputs.texCoord3.xy = fragInputs.texCoord3.xy * scale + offset;
|
|
fragInputs.positionRWS = posInput.positionWS;
|
|
fragInputs.tangentToWorld[2].xyz = TransformObjectToWorldDir(float3(0, 1, 0));
|
|
fragInputs.tangentToWorld[1].xyz = TransformObjectToWorldDir(float3(0, 0, 1));
|
|
#else
|
|
#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
|
|
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
|
|
#endif
|
|
|
|
float fadeFactor = 1.0;
|
|
#endif
|
|
|
|
SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
|
|
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
|
|
|
|
// setup defaults -- these are used if the graph doesn't output a value
|
|
ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
|
|
|
|
#ifdef _MATERIAL_AFFECTS_EMISSION
|
|
$SurfaceDescription.Emission: surfaceData.emissive.rgb = surfaceDescription.Emission.rgb * fadeFactor;
|
|
#endif
|
|
|
|
// copy across graph values, if defined
|
|
#ifdef _MATERIAL_AFFECTS_ALBEDO
|
|
$SurfaceDescription.BaseColor: surfaceData.baseColor.xyz = surfaceDescription.BaseColor;
|
|
$SurfaceDescription.Alpha: surfaceData.baseColor.w = surfaceDescription.Alpha * fadeFactor;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_AFFECTS_NORMAL
|
|
#ifdef DECAL_SURFACE_GRADIENT
|
|
#if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR)
|
|
$SurfaceDescription.NormalTS: float3x3 tangentToWorld = transpose((float3x3)normalToWorld);
|
|
#else
|
|
$SurfaceDescription.NormalTS: float3x3 tangentToWorld = fragInputs.tangentToWorld;
|
|
#endif
|
|
|
|
$SurfaceDescription.NormalTS: surfaceData.normalWS.xyz = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS.xyz, tangentToWorld[0], tangentToWorld[1]);
|
|
#else
|
|
#if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR)
|
|
$SurfaceDescription.NormalTS: surfaceData.normalWS.xyz = mul((float3x3)normalToWorld, surfaceDescription.NormalTS);
|
|
#elif (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_PREVIEW)
|
|
// We need to normalize as we use mikkt tangent space and this is expected (tangent space is not normalize)
|
|
$SurfaceDescription.NormalTS: surfaceData.normalWS.xyz = normalize(TransformTangentToWorld(surfaceDescription.NormalTS, fragInputs.tangentToWorld));
|
|
#endif
|
|
#endif
|
|
|
|
$SurfaceDescription.NormalAlpha: surfaceData.normalWS.w = surfaceDescription.NormalAlpha * fadeFactor;
|
|
#else
|
|
#if (SHADERPASS == SHADERPASS_FORWARD_PREVIEW) // Default to vertex normal
|
|
#ifdef DECAL_SURFACE_GRADIENT
|
|
$SurfaceDescription.NormalTS: surfaceData.normalWS.xyz = float3(0.0, 0.0, 0.0);
|
|
#else
|
|
$SurfaceDescription.NormalTS: surfaceData.normalWS.xyz = normalize(TransformTangentToWorld(float3(0.0, 0.0, 0.1), fragInputs.tangentToWorld));
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
// In case of Smoothness / AO / Metal, all the three are always computed but color mask can change
|
|
#ifdef _MATERIAL_AFFECTS_MASKMAP
|
|
$SurfaceDescription.Smoothness: surfaceData.mask.z = surfaceDescription.Smoothness;
|
|
$SurfaceDescription.MAOSAlpha: surfaceData.mask.w = surfaceDescription.MAOSAlpha * fadeFactor;
|
|
|
|
#ifdef DECALS_4RT
|
|
$SurfaceDescription.Metallic: surfaceData.mask.x = surfaceDescription.Metallic;
|
|
$SurfaceDescription.Occlusion: surfaceData.mask.y = surfaceDescription.Occlusion;
|
|
$SurfaceDescription.MAOSAlpha: surfaceData.MAOSBlend.x = surfaceDescription.MAOSAlpha * fadeFactor;
|
|
$SurfaceDescription.MAOSAlpha: surfaceData.MAOSBlend.y = surfaceDescription.MAOSAlpha * fadeFactor;
|
|
#endif
|
|
#endif
|
|
}
|
|
|
|
// --------------------------------------------------
|
|
// Main
|
|
|
|
$splice(PostGraphIncludes)
|
|
|
|
ENDHLSL
|
|
}
|