public virtual void SetLightingMaterialKeywords(Material material)
 {
     ShurikenMaster.LightMode lightMode = (ShurikenMaster.LightMode)material.GetInt("_LightMode");
     ShurikenMaster.SetKeyword(material, "VFX_LIGHTING", lightMode == ShurikenMaster.LightMode.DynamicPerPixel);
     ShurikenMaster.SetKeyword(material, "VFX_LIGHTING_VERTEX", lightMode == ShurikenMaster.LightMode.DynamicPerVertex);
     ShurikenMaster.SetKeyword(material, "VFX_LIGHTING_SH", lightMode == ShurikenMaster.LightMode.LightProbeProxyVolume);
 }
Пример #2
0
        public override void SetLightingMaterialKeywords(Material material)
        {
            CloudLightMode lightMode = (CloudLightMode)material.GetInt("_LightMode");

            ShurikenMaster.SetKeyword(material, "VFX_LIGHTING", lightMode == CloudLightMode.DynamicPerPixel);
            ShurikenMaster.SetKeyword(material, "VFX_LIGHTING_FAKEDIRECTIONAL", lightMode == CloudLightMode.FakeDirectional);
            ShurikenMaster.SetKeyword(material, "VFX_LIGHTING_RAYMARCH2D", lightMode == CloudLightMode.Raymarch2D);
        }
        public virtual void SetMaterialKeywords(Material material)
        {
            // Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
            // (MaterialProperty value might come from renderer material property block)
            if (GetCapability(ShurikenMaster.Capabilities.Lighting))
            {
                // For custom lighting models
                SetLightingMaterialKeywords(material);
            }

            if (GetCapability(ShurikenMaster.Capabilities.FlipbookBlending))
            {
                ShurikenMaster.SetKeyword(material, "VFX_FLIPBOOKBLEND", material.GetFloat("_EnableFlipbookBlending") == 1.0f);
                ShurikenMaster.SetKeyword(material, "VFX_FLIPBOOKBLEND_OFLOW", material.GetFloat("_EnableOFlowBlending") == 1.0f);
            }

            if (GetCapability(ShurikenMaster.Capabilities.SoftParticles))
            {
                ShurikenMaster.SetKeyword(material, "VFX_DEPTHFADING", material.GetFloat("_SoftParticle") == 1.0f);
            }

            if (GetCapability(ShurikenMaster.Capabilities.CameraFading))
            {
                ShurikenMaster.SetKeyword(material, "VFX_CAMERAFADING", material.GetFloat("_CameraFade") == 1.0f);
            }

            if (GetCapability(ShurikenMaster.Capabilities.UseNormalMap))
            {
                ShurikenMaster.SetKeyword(material, "VFX_USENORMALMAP", material.GetTexture("_NormalMap") != null);
            }
            if (GetCapability(ShurikenMaster.Capabilities.SwitchColorSource))
            {
                ShurikenMaster.SetKeyword(material, "COLORSOURCE_RGBA", material.GetInt("_ColorSetup") == 0);
                ShurikenMaster.SetKeyword(material, "COLORSOURCE_ALPHA", material.GetInt("_ColorSetup") == 1);
                ShurikenMaster.SetKeyword(material, "COLORSOURCE_ALTERNATEALPHA", material.GetInt("_ColorSetup") == 2);
            }
        }
 public void MaterialChanged(Material material)
 {
     ShurikenMaster.SetupMaterialWithBlendMode(material, (ShurikenMaster.ShaderBlendMode)material.GetInt("_BlendMode"));
     SetMaterialKeywords(material);
 }
        protected void ShaderPropertiesVertexStreamsGUI(Material material)
        {
            bool useLighting         = false;
            bool useTangents         = false;
            bool useFlipbookBlending = false;
            bool useCustom1          = false;

            if (GetCapability(ShurikenMaster.Capabilities.Lighting))
            {
                ShurikenMaster.LightMode lightMode = (ShurikenMaster.LightMode)material.GetInt("_LightMode");
                useLighting = lightMode != ShurikenMaster.LightMode.Unlit;
                useTangents = lightMode != ShurikenMaster.LightMode.DynamicPerVertex && material.GetTexture("_NormalMap") != null && useLighting;
            }
            if (GetCapability(ShurikenMaster.Capabilities.FlipbookBlending))
            {
                useFlipbookBlending = flipbookBlend.floatValue == 1.0f;
            }

            ShurikenMaster.DrawHeader(Content.vertexStreamHeader, EditorGUIUtility.ObjectContent(null, typeof(Mesh)).image);

            if (material.IsKeywordEnabled("SKM_REQUIRE_CUSTOM1"))
            {
                useCustom1 = false;
            }

            using (new GUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();

                // Set the streams on all systems using this material
                if (GUILayout.Button(Content.streamApplyToAllSystemsText, EditorStyles.miniButton, GUILayout.Width(120)))
                {
                    List <ParticleSystemVertexStream> streams = new List <ParticleSystemVertexStream>();
                    streams.Add(ParticleSystemVertexStream.Position);

                    if (useLighting)
                    {
                        streams.Add(ParticleSystemVertexStream.Normal);
                    }

                    streams.Add(ParticleSystemVertexStream.Color);
                    streams.Add(ParticleSystemVertexStream.UV);

                    if (useFlipbookBlending)
                    {
                        streams.Add(ParticleSystemVertexStream.UV2);
                        streams.Add(ParticleSystemVertexStream.AnimBlend);
                    }

                    if (useCustom1)
                    {
                        streams.Add(ParticleSystemVertexStream.Custom1X);
                    }

                    if (useTangents)
                    {
                        streams.Add(ParticleSystemVertexStream.Tangent);
                    }

                    ParticleSystemRenderer[] renderers = UnityEngine.Object.FindObjectsOfType(typeof(ParticleSystemRenderer)) as ParticleSystemRenderer[];
                    foreach (ParticleSystemRenderer renderer in renderers)
                    {
                        if (renderer.sharedMaterial == material)
                        {
                            renderer.SetActiveVertexStreams(streams);
                        }
                    }
                }
            }

            // Display list of streams required to make this shader work
            EditorGUI.indentLevel++;
            EditorGUILayout.LabelField(Content.streamPositionText, EditorStyles.label);

            if (useLighting)
            {
                EditorGUILayout.LabelField(Content.streamNormalText, EditorStyles.label);
            }

            EditorGUILayout.LabelField(Content.streamColorText, EditorStyles.label);
            EditorGUILayout.LabelField(Content.streamUVText, EditorStyles.label);

            if (useFlipbookBlending)
            {
                EditorGUILayout.LabelField(Content.streamUV2Text, EditorStyles.label);
                EditorGUILayout.LabelField(Content.streamAnimBlendText, EditorStyles.label);
            }

            if (useTangents)
            {
                EditorGUILayout.LabelField(Content.streamTangentText, EditorStyles.label);
            }

            EditorGUI.indentLevel--;
            EditorGUILayout.Space();
        }
        public void ShaderPropertiesGUI(Material material)
        {
            bool changed = false;

            m_ProgressBar.DoProgressBar(GetShaderComplexity(material));

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();


            ShurikenMaster.ShaderBlendMode blend = (ShurikenMaster.ShaderBlendMode)material.GetInt("_BlendMode");

            // Blending Options
            ShurikenMaster.DrawHeader(Content.blendingHeader, EditorGUIUtility.IconContent("SceneViewFx").image);

            using (new IndentScope(1))
            {
                blendMode.floatValue = (float)(ShurikenMaster.ShaderBlendMode)EditorGUILayout.EnumPopup("Blend Mode", blend);
                if (blend == ShurikenMaster.ShaderBlendMode.Cutout)
                {
                    alphaCutoff.floatValue = EditorGUILayout.Slider(Content.alphaCutoff, alphaCutoff.floatValue, 0.0f, 1.0f);
                }

                if (GetCapability(ShurikenMaster.Capabilities.PremultiplyRGBbyA) && blend == ShurikenMaster.ShaderBlendMode.PremultipliedAlpha)
                {
                    premultiplyRGBbyA.floatValue = EditorGUILayout.Toggle(Content.premultiplyRGBbyA, premultiplyRGBbyA.floatValue == 1.0f) ? 1.0f : 0.0f;
                }
            }

            EditorGUILayout.Space();

            // Lighting Options
            if (GetCapability(ShurikenMaster.Capabilities.Lighting))
            {
                ShurikenMaster.DrawHeader(Content.lightingHeader, EditorGUIUtility.IconContent("SceneViewLighting").image);

                using (new IndentScope(1))
                {
                    ShaderPropertiesLightingGUI(material);
                }

                EditorGUILayout.Space();
            }

            // Shader Options
            ShurikenMaster.DrawHeader(Content.configHeader, EditorGUIUtility.IconContent("PreTextureRGB").image);

            using (new IndentScope(1))
            {
                m_MaterialEditor.TexturePropertySingleLine(Content.colorMap, colorMap, null);

                if (GetCapability(ShurikenMaster.Capabilities.SwitchColorSource))
                {
                    ShurikenMaster.ColorSetup colorsetup = (ShurikenMaster.ColorSetup)material.GetInt("_ColorSetup");
                    if (colorsetup == ShurikenMaster.ColorSetup.RGBFromColorMapAndAlternateAlpha)
                    {
                        m_MaterialEditor.TexturePropertySingleLine(Content.alphaMap, alternateAlphaMap, null);
                    }
                    colorSetup.floatValue = (float)(ShurikenMaster.ColorSetup)EditorGUILayout.EnumPopup("Color Map Type", colorsetup);
                }

                rgbBrightness.floatValue = Mathf.Max(0, EditorGUILayout.FloatField(Content.rgbBrightness, rgbBrightness.floatValue));

                ShaderPropertiesCustomOptionsGUI(material);
            }

            EditorGUILayout.Space();

            // Other Options
            ShurikenMaster.DrawHeader(Content.optionsHeader, EditorGUIUtility.IconContent("Lighting").image);

            using (new IndentScope(1))
            {
                softParticle.floatValue = material.IsKeywordEnabled("VFX_DEPTHFADING") ? 1.0f : 0.0f;
                cameraFade.floatValue   = material.IsKeywordEnabled("VFX_CAMERAFADING") ? 1.0f : 0.0f;

                softParticle.floatValue = EditorGUILayout.Toggle(Content.softParticle, softParticle.floatValue == 1.0f) ? 1.0f : 0.0f;
                if (softParticle.floatValue == 1.0f)
                {
                    using (new IndentScope(1))
                    {
                        softParticleDistance.floatValue = EditorGUILayout.FloatField(Content.softParticleDistance, softParticleDistance.floatValue);
                    }
                }

                cameraFade.floatValue = EditorGUILayout.Toggle(Content.cameraFade, cameraFade.floatValue == 1.0f) ? 1.0f : 0.0f;

                if (cameraFade.floatValue == 1.0f)
                {
                    using (new IndentScope(1))
                    {
                        cameraFadeNear.floatValue = EditorGUILayout.FloatField(Content.cameraFadeNear, cameraFadeNear.floatValue);
                        cameraFadeFar.floatValue  = EditorGUILayout.FloatField(Content.cameraFadeFar, cameraFadeFar.floatValue);
                    }
                }
                flipbookBlend.floatValue = material.IsKeywordEnabled("VFX_FLIPBOOKBLEND") ? 1.0f : 0.0f;
                flipbookBlend.floatValue = EditorGUILayout.Toggle(Content.flipbookBlend, flipbookBlend.floatValue == 1.0f) ? 1.0f : 0.0f;

                if (flipbookBlend.floatValue == 1.0f)
                {
                    flipbookOflow.floatValue = material.IsKeywordEnabled("VFX_FLIPBOOKBLEND_OFLOW") ? 1.0f : 0.0f;
                    flipbookOflow.floatValue = EditorGUILayout.Toggle(Content.flipbookOflowBlend, flipbookOflow.floatValue == 1.0f) ? 1.0f : 0.0f;
                    if (flipbookOflow.floatValue == 1.0f)
                    {
                        using (new IndentScope(1))
                        {
                            m_MaterialEditor.TexturePropertySingleLine(Content.oFlowMap, oFlowMap, null);
                            oFlowIntensity.floatValue = EditorGUILayout.FloatField(Content.oFlowIntensity, oFlowIntensity.floatValue);
                        }
                    }
                }
            }

            // Info
            EditorGUILayout.Space();

            if (EditorGUI.EndChangeCheck())
            {
                HandleMiniLog(material);
                changed = true;
            }

            ShaderPropertiesVertexStreamsGUI(material);

            // Log
            ShurikenMaster.DrawHeader(Content.logHeader, EditorGUIUtility.ObjectContent(null, typeof(UnityEngine.UI.Text)).image);

            m_MiniLog.DoLog(80);

            if (changed)
            {
                MaterialChanged(material);
            }
        }