Пример #1
0
 public void DrawTriangle(Vertex v1, Vertex v2, Vertex v3)
 {
     ConvertToNDC(v1.pos.x, v1.pos.y, out v1.pos.x, out v1.pos.y);
     ConvertToNDC(v2.pos.x, v2.pos.y, out v2.pos.x, out v2.pos.y);
     ConvertToNDC(v3.pos.x, v3.pos.y, out v3.pos.x, out v3.pos.y);
     NormalizedDevice.DrawTriangle(this, v1, v2, v3);
 }
Пример #2
0
        public static void DrawCall(IDevice device, Mesh mesh, Material material, Matrix4x4 M, Matrix4x4 V, Matrix4x4 P)
        {
            currentMaterial = material != null ? material : Material.none;
            currentM        = M;
            currentV        = V;
            currentP        = P;
            currentMVP      = P * (V * M);
            currentInverseM = Matrix4x4.Inverse(M);

            CullFaceType faceCull = currentMaterial != null ? currentMaterial.cull : CullFaceType.None;

            for (int i = 0, count = mesh.indexs.Count; i < count; i += 3)
            {
                Vertex v1 = mesh.vertexs[mesh.indexs[i]];
                Vertex v2 = mesh.vertexs[mesh.indexs[i + 1]];
                Vertex v3 = mesh.vertexs[mesh.indexs[i + 2]];

                Vector4 hc1 = CallVertexStage(ref v1);
                Vector4 hc2 = CallVertexStage(ref v2);
                Vector4 hc3 = CallVertexStage(ref v3);

                if (HomogeneousSpaceFaceCull(hc1, hc2, hc3, faceCull))
                {
                    continue;
                }

                if (CanonicalViewVolumeCull(hc1) && CanonicalViewVolumeCull(hc2) && CanonicalViewVolumeCull(hc3))
                {
                    continue;
                }

                PerspectiveDivisionToNDC(hc1, ref v1);
                PerspectiveDivisionToNDC(hc2, ref v2);
                PerspectiveDivisionToNDC(hc3, ref v3);

                NormalizedDevice.DrawTriangle(device, v1, v2, v3);
            }
        }