Пример #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));
     }
 }
Пример #3
0
 private unsafe void InitConstantBuffer()
 {
     if (m_inverseConstants == ConstantsBufferId.NULL)
     {
         m_inverseConstants = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix), "MyShadowCascadesPostProcess");
     }
 }
Пример #4
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");
        }
Пример #5
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);
 }
Пример #6
0
 internal static ConstantsBufferId GetObjectCB(int size)
 {
     // align size
     size = ((size + 15) / 16) * 16;
     if (!m_objectsConstantBuffers.ContainsKey(size))
     {
         m_objectsConstantBuffers[size] = MyHwBuffers.CreateConstantsBuffer(size);
     }
     return(m_objectsConstantBuffers[size]);
 }
Пример #7
0
 internal static ConstantsBufferId GetMaterialCB(int size)
 {
     // align size
     size = ((size + 15) / 16) * 16;
     if (!m_materialsConstantBuffers.ContainsKey(size))
     {
         m_materialsConstantBuffers[size] = MyHwBuffers.CreateConstantsBuffer(size, "CommonMaterialCB" + size);
     }
     return(m_materialsConstantBuffers[size]);
 }
Пример #8
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");
            }
        }
Пример #9
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
        }
Пример #11
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();
        }
Пример #12
0
        public static void InitializeConstantBuffer(int?randomSeed = null)
        {
            MyRandom random;

            if (randomSeed.HasValue)
            {
                random = new MyRandom(randomSeed.Value);
            }
            else
            {
                random = new MyRandom();
            }

            const int JITTERSIZE = 4 * 4;
            var       jitters    = new Vector4[JITTERSIZE];

            for (int i = 0; i < JITTERSIZE; i++)
            {
                float angle = 2.0f * (float)Math.PI * random.NextFloat() / NUM_DIRECTIONS;
                jitters[i].X = (float)Math.Cos(angle);
                jitters[i].Y = (float)Math.Sin(angle);
                jitters[i].Z = random.NextFloat();
                jitters[i].W = random.NextFloat();
            }
            PerPassConstantBuffer data;

            for (uint sliceIndex = 0; sliceIndex < NUM_SLICES; ++sliceIndex)
            {
                data.Offset.X        = (float)(sliceIndex % 4) + 0.5f;
                data.Offset.Y        = (float)(sliceIndex / 4) + 0.5f;
                data.Jitter          = jitters[sliceIndex];
                data.SliceIndexFloat = (float)sliceIndex;
                data.SliceIndexInt   = sliceIndex;

                var buffer = m_perPassCBs[sliceIndex];
                if (buffer == ConstantsBufferId.NULL)
                {
                    buffer = MyHwBuffers.CreateConstantsBuffer(PERPASSCONSTANTBUFFERSIZE, "MyHBAO::passCB " + sliceIndex);
                    m_perPassCBs[sliceIndex] = buffer;
                }

                var mapping = MyMapping.MapDiscard(buffer);
                mapping.WriteAndPosition(ref data);
                mapping.Unmap();
            }
        }
Пример #13
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();
        }
Пример #14
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");
        }
Пример #15
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));
        }
Пример #16
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));
        }
Пример #17
0
 internal static void Init()
 {
     m_objectConstants = MyHwBuffers.CreateConstantsBuffer(64);
 }
Пример #18
0
 private unsafe void InitConstantBuffer()
 {
     DestroyConstantBuffer();
     m_csmConstants = MyHwBuffers.CreateConstantsBuffer((sizeof(Matrix) + 2 * sizeof(Vector4) + sizeof(Vector4)) * 8 + sizeof(Vector4), "MyShadowCascades");
 }