mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-02-21 14:41:39 +00:00
softgpu: Perspective correct texture mapping.
This commit is contained in:
parent
0c6a4c1bb6
commit
02f41ecbd6
@ -102,13 +102,6 @@ void DrawTriangle(VertexData vertexdata[3])
|
||||
minY = std::max(minY, gstate.getScissorY1());
|
||||
maxY = std::min(maxY, gstate.getScissorY2());
|
||||
|
||||
int w = orient2d(vertices[2], vertices[0], vertices[1]);
|
||||
if (w == 0)
|
||||
{
|
||||
// TODO: Should draw a line or point here instead
|
||||
return;
|
||||
}
|
||||
|
||||
DrawingCoords p(minX, minY);
|
||||
for (p.y = minY; p.y <= maxY; ++p.y)
|
||||
{
|
||||
@ -122,13 +115,13 @@ void DrawTriangle(VertexData vertexdata[3])
|
||||
// TODO: Should only render when it's on the left of the right edge
|
||||
if (w0 >=0 && w1 >= 0 && w2 >= 0)
|
||||
{
|
||||
// TODO: I fail at barycentric coordinates, I think... this doesn't seem to do what I think it's doing
|
||||
float s = vertexdata[0].texturecoords.s() * w0 / w + vertexdata[1].texturecoords.s() * w1 / w + vertexdata[2].texturecoords.s() * w2 / w;
|
||||
float t = vertexdata[0].texturecoords.t() * w0 / w + vertexdata[1].texturecoords.t() * w1 / w + vertexdata[2].texturecoords.t() * w2 / w;
|
||||
u32 vcol0 = (int)((vertexdata[0].color0.x * w0 / w + vertexdata[1].color0.x * w1 / w + vertexdata[2].color0.x * w2 / w) * 255)*256*256*256 +
|
||||
(int)((vertexdata[0].color0.y * w0 / w + vertexdata[1].color0.y * w1 / w + vertexdata[2].color0.y * w2 / w) * 255)*256*256 +
|
||||
(int)((vertexdata[0].color0.z * w0 / w + vertexdata[1].color0.z * w1 / w + vertexdata[2].color0.z * w2 / w) * 255)*256 +
|
||||
(int)((vertexdata[0].color0.w * w0 / w + vertexdata[1].color0.w * w1 / w + vertexdata[2].color0.w * w2 / w) * 255);
|
||||
float den = 1.0f/vertexdata[0].clippos.w * w0 + 1.0f/vertexdata[1].clippos.w * w1 + 1.0f/vertexdata[2].clippos.w * w2;
|
||||
float s = (vertexdata[0].texturecoords.s() * w0 / vertexdata[0].clippos.w + vertexdata[1].texturecoords.s() * w1 / vertexdata[1].clippos.w + vertexdata[2].texturecoords.s() * w2 / vertexdata[2].clippos.w) / den;
|
||||
float t = (vertexdata[0].texturecoords.t() * w0 / vertexdata[0].clippos.w + vertexdata[1].texturecoords.t() * w1 / vertexdata[1].clippos.w + vertexdata[2].texturecoords.t() * w2 / vertexdata[2].clippos.w) / den;
|
||||
u32 vcol0 = (int)((vertexdata[0].color0.x * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.x * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.x * w2 / vertexdata[2].clippos.w) / den * 255)*256*256*256 +
|
||||
(int)((vertexdata[0].color0.y * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.y * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.y * w2 / vertexdata[2].clippos.w) / den * 255)*256*256 +
|
||||
(int)((vertexdata[0].color0.z * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.z * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.z * w2 / vertexdata[2].clippos.w) / den * 255)*256 +
|
||||
(int)((vertexdata[0].color0.w * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.w * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.w * w2 / vertexdata[2].clippos.w) / den * 255);
|
||||
u32 color = /*TextureDecoder::*/SampleNearest(0, s, t);
|
||||
*(u32*)&fb[p.x*4+p.y*FB_WIDTH*4] = color | vcol0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user