unsafe ConstantsBufferId GetShadowConstants(ICascadeShadowMap csm, ref MyShadowsSettings settings)
        {
            const int MAX_SLICES_COUNT = 8;

            MyRenderProxy.Assert(csm.SlicesCount <= MAX_SLICES_COUNT, "It is not supported more than 8 slices per cascade shadow map");
            int size             = sizeof(Matrix) * MAX_SLICES_COUNT + sizeof(Vector4) * MAX_SLICES_COUNT;
            ConstantsBufferId cb = MyCommon.GetObjectCB(size);
            var mapping          = MyMapping.MapDiscard(cb);

            for (int i = 0; i < csm.SlicesCount; i++)
            {
                // Set matrices:
                Matrix matrix = csm.GetSlice(i).MatrixWorldAt0ToShadowSpace;
                matrix = matrix * Matrix.CreateTranslation(1, -1, 0);

                Vector2 scalingFactor = new Vector2(0.5f, -0.5f);
                matrix = matrix * Matrix.CreateScale(scalingFactor.X, scalingFactor.Y, 1);
                matrix = Matrix.Transpose(matrix);
                mapping.WriteAndPosition(ref matrix);

                // Set normal offsets:
                mapping.WriteAndPosition(ref settings.Cascades[i].ShadowNormalOffset);
                float zero = 0;
                for (int j = 1; j < 4; j++)
                {
                    mapping.WriteAndPosition(ref zero);
                }
            }

            mapping.Unmap();
            return(cb);
        }
Esempio n. 2
0
        unsafe void IManagerDevice.OnDeviceInit()
        {
            if (m_markerConstantBuffer == ConstantsBufferId.NULL)
            {
                m_markerConstantBuffer = MyHwBuffers.CreateConstantsBuffer(sizeof(MyMarkerConstants), "MyPostprocessMarkCascades.MarkerConstantBuffer");
            }

            if (m_psMarker == PixelShaderId.NULL)
            {
                m_psMarker = MyShaders.CreatePs("Shadows\\StencilMarker.hlsl");
            }
            if (m_vsMarker == VertexShaderId.NULL)
            {
                m_vsMarker = MyShaders.CreateVs("Shadows\\StencilMarker.hlsl");
            }
            if (m_psDrawCoverage == PixelShaderId.NULL)
            {
                m_psDrawCoverage = MyShaders.CreatePs("Shadows\\CascadeCoverage.hlsl");
            }
            if (m_inputLayout == InputLayoutId.NULL)
            {
                m_inputLayout = MyShaders.CreateIL(m_vsMarker.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3));
            }

            m_vertexBuffer = CreateVertexBuffer();
            m_indexBuffer  = CreateIndexBuffer();
        }
Esempio n. 3
0
        internal static unsafe void Init()
        {
            int typeCount = Enum.GetValues(typeof(MyBlurDensityFunctionType)).Length;
            m_blurShaders = new Dictionary<int, MyTuple<PixelShaderId, PixelShaderId>>();

            if (m_blurConstantBuffer == ConstantsBufferId.NULL)
                m_blurConstantBuffer = MyHwBuffers.CreateConstantsBuffer(sizeof(BlurConstants), "MyBlur");
        }
        unsafe void IManagerDevice.OnDeviceInit()
        {
            if (m_markerConstantBuffer == ConstantsBufferId.NULL)
                m_markerConstantBuffer = MyHwBuffers.CreateConstantsBuffer(sizeof(MyMarkerConstants), "MyPostprocessMarkCascades.MarkerConstantBuffer");

            if (m_psMarker == PixelShaderId.NULL)
                m_psMarker = MyShaders.CreatePs("Shadows\\StencilMarker.hlsl");
            if (m_vsMarker == VertexShaderId.NULL)
                m_vsMarker = MyShaders.CreateVs("Shadows\\StencilMarker.hlsl");
            if (m_psDrawCoverage == PixelShaderId.NULL)
                m_psDrawCoverage = MyShaders.CreatePs("Shadows\\CascadeCoverage.hlsl");
            if (m_inputLayout == InputLayoutId.NULL)
                m_inputLayout = MyShaders.CreateIL(m_vsMarker.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3));

            m_vertexBuffer = CreateVertexBuffer();
            m_indexBuffer = CreateIndexBuffer();
        }
        private static void InitDevice()
        {
            m_particleBuffer = new MyRWStructuredBuffer(MyGPUEmitters.MAX_PARTICLES, PARTICLE_STRIDE, MyRWStructuredBuffer.UavType.Default, true, "MyGPUParticleRenderer::particleBuffer");
            m_deadListBuffer = new MyRWStructuredBuffer(MyGPUEmitters.MAX_PARTICLES, sizeof(uint), MyRWStructuredBuffer.UavType.Append, false, "MyGPUParticleRenderer::deadListBuffer");
            m_skippedParticleCountBuffer = new MyRWStructuredBuffer(1, sizeof(uint), MyRWStructuredBuffer.UavType.Counter, true, "MyGPUParticleRenderer::skippedParticleCountBuffer");
 
            // Create a staging buffer that is used to read GPU atomic counter into that can then be mapped for reading 
            // back to the CPU for debugging purposes
            m_debugCounterBuffers[0] = new MyReadStructuredBuffer(1, sizeof(uint), "MyGPUParticleRenderer::debugCounterBuffers[0]");
            m_debugCounterBuffers[1] = new MyReadStructuredBuffer(1, sizeof(uint), "MyGPUParticleRenderer::debugCounterBuffers[1]");

            var description = new SharpDX.Direct3D11.BufferDescription(4 * sizeof(uint),
                SharpDX.Direct3D11.ResourceUsage.Default, SharpDX.Direct3D11.BindFlags.ConstantBuffer, SharpDX.Direct3D11.CpuAccessFlags.None, 
                SharpDX.Direct3D11.ResourceOptionFlags.None, sizeof(uint));
            m_activeListConstantBuffer = MyHwBuffers.CreateConstantsBuffer(description, "MyGPUParticleRenderer::activeListConstantBuffer");

            m_emitterConstantBuffer = MyHwBuffers.CreateConstantsBuffer(EMITTERCONSTANTBUFFER_SIZE, "MyGPUParticleRenderer::emitterConstantBuffer");
            m_emitterStructuredBuffer = MyHwBuffers.CreateStructuredBuffer(MyGPUEmitters.MAX_LIVE_EMITTERS, EMITTERDATA_SIZE, true, null,
                "MyGPUParticleRenderer::emitterStructuredBuffer");

            m_aliveIndexBuffer = new MyRWStructuredBuffer(MyGPUEmitters.MAX_PARTICLES, sizeof(float), MyRWStructuredBuffer.UavType.Counter, true,
                "MyGPUParticleRenderer::aliveIndexBuffer");

            m_indirectDrawArgsBuffer = new MyIndirectArgsBuffer(5, sizeof(uint), "MyGPUParticleRenderer::indirectDrawArgsBuffer");

            unsafe
            {
                uint[] indices = new uint[MyGPUEmitters.MAX_PARTICLES * 6];
                for (uint i = 0, index = 0, vertex = 0; i < MyGPUEmitters.MAX_PARTICLES; i++)
                {
                    indices[index + 0] = vertex + 0;
                    indices[index + 1] = vertex + 1;
                    indices[index + 2] = vertex + 2;

                    indices[index + 3] = vertex + 2;
                    indices[index + 4] = vertex + 1;
                    indices[index + 5] = vertex + 3;

                    vertex += 4;
                    index += 6;
                }
                fixed (uint* ptr = indices)
                {
                    m_ib = MyHwBuffers.CreateIndexBuffer(MyGPUEmitters.MAX_PARTICLES * 6, SharpDX.DXGI.Format.R32_UInt,
                        SharpDX.Direct3D11.BindFlags.IndexBuffer, SharpDX.Direct3D11.ResourceUsage.Immutable, new IntPtr(ptr), "MyGPUParticleRenderer::indexBuffer");
                }
            }

            //MyRender11.BlendAlphaPremult
        }
Esempio n. 6
0
        internal static void Init()
        {
            m_linearizeDepthPS = MyShaders.CreatePs("Postprocess/HBAO/LinearizeDepth.hlsl");
            m_deinterleaveDepthPS = MyShaders.CreatePs("Postprocess/HBAO/DeinterleaveDepth.hlsl");
            m_reinterleaveAOPS = MyShaders.CreatePs("Postprocess/HBAO/ReinterleaveAO.hlsl");
            m_reinterleaveAOPS_PreBlur = MyShaders.CreatePs("Postprocess/HBAO/ReinterleaveAO.hlsl", 
                new SharpDX.Direct3D.ShaderMacro[] { new SharpDX.Direct3D.ShaderMacro("ENABLE_BLUR", 1) });
            m_copyPS = MyShaders.CreatePs("Postprocess/HBAO/Copy.hlsl");

            m_dataCB = MyHwBuffers.CreateConstantsBuffer(GLOBALCONSTANTBUFFERSIZE, "MyHBAO::dataCB");

            for (int it = 0; it < NUM_SLICES; it++)
                m_perPassCBs[it] = ConstantsBufferId.NULL;

            InitializeConstantBuffer();
        }
 internal static Buffer GetConstantsBuffer(ConstantsBufferId id)
 {
     return CBuffersData[id.Index].Buffer;
 }
 internal static void InitConstantsBuffer(ConstantsBufferId id)
 {
     CBuffersData[id.Index].Buffer = new Buffer(MyRender11.Device, CBuffers.Data[id.Index].Description);
     if (CBuffers.Data[id.Index].DebugName != null)
     {
         CBuffersData[id.Index].Buffer.DebugName = CBuffers.Data[id.Index].DebugName;
     }
 }
 internal static void Destroy(ref ConstantsBufferId id)
 {
     if (id != ConstantsBufferId.NULL)
     {
         Destroy(id); id = ConstantsBufferId.NULL;
     }
 }
 internal static void Destroy(ConstantsBufferId id)
 {
     CbIndices.Remove(id);
     if (CBuffersData[id.Index].Buffer != null)
     {
         CBuffersData[id.Index].Buffer.Dispose();
         CBuffersData[id.Index].Buffer = null;
     }
     CBuffers.Free(id.Index);
 }
 private unsafe static void Init()
 {
     m_ps = MyShaders.CreatePs("Postprocess/PostprocessColorizeExportedEexture.hlsl");
     m_cb = MyHwBuffers.CreateConstantsBuffer(sizeof(Vector4), "ExportedTexturesColor");
     m_initialized = true;
 }
 private unsafe void InitConstantBuffer()
 {
     if (m_inverseConstants == ConstantsBufferId.NULL)
         m_inverseConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix), "MyShadowCascadesPostProcess");
 }
 private unsafe static void Init()
 {
     m_ps          = MyShaders.CreatePs("postprocess_colorize_exported_texture.hlsl");
     m_cb          = MyHwBuffers.CreateConstantsBuffer(sizeof(Vector4), "ExportedTexturesColor");
     m_initialized = true;
 }
Esempio n. 14
0
        internal static unsafe void Init()
        {
            FrameConstantsStereoLeftEye = MyHwBuffers.CreateConstantsBuffer(sizeof(MyFrameConstantsLayout), "FrameConstantsStereoLeftEye");
            FrameConstantsStereoRightEye = MyHwBuffers.CreateConstantsBuffer(sizeof(MyFrameConstantsLayout), "FrameConstantsStereoRightEye");

            FrameConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(MyFrameConstantsLayout), "FrameConstants");
            ProjectionConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix), "ProjectionConstants");
            ObjectConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix), "ObjectConstants");
            FoliageConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Vector4), "FoliageConstants");
            MaterialFoliageTableConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Vector4) * 256, "MaterialFoliageTableConstants");
            OutlineConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(OutlineConstantsLayout), "OutlineConstants");
            AlphamaskViewsConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix) * 181, "AlphamaskViewsConstants");

            UpdateAlphamaskViewsConstants();
        }
Esempio n. 15
0
        internal void FillConstantBuffer(ConstantsBufferId constantBuffer)
        {
            var mapping = MyMapping.MapDiscard(constantBuffer);
            for (int cascadeIndex = 0; cascadeIndex < m_initializedShadowCascadesCount; ++cascadeIndex)
            {
                var matrix = Matrix.Transpose(m_cascadeInfo[cascadeIndex].CurrentLocalToProjection * MyMatrixHelpers.ClipspaceToTexture);
                mapping.WriteAndPosition(ref matrix);
            }
            for (int cascadeIndex = m_initializedShadowCascadesCount; cascadeIndex < MaxShadowCascades; ++cascadeIndex)
                mapping.WriteAndPosition(ref Matrix.Zero);

            mapping.WriteAndPosition(ShadowCascadeSplitDepths, 0, ShadowCascadeSplitDepths.Length);

            float zero = 0;
            for (int splitIndex = ShadowCascadeSplitDepths.Length; splitIndex < MaxShadowCascades; ++splitIndex)
                mapping.WriteAndPosition(ref zero);

            for (int scaleIndex = 0; scaleIndex < ShadowCascadeScales.Length; ++scaleIndex)
            {
                Vector4 cascadeScale = ShadowCascadeScales[scaleIndex] / ShadowCascadeScales[0];
                mapping.WriteAndPosition(ref cascadeScale);
            }

            for (int scaleIndex = ShadowCascadeScales.Length; scaleIndex < MaxShadowCascades; ++scaleIndex)
                mapping.WriteAndPosition(ref Vector4.Zero);

            float resolution = MyRender11.RenderSettings.ShadowQuality.ShadowCascadeResolution();
            mapping.WriteAndPosition(ref resolution);

            for (int paddingIndex = 1; paddingIndex < 4; ++paddingIndex)
                mapping.WriteAndPosition(ref zero);

            mapping.Unmap();
        }
Esempio n. 16
0
 private void DestroyConstantBuffer()
 {
     m_csmConstants = ConstantsBufferId.NULL;
 }
Esempio n. 17
0
 private unsafe void InitConstantBuffer()
 {
     DestroyConstantBuffer();
     m_csmConstants = MyHwBuffers.CreateConstantsBuffer((sizeof(Matrix) + 2 * sizeof(Vector4) + sizeof(Vector4)) * 8 + sizeof(Vector4), "MyShadowCascades");
 }
        internal static ConstantsBufferId CreateConstantsBuffer(BufferDescription description, string debugName)
        {
            var id = new ConstantsBufferId { Index = CBuffers.Allocate() };
            MyArrayHelpers.Reserve(ref CBuffersData, id.Index + 1);
            CBuffers.Data[id.Index] = new MyHwBufferDesc { Description = description, DebugName = debugName };

            CbIndices.Add(id);
            InitConstantsBuffer(id);

            return id;
        }
        internal void GatherArray(IUavTexture postprocessTarget, ISrvBindable cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer)
        {
            MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality();
            if (!MyRender11.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows || shadowsQuality == MyShadowsQuality.DISABLED)
            {
                RC.ClearUav(postprocessTarget, new RawInt4());
                return;
            }

            MarkCascadesInStencil(cascadeInfo);

            MyGpuProfiler.IC_BeginBlock("Cascades postprocess");

            if (shadowsQuality == MyShadowsQuality.LOW)
                RC.ComputeShader.Set(m_gatherCS_LD);
            else if (shadowsQuality == MyShadowsQuality.MEDIUM)
                RC.ComputeShader.Set(m_gatherCS_MD);
            else if (shadowsQuality == MyShadowsQuality.HIGH)
                RC.ComputeShader.Set(m_gatherCS_HD);

            RC.ComputeShader.SetUav(0, postprocessTarget);

            RC.ComputeShader.SetSrv(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth);
            RC.ComputeShader.SetSrv(1, MyGBuffer.Main.DepthStencil.SrvStencil);
            RC.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MySamplerStateManager.Shadowmap);
            if (!MyStereoRender.Enable)
                RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            else
                MyStereoRender.CSBindRawCB_FrameConstants(RC);
            //RC.ComputeShader.SetConstantBuffer(4, MyManagers.Shadows.GetCsmConstantBufferOldOne());
            RC.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer);
            RC.ComputeShader.SetSrv(MyCommon.CASCADES_SM_SLOT, cascadeArray);
            //RC.ComputeShader.SetSrv(MyCommon.CASCADES_SM_SLOT, MyManagers.Shadow.GetCsmForGbuffer());

            Vector2I threadGroups = GetThreadGroupCount();
            RC.Dispatch(threadGroups.X, threadGroups.Y, 1);

            RC.ComputeShader.SetUav(0, null);
            RC.ComputeShader.SetSrv(0, null);
            RC.ComputeShader.SetSrv(1, null);

            if (shadowsQuality == MyShadowsQuality.HIGH && MyShadowCascades.Settings.Data.EnableShadowBlur)
            {
                IBorrowedUavTexture helper = MyManagers.RwTexturesPool.BorrowUav("MyShadowCascadesPostProcess.Helper", Format.R8_UNorm);
                MyBlur.Run(postprocessTarget, helper, postprocessTarget,
                    depthStencilState: MyDepthStencilStateManager.IgnoreDepthStencil,
                    depthDiscardThreshold: 0.2f, clearColor: Color4.White);
                helper.Release();
            }

            MyGpuProfiler.IC_EndBlock();
        }