Lighting fixes (sw + hw)

This commit is contained in:
Henrik Rydgard committed 2012-12-20 23:28:58 +01:00
1 parent 1551aea902
commit 79bd4e3d41
4 files changed
+18 -13

No files matched your search

+2 -2
View File
@@ -218,7 +218,7 @@ void LinkedShader::use() {
}
// Lighting
if (u_ambient != -1 && (dirtyUniforms & DIRTY_MATDIFFUSE)) {
if (u_ambient != -1 && (dirtyUniforms & DIRTY_AMBIENT)) {
SetColorUniform3Alpha(u_ambient, gstate.ambientcolor, gstate.ambientalpha & 0xFF);
}
if (u_matambientalpha != -1 && (dirtyUniforms & DIRTY_MATAMBIENTALPHA)) {
@@ -231,7 +231,7 @@ void LinkedShader::use() {
SetColorUniform3(u_matemissive, gstate.materialemissive);
}
if (u_matspecular != -1 && (dirtyUniforms & DIRTY_MATSPECULAR)) {
SetColorUniform3ExtraFloat(u_matemissive, gstate.materialspecular, getFloat24(gstate.materialspecularcoef));
SetColorUniform3ExtraFloat(u_matspecular, gstate.materialspecular, getFloat24(gstate.materialspecularcoef));
}
for (int i = 0; i < 4; i++) {
+8 -4
View File
@@ -152,9 +152,9 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[
dot = powf(dot, specCoef_);
float lightScale = 1.0f;
float distance = toLight.Normalize();
if (type != GE_LIGHTTYPE_DIRECTIONAL)
{
float distance = toLight.Normalize();
lightScale = 1.0f / (gstate_c.lightatt[l][0] + gstate_c.lightatt[l][1]*distance + gstate_c.lightatt[l][2]*distance*distance);
if (lightScale > 1.0f) lightScale = 1.0f;
}
@@ -361,7 +361,6 @@ void GLES_GPU::SoftwareTransformAndDraw(int prim, LinkedShader *program, int for
// Yes, we really must multiply by the world matrix too.
Vec3ByMatrix43(out, psum.v, gstate.worldMatrix);
if (reader.hasNormal()) {
nsum.Normalize();
Norm3ByMatrix43(norm, nsum.v, gstate.worldMatrix);
}
}
@@ -371,6 +370,11 @@ void GLES_GPU::SoftwareTransformAndDraw(int prim, LinkedShader *program, int for
float unlitColor[4] = {1, 1, 1, 1};
if (reader.hasColor0()) {
reader.ReadColor0(unlitColor);
} else {
unlitColor[0] = (gstate.materialambient & 0xFF) / 255.f;
unlitColor[1] = ((gstate.materialambient >> 8) & 0xFF) / 255.f;
unlitColor[2] = ((gstate.materialambient >> 16) & 0xFF) / 255.f;
unlitColor[3] = (gstate.materialalpha & 0xFF) / 255.f;
}
float litColor0[4];
float litColor1[4];
@@ -472,7 +476,7 @@ void GLES_GPU::SoftwareTransformAndDraw(int prim, LinkedShader *program, int for
memcpy(&transformed[index].x, v, 3 * sizeof(float));
memcpy(&transformed[index].uv, uv, 2 * sizeof(float));
memcpy(&transformed[index].color0, c0, 4 * sizeof(float));
memcpy(&transformed[index].color1, c1, 4 * sizeof(float));
memcpy(&transformed[index].color1, c1, 3 * sizeof(float));
}
// Step 2: Expand using the index buffer, and expand rectangles.
@@ -586,7 +590,7 @@ void GLES_GPU::SoftwareTransformAndDraw(int prim, LinkedShader *program, int for
glVertexAttribPointer(program->a_position, 3, GL_FLOAT, GL_FALSE, vertexSize, drawBuffer);
if (program->a_texcoord != -1) glVertexAttribPointer(program->a_texcoord, 2, GL_FLOAT, GL_FALSE, vertexSize, ((uint8_t*)drawBuffer) + 3 * 4);
if (program->a_color0 != -1) glVertexAttribPointer(program->a_color0, 4, GL_FLOAT, GL_FALSE, vertexSize, ((uint8_t*)drawBuffer) + 5 * 4);
if (program->a_color1 != -1) glVertexAttribPointer(program->a_color1, 4, GL_FLOAT, GL_FALSE, vertexSize, ((uint8_t*)drawBuffer) + 9 * 4);
if (program->a_color1 != -1) glVertexAttribPointer(program->a_color1, 3, GL_FLOAT, GL_FALSE, vertexSize, ((uint8_t*)drawBuffer) + 9 * 4);
// NOTICE_LOG(G3D,"DrawPrimitive: %i", numTrans);
if (drawIndexed) {
glDrawElements(glprim[prim], numTrans, glIndexType, (GLvoid *)inds);
+1 -1
View File
@@ -56,7 +56,7 @@ struct TransformedVertex
float x, y, z; // in case of morph, preblend during decode
float uv[2]; // scaled by uscale, vscale, if there
float color0[4]; // prelit
float color1[4]; // prelit
float color1[3]; // prelit
};
DecVtxFormat GetTransformedVtxFormat(const DecVtxFormat &fmt);
+7 -6
View File
@@ -44,7 +44,7 @@ static char buffer[16384];
bool CanUseHardwareTransform(int prim)
{
return !gstate.isModeThrough() && false; // prim != GE_PRIM_RECTANGLES;
// return !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES;
//return !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES;
}
// prim so we can special case for RECTANGLES :(
@@ -259,7 +259,7 @@ char *GenerateVertexShader(int prim)
// No skinning, just standard T&L.
WRITE(p, " vec3 worldpos = u_world * vec4(a_position, 1.0);\n");
if (hasNormal)
WRITE(p, " vec3 worldnormal = u_world * vec4(a_normal, 0.0);\n");
WRITE(p, " vec3 worldnormal = normalize(u_world * vec4(a_normal, 0.0));\n");
} else {
WRITE(p, " vec3 worldpos = vec3(0.0, 0.0, 0.0);\n");
if (hasNormal)
@@ -314,7 +314,7 @@ char *GenerateVertexShader(int prim)
bool doSpecular = (comp != GE_LIGHTCOMP_ONLYDIFFUSE);
bool poweredDiffuse = comp == GE_LIGHTCOMP_BOTHWITHPOWDIFFUSE;
WRITE(p, " float dot%i = dot(toLight%i, worldnormal);\n", i, i);
WRITE(p, " float dot%i = dot(normalize(toLight%i), worldnormal);\n", i, i);
if (poweredDiffuse) {
WRITE(p, " dot%i = pow(dot%i, u_matspecular.a);\n");
}
@@ -326,14 +326,15 @@ char *GenerateVertexShader(int prim)
if (type != GE_LIGHTTYPE_DIRECTIONAL) {
// Attenuation
WRITE(p, " float distance%i = length(toLight%i);\n", i, i);
WRITE(p, " lightScale%i = dot(u_lightatt%i, vec3(1.0, distance%i, distance%i*distance%i));\n", i, i, i, i, i);
WRITE(p, " lightScale%i = 1.0 / dot(u_lightatt%i, vec3(1.0, distance%i, distance%i*distance%i));\n", i, i, i, i, i);
WRITE(p, " if (lightScale%i > 1.0) lightScale%i = 1.0;\n", i, i);
}
WRITE(p, " vec3 diffuse%i = (u_lightdiffuse%i * %s) * (dot%i * lightScale%i);\n", i, i, diffuse, i, i);
if (doSpecular) {
WRITE(p, " vec3 halfVec%i = normalize(toLight%i + vec3(0, 0, 1));\n", i, i);
WRITE(p, " vec3 halfVec%i = normalize(normalize(toLight%i) + vec3(0, 0, 1));\n", i, i);
WRITE(p, " dot%i = dot(halfVec%i, worldnormal);\n", i, i);
WRITE(p, " if (dot%i > 0.0)\n", i);
WRITE(p, " lightSum1 += u_lightspecular%i * %s * (pow(dot%i, u_matspecular.a) * lightScale%i);\n", i, specular, i, i);
WRITE(p, " lightSum1 += u_lightspecular%i * %s * (pow(dot%i, u_matspecular.a) * (dot%i * lightScale%i));\n", i, specular, i, i, i);
}
WRITE(p, " lightSum0 += vec4(u_lightambient%i + diffuse%i, 0.0);\n", i, i);
}