示例#1
0
        public static void Render <TVertexShaderIn, TPixelShaderIn>(
            TVertexShaderIn[] vertices,
            int[] indices,
            MemoryResources resources,
            InputAssembler inputAssembler,
            OutputMerger outputMerger,
            IVertexShader <TVertexShaderIn, TPixelShaderIn> vertexShader,
            IGeometryProcessor <TPixelShaderIn> geometryProcessor,
            IRasterizer <TPixelShaderIn> rasterizer,
            IPixelShader <TPixelShaderIn> pixelShader,
            Bitmap output)
            where TVertexShaderIn : struct, IVertexShaderInput
            where TPixelShaderIn : struct, IPixelShaderInput
        {
            if (vertices.Length == 0 || indices.Length == 0)
            {
                return;
            }

            (vertices, indices) = inputAssembler.Assemble(vertices, indices);

            var vertexShaderOutput = new TPixelShaderIn[vertices.Length];

            for (var i = 0; i < vertices.Length; ++i)
            {
                vertexShaderOutput[i] = vertexShader.Transform(resources, vertices[i]);
            }

            (vertexShaderOutput, indices) = geometryProcessor.Process(vertexShaderOutput, indices);

            var pixelShaderOutput = rasterizer.Rasterize(resources, vertexShaderOutput, indices, pixelShader, outputMerger, output.Width, output.Height, _outputBuffer, _wBuffer);

            Helper.SetPixels(pixelShaderOutput, output);
        }
示例#2
0
        public void Render(IRenderer renderer)
        {
            rasterizer.ClearImage((byte)' ', (byte)((Kernel32Console.DefaultColors.Foreground.BLACK << 4) | Kernel32Console.DefaultColors.Foreground.WHITE));

            rasterizer.DrawMeshFilled(transformation, meshes);            //, Kernel32Console.DefaultColors.FOREGROUND_CYAN, Rasterizer.ShadePixelChar1);
            //rasterizer.DrawMeshVertices(transformation, meshes, Kernel32Console.DefaultColors.FOREGROUND_CYAN, (byte)'X');
            //rasterizer.DrawMeshWired(transformation, meshes, Kernel32Console.DefaultColors.Foreground.CYAN);

            //rasterizer.DrawMeshCenters(transformation, meshes, Kernel32Console.DefaultColors.Foreground.RED);
            //rasterizer.DrawMeshBoundingBox(transformation, meshes, Kernel32Console.DefaultColors.FOREGROUND_MAGENTA);

            //rasterizer.DrawAxes(Transformation.None, Kernel32Console.DefaultColors.Foreground.YELLOW);

            rasterizer.DrawStringHorizontal(Transformation.None, new Vector2(-Width / 2 + 1, Height / 2 - 2), string.Format("MODEL: '{0}'", currentWavefrontObjectFilePath));
            rasterizer.DrawStringHorizontal(Transformation.None, new Vector2(-Width / 2 + 1, Height / 2 - 3), string.Format("# POLYGONS: {0}", meshes.Sum(mesh => mesh.Faces.Count())));

            rasterizer.DrawStringHorizontal(Transformation.None, new Vector2(-Width / 2 + 1, 10), string.Format("TRANSLATION: {0}", transformation.Translation));
            rasterizer.DrawStringHorizontal(Transformation.None, new Vector2(-Width / 2 + 1, 9), string.Format("SCALE: {0}", transformation.Scale));
            rasterizer.DrawStringHorizontal(Transformation.None, new Vector2(-Width / 2 + 1, 8), string.Format("ROTATION: {0}", transformation.Rotation));

            rasterizer.DrawStringHorizontal(Transformation.None, new Vector2(-Width / 2 + 1, 6), string.Format("MODEL CENTER: {0}", transformation.Transform(meshes.First().Centers.Value)));

            var rasterizedFrameBuffer = rasterizer.Rasterize();

            renderer.Render(rasterizedFrameBuffer);
        }