コード例 #1
0
        public void Resize(IConstantBuffer buffer, int newElements, int newByteStride = -1, IntPtr?newData = null)
        {
            MyRenderProxy.Assert(newElements > 0);
            MyRenderProxy.Assert(newByteStride > 0 || newByteStride == -1);

            ResizeInternal(buffer as MyConstantBuffer, newElements, newByteStride, newData);
        }
コード例 #2
0
        internal unsafe static void Init()
        {
            m_cbCustomProjections = MyManagers.Buffers.CreateConstantBuffer("BilloardCustomProjections", sizeof(Matrix) * MAX_CUSTOM_PROJECTIONS_SIZE, usage: ResourceUsage.Dynamic);

            m_vs       = MyShaders.CreateVs("Transparent/Billboards.hlsl");
            m_ps       = MyShaders.CreatePs("Transparent/Billboards.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 = MyManagers.Buffers.CreateVertexBuffer("MyBillboardRenderer", MAX_BILLBOARDS_SIZE * 4, sizeof(MyVertexFormatPositionTextureH), usage: ResourceUsage.Dynamic);

            var stride = sizeof(MyBillboardData);

            m_SB = MyManagers.Buffers.CreateSrv(
                "MyBillboardRenderer", MAX_BILLBOARDS_SIZE, stride,
                usage: ResourceUsage.Dynamic);
            m_atlas = new MyTextureAtlas("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai");
        }
コード例 #3
0
 internal void Clear()
 {
     WorldMatrix           = MatrixD.Zero;
     CommonObjectData      = default(MyObjectDataCommon);
     NonVoxelObjectData    = MyObjectDataNonVoxel.Invalid;
     VoxelCommonObjectData = MyObjectDataVoxelCommon.Invalid;
     Mesh             = LodMeshId.NULL;
     MergedMesh       = MyMergedLodMeshId.NULL;
     Instancing       = InstancingId.NULL;
     DepthShaders     = MyMaterialShadersBundleId.NULL;
     Shaders          = MyMaterialShadersBundleId.NULL;
     ForwardShaders   = MyMaterialShadersBundleId.NULL;
     DrawSubmesh      = default(MyDrawSubmesh);
     PerMaterialIndex = 0;
     SectionSubmeshes = null;
     InstanceCount    = 0;
     StartInstance    = 0;
     SkinningMatrices = null;
     Type             = MyMaterialType.OPAQUE;
     Flags            = 0;
     Lod             = 0;
     ObjectBuffer    = null;
     Parent          = null;
     Material        = MyMeshMaterialId.NULL;
     UnusedMaterials = UnusedMaterials ?? new HashSet <string>();
     UnusedMaterials.Clear();
 }
コード例 #4
0
        unsafe IConstantBuffer 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;
            IConstantBuffer 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);
        }
コード例 #5
0
        public bool Render(SceneRenderer renderer, SceneNode root)
        {
            if (this.Geometry != null && renderer.ActiveShaderProgram != null)
            {
                if (renderer.ActiveCamera != null && this.Geometry.IsCreated(renderer) && !renderer.ActiveCamera.IsInViewFrustum(this, root))
                {
                    // geometry is not in the view frustum of the camera
                    return(false);
                }

                // upload model matrix
                IConstantBuffer trans = this.GetWorldTransformBuffer(root);
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ModelTransformation", trans.GetBuffer(renderer));

                if (renderer.ActiveCamera != null)
                {
                    // upload model-view and normal matrix
                    trans = this.GetModelViewTransformBuffer(root, renderer.ActiveCamera);
                    renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ModelViewTransformation", trans.GetBuffer(renderer));
                }

                // render the geometry
                this.Geometry.Render(renderer);

                return(true);
            }

            return(false);
        }
コード例 #6
0
ファイル: MyShaderStages.cs プロジェクト: viktorius/Viktor
 internal void SetConstantBuffer(int slot, IConstantBuffer constantBuffer)
 {
     m_vertexStage.SetConstantBuffer(slot, constantBuffer);
     m_geometryStage.SetConstantBuffer(slot, constantBuffer);
     m_pixelStage.SetConstantBuffer(slot, constantBuffer);
     m_computeStage.SetConstantBuffer(slot, constantBuffer);
 }
コード例 #7
0
 private unsafe void InitConstantBuffer()
 {
     if (m_inverseConstants == null)
     {
         m_inverseConstants = MyManagers.Buffers.CreateConstantBuffer("MyShadowCascadesPostProcess", sizeof(Matrix), usage: ResourceUsage.Dynamic);
     }
 }
コード例 #8
0
        unsafe void IManagerDevice.OnDeviceInit()
        {
            if (m_markerConstantBuffer == null)
            {
                m_markerConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyPostprocessMarkCascades.MarkerConstantBuffer", sizeof(MyMarkerConstants), usage: ResourceUsage.Dynamic);
            }

            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();
        }
コード例 #9
0
ファイル: MyRenderPass.cs プロジェクト: viktorius/Viktor
        // the method returns the same constant buffer as the parameter
        protected void FillConstantBuffer <T>(MyRenderContext RC, IConstantBuffer cb, T data) where T : struct
        {
            var mapping = MyMapping.MapDiscard(RC, MyCommon.ProjectionConstants);

            mapping.WriteAndPosition(ref data);
            mapping.Unmap();
        }
コード例 #10
0
ファイル: MyHighlight.cs プロジェクト: viktorius/Viktor
        static unsafe IConstantBuffer GetObjectCB(MyRenderContext RC, MyInstanceComponent instance, float stateData)
        {
            Vector4 col0, col1, col2;

            instance.GetMatrixCols(0, out col0, out col1, out col2);
            Matrix matrix = Matrix.Identity;

            matrix.SetRow(0, col0);
            matrix.SetRow(1, col1);
            matrix.SetRow(2, col2);
            matrix = Matrix.Transpose(matrix);

            int cbSize = sizeof(MyObjectDataCommon);

            cbSize += sizeof(MyObjectDataNonVoxel);

            IConstantBuffer      cb           = MyCommon.GetObjectCB(cbSize);
            var                  mapping      = MyMapping.MapDiscard(RC, cb);
            MyObjectDataNonVoxel nonVoxelData = new MyObjectDataNonVoxel();

            mapping.WriteAndPosition(ref nonVoxelData);
            MyObjectDataCommon commonData = new MyObjectDataCommon();

            commonData.LocalMatrix = matrix;
            commonData.ColorMul    = Vector3.One;
            commonData.KeyColor    = new Vector3(0, -1f, 0f);
            commonData.CustomAlpha = stateData;

            mapping.WriteAndPosition(ref commonData);
            mapping.Unmap();
            return(cb);
        }
コード例 #11
0
        public void Update(IConstantBuffer buffer, DataArray data)
        {
            var dxBuffer = graphicsDevice.Cast <ConstantBuffer>(buffer, "buffer");

            if (dxBuffer.Usage == ResourceUsage.Immutable)
            {
                throw new ArgumentException("Can't update immutable resource.", "buffer");
            }

            if (data.Size != buffer.SizeBytes)
            {
                throw new ArgumentException("Data does not match ConstantBuffer size.", "data");
            }

            if (dxBuffer.Usage == ResourceUsage.Normal)
            {
                renderContext.Context.UpdateSubresource(new SharpDX.DataBox(data.Pointer, 0, 0), dxBuffer.Buffer);
            }
            else
            {
                MapMode mapMode = dxBuffer.Usage == ResourceUsage.Dynamic ? MapMode.WriteDiscard : MapMode.Write;

                SharpDX.DataBox box = renderContext.Context.MapSubresource(dxBuffer.Buffer, 0, mapMode, MapFlags.None);
                SharpDX.Utilities.CopyMemory(box.DataPointer, data.Pointer, data.Size);
                renderContext.Context.UnmapSubresource(dxBuffer.Buffer, 0);
            }
        }
コード例 #12
0
ファイル: MyBlur.cs プロジェクト: 2asoft/SpaceEngineers
        internal static unsafe void Init()
        {
            int typeCount = Enum.GetValues(typeof(MyBlurDensityFunctionType)).Length;
            m_blurShaders = new Dictionary<int, MyTuple<PixelShaderId, PixelShaderId>>();

            if (m_blurConstantBuffer == null)
                m_blurConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyBlur", sizeof(BlurConstants), usage: ResourceUsage.Dynamic);
        }
コード例 #13
0
        private static void InitDevice()
        {
            m_particleBuffer = MyManagers.Buffers.CreateSrvUav(
                "MyGPUParticleRenderer::particleBuffer", MyGPUEmitters.MAX_PARTICLES, PARTICLE_STRIDE);
            m_deadListBuffer = MyManagers.Buffers.CreateUav(
                "MyGPUParticleRenderer::deadListBuffer", MyGPUEmitters.MAX_PARTICLES, sizeof(uint),
                uavType: MyUavType.Append);
            m_skippedParticleCountBuffer = MyManagers.Buffers.CreateSrvUav(
                "MyGPUParticleRenderer::skippedParticleCountBuffer", 1, sizeof(uint),
                uavType: MyUavType.Counter);

            // 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] = MyManagers.Buffers.CreateRead("MyGPUParticleRenderer::debugCounterBuffers[0]", 1, sizeof(uint));
            m_debugCounterBuffers[1] = MyManagers.Buffers.CreateRead("MyGPUParticleRenderer::debugCounterBuffers[1]", 1, sizeof(uint));

            m_activeListConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyGPUParticleRenderer::activeListConstantBuffer", 4 * sizeof(uint));

            m_emitterConstantBuffer   = MyManagers.Buffers.CreateConstantBuffer("MyGPUParticleRenderer::emitterConstantBuffer", EMITTERCONSTANTBUFFER_SIZE, usage: ResourceUsage.Dynamic);
            m_emitterStructuredBuffer = MyManagers.Buffers.CreateSrv(
                "MyGPUParticleRenderer::emitterStructuredBuffer", MyGPUEmitters.MAX_LIVE_EMITTERS, EMITTERDATA_SIZE,
                usage: ResourceUsage.Dynamic);

            m_aliveIndexBuffer = MyManagers.Buffers.CreateSrvUav(
                "MyGPUParticleRenderer::aliveIndexBuffer", MyGPUEmitters.MAX_PARTICLES, sizeof(float),
                uavType: MyUavType.Counter);

            m_indirectDrawArgsBuffer = MyManagers.Buffers.CreateIndirectArgsBuffer("MyGPUParticleRenderer::indirectDrawArgsBuffer", 5, sizeof(uint));

            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 = MyManagers.Buffers.CreateIndexBuffer(
                        "MyGPUParticleRenderer::indexBuffer", MyGPUEmitters.MAX_PARTICLES * 6, new IntPtr(ptr),
                        MyIndexBufferFormat.UInt, ResourceUsage.Immutable);
                }
            }

            //MyRender11.BlendAlphaPremult
        }
コード例 #14
0
        internal static unsafe void Init()
        {
            m_ps = MyShaders.CreatePs("EnvProbe/ForwardPostprocess.hlsl");
            //m_atmosphere = MyShaders.CreatePs("EnvProbe/AtmospherePostprocess.hlsl");
            m_mipmap    = MyShaders.CreateCs("EnvProbe/EnvPrefilteringMipmap.hlsl");
            m_prefilter = MyShaders.CreateCs("EnvProbe/EnvPrefiltering.hlsl");
            m_blend     = MyShaders.CreateCs("EnvProbe/EnvPrefilteringBlend.hlsl");

            TransformConstants = MyManagers.Buffers.CreateConstantBuffer("TransformConstants", sizeof(Matrix) * 2 + sizeof(Vector4), usage: ResourceUsage.Dynamic);
        }
コード例 #15
0
 public unsafe MyVoxelMaterialsConstantBuffer()
 {
     Cb            = MyManagers.Buffers.CreateConstantBuffer("VoxelMaterialConstants", sizeof(MyVoxelMaterialEntry) * MAX_ENTRIES, usage: ResourceUsage.Dynamic);
     m_entries     = new MyVoxelMaterialEntry[MAX_ENTRIES];
     m_needsUpdate = new bool[MAX_ENTRIES];
     for (int i = 0; i < MAX_ENTRIES; i++)
     {
         m_needsUpdate[i] = true;
     }
 }
コード例 #16
0
ファイル: GL46CommandList.cs プロジェクト: deccer/Xacor
        public void SetConstantBuffer(IConstantBuffer buffer, BufferScope bufferScope)
        {
            var command = new GLCommand
            {
                Type           = CommandType.SetConstantBuffers,
                ConstantBuffer = (GL46ConstantBuffer)buffer
            };

            _commandList.Add(command);
        }
コード例 #17
0
ファイル: MyBlur.cs プロジェクト: viktorius/Viktor
        internal static unsafe void Init()
        {
            int typeCount = Enum.GetValues(typeof(MyBlurDensityFunctionType)).Length;

            m_blurShaders = new Dictionary <int, MyTuple <PixelShaderId, PixelShaderId> >();

            if (m_blurConstantBuffer == null)
            {
                m_blurConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyBlur", sizeof(BlurConstants), usage: ResourceUsage.Dynamic);
            }
        }
コード例 #18
0
        internal void SetConstantBuffer(int slot, IConstantBuffer constantBuffer)
        {
            Buffer buffer = null;
            if (constantBuffer != null)
                buffer = constantBuffer.Buffer;

            if (constantBuffer == m_constantBuffers[slot])
                return;
            m_constantBuffers[slot] = constantBuffer;
            m_shaderStage.SetConstantBuffer(slot, buffer);
            m_statistics.SetConstantBuffers++;
        }
コード例 #19
0
        public void SetConstantBuffer(string bufferName, IConstantBuffer buffer)
        {
            if (_constantBuffers.ContainsKey(bufferName))
            {
                _constantBuffers.Remove(bufferName);
            }

            _constantBuffers.Add(bufferName, new NamedConstantBuffer()
            {
                Name = bufferName, ConstantBuffer = buffer
            });
        }
コード例 #20
0
 private static void DoneDevice()
 {
     MyManagers.Buffers.Dispose(m_ib); m_ib = null;
     MyManagers.Buffers.Dispose(m_activeListConstantBuffer); m_activeListConstantBuffer = null;
     MyManagers.Buffers.Dispose(m_indirectDrawArgsBuffer); m_indirectDrawArgsBuffer     = null;
     MyManagers.Buffers.Dispose(m_debugCounterBuffers); m_debugCounterBuffers           = new IReadBuffer[m_debugCounterBuffers.Length];
     MyManagers.Buffers.Dispose(m_aliveIndexBuffer); m_aliveIndexBuffer = null;
     MyManagers.Buffers.Dispose(m_deadListBuffer); m_deadListBuffer     = null;
     MyManagers.Buffers.Dispose(m_skippedParticleCountBuffer); m_skippedParticleCountBuffer = null;
     MyManagers.Buffers.Dispose(m_particleBuffer); m_particleBuffer = null;
     MyManagers.Buffers.Dispose(m_emitterConstantBuffer); m_emitterConstantBuffer     = null;
     MyManagers.Buffers.Dispose(m_emitterStructuredBuffer); m_emitterStructuredBuffer = null;
 }
コード例 #21
0
ファイル: MyRenderPass.cs プロジェクト: viktorius/Viktor
        // this is tricky call. The method assumes that Draw() has been called in this frame
        public void DrawGlass(MyRenderContext RC)
        {
            RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList);

            RC.SetViewport(m_viewport.OffsetX, m_viewport.OffsetY, m_viewport.Width, m_viewport.Height);
            //RC.SetRtvs(m_gbuffer, MyDepthStencilAccess.ReadWrite); <- the rtv is set out of the pass...

            FillConstantBuffer(RC, MyCommon.ProjectionConstants, Matrix.Transpose(m_viewProjMatrix));

            RC.VertexShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.VertexShader.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants);

            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.PixelShader.SetSrv(MyCommon.DITHER_8X8_SLOT, MyGeneratedTextureManager.Dithering8x8Tex);

            IConstantBuffer cbObjectData = GetPlaceholderObjectCB(RC, 255); // <- the lod value does not matter in this case

            RC.VertexShader.SetConstantBuffer(MyCommon.OBJECT_SLOT, cbObjectData);
            //RC.PixelShader.SetConstantBuffer(MyCommon.OBJECT_SLOT, cbObjectData);

            foreach (var itGroup in m_drawableGroupFactory.GetRawDrawableGroups())
            {
                MyRenderProxy.Assert(itGroup.InstancesCount != 0);
                MyRenderProxy.Assert(itGroup.InstancesCount == itGroup.InstancesIncrement);
                if (itGroup.Lod.GlassParts == null)
                {
                    continue;
                }
                foreach (var part in itGroup.Lod.GlassParts)
                {
                    MyGlassMaterial material = part.GlassMaterial;
                    RC.SetVertexBuffer(0, part.Parent.VB0);
                    RC.SetVertexBuffer(1, part.Parent.VB1);
                    RC.SetVertexBuffer(2, m_vbInstances);
                    RC.SetIndexBuffer(part.Parent.IB);

                    MyShaderBundle shaderBundle = part.GetShaderBundle(itGroup.State);
                    RC.SetInputLayout(shaderBundle.InputLayout);
                    RC.VertexShader.Set(shaderBundle.VertexShader);
                    RC.PixelShader.Set(shaderBundle.PixelShader);
                    RC.PixelShader.SetSrvs(0, material.Srvs);
                    RC.PixelShader.SetConstantBuffer(MyCommon.OBJECT_SLOT, GetGlassCB(RC, material));

                    int numInstances = itGroup.InstancesCount;
                    int ibOffset     = itGroup.OffsetInInstanceBuffer + (part.InstanceMaterialOffsetInLod + 1) * itGroup.InstancesCount;
                    RC.DrawIndexedInstanced(part.IndicesCount, numInstances, part.StartIndex,
                                            part.StartVertex, ibOffset);
                }
            }
        }
