mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
softgpu: Implement diffuse lighting.
This commit is contained in:
parent
288de895db
commit
7fdce30199
3 changed files with 35 additions and 2 deletions
|
@ -38,7 +38,25 @@ void Process(VertexData& vertex)
|
|||
float maa = (gstate.materialupdate&1) ? gstate.getMaterialAmbientA()/255.f : vertex.color0.a();
|
||||
vertex.color0.a() = gstate.getAmbientA()/255.f * maa;
|
||||
|
||||
// Currently only implementing ambient lighting, so secondary color is always zero anyway
|
||||
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
|
||||
: 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;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
|
|
@ -115,6 +115,12 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type
|
|||
data[i].texturecoords = Vec2<float>(uv[0], uv[1]);
|
||||
}
|
||||
|
||||
if (vreader.hasNormal()) {
|
||||
float normal[3];
|
||||
vreader.ReadNrm(normal);
|
||||
data[i].normal = Vec3<float>(normal[0], normal[1], normal[2]);
|
||||
}
|
||||
|
||||
if (vreader.hasColor0()) {
|
||||
float col[4];
|
||||
vreader.ReadColor0(col);
|
||||
|
@ -133,7 +139,8 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type
|
|||
|
||||
if (!gstate.isModeThrough()) {
|
||||
ModelCoords mcoords(pos[0], pos[1], pos[2]);
|
||||
data[i].clippos = ClipCoords(ClipCoords(TransformUnit::ViewToClip(TransformUnit::WorldToView(TransformUnit::ModelToWorld(mcoords)))));
|
||||
data[i].worldpos = WorldCoords(TransformUnit::ModelToWorld(mcoords));
|
||||
data[i].clippos = ClipCoords(ClipCoords(TransformUnit::ViewToClip(TransformUnit::WorldToView(data[i].worldpos))));
|
||||
data[i].drawpos = DrawingCoords(TransformUnit::ScreenToDrawing(TransformUnit::ClipToScreen(data[i].clippos)));
|
||||
|
||||
Lighting::Process(data[i]);
|
||||
|
|
|
@ -43,6 +43,8 @@ struct VertexData
|
|||
{
|
||||
#define LINTERP(T, OUT, IN) (OUT) + ((IN - OUT) * T)
|
||||
|
||||
// World coords only needed for lighting, so we don't Lerp those
|
||||
|
||||
clippos.x = LINTERP(t, a.clippos.x, b.clippos.x);
|
||||
clippos.y = LINTERP(t, a.clippos.y, b.clippos.y);
|
||||
clippos.z = LINTERP(t, a.clippos.z, b.clippos.z);
|
||||
|
@ -54,6 +56,10 @@ struct VertexData
|
|||
texturecoords.x = LINTERP(t, a.texturecoords.x, b.texturecoords.x);
|
||||
texturecoords.y = LINTERP(t, a.texturecoords.y, b.texturecoords.y);
|
||||
|
||||
normal.x = LINTERP(t, a.normal.x, b.normal.x);
|
||||
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);
|
||||
|
@ -64,9 +70,11 @@ struct VertexData
|
|||
color1.z = LINTERP(t, a.color1.z, b.color1.z);
|
||||
}
|
||||
|
||||
WorldCoords worldpos; // TODO: Storing this is dumb, should transform the light to clip space instead
|
||||
ClipCoords clippos;
|
||||
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!
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue