Exemplo n.º 1
0
        internal static void UpdateFrameConstants()
        {
            MyFrameConstantsLayout constants = new MyFrameConstantsLayout();

            constants.View                = Matrix.Transpose(MyEnvironment.ViewAt0);
            constants.Projection          = Matrix.Transpose(MyEnvironment.Projection);
            constants.ViewProjection      = Matrix.Transpose(MyEnvironment.ViewProjectionAt0);
            constants.InvView             = Matrix.Transpose(MyEnvironment.InvViewAt0);
            constants.InvProjection       = Matrix.Transpose(MyEnvironment.InvProjection);
            constants.InvViewProjection   = Matrix.Transpose(MyEnvironment.InvViewProjectionAt0);
            constants.ViewProjectionWorld = Matrix.Transpose(MyEnvironment.ViewProjection);
            constants.WorldOffset         = new Vector4(MyEnvironment.CameraPosition, 0);

            constants.Resolution = MyRender11.ResolutionF;
            constants.TerrainTextureDistances = new Vector4(
                MyRender11.Settings.TerrainDetailD0,
                1.0f / (MyRender11.Settings.TerrainDetailD1 - MyRender11.Settings.TerrainDetailD0),
                MyRender11.Settings.TerrainDetailD2,
                1.0f / (MyRender11.Settings.TerrainDetailD3 - MyRender11.Settings.TerrainDetailD2));

            constants.TerrainDetailRange.X = 0;
            constants.TerrainDetailRange.Y = 0;

            var currentGameplayFrame = MyRender11.Settings.GameplayFrame;

            constants.Time      = (float)(currentGameplayFrame) / 60.0f;
            constants.TimeDelta = (float)(currentGameplayFrame - m_lastGameplayFrame) / 60.0f;

            if ((int)FrameCounter != m_lastFrameGameplayUpdate)
            {
                m_lastGameplayFrame       = currentGameplayFrame;
                m_lastFrameGameplayUpdate = (int)FrameCounter;
            }

            constants.FoliageClippingScaling = new Vector4(
                //MyRender.Settings.GrassGeometryClippingDistance,
                MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance(),
                MyRender11.Settings.GrassGeometryScalingNearDistance,
                MyRender11.Settings.GrassGeometryScalingFarDistance,
                MyRender11.Settings.GrassGeometryDistanceScalingFactor);
            constants.WindVector = new Vector3(
                (float)Math.Cos(MyRender11.Settings.WindAzimuth * Math.PI / 180.0),
                0,
                (float)Math.Sin(MyRender11.Settings.WindAzimuth * Math.PI / 180.0)) * MyRender11.Settings.WindStrength;

            constants.Tau                      = MyRender11.Postprocess.EnableEyeAdaptation ? MyRender11.Postprocess.EyeAdaptationTau : 0;
            constants.BacklightMult            = MyRender11.Settings.BacklightMult;
            constants.EnvMult                  = MyRender11.Settings.EnvMult;
            constants.Contrast                 = MyRender11.Postprocess.Contrast;
            constants.Brightness               = MyRender11.Postprocess.Brightness;
            constants.MiddleGrey               = MyRender11.Postprocess.MiddleGrey;
            constants.LuminanceExposure        = MyRender11.Postprocess.LuminanceExposure;
            constants.BloomExposure            = MyRender11.Postprocess.BloomExposure;
            constants.BloomMult                = MyRender11.Postprocess.BloomMult;
            constants.MiddleGreyCurveSharpness = MyRender11.Postprocess.MiddleGreyCurveSharpness;
            constants.MiddleGreyAt0            = MyRender11.Postprocess.MiddleGreyAt0;
            constants.BlueShiftRapidness       = MyRender11.Postprocess.BlueShiftRapidness;
            constants.BlueShiftScale           = MyRender11.Postprocess.BlueShiftScale;
            constants.FogDensity               = MyEnvironment.FogSettings.FogDensity;
            constants.FogMult                  = MyEnvironment.FogSettings.FogMultiplier;
            constants.FogYOffset               = MyRender11.Settings.FogYOffset;
            constants.FogColor                 = MyEnvironment.FogSettings.FogColor.PackedValue;
            constants.ForwardPassAmbient       = MyRender11.Postprocess.ForwardPassAmbient;

            constants.LogLumThreshold = MyRender11.Postprocess.LogLumThreshold;
            constants.Tonemapping_A   = MyRender11.Postprocess.Tonemapping_A;
            constants.Tonemapping_B   = MyRender11.Postprocess.Tonemapping_B;
            constants.Tonemapping_C   = MyRender11.Postprocess.Tonemapping_C;
            constants.Tonemapping_D   = MyRender11.Postprocess.Tonemapping_D;
            constants.Tonemapping_E   = MyRender11.Postprocess.Tonemapping_E;
            constants.Tonemapping_F   = MyRender11.Postprocess.Tonemapping_F;


            //if (true)
            //{
            //    constants.Tau = MyRender11.Settings.AdaptationTau;
            //    constants.BacklightMult = MyRender11.Settings.BacklightMult;
            //    constants.EnvMult = MyRender11.Settings.EnvMult;
            //    constants.Contrast = MyRender11.Settings.Contrast;
            //    constants.Brightness = MyRender11.Settings.Brightness;
            //    constants.MiddleGrey = MyRender11.Settings.MiddleGrey;
            //    constants.LuminanceExposure = MyRender11.Settings.LuminanceExposure;
            //    constants.BloomExposure = MyRender11.Settings.BloomExposure;
            //    constants.BloomMult = MyRender11.Settings.BloomMult;
            //    constants.MiddleGreyCurveSharpness = MyRender11.Settings.MiddleGreyCurveSharpness;
            //    constants.MiddleGreyAt0 = MyRender11.Settings.MiddleGreyAt0;
            //    constants.BlueShiftRapidness = MyRender11.Settings.BlueShiftRapidness;
            //    constants.BlueShiftScale = MyRender11.Settings.BlueShiftScale;
            //}

            constants.TilesNum = (uint)MyScreenDependants.TilesNum;
            constants.TilesX   = (uint)MyScreenDependants.TilesX;

            constants.DirectionalLightColor = MyEnvironment.DirectionalLightIntensity;
            constants.DirectionalLightDir   = MyEnvironment.DirectionalLightDir;

            int lightIndex = 0;

            if (MyEnvironment.AdditionalSunDirections != null && MyEnvironment.AdditionalSunDirections.Length > 0)
            {
                constants.AdditionalSunColor     = MyEnvironment.AdditionalSunColors[0];
                constants.AdditionalSunIntensity = MyEnvironment.AdditionalSunIntensities[0];

                if (lightIndex < MyEnvironment.AdditionalSunDirections.Length)
                {
                    constants.SecondarySunDirection1 = new Vector4(MathHelper.CalculateVectorOnSphere(MyEnvironment.DirectionalLightDir, MyEnvironment.AdditionalSunDirections[lightIndex][0], MyEnvironment.AdditionalSunDirections[lightIndex][1]), 0);
                }
                ++lightIndex;
                if (lightIndex < MyEnvironment.AdditionalSunDirections.Length)
                {
                    constants.SecondarySunDirection2 = new Vector4(MathHelper.CalculateVectorOnSphere(MyEnvironment.DirectionalLightDir, MyEnvironment.AdditionalSunDirections[lightIndex][0], MyEnvironment.AdditionalSunDirections[lightIndex][1]), 0);
                }
                ++lightIndex;
                if (lightIndex < MyEnvironment.AdditionalSunDirections.Length)
                {
                    constants.SecondarySunDirection3 = new Vector4(MathHelper.CalculateVectorOnSphere(MyEnvironment.DirectionalLightDir, MyEnvironment.AdditionalSunDirections[lightIndex][0], MyEnvironment.AdditionalSunDirections[lightIndex][1]), 0);
                }
                ++lightIndex;
                if (lightIndex < MyEnvironment.AdditionalSunDirections.Length)
                {
                    constants.SecondarySunDirection4 = new Vector4(MathHelper.CalculateVectorOnSphere(MyEnvironment.DirectionalLightDir, MyEnvironment.AdditionalSunDirections[lightIndex][0], MyEnvironment.AdditionalSunDirections[lightIndex][1]), 0);
                }
                ++lightIndex;
                if (lightIndex < MyEnvironment.AdditionalSunDirections.Length)
                {
                    constants.SecondarySunDirection5 = new Vector4(MathHelper.CalculateVectorOnSphere(MyEnvironment.DirectionalLightDir, MyEnvironment.AdditionalSunDirections[lightIndex][0], MyEnvironment.AdditionalSunDirections[lightIndex][1]), 0);
                }
                ++lightIndex;
                constants.AdditionalSunCount = MyEnvironment.AdditionalSunDirections.Length;
            }
            else
            {
                constants.AdditionalSunCount = 0;
            }

            constants.SkyboxBlend      = 1 - 2 * (float)(Math.Abs(-MyEnvironment.DayTime + 0.5));
            constants.SkyboxBrightness = MathHelper.Lerp(1.0f, 0.01f, MyEnvironment.PlanetFactor);
            constants.ShadowFadeout    = MyRender11.Settings.ShadowFadeoutMultiplier;

            constants.DebugVoxelLod = MyRenderSettings.DebugClipmapLodColor ? 1.0f : 0.0f;
            constants.EnableVoxelAo = MyRenderSettings.EnableVoxelAo ? 1f : 0f;
            constants.VoxelAoMin    = MyRenderSettings.VoxelAoMin;
            constants.VoxelAoMax    = MyRenderSettings.VoxelAoMax;
            constants.VoxelAoOffset = MyRenderSettings.VoxelAoOffset;

            constants.BackgroundOrientation = Matrix.CreateFromQuaternion(MyEnvironment.BackgroundOrientation);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 0, out constants.VoxelLodRange0.X, out constants.VoxelLodRange0.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 1, out constants.VoxelLodRange0.Z, out constants.VoxelLodRange0.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 2, out constants.VoxelLodRange1.X, out constants.VoxelLodRange1.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 3, out constants.VoxelLodRange1.Z, out constants.VoxelLodRange1.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 4, out constants.VoxelLodRange2.X, out constants.VoxelLodRange2.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 5, out constants.VoxelLodRange2.Z, out constants.VoxelLodRange2.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 6, out constants.VoxelLodRange3.X, out constants.VoxelLodRange3.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 7, out constants.VoxelLodRange3.Z, out constants.VoxelLodRange3.W);

            //
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 0, out constants.VoxelMassiveLodRange0.X, out constants.VoxelMassiveLodRange0.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 1, out constants.VoxelMassiveLodRange0.Z, out constants.VoxelMassiveLodRange0.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 2, out constants.VoxelMassiveLodRange1.X, out constants.VoxelMassiveLodRange1.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 3, out constants.VoxelMassiveLodRange1.Z, out constants.VoxelMassiveLodRange1.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 4, out constants.VoxelMassiveLodRange2.X, out constants.VoxelMassiveLodRange2.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 5, out constants.VoxelMassiveLodRange2.Z, out constants.VoxelMassiveLodRange2.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 6, out constants.VoxelMassiveLodRange3.X, out constants.VoxelMassiveLodRange3.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 7, out constants.VoxelMassiveLodRange3.Z, out constants.VoxelMassiveLodRange3.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 8, out constants.VoxelMassiveLodRange4.X, out constants.VoxelMassiveLodRange4.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 9, out constants.VoxelMassiveLodRange4.Z, out constants.VoxelMassiveLodRange4.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 10, out constants.VoxelMassiveLodRange5.X, out constants.VoxelMassiveLodRange5.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 11, out constants.VoxelMassiveLodRange5.Z, out constants.VoxelMassiveLodRange5.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 12, out constants.VoxelMassiveLodRange6.X, out constants.VoxelMassiveLodRange6.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 13, out constants.VoxelMassiveLodRange6.Z, out constants.VoxelMassiveLodRange6.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 14, out constants.VoxelMassiveLodRange7.X, out constants.VoxelMassiveLodRange7.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 15, out constants.VoxelMassiveLodRange7.Z, out constants.VoxelMassiveLodRange7.W);


            var mapping = MyMapping.MapDiscard(MyCommon.FrameConstants);

            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();
        }
Exemplo n.º 2
0
        internal static void UpdateFrameConstants()
        {
            // environment
            MyFrameConstantsLayout constants = new MyFrameConstantsLayout();

            UpdateFrameConstantsInternal(MyRender11.Environment.Matrices, ref constants, MyStereoRegion.FULLSCREEN);
            constants.Environment.CameraPositionDelta = MyRender11.Environment.Matrices.CameraPosition - m_lastCameraPosition;
            m_lastCameraPosition = MyRender11.Environment.Matrices.CameraPosition;

            // skybox
            constants.Environment.BackgroundOrientation = Matrix.CreateFromQuaternion(MyRender11.Environment.Data.SkyboxOrientation);

            // screen
            constants.Screen.TilesNum = (uint)MyScreenDependants.TilesNum;
            constants.Screen.TilesX   = (uint)MyScreenDependants.TilesX;

            // foliage
            constants.Foliage.ClippingScaling = new Vector4(
                //MyRender.Settings.GrassGeometryClippingDistance,
                MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance(),
                MyRender11.Settings.GrassGeometryScalingNearDistance,
                MyRender11.Settings.GrassGeometryScalingFarDistance,
                MyRender11.Settings.GrassGeometryDistanceScalingFactor);
            constants.Foliage.WindVector = new Vector3(
                (float)Math.Cos(MyRender11.Settings.WindAzimuth * Math.PI / 180.0),
                0,
                (float)Math.Sin(MyRender11.Settings.WindAzimuth * Math.PI / 180.0)) * MyRender11.Settings.WindStrength;

            // postprocess
            constants.Postprocess = MyRender11.Postprocess.GetProcessedData();

            // lighting data
            constants.EnvironmentLight = MyRender11.Environment.Data.EnvironmentLight;
            if (!MyRender11.DebugOverrides.Sun)
            {
                constants.EnvironmentLight.SunColorRaw = new Vector3(0, 0, 0);
            }

            // fog
            constants.Fog.Density = MyRender11.Environment.Fog.FogDensity;
            constants.Fog.Mult    = MyRender11.Environment.Fog.FogMultiplier;
            constants.Fog.Color   = MyRender11.Environment.Fog.FogColor.PackedValue;

            // voxels
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 0, out constants.Voxel.LodRange0.X, out constants.Voxel.LodRange0.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 1, out constants.Voxel.LodRange0.Z, out constants.Voxel.LodRange0.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 2, out constants.Voxel.LodRange1.X, out constants.Voxel.LodRange1.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 3, out constants.Voxel.LodRange1.Z, out constants.Voxel.LodRange1.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 4, out constants.Voxel.LodRange2.X, out constants.Voxel.LodRange2.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 5, out constants.Voxel.LodRange2.Z, out constants.Voxel.LodRange2.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 6, out constants.Voxel.LodRange3.X, out constants.Voxel.LodRange3.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 7, out constants.Voxel.LodRange3.Z, out constants.Voxel.LodRange3.W);

            //
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 0, out constants.Voxel.MassiveLodRange0.X, out constants.Voxel.MassiveLodRange0.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 1, out constants.Voxel.MassiveLodRange0.Z, out constants.Voxel.MassiveLodRange0.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 2, out constants.Voxel.MassiveLodRange1.X, out constants.Voxel.MassiveLodRange1.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 3, out constants.Voxel.MassiveLodRange1.Z, out constants.Voxel.MassiveLodRange1.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 4, out constants.Voxel.MassiveLodRange2.X, out constants.Voxel.MassiveLodRange2.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 5, out constants.Voxel.MassiveLodRange2.Z, out constants.Voxel.MassiveLodRange2.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 6, out constants.Voxel.MassiveLodRange3.X, out constants.Voxel.MassiveLodRange3.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 7, out constants.Voxel.MassiveLodRange3.Z, out constants.Voxel.MassiveLodRange3.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 8, out constants.Voxel.MassiveLodRange4.X, out constants.Voxel.MassiveLodRange4.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 9, out constants.Voxel.MassiveLodRange4.Z, out constants.Voxel.MassiveLodRange4.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 10, out constants.Voxel.MassiveLodRange5.X, out constants.Voxel.MassiveLodRange5.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 11, out constants.Voxel.MassiveLodRange5.Z, out constants.Voxel.MassiveLodRange5.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 12, out constants.Voxel.MassiveLodRange6.X, out constants.Voxel.MassiveLodRange6.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 13, out constants.Voxel.MassiveLodRange6.Z, out constants.Voxel.MassiveLodRange6.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 14, out constants.Voxel.MassiveLodRange7.X, out constants.Voxel.MassiveLodRange7.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 15, out constants.Voxel.MassiveLodRange7.Z, out constants.Voxel.MassiveLodRange7.W);

            constants.Voxel.DebugVoxelLod = MyRender11.Settings.DebugClipmapLodColor ? 1.0f : 0.0f;

            // debug multipliers
            constants.TextureDebugMultipliers = new MyTextureDebugMultipliers
            {
                AlbedoMultiplier    = MyRender11.Settings.AlbedoMultiplier,
                AlbedoShift         = MyRender11.Settings.AlbedoShift,
                MetalnessMultiplier = MyRender11.Settings.MetalnessMultiplier,
                MetalnessShift      = MyRender11.Settings.MetalnessShift,
                GlossMultiplier     = MyRender11.Settings.GlossMultiplier,
                GlossShift          = MyRender11.Settings.GlossShift,
                AoMultiplier        = MyRender11.Settings.AoMultiplier,
                AoShift             = MyRender11.Settings.AoShift,
                EmissiveMultiplier  = MyRender11.Settings.EmissiveMultiplier,
                EmissiveShift       = MyRender11.Settings.EmissiveShift,
                ColorMaskMultiplier = MyRender11.Settings.ColorMaskMultiplier,
                ColorMaskShift      = MyRender11.Settings.ColorMaskShift,
            };

            // misc
            if (m_fixedTimeStep > 0)
            {
                m_frameTime      = m_frameTime + m_fixedTimeStep;
                m_lastFrameDelta = m_fixedTimeStep;
            }
            else
            {
                float timer = TimerMs;
                float delta = Math.Min(timer - m_lastFrameTimer, MAX_FRAMETIME) / 1000.0f;
                m_frameTime     += delta;
                m_lastFrameDelta = delta;
                m_lastFrameTimer = timer;
            }

            constants.FrameTimeDelta = m_lastFrameDelta;
            constants.FrameTime      = m_frameTime;

            constants.RandomSeed = m_random.NextFloat();

            // send constants to device
            var mapping = MyMapping.MapDiscard(MyCommon.FrameConstants);

            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();

            if (MyStereoRender.Enable)
            {
                UpdateFrameConstantsInternal(MyStereoRender.EnvMatricesLeftEye, ref constants, MyStereoRegion.LEFT);
                mapping = MyMapping.MapDiscard(MyCommon.FrameConstantsStereoLeftEye);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                UpdateFrameConstantsInternal(MyStereoRender.EnvMatricesRightEye, ref constants, MyStereoRegion.RIGHT);
                mapping = MyMapping.MapDiscard(MyCommon.FrameConstantsStereoRightEye);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();
            }
        }
