コード例 #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
        static new public void SetupMaterialKeywordsAndPass(Material material)
        {
            SetupBaseLitKeywords(material);
            SetupBaseLitMaterialPass(material);
            SetupLayersMappingKeywords(material);

            for (int i = 0; i < kMaxLayerCount; ++i)
            {
                NormalMapSpace normalMapSpace = ((NormalMapSpace)material.GetFloat(kNormalMapSpace + i));

                SetKeyword(material, "_NORMALMAP_TANGENT_SPACE" + i, normalMapSpace == NormalMapSpace.TangentSpace);

                if (normalMapSpace == NormalMapSpace.TangentSpace)
                {
                    SetKeyword(material, "_NORMALMAP" + i, material.GetTexture(kNormalMap + i) || material.GetTexture(kDetailMap + i));
                }
                else
                {
                    SetKeyword(material, "_NORMALMAP" + i, material.GetTexture(kNormalMapOS + i) || material.GetTexture(kDetailMap + i));
                }

                SetKeyword(material, "_MASKMAP" + i, material.GetTexture(kMaskMap + i));

                SetKeyword(material, "_SPECULAROCCLUSIONMAP" + i, material.GetTexture(kSpecularOcclusionMap + i));

                SetKeyword(material, "_DETAIL_MAP" + i, material.GetTexture(kDetailMap + i));

                SetKeyword(material, "_HEIGHTMAP" + i, material.GetTexture(kHeightMap + i));
            }

            SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));

            SetKeyword(material, "_MAIN_LAYER_INFLUENCE_MODE", material.GetFloat(kkUseMainLayerInfluence) != 0.0f);

            VertexColorMode VCMode = (VertexColorMode)material.GetFloat(kVertexColorMode);

            if (VCMode == VertexColorMode.Multiply)
            {
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", true);
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
            }
            else if (VCMode == VertexColorMode.Add)
            {
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", true);
            }
            else
            {
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
            }

            bool useHeightBasedBlend = material.GetFloat(kUseHeightBasedBlend) != 0.0f;

            SetKeyword(material, "_HEIGHT_BASED_BLEND", useHeightBasedBlend);

            bool useDensityModeEnable = material.GetFloat(kUseDensityMode) != 0.0f;

            SetKeyword(material, "_DENSITY_MODE", useDensityModeEnable);
        }
コード例 #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
        static new public void SetupMaterialKeywordsAndPass(Material material)
        {
            SetupBaseLitKeywords(material);
            SetupBaseLitMaterialPass(material);
            SetupLayersMappingKeywords(material);

            for (int i = 0; i < kMaxLayerCount; ++i)
            {
                NormalMapSpace normalMapSpace = ((NormalMapSpace)material.GetFloat(kNormalMapSpace + i));

                SetKeyword(material, "_NORMALMAP_TANGENT_SPACE" + i, normalMapSpace == NormalMapSpace.TangentSpace);

                if (normalMapSpace == NormalMapSpace.TangentSpace)
                {
                    SetKeyword(material, "_NORMALMAP" + i, material.GetTexture(kNormalMap + i) || material.GetTexture(kDetailMap + i));
                    SetKeyword(material, "_BENTNORMALMAP" + i, material.GetTexture(kBentNormalMap + i));
                }
                else
                {
                    SetKeyword(material, "_NORMALMAP" + i, material.GetTexture(kNormalMapOS + i) || material.GetTexture(kDetailMap + i));
                    SetKeyword(material, "_BENTNORMALMAP" + i, material.GetTexture(kBentNormalMapOS + i));
                }

                SetKeyword(material, "_MASKMAP" + i, material.GetTexture(kMaskMap + i));

                SetKeyword(material, "_DETAIL_MAP" + i, material.GetTexture(kDetailMap + i));

                SetKeyword(material, "_HEIGHTMAP" + i, material.GetTexture(kHeightMap + i));

                SetKeyword(material, "_SUBSURFACE_RADIUS_MAP" + i, material.GetTexture(kSubsurfaceRadiusMap + i));
                SetKeyword(material, "_THICKNESSMAP" + i, material.GetTexture(kThicknessMap + i));
            }

            SetKeyword(material, "_INFLUENCEMASK_MAP", material.GetTexture(kLayerInfluenceMaskMap) && material.GetFloat(kkUseMainLayerInfluence) != 0.0f);

            SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));
            SetKeyword(material, "_ENABLESPECULAROCCLUSION", material.GetFloat(kEnableSpecularOcclusion) > 0.0f);

            SetKeyword(material, "_MAIN_LAYER_INFLUENCE_MODE", material.GetFloat(kkUseMainLayerInfluence) != 0.0f);

            VertexColorMode VCMode = (VertexColorMode)material.GetFloat(kVertexColorMode);

            if (VCMode == VertexColorMode.Multiply)
            {
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", true);
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
            }
            else if (VCMode == VertexColorMode.Add)
            {
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", true);
            }
            else
            {
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
            }

            bool useHeightBasedBlend = material.GetFloat(kUseHeightBasedBlend) != 0.0f;

            SetKeyword(material, "_HEIGHT_BASED_BLEND", useHeightBasedBlend);

            bool useDensityModeEnable = false;

            for (int i = 0; i < material.GetInt(kLayerCount); ++i)
            {
                useDensityModeEnable |= material.GetFloat(kOpacityAsDensity + i) != 0.0f;
            }
            SetKeyword(material, "_DENSITY_MODE", useDensityModeEnable);

            Lit.MaterialId materialId = (Lit.MaterialId)material.GetFloat(kMaterialID);

            SetKeyword(material, "_MATID_SSS", materialId == Lit.MaterialId.LitSSS);
            //SetKeyword(material, "_MATID_STANDARD", materialId == Lit.MaterialId.LitStandard); // See comment in Lit.shader, it is the default, we don't define it
        }
