Exemple #1
0
        public void Invoke(List <V> vertexData, Rasterizer <F> rasterizer, FragmentStage <F> fragmentStage)
        {
            List <F> outData = new List <F>();

            foreach (var data in vertexData)
            {
                outData.Add(VertexShader.Invoke(data));
            }

            rasterizer.Invoke(outData, fragmentStage);
        }
        public ShaderProgram(Func <V, F> vertexShader, Func <F, Vector4> fragmentShader)
        {
            _vertexStage = new VertexStage <V, F> {
                VertexShader = vertexShader
            };

            _rasterizer = new Rasterizer <F>();

            _fragmentStage = new FragmentStage <F> {
                FragmentShader = fragmentShader
            };
        }
Exemple #3
0
        public void Invoke(List <F> vertexOutData, FragmentStage <F> fragmentStage)
        {
            var triangles = GenerateTriangles(vertexOutData);

            const float xDim       = 400;
            const float xPixelStep = 2.0f / xDim;
            const float yDim       = 400;
            const float yPixelStep = 2.0f / yDim;

            var fragments = new List <F> [(int)xDim, (int)yDim];


            for (int x = 0; x < xDim; x++)
            {
                float xPos = -1.0f + x * xPixelStep;

                for (int y = 0; y < yDim; y++)
                {
                    float yPos = -1.0f + y * yPixelStep;

                    fragments[x, y] = new List <F>();

                    foreach (var triangle in triangles)
                    {
                        Vector3 coords = Barycentric(xPos, yPos, triangle);

                        if (coords.X >= 0 && coords.Y >= 0 && coords.Z >= 0)
                        {
                            F data = new F();
                            data.Interpolate(coords, triangle);
                            fragments[x, y].Add(data);
                        }
                    }
                }
            }

            fragmentStage.Invoke(fragments);
        }