Esempio n. 1
0
        private static List <string> GetInstancingOptionsFromMasterNode(AbstractMaterialNode iMasterNode)
        {
            List <string> instancingOption = new List <string>();

            HDLitMasterNode masterNode = iMasterNode as HDLitMasterNode;

            if (masterNode.dotsInstancing.isOn)
            {
                instancingOption.Add("#pragma instancing_options nolightprobe");
                instancingOption.Add("#pragma instancing_options nolodfade");
            }
            else
            {
                instancingOption.Add("#pragma instancing_options renderinglayer");
            }

            return(instancingOption);
        }
Esempio n. 2
0
        private static bool GenerateShaderPassLit(HDLitMasterNode masterNode, Pass pass, GenerationMode mode, ShaderGenerator result, List <string> sourceAssetDependencyPaths)
        {
            if (mode == GenerationMode.ForReals || pass.UseInPreview)
            {
                SurfaceMaterialOptions materialOptions = HDSubShaderUtilities.BuildMaterialOptions(masterNode.surfaceType, masterNode.alphaMode, masterNode.doubleSidedMode != DoubleSidedMode.Disabled, masterNode.HasRefraction());

                pass.OnGeneratePass(masterNode);

                // apply master node options to active fields
                HashSet <string> activeFields = GetActiveFieldsFromMasterNode(masterNode, pass);

                // use standard shader pass generation
                bool vertexActive = masterNode.IsSlotConnected(HDLitMasterNode.PositionSlotId);
                return(HDSubShaderUtilities.GenerateShaderPass(masterNode, pass, mode, materialOptions, activeFields, result, sourceAssetDependencyPaths, vertexActive));
            }
            else
            {
                return(false);
            }
        }
        private static bool GenerateShaderPassLit(HDLitMasterNode masterNode, Pass pass, GenerationMode mode, ShaderGenerator result, List <string> sourceAssetDependencyPaths)
        {
            if (mode == GenerationMode.ForReals || pass.UseInPreview)
            {
                pass.OnGeneratePass(masterNode);

                // apply master node options to active fields
                HashSet <string> activeFields = GetActiveFieldsFromMasterNode(masterNode, pass);

                pass.ExtraInstancingOptions = GetInstancingOptionsFromMasterNode(masterNode);

                // use standard shader pass generation
                bool vertexActive = masterNode.IsSlotConnected(HDLitMasterNode.PositionSlotId);
                return(HDSubShaderUtilities.GenerateShaderPass(masterNode, pass, mode, activeFields, result, sourceAssetDependencyPaths, vertexActive));
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        private static HashSet <string> GetActiveFieldsFromMasterNode(INode iMasterNode, Pass pass)
        {
            HashSet <string> activeFields = new HashSet <string>();

            HDLitMasterNode masterNode = iMasterNode as HDLitMasterNode;

            if (masterNode == null)
            {
                return(activeFields);
            }

            if (masterNode.doubleSidedMode != DoubleSidedMode.Disabled)
            {
                activeFields.Add("DoubleSided");
                if (pass.ShaderPassName != "SHADERPASS_VELOCITY")   // HACK to get around lack of a good interpolator dependency system
                {                                                   // we need to be able to build interpolators using multiple input structs
                                                                    // also: should only require isFrontFace if Normals are required...
                    if (masterNode.doubleSidedMode == DoubleSidedMode.FlippedNormals)
                    {
                        activeFields.Add("DoubleSided.Flip");
                    }
                    else if (masterNode.doubleSidedMode == DoubleSidedMode.MirroredNormals)
                    {
                        activeFields.Add("DoubleSided.Mirror");
                    }
                    // Important: the following is used in SharedCode.template.hlsl for determining the normal flip mode
                    activeFields.Add("FragInputs.isFrontFace");
                }
            }

            switch (masterNode.materialType)
            {
            case HDLitMasterNode.MaterialType.Anisotropy:
                activeFields.Add("Material.Anisotropy");
                break;

            case HDLitMasterNode.MaterialType.Iridescence:
                activeFields.Add("Material.Iridescence");
                break;

            case HDLitMasterNode.MaterialType.SpecularColor:
                activeFields.Add("Material.SpecularColor");
                break;

            case HDLitMasterNode.MaterialType.Standard:
                activeFields.Add("Material.Standard");
                break;

            case HDLitMasterNode.MaterialType.SubsurfaceScattering:
            {
                if (masterNode.surfaceType != SurfaceType.Transparent)
                {
                    activeFields.Add("Material.SubsurfaceScattering");
                }
                if (masterNode.sssTransmission.isOn)
                {
                    activeFields.Add("Material.Transmission");
                }
            }
            break;

            case HDLitMasterNode.MaterialType.Translucent:
            {
                activeFields.Add("Material.Translucent");
                activeFields.Add("Material.Transmission");
            }
            break;

            default:
                UnityEngine.Debug.LogError("Unknown material type: " + masterNode.materialType);
                break;
            }

            if (masterNode.alphaTest.isOn)
            {
                int count = 0;
                // If alpha test shadow is enable, we use it, otherwise we use the regular test
                if (pass.PixelShaderUsesSlot(HDLitMasterNode.AlphaThresholdShadowSlotId) && masterNode.alphaTestShadow.isOn)
                {
                    activeFields.Add("AlphaTestShadow");
                    ++count;
                }
                else if (pass.PixelShaderUsesSlot(HDLitMasterNode.AlphaThresholdSlotId))
                {
                    activeFields.Add("AlphaTest");
                    ++count;
                }

                if (pass.PixelShaderUsesSlot(HDLitMasterNode.AlphaThresholdDepthPrepassSlotId))
                {
                    activeFields.Add("AlphaTestPrepass");
                    ++count;
                }
                if (pass.PixelShaderUsesSlot(HDLitMasterNode.AlphaThresholdDepthPostpassSlotId))
                {
                    activeFields.Add("AlphaTestPostpass");
                    ++count;
                }
                UnityEngine.Debug.Assert(count == 1, "Alpha test value not set correctly");
            }

            if (masterNode.surfaceType != SurfaceType.Opaque)
            {
                activeFields.Add("SurfaceType.Transparent");

                if (masterNode.alphaMode == AlphaMode.Alpha)
                {
                    activeFields.Add("BlendMode.Alpha");
                }
                else if (masterNode.alphaMode == AlphaMode.Premultiply)
                {
                    activeFields.Add("BlendMode.Premultiply");
                }
                else if (masterNode.alphaMode == AlphaMode.Additive)
                {
                    activeFields.Add("BlendMode.Add");
                }

                if (masterNode.blendPreserveSpecular.isOn)
                {
                    activeFields.Add("BlendMode.PreserveSpecular");
                }

                if (masterNode.transparencyFog.isOn)
                {
                    activeFields.Add("AlphaFog");
                }
            }

            if (!masterNode.receiveDecals.isOn)
            {
                activeFields.Add("DisableDecals");
            }

            if (!masterNode.receiveSSR.isOn)
            {
                activeFields.Add("DisableSSR");
            }


            if (masterNode.specularAA.isOn && pass.PixelShaderUsesSlot(HDLitMasterNode.SpecularAAThresholdSlotId) && pass.PixelShaderUsesSlot(HDLitMasterNode.SpecularAAScreenSpaceVarianceSlotId))
            {
                activeFields.Add("Specular.AA");
            }

            if (masterNode.energyConservingSpecular.isOn)
            {
                activeFields.Add("Specular.EnergyConserving");
            }

            if (masterNode.HasRefraction())
            {
                activeFields.Add("Refraction");
                switch (masterNode.refractionModel)
                {
                case ScreenSpaceRefraction.RefractionModel.Box:
                    activeFields.Add("RefractionBox");
                    break;

                case ScreenSpaceRefraction.RefractionModel.Sphere:
                    activeFields.Add("RefractionSphere");
                    break;

                default:
                    UnityEngine.Debug.LogError("Unknown refraction model: " + masterNode.refractionModel);
                    break;
                }
            }

            if (masterNode.IsSlotConnected(HDLitMasterNode.BentNormalSlotId) && pass.PixelShaderUsesSlot(HDLitMasterNode.BentNormalSlotId))
            {
                activeFields.Add("BentNormal");
            }

            if (masterNode.IsSlotConnected(HDLitMasterNode.TangentSlotId) && pass.PixelShaderUsesSlot(HDLitMasterNode.TangentSlotId))
            {
                activeFields.Add("Tangent");
            }

            switch (masterNode.specularOcclusionMode)
            {
            case SpecularOcclusionMode.Off:
                break;

            case SpecularOcclusionMode.FromAO:
                activeFields.Add("SpecularOcclusionFromAO");
                break;

            case SpecularOcclusionMode.FromAOAndBentNormal:
                activeFields.Add("SpecularOcclusionFromAOBentNormal");
                break;

            case SpecularOcclusionMode.Custom:
                activeFields.Add("SpecularOcclusionCustom");
                break;

            default:
                break;
            }

            if (pass.PixelShaderUsesSlot(HDLitMasterNode.AmbientOcclusionSlotId))
            {
                var occlusionSlot = masterNode.FindSlot <Vector1MaterialSlot>(HDLitMasterNode.AmbientOcclusionSlotId);

                bool connected = masterNode.IsSlotConnected(HDLitMasterNode.AmbientOcclusionSlotId);
                if (connected || occlusionSlot.value != occlusionSlot.defaultValue)
                {
                    activeFields.Add("AmbientOcclusion");
                }
            }

            if (pass.PixelShaderUsesSlot(HDLitMasterNode.CoatMaskSlotId))
            {
                var coatMaskSlot = masterNode.FindSlot <Vector1MaterialSlot>(HDLitMasterNode.CoatMaskSlotId);

                bool connected = masterNode.IsSlotConnected(HDLitMasterNode.CoatMaskSlotId);
                if (connected || coatMaskSlot.value > 0.0f)
                {
                    activeFields.Add("CoatMask");
                }
            }

            return(activeFields);
        }
Esempio n. 5
0
        private static HashSet <string> GetActiveFieldsFromMasterNode(INode iMasterNode, Pass pass)
        {
            HashSet <string> activeFields = new HashSet <string>();

            HDLitMasterNode masterNode = iMasterNode as HDLitMasterNode;

            if (masterNode == null)
            {
                return(activeFields);
            }

            if (masterNode.doubleSidedMode != DoubleSidedMode.Disabled)
            {
                activeFields.Add("DoubleSided");
                if (pass.ShaderPassName != "SHADERPASS_VELOCITY")   // HACK to get around lack of a good interpolator dependency system
                {                                                   // we need to be able to build interpolators using multiple input structs
                                                                    // also: should only require isFrontFace if Normals are required...
                    if (masterNode.doubleSidedMode == DoubleSidedMode.FlippedNormals)
                    {
                        activeFields.Add("DoubleSided.Flip");
                    }
                    else if (masterNode.doubleSidedMode == DoubleSidedMode.MirroredNormals)
                    {
                        activeFields.Add("DoubleSided.Mirror");
                    }

                    activeFields.Add("FragInputs.isFrontFace");     // will need this for determining normal flip mode
                }
            }

            switch (masterNode.materialType)
            {
            case HDLitMasterNode.MaterialType.Anisotropy:
                activeFields.Add("Material.Anisotropy");
                break;

            case HDLitMasterNode.MaterialType.Iridescence:
                activeFields.Add("Material.Iridescence");
                break;

            case HDLitMasterNode.MaterialType.SpecularColor:
                activeFields.Add("Material.SpecularColor");
                break;

            case HDLitMasterNode.MaterialType.Standard:
                activeFields.Add("Material.Standard");
                break;

            case HDLitMasterNode.MaterialType.SubsurfaceScattering:
            {
                activeFields.Add("Material.SubsurfaceScattering");
                if (masterNode.sssTransmission.isOn)
                {
                    activeFields.Add("Material.Transmission");
                }
            }
            break;

            case HDLitMasterNode.MaterialType.Translucent:
            {
                activeFields.Add("Material.Translucent");
                activeFields.Add("Material.Transmission");
            }
            break;

            default:
                UnityEngine.Debug.LogError("Unknown material type: " + masterNode.materialType);
                break;
            }

            if (masterNode.alphaTest.isOn)
            {
                int count = 0;
                if (pass.PixelShaderUsesSlot(HDLitMasterNode.AlphaThresholdSlotId))
                {
                    activeFields.Add("AlphaTest");
                    ++count;
                }
                if (pass.PixelShaderUsesSlot(HDLitMasterNode.AlphaThresholdDepthPrepassSlotId))
                {
                    activeFields.Add("AlphaTestPrepass");
                    ++count;
                }
                if (pass.PixelShaderUsesSlot(HDLitMasterNode.AlphaThresholdDepthPostpassSlotId))
                {
                    activeFields.Add("AlphaTestPostpass");
                    ++count;
                }
                UnityEngine.Debug.Assert(count == 1, "Alpha test value not set correctly");
            }

            if (masterNode.surfaceType != SurfaceType.Opaque)
            {
                activeFields.Add("SurfaceType.Transparent");

                if (masterNode.alphaMode == AlphaMode.Alpha)
                {
                    activeFields.Add("BlendMode.Alpha");
                }
                else if (masterNode.alphaMode == AlphaMode.Premultiply)
                {
                    activeFields.Add("BlendMode.Premultiply");
                }
                else if (masterNode.alphaMode == AlphaMode.Additive)
                {
                    activeFields.Add("BlendMode.Add");
                }

                if (masterNode.blendPreserveSpecular.isOn)
                {
                    activeFields.Add("BlendMode.PreserveSpecular");
                }

                if (masterNode.transparencyFog.isOn)
                {
                    activeFields.Add("AlphaFog");
                }
            }

            if (masterNode.receiveDecals.isOn)
            {
                activeFields.Add("Decals");
            }

            if (masterNode.specularAA.isOn && pass.PixelShaderUsesSlot(HDLitMasterNode.SpecularAAThresholdSlotId) && pass.PixelShaderUsesSlot(HDLitMasterNode.SpecularAAScreenSpaceVarianceSlotId))
            {
                activeFields.Add("Specular.AA");
            }

            if (masterNode.energyConservingSpecular.isOn)
            {
                activeFields.Add("Specular.EnergyConserving");
            }

            if (masterNode.HasRefraction())
            {
                activeFields.Add("Refraction");
                switch (masterNode.refractionModel)
                {
                case ScreenSpaceLighting.RefractionModel.Plane:
                    activeFields.Add("RefractionPlane");
                    break;

                case ScreenSpaceLighting.RefractionModel.Sphere:
                    activeFields.Add("RefractionSphere");
                    break;

                default:
                    UnityEngine.Debug.LogError("Unknown refraction model: " + masterNode.refractionModel);
                    break;
                }

                switch (masterNode.projectionModel)
                {
                case HDLitMasterNode.ProjectionModelLit.Proxy:
                    activeFields.Add("RefractionSSRayProxy");
                    break;

                case HDLitMasterNode.ProjectionModelLit.HiZ:
                    activeFields.Add("RefractionSSRayHiZ");
                    break;

                default:
                    UnityEngine.Debug.LogError("Unknown projection model: " + masterNode.projectionModel);
                    break;
                }
            }

            if (masterNode.IsSlotConnected(HDLitMasterNode.BentNormalSlotId) && pass.PixelShaderUsesSlot(HDLitMasterNode.BentNormalSlotId))
            {
                activeFields.Add("BentNormal");
            }

            if (masterNode.IsSlotConnected(HDLitMasterNode.TangentSlotId) && pass.PixelShaderUsesSlot(HDLitMasterNode.TangentSlotId))
            {
                activeFields.Add("Tangent");
            }

            switch (masterNode.specularOcclusionMode)
            {
            case SpecularOcclusionMode.Off:
                break;

            case SpecularOcclusionMode.On:
                activeFields.Add("SpecularOcclusion");
                break;

            case SpecularOcclusionMode.OnUseBentNormal:
                activeFields.Add("BentNormalSpecularOcclusion");
                break;

            default:
                break;
            }

            if (pass.PixelShaderUsesSlot(HDLitMasterNode.AmbientOcclusionSlotId))
            {
                var occlusionSlot = masterNode.FindSlot <Vector1MaterialSlot>(HDLitMasterNode.AmbientOcclusionSlotId);
                if (occlusionSlot.value != occlusionSlot.defaultValue)
                {
                    activeFields.Add("Occlusion");
                }
            }

            return(activeFields);
        }