예제 #1
0
        internal static void Run(MyBindableResource dst, MyBindableResource src, MyBindableResource avgLum, MyBindableResource bloom, bool enableTonemapping = true)
        {
            //Debug.Assert(src.GetSize() == dst.GetSize());

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

            mapping.stream.Write(MyRender11.Settings.MiddleGrey);
            mapping.stream.Write(MyRender11.Settings.LuminanceExposure);
            mapping.stream.Write(MyRender11.Settings.BloomExposure);
            mapping.stream.Write(MyRender11.Settings.BloomMult);
            mapping.Unmap();

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

            RC.BindUAV(0, dst);
            RC.BindSRV(0, src, avgLum, bloom);

            RC.Context.ComputeShader.SetSampler(0, MyRender11.m_defaultSamplerState);

            if (enableTonemapping)
            {
                RC.SetCS(m_cs);
            }
            else
            {
                RC.SetCS(m_csSkip);
            }

            var size = dst.GetSize();

            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);
            RC.SetCS(null);
        }
예제 #2
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);
        }
예제 #3
0
        private static void ResetInternal()
        {
            InitDeadList();

            RC.BindUAV(0, m_particleBuffer);
            RC.SetCS(m_csResetParticles);
            RC.DeviceContext.Dispatch(align(MyGPUEmitters.MAX_PARTICLES, 256) / 256, 1, 1);
        }
예제 #4
0
        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);
        }
예제 #5
0
        internal static MyBindableResource Run(MyBindableResource src, MyBindableResource avgLum)
        {
            RC.CSSetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

            RC.BindUAV(0, MyRender11.HalfScreenUavHDR);
            RC.BindSRVs(0, src, avgLum);

            RC.SetCS(m_bloomShader);

            var size = MyRender11.HalfScreenUavHDR.GetSize();

            VRageMath.Vector2I threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.SetCS(m_downscaleShader);

            size         = MyRender11.QuarterScreenUavHDR.GetSize();
            threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.BindUAV(0, MyRender11.QuarterScreenUavHDR);
            RC.BindSRV(0, MyRender11.HalfScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            size         = MyRender11.EighthScreenUavHDR.GetSize();
            threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.QuarterScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.SetCS(m_blurV);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDRHelper);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDR);
            RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.SetCS(m_blurH);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDRHelper);

            int nPasses = 1;

            if (MyStereoRender.Enable)
            {
                threadGroups.X /= 2;
                nPasses         = 2;
            }
            for (int nPass = 0; nPass < nPasses; nPass++)
            {
                MyStereoRegion region = MyStereoRegion.FULLSCREEN;
                if (MyStereoRender.Enable)
                {
                    region = nPass == 0 ? MyStereoRegion.LEFT : MyStereoRegion.RIGHT;
                }
                RC.CSSetCB(1, GetCB_blurH(region, size));
                RC.DeviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);
            }

            return(MyRender11.EighthScreenUavHDR);
        }
예제 #6
0
        internal static void Run(MyBindableResource dst, MyBindableResource src, MyBindableResource stencil)
        {
            RC.BindUAV(0, dst);
            RC.BindSRV(0, src, stencil);

            RC.SetCS(m_cs);

            var size = dst.GetSize();

            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);
            RC.SetCS(null);
        }
예제 #7
0
        // Init the dead list so that all the particles in the system are marked as dead, ready to be spawned.
        private static void InitDeadList()
        {
            RC.SetCS(m_csInitDeadList);

            RC.BindUAV(0, m_deadListBuffer, 0);

            // Disaptch a set of 1d thread groups to fill out the dead list, one thread per particle
            RC.DeviceContext.Dispatch(align(MyGPUEmitters.MAX_PARTICLES, 256) / 256, 1, 1);

#if DEBUG
            m_numDeadParticlesOnInit = ReadCounter(m_deadListBuffer);
#endif
        }
