From fd65b7c9b827eddb0349d37f6b807b2bb90760eb Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sat, 29 Jun 2013 14:01:17 +0200 Subject: [PATCH] softgpu: New try at specular lighting, still doesn't seem to work... --- GPU/Software/Lighting.cpp | 7 +++++-- GPU/Software/TransformUnit.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/GPU/Software/Lighting.cpp b/GPU/Software/Lighting.cpp index 5ef4e98881..98b4cfcdb7 100644 --- a/GPU/Software/Lighting.cpp +++ b/GPU/Software/Lighting.cpp @@ -94,7 +94,10 @@ void Process(VertexData& vertex) if (gstate.isUsingSpecularLight(light)) { Vec3 E(0.f, 0.f, 1.f); - Vec3 H = E / E.Length() + L / d; + Mat3x3 view_matrix(gstate.viewMatrix); + Vec3 worldE = view_matrix.Inverse() * (E - Vec3(gstate.viewMatrix[9], gstate.viewMatrix[10], gstate.viewMatrix[11])); + Vec3 H = worldE / worldE.Length() + L / L.Length(); + Vec3 lsc = Vec3(gstate.getSpecularColorR(light), gstate.getSpecularColorG(light), gstate.getSpecularColorB(light)); Vec3 msc = (gstate.materialupdate&4) ? Vec3(gstate.getMaterialSpecularR(), gstate.getMaterialSpecularG(), gstate.getMaterialSpecularB()) @@ -104,7 +107,7 @@ void Process(VertexData& vertex) float k = getFloat24(gstate.materialspecularcoef&0xFFFFFF); specular_factor = pow(specular_factor, k); - if (specular_factor > 0.f) { + /*if (specular_factor > 0.f)*/ { specular_color.r() += att * spot * lsc.r() * msc.r() * specular_factor / 255; specular_color.g() += att * spot * lsc.g() * msc.g() * specular_factor / 255; specular_color.b() += att * spot * lsc.b() * msc.b() * specular_factor / 255; diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 94de748f14..b86cecaa58 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -146,7 +146,7 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type if (vreader.hasNormal()) { data[i].worldnormal = TransformUnit::ModelToWorld(data[i].normal) - Vec3(gstate.worldMatrix[9], gstate.worldMatrix[10], gstate.worldMatrix[11]); - data[i].worldnormal /= data[i].worldnormal.Length(); + data[i].worldnormal /= data[i].worldnormal.Length(); // TODO: Shouldn't be necessary.. } Lighting::Process(data[i]);