示例#1
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);
        }
        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);
        }
示例#3
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);
        }
示例#4
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);
        }