Exemplo n.º 3
0
        internal static void UpdateFrameConstants()
        {
            MyFrameConstantsLayout constants = new MyFrameConstantsLayout();
            constants.View = Matrix.Transpose(MyEnvironment.ViewAt0);
            constants.Projection = Matrix.Transpose(MyEnvironment.Projection);
            constants.ViewProjection = Matrix.Transpose(MyEnvironment.ViewProjectionAt0);
            constants.InvView = Matrix.Transpose(MyEnvironment.InvViewAt0);
            constants.ViewProjectionWorld = Matrix.Transpose(MyEnvironment.ViewProjection);
            constants.WorldOffset = new Vector4(MyEnvironment.CameraPosition, 0);
            
            constants.Resolution = MyRender11.ResolutionF;
            constants.TerrainTextureDistances = new Vector4(
                MyRender11.Settings.TerrainDetailD0,
                1.0f / (MyRender11.Settings.TerrainDetailD1 - MyRender11.Settings.TerrainDetailD0),
                MyRender11.Settings.TerrainDetailD2,
                1.0f / (MyRender11.Settings.TerrainDetailD3 - MyRender11.Settings.TerrainDetailD2));
            
            constants.TerrainDetailRange.X = 0;
            constants.TerrainDetailRange.Y = 0;
            constants.Time = (float) ( MyRender11.CurrentDrawTime.Seconds - Math.Truncate(MyRender11.CurrentDrawTime.Seconds / 1000.0) * 1000 );
            constants.TimeDelta = (float)(MyRender11.TimeDelta.Seconds);
            constants.FoliageClippingScaling = new Vector4(
                //MyRender.Settings.GrassGeometryClippingDistance,
                MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance(),
                MyRender11.Settings.GrassGeometryScalingNearDistance,
                MyRender11.Settings.GrassGeometryScalingFarDistance,
                MyRender11.Settings.GrassGeometryDistanceScalingFactor);
            constants.WindVector = new Vector3(
                (float)Math.Cos(MyRender11.Settings.WindAzimuth * Math.PI / 180.0),
                0, 
                (float)Math.Sin(MyRender11.Settings.WindAzimuth * Math.PI / 180.0)) * MyRender11.Settings.WindStrength;

            constants.Tau = MyRender11.Postprocess.EyeAdaptationTau;
            constants.BacklightMult = MyRender11.Settings.BacklightMult;
            constants.EnvMult = MyRender11.Settings.EnvMult;
            constants.Contrast = MyRender11.Postprocess.Contrast;
            constants.Brightness = MyRender11.Postprocess.Brightness;
            constants.MiddleGrey = MyRender11.Postprocess.MiddleGrey;
            constants.LuminanceExposure = MyRender11.Postprocess.LuminanceExposure;
            constants.BloomExposure = MyRender11.Postprocess.BloomExposure;
            constants.BloomMult = MyRender11.Postprocess.BloomMult;
            constants.MiddleGreyCurveSharpness = MyRender11.Postprocess.MiddleGreyCurveSharpness;
            constants.MiddleGreyAt0 = MyRender11.Postprocess.MiddleGreyAt0;
            constants.BlueShiftRapidness = MyRender11.Postprocess.BlueShiftRapidness;
            constants.BlueShiftScale = MyRender11.Postprocess.BlueShiftScale;
            constants.FogDensity = MyEnvironment.FogSettings.FogDensity;
            constants.FogMult = MyEnvironment.FogSettings.FogMultiplier;
            constants.FogYOffset = MyRender11.Settings.FogYOffset;
            constants.FogColor = MyEnvironment.FogSettings.FogColor.PackedValue;
            constants.ForwardPassAmbient = MyRender11.Postprocess.ForwardPassAmbient;

            constants.LogLumThreshold = MyRender11.Postprocess.LogLumThreshold;
            constants.Tonemapping_A = MyRender11.Postprocess.Tonemapping_A;
            constants.Tonemapping_B = MyRender11.Postprocess.Tonemapping_B;
            constants.Tonemapping_C = MyRender11.Postprocess.Tonemapping_C;
            constants.Tonemapping_D = MyRender11.Postprocess.Tonemapping_D;
            constants.Tonemapping_E = MyRender11.Postprocess.Tonemapping_E;
            constants.Tonemapping_F = MyRender11.Postprocess.Tonemapping_F;


            //if (true)
            //{
            //    constants.Tau = MyRender11.Settings.AdaptationTau;
            //    constants.BacklightMult = MyRender11.Settings.BacklightMult;
            //    constants.EnvMult = MyRender11.Settings.EnvMult;
            //    constants.Contrast = MyRender11.Settings.Contrast;
            //    constants.Brightness = MyRender11.Settings.Brightness;
            //    constants.MiddleGrey = MyRender11.Settings.MiddleGrey;
            //    constants.LuminanceExposure = MyRender11.Settings.LuminanceExposure;
            //    constants.BloomExposure = MyRender11.Settings.BloomExposure;
            //    constants.BloomMult = MyRender11.Settings.BloomMult;
            //    constants.MiddleGreyCurveSharpness = MyRender11.Settings.MiddleGreyCurveSharpness;
            //    constants.MiddleGreyAt0 = MyRender11.Settings.MiddleGreyAt0;
            //    constants.BlueShiftRapidness = MyRender11.Settings.BlueShiftRapidness;
            //    constants.BlueShiftScale = MyRender11.Settings.BlueShiftScale;
            //}

            constants.TilesNum = (uint)MyScreenDependants.TilesNum;
            constants.TilesX = (uint)MyScreenDependants.TilesX;

            constants.DirectionalLightColor = MyEnvironment.DirectionalLightIntensity;
            constants.DirectionalLightDir = MyEnvironment.DirectionalLightDir;
            constants.SkyboxBlend = 1 - 2 * (float)(Math.Abs(-MyEnvironment.DayTime + 0.5));

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 0, out constants.VoxelLodRange0.X, out constants.VoxelLodRange0.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 1, out constants.VoxelLodRange0.Z, out constants.VoxelLodRange0.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 2, out constants.VoxelLodRange1.X, out constants.VoxelLodRange1.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 3, out constants.VoxelLodRange1.Z, out constants.VoxelLodRange1.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 4, out constants.VoxelLodRange2.X, out constants.VoxelLodRange2.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 5, out constants.VoxelLodRange2.Z, out constants.VoxelLodRange2.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 6, out constants.VoxelLodRange3.X, out constants.VoxelLodRange3.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 7, out constants.VoxelLodRange3.Z, out constants.VoxelLodRange3.W);

            var mapping = MyMapping.MapDiscard(MyCommon.FrameConstants);
            mapping.stream.Write(constants);
            mapping.Unmap();
        }
