private static unsafe void Precompute1(MyAtmosphere atmosphere, ref AtmosphereLuts luts) { var RC = MyImmediateRC.RC; var cb = MyCommon.GetObjectCB(sizeof(AtmosphereConstants)); RC.ComputeShader.SetConstantBuffer(1, cb); var worldMatrix = atmosphere.WorldMatrix; worldMatrix.Translation -= MyRender11.Environment.Matrices.CameraPosition; var constants = FillAtmosphereConstants(MyRender11.Environment.Matrices.CameraPosition, atmosphere); var mapping = MyMapping.MapDiscard(cb); mapping.WriteAndPosition(ref constants); mapping.Unmap(); // transmittance RC.ComputeShader.SetUav(0, luts.TransmittanceLut); RC.ComputeShader.Set(m_precomputeDensity); RC.Dispatch(512 / 8, 128 / 8, 1); RC.ComputeShader.SetUav(0, null); }
internal unsafe static void AllocateLuts(ref AtmosphereLuts luts) { if (luts.TransmittanceLut == RwTexId.NULL) { luts.TransmittanceLut = MyRwTextures.CreateUav2D(512, 128, SharpDX.DXGI.Format.R32G32_Float); } }
private static void AllocateLuts(ref AtmosphereLuts luts) { if (luts.TransmittanceLut == null) { luts.TransmittanceLut = MyManagers.RwTextures.CreateUav("AtmosphereLuts.TransmittanceLut", 512, 128, SharpDX.DXGI.Format.R32G32_Float); } }
internal unsafe static void AllocateLuts(ref AtmosphereLuts luts) { if (luts.TransmittanceLut == RwTexId.NULL) { luts.TransmittanceLut = MyRwTextures.CreateUav2D(256, 64, SharpDX.DXGI.Format.R16G16B16A16_Float); luts.InscatterLut = MyRwTextures.CreateUav3D(32, 128, 32 * 8, SharpDX.DXGI.Format.R16G16B16A16_Float); } }
internal static void CreateAtmosphere(uint ID, MatrixD worldMatrix, float planetRadius, float atmosphereRadius, Vector3 rayleighScattering, float rayleighHeightScale, Vector3 mieScattering, float mieHeightScale, float planetScaleFactor, float atmosphereScaleFactor) { Atmospheres.Add(ID, new MyAtmosphere { WorldMatrix = worldMatrix, PlanetRadius = planetRadius, AtmosphereRadius = atmosphereRadius, BetaRayleighScattering = rayleighScattering, BetaMieScattering = mieScattering, HeightScaleRayleighMie = new Vector2(rayleighHeightScale, mieHeightScale), PlanetScaleFactor = planetScaleFactor, AtmosphereScaleFactor = atmosphereScaleFactor }); AtmosphereLuts luts = new AtmosphereLuts { TransmittanceLut = RwTexId.NULL }; AllocateLuts(ref luts); Precompute1(Atmospheres[ID], ref luts); AtmosphereLUT[ID] = luts; }
internal unsafe static void Precompute1(MyAtmosphere atmosphere, ref AtmosphereLuts luts) { var RC = MyImmediateRC.RC; float radiusGround = atmosphere.PlanetRadius; float RadiusAtmosphere = atmosphere.AtmosphereRadius; var cb = MyCommon.GetObjectCB(sizeof(AtmospherePrecomputeConstants)); RC.Context.ComputeShader.SetConstantBuffer(1, cb); AtmospherePrecomputeConstants constants = new AtmospherePrecomputeConstants(); constants.RadiusGround = radiusGround; constants.RadiusAtmosphere = RadiusAtmosphere; constants.RadiusLimit = RadiusAtmosphere + 1; constants.HeightScaleRayleighMie = atmosphere.HeightScaleRayleighMie; constants.BetaRayleighScattering = atmosphere.BetaRayleighScattering; constants.BetaMieScattering = atmosphere.BetaMieScattering; var mapping = MyMapping.MapDiscard(cb); mapping.stream.Write(constants); mapping.Unmap(); // transmittance RC.Context.ComputeShader.SetUnorderedAccessView(0, luts.TransmittanceLut.Uav); RC.SetCS(m_precomputeDensity); RC.Context.Dispatch(256 / 8, 64 / 8, 1); RC.Context.ComputeShader.SetUnorderedAccessView(0, null); // inscatter 1 RC.Context.ComputeShader.SetShaderResource(0, luts.TransmittanceLut.ShaderView); RC.SetCS(m_precomputeInscatter1); RC.Context.ComputeShader.SetUnorderedAccessViews(0, luts.InscatterLut.Uav); RC.Context.Dispatch(32 / 8, 128 / 8, 32 * 8); RC.Context.ComputeShader.SetUnorderedAccessViews(0, null as UnorderedAccessView, null as UnorderedAccessView); }
internal unsafe static void Precompute1(MyAtmosphere atmosphere, ref AtmosphereLuts luts) { var RC = MyImmediateRC.RC; float radiusGround = atmosphere.PlanetRadius; float RadiusAtmosphere = atmosphere.AtmosphereRadius; var cb = MyCommon.GetObjectCB(sizeof(AtmospherePrecomputeConstants)); RC.DeviceContext.ComputeShader.SetConstantBuffer(1, cb); var worldMatrix = atmosphere.WorldMatrix; worldMatrix.Translation -= MyEnvironment.CameraPosition; AtmospherePrecomputeConstants constants = new AtmospherePrecomputeConstants(); // Raise the ground a bit for better sunsets constants.RadiusGround = radiusGround * 1.01f * atmosphere.Settings.SeaLevelModifier; constants.RadiusAtmosphere = RadiusAtmosphere * atmosphere.Settings.AtmosphereTopModifier; constants.HeightScaleRayleighMie = atmosphere.HeightScaleRayleighMie * new Vector2(atmosphere.Settings.RayleighHeight, atmosphere.Settings.MieHeight); constants.BetaRayleighScattering = atmosphere.BetaRayleighScattering / atmosphere.Settings.RayleighScattering; constants.BetaMieScattering = atmosphere.BetaMieScattering / atmosphere.Settings.MieColorScattering; constants.MieG = atmosphere.Settings.MieG; constants.PlanetScaleFactor = atmosphere.PlanetScaleFactor; constants.AtmosphereScaleFactor = atmosphere.AtmosphereScaleFactor; constants.PlanetCentre = (Vector3)worldMatrix.Translation; constants.Intensity = atmosphere.Settings.Intensity; var mapping = MyMapping.MapDiscard(cb); mapping.WriteAndPosition(ref constants); mapping.Unmap(); // transmittance RC.DeviceContext.ComputeShader.SetUnorderedAccessView(0, luts.TransmittanceLut.Uav); RC.SetCS(m_precomputeDensity); RC.DeviceContext.Dispatch(512 / 8, 128 / 8, 1); RC.DeviceContext.ComputeShader.SetUnorderedAccessView(0, null); }
internal unsafe static void AllocateLuts(ref AtmosphereLuts luts) { if (luts.TransmittanceLut == null) { luts.TransmittanceLut = MyManagers.RwTextures.CreateUav("AtmosphereLuts.TransmittanceLut", 512, 128, SharpDX.DXGI.Format.R32G32_Float); } }
internal static void CreateAtmosphere(uint ID, MatrixD worldMatrix, float planetRadius, float atmosphereRadius, Vector3 rayleighScattering, float rayleighHeightScale, Vector3 mieScattering, float mieHeightScale, float planetScaleFactor, float atmosphereScaleFactor) { Atmospheres.Add(ID, new MyAtmosphere { WorldMatrix = worldMatrix, PlanetRadius = planetRadius, AtmosphereRadius = atmosphereRadius, BetaRayleighScattering = rayleighScattering, BetaMieScattering = mieScattering, HeightScaleRayleighMie = new Vector2(rayleighHeightScale, mieHeightScale), PlanetScaleFactor = planetScaleFactor, AtmosphereScaleFactor = atmosphereScaleFactor }); AtmosphereLuts luts = new AtmosphereLuts(); AllocateLuts(ref luts); Precompute1(Atmospheres[ID], ref luts); AtmosphereLUT[ID] = luts; }
internal unsafe static void Precompute1(MyAtmosphere atmosphere, ref AtmosphereLuts luts) { var RC = MyImmediateRC.RC; float radiusGround = atmosphere.PlanetRadius; float RadiusAtmosphere = atmosphere.AtmosphereRadius; var cb = MyCommon.GetObjectCB(sizeof(AtmospherePrecomputeConstants)); RC.ComputeShader.SetConstantBuffer(1, cb); var worldMatrix = atmosphere.WorldMatrix; worldMatrix.Translation -= MyRender11.Environment.Matrices.CameraPosition; AtmospherePrecomputeConstants constants = new AtmospherePrecomputeConstants(); // Raise the ground a bit for better sunsets constants.RadiusGround = radiusGround * 1.01f * atmosphere.Settings.SeaLevelModifier; constants.RadiusAtmosphere = RadiusAtmosphere * atmosphere.Settings.AtmosphereTopModifier; constants.HeightScaleRayleighMie = atmosphere.HeightScaleRayleighMie * new Vector2(atmosphere.Settings.RayleighHeight, atmosphere.Settings.MieHeight); constants.BetaRayleighScattering = atmosphere.BetaRayleighScattering / atmosphere.Settings.RayleighScattering; constants.BetaMieScattering = atmosphere.BetaMieScattering / atmosphere.Settings.MieColorScattering; constants.MieG = atmosphere.Settings.MieG; constants.PlanetScaleFactor = atmosphere.PlanetScaleFactor; constants.AtmosphereScaleFactor = atmosphere.AtmosphereScaleFactor; constants.PlanetCentre = (Vector3)worldMatrix.Translation; constants.Intensity = atmosphere.Settings.Intensity; var mapping = MyMapping.MapDiscard(cb); mapping.WriteAndPosition(ref constants); mapping.Unmap(); // transmittance RC.ComputeShader.SetUav(0, luts.TransmittanceLut); RC.ComputeShader.Set(m_precomputeDensity); RC.Dispatch(512 / 8, 128 / 8, 1); RC.ComputeShader.SetUav(0, null); }