コード例 #1
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);
    }
コード例 #2
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);
        }