Ignore the material update flag w/o vertex color.

Instead of using materialambient for all of them.

Fixes #3918, and seems to match tests with 3dstudio.
This commit is contained in:
Unknown W. Brackets 2013-12-29 12:57:30 -08:00
parent 22b859acc2
commit 25bc394284
7 changed files with 25 additions and 23 deletions

View file

@ -137,7 +137,7 @@ using namespace DX9;
// that's common between the many vertices of a draw call.
class Lighter {
public:
Lighter();
Lighter(int vertType);
void Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], Vec3f pos, Vec3f normal);
private:
@ -152,7 +152,7 @@ private:
int materialUpdate_;
};
Lighter::Lighter() {
Lighter::Lighter(int vertType) {
doShadeMapping_ = gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP;
materialEmissive.GetFromRGB(gstate.materialemissive);
materialEmissive.a = 0.0f;
@ -166,7 +166,8 @@ Lighter::Lighter() {
materialSpecular.a = 1.0f;
specCoef_ = getFloat24(gstate.materialspecularcoef);
// viewer_ = Vec3f(-gstate.viewMatrix[9], -gstate.viewMatrix[10], -gstate.viewMatrix[11]);
materialUpdate_ = gstate.materialupdate & 7;
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0;
materialUpdate_ = hasColor ? gstate.materialupdate & 7 : 0;
}
void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], Vec3f pos, Vec3f norm)
@ -560,7 +561,7 @@ void TransformDrawEngineDX9::SoftwareTransformAndDraw(
float widthFactor = (float) w / (float) gstate_c.curTextureWidth;
float heightFactor = (float) h / (float) gstate_c.curTextureHeight;
Lighter lighter;
Lighter lighter(vertType);
float fog_end = getFloat24(gstate.fog1);
float fog_slope = getFloat24(gstate.fog2);

View file

@ -210,7 +210,7 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
}
if (gstate.isLightingEnabled()) {
WRITE(p, "float4 u_ambient;\n");
if ((gstate.materialupdate & 2) == 0)
if ((gstate.materialupdate & 2) == 0 || !hasColor)
WRITE(p, "float3 u_matdiffuse;\n");
// if ((gstate.materialupdate & 4) == 0)
WRITE(p, "float4 u_matspecular;\n"); // Specular coef is contained in alpha
@ -371,9 +371,9 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
// TODO: Declare variables for dots for shade mapping if needed.
const char *ambientStr = (gstate.materialupdate & 1) ? (hasColor ? "In.C1" : "u_matambientalpha") : "u_matambientalpha";
const char *diffuseStr = (gstate.materialupdate & 2) ? (hasColor ? "In.C1.rgb" : "u_matambientalpha.rgb") : "u_matdiffuse";
const char *specularStr = (gstate.materialupdate & 4) ? (hasColor ? "In.C1.rgb" : "u_matambientalpha.rgb") : "u_matspecular.rgb";
const char *ambientStr = (gstate.materialupdate & 1) && hasColor ? "In.C1" : "u_matambientalpha";
const char *diffuseStr = (gstate.materialupdate & 2) && hasColor ? "In.C1.rgb" : "u_matdiffuse";
const char *specularStr = (gstate.materialupdate & 4) && hasColor ? "In.C1.rgb" : "u_matspecular.rgb";
bool diffuseIsZero = true;
bool specularIsZero = true;

View file

@ -51,7 +51,7 @@ inline float clamp(float in, float min, float max) {
// that's common between the many vertices of a draw call.
class Lighter {
public:
Lighter();
Lighter(int vertType);
void Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], Vec3f pos, Vec3f normal);
private:
@ -66,7 +66,7 @@ private:
int materialUpdate_;
};
Lighter::Lighter() {
Lighter::Lighter(int vertType) {
doShadeMapping_ = gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP;
materialEmissive.GetFromRGB(gstate.materialemissive);
materialEmissive.a = 0.0f;
@ -80,7 +80,8 @@ Lighter::Lighter() {
materialSpecular.a = 1.0f;
specCoef_ = getFloat24(gstate.materialspecularcoef);
// viewer_ = Vec3f(-gstate.viewMatrix[9], -gstate.viewMatrix[10], -gstate.viewMatrix[11]);
materialUpdate_ = gstate.materialupdate & 7;
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0;
materialUpdate_ = hasColor ? gstate.materialupdate & 7 : 0;
}
void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], Vec3f pos, Vec3f norm)
@ -307,7 +308,7 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
float widthFactor = (float) w / (float) gstate_c.curTextureWidth;
float heightFactor = (float) h / (float) gstate_c.curTextureHeight;
Lighter lighter;
Lighter lighter(vertType);
float fog_end = getFloat24(gstate.fog1);
float fog_slope = getFloat24(gstate.fog2);

View file

@ -297,7 +297,7 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf
}
if (gstate.isLightingEnabled()) {
WRITE(p, "uniform lowp vec4 u_ambient;\n");
if ((gstate.materialupdate & 2) == 0)
if ((gstate.materialupdate & 2) == 0 || !hasColor)
WRITE(p, "uniform lowp vec3 u_matdiffuse;\n");
// if ((gstate.materialupdate & 4) == 0)
WRITE(p, "uniform lowp vec4 u_matspecular;\n"); // Specular coef is contained in alpha
@ -451,9 +451,9 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf
// TODO: Declare variables for dots for shade mapping if needed.
const char *ambientStr = (gstate.materialupdate & 1) ? (hasColor ? "color0" : "u_matambientalpha") : "u_matambientalpha";
const char *diffuseStr = (gstate.materialupdate & 2) ? (hasColor ? "color0.rgb" : "u_matambientalpha.rgb") : "u_matdiffuse";
const char *specularStr = (gstate.materialupdate & 4) ? (hasColor ? "color0.rgb" : "u_matambientalpha.rgb") : "u_matspecular.rgb";
const char *ambientStr = (gstate.materialupdate & 1) && hasColor ? "color0" : "u_matambientalpha";
const char *diffuseStr = (gstate.materialupdate & 2) && hasColor ? "color0.rgb" : "u_matdiffuse";
const char *specularStr = (gstate.materialupdate & 4) && hasColor ? "color0.rgb" : "u_matspecular.rgb";
bool diffuseIsZero = true;
bool specularIsZero = true;

View file

@ -21,11 +21,11 @@
namespace Lighting {
void Process(VertexData& vertex)
void Process(VertexData& vertex, bool hasColor)
{
Vec3<int> mec = Vec3<int>(gstate.getMaterialEmissiveR(), gstate.getMaterialEmissiveG(), gstate.getMaterialEmissiveB());
Vec3<int> mac = (gstate.materialupdate&1)
Vec3<int> mac = hasColor && (gstate.materialupdate&1)
? vertex.color0.rgb()
: Vec3<int>(gstate.getMaterialAmbientR(), gstate.getMaterialAmbientG(), gstate.getMaterialAmbientB());
Vec3<int> final_color = mec + mac * Vec3<int>(gstate.getAmbientR(), gstate.getAmbientG(), gstate.getAmbientB()) / 255;
@ -92,7 +92,7 @@ void Process(VertexData& vertex)
// diffuse lighting
Vec3<int> ldc = Vec3<int>(gstate.getDiffuseColorR(light), gstate.getDiffuseColorG(light), gstate.getDiffuseColorB(light));
Vec3<int> mdc = (gstate.materialupdate&2)
Vec3<int> mdc = hasColor && (gstate.materialupdate&2)
? vertex.color0.rgb()
: Vec3<int>(gstate.getMaterialDiffuseR(), gstate.getMaterialDiffuseG(), gstate.getMaterialDiffuseB());
@ -115,7 +115,7 @@ void Process(VertexData& vertex)
Vec3<float> H = worldE / worldE.Length() + L / L.Length();
Vec3<int> lsc = Vec3<int>(gstate.getSpecularColorR(light), gstate.getSpecularColorG(light), gstate.getSpecularColorB(light));
Vec3<int> msc = (gstate.materialupdate&4)
Vec3<int> msc = hasColor && (gstate.materialupdate&4)
? vertex.color0.rgb()
: Vec3<int>(gstate.getMaterialSpecularR(), gstate.getMaterialSpecularG(), gstate.getMaterialSpecularB());
@ -144,7 +144,7 @@ void Process(VertexData& vertex)
vertex.color1 = Vec3<int>(0, 0, 0);
}
int maa = (gstate.materialupdate&1) ? vertex.color0.a() : gstate.getMaterialAmbientA();
int maa = hasColor && (gstate.materialupdate&1) ? vertex.color0.a() : gstate.getMaterialAmbientA();
vertex.color0.a() = gstate.getAmbientA() * maa / 255;
vertex.color0 = vertex.color0.Clamp(0, 255);

View file

@ -21,6 +21,6 @@
namespace Lighting {
void Process(VertexData& vertex);
void Process(VertexData& vertex, bool hasColor);
}

View file

@ -177,7 +177,7 @@ static VertexData ReadVertex(VertexReader& vreader)
vertex.worldnormal /= vertex.worldnormal.Length();
}
Lighting::Process(vertex);
Lighting::Process(vertex, vreader.hasColor0());
} else {
vertex.screenpos.x = (u32)pos[0] * 16 + gstate.getOffsetX16();
vertex.screenpos.y = (u32)pos[1] * 16 + gstate.getOffsetY16();