Ejemplo n.º 1
0
        internal unsafe static void Init()
        {
            //m_spotlightShadowmapPool = new MyShadowmapArray(256, 256, 4, Format.R16_Typeless, Format.D16_UNorm, Format.R16_Float);
            //m_spotlightShadowmapPool.SetDebugName("spotlight shadowmaps pool");

            m_cascadesNum = 4;
            m_splitDepth  = new float[m_cascadesNum + 1];

            m_cascadeResolution = 1024;
            ResizeCascades();

            m_csmConstants = MyHwBuffers.CreateConstantsBuffer((sizeof(Matrix) + sizeof(Vector2)) * 8 + 2 * sizeof(Vector4));

            m_cascadesBoundingsVertices = MyHwBuffers.CreateVertexBuffer(8 * 4, sizeof(Vector3), BindFlags.VertexBuffer, ResourceUsage.Dynamic);
            InitIB();

            m_cornersCS = new Vector3[8] {
                new Vector3(-1, -1, 0),
                new Vector3(-1, 1, 0),
                new Vector3(1, 1, 0),
                new Vector3(1, -1, 0),

                new Vector3(-1, -1, 1),
                new Vector3(-1, 1, 1),
                new Vector3(1, 1, 1),
                new Vector3(1, -1, 1)
            };

            m_markVS      = MyShaders.CreateVs("shape.hlsl", "vs");
            m_markPS      = MyShaders.CreatePs("shape.hlsl", "ps_dummy");
            m_inputLayout = MyShaders.CreateIL(m_markVS.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3));
        }
 private unsafe void InitConstantBuffer()
 {
     if (m_inverseConstants == ConstantsBufferId.NULL)
     {
         m_inverseConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix));
     }
 }
Ejemplo n.º 3
0
 private unsafe void InitConstantBuffer()
 {
     if (m_inverseConstants == ConstantsBufferId.NULL)
     {
         m_inverseConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix), "MyShadowCascadesPostProcess");
     }
 }
Ejemplo n.º 4
0
 internal static void Destroy(ref ConstantsBufferId id)
 {
     if (id != ConstantsBufferId.NULL)
     {
         Destroy(id); id = ConstantsBufferId.NULL;
     }
 }
Ejemplo n.º 5
0
        internal unsafe static void Init()
        {
            m_cbCustomProjections = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix) * MAX_CUSTOM_PROJECTIONS_SIZE, "BilloardCustomProjections");

            m_vs          = MyShaders.CreateVs("Transparent/Billboards.hlsl");
            m_vsDepthOnly = MyShaders.CreateVs("Transparent/BillboardsDepthOnly.hlsl");
            m_ps          = MyShaders.CreatePs("Transparent/Billboards.hlsl");
            m_psDepthOnly = MyShaders.CreatePs("Transparent/BillboardsDepthOnly.hlsl");
            m_psOIT       = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("OIT", null) });
            m_vsLit       = MyShaders.CreateVs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLit       = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLitOIT    = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) });

            m_psAlphaCutout       = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null) });
            m_psAlphaCutoutAndLit = MyShaders.CreatePs("Transparent/Billboards.hlsl",
                                                       new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null) });
            m_psAlphaCutoutOIT = MyShaders.CreatePs("Transparent/Billboards.hlsl",
                                                    new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("OIT", null) });
            m_psAlphaCutoutAndLitOIT = MyShaders.CreatePs("Transparent/Billboards.hlsl",
                                                          new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) });

            m_psDebugUniformAccum    = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("DEBUG_UNIFORM_ACCUM", null) });
            m_psDebugUniformAccumOIT = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("DEBUG_UNIFORM_ACCUM", null), new ShaderMacro("OIT", null) });

            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            InitBillboardsIndexBuffer();

            m_VB = MyHwBuffers.CreateVertexBuffer(MAX_BILLBOARDS_SIZE * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyBillboardRenderer");

            var stride = sizeof(MyBillboardData);

            m_SB    = MyHwBuffers.CreateStructuredBuffer(MAX_BILLBOARDS_SIZE, stride, true, null, "MyBillboardRenderer");
            m_atlas = new MyTextureAtlas("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai");
        }
Ejemplo n.º 6
0
 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;
     }
 }
Ejemplo n.º 7
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");
        }
Ejemplo n.º 8
0
 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);
 }
Ejemplo n.º 9
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");
            }
        }
Ejemplo n.º 10
0
        internal unsafe static void Init()
        {
            FrameConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(MyFrameConstantsLayout));
            ProjectionConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix));
            ObjectConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix));
            FoliageConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix));
            MaterialFoliageTableConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Vector4) * 256);
            OutlineConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(OutlineConstantsLayout));
            AlphamaskViewsConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix) * 181);

            UpdateAlphamaskViewsConstants();
        }
Ejemplo n.º 11
0
        internal unsafe static void Init()
        {
            FrameConstants                = MyHwBuffers.CreateConstantsBuffer(sizeof(MyFrameConstantsLayout));
            ProjectionConstants           = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix));
            ObjectConstants               = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix));
            FoliageConstants              = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix));
            MaterialFoliageTableConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Vector4) * 256);
            OutlineConstants              = MyHwBuffers.CreateConstantsBuffer(sizeof(OutlineConstantsLayout));
            AlphamaskViewsConstants       = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix) * 181);

            UpdateAlphamaskViewsConstants();
        }
        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
        }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        internal static void Prefilter(RwTexId probe, RwTexId prefiltered)
        {
            RC.DeviceContext.ComputeShader.Set(m_prefilter);

            var  mipLevels = prefiltered.Description2d.MipLevels;
            var  side      = prefiltered.Description2d.Width;
            uint probeSide = (uint)probe.Description2d.Width;

            ConstantsBufferId constantBuffer = MyCommon.GetObjectCB(32);

            RC.CSSetCB(1, constantBuffer);

            RC.DeviceContext.ComputeShader.SetShaderResource(0, probe.ShaderView);
            RC.DeviceContext.ComputeShader.SetSamplers(0, MyRender11.StandardSamplers);

            for (int j = 0; j < 6; ++j)
            {
                int mipSide = side;
                for (int i = 0; i < mipLevels; ++i)
                {
                    uint  samplesNum     = i == 0 ? 1u : 64u;
                    uint  mipSideUint    = (uint)mipSide;
                    uint  ju             = (uint)j;
                    float mipLevelFactor = 1 - (i / (float)(mipLevels - 1));

                    var mapping = MyMapping.MapDiscard(constantBuffer);
                    mapping.WriteAndPosition(ref samplesNum);
                    mapping.WriteAndPosition(ref probeSide);
                    mapping.WriteAndPosition(ref mipSideUint);
                    mapping.WriteAndPosition(ref ju);
                    mapping.WriteAndPosition(ref mipLevelFactor);
                    mapping.Unmap();

                    ComputeShaderId.TmpUav[0] = prefiltered.SubresourceUav(j, i);
                    RC.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
                    RC.DeviceContext.Dispatch((mipSide + 7) / 8, (mipSide + 7) / 8, 1);

                    mipSide >>= 1;
                }
            }

            ComputeShaderId.TmpUav[0] = null;
            RC.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
            RC.DeviceContext.ComputeShader.SetShaderResource(0, null);

            RC.DeviceContext.ComputeShader.Set(null);
        }
Ejemplo n.º 16
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();
        }
        internal static void Prefilter(IUavArrayTexture probe, IUavArrayTexture prefiltered)
        {
            RC.ComputeShader.Set(m_prefilter);

            var  mipLevels = prefiltered.MipmapLevels;
            var  side      = prefiltered.Size.X;
            uint probeSide = (uint)probe.Size.X;

            ConstantsBufferId constantBuffer = MyCommon.GetObjectCB(32);

            RC.ComputeShader.SetConstantBuffer(1, constantBuffer);

            RC.ComputeShader.SetSrv(0, probe);
            RC.ComputeShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

            for (int j = 0; j < 6; ++j)
            {
                int mipSide = side;
                for (int i = 0; i < mipLevels; ++i)
                {
                    uint  samplesNum     = i == 0 ? 1u : 64u;
                    uint  mipSideUint    = (uint)mipSide;
                    uint  ju             = (uint)j;
                    float mipLevelFactor = 1 - (i / (float)(mipLevels - 1));

                    var mapping = MyMapping.MapDiscard(constantBuffer);
                    mapping.WriteAndPosition(ref samplesNum);
                    mapping.WriteAndPosition(ref probeSide);
                    mapping.WriteAndPosition(ref mipSideUint);
                    mapping.WriteAndPosition(ref ju);
                    mapping.WriteAndPosition(ref mipLevelFactor);
                    mapping.Unmap();

                    RC.ComputeShader.SetUav(0, prefiltered.SubresourceUav(j, i));
                    RC.Dispatch((mipSide + 7) / 8, (mipSide + 7) / 8, 1);

                    mipSide >>= 1;
                }
            }

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

            RC.ComputeShader.Set(null);
        }
Ejemplo n.º 18
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 unsafe void Init()
        {
            //MyRender11.RegisterSettingsChangedListener(new OnSettingsChangedDelegate(RecreateShadersForSettings));

			DirectionalEnvironmentLight_Pixel = MyShaders.CreatePs("light_dir.hlsl");
            DirectionalEnvironmentLight_Sample = MyShaders.CreatePs("light_dir.hlsl", MyRender11.ShaderSampleFrequencyDefine());

            PointlightsTiled_Pixel = MyShaders.CreatePs("light_point.hlsl");
            PointlightsTiled_Sample = MyShaders.CreatePs("light_point.hlsl", MyRender11.ShaderSampleFrequencyDefine());

            m_preparePointLights = MyShaders.CreateCs("prepare_lights.hlsl", new[] { new ShaderMacro("NUMTHREADS", TILE_SIZE) });

			SpotlightProxyVs = MyShaders.CreateVs("light_spot.hlsl");
            SpotlightPs_Pixel = MyShaders.CreatePs("light_spot.hlsl");
            SpotlightPs_Sample = MyShaders.CreatePs("light_spot.hlsl", MyRender11.ShaderSampleFrequencyDefine());
            SpotlightProxyIL = MyShaders.CreateIL(SpotlightProxyVs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION_PACKED));

            m_pointlightCullHwBuffer = MyHwBuffers.CreateStructuredBuffer(MyRender11Constants.MAX_POINT_LIGHTS, sizeof(MyPointlightConstants), true, null, "MyLightRendering");
            m_pointlightsConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(MyPointlightInfo) * MyRender11Constants.MAX_POINT_LIGHTS, "MyLightRendering pointLights");
            m_spotlightsConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(SpotlightConstants) * MyRender11Constants.MAX_SPOTLIGHTS, "MyLightRendering spotLights");
            m_sunlightConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(MySunlightConstantsLayout), "MyLightRendering sunLights");
        }
Ejemplo n.º 20
0
        internal static unsafe void Init()
        {
            //MyRender11.RegisterSettingsChangedListener(new OnSettingsChangedDelegate(RecreateShadersForSettings));

            DirectionalEnvironmentLight_Pixel  = MyShaders.CreatePs("light_dir.hlsl");
            DirectionalEnvironmentLight_Sample = MyShaders.CreatePs("light_dir.hlsl", MyRender11.ShaderSampleFrequencyDefine());

            PointlightsTiled_Pixel  = MyShaders.CreatePs("light_point.hlsl");
            PointlightsTiled_Sample = MyShaders.CreatePs("light_point.hlsl", MyRender11.ShaderSampleFrequencyDefine());

            m_preparePointLights = MyShaders.CreateCs("prepare_lights.hlsl", new[] { new ShaderMacro("NUMTHREADS", TILE_SIZE) });

            SpotlightProxyVs   = MyShaders.CreateVs("light_spot.hlsl");
            SpotlightPs_Pixel  = MyShaders.CreatePs("light_spot.hlsl");
            SpotlightPs_Sample = MyShaders.CreatePs("light_spot.hlsl", MyRender11.ShaderSampleFrequencyDefine());
            SpotlightProxyIL   = MyShaders.CreateIL(SpotlightProxyVs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION_PACKED));

            m_pointlightCullHwBuffer = MyHwBuffers.CreateStructuredBuffer(MyRender11Constants.MAX_POINT_LIGHTS, sizeof(MyPointlightConstants), true, null, "MyLightRendering");
            m_pointlightsConstants   = MyHwBuffers.CreateConstantsBuffer(sizeof(MyPointlightInfo) * MyRender11Constants.MAX_POINT_LIGHTS, "MyLightRendering pointLights");
            m_spotlightsConstants    = MyHwBuffers.CreateConstantsBuffer(sizeof(SpotlightConstants) * MyRender11Constants.MAX_SPOTLIGHTS, "MyLightRendering spotLights");
            m_sunlightConstants      = MyHwBuffers.CreateConstantsBuffer(sizeof(MySunlightConstantsLayout), "MyLightRendering sunLights");
        }
Ejemplo n.º 21
0
        internal static unsafe void Init()
        {
            //MyRender11.RegisterSettingsChangedListener(new OnSettingsChangedDelegate(RecreateShadersForSettings));

            DirectionalEnvironmentLight_Pixel  = MyShaders.CreatePs("light.hlsl", "directional_environment");
            DirectionalEnvironmentLight_Sample = MyShaders.CreatePs("light.hlsl", "directional_environment", MyShaderHelpers.FormatMacros(MyRender11.ShaderSampleFrequencyDefine()));

            PointlightsTiled_Pixel  = MyShaders.CreatePs("light.hlsl", "pointlights_tiled");
            PointlightsTiled_Sample = MyShaders.CreatePs("light.hlsl", "pointlights_tiled", MyShaderHelpers.FormatMacros(MyRender11.ShaderSampleFrequencyDefine()));

            m_preparePointLights = MyShaders.CreateCs("prepare_lights.hlsl", "prepare_lights", MyShaderHelpers.FormatMacros("NUMTHREADS " + TILE_SIZE));

            SpotlightProxyVs = MyShaders.CreateVs("light.hlsl", "spotlightVs");
            SpotlightPs      = MyShaders.CreatePs("light.hlsl", "spotlightFromProxy");
            SpotlightProxyIL = MyShaders.CreateIL(SpotlightProxyVs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION_PACKED));

            var stride = sizeof(MyPointlightConstants);

            m_pointlightCullHwBuffer = MyHwBuffers.CreateStructuredBuffer(MyRender11Constants.MAX_POINT_LIGHTS, stride, true);
            m_pointlightsConstants   = MyHwBuffers.CreateConstantsBuffer(sizeof(MyPointlightInfo) * MyRender11Constants.MAX_POINT_LIGHTS);
            m_spotlightsConstants    = MyHwBuffers.CreateConstantsBuffer(sizeof(MySpotlightConstants) * MyRender11Constants.MAX_SPOTLIGHTS);
            m_sunlightConstants      = MyHwBuffers.CreateConstantsBuffer(sizeof(MySunlightConstantsLayout));
        }
Ejemplo n.º 22
0
        internal unsafe static void Init()
        {
            ResetCascades();

            m_csmConstants = MyHwBuffers.CreateConstantsBuffer((sizeof(Matrix) + sizeof(Vector2)) * 8 + 2 * sizeof(Vector4));

            InitIB();

            m_cornersCS = new Vector3D[8] {
                new Vector3D(-1, -1, 0),
                new Vector3D(-1, 1, 0),
                new Vector3D(1, 1, 0),
                new Vector3D(1, -1, 0),

                new Vector3D(-1, -1, 1),
                new Vector3D(-1, 1, 1),
                new Vector3D(1, 1, 1),
                new Vector3D(1, -1, 1)
            };

            m_markVS      = MyShaders.CreateVs("shape.hlsl", "vs");
            m_markPS      = MyShaders.CreatePs("shape.hlsl", "ps_dummy");
            m_inputLayout = MyShaders.CreateIL(m_markVS.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3));
        }
Ejemplo n.º 23
0
        internal void GatherArray(RwTexId postprocessTarget, RwTexId cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer)
        {
            if (!MyRenderProxy.Settings.EnableShadows)
            {
                return;
            }

            MarkCascadesInStencil(cascadeInfo);

            MyGpuProfiler.IC_BeginBlock("Cascades postprocess");

            MyRenderContext renderContext = MyRenderContext.Immediate;
            DeviceContext   deviceContext = renderContext.DeviceContext;

            renderContext.SetCS(m_gatherCS);
            ComputeShaderId.TmpUav[0] = postprocessTarget.Uav;
            deviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);

            deviceContext.ComputeShader.SetShaderResource(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.m_SRV_depth : MyGBuffer.Main.DepthStencil.m_SRV_depth);
            deviceContext.ComputeShader.SetShaderResource(1, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            deviceContext.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MyRender11.m_shadowmapSamplerState);
            deviceContext.ComputeShader.SetConstantBuffer(0, MyCommon.FrameConstants);
            deviceContext.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer);
            deviceContext.ComputeShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, cascadeArray.ShaderView);

            deviceContext.Dispatch(m_threadGroupCountX, m_threadGroupCountY, 1);

            ComputeShaderId.TmpUav[0] = null;
            renderContext.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
            deviceContext.ComputeShader.SetShaderResource(0, null);

            if (MyRender11.Settings.EnableShadowBlur)
            {
                MyBlur.Run(postprocessTarget.Rtv, MyRender11.CascadesHelper.Rtv, MyRender11.CascadesHelper.ShaderView, postprocessTarget.ShaderView, depthDiscardThreshold: 0.2f);
            }

            MyGpuProfiler.IC_EndBlock();
        }
Ejemplo n.º 24
0
 internal static Buffer GetConstantsBuffer(ConstantsBufferId id)
 {
     return CBuffersData[id.Index].Buffer;
 }
Ejemplo n.º 25
0
        internal static ConstantsBufferId CreateConstantsBuffer(BufferDescription description, string debugName = null)
        {
            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;
        }
Ejemplo n.º 26
0
 internal static void Init()
 {
     m_objectConstants = MyHwBuffers.CreateConstantsBuffer(64);
 }
        internal void GatherArray(RwTexId postprocessTarget, RwTexId cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer)
        {
            if (!MyRenderProxy.Settings.EnableShadows)
                return;

            MarkCascadesInStencil(cascadeInfo);

            MyGpuProfiler.IC_BeginBlock("Cascades postprocess");

            MyRenderContext renderContext = MyRenderContext.Immediate;
            DeviceContext deviceContext = renderContext.DeviceContext;

            renderContext.SetCS(m_gatherCS);
            ComputeShaderId.TmpUav[0] = postprocessTarget.Uav;
            deviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);

            deviceContext.ComputeShader.SetShaderResource(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.m_SRV_depth : MyGBuffer.Main.DepthStencil.m_SRV_depth);
            deviceContext.ComputeShader.SetShaderResource(1, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            deviceContext.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MyRender11.m_shadowmapSamplerState);
            deviceContext.ComputeShader.SetConstantBuffer(0, MyCommon.FrameConstants);
            deviceContext.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer);
            deviceContext.ComputeShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, cascadeArray.ShaderView);

            deviceContext.Dispatch(m_threadGroupCountX, m_threadGroupCountY, 1);

            ComputeShaderId.TmpUav[0] = null;
            renderContext.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
            deviceContext.ComputeShader.SetShaderResource(0, null);

            if(MyRender11.Settings.EnableShadowBlur)
                MyBlur.Run(postprocessTarget.Rtv, MyRender11.CascadesHelper.Rtv, MyRender11.CascadesHelper.ShaderView, postprocessTarget.ShaderView, depthDiscardThreshold: 0.2f);

            MyGpuProfiler.IC_EndBlock();
        }
Ejemplo n.º 28
0
 internal static void Destroy(ref ConstantsBufferId id)
 {
     if (id != ConstantsBufferId.NULL)
     {
         Destroy(id); id = ConstantsBufferId.NULL;
     }
 }
Ejemplo n.º 29
0
        internal static unsafe void Init()
        {
            //MyRender11.RegisterSettingsChangedListener(new OnSettingsChangedDelegate(RecreateShadersForSettings));

            DirectionalEnvironmentLight_Pixel = MyShaders.CreatePs("light.hlsl", "directional_environment");
            DirectionalEnvironmentLight_Sample = MyShaders.CreatePs("light.hlsl", "directional_environment", MyShaderHelpers.FormatMacros(MyRender11.ShaderSampleFrequencyDefine()));

            PointlightsTiled_Pixel = MyShaders.CreatePs("light.hlsl", "pointlights_tiled");
            PointlightsTiled_Sample = MyShaders.CreatePs("light.hlsl", "pointlights_tiled", MyShaderHelpers.FormatMacros(MyRender11.ShaderSampleFrequencyDefine()));

            m_preparePointLights = MyShaders.CreateCs("prepare_lights.hlsl", "prepare_lights", MyShaderHelpers.FormatMacros("NUMTHREADS " + TILE_SIZE));

            SpotlightProxyVs = MyShaders.CreateVs("light.hlsl", "spotlightVs");
            SpotlightPs_Pixel = MyShaders.CreatePs("light.hlsl", "spotlightFromProxy");
            SpotlightPs_Sample = MyShaders.CreatePs("light.hlsl", "spotlightFromProxy", MyShaderHelpers.FormatMacros(MyRender11.ShaderSampleFrequencyDefine()));
            SpotlightProxyIL = MyShaders.CreateIL(SpotlightProxyVs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION_PACKED));

            var stride = sizeof(MyPointlightConstants);
            m_pointlightCullHwBuffer = MyHwBuffers.CreateStructuredBuffer(MyRender11Constants.MAX_POINT_LIGHTS, stride, true);
            m_pointlightsConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(MyPointlightInfo) * MyRender11Constants.MAX_POINT_LIGHTS);
            m_spotlightsConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(MySpotlightConstants) * MyRender11Constants.MAX_SPOTLIGHTS);
            m_sunlightConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(MySunlightConstantsLayout));
        }
Ejemplo n.º 30
0
 private void DestroyConstantBuffer()
 {
     m_csmConstants = ConstantsBufferId.NULL;
 }
Ejemplo n.º 31
0
 private unsafe void InitConstantBuffer()
 {
     DestroyConstantBuffer();
     m_csmConstants = MyHwBuffers.CreateConstantsBuffer((sizeof(Matrix) + 2 * sizeof(Vector4) + sizeof(Vector4)) * 8 + sizeof(Vector4), "MyShadowCascades");
 }
Ejemplo n.º 32
0
        internal unsafe static 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();
        }
Ejemplo n.º 33
0
 internal static void RecreateShadersForSettings()
 {
     m_psH = MyShaders.CreatePs("blur_planet_h.hlsl");
     m_psV = MyShaders.CreatePs("blur_planet_v.hlsl");
     m_cb  = MyCommon.GetObjectCB(16);
 }
Ejemplo n.º 34
0
 private void DestroyConstantBuffer()
 {
     m_csmConstants = ConstantsBufferId.NULL;
 }
Ejemplo n.º 35
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();
        }
 private unsafe static void Init()
 {
     m_ps = MyShaders.CreatePs("postprocess_colorize_exported_texture.hlsl");
     m_cb = MyHwBuffers.CreateConstantsBuffer(sizeof(Vector4), "ExportedTexturesColor");
     m_initialized = true;
 }
Ejemplo n.º 37
0
 private unsafe void InitConstantBuffer()
 {
     DestroyConstantBuffer();
     m_csmConstants = MyHwBuffers.CreateConstantsBuffer((sizeof(Matrix) + 2 * sizeof(Vector4) + sizeof(Vector4)) * 8 + sizeof(Vector4), "MyShadowCascades");
 }
        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");
#if DEBUG
            // 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_debugCounterBuffer = new MyReadStructuredBuffer(1, sizeof(uint), "MyGPUParticleRenderer::debugCounterBuffer");
#endif
            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
        }
 private unsafe void InitConstantBuffer()
 {
     if (m_inverseConstants == ConstantsBufferId.NULL)
         m_inverseConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix), "MyShadowCascadesPostProcess");
 }
Ejemplo n.º 40
0
 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);
 }
        internal void GatherArray(RwTexId postprocessTarget, RwTexId cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer)
        {
            if (!MyRenderProxy.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows)
                return;

            MarkCascadesInStencil(cascadeInfo);

            MyGpuProfiler.IC_BeginBlock("Cascades postprocess");

            MyRenderContext renderContext = MyRenderContext.Immediate;
            DeviceContext deviceContext = renderContext.DeviceContext;

            MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality();
            if (shadowsQuality == MyShadowsQuality.LOW)
                renderContext.SetCS(m_gatherCS_LD);
            else if (shadowsQuality == MyShadowsQuality.MEDIUM)
                renderContext.SetCS(m_gatherCS_MD);
            else if (shadowsQuality == MyShadowsQuality.HIGH)
                renderContext.SetCS(m_gatherCS_HD);

            ComputeShaderId.TmpUav[0] = postprocessTarget.Uav;
            deviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);

            deviceContext.ComputeShader.SetShaderResource(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.m_SRV_depth : MyGBuffer.Main.DepthStencil.m_SRV_depth);
            deviceContext.ComputeShader.SetShaderResource(1, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            deviceContext.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, SamplerStates.m_shadowmap);
            if (!MyStereoRender.Enable)
                deviceContext.ComputeShader.SetConstantBuffer(0, MyCommon.FrameConstants);
            else
                MyStereoRender.CSBindRawCB_FrameConstants(renderContext);
            deviceContext.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer);
            deviceContext.ComputeShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, cascadeArray.SRV);

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

            ComputeShaderId.TmpUav[0] = null;
            renderContext.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
            deviceContext.ComputeShader.SetShaderResource(0, null);
            deviceContext.ComputeShader.SetShaderResource(1, null);

            if (shadowsQuality == MyShadowsQuality.HIGH && MyRender11.Settings.EnableShadowBlur)
                MyBlur.Run(postprocessTarget.Rtv, MyRender11.CascadesHelper.Rtv, MyRender11.CascadesHelper.SRV, postprocessTarget.SRV, depthDiscardThreshold: 0.2f);

            MyGpuProfiler.IC_EndBlock();
        }
 private unsafe void InitConstantBuffer()
 {
     if(m_inverseConstants == ConstantsBufferId.NULL)
         m_inverseConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix));
 }
Ejemplo n.º 43
0
 internal static Buffer GetConstantsBuffer(ConstantsBufferId id)
 {
     return(CBuffersData[id.Index].Buffer);
 }
        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();
        }
Ejemplo n.º 45
0
 internal static void RecreateShadersForSettings()
 {
     m_psH = MyShaders.CreatePs("blur_planet_h.hlsl");
     m_psV = MyShaders.CreatePs("blur_planet_v.hlsl");
     m_cb = MyCommon.GetObjectCB(16);
 }
Ejemplo n.º 46
0
 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 unsafe static void Init()
        {
            m_cbCustomProjections = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix) * MAX_CUSTOM_PROJECTIONS_SIZE, "BilloardCustomProjections");

            m_vs = MyShaders.CreateVs("billboard.hlsl");
            m_vsDepthOnly = MyShaders.CreateVs("billboard_depth_only.hlsl"); 
            m_ps = MyShaders.CreatePs("billboard.hlsl");
            m_psDepthOnly = MyShaders.CreatePs("billboard_depth_only.hlsl"); 
            m_psOIT = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("OIT", null) });
            m_vsLit = MyShaders.CreateVs("billboard.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLit = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLitOIT = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) });

            m_psAlphaCutout = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null) });
            m_psAlphaCutoutAndLit = MyShaders.CreatePs("billboard.hlsl", 
                new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null) });
            m_psAlphaCutoutOIT = MyShaders.CreatePs("billboard.hlsl", 
                new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("OIT", null) });
            m_psAlphaCutoutAndLitOIT = MyShaders.CreatePs("billboard.hlsl", 
                new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) });

            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            InitBillboardsIndexBuffer();

            m_VB = MyHwBuffers.CreateVertexBuffer(MAX_BILLBOARDS_SIZE * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyBillboardRenderer");

            var stride = sizeof(MyBillboardData);
            m_SB = MyHwBuffers.CreateStructuredBuffer(MAX_BILLBOARDS_SIZE, stride, true, null, "MyBillboardRenderer");
            m_atlas = new MyTextureAtlas("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai");
        }