Exemplo n.º 4
0
        private static void UpdateFrameConstantsInternal(MyEnvironmentMatrices envMatrices, ref MyFrameConstantsLayout constants, MyStereoRegion typeofFC)
        {
            constants.Environment.View                = Matrix.Transpose(envMatrices.ViewAt0);
            constants.Environment.Projection          = Matrix.Transpose(envMatrices.Projection);
            constants.Environment.ViewProjection      = Matrix.Transpose(envMatrices.ViewProjectionAt0);
            constants.Environment.InvView             = Matrix.Transpose(envMatrices.InvViewAt0);
            constants.Environment.InvProjection       = Matrix.Transpose(envMatrices.InvProjection);
            constants.Environment.InvViewProjection   = Matrix.Transpose(envMatrices.InvViewProjectionAt0);
            constants.Environment.ViewProjectionWorld = Matrix.Transpose(envMatrices.ViewProjection);
            constants.Environment.WorldOffset         = new Vector4(envMatrices.CameraPosition, 0);

            constants.Screen.Resolution = MyRender11.ResolutionF;
            if (typeofFC != MyStereoRegion.FULLSCREEN)
            {
                constants.Screen.Resolution.X /= 2;

                Vector3 eyeOffset        = new Vector3(envMatrices.ViewAt0.M41, envMatrices.ViewAt0.M42, envMatrices.ViewAt0.M43);
                Vector3 eyeOffsetInWorld = Vector3.Transform(eyeOffset, Matrix.Transpose(MyRender11.Environment.Matrices.ViewAt0));
                constants.Environment.EyeOffsetInWorld = eyeOffsetInWorld;
            }

            constants.Screen.GBufferOffset = new Vector2I(0, 0);
            if (typeofFC == MyStereoRegion.RIGHT)
            {
                constants.Screen.GBufferOffset.X = MyRender11.ResolutionI.X / 2;
            }

            constants.Screen.ResolutionOfGBuffer = MyRender11.ResolutionI;
        }
Exemplo n.º 5
0
        internal static void UpdateFrameConstants()
        {
            MyFrameConstantsLayout constants = new MyFrameConstantsLayout();
            constants.View = Matrix.Transpose(MyEnvironment.ViewAt0);
            constants.Projection = Matrix.Transpose(MyEnvironment.Projection);
            constants.ViewProjection = Matrix.Transpose(MyEnvironment.ViewProjectionAt0);
            constants.InvView = Matrix.Transpose(MyEnvironment.InvViewAt0);
            constants.InvProjection = Matrix.Transpose(MyEnvironment.InvProjection);
            constants.InvViewProjection = Matrix.Transpose(MyEnvironment.InvViewProjectionAt0);
            constants.ViewProjectionWorld = Matrix.Transpose(MyEnvironment.ViewProjection);
            constants.WorldOffset = new Vector4(MyEnvironment.CameraPosition, 0);

            float skyboxBlend = 1 - 2 * (float)(Math.Abs(-MyEnvironment.DayTime + 0.5));
            
            constants.Resolution = MyRender11.ResolutionF;
            constants.TerrainTextureDistances = new Vector4(
                MyRender11.Settings.TerrainDetailD0,
                1.0f / (MyRender11.Settings.TerrainDetailD1 - MyRender11.Settings.TerrainDetailD0),
                MyRender11.Settings.TerrainDetailD2,
                1.0f / (MyRender11.Settings.TerrainDetailD3 - MyRender11.Settings.TerrainDetailD2));
            
            constants.TerrainDetailRange.X = 0;
            constants.TerrainDetailRange.Y = 0;

            var currentGameplayFrame = MyRender11.Settings.GameplayFrame;
            constants.Time = (float) (currentGameplayFrame) / 60.0f;
            constants.TimeDelta = (float)(currentGameplayFrame - m_lastGameplayFrame) / 60.0f;

            if ((int)FrameCounter != m_lastFrameGameplayUpdate)
            {
                m_lastGameplayFrame = currentGameplayFrame;
                m_lastFrameGameplayUpdate = (int)FrameCounter;
            }

            float time = TimerMs;
            float delta = Math.Min(time - m_lastFrameTime, MAX_FRAMETIME);
            m_lastFrameTime = time;
            m_lastFrameDelta = delta / 1000.0f;
            constants.FrameTimeDelta = m_lastFrameDelta;
            constants.RandomSeed = m_random.NextFloat();

            constants.FoliageClippingScaling = new Vector4(
                //MyRender.Settings.GrassGeometryClippingDistance,
                MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance(),
                MyRender11.Settings.GrassGeometryScalingNearDistance,
                MyRender11.Settings.GrassGeometryScalingFarDistance,
                MyRender11.Settings.GrassGeometryDistanceScalingFactor);
            constants.WindVector = new Vector3(
                (float)Math.Cos(MyRender11.Settings.WindAzimuth * Math.PI / 180.0),
                0, 
                (float)Math.Sin(MyRender11.Settings.WindAzimuth * Math.PI / 180.0)) * MyRender11.Settings.WindStrength;

            constants.Tau = MyRender11.Postprocess.EnableEyeAdaptation ? MyRender11.Postprocess.EyeAdaptationTau : 0;
            constants.BacklightMult = MyRender11.Settings.BacklightMult;
            constants.EnvMult = MyRender11.Settings.EnvMult;
            constants.Contrast = MyRender11.Postprocess.Contrast;
            constants.Brightness = MyRender11.Postprocess.Brightness;
            constants.MiddleGrey = MyRender11.Postprocess.MiddleGrey;
            constants.LuminanceExposure = MyRender11.Postprocess.LuminanceExposure;
            constants.BloomExposure = MyRender11.Postprocess.BloomExposure;
            constants.BloomMult = MyRender11.Postprocess.BloomMult;
            constants.MiddleGreyCurveSharpness = MyRender11.Postprocess.MiddleGreyCurveSharpness;
            constants.MiddleGreyAt0 = MyRender11.Postprocess.MiddleGreyAt0;
            constants.BlueShiftRapidness = MyRender11.Postprocess.BlueShiftRapidness;
            constants.BlueShiftScale = MyRender11.Postprocess.BlueShiftScale;
            constants.FogDensity = MyEnvironment.FogSettings.FogDensity;
            constants.FogMult = MyEnvironment.FogSettings.FogMultiplier;
            constants.FogYOffset = MyRender11.Settings.FogYOffset;
            constants.FogColor = MyEnvironment.FogSettings.FogColor.PackedValue;
            constants.ForwardPassAmbient = MyRender11.Postprocess.ForwardPassAmbient;

            constants.LogLumThreshold = MyRender11.Postprocess.LogLumThreshold + (MyRender11.Postprocess.LogLumThreshold + 2 - MyRender11.Postprocess.LogLumThreshold) * skyboxBlend;
            constants.Tonemapping_A = MyRender11.Postprocess.Tonemapping_A;
            constants.Tonemapping_B = MyRender11.Postprocess.Tonemapping_B;
            constants.Tonemapping_C = MyRender11.Postprocess.Tonemapping_C;
            constants.Tonemapping_D = MyRender11.Postprocess.Tonemapping_D;
            constants.Tonemapping_E = MyRender11.Postprocess.Tonemapping_E;
            constants.Tonemapping_F = MyRender11.Postprocess.Tonemapping_F;


            //if (true)
            //{
            //    constants.Tau = MyRender11.Settings.AdaptationTau;
            //    constants.BacklightMult = MyRender11.Settings.BacklightMult;
            //    constants.EnvMult = MyRender11.Settings.EnvMult;
            //    constants.Contrast = MyRender11.Settings.Contrast;
            //    constants.Brightness = MyRender11.Settings.Brightness;
            //    constants.MiddleGrey = MyRender11.Settings.MiddleGrey;
            //    constants.LuminanceExposure = MyRender11.Settings.LuminanceExposure;
            //    constants.BloomExposure = MyRender11.Settings.BloomExposure;
            //    constants.BloomMult = MyRender11.Settings.BloomMult;
            //    constants.MiddleGreyCurveSharpness = MyRender11.Settings.MiddleGreyCurveSharpness;
            //    constants.MiddleGreyAt0 = MyRender11.Settings.MiddleGreyAt0;
            //    constants.BlueShiftRapidness = MyRender11.Settings.BlueShiftRapidness;
            //    constants.BlueShiftScale = MyRender11.Settings.BlueShiftScale;
            //}

            constants.TilesNum = (uint)MyScreenDependants.TilesNum;
            constants.TilesX = (uint)MyScreenDependants.TilesX;

            constants.DirectionalLightColor = MyEnvironment.DirectionalLightIntensity;
            constants.DirectionalLightDir = MyEnvironment.DirectionalLightDir;

            int lightIndex = 0;
            if (MyEnvironment.AdditionalSunDirections != null && MyEnvironment.AdditionalSunDirections.Length > 0)
            {
                constants.AdditionalSunColor = MyEnvironment.AdditionalSunColors[0];
                constants.AdditionalSunIntensity = MyEnvironment.AdditionalSunIntensities[0];

                if (lightIndex < MyEnvironment.AdditionalSunDirections.Length)
                    constants.SecondarySunDirection1 = new Vector4(MathHelper.CalculateVectorOnSphere(MyEnvironment.DirectionalLightDir, MyEnvironment.AdditionalSunDirections[lightIndex][0], MyEnvironment.AdditionalSunDirections[lightIndex][1]), 0);
                ++lightIndex;
                if (lightIndex < MyEnvironment.AdditionalSunDirections.Length)
                    constants.SecondarySunDirection2 = new Vector4(MathHelper.CalculateVectorOnSphere(MyEnvironment.DirectionalLightDir, MyEnvironment.AdditionalSunDirections[lightIndex][0], MyEnvironment.AdditionalSunDirections[lightIndex][1]), 0);
                ++lightIndex;
                if (lightIndex < MyEnvironment.AdditionalSunDirections.Length)
                    constants.SecondarySunDirection3 = new Vector4(MathHelper.CalculateVectorOnSphere(MyEnvironment.DirectionalLightDir, MyEnvironment.AdditionalSunDirections[lightIndex][0], MyEnvironment.AdditionalSunDirections[lightIndex][1]), 0);
                ++lightIndex;
                if (lightIndex < MyEnvironment.AdditionalSunDirections.Length)
                    constants.SecondarySunDirection4 = new Vector4(MathHelper.CalculateVectorOnSphere(MyEnvironment.DirectionalLightDir, MyEnvironment.AdditionalSunDirections[lightIndex][0], MyEnvironment.AdditionalSunDirections[lightIndex][1]), 0);
                ++lightIndex;
                if (lightIndex < MyEnvironment.AdditionalSunDirections.Length)
                    constants.SecondarySunDirection5 = new Vector4(MathHelper.CalculateVectorOnSphere(MyEnvironment.DirectionalLightDir, MyEnvironment.AdditionalSunDirections[lightIndex][0], MyEnvironment.AdditionalSunDirections[lightIndex][1]), 0);
                ++lightIndex;
                constants.AdditionalSunCount = MyEnvironment.AdditionalSunDirections.Length;
            }
            else
                constants.AdditionalSunCount = 0;

            constants.SkyboxBlend = skyboxBlend;
            constants.SkyboxBrightness = MathHelper.Lerp(1.0f, 0.01f, MyEnvironment.PlanetFactor);
			constants.ShadowFadeout = MyRender11.Settings.ShadowFadeoutMultiplier;

            constants.DebugVoxelLod = MyRenderSettings.DebugClipmapLodColor ? 1.0f : 0.0f;
            constants.EnableVoxelAo = MyRenderSettings.EnableVoxelAo ? 1f : 0f;
            constants.VoxelAoMin = MyRenderSettings.VoxelAoMin;
            constants.VoxelAoMax = MyRenderSettings.VoxelAoMax;
            constants.VoxelAoOffset = MyRenderSettings.VoxelAoOffset;

            constants.BackgroundOrientation = Matrix.CreateFromQuaternion(MyEnvironment.BackgroundOrientation);

            constants.CameraPositionDelta = MyEnvironment.CameraPosition - m_lastCameraPosition;
            m_lastCameraPosition = MyEnvironment.CameraPosition;

            constants.TextureDebugMultipliers = new MyTextureDebugMultipliers
            {
                RgbMultiplier = MyRender11.Settings.RgbMultiplier,
                MetalnessMultiplier = MyRender11.Settings.MetalnessMultiplier,
                GlossMultiplier = MyRender11.Settings.GlossMultiplier,
                AoMultiplier = MyRender11.Settings.AoMultiplier,
                EmissiveMultiplier = MyRender11.Settings.EmissiveMultiplier,
                ColorMaskMultiplier = MyRender11.Settings.ColorMaskMultiplier,
            };

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 0, out constants.VoxelLodRange0.X, out constants.VoxelLodRange0.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 1, out constants.VoxelLodRange0.Z, out constants.VoxelLodRange0.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 2, out constants.VoxelLodRange1.X, out constants.VoxelLodRange1.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 3, out constants.VoxelLodRange1.Z, out constants.VoxelLodRange1.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 4, out constants.VoxelLodRange2.X, out constants.VoxelLodRange2.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 5, out constants.VoxelLodRange2.Z, out constants.VoxelLodRange2.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 6, out constants.VoxelLodRange3.X, out constants.VoxelLodRange3.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 7, out constants.VoxelLodRange3.Z, out constants.VoxelLodRange3.W);

            //
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 0, out constants.VoxelMassiveLodRange0.X, out constants.VoxelMassiveLodRange0.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 1, out constants.VoxelMassiveLodRange0.Z, out constants.VoxelMassiveLodRange0.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 2, out constants.VoxelMassiveLodRange1.X, out constants.VoxelMassiveLodRange1.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 3, out constants.VoxelMassiveLodRange1.Z, out constants.VoxelMassiveLodRange1.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 4, out constants.VoxelMassiveLodRange2.X, out constants.VoxelMassiveLodRange2.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 5, out constants.VoxelMassiveLodRange2.Z, out constants.VoxelMassiveLodRange2.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 6, out constants.VoxelMassiveLodRange3.X, out constants.VoxelMassiveLodRange3.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 7, out constants.VoxelMassiveLodRange3.Z, out constants.VoxelMassiveLodRange3.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 8, out constants.VoxelMassiveLodRange4.X, out constants.VoxelMassiveLodRange4.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 9, out constants.VoxelMassiveLodRange4.Z, out constants.VoxelMassiveLodRange4.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 10, out constants.VoxelMassiveLodRange5.X, out constants.VoxelMassiveLodRange5.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 11, out constants.VoxelMassiveLodRange5.Z, out constants.VoxelMassiveLodRange5.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 12, out constants.VoxelMassiveLodRange6.X, out constants.VoxelMassiveLodRange6.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 13, out constants.VoxelMassiveLodRange6.Z, out constants.VoxelMassiveLodRange6.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 14, out constants.VoxelMassiveLodRange7.X, out constants.VoxelMassiveLodRange7.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 15, out constants.VoxelMassiveLodRange7.Z, out constants.VoxelMassiveLodRange7.W);
            

            var mapping = MyMapping.MapDiscard(MyCommon.FrameConstants);
            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();
        }
Exemplo n.º 6
0
        internal static void UpdateFrameConstants()
        {
            MyFrameConstantsLayout constants = new MyFrameConstantsLayout();

            constants.View                = Matrix.Transpose(MyEnvironment.ViewAt0);
            constants.Projection          = Matrix.Transpose(MyEnvironment.Projection);
            constants.ViewProjection      = Matrix.Transpose(MyEnvironment.ViewProjectionAt0);
            constants.InvView             = Matrix.Transpose(MyEnvironment.InvViewAt0);
            constants.ViewProjectionWorld = Matrix.Transpose(MyEnvironment.ViewProjection);
            constants.WorldOffset         = new Vector4(MyEnvironment.CameraPosition, 0);

            constants.Resolution = MyRender11.ResolutionF;
            constants.TerrainTextureDistances = new Vector4(
                MyRender11.Settings.TerrainDetailD0,
                1.0f / (MyRender11.Settings.TerrainDetailD1 - MyRender11.Settings.TerrainDetailD0),
                MyRender11.Settings.TerrainDetailD2,
                1.0f / (MyRender11.Settings.TerrainDetailD3 - MyRender11.Settings.TerrainDetailD2));

            constants.TerrainDetailRange.X = 0;
            constants.TerrainDetailRange.Y = 0;
            constants.Time      = (float)(MyRender11.CurrentDrawTime.Seconds - Math.Truncate(MyRender11.CurrentDrawTime.Seconds / 1000.0) * 1000);
            constants.TimeDelta = (float)(MyRender11.TimeDelta.Seconds);
            constants.FoliageClippingScaling = new Vector4(
                //MyRender.Settings.GrassGeometryClippingDistance,
                MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance(),
                MyRender11.Settings.GrassGeometryScalingNearDistance,
                MyRender11.Settings.GrassGeometryScalingFarDistance,
                MyRender11.Settings.GrassGeometryDistanceScalingFactor);
            constants.WindVector = new Vector3(
                (float)Math.Cos(MyRender11.Settings.WindAzimuth * Math.PI / 180.0),
                0,
                (float)Math.Sin(MyRender11.Settings.WindAzimuth * Math.PI / 180.0)) * MyRender11.Settings.WindStrength;

            constants.Tau                      = MyRender11.Postprocess.EyeAdaptationTau;
            constants.BacklightMult            = MyRender11.Settings.BacklightMult;
            constants.EnvMult                  = MyRender11.Settings.EnvMult;
            constants.Contrast                 = MyRender11.Postprocess.Contrast;
            constants.Brightness               = MyRender11.Postprocess.Brightness;
            constants.MiddleGrey               = MyRender11.Postprocess.MiddleGrey;
            constants.LuminanceExposure        = MyRender11.Postprocess.LuminanceExposure;
            constants.BloomExposure            = MyRender11.Postprocess.BloomExposure;
            constants.BloomMult                = MyRender11.Postprocess.BloomMult;
            constants.MiddleGreyCurveSharpness = MyRender11.Postprocess.MiddleGreyCurveSharpness;
            constants.MiddleGreyAt0            = MyRender11.Postprocess.MiddleGreyAt0;
            constants.BlueShiftRapidness       = MyRender11.Postprocess.BlueShiftRapidness;
            constants.BlueShiftScale           = MyRender11.Postprocess.BlueShiftScale;
            constants.FogDensity               = MyEnvironment.FogSettings.FogDensity;
            constants.FogMult                  = MyEnvironment.FogSettings.FogMultiplier;
            constants.FogYOffset               = MyRender11.Settings.FogYOffset;
            constants.FogColor                 = MyEnvironment.FogSettings.FogColor.PackedValue;
            constants.ForwardPassAmbient       = MyRender11.Postprocess.ForwardPassAmbient;

            constants.LogLumThreshold = MyRender11.Postprocess.LogLumThreshold;
            constants.Tonemapping_A   = MyRender11.Postprocess.Tonemapping_A;
            constants.Tonemapping_B   = MyRender11.Postprocess.Tonemapping_B;
            constants.Tonemapping_C   = MyRender11.Postprocess.Tonemapping_C;
            constants.Tonemapping_D   = MyRender11.Postprocess.Tonemapping_D;
            constants.Tonemapping_E   = MyRender11.Postprocess.Tonemapping_E;
            constants.Tonemapping_F   = MyRender11.Postprocess.Tonemapping_F;


            //if (true)
            //{
            //    constants.Tau = MyRender11.Settings.AdaptationTau;
            //    constants.BacklightMult = MyRender11.Settings.BacklightMult;
            //    constants.EnvMult = MyRender11.Settings.EnvMult;
            //    constants.Contrast = MyRender11.Settings.Contrast;
            //    constants.Brightness = MyRender11.Settings.Brightness;
            //    constants.MiddleGrey = MyRender11.Settings.MiddleGrey;
            //    constants.LuminanceExposure = MyRender11.Settings.LuminanceExposure;
            //    constants.BloomExposure = MyRender11.Settings.BloomExposure;
            //    constants.BloomMult = MyRender11.Settings.BloomMult;
            //    constants.MiddleGreyCurveSharpness = MyRender11.Settings.MiddleGreyCurveSharpness;
            //    constants.MiddleGreyAt0 = MyRender11.Settings.MiddleGreyAt0;
            //    constants.BlueShiftRapidness = MyRender11.Settings.BlueShiftRapidness;
            //    constants.BlueShiftScale = MyRender11.Settings.BlueShiftScale;
            //}

            constants.TilesNum = (uint)MyScreenDependants.TilesNum;
            constants.TilesX   = (uint)MyScreenDependants.TilesX;

            constants.DirectionalLightColor = MyEnvironment.DirectionalLightIntensity;
            constants.DirectionalLightDir   = MyEnvironment.DirectionalLightDir;
            constants.SkyboxBlend           = 1 - 2 * (float)(Math.Abs(-MyEnvironment.DayTime + 0.5));

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 0, out constants.VoxelLodRange0.X, out constants.VoxelLodRange0.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 1, out constants.VoxelLodRange0.Z, out constants.VoxelLodRange0.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 2, out constants.VoxelLodRange1.X, out constants.VoxelLodRange1.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 3, out constants.VoxelLodRange1.Z, out constants.VoxelLodRange1.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 4, out constants.VoxelLodRange2.X, out constants.VoxelLodRange2.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 5, out constants.VoxelLodRange2.Z, out constants.VoxelLodRange2.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 6, out constants.VoxelLodRange3.X, out constants.VoxelLodRange3.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 7, out constants.VoxelLodRange3.Z, out constants.VoxelLodRange3.W);

            var mapping = MyMapping.MapDiscard(MyCommon.FrameConstants);

            mapping.stream.Write(constants);
            mapping.Unmap();
        }
