Esempio n. 1
0
        // All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
        public static void SetupMaterialKeywordsAndPass(Material material)
        {
            SetupBaseUnlitKeywords(material);
            SetupBaseUnlitMaterialPass(material);

            bool doubleSidedEnable = material.GetFloat(kDoubleSidedEnable) > 0.0f;

            if (doubleSidedEnable)
            {
                BaseLitGUI.DoubleSidedNormalMode doubleSidedNormalMode =
                    (BaseLitGUI.DoubleSidedNormalMode)material.GetFloat(k_DoubleSidedNormalMode);
                switch (doubleSidedNormalMode)
                {
                case BaseLitGUI.DoubleSidedNormalMode.Mirror:     // Mirror mode (in tangent space)
                    material.SetVector("_DoubleSidedConstants", new Vector4(1.0f, 1.0f, -1.0f, 0.0f));
                    break;

                case BaseLitGUI.DoubleSidedNormalMode.Flip:     // Flip mode (in tangent space)
                    material.SetVector("_DoubleSidedConstants", new Vector4(-1.0f, -1.0f, -1.0f, 0.0f));
                    break;

                case BaseLitGUI.DoubleSidedNormalMode.None:     // None mode (in tangent space)
                    material.SetVector("_DoubleSidedConstants", new Vector4(1.0f, 1.0f, 1.0f, 0.0f));
                    break;
                }
            }

            SetupMainTexForAlphaTestGI("_BaseColorMap", "_BaseColor", material);

            //TODO: disable DBUFFER

            SetupTextureMaterialProperty(material, k_Metallic);
            SetupTextureMaterialProperty(material, k_SmoothnessA);
            SetupTextureMaterialProperty(material, k_SmoothnessB);
            SetupTextureMaterialProperty(material, k_AmbientOcclusion);
            SetupTextureMaterialProperty(material, k_SubsurfaceMask);
            SetupTextureMaterialProperty(material, k_Thickness);
            SetupTextureMaterialProperty(material, k_Anisotropy);
            SetupTextureMaterialProperty(material, k_IridescenceThickness);
            SetupTextureMaterialProperty(material, k_IridescenceMask);
            SetupTextureMaterialProperty(material, k_CoatSmoothness);

            // details
            SetupTextureMaterialProperty(material, k_DetailMask);
            SetupTextureMaterialProperty(material, k_DetailSmoothness);

            // Check if we are using specific UVs.
            TextureProperty.UVMapping[] uvIndices = new[]
            {
                (TextureProperty.UVMapping)material.GetFloat(k_BaseColorMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_MetallicMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_NormalMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_SmoothnessAMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_SmoothnessBMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_AmbientOcclusionMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_EmissiveColorMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_SubsurfaceMaskMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_ThicknessMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_AnisotropyMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_IridescenceThicknessMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_IridescenceMaskMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_CoatSmoothnessMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_CoatNormalMapUV),
                // Details
                (TextureProperty.UVMapping)material.GetFloat(k_DetailMaskMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_DetailSmoothnessMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_DetailNormalMapUV),
            };

            // Set keyword for mapping

            //bool requireUv2 = false;
            //bool requireUv3 = false;
            bool requireTriplanar = false;

            for (int i = 0; i < uvIndices.Length; ++i)
            {
                //requireUv2 = requireUv2 || uvIndices[i] == TextureProperty.UVMapping.UV2;
                //requireUv3 = requireUv3 || uvIndices[i] == TextureProperty.UVMapping.UV3;
                requireTriplanar = requireTriplanar || uvIndices[i] == TextureProperty.UVMapping.Triplanar;
            }
            CoreUtils.SetKeyword(material, "_USE_TRIPLANAR", requireTriplanar);

            bool detailsEnabled = material.HasProperty(k_EnableDetails) && material.GetFloat(k_EnableDetails) > 0.0f;

            CoreUtils.SetKeyword(material, "_USE_DETAILMAP", detailsEnabled);

            bool dualSpecularLobeEnabled = material.HasProperty(k_EnableDualSpecularLobe) && material.GetFloat(k_EnableDualSpecularLobe) > 0.0f;

            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_DUAL_SPECULAR_LOBE", dualSpecularLobeEnabled);

            bool anisotropyEnabled = material.HasProperty(k_EnableAnisotropy) && material.GetFloat(k_EnableAnisotropy) > 0.0f;

            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_ANISOTROPY", anisotropyEnabled);

            bool iridescenceEnabled = material.HasProperty(k_EnableIridescence) && material.GetFloat(k_EnableIridescence) > 0.0f;

            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_IRIDESCENCE", iridescenceEnabled);

            bool transmissionEnabled = material.HasProperty(k_EnableTransmission) && material.GetFloat(k_EnableTransmission) > 0.0f;

            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", transmissionEnabled);

            bool sssEnabled = material.HasProperty(k_EnableSubsurfaceScattering) && material.GetFloat(k_EnableSubsurfaceScattering) > 0.0f;

            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", sssEnabled);

            bool coatEnabled = material.HasProperty(k_EnableCoat) && material.GetFloat(k_EnableCoat) > 0.0f;

            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_COAT", coatEnabled);

            bool coatNormalMapEnabled = material.HasProperty(k_EnableCoatNormalMap) && material.GetFloat(k_EnableCoatNormalMap) > 0.0f;

            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_COAT_NORMALMAP", coatNormalMapEnabled);

            // TEMP - Remove once dev is finish
            bool debugEnabled = material.HasProperty("_DebugEnable") && material.GetFloat("_DebugEnable") > 0.0f;

            CoreUtils.SetKeyword(material, "_STACKLIT_DEBUG", debugEnabled);

            bool vlayerRecomputePerLight = material.HasProperty("_VlayerRecomputePerLight") && material.GetFloat("_VlayerRecomputePerLight") > 0.0f;

            CoreUtils.SetKeyword(material, "_VLAYERED_RECOMPUTE_PERLIGHT", vlayerRecomputePerLight);

            bool vlayerUseRefractedAnglesForBase = material.HasProperty("_VlayerUseRefractedAnglesForBase") && material.GetFloat("_VlayerUseRefractedAnglesForBase") > 0.0f;

            CoreUtils.SetKeyword(material, "_VLAYERED_USE_REFRACTED_ANGLES_FOR_BASE", vlayerUseRefractedAnglesForBase);


            // Set the reference value for the stencil test - required for SSS
            int stencilRef = (int)StencilLightingUsage.RegularLighting;

            if (sssEnabled)
            {
                stencilRef = (int)StencilLightingUsage.SplitLighting;
            }

            // As we tag both during velocity pass and Gbuffer pass we need a separate state and we need to use the write mask
            material.SetInt(kStencilRef, stencilRef);
            material.SetInt(kStencilWriteMask, (int)HDRenderPipeline.StencilBitMask.LightingMask);
            material.SetInt(kStencilRefMV, (int)HDRenderPipeline.StencilBitMask.ObjectVelocity);
            material.SetInt(kStencilWriteMaskMV, (int)HDRenderPipeline.StencilBitMask.ObjectVelocity);
        }
