internal MyLodMeshMerge(MyClipmap parentClipmap, int lod, int lodDivisions, ref MatrixD worldMatrix, ref Vector3D massiveCenter, float massiveRadius, RenderFlags renderFlags)
            {
                Debug.Assert(parentClipmap != null, "Parent clipmap cannot be null");
                Debug.Assert(lod >= 0, "Lod level must be non-negative");
                Debug.Assert(lodDivisions >= 0, "Invalid number of lod divisions");
                m_parentClipmap = parentClipmap;
                m_lod = lod;
                m_lodDivisions = lodDivisions;

                if (!IsUsed())
                    return;

                m_dirtyProxyIndices = new HashSet<int>();
                m_cellProxyToAabbProxy = new Dictionary<MyClipmapCellProxy, int>();
                m_boundingBoxes = new MyDynamicAABBTreeD(Vector3D.Zero);

                int cellCount = lodDivisions*lodDivisions*lodDivisions;
                m_mergeJobs = new MergeJobInfo[cellCount];
                m_mergedLodMeshProxies = new MyClipmapCellProxy[cellCount];
                m_trackedActors = new HashSet<MyActor>[cellCount];

                for (int divideIndex = 0; divideIndex < cellCount; ++divideIndex)
                {
                    m_mergedLodMeshProxies[divideIndex] = new MyClipmapCellProxy(new MyCellCoord(Lod, GetCellFromDivideIndex(divideIndex)), ref worldMatrix, massiveCenter, massiveRadius, renderFlags, true);
                    m_mergeJobs[divideIndex] = new MergeJobInfo { CurrentWorkId = 0, LodMeshesBeingMerged = new List<LodMeshId>(), NextPossibleMergeStartTime = MyCommon.FrameCounter };
                    m_trackedActors[divideIndex] = new HashSet<MyActor>();
                    m_dirtyProxyIndices.Add(divideIndex);
                }
            }
        internal MyClipmapHandler(uint id, MyClipmapScaleEnum scaleGroup, MatrixD worldMatrix, Vector3I sizeLod0, Vector3D massiveCenter, float massiveRadius, bool spherize, RenderFlags additionalFlags, MyClipmap.PruningFunc prunningFunc)
        {
            m_clipmapBase = new MyClipmap(id, scaleGroup, worldMatrix, sizeLod0, this, massiveCenter, massiveRadius, prunningFunc);
            m_massiveCenter = massiveCenter;
            m_renderFlags = additionalFlags;
            m_mergeHandler = null;

            if (spherize)
                m_massiveRadius = massiveRadius;

            if (MyLodMeshMergeHandler.ShouldAllocate(m_mergeHandler))
                m_mergeHandler = AllocateMergeHandler();

            MyClipmap.AddToUpdate(MyRender11.Environment.Matrices.CameraPosition, Base);
        }
Beispiel #3
0
        internal MyClipmapHandler(uint id, MyClipmapScaleEnum scaleGroup, MatrixD worldMatrix, Vector3I sizeLod0, Vector3D massiveCenter, float massiveRadius, bool spherize, RenderFlags additionalFlags, MyClipmap.PruningFunc prunningFunc)
        {
            m_clipmapBase   = new MyClipmap(id, scaleGroup, worldMatrix, sizeLod0, this, massiveCenter, massiveRadius, prunningFunc);
            m_massiveCenter = massiveCenter;
            m_renderFlags   = additionalFlags;
            m_mergeHandler  = null;

            if (spherize)
            {
                m_massiveRadius = massiveRadius;
            }

            if (MyLodMeshMergeHandler.ShouldAllocate(m_mergeHandler))
            {
                m_mergeHandler = AllocateMergeHandler();
            }

            MyClipmap.AddToUpdate(MyRender11.Environment.Matrices.CameraPosition, Base);
        }
        internal static void UnloadData()
        {
            MyActorFactory.RemoveAll();
            // many-to-one relation, can live withput owners, deallocated separately
            // MyComponentFactory<MyInstancingComponent>.RemoveAll();

            //MyVoxelMesh.RemoveAll();
            //MyDynamicMesh.RemoveAll();


            MyRender11.Log.WriteLine("Unloading session data");

            // Remove leftover persistent debug draw messages
            m_debugDrawMessages.Clear();

            MyScene.DynamicRenderablesDBVH.Clear();
            if (MyScene.SeparateGeometry)
            {
                MyScene.StaticRenderablesDBVH.Clear();
            }
            MyScene.GroupsDBVH.Clear();
            MyScene.FoliageDBVH.Clear();
            MyClipmapFactory.RemoveAll();
            MyClipmap.UnloadCache();

            MyInstancing.OnSessionEnd();
            MyFoliageComponents.OnSessionEnd();
            MyMeshes.OnSessionEnd();
            MyLights.OnSessionEnd();

            MyMaterials1.OnSessionEnd();
            MyVoxelMaterials1.OnSessionEnd();
            MyMeshMaterials1.OnSessionEnd();
            MyScreenDecals.OnSessionEnd();

            MyTextures.OnSessionEnd();
            MyBigMeshTable.Table.OnSessionEnd();

            MyPrimitivesRenderer.Unload();

            //MyAssetsLoader.ClearMeshes();
        }