コード例 #22
0
ファイル: RenderMeshPass.cs プロジェクト: Golle/GameDev
        public RenderMeshPass(IDevice device, ID3DCompiler compiler)
        {
            using var vertexShaderBlob = new Blob(compiler.CompileShaderFromFile(@"F:\Git\GameDev\src\Titan.D3D11.Bindings\VertexShader.hlsl", "main", "vs_5_0"));
            using var pixelShaderBlob  = new Blob(compiler.CompileShaderFromFile(@"F:\Git\GameDev\src\Titan.D3D11.Bindings\PixelShader.hlsl", "main", "ps_5_0"));

            _vertexShader = device.CreateVertexShader(vertexShaderBlob);
            _pixelShader  = device.CreatePixelShader(pixelShaderBlob);

            _inputLayout             = device.CreateInputLayout(new VertexLayout(4).Append("Position", VertexLayoutTypes.Position3D).Append("Normal", VertexLayoutTypes.Position3D).Append("Texture", VertexLayoutTypes.Texture2D).Append("Color", VertexLayoutTypes.Float4Color), vertexShaderBlob);
            _perFrameConstantBuffer  = device.CreateConstantBuffer <PerFrameContantBuffer>(BufferUsage.Dynamic, BufferAccessFlags.Write);
            _lightsConstantBuffer    = device.CreateConstantBuffer <LightsConstantBuffer>(BufferUsage.Dynamic, BufferAccessFlags.Write);
            _perObjectConstantBuffer = device.CreateConstantBuffer <PerObjectContantBuffer>(BufferUsage.Dynamic, BufferAccessFlags.Write);
            _sampler = device.CreateSampler();
        }
コード例 #23
0
        public void Bind(SceneRenderer renderer, SceneNode root)
        {
            renderer.ActiveCamera = this;

            if (renderer.ActiveShaderProgram != null)
            {
                // upload projection matrix
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "CameraProjection", _projectionMatrixBuffer.GetBuffer(renderer));

                // upload view matrix
                IConstantBuffer trans = this.GetInverseWorldTransformBuffer(root);
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "CameraTransformation", trans.GetBuffer(renderer));
            }
        }
コード例 #24
0
        internal static unsafe void Init()
        {
            FrameConstantsStereoLeftEye  = MyManagers.Buffers.CreateConstantBuffer("FrameConstantsStereoLeftEye", sizeof(MyFrameConstantsLayout), usage: ResourceUsage.Dynamic);
            FrameConstantsStereoRightEye = MyManagers.Buffers.CreateConstantBuffer("FrameConstantsStereoRightEye", sizeof(MyFrameConstantsLayout), usage: ResourceUsage.Dynamic);

            FrameConstants                = MyManagers.Buffers.CreateConstantBuffer("FrameConstants", sizeof(MyFrameConstantsLayout), usage: ResourceUsage.Dynamic);
            ProjectionConstants           = MyManagers.Buffers.CreateConstantBuffer("ProjectionConstants", sizeof(Matrix), usage: ResourceUsage.Dynamic);
            ObjectConstants               = MyManagers.Buffers.CreateConstantBuffer("ObjectConstants", sizeof(Matrix), usage: ResourceUsage.Dynamic);
            FoliageConstants              = MyManagers.Buffers.CreateConstantBuffer("FoliageConstants", sizeof(Vector4), usage: ResourceUsage.Dynamic);
            MaterialFoliageTableConstants = MyManagers.Buffers.CreateConstantBuffer("MaterialFoliageTableConstants", sizeof(Vector4) * 256, usage: ResourceUsage.Dynamic);
            HighlightConstants            = MyManagers.Buffers.CreateConstantBuffer("HighlightConstants", sizeof(HighlightConstantsLayout), usage: ResourceUsage.Dynamic);
            AlphamaskViewsConstants       = MyManagers.Buffers.CreateConstantBuffer("AlphamaskViewsConstants", sizeof(Matrix) * 181, usage: ResourceUsage.Dynamic);

            UpdateAlphamaskViewsConstants();
        }
コード例 #25
0
ファイル: RenderUpdateContext.cs プロジェクト: K0bin/DotGame
        // TODO (henrik1235) Data* Update einbauen


        public void Update(IConstantBuffer constantBuffer, DataArray data)
        {
            var internalBuffer = graphicsDevice.Cast <ConstantBuffer>(constantBuffer, "constantBuffer");

            if (internalBuffer.IsDisposed)
            {
                throw new ObjectDisposedException("constantBuffer");
            }
            if (internalBuffer.Usage == ResourceUsage.Immutable)
            {
                throw new ArgumentException("Can't update immutable resource.", "constantBuffer");
            }

            internalBuffer.UpdateData(data);
        }
コード例 #26
0
ファイル: MyCommon.cs プロジェクト: 2asoft/SpaceEngineers
        internal static unsafe void Init()
        {
            FrameConstantsStereoLeftEye = MyManagers.Buffers.CreateConstantBuffer("FrameConstantsStereoLeftEye", sizeof(MyFrameConstantsLayout), usage: ResourceUsage.Dynamic);
            FrameConstantsStereoRightEye = MyManagers.Buffers.CreateConstantBuffer("FrameConstantsStereoRightEye", sizeof(MyFrameConstantsLayout), usage: ResourceUsage.Dynamic);

            FrameConstants = MyManagers.Buffers.CreateConstantBuffer("FrameConstants", sizeof(MyFrameConstantsLayout), usage: ResourceUsage.Dynamic);
            ProjectionConstants = MyManagers.Buffers.CreateConstantBuffer("ProjectionConstants", sizeof(Matrix), usage: ResourceUsage.Dynamic);
            ObjectConstants = MyManagers.Buffers.CreateConstantBuffer("ObjectConstants", sizeof(Matrix), usage: ResourceUsage.Dynamic);
            FoliageConstants = MyManagers.Buffers.CreateConstantBuffer("FoliageConstants", sizeof(Vector4), usage: ResourceUsage.Dynamic);
            MaterialFoliageTableConstants = MyManagers.Buffers.CreateConstantBuffer("MaterialFoliageTableConstants", sizeof(Vector4) * 256, usage: ResourceUsage.Dynamic);
            HighlightConstants = MyManagers.Buffers.CreateConstantBuffer("HighlightConstants", sizeof(HighlightConstantsLayout), usage: ResourceUsage.Dynamic);
            AlphamaskViewsConstants = MyManagers.Buffers.CreateConstantBuffer("AlphamaskViewsConstants", sizeof(Matrix) * 181, usage: ResourceUsage.Dynamic);

            UpdateAlphamaskViewsConstants();
        }
コード例 #27
0
        public void BindLightCamera(SceneRenderer renderer, SceneNode root, int shadowMapIdx)
        {
            renderer.ActiveCamera = this;
            _currentShadowMapIdx  = shadowMapIdx;

            if (renderer.ActiveShaderProgram != null)
            {
                // upload projection matrix
                _shadowCascades[_currentShadowMapIdx].BindProjection(renderer);

                // upload view matrix
                IConstantBuffer trans = this.GetInverseWorldTransformBuffer(root);
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "CameraTransformation", trans.GetBuffer(renderer));
            }
        }
コード例 #28
0
        public void SetConstantBuffer(IShader shader, string name, IConstantBuffer buffer)
        {
            var internalShader = graphicsDevice.Cast <Shader>(shader, "shader");

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            var internalBuffer = graphicsDevice.Cast <ConstantBuffer>(buffer, "buffer");

            graphicsDevice.BindManager.Shader = shader;

            graphicsDevice.BindManager.ConstantBuffer = buffer;
            GL.BindBufferBase(BufferRangeTarget.UniformBuffer, internalShader.GetUniformBlockBindingPoint(name), internalBuffer.UboId);
            graphicsDevice.CheckGLError();
        }
コード例 #29
0
ファイル: MyAtmosphere.cs プロジェクト: viktorius/Viktor
        // inscatter texture
        // transmittance texture
        //static RwTexId m_transmittanceLut;
        //static RwTexId m_inscatterLutR;
        //static RwTexId m_inscatterLutM;

        internal static unsafe void Init()
        {
            m_ps          = MyShaders.CreatePs("Transparent/Atmosphere/AtmosphereGBuffer.hlsl");
            m_psPerSample = MyShaders.CreatePs("Transparent/Atmosphere/AtmosphereGBuffer.hlsl", MyRender11.ShaderSampleFrequencyDefine());

            m_psEnv          = MyShaders.CreatePs("Transparent/Atmosphere/AtmosphereEnv.hlsl");
            m_psEnvPerSample = MyShaders.CreatePs("Transparent/Atmosphere/AtmosphereEnv.hlsl", MyRender11.ShaderSampleFrequencyDefine());

            m_precomputeDensity = MyShaders.CreateCs("Transparent/Atmosphere/AtmospherePrecompute.hlsl");

            m_proxyVs = MyShaders.CreateVs("Transparent/Atmosphere/AtmosphereVS.hlsl");
            m_proxyIL = MyShaders.CreateIL(m_proxyVs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION_PACKED));

            m_cb = MyManagers.Buffers.CreateConstantBuffer("CommonObjectCB" + sizeof(AtmosphereConstants), sizeof(AtmosphereConstants),
                                                           usage: SharpDX.Direct3D11.ResourceUsage.Dynamic);
        }
コード例 #30
0
        unsafe void IManagerDevice.OnDeviceInit()
        {
            if (m_markerConstantBuffer == null)
                m_markerConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyPostprocessMarkCascades.MarkerConstantBuffer", sizeof(MyMarkerConstants), usage: ResourceUsage.Dynamic);

            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();
        }