コード例 #3
0
        // All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
        static public void SetupMaterialKeywordsAndPass(Material material)
        {
            BaseLitGUI.SetupBaseLitKeywords(material);
            BaseLitGUI.SetupBaseLitMaterialPass(material);
            SetupLayersMappingKeywords(material);
            BaseLitGUI.SetupStencil(material, material.GetInt(kReceivesSSR) != 0, material.GetMaterialId() == MaterialId.LitSSS);

            for (int i = 0; i < kMaxLayerCount; ++i)
            {
                NormalMapSpace normalMapSpace = ((NormalMapSpace)material.GetFloat(kNormalMapSpace + i));

                CoreUtils.SetKeyword(material, "_NORMALMAP_TANGENT_SPACE" + i, normalMapSpace == NormalMapSpace.TangentSpace);

                if (normalMapSpace == NormalMapSpace.TangentSpace)
                {
                    CoreUtils.SetKeyword(material, "_NORMALMAP" + i, material.GetTexture(kNormalMap + i) || material.GetTexture(kDetailMap + i));
                    CoreUtils.SetKeyword(material, "_BENTNORMALMAP" + i, material.GetTexture(kBentNormalMap + i));
                }
                else
                {
                    CoreUtils.SetKeyword(material, "_NORMALMAP" + i, material.GetTexture(kNormalMapOS + i) || material.GetTexture(kDetailMap + i));
                    CoreUtils.SetKeyword(material, "_BENTNORMALMAP" + i, material.GetTexture(kBentNormalMapOS + i));
                }

                CoreUtils.SetKeyword(material, "_MASKMAP" + i, material.GetTexture(kMaskMap + i));

                CoreUtils.SetKeyword(material, "_DETAIL_MAP" + i, material.GetTexture(kDetailMap + i));

                CoreUtils.SetKeyword(material, "_HEIGHTMAP" + i, material.GetTexture(kHeightMap + i));

                CoreUtils.SetKeyword(material, "_SUBSURFACE_MASK_MAP" + i, material.GetTexture(kSubsurfaceMaskMap + i));
                CoreUtils.SetKeyword(material, "_THICKNESSMAP" + i, material.GetTexture(kThicknessMap + i));
            }

            CoreUtils.SetKeyword(material, "_INFLUENCEMASK_MAP", material.GetTexture(kLayerInfluenceMaskMap) && material.GetFloat(kkUseMainLayerInfluence) != 0.0f);

            CoreUtils.SetKeyword(material, "_EMISSIVE_MAPPING_PLANAR", ((UVBaseMapping)material.GetFloat(kUVEmissive)) == UVBaseMapping.Planar && material.GetTexture(kEmissiveColorMap));
            CoreUtils.SetKeyword(material, "_EMISSIVE_MAPPING_TRIPLANAR", ((UVBaseMapping)material.GetFloat(kUVEmissive)) == UVBaseMapping.Triplanar && material.GetTexture(kEmissiveColorMap));
            CoreUtils.SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));
            CoreUtils.SetKeyword(material, "_ENABLESPECULAROCCLUSION", material.GetFloat(kEnableSpecularOcclusion) > 0.0f);

            CoreUtils.SetKeyword(material, "_MAIN_LAYER_INFLUENCE_MODE", material.GetFloat(kkUseMainLayerInfluence) != 0.0f);

            VertexColorMode VCMode = (VertexColorMode)material.GetFloat(kVertexColorMode);

            if (VCMode == VertexColorMode.Multiply)
            {
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", true);
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
            }
            else if (VCMode == VertexColorMode.Add)
            {
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", true);
            }
            else
            {
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
            }

            bool useHeightBasedBlend = material.GetFloat(kUseHeightBasedBlend) != 0.0f;

            CoreUtils.SetKeyword(material, "_HEIGHT_BASED_BLEND", useHeightBasedBlend);

            bool useDensityModeEnable = false;

            for (int i = 0; i < material.GetInt(kLayerCount); ++i)
            {
                useDensityModeEnable |= material.GetFloat(kOpacityAsDensity + i) != 0.0f;
            }
            CoreUtils.SetKeyword(material, "_DENSITY_MODE", useDensityModeEnable);

            MaterialId materialId = material.GetMaterialId();

            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", materialId == MaterialId.LitSSS);
            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", materialId == MaterialId.LitTranslucent || (materialId == MaterialId.LitSSS && material.GetFloat(kTransmissionEnable) > 0.0f));
        }
