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"); } } }