private static bool ShouldSpliceField(System.Type parentType, FieldInfo field, IActiveFields activeFields, out bool isOptional)
        {
            bool fieldActive = true;

            isOptional = field.IsDefined(typeof(Optional), false);
            if (isOptional)
            {
                string fullName = parentType.Name + "." + field.Name;
                if (!activeFields.Contains(fullName))
                {
                    // not active, skip the optional field
                    fieldActive = false;
                }
            }
            return(fieldActive);
        }
Exemplo n.º 2
0
        static void AddActiveFieldsFromGraphRequirements(IActiveFields activeFields, ShaderGraphRequirements requirements, string structName)
        {
            if (requirements.requiresScreenPosition)
            {
                activeFields.Add($"{structName}.ScreenPosition");
            }

            if (requirements.requiresVertexColor)
            {
                activeFields.Add($"{structName}.VertexColor");
            }

            if (requirements.requiresFaceSign)
            {
                activeFields.Add($"{structName}.FaceSign");
            }

            if (requirements.requiresNormal != 0)
            {
                if ((requirements.requiresNormal & NeededCoordinateSpace.Object) > 0)
                {
                    activeFields.Add($"{structName}.ObjectSpaceNormal");
                }

                if ((requirements.requiresNormal & NeededCoordinateSpace.View) > 0)
                {
                    activeFields.Add($"{structName}.ViewSpaceNormal");
                }

                if ((requirements.requiresNormal & NeededCoordinateSpace.World) > 0)
                {
                    activeFields.Add($"{structName}.WorldSpaceNormal");
                }

                if ((requirements.requiresNormal & NeededCoordinateSpace.Tangent) > 0)
                {
                    activeFields.Add($"{structName}.TangentSpaceNormal");
                }
            }

            if (requirements.requiresTangent != 0)
            {
                if ((requirements.requiresTangent & NeededCoordinateSpace.Object) > 0)
                {
                    activeFields.Add($"{structName}.ObjectSpaceTangent");
                }

                if ((requirements.requiresTangent & NeededCoordinateSpace.View) > 0)
                {
                    activeFields.Add($"{structName}.ViewSpaceTangent");
                }

                if ((requirements.requiresTangent & NeededCoordinateSpace.World) > 0)
                {
                    activeFields.Add($"{structName}.WorldSpaceTangent");
                }

                if ((requirements.requiresTangent & NeededCoordinateSpace.Tangent) > 0)
                {
                    activeFields.Add($"{structName}.TangentSpaceTangent");
                }
            }

            if (requirements.requiresBitangent != 0)
            {
                if ((requirements.requiresBitangent & NeededCoordinateSpace.Object) > 0)
                {
                    activeFields.Add($"{structName}.ObjectSpaceBiTangent");
                }

                if ((requirements.requiresBitangent & NeededCoordinateSpace.View) > 0)
                {
                    activeFields.Add($"{structName}.ViewSpaceBiTangent");
                }

                if ((requirements.requiresBitangent & NeededCoordinateSpace.World) > 0)
                {
                    activeFields.Add($"{structName}.WorldSpaceBiTangent");
                }

                if ((requirements.requiresBitangent & NeededCoordinateSpace.Tangent) > 0)
                {
                    activeFields.Add($"{structName}.TangentSpaceBiTangent");
                }
            }

            if (requirements.requiresViewDir != 0)
            {
                if ((requirements.requiresViewDir & NeededCoordinateSpace.Object) > 0)
                {
                    activeFields.Add($"{structName}.ObjectSpaceViewDirection");
                }

                if ((requirements.requiresViewDir & NeededCoordinateSpace.View) > 0)
                {
                    activeFields.Add($"{structName}.ViewSpaceViewDirection");
                }

                if ((requirements.requiresViewDir & NeededCoordinateSpace.World) > 0)
                {
                    activeFields.Add($"{structName}.WorldSpaceViewDirection");
                }

                if ((requirements.requiresViewDir & NeededCoordinateSpace.Tangent) > 0)
                {
                    activeFields.Add($"{structName}.TangentSpaceViewDirection");
                }
            }

            if (requirements.requiresPosition != 0)
            {
                if ((requirements.requiresPosition & NeededCoordinateSpace.Object) > 0)
                {
                    activeFields.Add($"{structName}.ObjectSpacePosition");
                }

                if ((requirements.requiresPosition & NeededCoordinateSpace.View) > 0)
                {
                    activeFields.Add($"{structName}.ViewSpacePosition");
                }

                if ((requirements.requiresPosition & NeededCoordinateSpace.World) > 0)
                {
                    activeFields.Add($"{structName}.WorldSpacePosition");
                }

                if ((requirements.requiresPosition & NeededCoordinateSpace.Tangent) > 0)
                {
                    activeFields.Add($"{structName}.TangentSpacePosition");
                }

                if ((requirements.requiresPosition & NeededCoordinateSpace.AbsoluteWorld) > 0)
                {
                    activeFields.Add($"{structName}.AbsoluteWorldSpacePosition");
                }
            }

            foreach (var channel in requirements.requiresMeshUVs.Distinct())
            {
                activeFields.Add($"{structName}.{channel.GetUVName()}");
            }

            if (requirements.requiresTime)
            {
                activeFields.Add($"{structName}.TimeParameters");
            }

            if (requirements.requiresVertexSkinning)
            {
                activeFields.Add($"{structName}.BoneWeights");
                activeFields.Add($"{structName}.BoneIndices");
            }
        }