Modifying shade mapping in HW and SW

This commit is contained in:
BeaR 2013-04-02 12:23:39 +02:00
parent da1b345cd4
commit b3aa63f64f
2 changed files with 19 additions and 19 deletions

View File

@ -209,7 +209,7 @@ void TransformDrawEngine::DrawSpline(int ucount, int vcount, int utype, int vtyp
class Lighter {
public:
Lighter();
void Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], Vec3 pos, Vec3 normal, float dots[4]);
void Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], Vec3 pos, Vec3 normal);
private:
bool disabled_;
@ -241,7 +241,7 @@ Lighter::Lighter() {
materialUpdate_ = gstate.materialupdate & 7;
}
void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], Vec3 pos, Vec3 norm, float dots[4])
void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], Vec3 pos, Vec3 norm)
{
Color4 in(colorIn);
@ -269,7 +269,7 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[
for (int l = 0; l < 4; l++)
{
// can we skip this light?
if ((gstate.lightEnable[l] & 1) == 0 && !doShadeMapping_)
if ((gstate.lightEnable[l] & 1) == 0)
continue;
GELightComputation comp = (GELightComputation)(gstate.ltype[l] & 3);
@ -326,7 +326,7 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[
lightSum1 += (lightSpec * *specular * (powf(dot, specCoef_) * (dot * lightScale)));
}
}
dots[l] = dot;
if (gstate.lightEnable[l] & 1)
{
Color4 lightAmbient(gstate_c.lightColor[0][l], 0.0f);
@ -539,7 +539,6 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
}
// Perform lighting here if enabled. don't need to check through, it's checked above.
float dots[4] = {0,0,0,0};
float unlitColor[4] = {1, 1, 1, 1};
if (reader.hasColor0()) {
reader.ReadColor0(unlitColor);
@ -551,7 +550,7 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
}
float litColor0[4];
float litColor1[4];
lighter.Light(litColor0, litColor1, unlitColor, out, normal, dots);
lighter.Light(litColor0, litColor1, unlitColor, out, normal);
if (gstate.isLightingEnabled()) {
// Don't ignore gstate.lmode - we should send two colors in that case
@ -626,10 +625,13 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
}
break;
case 2:
// Shade mapping - use dot products from light sources to generate U and V.
// Shade mapping - use two light sources to generate U and V.
{
uv[0] = dots[gstate.getUVLS0()];
uv[1] = dots[gstate.getUVLS1()];
Vec3 lightpos0 = Vec3(gstate_c.lightpos[gstate.getUVLS0()]).Normalized();
Vec3 lightpos1 = Vec3(gstate_c.lightpos[gstate.getUVLS1()]).Normalized();
uv[0] = (1.0f + (lightpos0 * normal))/2.0f;
uv[1] = (1.0f - (lightpos1 * normal))/2.0f;
}
break;
case 3:

View File

@ -123,7 +123,7 @@ const char *boneWeightAttr[8] = {
enum DoLightComputation {
LIGHT_OFF,
LIGHT_DOTONLY,
LIGHT_SHADE,
LIGHT_FULL,
};
@ -160,7 +160,7 @@ void GenerateVertexShader(int prim, char *buffer) {
if (!hasNormal)
continue;
if (i == shadeLight0 || i == shadeLight1)
doLight[i] = LIGHT_DOTONLY;
doLight[i] = LIGHT_SHADE;
if ((gstate.lightingEnable & 1) && (gstate.lightEnable[i] & 1))
doLight[i] = LIGHT_FULL;
}
@ -223,13 +223,14 @@ void GenerateVertexShader(int prim, char *buffer) {
}
for (int i = 0; i < 4; i++) {
if (doLight[i] != LIGHT_OFF) {
// These are needed for dot product only (for shade mapping)
// This is needed for shade mapping
WRITE(p, "uniform vec3 u_lightpos%i;\n", i);
WRITE(p, "uniform vec3 u_lightdir%i;\n", i);
WRITE(p, "uniform vec3 u_lightatt%i;\n", i);
}
if (doLight[i] == LIGHT_FULL) {
// These are needed for the full thing
WRITE(p, "uniform vec3 u_lightdir%i;\n", i);
WRITE(p, "uniform vec3 u_lightatt%i;\n", i);
WRITE(p, "uniform lowp vec3 u_lightambient%i;\n", i);
WRITE(p, "uniform lowp vec3 u_lightdiffuse%i;\n", i);
WRITE(p, "uniform lowp vec3 u_lightspecular%i;\n", i);
@ -316,7 +317,7 @@ void GenerateVertexShader(int prim, char *buffer) {
// Calculate lights if needed. If shade mapping is enabled, lights may need to be
// at least partially calculated.
for (int i = 0; i < 4; i++) {
if (doLight[i] == LIGHT_OFF)
if (doLight[i] != LIGHT_FULL)
continue;
GELightComputation comp = (GELightComputation)(gstate.ltype[i] & 3);
@ -335,9 +336,6 @@ void GenerateVertexShader(int prim, char *buffer) {
WRITE(p, " dot%i = pow(dot%i, u_matspecular.a);\n", i, i);
}
if (doLight[i] == LIGHT_DOTONLY)
continue; // TODO: Actually, might want specular dot.... TODO
WRITE(p, " float lightScale%i = 1.0;\n", i);
if (type != GE_LIGHTTYPE_DIRECTIONAL) {
// Attenuation
@ -401,7 +399,7 @@ void GenerateVertexShader(int prim, char *buffer) {
break;
case 2: // Shade mapping - use dots from light sources.
WRITE(p, " v_texcoord = vec2(dot%i, dot%i);\n", gstate.getUVLS0(), gstate.getUVLS1());
WRITE(p, " v_texcoord = vec2(1.0 + dot(normalize(u_lightpos%i), worldnormal), 1.0 - dot(normalize(u_lightpos%i), worldnormal)) * 0.5;\n", gstate.getUVLS0(), gstate.getUVLS1());
break;
case 3: