예제 #1
0
    private void InitializeDrawer(FlowRainDrawerContainer dc)
    {
        dc.TimeElapsed             = 0f;
        dc.lifetime                = RainDropTools.Random(Variables.LifetimeMin, Variables.LifetimeMax);
        dc.fluctuationRate         = RainDropTools.Random(Variables.fluctuationRateMin, Variables.fluctuationRateMax);
        dc.acceleration            = RainDropTools.Random(Variables.AccelerationMin, Variables.AccelerationMax);
        dc.transform.localPosition = RainDropTools.GetSpawnLocalPos(this.transform, camera, 0f, Variables.SpawnOffsetY);
        dc.startPos                = dc.transform.localPosition;

        dc.acceleration = RainDropTools.Random(Variables.AccelerationMin, Variables.AccelerationMax);
        Material mat = RainDropTools.CreateRainMaterial(ShaderType, RenderQueue);

        RainDropTools.ApplyRainMaterialValue(
            mat,
            ShaderType,
            Variables.NormalMap,
            Variables.OverlayTexture,
            Variables.DistortionValue,
            Variables.OverlayColor,
            Variables.ReliefValue,
            Variables.Blur,
            Variables.Darkness
            );
        dc.Drawer.lifeTime        = dc.lifetime;
        dc.Drawer.vertexDistance  = 0.01f;
        dc.Drawer.angleDivisions  = 20;
        dc.Drawer.material        = mat;
        dc.Drawer.widthCurve      = Variables.TrailWidth;
        dc.Drawer.widthMultiplier = RainDropTools.Random(Variables.SizeMinX, Variables.SizeMaxX);
        dc.Drawer.textureMode     = LineTextureMode.Stretch;
        dc.Drawer.vertexDistance  = (1f * this.Distance * RainDropTools.GetCameraOrthographicSize(this.camera).y) / (Variables.Resolution * 10f);
        dc.Drawer.Clear();
        dc.Drawer.enabled = false;
    }
예제 #2
0
파일: RainDrawer.cs 프로젝트: bqhuyy/HHAB
        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
                    );
            }
        }
예제 #3
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;
    }