コード例 #1
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);
                }
            }
        }
コード例 #2
0
ファイル: MyRenderPass.cs プロジェクト: viktorius/Viktor
        unsafe IConstantBuffer GetGlassCB(MyRenderContext RC, MyGlassMaterial material)
        {
            StaticGlassConstants glassConstants = new StaticGlassConstants();

            glassConstants.Color      = material.Color;
            glassConstants.Reflective = material.Refraction;

            var glassCB = MyCommon.GetMaterialCB(sizeof(StaticGlassConstants));
            var mapping = MyMapping.MapDiscard(RC, glassCB);

            mapping.WriteAndPosition(ref glassConstants);
            mapping.Unmap();
            return(glassCB);
        }