Exemplo n.º 1
0
        private void SetMieScattering()
        {
            ShaderFeatureHelper(FogMaterial, Shader_HG_SCATTERING, false);
            ShaderFeatureHelper(FogMaterial, Shader_CS_SCATTERING, false);
            ShaderFeatureHelper(FogMaterial, Shader_SCHLICK_HG_SCATTERING, false);

            switch (m_MieScatteringApproximation)
            {
            case MieScatteringApproximation.HenyeyGreenstein:
                ShaderFeatureHelper(FogMaterial, Shader_HG_SCATTERING, true);
                FogMaterial.SetFloat(ShaderIDs.MieScatteringCoeff, m_MieScatteringCoeff);
                break;

            case MieScatteringApproximation.CornetteShanks:
                ShaderFeatureHelper(FogMaterial, Shader_CS_SCATTERING, true);
                FogMaterial.SetFloat(ShaderIDs.MieScatteringCoeff, m_MieScatteringCoeff);
                break;

            case MieScatteringApproximation.Schlick:
                CalculateKFactor();
                ShaderFeatureHelper(FogMaterial, Shader_SCHLICK_HG_SCATTERING, true);
                FogMaterial.SetFloat(ShaderIDs.KFactor, k_Factor);
                FogMaterial.SetFloat(ShaderIDs.MieScatteringCoeff, m_MieScatteringCoeff);
                break;

            case MieScatteringApproximation.Off:
                break;

            default:
                break;
            }
        }
        protected override void LateUpdate()
        {
            base.LateUpdate();

            Bounds  b        = fogRenderer.bounds;
            Vector3 shrinker = b.size * -(1.0f - FogProfile.FogPercentage);

            b.Expand(shrinker);
            FogMaterial.SetVector("_FogBoxMin", b.min);
            FogMaterial.SetVector("_FogBoxMax", b.max);
            FogMaterial.SetVector("_FogBoxMinDir", (b.max - b.min).normalized);
            FogMaterial.SetVector("_FogBoxMaxDir", (b.min - b.max).normalized);
            FogMaterial.SetFloat("_FogBoxDiameter", Vector3.Distance(b.min, b.max));
            fogRenderer.enabled = (FogProfile.FogDensity > 0.0f);
        }
Exemplo n.º 3
0
    private void FogUpdate()
    {
        if (Mathf.Abs(lastDepth - Depth) > 0.1f)
        {
            BuildMesh();
        }

        PositionAndScale();

        FogOffset += Time.fixedDeltaTime * (WindSpeed * 0.001f);

        FogMaterial.SetColor("_FogColor", FogColor);
        FogMaterial.SetFloat("_FogCover", FogCover);
        FogMaterial.SetFloat("_FogOffset", FogOffset);
        FogMaterial.SetFloat("_FogTilingX", FogTiling.x);
        FogMaterial.SetFloat("_FogTilingY", FogTiling.y);
        FogMaterial.SetFloat("_VerticalMotion", VerticalSpeed);
    }
Exemplo n.º 4
0
        private void RenderFog(RenderTexture fogRenderTexture, RenderTexture src)
        {
            if (m_EnableRayleighScattering)
            {
                ShaderFeatureHelper(FogMaterial, Shader_RAYLEIGH_SCATTERING, true);
                FogMaterial.SetFloat(ShaderIDs.RayleighScatteringCoeff, m_RayleighScatteringCoeff);
            }
            else
            {
                ShaderFeatureHelper(FogMaterial, Shader_RAYLEIGH_SCATTERING, false);
            }

            ShaderFeatureHelper(FogMaterial, Shader_LIMIT_FOG_SIZE, m_LimitFogSize);
            ShaderFeatureHelper(FogMaterial, Shader_HEIGHTFOG, m_HeightFogEnabled);

            var rmsr = CalculateRaymarchStepRation();

            FogMaterial.SetFloat(ShaderIDs.RayMarchingSteps, m_RayMarchingSteps * Mathf.Pow(rmsr, 2));
            FogMaterial.SetFloat(ShaderIDs.FogDensity, m_FogDensityCoeff);
            FogMaterial.SetFloat(ShaderIDs.NoiseScale, m_NoiseScale);

            FogMaterial.SetFloat(ShaderIDs.ExtinctionCoeff, m_ExtinctionCoeff);
            FogMaterial.SetFloat(ShaderIDs.Anisotropy, m_Anisotropy);
            FogMaterial.SetFloat(ShaderIDs.BaseHeightDensity, m_BaseHeightDensity);

            FogMaterial.SetVector(ShaderIDs.FogWorldPosition, m_FogWorldPosition);
            FogMaterial.SetFloat(ShaderIDs.FogSize, m_FogSize);
            FogMaterial.SetFloat(ShaderIDs.LightIntensity, m_LightIntensity);

            FogMaterial.SetColor(ShaderIDs.FogColor, m_Light.GetComponent <Light>().color);
            FogMaterial.SetColor(ShaderIDs.ShadowColor, m_FogInShadowColor);
            FogMaterial.SetColor(ShaderIDs.FogColor, m_UseLightColor ? m_Light.GetComponent <Light>().color : m_FogInLightColor);

            FogMaterial.SetVector(ShaderIDs.LightDir, m_Light.GetComponent <Light>().transform.forward);
            FogMaterial.SetFloat(ShaderIDs.AmbientFog, m_AmbientFog);

            FogMaterial.SetVector(ShaderIDs.FogDirection, m_WindDirection);
            FogMaterial.SetFloat(ShaderIDs.FogSpeed, m_WindSpeed);

            FogMaterial.SetTexture(ShaderIDs.BlurNoiseTexture, m_BlurNoiseTexture2D);

            Graphics.Blit(src, fogRenderTexture, FogMaterial);
        }
        protected override void UpdateMaterial()
        {
            base.UpdateMaterial();

            if (FogHeight > 0.0f)
            {
                FogMaterial.SetFloat("_FogHeight", FogHeight);
                if (FogNoiseHeightScale > 0.0f && FogNoiseHeight != null)
                {
                    FogMaterial.SetTexture("_FogNoiseHeight", FogNoiseHeight);
                    FogMaterial.EnableKeyword("ENABLE_FOG_HEIGHT_WITH_NOISE");
                    FogMaterial.DisableKeyword("ENABLE_FOG_HEIGHT");
                }
                else
                {
                    FogMaterial.EnableKeyword("ENABLE_FOG_HEIGHT");
                    FogMaterial.DisableKeyword("ENABLE_FOG_HEIGHT_WITH_NOISE");
                }
            }
            else
            {
                FogMaterial.DisableKeyword("ENABLE_FOG_HEIGHT");
                FogMaterial.DisableKeyword("ENABLE_FOG_HEIGHT_WITH_NOISE");
            }

            if (Sun == null)
            {
                FogMaterial.DisableKeyword("ENABLE_SUN");
            }
            else
            {
                if (Sun.intensity == 0.0f || !SunEnabled || (Sun.color.r == 0.0f && Sun.color.g == 0.0f && Sun.color.b == 0.0f))
                {
                    FogMaterial.DisableKeyword("ENABLE_SUN");
                }
                else
                {
                    FogMaterial.EnableKeyword("ENABLE_SUN");
                }
            }
        }