internal static void Render()
        {
            MyGpuProfiler.IC_BeginBlock("Map lights to tiles");
            MyLightRendering.PreparePointLights();
            MyGpuProfiler.IC_EndBlock();

            RC.Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.BindGBufferForRead(0, MyGBuffer.Main);
            RC.BindRawSRV(MyCommon.MATERIAL_BUFFER_SLOT, MySceneMaterials.m_buffer.Srv);
            RC.SetBS(MyRender11.BlendAdditive);

            MyGpuProfiler.IC_BeginBlock("Apply point lights");
            RenderPointlightsTiled();
            MyGpuProfiler.IC_EndBlock();


            MyGpuProfiler.IC_BeginBlock("Apply spotlights");
            RenderSpotlights();
            MyGpuProfiler.IC_EndBlock();

            DrawGlares();

            MyGpuProfiler.IC_BeginBlock("Apply directional light");
            RenderDirectionalEnvironmentLight();
            MyGpuProfiler.IC_EndBlock();
        }
Esempio n. 2
0
        internal static void Run(MyBindableResource dst, MyGBuffer gbuffer, MyBindableResource resolvedDepth)
        {
            RC.Context.ClearRenderTargetView((dst as IRenderTargetBindable).RTV, new SharpDX.Color4(1, 1, 1, 1));

            var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2));

            var mapping = MyMapping.MapDiscard(paramsCB);

            mapping.stream.Write(Params.MinRadius);
            mapping.stream.Write(Params.MaxRadius);
            mapping.stream.Write(Params.RadiusGrow);
            mapping.stream.Write(Params.Falloff);
            mapping.stream.Write(Params.RadiusBias);
            mapping.stream.Write(Params.Contrast);
            mapping.stream.Write(Params.Normalization);
            mapping.stream.Write(0);
            FillRandomVectors(mapping.stream);
            mapping.Unmap();

            RC.SetCB(0, MyCommon.FrameConstants);
            RC.SetCB(1, paramsCB);

            RC.SetPS(m_ps);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst);

            RC.BindGBufferForRead(0, gbuffer);
            RC.BindSRV(5, resolvedDepth);

            DrawFullscreenQuad();
        }
Esempio n. 3
0
        internal static void Run(MyBindableResource dst, MyGBuffer gbuffer, MyBindableResource resolvedDepth)
        {
            RC.DeviceContext.ClearRenderTargetView((dst as IRenderTargetBindable).RTV, new SharpDX.Color4(1, 1, 1, 1));

            var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2));

            var mapping = MyMapping.MapDiscard(paramsCB);

            mapping.WriteAndPosition(ref Params);
            FillRandomVectors(mapping);
            mapping.Unmap();

            if (!MyStereoRender.Enable)
            {
                RC.SetCB(0, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.BindRawCB_FrameConstants(RC);
            }
            RC.SetCB(1, paramsCB);

            RC.SetPS(m_ps);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst);

            RC.BindGBufferForRead(0, gbuffer);
            RC.BindSRV(5, resolvedDepth);

            DrawFullscreenQuad();
        }
Esempio n. 4
0
        internal static void PreparePointLights()
        {
            var activePointlights = 0;

            MyLights.Update();
            MyLights.PointlightsBvh.OverlapAllFrustum(ref MyEnvironment.ViewFrustumClippedD, VisiblePointlights);

            bool visiblePointlights = VisiblePointlights.Count != 0;

            if (!visiblePointlights && !m_lastFrameVisiblePointlights)
            {
                return;
            }

            m_lastFrameVisiblePointlights = visiblePointlights;

            if (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
            {
                VisiblePointlights.Sort((x, y) => x.ViewerDistanceSquared.CompareTo(y.ViewerDistanceSquared));

                while (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
                {
                    VisiblePointlights.RemoveAtFast(VisiblePointlights.Count - 1);
                }
            }

            foreach (var light in VisiblePointlights)
            {
                MyLights.WritePointlightConstants(light, ref m_pointlightsCullBuffer[activePointlights]);

                activePointlights++;
                Debug.Assert(activePointlights <= MyRender11Constants.MAX_POINT_LIGHTS);
            }
            for (int lightIndex = activePointlights; lightIndex < MyRender11Constants.MAX_POINT_LIGHTS; ++lightIndex)
            {
                MyLights.WritePointlightConstants(LightId.NULL, ref m_pointlightsCullBuffer[lightIndex]);
            }

            var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

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

            mapping = MyMapping.MapDiscard(m_pointlightCullHwBuffer.Buffer);
            mapping.WriteAndPosition(m_pointlightsCullBuffer, 0, MyRender11Constants.MAX_POINT_LIGHTS);
            mapping.Unmap();

            RC.CSSetCB(0, MyCommon.FrameConstants);
            RC.CSSetCB(1, MyCommon.GetObjectCB(16));

            //RC.BindUAV(0, MyScreenDependants.m_test);
            RC.BindUAV(0, MyScreenDependants.m_tileIndices);
            RC.BindGBufferForRead(0, MyGBuffer.Main);
            RC.CSBindRawSRV(MyCommon.POINTLIGHT_SLOT, m_pointlightCullHwBuffer.Srv);
            RC.SetCS(m_preparePointLights);

            RC.DeviceContext.Dispatch(MyScreenDependants.TilesX, MyScreenDependants.TilesY, 1);
            RC.SetCS(null);
        }
        internal static void PreparePointLights()
        {
            var activePointlights = 0;

            MyLights.Update();
            MyLights.PointlightsBvh.OverlapAllFrustum(ref MyEnvironment.ViewFrustumClippedD, VisiblePointlights);

            if (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
            {
                VisiblePointlights.Sort((x, y) => x.ViewerDistanceSquared.CompareTo(y.ViewerDistanceSquared));

                while (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
                {
                    VisiblePointlights.RemoveAtFast(VisiblePointlights.Count - 1);
                }
            }

            foreach (var light in VisiblePointlights)
            {
                MyLights.WritePointlightConstants(light, ref m_pointlightsCullBuffer[activePointlights]);

                activePointlights++;
                Debug.Assert(activePointlights <= MyRender11Constants.MAX_POINT_LIGHTS);
            }

            var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

            mapping.stream.Write(activePointlights);
            mapping.stream.Write(0f);
            mapping.stream.Write(0f);
            mapping.stream.Write(0f);
            mapping.Unmap();

            mapping = MyMapping.MapDiscard(m_pointlightCullHwBuffer.Buffer);
            for (int i = 0; i < activePointlights; i++)
            {
                mapping.stream.Write(m_pointlightsCullBuffer[i]);
            }
            for (int i = activePointlights; i < MyRender11Constants.MAX_POINT_LIGHTS; i++)
            {
                mapping.stream.Write(new MyPointlightConstants());
            }
            mapping.Unmap();

            RC.CSSetCB(0, MyCommon.FrameConstants);
            RC.CSSetCB(1, MyCommon.GetObjectCB(16));

            //RC.BindUAV(0, MyScreenDependants.m_test);
            RC.BindUAV(0, MyScreenDependants.m_tileIndexes);
            RC.BindGBufferForRead(0, MyGBuffer.Main);
            RC.CSBindRawSRV(MyCommon.POINTLIGHT_SLOT, m_pointlightCullHwBuffer.Srv);
            RC.SetCS(m_preparePointLights);

            var size = MyRender11.ViewportResolution;

            RC.Context.Dispatch((size.X + TILE_SIZE - 1) / TILE_SIZE, (size.Y + TILE_SIZE - 1) / TILE_SIZE, 1);
            RC.SetCS(null);
        }
Esempio n. 6
0
        internal static void Run(MyBindableResource dst1, MyBindableResource dst2, MyBindableResource lightBuffer, MyGBuffer gbuffer)
        {
            if (!Settings.BlurEnabled || Settings.BlurAmount < 0.01f)
            {
                return;
            }

            RC.DeviceContext.ClearRenderTargetView((dst1 as IRenderTargetBindable).RTV, new SharpDX.Color4(0, 0, 0, 0));
            RC.DeviceContext.ClearRenderTargetView((dst2 as IRenderTargetBindable).RTV, new SharpDX.Color4(0, 0, 0, 0));

            float zero    = 0f;
            var   mapping = MyMapping.MapDiscard(m_cb);

            mapping.WriteAndPosition(ref Settings.BlurAmount);
            mapping.WriteAndPosition(ref Settings.BlurDistance);
            mapping.WriteAndPosition(ref Settings.BlurTransitionRatio);
            mapping.WriteAndPosition(ref zero);
            mapping.Unmap();

            RC.SetCB(0, MyCommon.FrameConstants);
            RC.SetCB(1, m_cb);


            RC.SetPS(m_psH);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst1);
            RC.BindGBufferForRead(0, gbuffer);
            RC.BindSRV(5, lightBuffer);
            DrawFullscreenQuad();


            RC.SetPS(m_psV);
            RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst2);
            RC.BindSRV(5, dst1);

            DrawFullscreenQuad();

//          MyBlendTargets.Run(lightBuffer, MyScreenDependants.m_planetBlur2, MyRender11.BlendPlanetBlur);
//          MyBlendTargets.Run(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer), MyScreenDependants.m_planetBlur2, MyRender11.BlendPlanetBlur);
        }
Esempio n. 7
0
        internal static void Render()
        {
            MyGpuProfiler.IC_BeginBlock("Map lights to tiles");
            if (MyRender11.DebugOverrides.PointLights)
            {
                PreparePointLights();
            }
            MyGpuProfiler.IC_EndBlock();

            RC.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.BindGBufferForRead(0, MyGBuffer.Main);
            RC.BindRawSRV(MyCommon.MATERIAL_BUFFER_SLOT, MySceneMaterials.m_buffer.Srv);
            RC.SetBS(MyRender11.BlendAdditive);
            RC.SetDS(MyDepthStencilState.IgnoreDepthStencil);
            RC.DeviceContext.PixelShader.SetSamplers(0, MyRender11.StandardSamplers);

            MyGpuProfiler.IC_BeginBlock("Apply point lights");
            if (MyRender11.DebugOverrides.PointLights)
            {
                RenderPointlightsTiled();
            }
            MyGpuProfiler.IC_EndBlock();

            MyGpuProfiler.IC_BeginBlock("Apply spotlights");
            if (MyRender11.DebugOverrides.SpotLights)
            {
                RenderSpotlights();
            }
            MyGpuProfiler.IC_EndBlock();

            DrawGlares();

            MyGpuProfiler.IC_BeginBlock("Apply directional light");
            RenderDirectionalEnvironmentLight();
            MyGpuProfiler.IC_EndBlock();
        }
Esempio n. 8
0
        internal static void DrawSkybox(MyBindableResource destination)
        {
            var context = MyRender.Context;

            context.OutputMerger.BlendState = null;
            context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);

            context.PixelShader.SetSamplers(0, MyRender.StandardSamplers);

            context.VertexShader.Set(FullscreenShader.VertexShader);
            context.PixelShader.Set(SkyboxShader.PixelShader);

            //context.OutputMerger.SetTargets(null as DepthStencilView, target);
            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, destination);
            RC.BindGBufferForRead(0, MyGBuffer.Main);

            //context.PixelShader.SetShaderResources(0, MyRender.MainGbuffer.DepthGbufferViews);
            context.PixelShader.SetShaderResource(MyCommon.SKYBOX_SLOT,
                                                  MyTextureManager.GetTexture(MyEnvironment.SkyboxTexture).ShaderView);

            context.Draw(3, 0);

            context.PixelShader.SetShaderResource(0, null);
        }
        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 static void RenderColoredTextures(List <renderColoredTextureProperties> texturesToRender)
        {
            if (texturesToRender.Count == 0)
            {
                return;
            }

            if (!m_initialized)
            {
                Init();
            }

            const int RENDER_TEXTURE_RESOLUTION = 512;

            RC.DeviceContext.OutputMerger.BlendState = null;
            RC.SetIL(null);

            RC.SetPS(m_ps);
            RC.SetCB(0, MyCommon.FrameConstants);
            RC.SetCB(1, m_cb);

            Dictionary <Vector2I, MyRenderTarget> createdRenderTextureTargets = new Dictionary <Vector2I, MyRenderTarget>();

            foreach (var texture in texturesToRender)
            {
                TexId texId = MyTextures.GetTexture(texture.TextureName, MyTextureEnum.COLOR_METAL, true);
                if (texId == TexId.NULL)
                {
                    continue;
                }

                Vector2  texSize = MyTextures.GetSize(texId);
                Vector2I renderTargetResolution = new Vector2I(RENDER_TEXTURE_RESOLUTION, RENDER_TEXTURE_RESOLUTION);
                if (texSize.Y > 0)
                {
                    if (texSize.Y < RENDER_TEXTURE_RESOLUTION)
                    {
                        renderTargetResolution.X = (int)texSize.X;
                        renderTargetResolution.Y = (int)texSize.Y;
                    }
                    else
                    {
                        renderTargetResolution.X *= (int)(texSize.X / texSize.Y);
                    }
                }

                MyViewport viewport = new MyViewport(renderTargetResolution.X, renderTargetResolution.Y);

                MyRenderTarget renderTexture = null;
                if (!createdRenderTextureTargets.TryGetValue(renderTargetResolution, out renderTexture))
                {
                    renderTexture = new MyRenderTarget(renderTargetResolution.X, renderTargetResolution.Y, SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, 1, 0);
                    createdRenderTextureTargets[renderTargetResolution] = renderTexture;
                }

                RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, renderTexture);

                // Set color
                var     mapping = MyMapping.MapDiscard(m_cb);
                Vector4 color   = new Vector4(texture.ColorMaskHSV, 1);
                mapping.WriteAndPosition(ref color);
                mapping.Unmap();

                // Set texture
                RC.DeviceContext.PixelShader.SetShaderResource(0, MyTextures.GetView(texId));

                // Draw
                MyScreenPass.DrawFullscreenQuad(viewport);

                // Save to file
                MyTextureData.ToFile(renderTexture.GetHWResource(), texture.PathToSave, ImageFileFormat.Png);
            }

            texturesToRender.Clear();

            foreach (var texture in createdRenderTextureTargets)
            {
                texture.Value.Release();
            }
            createdRenderTextureTargets.Clear();

            RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, null);
            RC.BindGBufferForRead(0, MyGBuffer.Main);
        }
Esempio n. 11
0
        internal static void Render()
        {
            MyLights.Update();

            MyGpuProfiler.IC_BeginBlock("Map lights to tiles");
            if (MyRender11.DebugOverrides.PointLights)
            {
                PreparePointLights();
            }
            MyGpuProfiler.IC_EndBlock();

            RC.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            if (!MyStereoRender.Enable)
            {
                RC.CSSetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.CSBindRawCB_FrameConstants(RC);
            }

            RC.BindGBufferForRead(0, MyGBuffer.Main);
            RC.BindRawSRV(MyCommon.MATERIAL_BUFFER_SLOT, MySceneMaterials.m_buffer);
            RC.SetBS(MyRender11.BlendAdditive);
            if (!MyStereoRender.Enable)
            {
                RC.SetDS(MyDepthStencilState.IgnoreDepthStencil);
            }
            else
            {
                RC.SetDS(MyDepthStencilState.StereoIgnoreDepthStencil);
            }
            RC.DeviceContext.PixelShader.SetSamplers(0, SamplerStates.StandardSamplers);

            MyGpuProfiler.IC_BeginBlock("Apply point lights");
            if (MyRender11.DebugOverrides.PointLights)
            {
                RenderPointlightsTiled();
            }
            MyGpuProfiler.IC_EndBlock();

            MyGpuProfiler.IC_BeginBlock("Apply spotlights");
            if (MyRender11.DebugOverrides.SpotLights)
            {
                RenderSpotlights();
            }
            MyGpuProfiler.IC_EndBlock();

            MyGpuProfiler.IC_BeginBlock("Apply directional light");
            if (MyRender11.DebugOverrides.EnvLight)
            {
                RenderDirectionalEnvironmentLight();
            }
            MyGpuProfiler.IC_EndBlock();

            // Because of BindGBufferForRead:
            RC.BindRawSRV(0, null);
            RC.BindRawSRV(1, null);
            RC.BindRawSRV(2, null);
            RC.BindRawSRV(3, null);
            RC.BindRawSRV(4, null);
            RC.CSBindRawSRV(0, null);
            RC.CSBindRawSRV(1, null);
            RC.CSBindRawSRV(2, null);
            RC.CSBindRawSRV(3, null);
            RC.CSBindRawSRV(4, null);
            RC.SetBS(null);
        }
Esempio n. 12
0
        internal static void PreparePointLights()
        {
            var activePointlights = 0;

            MyLights.Update();
            BoundingFrustumD viewFrustumClippedD = MyRender11.Environment.ViewFrustumClippedD;

            if (MyStereoRender.Enable)
            {
                if (MyStereoRender.RenderRegion == MyStereoRegion.LEFT)
                {
                    viewFrustumClippedD = MyStereoRender.EnvMatricesLeftEye.ViewFrustumClippedD;
                }
                else if (MyStereoRender.RenderRegion == MyStereoRegion.RIGHT)
                {
                    viewFrustumClippedD = MyStereoRender.EnvMatricesRightEye.ViewFrustumClippedD;
                }
            }
            MyLights.PointlightsBvh.OverlapAllFrustum(ref viewFrustumClippedD, VisiblePointlights);

            bool visiblePointlights = VisiblePointlights.Count != 0;

            if (!visiblePointlights && !m_lastFrameVisiblePointlights)
            {
                return;
            }

            m_lastFrameVisiblePointlights = visiblePointlights;

            if (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
            {
                VisiblePointlights.Sort((x, y) => x.ViewerDistanceSquared.CompareTo(y.ViewerDistanceSquared));

                while (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
                {
                    VisiblePointlights.RemoveAtFast(VisiblePointlights.Count - 1);
                }
            }

            foreach (var light in VisiblePointlights)
            {
                MyLights.WritePointlightConstants(light, ref m_pointlightsCullBuffer[activePointlights]);

                activePointlights++;
                Debug.Assert(activePointlights <= MyRender11Constants.MAX_POINT_LIGHTS);
            }
            for (int lightIndex = activePointlights; lightIndex < MyRender11Constants.MAX_POINT_LIGHTS; ++lightIndex)
            {
                MyLights.WritePointlightConstants(LightId.NULL, ref m_pointlightsCullBuffer[lightIndex]);
            }

            var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

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

            mapping = MyMapping.MapDiscard(m_pointlightCullHwBuffer.Buffer);
            mapping.WriteAndPosition(m_pointlightsCullBuffer, 0, MyRender11Constants.MAX_POINT_LIGHTS);
            mapping.Unmap();

            if (!MyStereoRender.Enable)
            {
                RC.CSSetCB(0, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.CSBindRawCB_FrameConstants(RC);
            }
            RC.CSSetCB(1, MyCommon.GetObjectCB(16));

            //RC.BindUAV(0, MyScreenDependants.m_test);
            RC.BindUAV(0, MyScreenDependants.m_tileIndices);
            RC.BindGBufferForRead(0, MyGBuffer.Main);
            RC.CSBindRawSRV(MyCommon.POINTLIGHT_SLOT, m_pointlightCullHwBuffer);
            RC.SetCS(m_preparePointLights);
            Vector2I tiles = new Vector2I(MyScreenDependants.TilesX, MyScreenDependants.TilesY);

            if (MyStereoRender.Enable && MyStereoRender.RenderRegion != MyStereoRegion.FULLSCREEN)
            {
                tiles.X /= 2;
            }

            RC.DeviceContext.Dispatch(tiles.X, tiles.Y, 1);
            RC.SetCS(null);
        }