struct AttributesMesh
{
[Semantic("POSITION")] Vector3 positionOS ;
[Semantic("NORMAL")] [ Optional ] Vector3 normalOS ;
[Semantic("TANGENT")] [ Optional ] Vector4 tangentOS ; // Stores bi-tangent sign in w
[Semantic("TEXCOORD0")] [ Optional ] Vector2 uv0 ;
[Semantic("TEXCOORD1")] [ Optional ] Vector2 uv1 ;
[Semantic("TEXCOORD2")] [ Optional ] Vector2 uv2 ;
[Semantic("TEXCOORD3")] [ Optional ] Vector2 uv3 ;
[Semantic("COLOR")] [ Optional ] Vector4 color ;
[Semantic("NORMAL")] [ Optional ] Vector3 normalOS ;
[Semantic("TANGENT")] [ Optional ] Vector4 tangentOS ; // Stores bi-tangent sign in w
[Semantic("TEXCOORD0")] [ Optional ] Vector2 uv0 ;
[Semantic("TEXCOORD1")] [ Optional ] Vector2 uv1 ;
[Semantic("TEXCOORD2")] [ Optional ] Vector2 uv2 ;
[Semantic("TEXCOORD3")] [ Optional ] Vector2 uv3 ;
[Semantic("COLOR")] [ Optional ] Vector4 color ;
} ;
struct VaryingsMeshToPS
} ;
} ;
struct SurfaceDescriptionInputs
// this describes the input to the pixel shader graph eval
public struct SurfaceDescriptionInputs
{
[Optional] Vector3 ObjectSpaceNormal ;
[Optional] Vector3 ViewSpaceNormal ;
[Optional] Vector3 WorldSpacePosition ;
[Optional] Vector3 TangentSpacePosition ;
[Optional] Vector4 s creenPosition;
[Optional] Vector4 S creenPosition;
[Optional] Vector4 v ertexColor;
[Optional] Vector4 V ertexColor;
public static Dependency [ ] dependencies = new Dependency [ ]
{
new Dependency ( "SurfaceDescriptionInputs.TangentSpaceViewDirection" , "SurfaceDescriptionInputs.WorldSpaceBiTangent" ) ,
new Dependency ( "SurfaceDescriptionInputs.TangentSpaceViewDirection" , "SurfaceDescriptionInputs.WorldSpaceNormal" ) ,
new Dependency ( "SurfaceDescriptionInputs.screenPosition" , "FragInputs.positionSS" ) ,
new Dependency ( "SurfaceDescriptionInputs.ScreenPosition" , "FragInputs.positionSS" ) ,
new Dependency ( "SurfaceDescriptionInputs.vertexColor" , "FragInputs.color" ) ,
new Dependency ( "SurfaceDescriptionInputs.VertexColor" , "FragInputs.color" ) ,
static void AddActiveFieldsFromGraphRequirements ( HashSet < string > activeFields , ShaderGraphRequirements requirements )
// this describes the input to the pixel shader graph eval
public struct VertexDescriptionInputs
{
[Optional] Vector3 ObjectSpaceNormal ;
[Optional] Vector3 ViewSpaceNormal ;
[Optional] Vector3 WorldSpaceNormal ;
[Optional] Vector3 TangentSpaceNormal ;
[Optional] Vector3 ObjectSpaceTangent ;
[Optional] Vector3 ViewSpaceTangent ;
[Optional] Vector3 WorldSpaceTangent ;
[Optional] Vector3 TangentSpaceTangent ;
[Optional] Vector3 ObjectSpaceBiTangent ;
[Optional] Vector3 ViewSpaceBiTangent ;
[Optional] Vector3 WorldSpaceBiTangent ;
[Optional] Vector3 TangentSpaceBiTangent ;
[Optional] Vector3 ObjectSpaceViewDirection ;
[Optional] Vector3 ViewSpaceViewDirection ;
[Optional] Vector3 WorldSpaceViewDirection ;
[Optional] Vector3 TangentSpaceViewDirection ;
[Optional] Vector3 ObjectSpacePosition ;
[Optional] Vector3 ViewSpacePosition ;
[Optional] Vector3 WorldSpacePosition ;
[Optional] Vector3 TangentSpacePosition ;
[Optional] Vector4 ScreenPosition ;
[Optional] Vector4 uv0 ;
[Optional] Vector4 uv1 ;
[Optional] Vector4 uv2 ;
[Optional] Vector4 uv3 ;
[Optional] Vector4 VertexColor ;
public static Dependency [ ] dependencies = new Dependency [ ]
{ // TODO: NOCHECKIN: these dependencies are not correct for vertex pass
new Dependency ( "VertexDescriptionInputs.ObjectSpaceNormal" , "AttributesMesh.normalOS" ) ,
new Dependency ( "VertexDescriptionInputs.WorldSpaceNormal" , "AttributesMesh.normalOS" ) ,
new Dependency ( "VertexDescriptionInputs.ViewSpaceNormal" , "VertexDescriptionInputs.WorldSpaceNormal" ) ,
new Dependency ( "VertexDescriptionInputs.ObjectSpaceTangent" , "AttributesMesh.tangentOS" ) ,
new Dependency ( "VertexDescriptionInputs.WorldSpaceTangent" , "AttributesMesh.tangentOS" ) ,
new Dependency ( "VertexDescriptionInputs.ViewSpaceTangent" , "VertexDescriptionInputs.WorldSpaceTangent" ) ,
new Dependency ( "VertexDescriptionInputs.ObjectSpaceBiTangent" , "AttributesMesh.normalOS" ) ,
new Dependency ( "VertexDescriptionInputs.ObjectSpaceBiTangent" , "AttributesMesh.tangentOS" ) ,
new Dependency ( "VertexDescriptionInputs.WorldSpaceBiTangent" , "VertexDescriptionInputs.ObjectSpaceBiTangent" ) ,
new Dependency ( "VertexDescriptionInputs.ViewSpaceBiTangent" , "VertexDescriptionInputs.WorldSpaceBiTangent" ) ,
new Dependency ( "VertexDescriptionInputs.ObjectSpacePosition" , "AttributesMesh.positionOS" ) ,
new Dependency ( "VertexDescriptionInputs.WorldSpacePosition" , "AttributesMesh.positionOS" ) ,
new Dependency ( "VertexDescriptionInputs.ViewSpacePosition" , "VertexDescriptionInputs.WorldSpacePosition" ) ,
// TODO : view direction accessible in vertex shader
// new Dependency("VertexDescriptionInputs.WorldSpaceViewDirection", "FragInputs.positionWS"), // we build WorldSpaceViewDirection using FragInputs.positionWS in GetWorldSpaceNormalizeViewDir()
// new Dependency("VertexDescriptionInputs.ObjectSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceViewDirection"),
// new Dependency("VertexDescriptionInputs.ViewSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceViewDirection"),
// new Dependency("VertexDescriptionInputs.TangentSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceViewDirection"),
// new Dependency("VertexDescriptionInputs.TangentSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceTangent"),
// new Dependency("VertexDescriptionInputs.TangentSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceBiTangent"),
// new Dependency("VertexDescriptionInputs.TangentSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceNormal"),
// TODO : screen position accessible in vertex shader
// new Dependency("VertexDescriptionInputs.ScreenPosition", "VertexDescriptionInputs.WorldSpacePosition"),
new Dependency ( "VertexDescriptionInputs.uv0" , "AttributesMesh.uv0" ) ,
new Dependency ( "VertexDescriptionInputs.uv1" , "AttributesMesh.uv1" ) ,
new Dependency ( "VertexDescriptionInputs.uv2" , "AttributesMesh.uv2" ) ,
new Dependency ( "VertexDescriptionInputs.uv3" , "AttributesMesh.uv3" ) ,
new Dependency ( "VertexDescriptionInputs.VertexColor" , "AttributesMesh.color" ) ,
} ;
} ;
// TODO: move this out of HDRPShaderStructs
static public void AddActiveFieldsFromVertexGraphRequirements ( HashSet < string > activeFields , ShaderGraphRequirements requirements )
{
if ( requirements . requiresScreenPosition )
{
activeFields . Add ( "VertexDescriptionInputs.ScreenPosition" ) ;
}
if ( requirements . requiresVertexColor )
{
activeFields . Add ( "VertexDescriptionInputs.VertexColor" ) ;
}
if ( requirements . requiresNormal ! = 0 )
{
if ( ( requirements . requiresNormal & NeededCoordinateSpace . Object ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.ObjectSpaceNormal" ) ;
if ( ( requirements . requiresNormal & NeededCoordinateSpace . View ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.ViewSpaceNormal" ) ;
if ( ( requirements . requiresNormal & NeededCoordinateSpace . World ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.WorldSpaceNormal" ) ;
if ( ( requirements . requiresNormal & NeededCoordinateSpace . Tangent ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.TangentSpaceNormal" ) ;
}
if ( requirements . requiresTangent ! = 0 )
{
if ( ( requirements . requiresTangent & NeededCoordinateSpace . Object ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.ObjectSpaceTangent" ) ;
if ( ( requirements . requiresTangent & NeededCoordinateSpace . View ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.ViewSpaceTangent" ) ;
if ( ( requirements . requiresTangent & NeededCoordinateSpace . World ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.WorldSpaceTangent" ) ;
if ( ( requirements . requiresTangent & NeededCoordinateSpace . Tangent ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.TangentSpaceTangent" ) ;
}
if ( requirements . requiresBitangent ! = 0 )
{
if ( ( requirements . requiresBitangent & NeededCoordinateSpace . Object ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.ObjectSpaceBiTangent" ) ;
if ( ( requirements . requiresBitangent & NeededCoordinateSpace . View ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.ViewSpaceBiTangent" ) ;
if ( ( requirements . requiresBitangent & NeededCoordinateSpace . World ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.WorldSpaceBiTangent" ) ;
if ( ( requirements . requiresBitangent & NeededCoordinateSpace . Tangent ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.TangentSpaceBiTangent" ) ;
}
if ( requirements . requiresViewDir ! = 0 )
{
if ( ( requirements . requiresViewDir & NeededCoordinateSpace . Object ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.ObjectSpaceViewDirection" ) ;
if ( ( requirements . requiresViewDir & NeededCoordinateSpace . View ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.ViewSpaceViewDirection" ) ;
if ( ( requirements . requiresViewDir & NeededCoordinateSpace . World ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.WorldSpaceViewDirection" ) ;
if ( ( requirements . requiresViewDir & NeededCoordinateSpace . Tangent ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.TangentSpaceViewDirection" ) ;
}
if ( requirements . requiresPosition ! = 0 )
{
if ( ( requirements . requiresPosition & NeededCoordinateSpace . Object ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.ObjectSpacePosition" ) ;
if ( ( requirements . requiresPosition & NeededCoordinateSpace . View ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.ViewSpacePosition" ) ;
if ( ( requirements . requiresPosition & NeededCoordinateSpace . World ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.WorldSpacePosition" ) ;
if ( ( requirements . requiresPosition & NeededCoordinateSpace . Tangent ) > 0 )
activeFields . Add ( "VertexDescriptionInputs.TangentSpacePosition" ) ;
}
foreach ( var channel in requirements . requiresMeshUVs . Distinct ( ) )
{
activeFields . Add ( "VertexDescriptionInputs." + channel . GetUVName ( ) ) ;
}
}
// TODO: move this out of HDRPShaderStructs
static public void AddActiveFieldsFromPixelGraphRequirements ( HashSet < string > activeFields , ShaderGraphRequirements requirements )
activeFields . Add ( "SurfaceDescriptionInputs.screenPosition" ) ;
activeFields . Add ( "SurfaceDescriptionInputs.ScreenPosition" ) ;
activeFields . Add ( "SurfaceDescriptionInputs.vertexColor" ) ;
activeFields . Add ( "SurfaceDescriptionInputs.VertexColor" ) ;
}
if ( requirements . requiresNormal ! = 0 )
}
}
// TODO : split this function into buildActiveFields and buildHLSLTypeDeclaration functions
public static void Generate (
ShaderGenerator codeResult ,
ShaderGenerator graphInputsResult ,
ShaderGraphRequirements graphRequirements ,
public static void AddRequiredFields (
CoordinateSpace preferedCoordinateSpace ,
if ( preferedCoordinateSpace = = CoordinateSpace . Tangent )
preferedCoordinateSpace = CoordinateSpace . World ;
// build initial requirements
AddActiveFieldsFromGraphRequirements ( activeFields , graphRequirements ) ;
if ( passRequiredFields ! = null )
{
foreach ( var requiredField in passRequiredFields )
}
}
public static void Generate (
ShaderGenerator codeResult ,
HashSet < string > activeFields )
{
// propagate requirements using dependencies
{
ShaderSpliceUtil . ApplyDependencies (
FragInputs . dependencies ,
VaryingsMeshToPS . standardDependencies ,
SurfaceDescriptionInputs . dependencies ,
VertexDescriptionInputs . dependencies
} ) ;
}
ShaderSpliceUtil . BuildType ( typeof ( VaryingsMeshToDS ) , activeFields , codeResult ) ;
ShaderSpliceUtil . BuildPackedType ( typeof ( VaryingsMeshToPS ) , activeFields , codeResult ) ;
ShaderSpliceUtil . BuildPackedType ( typeof ( VaryingsMeshToDS ) , activeFields , codeResult ) ;
ShaderSpliceUtil . BuildType ( typeof ( SurfaceDescriptionInputs ) , activeFields , graphInputsResult ) ;
}
} ;
public static class HDSubShaderUtilities
{
public static List < MaterialSlot > FindSlotsOnMasterNode ( IEnumerable < int > slots , PBRMasterNode masterNode )
{
var activeSlots = new List < MaterialSlot > ( ) ;
if ( slots ! = null )
{
foreach ( var id in slots )
{
MaterialSlot slot = masterNode . FindSlot < MaterialSlot > ( id ) ;
if ( slot ! = null )
{
activeSlots . Add ( slot ) ;
}
}
}
return activeSlots ;
}
public static void BuildRenderStatesFromPassAndMaterialOptions (
Pass pass ,
SurfaceMaterialOptions materialOptions ,