Esempio n. 1
0
        public void Show()
        {
            if (changed)
            {
                DestroyImmediate(meshRenderer);
                DestroyImmediate(meshFilter);
                meshRenderer = null;
                meshFilter   = null;
                material     = null;
                mesh         = null;
                changed      = false;
            }

            if (NormalMap != null)
            {
                if (ShaderType == RainDropTools.RainDropShaderType.Cheap)
                {
                    if (DistortionStrength == 0f)
                    {
                        Hide();
                        return;
                    }
                }
                else
                {
                    if (DistortionStrength == 0f && ReliefValue == 0f && OverlayColor.a == 0f && Blur == 0f)
                    {
                        Hide();
                        return;
                    }
                }
            }
            else
            {
                Debug.LogError("Normal Map is null!");
                Hide();
                return;
            }

            if (material == null)
            {
                material = RainDropTools.CreateRainMaterial(ShaderType, RenderQueue);
            }

            if (meshFilter == null)
            {
                meshFilter = gameObject.AddComponent <MeshFilter>();
            }

            if (meshRenderer == null)
            {
                meshRenderer = gameObject.AddComponent <MeshRenderer>();
            }

            if (mesh == null)
            {
                mesh = RainDropTools.CreateQuadMesh();
            }

            // Update shader if needed
            if (material.shader.name != RainDropTools.GetShaderName(ShaderType))
            {
                material = RainDropTools.CreateRainMaterial(ShaderType, material.renderQueue);
            }

            if (material != null && mesh != null && meshFilter != null)
            {
                meshFilter.mesh = mesh;
                meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                meshRenderer.material          = material;
                meshRenderer.lightProbeUsage   = UnityEngine.Rendering.LightProbeUsage.Off;
                meshRenderer.enabled           = true;

                RainDropTools.ApplyRainMaterialValue(
                    material,
                    ShaderType,
                    NormalMap,
                    ReliefTexture,
                    DistortionStrength,
                    OverlayColor,
                    ReliefValue,
                    Blur,
                    Darkness
                    );
            }
        }
Esempio n. 2
0
    private void UpdateShader(FlowRainDrawerContainer dc, int index)
    {
        float progress = GetProgress(dc);

        dc.Drawer.material.renderQueue = RenderQueue + index;

        // Update shader if needed
        if (dc.Drawer.material.shader.name != RainDropTools.GetShaderName(ShaderType))
        {
            dc.Drawer.material = RainDropTools.CreateRainMaterial(ShaderType, RenderQueue + index);
        }

        float distortionValue = Variables.DistortionValue * Variables.DistortionOverLifetime.Evaluate(progress) * Alpha;
        float reliefValue     = Variables.ReliefValue * Variables.ReliefOverLifetime.Evaluate(progress) * Alpha;
        float blurValue       = Variables.Blur * Variables.BlurOverLifetime.Evaluate(progress) * Alpha;
        Color overlayColor    = new Color(
            Variables.OverlayColor.r,
            Variables.OverlayColor.g,
            Variables.OverlayColor.b,
            Variables.OverlayColor.a * Variables.AlphaOverLifetime.Evaluate(progress) * Alpha
            );

        switch (ShaderType)
        {
        case RainDropTools.RainDropShaderType.Expensive:
            if (distortionValue == 0f && reliefValue == 0f && overlayColor.a == 0f && blurValue == 0f)
            {
                dc.Drawer.enabled = false;
                return;
            }
            break;

        case RainDropTools.RainDropShaderType.Cheap:
            if (distortionValue == 0f)
            {
                dc.Drawer.enabled = false;
                return;
            }
            break;

        case RainDropTools.RainDropShaderType.NoDistortion:
            if (reliefValue == 0f && overlayColor.a == 0f)
            {
                dc.Drawer.enabled = false;
                return;
            }
            break;
        }

        RainDropTools.ApplyRainMaterialValue(
            dc.Drawer.material,
            ShaderType,
            Variables.NormalMap,
            Variables.OverlayTexture,
            distortionValue,
            overlayColor,
            reliefValue,
            blurValue,
            Variables.Darkness * Alpha
            );
        dc.Drawer.enabled = true;
    }