Beispiel #5
0
        private static void OnSessionEnd()
        {
            MyManagers.OnUnloadData();

            MyActorFactory.RemoveAll();
            // many-to-one relation, can live withput owners, deallocated separately
            // MyComponentFactory<MyInstancingComponent>.RemoveAll();

            //MyVoxelMesh.RemoveAll();
            //MyDynamicMesh.RemoveAll();


            MyRender11.Log.WriteLine("Unloading session data");

            // Remove leftover persistent debug draw messages
            m_debugDrawMessages.Clear();

            MyScene.Clear();

            MyClipmapFactory.RemoveAll();
            MyClipmap.UnloadCache();

            MyInstancing.OnSessionEnd();
            MyFoliageComponents.OnSessionEnd();
            MyMeshes.OnSessionEnd();
            MyLights.OnSessionEnd();

            MyMaterials1.OnSessionEnd();
            MyVoxelMaterials1.OnSessionEnd();
            MyMeshMaterials1.OnSessionEnd();
            MyScreenDecals.OnSessionEnd();

            MyBigMeshTable.Table.OnSessionEnd();

            MyPrimitivesRenderer.Unload();

            MyTransparentRendering.OnSessionEnd();
            MyBillboardRenderer.OnSessionEnd();

            //MyAssetsLoader.ClearMeshes();
        }
Beispiel #6
0
 public override void UnloadContent()
 {
     m_clipmapBase.UnloadContent();
     MyClipmap.RemoveFromUpdate(m_clipmapBase);
     base.UnloadContent();
 }
Beispiel #7
0
 public override void LoadContent()
 {
     m_clipmapBase.LoadContent();
     MyClipmap.AddToUpdate(MyRenderCamera.Position, m_clipmapBase);
     base.LoadContent();
 }
Beispiel #8
0
 internal void RemoveFromUpdate()
 {
     Base.UnloadContent();
     MyClipmap.RemoveFromUpdate(Base);
 }
Beispiel #9
0
 internal MyClipmapHandler(uint id, MyClipmapScaleEnum scaleGroup, MatrixD worldMatrix, Vector3I sizeLod0)
 {
     m_clipmapBase = new MyClipmap(id, scaleGroup, worldMatrix, sizeLod0, this);
     MyClipmap.AddToUpdate(MyEnvironment.CameraPosition, m_clipmapBase);
 }
        internal MyLodMeshMergeHandler(MyClipmap parentClipmap, int lodCount, int lodDivisions, ref MatrixD worldMatrix, ref Vector3D massiveCenter, float massiveRadius, RenderFlags renderFlags)
        {
            Debug.Assert(lodCount <= NUM_DIVISIONS_PER_LOD.Length, "Only " + NUM_DIVISIONS_PER_LOD.Length + " lods allowed, " + lodCount + " requested. Consider adding elements to NUM_DIVISIONS_PER_LOD.");
            Debug.Assert(parentClipmap != null, "Parent clipmap of merge handler cannot be null!");
            m_mergesPerLod = new MyLodMeshMerge[lodCount];

            for (int lodIndex = 0; lodIndex < m_mergesPerLod.Length; ++lodIndex)
            {
                int divisions = NUM_DIVISIONS_PER_LOD[lodIndex];
                m_mergesPerLod[lodIndex] = new MyLodMeshMerge(parentClipmap, lodIndex, divisions, ref worldMatrix, ref massiveCenter, massiveRadius, renderFlags);
                m_dirtyLodMergeIndices.Add(lodIndex);
            }

            m_parentClipmap = parentClipmap;
        }
Beispiel #11
0
        public static uint CreateClipmap(
            MatrixD worldMatrix,
            Vector3I sizeLod0,
            MyClipmapScaleEnum scaleGroup,
            Vector3D position,
            float atmosphereRadius = 0.0f,
            float planetRadius = 0.0f,
            bool hasAtmosphere = false,
            Vector3? atmosphereWaveLenghts = null,
            bool spherizeWithDistance = true,
            RenderFlags additionalFlags = 0,
            MyClipmap.PruningFunc prunningFunc = null)
        {
            var message = MessagePool.Get<MyRenderMessageCreateClipmap>(MyRenderMessageEnum.CreateClipmap);

            uint clipmapId = GetMessageId(ObjectType.Clipmap);
            message.ClipmapId = clipmapId;
            message.WorldMatrix = worldMatrix;
            message.SizeLod0 = sizeLod0;
            message.ScaleGroup = scaleGroup;
            message.AtmosphereRadius = atmosphereRadius;
            message.PlanetRadius = planetRadius;
            message.HasAtmosphere = hasAtmosphere;
            message.Position = position;
            message.AtmosphereWaveLenghts = atmosphereWaveLenghts;
            message.SpherizeWithDistance = spherizeWithDistance;
            message.AdditionalRenderFlags = additionalFlags;
            message.PrunningFunc = prunningFunc;
            EnqueueMessage(message);

            return clipmapId;
        }
Beispiel #12
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();
            }
        }
Beispiel #13
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();
        }
 internal void RemoveFromUpdate()
 {
     MyClipmap.RemoveFromUpdate(Base);
 }
