public unsafe void ProcessVertex(int index, ref RasterizerVertex o) { var v = Data[index]; var pos = Vector4.Transform(new Vector4(v.position, 1.0f), ModelViewProjectionMatrix); o.x = pos.X; o.y = pos.Y; o.z = pos.Z; o.w = pos.W; o.pvar[0] = v.texcoord.X; o.pvar[1] = v.texcoord.Y; }
public unsafe void ProcessVertex(int index, ref RasterizerVertex output) { var data = VertexData[index]; output.x = data.x; output.y = data.y; output.z = data.z; output.w = 1.0f; output.avar[0] = data.r; output.avar[1] = data.g; output.avar[2] = data.b; }
public static unsafe RasterizerVertex InterpolateVertex(RasterizerVertex v0, RasterizerVertex v1, float t, int avarCount, int pvarCount) { RasterizerVertex result = new RasterizerVertex(); result.x = v0.x * (1.0f - t) + v1.x * t; result.y = v0.y * (1.0f - t) + v1.y * t; result.z = v0.z * (1.0f - t) + v1.z * t; result.w = v0.w * (1.0f - t) + v1.w * t; for (int i = 0; i < avarCount; ++i) { result.avar[i] = v0.avar[i] * (1.0f - t) + v1.avar[i] * t; } for (int i = 0; i < pvarCount; ++i) { result.pvar[i] = v0.pvar[i] * (1.0f - t) + v1.pvar[i] * t; } return(result); }
public TriangleEquations(ref RasterizerVertex v0, ref RasterizerVertex v1, ref RasterizerVertex v2, int aVarCount, int pVarCount) { e0 = new EdgeEquation(); e1 = new EdgeEquation(); e2 = new EdgeEquation(); z = new ParameterEquation(); invw = new ParameterEquation(); avar = new ParameterEquation[aVarCount]; pvar = new ParameterEquation[pVarCount]; e0.init(ref v1, ref v2); e1.init(ref v2, ref v0); e2.init(ref v0, ref v1); area2 = e0.c + e1.c + e2.c; // Cull backfacing triangles. if (area2 <= 0) { return; } float factor = 1.0f / area2; z.Init(v0.z, v1.z, v2.z, ref e0, ref e1, ref e2, factor); float invw0 = 1.0f / v0.w; float invw1 = 1.0f / v1.w; float invw2 = 1.0f / v2.w; invw.Init(invw0, invw1, invw2, ref e0, ref e1, ref e2, factor); for (int i = 0; i < aVarCount; ++i) { avar[i].Init(v0.avar[i], v1.avar[i], v2.avar[i], ref e0, ref e1, ref e2, factor); } for (int i = 0; i < pVarCount; ++i) { pvar[i].Init(v0.pvar[i] * invw0, v1.pvar[i] * invw1, v2.pvar[i] * invw2, ref e0, ref e1, ref e2, factor); } }