Example #1
0
        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 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);
        }
Example #4
0
        private static AtmosphereConstants FillAtmosphereConstants(Vector3D cameraPosition, MyAtmosphere atmosphere)
        {
            var    position      = atmosphere.WorldMatrix.Translation - cameraPosition;
            double distance      = position.Length();
            double atmosphereTop = atmosphere.AtmosphereRadius * atmosphere.Settings.AtmosphereTopModifier *
                                   atmosphere.PlanetScaleFactor * atmosphere.Settings.RayleighTransitionModifier;
            float t = 0.0f;

            if (distance > atmosphereTop)
            {
                if (distance > atmosphereTop * 2.0f)
                {
                    t = 1.0f;
                }
                else
                {
                    t = (float)((distance - atmosphereTop) / atmosphereTop);
                }
            }
            var rayleighHeight = MathHelper.Lerp(atmosphere.Settings.RayleighHeight, atmosphere.Settings.RayleighHeightSpace, t);

            return(new AtmosphereConstants
            {
                PlanetCentre = position,
                AtmosphereRadius = atmosphere.AtmosphereRadius * atmosphere.Settings.AtmosphereTopModifier,
                GroundRadius = atmosphere.PlanetRadius * 1.01f * atmosphere.Settings.SeaLevelModifier,
                BetaRayleighScattering = atmosphere.BetaRayleighScattering / atmosphere.Settings.RayleighScattering,
                BetaMieScattering = atmosphere.BetaMieScattering / atmosphere.Settings.MieColorScattering,
                HeightScaleRayleighMie = atmosphere.HeightScaleRayleighMie * new Vector2(rayleighHeight, atmosphere.Settings.MieHeight),
                // precompute:
                //HeightScaleRayleighMie = atmosphere.HeightScaleRayleighMie * new Vector2(atmosphere.Settings.RayleighHeight, atmosphere.Settings.MieHeight),
                MieG = atmosphere.Settings.MieG,
                PlanetScaleFactor = atmosphere.PlanetScaleFactor,
                AtmosphereScaleFactor = atmosphere.AtmosphereScaleFactor,
                Intensity = atmosphere.Settings.Intensity,
                FogIntensity = atmosphere.Settings.FogIntensity
            });
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }