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); }
internal static void PreparePointLights() { var activePointlights = 0; MyLights.Update(); BoundingFrustumD viewFrustumClippedD = MyRender11.Environment.Matrices.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.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(RC); } RC.ComputeShader.SetConstantBuffer(1, MyCommon.GetObjectCB(16)); //RC.BindUAV(0, MyScreenDependants.m_test); RC.ComputeShader.SetRawUav(0, MyScreenDependants.m_tileIndices.m_uav); RC.ComputeShader.SetSrvs(0, MyGBuffer.Main); RC.ComputeShader.SetRawSrv(MyCommon.POINTLIGHT_SLOT, m_pointlightCullHwBuffer.Srv); RC.ComputeShader.Set(m_preparePointLights); Vector2I tiles = new Vector2I(MyScreenDependants.TilesX, MyScreenDependants.TilesY); if (MyStereoRender.Enable && MyStereoRender.RenderRegion != MyStereoRegion.FULLSCREEN) { tiles.X /= 2; } RC.Dispatch(tiles.X, tiles.Y, 1); RC.ComputeShader.Set(null); RC.ComputeShader.SetRawUav(0, null); RC.ComputeShader.ResetSrvs(0, MyGBufferSrvFilter.ALL); }