Exemplo n.º 1
0
        unsafe static void DrawBatches(MyRenderContext RC, MyStringId material)
        {
            if (m_matrices.Count == 0)
            {
                return;
            }

            var matDesc = m_materials[material];

            switch (matDesc.DecalType)
            {
            case MyScreenDecalType.NormalMap:
                BindResources(RC, false);
                RC.SetPS(m_psNormalMap);
                RC.SetBS(MyRender11.BlendDecalNormal);
                break;

            case MyScreenDecalType.ColorMap:
                BindResources(RC, true);
                RC.SetPS(m_psColorMap);
                RC.SetBS(MyRender11.BlendDecalColor);
                break;

            case MyScreenDecalType.NormalColorMap:
                BindResources(RC, false);
                RC.SetPS(m_psNormalColorMap);
                RC.SetBS(MyRender11.BlendDecalNormalColor);
                break;

            default:
                throw new Exception("Unknown decal type");
            }

            // factor 1 makes overwriting of gbuffer color & subtracting from ao
            RC.DeviceContext.PixelShader.SetShaderResource(3, MyTextures.GetView(matDesc.AlphamaskTexture));
            RC.DeviceContext.PixelShader.SetShaderResource(4, MyTextures.GetView(matDesc.ColorMetalTexture));
            RC.DeviceContext.PixelShader.SetShaderResource(5, MyTextures.GetView(matDesc.NormalmapTexture));

            var decalCb = MyCommon.GetObjectCB(sizeof(MyDecalConstants) * DECAL_BATCH_SIZE);

            int batchCount = m_matrices.Count / DECAL_BATCH_SIZE + 1;
            int offset     = 0;

            for (int i1 = 0; i1 < batchCount; i1++)
            {
                var mapping = MyMapping.MapDiscard(decalCb);

                int leftDecals = m_matrices.Count - offset;
                int decalCount = leftDecals > DECAL_BATCH_SIZE ? DECAL_BATCH_SIZE : leftDecals;
                for (int i2 = 0; i2 < decalCount; ++i2)
                {
                    Matrix worldMatrix            = Matrix.Transpose(m_matrices[i2]);
                    Matrix transposeInverseMatrix = Matrix.Transpose(Matrix.Invert(m_matrices[i2]));
                    mapping.WriteAndPosition(ref worldMatrix);
                    mapping.WriteAndPosition(ref transposeInverseMatrix);
                }

                mapping.Unmap();

                // Draw a box without buffer: 36 vertices -> 12 triangles. 2 triangles per face -> 6 faces
                MyImmediateRC.RC.DeviceContext.DrawIndexed(36 * decalCount, 0, 0);

                offset += DECAL_BATCH_SIZE;
            }

            m_matrices.Clear();
        }
Exemplo n.º 2
0
        unsafe static void DrawBatches(MyRenderContext RC, MyStringId material, int matIndex, bool transparent)
        {
            if (m_jobs.Count == 0)
            {
                return;
            }

            var matDesc            = m_materials[material][matIndex];
            MyScreenDecalType type = matDesc.DecalType;

            if (transparent)
            {
                // Always fallback to colormap for transparent surface decals
                type = MyScreenDecalType.ColorMap;
            }

            switch (type)
            {
            case MyScreenDecalType.NormalMap:
                BindResources(RC);
                RC.SetPS(m_psNormalMap);
                RC.SetBS(MyRender11.BlendDecalNormal);
                break;

            case MyScreenDecalType.ColorMap:
                if (transparent)
                {
                    BindResourcesTransparentBillboards(RC);
                    RC.SetPS(m_psColorMapTransparent);
                }
                else
                {
                    BindResources(RC);
                    RC.SetPS(m_psColorMap);
                    RC.SetBS(MyRender11.BlendDecalColor);
                }
                break;

            case MyScreenDecalType.NormalColorMap:
                BindResources(RC);
                RC.SetPS(m_psNormalColorMap);
                RC.SetBS(MyRender11.BlendDecalNormalColor);
                break;

            case MyScreenDecalType.NormalColorExtMap:
                BindResources(RC);
                RC.SetPS(m_psNormalColorExtMap);
                RC.SetBS(MyRender11.BlendDecalNormalColorExt);
                break;

            default:
                throw new Exception("Unknown decal type");
            }

            // factor 1 makes overwriting of gbuffer color & subtracting from ao
            RC.DeviceContext.PixelShader.SetShaderResource(3, MyTextures.GetView(matDesc.AlphamaskTexture));
            RC.DeviceContext.PixelShader.SetShaderResource(4, MyTextures.GetView(matDesc.ColorMetalTexture));
            RC.DeviceContext.PixelShader.SetShaderResource(5, MyTextures.GetView(matDesc.NormalmapTexture));
            RC.DeviceContext.PixelShader.SetShaderResource(6, MyTextures.GetView(matDesc.ExtensionsTexture));

            var decalCb = MyCommon.GetObjectCB(sizeof(MyDecalConstants) * DECAL_BATCH_SIZE);

            int batchCount = m_jobs.Count / DECAL_BATCH_SIZE + 1;
            int offset     = 0;

            for (int i1 = 0; i1 < batchCount; i1++)
            {
                var mapping = MyMapping.MapDiscard(decalCb);

                int leftDecals = m_jobs.Count - offset;
                int decalCount = leftDecals > DECAL_BATCH_SIZE ? DECAL_BATCH_SIZE : leftDecals;
                for (int i2 = 0; i2 < decalCount; ++i2)
                {
                    MyDecalConstants constants = new MyDecalConstants();
                    EncodeJobConstants(i2, ref constants);
                    mapping.WriteAndPosition(ref constants);
                }

                mapping.Unmap();

                // Draw a box without buffer: 36 vertices -> 12 triangles. 2 triangles per face -> 6 faces
                MyImmediateRC.RC.DeviceContext.DrawIndexed(36 * decalCount, 0, 0);

                offset += DECAL_BATCH_SIZE;
            }
        }
        unsafe static void DrawBatches(MyRenderContext RC, MyStringId material)
        {
            if (m_matrices.Count == 0)
                return;

            var matDesc = m_materials[material];

            switch (matDesc.DecalType)
            {
                case MyScreenDecalType.NormalMap:
                    BindResources(RC, false);
                    RC.SetPS(m_psNormalMap);
                    RC.SetBS(MyRender11.BlendDecalNormal);
                    break;
                case MyScreenDecalType.ColorMap:
                    BindResources(RC, true);
                    RC.SetPS(m_psColorMap);
                    RC.SetBS(MyRender11.BlendDecalColor);
                    break;
                case MyScreenDecalType.NormalColorMap:
                    BindResources(RC, false);
                    RC.SetPS(m_psNormalColorMap);
                    RC.SetBS(MyRender11.BlendDecalNormalColor);
                    break;
                default:
                    throw new Exception("Unknown decal type");
            }

            // factor 1 makes overwriting of gbuffer color & subtracting from ao
            RC.DeviceContext.PixelShader.SetShaderResource(3, MyTextures.GetView(matDesc.AlphamaskTexture));
            RC.DeviceContext.PixelShader.SetShaderResource(4, MyTextures.GetView(matDesc.ColorMetalTexture));
            RC.DeviceContext.PixelShader.SetShaderResource(5, MyTextures.GetView(matDesc.NormalmapTexture));

            var decalCb = MyCommon.GetObjectCB(sizeof(MyDecalConstants) * DECAL_BATCH_SIZE);

            int batchCount = m_matrices.Count / DECAL_BATCH_SIZE + 1;
            int offset = 0;
            for (int i1 = 0; i1 < batchCount; i1++)
            {
                var mapping = MyMapping.MapDiscard(decalCb);

                int leftDecals = m_matrices.Count - offset;
                int decalCount = leftDecals > DECAL_BATCH_SIZE ? DECAL_BATCH_SIZE : leftDecals;
                for (int i2 = 0; i2 < decalCount; ++i2)
                {
                    Matrix worldMatrix = Matrix.Transpose(m_matrices[i2]);
                    Matrix transposeInverseMatrix = Matrix.Transpose(Matrix.Invert(m_matrices[i2]));
                    mapping.WriteAndPosition(ref worldMatrix);
                    mapping.WriteAndPosition(ref transposeInverseMatrix);
                }

                mapping.Unmap();

                // Draw a box without buffer: 36 vertices -> 12 triangles. 2 triangles per face -> 6 faces
                MyImmediateRC.RC.DeviceContext.DrawIndexed(36 * decalCount, 0, 0);

                offset += DECAL_BATCH_SIZE;
            }

            m_matrices.Clear();
        }