コード例 #31
0
ファイル: MyShaderStages.cs プロジェクト: viktorius/Viktor
        internal void SetConstantBuffer(int slot, IConstantBuffer constantBuffer)
        {
            Buffer buffer = null;

            if (constantBuffer != null)
            {
                buffer = constantBuffer.Buffer;
            }

            if (constantBuffer == m_constantBuffers[slot])
            {
                return;
            }
            m_constantBuffers[slot] = constantBuffer;
            m_shaderStage.SetConstantBuffer(slot, buffer);
            m_statistics.SetConstantBuffers++;
        }
コード例 #32
0
        public static unsafe RenderCommand SetShaderConstantBuffers(Shader shader)
        {
            Assure.NotNull(shader);
            Assure.False(shader.IsDisposed, "Shader was disposed.");
            IntPtr *resourceHandleArrayPtr = (IntPtr *)AllocAndZeroTemp(shader.NumConstantBufferSlots * (uint)sizeof(IntPtr));

            for (int i = 0; i < shader.ConstantBufferBindings.Length; i++)
            {
                IConstantBuffer boundResource = shader.ConstantBufferBindings[i].GetBoundResource();
                if (boundResource == null)
                {
                    continue;
                }
                resourceHandleArrayPtr[shader.ConstantBufferBindings[i].SlotIndex] = (IntPtr)boundResource.ResourceHandle;
            }
            return(new RenderCommand(shader.SetConstantBuffersInstruction, (IntPtr)resourceHandleArrayPtr, shader.NumConstantBufferSlots, 0U));
        }
コード例 #33
0
        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;

            IConstantBuffer 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);
        }
コード例 #34
0
        internal void FillConstantBuffer(IConstantBuffer 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, 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.Settings.User.ShadowQuality.ShadowCascadeResolution();

            mapping.WriteAndPosition(ref resolution);

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

            mapping.Unmap();
        }
コード例 #35
0
        internal void FillConstantBuffer(IConstantBuffer 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, 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();
        }
コード例 #36
0
 internal void SetConstantBuffer(int slot, IConstantBuffer constantBuffer)
 {
     m_vertexStage.SetConstantBuffer(slot, constantBuffer);
     m_geometryStage.SetConstantBuffer(slot, constantBuffer);
     m_pixelStage.SetConstantBuffer(slot, constantBuffer);
     m_computeStage.SetConstantBuffer(slot, constantBuffer);
 }
コード例 #37
0
 private unsafe static void Init()
 {
     m_ps = MyShaders.CreatePs("Postprocess/PostprocessColorizeExportedEexture.hlsl");
     m_cb = MyManagers.Buffers.CreateConstantBuffer("ExportedTexturesColor", sizeof(Vector4), usage: ResourceUsage.Dynamic);
     m_initialized = true;
 }
コード例 #38
0
 private static void DoneDevice()
 {
     MyManagers.Buffers.Dispose(m_ib); m_ib = null;
     MyManagers.Buffers.Dispose(m_activeListConstantBuffer); m_activeListConstantBuffer = null;
     MyManagers.Buffers.Dispose(m_indirectDrawArgsBuffer); m_indirectDrawArgsBuffer = null;
     MyManagers.Buffers.Dispose(m_debugCounterBuffers); m_debugCounterBuffers = new IReadBuffer[m_debugCounterBuffers.Length];
     MyManagers.Buffers.Dispose(m_aliveIndexBuffer); m_aliveIndexBuffer = null;
     MyManagers.Buffers.Dispose(m_deadListBuffer); m_deadListBuffer = null;
     MyManagers.Buffers.Dispose(m_skippedParticleCountBuffer); m_skippedParticleCountBuffer = null;
     MyManagers.Buffers.Dispose(m_particleBuffer); m_particleBuffer = null;
     MyManagers.Buffers.Dispose(m_emitterConstantBuffer); m_emitterConstantBuffer = null;
     MyManagers.Buffers.Dispose(m_emitterStructuredBuffer); m_emitterStructuredBuffer = null;
 }
コード例 #39
0
        private static void InitDevice()
        {
            m_particleBuffer = MyManagers.Buffers.CreateSrvUav(
                "MyGPUParticleRenderer::particleBuffer", MyGPUEmitters.MAX_PARTICLES, PARTICLE_STRIDE);
            m_deadListBuffer = MyManagers.Buffers.CreateUav(
                "MyGPUParticleRenderer::deadListBuffer", MyGPUEmitters.MAX_PARTICLES, sizeof(uint),
                uavType: MyUavType.Append);
            m_skippedParticleCountBuffer = MyManagers.Buffers.CreateSrvUav(
                "MyGPUParticleRenderer::skippedParticleCountBuffer", 1, sizeof(uint),
                uavType: MyUavType.Counter);

            // 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] = MyManagers.Buffers.CreateRead("MyGPUParticleRenderer::debugCounterBuffers[0]", 1, sizeof(uint));
            m_debugCounterBuffers[1] = MyManagers.Buffers.CreateRead("MyGPUParticleRenderer::debugCounterBuffers[1]", 1, sizeof(uint));

            m_activeListConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyGPUParticleRenderer::activeListConstantBuffer", 4 * sizeof(uint));

            m_emitterConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyGPUParticleRenderer::emitterConstantBuffer", EMITTERCONSTANTBUFFER_SIZE, usage: ResourceUsage.Dynamic);
            m_emitterStructuredBuffer = MyManagers.Buffers.CreateSrv(
                "MyGPUParticleRenderer::emitterStructuredBuffer", MyGPUEmitters.MAX_LIVE_EMITTERS, EMITTERDATA_SIZE,
                usage: ResourceUsage.Dynamic);

            m_aliveIndexBuffer = MyManagers.Buffers.CreateSrvUav(
                "MyGPUParticleRenderer::aliveIndexBuffer", MyGPUEmitters.MAX_PARTICLES, sizeof(float),
                uavType: MyUavType.Counter);

            m_indirectDrawArgsBuffer = MyManagers.Buffers.CreateIndirectArgsBuffer("MyGPUParticleRenderer::indirectDrawArgsBuffer", 5, sizeof(uint));

            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 = MyManagers.Buffers.CreateIndexBuffer(
                        "MyGPUParticleRenderer::indexBuffer", MyGPUEmitters.MAX_PARTICLES * 6, new IntPtr(ptr),
                        MyIndexBufferFormat.UInt, ResourceUsage.Immutable);
                }
            }

            //MyRender11.BlendAlphaPremult
        }
コード例 #40
0
 private void DestroyConstantBuffer()
 {
     MyManagers.Buffers.Dispose(m_csmConstants);
     m_csmConstants = null;
 }
コード例 #41
0
 internal void Clear()
 {
     WorldMatrix = MatrixD.Zero;
     CommonObjectData = default(MyObjectDataCommon);
     NonVoxelObjectData = MyObjectDataNonVoxel.Invalid;
     VoxelCommonObjectData = MyObjectDataVoxelCommon.Invalid;
     Mesh = LodMeshId.NULL;
     MergedMesh = MyMergedLodMeshId.NULL;
     Instancing = InstancingId.NULL;
     DepthShaders = MyMaterialShadersBundleId.NULL;
     Shaders = MyMaterialShadersBundleId.NULL;
     ForwardShaders = MyMaterialShadersBundleId.NULL;
     DrawSubmesh = default(MyDrawSubmesh);
     PerMaterialIndex = 0;
     SectionSubmeshes = null;
     InstanceCount = 0;
     StartInstance = 0;
     SkinningMatrices = null;
     Type = MyMaterialType.OPAQUE;
     Flags = 0;
     Lod = 0;
     ObjectBuffer = null;
     Parent = null;
     Material = MyMeshMaterialId.NULL;
     UnusedMaterials = UnusedMaterials ?? new HashSet<string>();
     UnusedMaterials.Clear();
 }
コード例 #42
0
 private unsafe void InitConstantBuffer()
 {
     DestroyConstantBuffer();
     m_csmConstants = MyManagers.Buffers.CreateConstantBuffer("MyShadowCascades", (sizeof(Matrix) + 2 * sizeof(Vector4) + sizeof(Vector4)) * 8 + sizeof(Vector4), usage: ResourceUsage.Dynamic);
 }
コード例 #43
0
ファイル: MyHBAO.cs プロジェクト: 2asoft/SpaceEngineers
        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 = MyManagers.Buffers.CreateConstantBuffer("MyHBAO::dataCB", GLOBALCONSTANTBUFFERSIZE, usage: ResourceUsage.Dynamic);

            for (int it = 0; it < NUM_SLICES; it++)
                m_perPassCBs[it] = null;

            InitializeConstantBuffer();
        }
コード例 #44
0
 private unsafe void InitConstantBuffer()
 {
     if (m_inverseConstants == null)
         m_inverseConstants = MyManagers.Buffers.CreateConstantBuffer("MyShadowCascadesPostProcess", sizeof(Matrix), usage: ResourceUsage.Dynamic);
 }
コード例 #45
0
        internal void GatherArray(IUavTexture postprocessTarget, ISrvBindable cascadeArray, MyProjectionInfo[] cascadeInfo, IConstantBuffer 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, MyGBuffer.Main.ResolvedDepthStencil.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();
        }