Esempio n. 2
0
        // All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
        public static void SetupMaterialKeywordsAndPass(Material material)
        {
            //TODO see BaseLitUI.cs:SetupBaseLitKeywords (stencil etc)
            SetupBaseUnlitKeywords(material);
            SetupBaseUnlitMaterialPass(material);

            bool doubleSidedEnable = material.GetFloat(kDoubleSidedEnable) > 0.0f;

            if (doubleSidedEnable)
            {
                BaseLitGUI.DoubleSidedNormalMode doubleSidedNormalMode = (BaseLitGUI.DoubleSidedNormalMode)material.GetFloat(k_DoubleSidedNormalMode);
                switch (doubleSidedNormalMode)
                {
                case BaseLitGUI.DoubleSidedNormalMode.Mirror:     // Mirror mode (in tangent space)
                    material.SetVector("_DoubleSidedConstants", new Vector4(1.0f, 1.0f, -1.0f, 0.0f));
                    break;

                case BaseLitGUI.DoubleSidedNormalMode.Flip:     // Flip mode (in tangent space)
                    material.SetVector("_DoubleSidedConstants", new Vector4(-1.0f, -1.0f, -1.0f, 0.0f));
                    break;

                case BaseLitGUI.DoubleSidedNormalMode.None:     // None mode (in tangent space)
                    material.SetVector("_DoubleSidedConstants", new Vector4(1.0f, 1.0f, 1.0f, 0.0f));
                    break;
                }
            }

            //NOTE: For SSS in forward and split lighting, obviously we don't have a gbuffer pass,
            // so no stencil tagging there, but velocity? To check...

            //TODO: stencil state, displacement, wind, depthoffset, tessellation

            SetupMainTexForAlphaTestGI("_BaseColorMap", "_BaseColor", material);

            //TODO: disable DBUFFER

            CoreUtils.SetKeyword(material, "_NORMALMAP_TANGENT_SPACE", true);
            CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture(k_NormalMap));

            SetupTextureMaterialProperty(material, k_Metallic);
            SetupTextureMaterialProperty(material, k_Smoothness1);
            SetupTextureMaterialProperty(material, k_Smoothness2);
            SetupTextureMaterialProperty(material, k_AmbientOcclusion);
            SetupTextureMaterialProperty(material, k_SubsurfaceMask);
            SetupTextureMaterialProperty(material, k_Thickness);

            // Check if we are using specific UVs.
            TextureProperty.UVMapping[] uvIndices = new[]
            {
                (TextureProperty.UVMapping)material.GetFloat(k_BaseColorMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_MetallicMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_NormalMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_Smoothness1MapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_Smoothness2MapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_AmbientOcclusionMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_EmissiveColorMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_SubsurfaceMaskMapUV),
                (TextureProperty.UVMapping)material.GetFloat(k_ThicknessMapUV),
            };

            bool requireUv2       = false;
            bool requireUv3       = false;
            bool requireTriplanar = false;

            for (int i = 0; i < uvIndices.Length; ++i)
            {
                requireUv2       = requireUv2 || uvIndices[i] == TextureProperty.UVMapping.UV2;
                requireUv3       = requireUv3 || uvIndices[i] == TextureProperty.UVMapping.UV3;
                requireTriplanar = requireTriplanar || uvIndices[i] == TextureProperty.UVMapping.Triplanar;
            }

            //CoreUtils.SetKeyword(material, "_USE_UV2", requireUv2);
            //CoreUtils.SetKeyword(material, "_USE_UV3", requireUv3);
            CoreUtils.SetKeyword(material, "_USE_TRIPLANAR", requireTriplanar);

            bool anisotropyEnabled = material.HasProperty(k_Anisotropy) && (material.GetFloat(k_Anisotropy) != 0.0f);
            // TODO: When we have a map, also test for map for enable. (This scheme doesn't allow enabling from
            // neutral value though, better to still have flag and uncheck it in UI code when reach neutral
            // value and re-enable otherwise).
            bool coatEnabled     = material.HasProperty(k_CoatEnable) && (material.GetFloat(k_CoatEnable) > 0.0f);
            bool dualLobeEnabled = material.HasProperty(k_LobeMix) && (material.GetFloat(k_LobeMix) > 0.0f);

            // Note that we don't use the materialId (cf Lit.shader) mechanism in the UI
            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_ANISOTROPY", anisotropyEnabled);
            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_COAT", coatEnabled);
            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_DUAL_LOBE", dualLobeEnabled);
        }