コード例 #4
0
ファイル: LayeredLitGUI.cs プロジェクト: zydzy1988/Graphics
        // All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
        static public void SetupLayeredLitKeywordsAndPass(Material material)
        {
            BaseLitGUI.SetupBaseLitKeywords(material);
            BaseLitGUI.SetupBaseLitMaterialPass(material);
            SetupLayersMappingKeywords(material);
            bool receiveSSR = material.GetSurfaceType() == SurfaceType.Opaque ? (material.HasProperty(kReceivesSSR) ? material.GetInt(kReceivesSSR) != 0 : false)
                : (material.HasProperty(kReceivesSSRTransparent) ? material.GetInt(kReceivesSSRTransparent) != 0 : false);

            BaseLitGUI.SetupStencil(material, receiveSSR, material.GetMaterialId() == MaterialId.LitSSS);

            if (material.HasProperty(kAddPrecomputedVelocity))
            {
                CoreUtils.SetKeyword(material, "_ADD_PRECOMPUTED_VELOCITY", material.GetInt(kAddPrecomputedVelocity) != 0);
            }


            for (int i = 0; i < kMaxLayerCount; ++i)
            {
                NormalMapSpace normalMapSpace = ((NormalMapSpace)material.GetFloat(kNormalMapSpace + i));

                CoreUtils.SetKeyword(material, "_NORMALMAP_TANGENT_SPACE" + i, normalMapSpace == NormalMapSpace.TangentSpace);

                if (normalMapSpace == NormalMapSpace.TangentSpace)
                {
                    CoreUtils.SetKeyword(material, "_NORMALMAP" + i, material.GetTexture(kNormalMap + i) || material.GetTexture(kDetailMap + i));
                    CoreUtils.SetKeyword(material, "_BENTNORMALMAP" + i, material.GetTexture(kBentNormalMap + i));
                }
                else
                {
                    CoreUtils.SetKeyword(material, "_NORMALMAP" + i, material.GetTexture(kNormalMapOS + i) || material.GetTexture(kDetailMap + i));
                    CoreUtils.SetKeyword(material, "_BENTNORMALMAP" + i, material.GetTexture(kBentNormalMapOS + i));
                }

                CoreUtils.SetKeyword(material, "_MASKMAP" + i, material.GetTexture(kMaskMap + i));

                CoreUtils.SetKeyword(material, "_DETAIL_MAP" + i, material.GetTexture(kDetailMap + i));

                CoreUtils.SetKeyword(material, "_HEIGHTMAP" + i, material.GetTexture(kHeightMap + i));

                CoreUtils.SetKeyword(material, "_SUBSURFACE_MASK_MAP" + i, material.GetTexture(kSubsurfaceMaskMap + i));
                CoreUtils.SetKeyword(material, "_THICKNESSMAP" + i, material.GetTexture(kThicknessMap + i));
            }

            CoreUtils.SetKeyword(material, "_INFLUENCEMASK_MAP", material.GetTexture(kLayerInfluenceMaskMap) && material.GetFloat(kkUseMainLayerInfluence) != 0.0f);

            CoreUtils.SetKeyword(material, "_EMISSIVE_MAPPING_PLANAR", ((UVEmissiveMapping)material.GetFloat(kUVEmissive)) == UVEmissiveMapping.Planar && material.GetTexture(kEmissiveColorMap));
            CoreUtils.SetKeyword(material, "_EMISSIVE_MAPPING_TRIPLANAR", ((UVEmissiveMapping)material.GetFloat(kUVEmissive)) == UVEmissiveMapping.Triplanar && material.GetTexture(kEmissiveColorMap));
            CoreUtils.SetKeyword(material, "_EMISSIVE_MAPPING_BASE", ((UVEmissiveMapping)material.GetFloat(kUVEmissive)) == UVEmissiveMapping.SameAsBase && material.GetTexture(kEmissiveColorMap));
            CoreUtils.SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));

            // For migration of specular occlusion to specular mode we remove previous keyword
            // _ENABLESPECULAROCCLUSION is deprecated
            CoreUtils.SetKeyword(material, "_ENABLESPECULAROCCLUSION", false);

            int specOcclusionMode = material.GetInt(kSpecularOcclusionMode);

            CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_NONE", specOcclusionMode == 0);
            CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP", specOcclusionMode == 2);
            CoreUtils.SetKeyword(material, "_MAIN_LAYER_INFLUENCE_MODE", material.GetFloat(kkUseMainLayerInfluence) != 0.0f);

            VertexColorMode VCMode = (VertexColorMode)material.GetFloat(kVertexColorMode);

            if (VCMode == VertexColorMode.Multiply)
            {
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", true);
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
            }
            else if (VCMode == VertexColorMode.Add)
            {
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", true);
            }
            else
            {
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
                CoreUtils.SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
            }

            bool useHeightBasedBlend = material.GetFloat(kUseHeightBasedBlend) != 0.0f;

            CoreUtils.SetKeyword(material, "_HEIGHT_BASED_BLEND", useHeightBasedBlend);

            bool useDensityModeEnable = false;

            for (int i = 0; i < material.GetInt(kLayerCount); ++i)
            {
                useDensityModeEnable |= material.GetFloat(kOpacityAsDensity + i) != 0.0f;
            }
            CoreUtils.SetKeyword(material, "_DENSITY_MODE", useDensityModeEnable);

            MaterialId materialId = material.GetMaterialId();

            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", materialId == MaterialId.LitSSS);
            CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", materialId == MaterialId.LitTranslucent || (materialId == MaterialId.LitSSS && material.GetFloat(kTransmissionEnable) > 0.0f));
        }
