internal unsafe static void RunForwardPostprocess(RenderTargetView rt, ShaderResourceView depth, ref Matrix viewMatrix, uint?atmosphereId) { var transpose = Matrix.Transpose(viewMatrix); var mapping = MyMapping.MapDiscard(RC.DeviceContext, MyCommon.ProjectionConstants); mapping.WriteAndPosition(ref transpose); mapping.Unmap(); RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.SetCB(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants); RC.DeviceContext.OutputMerger.SetTargets(rt); RC.DeviceContext.PixelShader.SetShaderResource(0, depth); RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SKYBOX_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.DaySkybox, MyTextureEnum.CUBEMAP, true))); RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SKYBOX2_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.NightSkybox, MyTextureEnum.CUBEMAP, true))); RC.DeviceContext.PixelShader.SetSamplers(0, MyRender11.StandardSamplers); RC.DeviceContext.PixelShader.Set(m_ps); MyScreenPass.DrawFullscreenQuad(new MyViewport(256, 256)); if (atmosphereId != null) { var atmosphere = MyAtmosphereRenderer.GetAtmosphere(atmosphereId.Value); var constants = new AtmosphereConstants(); //TODO(AF) These values are computed in MyAtmosphere as well. Find a way to remove the duplication var worldMatrix = atmosphere.WorldMatrix; worldMatrix.Translation -= MyEnvironment.CameraPosition; double distance = worldMatrix.Translation.Length(); double atmosphereTop = atmosphere.AtmosphereRadius * atmosphere.Settings.AtmosphereTopModifier * atmosphere.PlanetScaleFactor * atmosphere.Settings.RayleighTransitionModifier; float rayleighHeight = atmosphere.Settings.RayleighHeight; float t = 0.0f; if (distance > atmosphereTop) { if (distance > atmosphereTop * 2.0f) { t = 1.0f; } else { t = (float)((distance - atmosphereTop) / atmosphereTop); } } rayleighHeight = MathHelper.Lerp(atmosphere.Settings.RayleighHeight, atmosphere.Settings.RayleighHeightSpace, t); constants.PlanetCentre = (Vector3)worldMatrix.Translation; constants.AtmosphereRadius = atmosphere.AtmosphereRadius * atmosphere.Settings.AtmosphereTopModifier; constants.GroundRadius = atmosphere.PlanetRadius * 1.01f * atmosphere.Settings.SeaLevelModifier; constants.BetaRayleighScattering = atmosphere.BetaRayleighScattering / atmosphere.Settings.RayleighScattering; constants.BetaMieScattering = atmosphere.BetaMieScattering / atmosphere.Settings.MieColorScattering; constants.HeightScaleRayleighMie = atmosphere.HeightScaleRayleighMie * new Vector2(rayleighHeight, atmosphere.Settings.MieHeight); constants.MieG = atmosphere.Settings.MieG; constants.PlanetScaleFactor = atmosphere.PlanetScaleFactor; constants.AtmosphereScaleFactor = atmosphere.AtmosphereScaleFactor; constants.Intensity = atmosphere.Settings.Intensity; constants.FogIntensity = atmosphere.Settings.FogIntensity; var cb = MyCommon.GetObjectCB(sizeof(AtmosphereConstants)); mapping = MyMapping.MapDiscard(RC.DeviceContext, cb); mapping.WriteAndPosition(ref constants); mapping.Unmap(); RC.SetBS(MyRender11.BlendAdditive); RC.SetCB(2, cb); RC.DeviceContext.PixelShader.SetShaderResource(2, MyAtmosphereRenderer.GetAtmosphereLuts(atmosphereId.Value).TransmittanceLut.ShaderView); RC.DeviceContext.PixelShader.Set(m_atmosphere); MyScreenPass.DrawFullscreenQuad(new MyViewport(MyEnvironmentProbe.CubeMapResolution, MyEnvironmentProbe.CubeMapResolution)); } RC.DeviceContext.OutputMerger.SetTargets(null as RenderTargetView); }
internal unsafe static void RunForwardPostprocess(IRtvBindable rt, ISrvBindable depth, ref Matrix viewMatrix, uint?atmosphereId) { MyGpuProfiler.IC_BeginBlock("Postprocess"); var transpose = Matrix.Transpose(viewMatrix); var mapping = MyMapping.MapDiscard(RC, MyCommon.ProjectionConstants); mapping.WriteAndPosition(ref transpose); mapping.Unmap(); RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants); RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); RC.SetRtv(rt); RC.PixelShader.SetSrv(0, depth); MyFileTextureManager texManager = MyManagers.FileTextures; RC.PixelShader.SetSrv(MyCommon.SKYBOX_SLOT, texManager.GetTexture(MyRender11.Environment.Data.Skybox, MyFileTextureEnum.CUBEMAP, true)); RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers); RC.PixelShader.Set(m_ps); MyScreenPass.DrawFullscreenQuad(new MyViewport(m_viewportSize, m_viewportSize)); MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("Atmosphere"); if (atmosphereId != null) { var atmosphere = MyAtmosphereRenderer.GetAtmosphere(atmosphereId.Value); var constants = new AtmosphereConstants(); //TODO(AF) These values are computed in MyAtmosphere as well. Find a way to remove the duplication var worldMatrix = atmosphere.WorldMatrix; worldMatrix.Translation -= MyRender11.Environment.Matrices.CameraPosition; double distance = worldMatrix.Translation.Length(); double atmosphereTop = atmosphere.AtmosphereRadius * atmosphere.Settings.AtmosphereTopModifier * atmosphere.PlanetScaleFactor * atmosphere.Settings.RayleighTransitionModifier; float rayleighHeight = atmosphere.Settings.RayleighHeight; float t = 0.0f; if (distance > atmosphereTop) { if (distance > atmosphereTop * 2.0f) { t = 1.0f; } else { t = (float)((distance - atmosphereTop) / atmosphereTop); } } rayleighHeight = MathHelper.Lerp(atmosphere.Settings.RayleighHeight, atmosphere.Settings.RayleighHeightSpace, t); constants.PlanetCentre = (Vector3)worldMatrix.Translation; constants.AtmosphereRadius = atmosphere.AtmosphereRadius * atmosphere.Settings.AtmosphereTopModifier; constants.GroundRadius = atmosphere.PlanetRadius * 1.01f * atmosphere.Settings.SeaLevelModifier; constants.BetaRayleighScattering = atmosphere.BetaRayleighScattering / atmosphere.Settings.RayleighScattering; constants.BetaMieScattering = atmosphere.BetaMieScattering / atmosphere.Settings.MieColorScattering; constants.HeightScaleRayleighMie = atmosphere.HeightScaleRayleighMie * new Vector2(rayleighHeight, atmosphere.Settings.MieHeight); constants.MieG = atmosphere.Settings.MieG; constants.PlanetScaleFactor = atmosphere.PlanetScaleFactor; constants.AtmosphereScaleFactor = atmosphere.AtmosphereScaleFactor; constants.Intensity = atmosphere.Settings.Intensity; constants.FogIntensity = atmosphere.Settings.FogIntensity; var cb = MyCommon.GetObjectCB(sizeof(AtmosphereConstants)); mapping = MyMapping.MapDiscard(RC, cb); mapping.WriteAndPosition(ref constants); mapping.Unmap(); RC.SetBlendState(MyBlendStateManager.BlendAdditive); RC.PixelShader.SetConstantBuffer(2, cb); RC.PixelShader.SetSrv(2, MyAtmosphereRenderer.GetAtmosphereLuts(atmosphereId.Value).TransmittanceLut); RC.PixelShader.Set(m_atmosphere); MyScreenPass.DrawFullscreenQuad(new MyViewport(MyEnvironmentProbe.CubeMapResolution, MyEnvironmentProbe.CubeMapResolution)); } MyGpuProfiler.IC_EndBlock(); RC.SetRtv(null); }