Ejemplo n.º 48
0
        internal unsafe static void Init()
        {
            //m_spotlightShadowmapPool = new MyShadowmapArray(256, 256, 4, Format.R16_Typeless, Format.D16_UNorm, Format.R16_Float);
            //m_spotlightShadowmapPool.SetDebugName("spotlight shadowmaps pool");

            m_cascadesNum = 4;
            m_splitDepth = new float[m_cascadesNum + 1];

            m_cascadeResolution = 1024;
            ResizeCascades();

            m_csmConstants = MyHwBuffers.CreateConstantsBuffer((sizeof(Matrix) + sizeof(Vector2)) * 8 + 2 * sizeof(Vector4) );

            m_cascadesBoundingsVertices = MyHwBuffers.CreateVertexBuffer(8 * 4, sizeof(Vector3), BindFlags.VertexBuffer, ResourceUsage.Dynamic);
            InitIB();

            m_cornersCS = new Vector3[8] {
                    new Vector3(-1, -1, 0),
                    new Vector3(-1, 1, 0),
                    new Vector3( 1, 1, 0),
                    new Vector3( 1, -1, 0),

                    new Vector3(-1, -1, 1),
                    new Vector3(-1, 1, 1),
                    new Vector3( 1, 1, 1),
                    new Vector3( 1, -1, 1)
                };

            m_markVS = MyShaders.CreateVs("shape.hlsl", "vs");
            m_markPS  = MyShaders.CreatePs("shape.hlsl", "ps_dummy");
            m_inputLayout = MyShaders.CreateIL(m_markVS.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3));
        }
Ejemplo n.º 49
0
        internal void GatherArray(RwTexId postprocessTarget, RwTexId cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer)
        {
            if (!MyRenderProxy.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows)
            {
                return;
            }

            MarkCascadesInStencil(cascadeInfo);

            MyGpuProfiler.IC_BeginBlock("Cascades postprocess");

            MyRenderContext renderContext = MyRenderContext.Immediate;
            DeviceContext   deviceContext = renderContext.DeviceContext;

            MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality();

            if (shadowsQuality == MyShadowsQuality.LOW)
            {
                renderContext.SetCS(m_gatherCS_LD);
            }
            else if (shadowsQuality == MyShadowsQuality.MEDIUM)
            {
                renderContext.SetCS(m_gatherCS_MD);
            }
            else if (shadowsQuality == MyShadowsQuality.HIGH)
            {
                renderContext.SetCS(m_gatherCS_HD);
            }

            ComputeShaderId.TmpUav[0] = postprocessTarget.Uav;
            deviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);

            deviceContext.ComputeShader.SetShaderResource(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.m_SRV_depth : MyGBuffer.Main.DepthStencil.m_SRV_depth);
            deviceContext.ComputeShader.SetShaderResource(1, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            deviceContext.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, SamplerStates.m_shadowmap);
            if (!MyStereoRender.Enable)
            {
                deviceContext.ComputeShader.SetConstantBuffer(0, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.CSBindRawCB_FrameConstants(renderContext);
            }
            deviceContext.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer);
            deviceContext.ComputeShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, cascadeArray.SRV);

            Vector2I threadGroups = GetThreadGroupCount();

            deviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            ComputeShaderId.TmpUav[0] = null;
            renderContext.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
            deviceContext.ComputeShader.SetShaderResource(0, null);
            deviceContext.ComputeShader.SetShaderResource(1, null);

            if (shadowsQuality == MyShadowsQuality.HIGH && MyRender11.Settings.EnableShadowBlur)
            {
                MyBlur.Run(postprocessTarget.Rtv, MyRender11.CascadesHelper.Rtv, MyRender11.CascadesHelper.SRV, postprocessTarget.SRV, depthDiscardThreshold: 0.2f);
            }

            MyGpuProfiler.IC_EndBlock();
        }