Exemplo n.º 7
0
        internal static void UpdateFrameConstants()
        {
            // environment
            MyFrameConstantsLayout constants = new MyFrameConstantsLayout();
            UpdateFrameConstantsInternal(MyRender11.Environment.Matrices, ref constants, MyStereoRegion.FULLSCREEN);
            constants.Environment.CameraPositionDelta = MyRender11.Environment.Matrices.CameraPosition - m_lastCameraPosition;
            m_lastCameraPosition = MyRender11.Environment.Matrices.CameraPosition;

            // skybox
            constants.Environment.BackgroundOrientation = Matrix.CreateFromQuaternion(MyRender11.Environment.Data.SkyboxOrientation);

            // screen
            constants.Screen.TilesNum = (uint)MyScreenDependants.TilesNum;
            constants.Screen.TilesX = (uint)MyScreenDependants.TilesX;

            // foliage
            constants.Foliage.ClippingScaling = new Vector4(
                //MyRender.Settings.GrassGeometryClippingDistance,
                MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance(),
                MyRender11.Settings.GrassGeometryScalingNearDistance,
                MyRender11.Settings.GrassGeometryScalingFarDistance,
                MyRender11.Settings.GrassGeometryDistanceScalingFactor);
            constants.Foliage.WindVector = new Vector3(
                (float)Math.Cos(MyRender11.Settings.WindAzimuth * Math.PI / 180.0),
                0,
                (float)Math.Sin(MyRender11.Settings.WindAzimuth * Math.PI / 180.0)) * MyRender11.Settings.WindStrength;

            // postprocess
            constants.Postprocess = MyRender11.Postprocess.GetProcessedData();

            // lighting data
            constants.EnvironmentLight = MyRender11.Environment.Data.EnvironmentLight;
            if (!MyRender11.DebugOverrides.Sun)
                constants.EnvironmentLight.SunColorRaw = new Vector3(0, 0, 0);

            // fog
            constants.Fog.Density = MyRender11.Environment.Fog.FogDensity;
            constants.Fog.Mult = MyRender11.Environment.Fog.FogMultiplier;
            constants.Fog.Color = MyRender11.Environment.Fog.FogColor.PackedValue;

            // voxels
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 0, out constants.Voxel.LodRange0.X, out constants.Voxel.LodRange0.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 1, out constants.Voxel.LodRange0.Z, out constants.Voxel.LodRange0.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 2, out constants.Voxel.LodRange1.X, out constants.Voxel.LodRange1.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 3, out constants.Voxel.LodRange1.Z, out constants.Voxel.LodRange1.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 4, out constants.Voxel.LodRange2.X, out constants.Voxel.LodRange2.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 5, out constants.Voxel.LodRange2.Z, out constants.Voxel.LodRange2.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 6, out constants.Voxel.LodRange3.X, out constants.Voxel.LodRange3.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Normal, 7, out constants.Voxel.LodRange3.Z, out constants.Voxel.LodRange3.W);

            //
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 0, out constants.Voxel.MassiveLodRange0.X, out constants.Voxel.MassiveLodRange0.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 1, out constants.Voxel.MassiveLodRange0.Z, out constants.Voxel.MassiveLodRange0.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 2, out constants.Voxel.MassiveLodRange1.X, out constants.Voxel.MassiveLodRange1.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 3, out constants.Voxel.MassiveLodRange1.Z, out constants.Voxel.MassiveLodRange1.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 4, out constants.Voxel.MassiveLodRange2.X, out constants.Voxel.MassiveLodRange2.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 5, out constants.Voxel.MassiveLodRange2.Z, out constants.Voxel.MassiveLodRange2.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 6, out constants.Voxel.MassiveLodRange3.X, out constants.Voxel.MassiveLodRange3.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 7, out constants.Voxel.MassiveLodRange3.Z, out constants.Voxel.MassiveLodRange3.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 8, out constants.Voxel.MassiveLodRange4.X, out constants.Voxel.MassiveLodRange4.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 9, out constants.Voxel.MassiveLodRange4.Z, out constants.Voxel.MassiveLodRange4.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 10, out constants.Voxel.MassiveLodRange5.X, out constants.Voxel.MassiveLodRange5.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 11, out constants.Voxel.MassiveLodRange5.Z, out constants.Voxel.MassiveLodRange5.W);

            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 12, out constants.Voxel.MassiveLodRange6.X, out constants.Voxel.MassiveLodRange6.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 13, out constants.Voxel.MassiveLodRange6.Z, out constants.Voxel.MassiveLodRange6.W);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 14, out constants.Voxel.MassiveLodRange7.X, out constants.Voxel.MassiveLodRange7.Y);
            MyClipmap.ComputeLodViewBounds(MyClipmapScaleEnum.Massive, 15, out constants.Voxel.MassiveLodRange7.Z, out constants.Voxel.MassiveLodRange7.W);

            constants.Voxel.DebugVoxelLod = MyRender11.Settings.DebugClipmapLodColor ? 1.0f : 0.0f;

            // debug multipliers
            constants.TextureDebugMultipliers = new MyTextureDebugMultipliers
            {
                AlbedoMultiplier = MyRender11.Settings.AlbedoMultiplier,
                AlbedoShift = MyRender11.Settings.AlbedoShift,
                MetalnessMultiplier = MyRender11.Settings.MetalnessMultiplier,
                MetalnessShift = MyRender11.Settings.MetalnessShift,
                GlossMultiplier = MyRender11.Settings.GlossMultiplier,
                GlossShift = MyRender11.Settings.GlossShift,
                AoMultiplier = MyRender11.Settings.AoMultiplier,
                AoShift = MyRender11.Settings.AoShift,
                EmissiveMultiplier = MyRender11.Settings.EmissiveMultiplier,
                EmissiveShift = MyRender11.Settings.EmissiveShift,
                ColorMaskMultiplier = MyRender11.Settings.ColorMaskMultiplier,
                ColorMaskShift = MyRender11.Settings.ColorMaskShift,
            };

            // misc
            if (m_fixedTimeStep > 0)
            {
                m_frameTime = m_frameTime + m_fixedTimeStep;
                m_lastFrameDelta = m_fixedTimeStep;
            }
            else
            {
                float timer = TimerMs;
                float delta = Math.Min(timer - m_lastFrameTimer, MAX_FRAMETIME) / 1000.0f;
                m_frameTime += delta;
                m_lastFrameDelta = delta;
                m_lastFrameTimer = timer;
            }

            constants.FrameTimeDelta = m_lastFrameDelta;
            constants.FrameTime = m_frameTime;

            constants.RandomSeed = m_random.NextFloat();

            // send constants to device
            var mapping = MyMapping.MapDiscard(MyCommon.FrameConstants);
            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();

            if (MyStereoRender.Enable)
            {
                UpdateFrameConstantsInternal(MyStereoRender.EnvMatricesLeftEye, ref constants, MyStereoRegion.LEFT);
                mapping = MyMapping.MapDiscard(MyCommon.FrameConstantsStereoLeftEye);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                UpdateFrameConstantsInternal(MyStereoRender.EnvMatricesRightEye, ref constants, MyStereoRegion.RIGHT);
                mapping = MyMapping.MapDiscard(MyCommon.FrameConstantsStereoRightEye);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();
            }
        }
Exemplo n.º 8
0
        private static void UpdateFrameConstantsInternal(MyEnvironmentMatrices envMatrices, ref MyFrameConstantsLayout constants, MyStereoRegion typeofFC)
        {
            constants.Environment.View = Matrix.Transpose(envMatrices.ViewAt0);
            constants.Environment.Projection = Matrix.Transpose(envMatrices.Projection);
            constants.Environment.ViewProjection = Matrix.Transpose(envMatrices.ViewProjectionAt0);
            constants.Environment.InvView = Matrix.Transpose(envMatrices.InvViewAt0);
            constants.Environment.InvProjection = Matrix.Transpose(envMatrices.InvProjection);
            constants.Environment.InvViewProjection = Matrix.Transpose(envMatrices.InvViewProjectionAt0);
            constants.Environment.ViewProjectionWorld = Matrix.Transpose(envMatrices.ViewProjection);
            constants.Environment.WorldOffset = new Vector4(envMatrices.CameraPosition, 0);

            constants.Screen.Resolution = MyRender11.ResolutionF;
            if (typeofFC != MyStereoRegion.FULLSCREEN)
            {
                constants.Screen.Resolution.X /= 2;

                Vector3 eyeOffset = new Vector3(envMatrices.ViewAt0.M41, envMatrices.ViewAt0.M42, envMatrices.ViewAt0.M43);
                Vector3 eyeOffsetInWorld = Vector3.Transform(eyeOffset, Matrix.Transpose(MyRender11.Environment.Matrices.ViewAt0));
                constants.Environment.EyeOffsetInWorld = eyeOffsetInWorld;
            }

            constants.Screen.GBufferOffset = new Vector2I(0, 0);
            if (typeofFC == MyStereoRegion.RIGHT)
                constants.Screen.GBufferOffset.X = MyRender11.ResolutionI.X / 2;

            constants.Screen.ResolutionOfGBuffer = MyRender11.ResolutionI;
        }