Exemplo n.º 1
0
        public Color[] Render()
        {
            this.Scene.ToList().ForEach(group =>
                                        group.ToList().ForEach(renderable =>
            {
                //for now only one shader.
                var material = renderable.material;

                //render
                var triIndex = 0;
                foreach (var triFace in renderable.RenderableObject.Triangles)
                {
                    //transform verts to screenspace
                    var screenCoords   = new List <Vector3>();
                    var localVertIndex = 0;
                    foreach (var meshVertInde in triFace.vertIndexList)
                    {
                        screenCoords.Add(material.Shader.VertexToFragment(renderable.RenderableObject, triIndex, localVertIndex));
                        localVertIndex++;
                    }

                    TriangleExtensions.drawTriangle(triIndex, screenCoords.ToArray(), material, depthBuffer, imageBuffer, Width);
                    triIndex = triIndex + 1;
                }
            })
                                        );

            return(imageBuffer.ToArray());
        }
Exemplo n.º 2
0
        public Color[] Render()
        {
            //cleanup from previous renders
            ImageBuffer = Enumerable.Repeat(fillColor, Width * Height).ToArray();
            DepthBuffer = Enumerable.Repeat(10000.0, Width * Height).ToArray();

            this.Scene.ToList().ForEach(group =>
                                        group.ToList().ForEach(renderable =>
            {
                //for now only one shader.
                var material = renderable.material;

                //render
                var triIndex = 0;
                foreach (var triFace in renderable.RenderableObject.Triangles)
                {
                    // Console.WriteLine($"{triIndex} out of {renderable.RenderableObject.Triangles.Count}");
                    //transform verts to screenspace
                    var screenCoords   = new List <Vector3>();
                    var localVertIndex = 0;
                    foreach (var meshVertInde in triFace.vertIndexList)
                    {
                        var vect = material.Shader.VertexToFragment(renderable.RenderableObject, triIndex, localVertIndex);

                        //if outside clip bounds, we will mark the vert NAN.

                        /* if (scaledX < 0 || scaledX > Width || scaledY < 0 || scaledY > Height)
                         * {
                         *   screenCoords.Add(new Vector3(float.NaN, float.NaN, float.NaN));
                         * }
                         * else
                         */
                        {
                            screenCoords.Add(new Vector3(vect.X, vect.Y, vect.Z));
                        }

                        localVertIndex++;
                    }
                    //draw if not nan.
                    //todo - logic is a bit backward.
                    //  if (screenCoords.All(x => !float.IsNaN(x.X)))
                    {
                        TriangleExtensions.drawTriangle(triIndex, screenCoords.ToArray(), material, DepthBuffer, ImageBuffer, Width);
                    }
                    triIndex = triIndex + 1;
                }
            })
                                        );

            return(ImageBuffer.ToArray());
        }