コード例 #5
0
        public static void SetupMaterialLightingMode(Material material)
        {
            if (material == null)
            {
                throw new ArgumentNullException("material");
            }

            LightingMode    lightingMode    = (LightingMode)material.GetFloat("_LightingMode");
            VertexColorMode vertexColorMode = (VertexColorMode)material.GetFloat("_VertexColorMode");

            bool lightingBakedEnabled       = material.GetFloat("_LightingBaked") == 1;
            bool lightingVertexColorEnabled = vertexColorMode == VertexColorMode.Lighting;
            bool lightingDynamicEnabled     = material.GetFloat("_LightingDynamic") == 1;

            if (vertexColorMode == VertexColorMode.Color)
            {
                material.EnableKeyword("_VERTEX_COLOR_MODE_COLOR");
            }
            else
            {
                material.DisableKeyword("_VERTEX_COLOR_MODE_COLOR");
            }

            switch (lightingMode)
            {
            case LightingMode.Unlit:
            {
                material.DisableKeyword("_LIGHTING_BAKED_ON");
                material.DisableKeyword("_VERTEX_COLOR_MODE_LIGHTING");
                material.DisableKeyword("_LIGHTING_DYNAMIC_ON");
                break;
            }

            case LightingMode.Lit:
            default:         // Old versions of the material can have enum values serialized outside the range that we are currently supporting. Default these materials back to lit.
            {
                if (lightingBakedEnabled)
                {
                    material.EnableKeyword("_LIGHTING_BAKED_ON");
                }
                else
                {
                    material.DisableKeyword("_LIGHTING_BAKED_ON");
                }

                if (lightingVertexColorEnabled)
                {
                    material.EnableKeyword("_VERTEX_COLOR_MODE_LIGHTING");
                }
                else
                {
                    material.DisableKeyword("_VERTEX_COLOR_MODE_LIGHTING");
                }

                if (lightingDynamicEnabled)
                {
                    material.EnableKeyword("_LIGHTING_DYNAMIC_ON");
                }
                else
                {
                    material.DisableKeyword("_LIGHTING_DYNAMIC_ON");
                }
                break;
            }
            }
        }
