protected void SetupSkyParametersSimple( NuajMaterial _Material, ICloudLayer[] _Layers, bool _bIsEnvironmentRendering ) { // Build the GPU & CPU density textures if they do not already exist ComputeDensityTexture(); _Material.SetTexture( "_TexDensity", m_DensityTexture ); _Material.SetVector( "_Sigma_Rayleigh", m_SigmaRayleigh ); _Material.SetFloat( "_Sigma_Mie", m_SigmaMie ); _Material.SetFloat( "_MiePhaseAnisotropy", Mathf.Clamp( m_ScatteringAnisotropy, -0.99f, +0.99f ) ); _Material.SetFloat( "_PlanetRadiusOffsetKm", m_PlanetRadiusOffsetKm ); // Prepare cloud Mie factors & cloud layers' textures switch ( _Layers.Length ) { case 0: _Material.SetTexture( "_TexCloudLayer0", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer1", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer2", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer3", m_Owner.m_TextureEmptyCloud, true ); break; case 1: _Material.SetTexture( "_TexCloudLayer0", _bIsEnvironmentRendering ? _Layers[0].EnvironmentRenderTargetSky : _Layers[0].RenderTarget ); _Material.SetTexture( "_TexCloudLayer1", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer2", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer3", m_Owner.m_TextureEmptyCloud, true ); break; case 2: _Material.SetTexture( "_TexCloudLayer0", _bIsEnvironmentRendering ? _Layers[0].EnvironmentRenderTargetSky : _Layers[0].RenderTarget ); _Material.SetTexture( "_TexCloudLayer1", _bIsEnvironmentRendering ? _Layers[1].EnvironmentRenderTargetSky : _Layers[1].RenderTarget ); _Material.SetTexture( "_TexCloudLayer2", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer3", m_Owner.m_TextureEmptyCloud, true ); break; case 3: _Material.SetTexture( "_TexCloudLayer0", _bIsEnvironmentRendering ? _Layers[0].EnvironmentRenderTargetSky : _Layers[0].RenderTarget ); _Material.SetTexture( "_TexCloudLayer1", _bIsEnvironmentRendering ? _Layers[1].EnvironmentRenderTargetSky : _Layers[1].RenderTarget ); _Material.SetTexture( "_TexCloudLayer2", _bIsEnvironmentRendering ? _Layers[2].EnvironmentRenderTargetSky : _Layers[2].RenderTarget ); _Material.SetTexture( "_TexCloudLayer3", m_Owner.m_TextureEmptyCloud, true ); break; case 4: _Material.SetTexture( "_TexCloudLayer0", _bIsEnvironmentRendering ? _Layers[0].EnvironmentRenderTargetSky : _Layers[0].RenderTarget ); _Material.SetTexture( "_TexCloudLayer1", _bIsEnvironmentRendering ? _Layers[1].EnvironmentRenderTargetSky : _Layers[1].RenderTarget ); _Material.SetTexture( "_TexCloudLayer2", _bIsEnvironmentRendering ? _Layers[2].EnvironmentRenderTargetSky : _Layers[2].RenderTarget ); _Material.SetTexture( "_TexCloudLayer3", _bIsEnvironmentRendering ? _Layers[3].EnvironmentRenderTargetSky : _Layers[3].RenderTarget ); break; } }
/// <summary> /// Assigns basic scattering coefficients to a material that would require to compute the optical depth of the atmosphere /// </summary> /// <param name="_Material"></param> /// <param name="_bSetupDensityTexture"></param> internal void SetupScatteringCoefficients( NuajMaterial _Material, bool _bSetupDensityTexture ) { // Build the GPU & CPU density textures if they do not already exist _Material.SetFloat( "_DensitySeaLevel_Rayleigh", m_DensityRayleigh ); _Material.SetVector( "_Sigma_Rayleigh", m_SigmaRayleigh ); _Material.SetFloat( "_DensitySeaLevel_Mie", m_DensityMie ); _Material.SetFloat( "_Sigma_Mie", m_SigmaMie ); _Material.SetFloat( "_MiePhaseAnisotropy", Mathf.Clamp( m_ScatteringAnisotropy, -0.99f, +0.99f ) ); ComputeDensityTexture(); if ( _bSetupDensityTexture ) _Material.SetTexture( "_TexDensity", m_DensityTexture ); }
/// <summary> /// Setups the sky parameters for the sky material /// </summary> /// <param name="_Material">The material to setup</param> /// <param name="_Layers">The array of cloud layers (from 0 to 4 elements)</param> /// <param name="_ShadowMap">The shadow map</param> /// <param name="_bIsEnvironmentRendering"></param> protected void SetupSkyParameters( NuajMaterial _Material, ICloudLayer[] _Layers, Texture _ShadowMap, bool _bIsEnvironmentRendering ) { // Build the GPU & CPU density textures if they do not already exist ComputeDensityTexture(); _Material.SetTexture( "_TexDensity", m_DensityTexture ); _Material.SetTextureRAW( "_TexShadowMap", _ShadowMap ); _Material.SetFloat( "_DensitySeaLevel_Rayleigh", m_DensityRayleigh ); _Material.SetVector( "_Sigma_Rayleigh", m_SigmaRayleigh ); _Material.SetFloat( "_DensitySeaLevel_Mie", m_DensityMie ); _Material.SetFloat( "_Sigma_Mie", m_SigmaMie ); _Material.SetFloat( "_MiePhaseAnisotropy", Mathf.Clamp( m_ScatteringAnisotropy, -0.99f, +0.99f ) ); _Material.SetFloat( "_SkyStepsCount", m_SkyStepsCount );//+ (_Layers.Length == 0 ? m_UnderCloudsMinStepsCount : 0) ); // Use higher resolution if no cloud layers _Material.SetFloat( "_UnderCloudsMinStepsCount", m_bGodRays ? m_UnderCloudsMinStepsCount : 0 ); _Material.SetFloat( "_bGodRays", m_bGodRays ? 1 : 0 ); _Material.SetFloat( "_PlanetRadiusOffsetKm", m_PlanetRadiusOffsetKm ); // Prepare cloud Mie factors & cloud layers' textures switch ( _Layers.Length ) { case 0: _Material.SetTexture( "_TexCloudLayer0", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer1", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer2", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer3", m_Owner.m_TextureEmptyCloud, true ); break; case 1: _Material.SetTexture( "_TexCloudLayer0", _bIsEnvironmentRendering ? _Layers[0].EnvironmentRenderTargetSky : _Layers[0].RenderTarget ); _Material.SetTexture( "_TexCloudLayer1", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer2", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer3", m_Owner.m_TextureEmptyCloud, true ); break; case 2: _Material.SetTexture( "_TexCloudLayer0", _bIsEnvironmentRendering ? _Layers[0].EnvironmentRenderTargetSky : _Layers[0].RenderTarget ); _Material.SetTexture( "_TexCloudLayer1", _bIsEnvironmentRendering ? _Layers[1].EnvironmentRenderTargetSky : _Layers[1].RenderTarget ); _Material.SetTexture( "_TexCloudLayer2", m_Owner.m_TextureEmptyCloud, true ); _Material.SetTexture( "_TexCloudLayer3", m_Owner.m_TextureEmptyCloud, true ); break; case 3: _Material.SetTexture( "_TexCloudLayer0", _bIsEnvironmentRendering ? _Layers[0].EnvironmentRenderTargetSky : _Layers[0].RenderTarget ); _Material.SetTexture( "_TexCloudLayer1", _bIsEnvironmentRendering ? _Layers[1].EnvironmentRenderTargetSky : _Layers[1].RenderTarget ); _Material.SetTexture( "_TexCloudLayer2", _bIsEnvironmentRendering ? _Layers[2].EnvironmentRenderTargetSky : _Layers[2].RenderTarget ); _Material.SetTexture( "_TexCloudLayer3", m_Owner.m_TextureEmptyCloud, true ); break; case 4: _Material.SetTexture( "_TexCloudLayer0", _bIsEnvironmentRendering ? _Layers[0].EnvironmentRenderTargetSky : _Layers[0].RenderTarget ); _Material.SetTexture( "_TexCloudLayer1", _bIsEnvironmentRendering ? _Layers[1].EnvironmentRenderTargetSky : _Layers[1].RenderTarget ); _Material.SetTexture( "_TexCloudLayer2", _bIsEnvironmentRendering ? _Layers[2].EnvironmentRenderTargetSky : _Layers[2].RenderTarget ); _Material.SetTexture( "_TexCloudLayer3", _bIsEnvironmentRendering ? _Layers[3].EnvironmentRenderTargetSky : _Layers[3].RenderTarget ); break; } }