예제 #8
0
        // Per-frame emission of particles into the GPU simulation
        private static void Emit(int emitterCount, MyGPUEmitterData[] emitterData)
        {
            // update emitter data
            var mapping = MyMapping.MapDiscard(m_emitterStructuredBuffer.Buffer);
            int maxParticlesToEmitThisFrame = 0;

            for (int i = 0; i < emitterCount; i++)
            {
                mapping.WriteAndPosition(ref emitterData[i]);

                if (emitterData[i].NumParticlesToEmitThisFrame > maxParticlesToEmitThisFrame)
                {
                    maxParticlesToEmitThisFrame = emitterData[i].NumParticlesToEmitThisFrame;
                }
            }
            mapping.Unmap();

            int numThreadGroupsX = align(maxParticlesToEmitThisFrame, MAX_PARTICLE_EMIT_THREADS) / MAX_PARTICLE_EMIT_THREADS;
            int numThreadGroupsY = align(emitterCount, MAX_EMITTERS) / MAX_EMITTERS;

            // update emitter count
            mapping = MyMapping.MapDiscard(m_emitterConstantBuffer);
            mapping.WriteAndPosition(ref emitterCount);
            mapping.WriteAndPosition(ref numThreadGroupsX);
            mapping.Unmap();

            if (maxParticlesToEmitThisFrame > 0)
            {
                // Set resources but don't reset any atomic counters
                RC.BindUAV(0, m_particleBuffer);
                RC.BindUAV(1, m_deadListBuffer);
                RC.BindUAV(2, m_skippedParticleCountBuffer, 0);

                RC.CSSetCB(1, m_emitterConstantBuffer);

                RC.CSBindRawSRV(0, Resources.MyTextures.RandomTexId);
                RC.CSBindRawSRV(1, m_emitterStructuredBuffer);

                RC.SetCS(m_csEmit);
                RC.DeviceContext.Dispatch(numThreadGroupsX, numThreadGroupsY, 1);
                RC.CSSetCB(1, null);

                RC.SetCS(m_csEmitSkipFix);
                // Disaptch a set of 1d thread groups to fill out the dead list, one thread per particle
                RC.DeviceContext.Dispatch(1, 1, 1);
            }

#if DEBUG
            //m_numDeadParticlesAfterEmit = ReadCounter(m_deadListBuffer);
#endif
        }
예제 #9
0
        internal static MyBindableResource Run(MyBindableResource src, MyBindableResource avgLum)
        {
            var buffer  = MyCommon.GetObjectCB(16);
            var mapping = MyMapping.MapDiscard(buffer);

            mapping.WriteAndPosition(ref MyRender11.Settings.MiddleGrey);
            mapping.WriteAndPosition(ref MyRender11.Settings.LuminanceExposure);
            mapping.WriteAndPosition(ref MyRender11.Settings.BloomExposure);
            mapping.WriteAndPosition(ref MyRender11.Settings.BloomMult);
            mapping.Unmap();

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

            RC.BindUAV(0, MyRender11.HalfScreenUavHDR);
            RC.BindSRVs(0, src, avgLum);

            RC.SetCS(m_bloomShader);

            var size = MyRender11.HalfScreenUavHDR.GetSize();

            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_downscaleShader);

            size = MyRender11.QuarterScreenUavHDR.GetSize();
            RC.BindUAV(0, MyRender11.QuarterScreenUavHDR);
            RC.BindSRV(0, MyRender11.HalfScreenUavHDR);
            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            size = MyRender11.EighthScreenUavHDR.GetSize();
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.QuarterScreenUavHDR);
            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_blurH);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDRHelper);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDR);
            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_blurV);
            RC.BindUAV(0, MyRender11.EighthScreenUavHDR);
            RC.BindSRV(0, MyRender11.EighthScreenUavHDRHelper);
            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            return(MyRender11.EighthScreenUavHDR);
        }
예제 #10
0
        internal static MyBindableResource Run(MyBindableResource src, MyBindableResource avgLum)
        {
            var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

            mapping.stream.Write(MyRender11.Settings.MiddleGrey);
            mapping.stream.Write(MyRender11.Settings.LuminanceExposure);
            mapping.stream.Write(MyRender11.Settings.BloomExposure);
            mapping.stream.Write(MyRender11.Settings.BloomMult);
            mapping.Unmap();

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

            RC.BindUAV(0, MyRender11.m_div2);
            RC.BindSRV(0, src, avgLum);

            RC.SetCS(m_bloomShader);

            var size = MyRender11.m_div2.GetSize();

            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_downscaleShader);

            size = MyRender11.m_div4.GetSize();
            RC.BindUAV(0, MyRender11.m_div4);
            RC.BindSRV(0, MyRender11.m_div2);
            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            size = MyRender11.m_div8.GetSize();
            RC.BindUAV(0, MyRender11.m_div8);
            RC.BindSRV(0, MyRender11.m_div4);
            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_blurH);
            RC.BindUAV(0, MyRender11.m_div8_1);
            RC.BindSRV(0, MyRender11.m_div8);
            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_blurV);
            RC.BindUAV(0, MyRender11.m_div8);
            RC.BindSRV(0, MyRender11.m_div8_1);
            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            return(MyRender11.m_div8);
        }
예제 #11
0
        // Per-frame simulation step
        private static void Simulate(MyBindableResource depthRead)
        {
            RC.BindUAV(0, m_particleBuffer);
            RC.BindUAV(1, m_deadListBuffer);
            RC.BindUAV(2, m_aliveIndexBuffer, 0);
            RC.BindUAV(3, m_indirectDrawArgsBuffer);

            RC.BindSRV(0, depthRead);
            RC.CSBindRawSRV(1, m_emitterStructuredBuffer);

            RC.SetCS(m_csSimulate);

            RC.DeviceContext.Dispatch(align(MyGPUEmitters.MAX_PARTICLES, 256) / 256, 1, 1);

            RC.DeviceContext.ComputeShader.SetUnorderedAccessView(0, null, -1);
            RC.DeviceContext.ComputeShader.SetUnorderedAccessView(1, null, -1);
            RC.DeviceContext.ComputeShader.SetUnorderedAccessView(2, null, -1);
            RC.DeviceContext.ComputeShader.SetUnorderedAccessView(3, null, -1);
        }
예제 #12
0
        internal static void Run(MyBindableResource dst, MyBindableResource src, MyBindableResource avgLum, MyBindableResource bloom, bool enableTonemapping = true)
        {
            //Debug.Assert(src.GetSize() == dst.GetSize());

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

            mapping.WriteAndPosition(ref MyRender11.Settings.MiddleGrey);
            mapping.WriteAndPosition(ref MyRender11.Settings.LuminanceExposure);
            mapping.WriteAndPosition(ref MyRender11.Settings.BloomExposure);
            mapping.WriteAndPosition(ref MyRender11.Settings.BloomMult);
            mapping.Unmap();

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

            RC.BindUAV(0, dst);
            RC.BindSRVs(0, src, avgLum, bloom);

            RC.DeviceContext.ComputeShader.SetSampler(0, SamplerStates.m_default);

            if (enableTonemapping)
            {
                RC.SetCS(m_cs);
            }
            else
            {
                RC.SetCS(m_csSkip);
            }

            var size = dst.GetSize();

            RC.DeviceContext.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            ComputeShaderId.TmpUav[0] = null;
            RC.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
            RC.SetCS(null);
        }
예제 #13
0
        internal static MyBindableResource Run(MyBindableResource uav0, MyBindableResource uav1, MyBindableResource src,
                                               MyBindableResource prevLum, MyBindableResource localAvgLum)
        {
            var size      = src.GetSize();
            var texelsNum = size.X * size.Y;
            var mapping   = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

            mapping.stream.Write((uint)size.X);
            mapping.stream.Write((uint)size.Y);
            mapping.stream.Write(texelsNum);
            mapping.stream.Write(MyRender11.Postprocess.EnableEyeAdaptation ? -1.0f : MyRender11.Postprocess.ConstantLuminance);

            mapping.Unmap();

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

            RC.BindUAV(0, uav0);
            RC.BindSRV(0, src);
            RC.SetCS(m_initialShader);

            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(m_sumShader);
            int i = 0;

            while (true)
            {
                size.X = (size.X + m_numthreads - 1) / m_numthreads;
                size.Y = (size.Y + m_numthreads - 1) / m_numthreads;

                if (size.X <= 8 && size.Y <= 8)
                {
                    break;
                }

                //mapping = MyMapping.MapDiscard(MyCommon.GetObjectBuffer(16).Buffer);
                //mapping.stream.Write(new Vector2I(size.X, size.Y));
                //mapping.Unmap();

                RC.BindUAV(0, (i % 2 == 0) ? uav1 : uav0);
                RC.BindSRV(0, (i % 2 == 0) ? uav0 : uav1);

                RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

                //might not be exactly correct if we skip this
                var dirty = (i % 2 == 0) ? uav0 : uav1;
                RC.Context.ClearUnorderedAccessView((dirty as IUnorderedAccessBindable).UAV, new SharpDX.Int4(0, 0, 0, 0));

                i++;
            }

            RC.SetCS(m_finalShader);

            //mapping = MyMapping.MapDiscard(MyCommon.GetObjectBuffer(16).Buffer);
            //mapping.stream.Write(new Vector2I(size.X, size.Y));
            //mapping.stream.Write(texelsNum);
            //mapping.Unmap();

            RC.BindUAV(0, (i % 2 == 0) ? uav1 : uav0);
            RC.BindSRV(0, (i % 2 == 0) ? uav0 : uav1, prevLum);

            RC.Context.Dispatch((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads, 1);

            RC.SetCS(null);

            var output = (i % 2 == 0) ? uav1 : uav0;

            RC.Context.CopySubresourceRegion(output.m_resource, 0, new ResourceRegion(0, 0, 0, 1, 1, 1), prevLum.m_resource, 0);

            return(output);
        }
예제 #14
0
        internal static MyBindableResource Run(MyBindableResource uav0, MyBindableResource uav1, MyBindableResource src,
                                               MyBindableResource prevLum)
        {
            Vector3I size             = src.GetSize();
            int      texelsNum        = size.X * size.Y;
            uint     sizeX            = (uint)size.X;
            uint     sizeY            = (uint)size.Y;
            float    adaptationFactor = MyRender11.Postprocess.EnableEyeAdaptation ? -1.0f : MyRender11.Postprocess.ConstantLuminance;
            var      buffer           = MyCommon.GetObjectCB(16);
            var      mapping          = MyMapping.MapDiscard(buffer);

            mapping.WriteAndPosition(ref sizeX);
            mapping.WriteAndPosition(ref sizeY);
            mapping.WriteAndPosition(ref texelsNum);
            mapping.WriteAndPosition(ref adaptationFactor);
            mapping.Unmap();

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

            RC.SetCS(m_initialShader);

            MyBindableResource output = uav0;
            MyBindableResource input  = src;

            RC.BindUAV(0, output);
            RC.BindSRV(0, input);

            int threadGroupCountX = ComputeGroupCount(size.X);
            int threadGroupCountY = ComputeGroupCount(size.Y);

            RC.DeviceContext.Dispatch(threadGroupCountX, threadGroupCountY, 1);

            RC.SetCS(m_sumShader);

            int i = 0;

            while (true)
            {
                size.X = threadGroupCountX;
                size.Y = threadGroupCountY;

                if (size.X <= NUM_THREADS && size.Y <= NUM_THREADS)
                {
                    break;
                }

                output = (i % 2 == 0) ? uav1 : uav0;
                input  = (i % 2 == 0) ? uav0 : uav1;
                RC.BindUAV(0, output);
                RC.BindSRV(0, input);

                threadGroupCountX = ComputeGroupCount(size.X);
                threadGroupCountY = ComputeGroupCount(size.Y);
                RC.DeviceContext.Dispatch(threadGroupCountX, threadGroupCountY, 1);

                i++;
            }

            RC.SetCS(m_finalShader);

            output = (i % 2 == 0) ? uav1 : uav0;
            input  = (i % 2 == 0) ? uav0 : uav1;
            RC.BindUAV(0, output);
            RC.BindSRVs(0, input, prevLum);

            threadGroupCountX = ComputeGroupCount(size.X);
            threadGroupCountY = ComputeGroupCount(size.Y);
            RC.DeviceContext.Dispatch(threadGroupCountX, threadGroupCountY, 1);

            RC.SetCS(null);

            // Backup the result for later process
            RC.DeviceContext.CopySubresourceRegion(output.m_resource, 0, new ResourceRegion(0, 0, 0, 1, 1, 1), prevLum.m_resource, 0);

            return(output);
        }
예제 #15
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);
        }