Example #1
0
        //按列逐行扫描
        private void ScanLinePerRow(VertexOut left, VertexOut right, BaseShader shader)
        {
            VertexOut current;
            int       length = (int)right.posProjective.x - (int)left.posProjective.x;

            if (length == 0)
            {
                return;
            }
            for (int i = 0; i <= length; i++)
            {
                float weight = (float)i / length;
                current = LerpVertexOut(left, right, weight);

                if (shader.ZTest == true)
                {
                    if (current.posProjective.z >= 0.5f &&
                        current.posProjective.z > backBuffer.GetDepth((int)current.posProjective.x, (int)current.posProjective.y))
                    {
                        continue;
                    }
                }

                if (shader.ZWrite == true)
                {
                    backBuffer.DrawDepth((int)current.posProjective.x, (int)current.posProjective.y, current.posProjective.z);
                }

                current.posProjective.x = left.posProjective.x + i;
                current.posProjective.y = left.posProjective.y;

                //透视纹理处理
                shader.ProjectedMapRestore(current);

                //片段着色
                backBuffer.DrawPixel((int)current.posProjective.x, (int)current.posProjective.y, shader.FragmentShader(current));
            }
        }