mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-27 15:30:35 +00:00
softgpu: Store color values as integers instead of as floating points.
This commit is contained in:
parent
7fdce30199
commit
b42b30e795
@ -26,40 +26,40 @@ void Process(VertexData& vertex)
|
||||
if (!gstate.isLightingEnabled())
|
||||
return;
|
||||
|
||||
Vec3<float> mec = Vec3<float>(gstate.getMaterialEmissiveR(), gstate.getMaterialEmissiveG(), gstate.getMaterialEmissiveB())/255.f;
|
||||
Vec3<int> mec = Vec3<int>(gstate.getMaterialEmissiveR(), gstate.getMaterialEmissiveG(), gstate.getMaterialEmissiveB());
|
||||
|
||||
Vec3<float> mac = (gstate.materialupdate&1)
|
||||
? Vec3<float>(gstate.getMaterialAmbientR(), gstate.getMaterialAmbientG(), gstate.getMaterialAmbientB())/255.f
|
||||
Vec3<int> mac = (gstate.materialupdate&1)
|
||||
? Vec3<int>(gstate.getMaterialAmbientR(), gstate.getMaterialAmbientG(), gstate.getMaterialAmbientB())
|
||||
: vertex.color0.rgb();
|
||||
vertex.color0.r() = mec.r() + mac.r() * gstate.getAmbientR()/255.f;
|
||||
vertex.color0.g() = mec.g() + mac.g() * gstate.getAmbientG()/255.f;
|
||||
vertex.color0.b() = mec.b() + mac.b() * gstate.getAmbientB()/255.f;
|
||||
vertex.color0.r() = mec.r() + mac.r() * gstate.getAmbientR()/255;
|
||||
vertex.color0.g() = mec.g() + mac.g() * gstate.getAmbientG()/255;
|
||||
vertex.color0.b() = mec.b() + mac.b() * gstate.getAmbientB()/255;
|
||||
|
||||
float maa = (gstate.materialupdate&1) ? gstate.getMaterialAmbientA()/255.f : vertex.color0.a();
|
||||
vertex.color0.a() = gstate.getAmbientA()/255.f * maa;
|
||||
int maa = (gstate.materialupdate&1) ? gstate.getMaterialAmbientA() : vertex.color0.a();
|
||||
vertex.color0.a() = gstate.getAmbientA() * maa / 255;
|
||||
|
||||
for (unsigned int light = 0; light < 4; ++light) {
|
||||
if (!gstate.isLightChanEnabled(light))
|
||||
continue;
|
||||
|
||||
Vec3<float> ldc = Vec3<float>(gstate.getDiffuseColorR(light), gstate.getDiffuseColorG(light), gstate.getDiffuseColorB(light))/255.f;
|
||||
Vec3<float> mdc = (gstate.materialupdate&2)
|
||||
? Vec3<float>(gstate.getMaterialDiffuseR(), gstate.getMaterialDiffuseG(), gstate.getMaterialDiffuseB())/255.f
|
||||
Vec3<int> ldc = Vec3<int>(gstate.getDiffuseColorR(light), gstate.getDiffuseColorG(light), gstate.getDiffuseColorB(light));
|
||||
Vec3<int> mdc = (gstate.materialupdate&2)
|
||||
? Vec3<int>(gstate.getMaterialDiffuseR(), gstate.getMaterialDiffuseG(), gstate.getMaterialDiffuseB())
|
||||
: vertex.color0.rgb();
|
||||
Vec3<float> L = Vec3<float>(getFloat24(gstate.lpos[3*light]&0xFFFFFF), getFloat24(gstate.lpos[3*light+1]&0xFFFFFF),getFloat24(gstate.lpos[3*light+2]&0xFFFFFF));
|
||||
L -= vertex.worldpos;
|
||||
|
||||
float factor = Dot(L,vertex.normal) / L.Length() / vertex.worldpos.Length();
|
||||
|
||||
vertex.color0.r() += ldc.r() * mdc.r() * factor;
|
||||
vertex.color0.g() += ldc.g() * mdc.g() * factor;
|
||||
vertex.color0.b() += ldc.b() * mdc.b() * factor;
|
||||
vertex.color0.r() += ldc.r() * mdc.r() * factor / 255;
|
||||
vertex.color0.g() += ldc.g() * mdc.g() * factor / 255;
|
||||
vertex.color0.b() += ldc.b() * mdc.b() * factor / 255;
|
||||
}
|
||||
|
||||
// Currently only implementing ambient+diffuse lighting, so secondary color is always zero anyway
|
||||
//if (!gstate.isUsingSecondaryColor())
|
||||
{
|
||||
vertex.color1 = Vec3<float>(0.f, 0.f, 0.f);
|
||||
vertex.color1 = Vec3<int>(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,12 +120,12 @@ void DrawTriangle(VertexData vertexdata[3])
|
||||
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 = 0;
|
||||
if ((gstate.shademodel&1) == GE_SHADE_GOURAUD)
|
||||
vcol0 = (int)((vertexdata[0].color0.r() * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.r() * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.r() * w2 / vertexdata[2].clippos.w) / den * 255) +
|
||||
(int)((vertexdata[0].color0.g() * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.g() * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.g() * w2 / vertexdata[2].clippos.w) / den * 255)*256 +
|
||||
(int)((vertexdata[0].color0.b() * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.b() * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.b() * w2 / vertexdata[2].clippos.w) / den * 255)*256*256 +
|
||||
(int)((vertexdata[0].color0.a() * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.a() * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.a() * w2 / vertexdata[2].clippos.w) / den * 255)*256*256*256;
|
||||
vcol0 = (int)((vertexdata[0].color0.r() * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.r() * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.r() * w2 / vertexdata[2].clippos.w) / den) +
|
||||
(int)((vertexdata[0].color0.g() * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.g() * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.g() * w2 / vertexdata[2].clippos.w) / den)*256 +
|
||||
(int)((vertexdata[0].color0.b() * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.b() * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.b() * w2 / vertexdata[2].clippos.w) / den)*256*256 +
|
||||
(int)((vertexdata[0].color0.a() * w0 / vertexdata[0].clippos.w + vertexdata[1].color0.a() * w1 / vertexdata[1].clippos.w + vertexdata[2].color0.a() * w2 / vertexdata[2].clippos.w) / den)*256*256*256;
|
||||
else
|
||||
vcol0 = vertexdata[2].color0.r() + (vertexdata[2].color0.g()*256) + (vertexdata[2].color0.b()*256*256) + (vertexdata[2].color0.a()*256*256*256);
|
||||
vcol0 = vertexdata[2].color0.r() | (vertexdata[2].color0.g()<<8) | (vertexdata[2].color0.b()<<16) | (vertexdata[2].color0.a()<<24);
|
||||
|
||||
u32 color = /*TextureDecoder::*/SampleNearest(0, s, t);
|
||||
*(u32*)&fb[p.x*4+p.y*FB_WIDTH*4] = color | vcol0;
|
||||
|
@ -124,17 +124,17 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type
|
||||
if (vreader.hasColor0()) {
|
||||
float col[4];
|
||||
vreader.ReadColor0(col);
|
||||
data[i].color0 = Vec4<float>(col[0], col[1], col[2], col[3]);
|
||||
data[i].color0 = Vec4<int>(col[0]*255, col[1]*255, col[2]*255, col[3]*255);
|
||||
} else {
|
||||
data[i].color0 = Vec4<float>((gstate.materialdiffuse&0xFF)/255.f, ((gstate.materialdiffuse>>8)&0xFF)/255.f, ((gstate.materialdiffuse>>16)&0xFF)/255.f, (gstate.materialalpha&0xFF)/255.f);
|
||||
data[i].color0 = Vec4<int>(gstate.materialdiffuse&0xFF, (gstate.materialdiffuse>>8)&0xFF, (gstate.materialdiffuse>>16)&0xFF, gstate.materialalpha&0xFF);
|
||||
}
|
||||
|
||||
if (vreader.hasColor1()) {
|
||||
float col[3];
|
||||
vreader.ReadColor0(col);
|
||||
data[i].color1 = Vec3<float>(col[0], col[1], col[2]);
|
||||
data[i].color1 = Vec3<int>(col[0]*255, col[1]*255, col[2]*255);
|
||||
} else {
|
||||
data[i].color1 = Vec3<float>(0.f, 0.f, 0.f);
|
||||
data[i].color1 = Vec3<int>(0, 0, 0);
|
||||
}
|
||||
|
||||
if (!gstate.isModeThrough()) {
|
||||
|
@ -42,6 +42,7 @@ struct VertexData
|
||||
void Lerp(float t, const VertexData& a, const VertexData& b)
|
||||
{
|
||||
#define LINTERP(T, OUT, IN) (OUT) + ((IN - OUT) * T)
|
||||
#define LINTERP_INT(T, OUT, IN) (OUT) + (((IN - OUT) * T) >> 8)
|
||||
|
||||
// World coords only needed for lighting, so we don't Lerp those
|
||||
|
||||
@ -60,14 +61,18 @@ struct VertexData
|
||||
normal.y = LINTERP(t, a.normal.y, b.normal.y);
|
||||
normal.z = LINTERP(t, a.normal.z, b.normal.z);
|
||||
|
||||
color0.x = LINTERP(t, a.color0.x, b.color0.x);
|
||||
color0.y = LINTERP(t, a.color0.y, b.color0.y);
|
||||
color0.z = LINTERP(t, a.color0.z, b.color0.z);
|
||||
color0.w = LINTERP(t, a.color0.w, b.color0.w);
|
||||
u16 t_int =(u16)(t*256);
|
||||
color0.x = LINTERP_INT(t_int, a.color0.x, b.color0.x);
|
||||
color0.y = LINTERP_INT(t_int, a.color0.y, b.color0.y);
|
||||
color0.z = LINTERP_INT(t_int, a.color0.z, b.color0.z);
|
||||
color0.w = LINTERP_INT(t_int, a.color0.w, b.color0.w);
|
||||
|
||||
color1.x = LINTERP(t, a.color1.x, b.color1.x);
|
||||
color1.y = LINTERP(t, a.color1.y, b.color1.y);
|
||||
color1.z = LINTERP(t, a.color1.z, b.color1.z);
|
||||
color1.x = LINTERP_INT(t_int, a.color1.x, b.color1.x);
|
||||
color1.y = LINTERP_INT(t_int, a.color1.y, b.color1.y);
|
||||
color1.z = LINTERP_INT(t_int, a.color1.z, b.color1.z);
|
||||
|
||||
#undef LINTERP
|
||||
#undef LINTERP_INT
|
||||
}
|
||||
|
||||
WorldCoords worldpos; // TODO: Storing this is dumb, should transform the light to clip space instead
|
||||
@ -75,8 +80,8 @@ struct VertexData
|
||||
DrawingCoords drawpos; // TODO: Shouldn't store this ?
|
||||
Vec2<float> texturecoords;
|
||||
Vec3<float> normal;
|
||||
Vec4<float> color0; // TODO: Should be an int vector!
|
||||
Vec3<float> color1; // TODO: Should be an int vector!
|
||||
Vec4<int> color0;
|
||||
Vec3<int> color1;
|
||||
};
|
||||
|
||||
class TransformUnit
|
||||
|
Loading…
Reference in New Issue
Block a user