コード例 #6
0
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    {
        Material tm = materialEditor.target as Material;

        _specGlossMap       = tm.IsKeywordEnabled("_SPECGLOSSMAP");
        _metallic           = tm.IsKeywordEnabled("_METALLIC");
        _vertexColorMode    = (VertexColorMode)ShaderGUIUtils.GetMultiCompileKeywordIndex(vertexColorKeywords, tm);
        _alphaTest          = tm.IsKeywordEnabled("_ALPHATEST_ON");
        _isTerrain          = tm.shader.name.Contains("Terrain");
        _isEnv              = tm.shader.name.Contains("Environment");
        is2Side             = tm.shader.name.Contains("2-Side");
        _isCharacter        = tm.shader.name.Contains("Character");
        _rimLight           = tm.IsKeywordEnabled("RIM_LIGHT");
        _deathDissolve      = tm.IsKeywordEnabled("DEATH_DISSOLVE");
        _breakable          = tm.IsKeywordEnabled("IS_BREAKABLE");
        _reverseBack        = tm.IsKeywordEnabled("REVERSE_BACKSIDE");
        _emissionOnLightmap = (tm.globalIlluminationFlags == MaterialGlobalIlluminationFlags.BakedEmissive);
        //clean up shader keywords
        List <string> keywords = new List <string>();

        foreach (string s in tm.shaderKeywords)
        {
            if (ArrayUtility.Contains <string>(allKeywords, s))
            {
                keywords.Add(s);
            }
        }
        tm.shaderKeywords = keywords.ToArray();

        terrainCount = 0;

        if (is2Side)
        {
            _reverseBack = ShaderGUIUtils.ShaderKeywordToggle("反转反向法线", _reverseBack, "REVERSE_BACKSIDE", tm);
        }
        _vertexColorMode = (VertexColorMode)ShaderGUIUtils.MultiKeywordSwitch("顶点色模式", vertexColorOptions, vertexColorKeywords, (int)_vertexColorMode, tm);
        _alphaTest       = ShaderGUIUtils.ShaderKeywordToggle("使用Alpha Test", _alphaTest, "_ALPHATEST_ON", tm);

        if (_alphaTest)
        {
            MaterialProperty _Cutoff = FindProperty("_Cutoff", properties);
            _Cutoff.floatValue = EditorGUILayout.Slider("Alpha Cutoff", _Cutoff.floatValue, 0, 1);
            //materialEditor.FloatProperty(FindProperty("_Cutoff", properties), "Cutoff");
        }
        EditorGUILayout.Space();

        MaterialProperty _Color = FindProperty("_Color", properties);

        materialEditor.ColorProperty(_Color, "整体颜色");
        MaterialProperty _MainTex = FindProperty("_MainTex", properties);

        materialEditor.TexturePropertySingleLine(new GUIContent("主贴图", "RGB - albedo, A - 透明度"), _MainTex);
        MaterialProperty _BumpMap = FindProperty("_BumpMap", properties);

        materialEditor.TexturePropertySingleLine(new GUIContent("法线贴图"), _BumpMap);

        if (_isTerrain)
        {
            materialEditor.TextureScaleOffsetProperty(_MainTex);
            terrainCount = 1;
        }

        if (!_isTerrain)
        {
            if (!_isCharacter)
            {
                _metallic = ShaderGUIUtils.ShaderKeywordToggle("金属度模式", _metallic, "_METALLIC", tm);

                MaterialProperty _EmissionColor = FindProperty("_EmissionColor", properties);
                materialEditor.ColorProperty(_EmissionColor, "自发光颜色");

                MaterialProperty _EmissionMap = FindProperty("_EmissionMap", properties);
                materialEditor.TexturePropertySingleLine(new GUIContent("自发光贴图"), _EmissionMap);
            }


            // if (!_specGlossMap)
            // {
            //     if (_metallic)
            //     {
            //         MaterialProperty _Metallic = FindProperty("_Metallic", properties);
            //         _Metallic.floatValue = EditorGUILayout.Slider("金属度", _Metallic.floatValue, 0, 1);
            //         MaterialProperty _Roughness = FindProperty("_Roughness", properties);
            //         _Roughness.floatValue = EditorGUILayout.Slider("粗糙度", _Roughness.floatValue, 0, 1);
            //     }
            //     else
            //     {
            //         materialEditor.ColorProperty(FindProperty("_SpecColor", properties), "高光色");
            //         MaterialProperty _Glossiness = FindProperty("_Glossiness", properties);
            //         _Glossiness.floatValue = EditorGUILayout.Slider("光滑度", _Glossiness.floatValue, 0, 1);
            //     }
            // }
            MaterialProperty _SpecGlossMap = FindProperty("_SpecGlossMap", properties);
            if (_metallic)
            {
                materialEditor.TexturePropertySingleLine(new GUIContent("高光贴图(MRAV)", "R-金属度,G-粗糙度,B-AO,A-顶点色遮罩"), _SpecGlossMap);
            }
            else
            {
                materialEditor.TexturePropertySingleLine(new GUIContent("R-光泽度 G-透贴 B-自发光遮罩", "R - 光泽度,G - 透贴, B - 自发光遮罩"), _SpecGlossMap);
                // materialEditor.TexturePropertySingleLine(new GUIContent("高光贴图(SSSG)", "RGB - 高光色, A - 光滑度"), _SpecGlossMap);

                // if (_isCharacter || _isEnv){
                MaterialProperty _Glossiness = FindProperty("_Glossiness", properties);
                _Glossiness.floatValue = EditorGUILayout.Slider("光滑度", _Glossiness.floatValue, 0, 1);
                if (_Glossiness.floatValue < 0.01f)
                {
                    tm.EnableKeyword("NO_DIRECT_SPECULAR");
                }
                else
                {
                    tm.DisableKeyword("NO_DIRECT_SPECULAR");
                }
                // }
            }
            _emissionOnLightmap = EditorGUILayout.ToggleLeft("自发光影响Lightmap", _emissionOnLightmap);
            MaterialProperty _EmissionLightmapScale = FindProperty("_EmissionLightmapScale", properties);
            materialEditor.FloatProperty(_EmissionLightmapScale, "Lightmap中自发光强度");
        }



        if (_isCharacter)
        {
            tm.EnableKeyword("EMISSION_ADJUSTMENT");

            _rimLight = ShaderGUIUtils.ShaderKeywordToggle("边缘发光效果", _rimLight, "RIM_LIGHT", tm);
            if (_rimLight)
            {
                // MaterialProperty _RimColor = FindProperty("_RimColor", properties);
                // materialEditor.ColorProperty(_RimColor, "边缘发光颜色");

                // MaterialProperty _RimFactor = FindProperty("_RimFactor", properties);
                // materialEditor.VectorProperty(_RimFactor, "边缘光参数    X:   Y:  Z:范围  W:强度  ");
            }
            _deathDissolve = ShaderGUIUtils.ShaderKeywordToggle("死亡溶解效果", _deathDissolve, "DEATH_DISSOLVE", tm);
            if (_deathDissolve)
            {
                MaterialProperty _DissovleColor = FindProperty("_DissolveColor", properties);
                materialEditor.ColorProperty(_DissovleColor, "溶解边界颜色");
                MaterialProperty _DissolveTex = FindProperty("_DissolveTex", properties);
                materialEditor.TexturePropertySingleLine(new GUIContent("溶解灰度贴图"), _DissolveTex);
            }
        }
        else
        {
            tm.DisableKeyword("EMISSION_ADJUSTMENT");
        }

        if (_isEnv)
        {
            _breakable = ShaderGUIUtils.ShaderKeywordToggle("是否击碎物", _breakable, "IS_BREAKABLE", tm);
            if (_breakable)
            {
                MaterialProperty _BreakableDistance = FindProperty("_BreakableDistance", properties);
                materialEditor.FloatProperty(_BreakableDistance, "击碎物标记距离");
                MaterialProperty _BreakableColor = FindProperty("_BreakableColor", properties);
                materialEditor.ColorProperty(_BreakableColor, "击碎物边缘颜色");
            }
        }

        if (_isTerrain)
        {
            MaterialProperty _SpecMap = FindProperty("_SpecMap", properties);
            materialEditor.TexturePropertySingleLine(new GUIContent("L1 高光", "RGB - Spec"), _SpecMap);

            // L2
            // EditorGUILayout.LabelField("地形用贴图区域");
            MaterialProperty _MainTex1 = FindProperty("_MainTex1", properties);
            materialEditor.TexturePropertySingleLine(new GUIContent("L2 纹理", "RGB - diffuse"), _MainTex1);
            if (tm.GetTexture("_MainTex1") != null)
            {
                terrainCount = 2;
            }
            MaterialProperty _BumpMap1 = FindProperty("_BumpMap1", properties);
            materialEditor.TexturePropertySingleLine(new GUIContent("L2 法线", "RGB - 法线"), _BumpMap1);

            MaterialProperty _SpecMap2 = FindProperty("_SpecMap1", properties);
            materialEditor.TexturePropertySingleLine(new GUIContent("L2 高光", "RGB - Spec"), _SpecMap2);


            // L3
            MaterialProperty _MainTex2 = FindProperty("_MainTex2", properties);
            materialEditor.TexturePropertySingleLine(new GUIContent("L3 纹理", "RGB - diffuse, A - 光滑度"), _MainTex2);
            if (tm.GetTexture("_MainTex2") != null)
            {
                terrainCount = 3;
            }
            MaterialProperty _BumpMap2 = FindProperty("_BumpMap2", properties);
            materialEditor.TexturePropertySingleLine(new GUIContent("L3 法线", "RGB - 法线"), _BumpMap2);

            MaterialProperty _SpecMap3 = FindProperty("_SpecMap2", properties);
            materialEditor.TexturePropertySingleLine(new GUIContent("L3 高光", "RGB - Spec"), _SpecMap3);

            MaterialProperty _SplatTex = FindProperty("_SplatTex", properties);
            materialEditor.TexturePropertySingleLine(new GUIContent("地形混合贴图", "RGB - 对应三个层次"), _SplatTex);
        }

        if (tm.GetTexture("_BumpMap") != null)
        {
            tm.EnableKeyword("_NORMALMAP");
        }
        else
        {
            tm.DisableKeyword("_NORMALMAP");
        }

        if (tm.GetTexture("_SpecGlossMap") != null)
        {
            tm.EnableKeyword("_SPECGLOSSMAP");
        }
        else
        {
            tm.DisableKeyword("_SPECGLOSSMAP");
            MaterialProperty _Glossiness = FindProperty("_Glossiness", properties);
            if (_Glossiness.floatValue < 0.01f)
            {
                tm.EnableKeyword("NO_DIRECT_SPECULAR");
            }
            else
            {
                tm.DisableKeyword("NO_DIRECT_SPECULAR");
            }
        }

        if (!_isTerrain)
        {
            MaterialProperty _EmissionColor = FindProperty("_EmissionColor", properties);
            if (_EmissionColor.colorValue.grayscale > 0.01f)
            {
                tm.EnableKeyword("_EMISSION");
                tm.globalIlluminationFlags = (_emissionOnLightmap)?MaterialGlobalIlluminationFlags.BakedEmissive : MaterialGlobalIlluminationFlags.None;
            }
            else
            {
                tm.DisableKeyword("_EMISSION");
            }
        }



        if (_isTerrain)
        {
            //Debug.Log("Terrain Count " + terrainCount);
            tm.DisableKeyword("IS_TERRAIN");
            if (terrainCount == 1)
            {
                tm.EnableKeyword("ONE_LAYER"); tm.DisableKeyword("TWO_LAYER"); tm.DisableKeyword("THREE_LAYER");
            }
            if (terrainCount == 2)
            {
                tm.DisableKeyword("ONE_LAYER"); tm.EnableKeyword("TWO_LAYER"); tm.DisableKeyword("THREE_LAYER");
            }
            if (terrainCount == 3)
            {
                tm.DisableKeyword("ONE_LAYER"); tm.DisableKeyword("TWO_LAYER"); tm.EnableKeyword("THREE_LAYER");
            }
        }
        tm.DisableKeyword("VIRTUAL_LIGHT_ON");
    }