Beispiel #15
0
        internal static void Draw(IRtvBindable renderTarget, IRtvTexture ambientOcclusion)
        {
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.SetRtv(renderTarget);
            RC.PixelShader.SetSrvs(0, MyGBuffer.Main);

            RC.SetBlendState(null);

            if (MyRender11.Settings.DisplayGbufferColor)
            {
                RC.PixelShader.Set(m_baseColorShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferAlbedo)
            {
                RC.PixelShader.Set(m_albedoShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferNormal)
            {
                RC.PixelShader.Set(m_normalShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferNormalView)
            {
                RC.PixelShader.Set(m_normalViewShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferGlossiness)
            {
                RC.PixelShader.Set(m_glossinessShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferMetalness)
            {
                RC.PixelShader.Set(m_metalnessShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferAO)
            {
                RC.PixelShader.Set(m_aoShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEmissive)
            {
                RC.PixelShader.Set(m_emissiveShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAmbientDiffuse)
            {
                RC.PixelShader.Set(m_ambientDiffuseShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAmbientSpecular)
            {
                RC.PixelShader.Set(m_ambientSpecularShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEdgeMask)
            {
                RC.PixelShader.Set(m_edgeDebugShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayShadowsWithDebug)
            {
                RC.PixelShader.Set(m_shadowsDebugShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayNDotL)
            {
                RC.PixelShader.Set(m_NDotLShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferLOD)
            {
                RC.PixelShader.Set(m_LODShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayMipmap)
            {
                RC.PixelShader.Set(m_baseColorShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayDepth)
            {
                RC.PixelShader.Set(m_depthShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayReprojectedDepth)
            {
                var dst = MyManagers.RwTexturesPool.BorrowUav("DebugRender.DepthReprojection", Format.R32_Float);
                MyRender11.RC.ClearUav(dst, SharpDX.Int4.Zero);

                RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
                RC.ComputeShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth);
                RC.ComputeShader.SetUav(0, dst);
                RC.ComputeShader.Set(m_depthReprojectionShader);
                int numThreadGroupsX = align(MyRender11.ResolutionI.X, 32) / 32;
                int numThreadGroupsY = align(MyRender11.ResolutionI.Y, 32) / 32;
                RC.Dispatch(numThreadGroupsX, numThreadGroupsY, 1);
                RC.ComputeShader.SetSrv(0, null);
                RC.ComputeShader.SetUav(0, null);

                RC.PixelShader.SetSrv(0, dst);
                RC.PixelShader.Set(m_depthShader);
                MyScreenPass.DrawFullscreenQuad();

                RC.PixelShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth);
            }
            else if (MyRender11.Settings.DisplayStencil)
            {
                RC.PixelShader.Set(m_stencilShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAO)
            {
                RC.PixelShader.SetSrv(0, ambientOcclusion);
                RC.PixelShader.SetSampler(0, MySamplerStateManager.Linear);
                RC.PixelShader.Set(m_rtShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEnvProbe)
            {
                DrawEnvProbe();
            }

            //DrawEnvProbe();
            //DrawAtmosphereTransmittance(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]);
            //DrawAtmosphereInscatter(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]);

            if (MyRender11.Settings.DrawCascadeTextures)
            {
                //DrawDepthArrayTexture(MyManagers.Shadow.GetCsmForGbuffer(), 100, 100, 200);
                DrawDepthArrayTexture(MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray, 100, 100, 200);
                if (MyScene.SeparateGeometry)
                {
                    DrawDepthArrayTexture(MyRender11.StaticShadows.ShadowCascades.CascadeShadowmapArray, 100, 300, 200);
                    DrawDepthArrayTexture(MyShadowCascades.CombineShadowmapArray, 100, 500, 200);
                }
            }

            if (MyRender11.Settings.DisplayIDs || MyRender11.Settings.DisplayAabbs)
            {
                DrawHierarchyDebug();
            }

            if (false)
            {
                var batch = MyLinesRenderer.CreateBatch();

                foreach (var light in MyLightsRendering.VisiblePointlights)
                {
                    batch.AddSphereRing(new BoundingSphere(light.PointPosition, 0.5f), Color.White, Matrix.Identity);
                }
                batch.Commit();
            }

            // draw terrain lods
            if (MyRender11.Settings.DebugRenderClipmapCells)
            {
                //var batch = MyLinesRenderer.CreateBatch();

                //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => (MyMeshes.IsVoxelMesh(x.Mesh))))
                //{
                //    if (renderable.IsVisible)
                //    {
                //        if (renderable.m_lod >= LOD_COLORS.Length)
                //            return;

                //        BoundingBox bb = new BoundingBox(renderable.m_owner.Aabb.Min - MyRender11.Environment.CameraPosition,renderable.m_owner.Aabb.Max - MyRender11.Environment.CameraPosition);

                //        batch.AddBoundingBox(bb, new Color(LOD_COLORS[renderable.m_voxelLod]));


                //        if (renderable.m_lods != null && renderable.m_voxelLod != renderable.m_lods[0].RenderableProxies[0].ObjectData.CustomAlpha)
                //        {

                //        }
                //    }
                //}

                //batch.Commit();

                MyClipmap.DebugDrawClipmaps();
            }

            //if(true)
            //{
            //    var batch = MyLinesRenderer.CreateBatch();

            //    foreach(var id in MyLights.DirtySpotlights)
            //    {
            //        var info = MyLights.Spotlights[id.Index];

            //        if(info.ApertureCos > 0)
            //        {
            //            var D = info.Direction * info.Range;
            //            //batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed);

            //            //var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range).Transform(Matrix.CreateLookAt(MyLights.Lights.Data[id.Index].Position, info.Direction, info.Up));


            //            //batch.AddBoundingBox(bb, Color.Green);

            //            batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed);

            //            var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range, MyLights.Lights.Data[id.Index].Position, info.Up);
            //            batch.AddBoundingBox(bb, Color.Green);
            //        }
            //    }



            //    batch.Commit();
            //}

            // draw lods
            if (false)
            {
                var batch = MyLinesRenderer.CreateBatch();

                //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => ((x.GetMesh() as MyVoxelMesh) == null)))
                //{

                //    if (renderable.CurrentLodNum >= LOD_COLORS.Length || renderable.m_lods.Length == 1)
                //        continue;

                //    batch.AddBoundingBox(renderable.m_owner.Aabb, new Color(LOD_COLORS[renderable.CurrentLodNum]));
                //}

                batch.Commit();
            }
        }
Beispiel #16
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();
        }
        internal static void Draw(MyBindableResource renderTarget)
        {
            var context = RC.DeviceContext;

            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.Rasterizer.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            context.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, renderTarget);
            RC.BindGBufferForRead(0, MyGBuffer.Main);

            //context.OutputMerger.SetTargets(null as DepthStencilView, MyRender.Backbuffer.RenderTarget);

            //context.PixelShader.SetShaderResources(0, MyRender.MainGbuffer.DepthGbufferViews);

            context.OutputMerger.BlendState = null;

            RC.SetVS(null);
            RC.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding());
            RC.DeviceContext.InputAssembler.InputLayout = null;

            if (MyRender11.Settings.DisplayGbufferColor)
            {
                context.PixelShader.Set(m_baseColorShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            if (MyRender11.Settings.DisplayGbufferColorLinear)
            {
                context.PixelShader.Set(m_baseColorLinearShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferNormal)
            {
                context.PixelShader.Set(m_normalShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferGlossiness)
            {
                context.PixelShader.Set(m_glossinessShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferMetalness)
            {
                context.PixelShader.Set(m_metalnessShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferMaterialID)
            {
                context.PixelShader.Set(m_matIDShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayGbufferAO)
            {
                context.PixelShader.Set(m_aoShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEmissive)
            {
                context.PixelShader.Set(m_emissiveShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAmbientDiffuse)
            {
                context.PixelShader.Set(m_ambientDiffuseShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayAmbientSpecular)
            {
                context.PixelShader.Set(m_ambientSpecularShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayEdgeMask)
            {
                context.PixelShader.Set(m_edgeDebugShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayShadowsWithDebug)
            {
                context.PixelShader.Set(m_shadowsDebugShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayNDotL)
            {
                context.PixelShader.Set(m_NDotLShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            else if (MyRender11.Settings.DisplayStencil)
            {
                context.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
                context.PixelShader.Set(m_stencilShader);
                MyScreenPass.DrawFullscreenQuad();
            }
            //DrawEnvProbe();
            //DrawAtmosphereTransmittance(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]);
            //DrawAtmosphereInscatter(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]);

            if (MyRender11.Settings.DrawCascadeTextures)
            {
                DrawCascades(MyRender11.DynamicShadows.ShadowCascades, 100, 100, 200);
                if (MyScene.SeparateGeometry)
                {
                    DrawCascades(MyRender11.StaticShadows.ShadowCascades, 100, 300, 200);
                    DrawCombinedCascades(100, 500, 200);
                }
            }

            if (MyRender11.Settings.DisplayIDs || MyRender11.Settings.DisplayAabbs)
            {
                DrawHierarchyDebug();
            }

            if (false)
            {
                var batch = MyLinesRenderer.CreateBatch();

                foreach (var light in MyLightRendering.VisiblePointlights)
                {
                    batch.AddSphereRing(new BoundingSphere(light.Position, 0.5f), Color.White, Matrix.Identity);
                }
                batch.Commit();
            }

            // draw terrain lods
            if (MyRender11.Settings.DebugRenderClipmapCells)
            {
                //var batch = MyLinesRenderer.CreateBatch();

                //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => (MyMeshes.IsVoxelMesh(x.Mesh))))
                //{
                //    if (renderable.IsVisible)
                //    {
                //        if (renderable.m_lod >= LOD_COLORS.Length)
                //            return;

                //        BoundingBox bb = new BoundingBox(renderable.m_owner.Aabb.Min - MyEnvironment.CameraPosition,renderable.m_owner.Aabb.Max - MyEnvironment.CameraPosition);

                //        batch.AddBoundingBox(bb, new Color(LOD_COLORS[renderable.m_voxelLod]));


                //        if (renderable.m_lods != null && renderable.m_voxelLod != renderable.m_lods[0].RenderableProxies[0].ObjectData.CustomAlpha)
                //        {

                //        }
                //    }
                //}

                //batch.Commit();

                MyClipmap.DebugDrawClipmaps();
            }

            if (MyRender11.Settings.EnableVoxelMerging && MyRender11.Settings.DebugRenderMergedCells)
            {
                MyClipmap.DebugDrawMergedCells();
            }

            //if(true)
            //{
            //    var batch = MyLinesRenderer.CreateBatch();

            //    foreach(var id in MyLights.DirtySpotlights)
            //    {
            //        var info = MyLights.Spotlights[id.Index];

            //        if(info.ApertureCos > 0)
            //        {
            //            var D = info.Direction * info.Range;
            //            //batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed);

            //            //var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range).Transform(Matrix.CreateLookAt(MyLights.Lights.Data[id.Index].Position, info.Direction, info.Up));


            //            //batch.AddBoundingBox(bb, Color.Green);

            //            batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed);

            //            var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range, MyLights.Lights.Data[id.Index].Position, info.Up);
            //            batch.AddBoundingBox(bb, Color.Green);
            //        }
            //    }



            //    batch.Commit();
            //}

            // draw lods
            if (false)
            {
                var batch = MyLinesRenderer.CreateBatch();

                //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => ((x.GetMesh() as MyVoxelMesh) == null)))
                //{

                //    if (renderable.CurrentLodNum >= LOD_COLORS.Length || renderable.m_lods.Length == 1)
                //        continue;

                //    batch.AddBoundingBox(renderable.m_owner.Aabb, new Color(LOD_COLORS[renderable.CurrentLodNum]));
                //}

                batch.Commit();
            }
        }
 internal LodLevel(MyClipmap parent, int lodIndex, Vector3I lodSize)
 {
     m_clipmap = parent;
     m_lodIndex = lodIndex;
     m_lodSizeMinusOne = lodSize - 1;
 }