コード例 #7
0
        protected override void SetupMaterialKeywords(Material material)
        {
            SetupCommonOptionsKeywords(material);
            SetupLayersKeywords(material);

            // Find first non null layer
            int i = 0;

            while (i < numLayer && (m_MaterialLayers[i] == null))
            {
                ++i;
            }

            if (i < numLayer)
            {
                SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap + i));
                SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap + i));
                SetKeyword(material, "_SPECULAROCCLUSIONMAP", material.GetTexture(kSpecularOcclusionMap + i));
                SetKeyword(material, "_HEIGHTMAP", material.GetTexture(kHeightMap + i));
                SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap + i));

                SetKeyword(material, "_DETAIL_MAP_WITH_NORMAL", ((DetailMapMode)material.GetFloat(kDetailMapMode)) == DetailMapMode.DetailWithNormal);
                bool perPixelDisplacement = material.GetFloat(kEnablePerPixelDisplacement) == 1.0;
                SetKeyword(material, "_PER_PIXEL_DISPLACEMENT", perPixelDisplacement);
                SetKeyword(material, "_NORMALMAP_TANGENT_SPACE", ((NormalMapSpace)material.GetFloat(kNormalMapSpace)) == NormalMapSpace.TangentSpace);
                SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", ((SmoothnessMapChannel)material.GetFloat(kSmoothnessTextureChannel)) == SmoothnessMapChannel.AlbedoAlpha);
            }

            SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));

            SetKeyword(material, "_MAIN_LAYER_INFLUENCE_MODE", material.GetFloat(kkUseMainLayerInfluence) != 0.0f);

            VertexColorMode VCMode = (VertexColorMode)vertexColorMode.floatValue;

            if (VCMode == VertexColorMode.Multiply)
            {
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", true);
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
            }
            else if (VCMode == VertexColorMode.Add)
            {
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", true);
            }
            else
            {
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
                SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
            }

            bool useHeightBasedBlend = material.GetFloat(kUseHeightBasedBlend) != 0.0f;

            SetKeyword(material, "_HEIGHT_BASED_BLEND", useHeightBasedBlend);

            bool useDensityModeEnable = material.GetFloat(kUseDensityMode) != 0.0f;

            SetKeyword(material, "_DENSITY_MODE", useDensityModeEnable);


            // We have to check for each layer if the UV2 or UV3 is needed.
            bool needUV3 = false;
            bool needUV2 = false;

            for (int layer = 0; layer < numLayer; ++layer)
            {
                string uvBase   = string.Format("{0}{1}", kUVBase, layer);
                string uvDetail = string.Format("{0}{1}", kUVDetail, layer);

                if (((UVDetailMapping)material.GetFloat(uvDetail) == UVDetailMapping.UV2) ||
                    ((LayerUVBaseMapping)material.GetFloat(uvBase) == LayerUVBaseMapping.UV2))
                {
                    needUV2 = true;
                }

                if (((UVDetailMapping)material.GetFloat(uvDetail) == UVDetailMapping.UV3) ||
                    ((LayerUVBaseMapping)material.GetFloat(uvBase) == LayerUVBaseMapping.UV3))
                {
                    needUV3 = true;
                    break; // If we find it UV3 let's early out
                }
            }

            if (needUV3)
            {
                material.DisableKeyword("_REQUIRE_UV2");
                material.EnableKeyword("_REQUIRE_UV3");
            }
            else if (needUV2)
            {
                material.EnableKeyword("_REQUIRE_UV2");
                material.DisableKeyword("_REQUIRE_UV3");
            }
            else
            {
                material.DisableKeyword("_REQUIRE_UV2");
                material.DisableKeyword("_REQUIRE_UV3");
            }
        }