diff options
author | Andrey Nazarov <skuller@skuller.net> | 2013-03-18 19:47:33 +0400 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2013-03-20 22:04:53 +0400 |
commit | fb3e8b753ca7e429f3b657ee2e2d1941fb1965a7 (patch) | |
tree | bccb5ef1ed927a2e8f3295b015db83546f00cd52 | |
parent | a8dccaf4c1e274012aca6212dd6efea5522d2dab (diff) |
Make software alias model lighting colored.
-rw-r--r-- | src/refresh/sw/alias.c | 37 | ||||
-rw-r--r-- | src/refresh/sw/polyset.c | 25 |
2 files changed, 34 insertions, 28 deletions
diff --git a/src/refresh/sw/alias.c b/src/refresh/sw/alias.c index 1a0a544..b7f0a81 100644 --- a/src/refresh/sw/alias.c +++ b/src/refresh/sw/alias.c @@ -33,9 +33,6 @@ fixed8_t r_aliasblendcolor[3]; static vec3_t r_plightvec; static vec3_t r_lerp_frontv, r_lerp_backv, r_lerp_move; -static int r_ambientlight; -static float r_shadelight; - static maliasframe_t *r_thisframe, *r_lastframe; static float aliastransform[3][4]; @@ -224,7 +221,6 @@ static void R_AliasTransformFinalVerts(int numpoints, finalvert_t *fv, maliasver int i; for (i = 0; i < numpoints; i++, fv++, oldv++, newv++) { - int temp; float lightcos; const vec_t *plightnormal; vec3_t lerped_vert; @@ -252,15 +248,7 @@ static void R_AliasTransformFinalVerts(int numpoints, finalvert_t *fv, maliasver if (lightcos < 0) lightcos *= 0.3f; - temp = r_ambientlight; - temp += (int)(r_shadelight * (lightcos + 1)); - - // clamp; because we limited the minimum ambient and shading light, we - // don't have to clamp low light, just bright - if (temp > 0xffff) - temp = 0xffff; - - fv->l = temp; + fv->l = 0x8000 + (int)(0x7fff * lightcos); if (fv->xyz[2] < ALIAS_Z_CLIP_PLANE) { fv->flags |= ALIAS_Z_CLIP; @@ -497,9 +485,10 @@ R_AliasSetupLighting */ static void R_AliasSetupLighting(void) { - float lightvec[3] = { -1, 0, 0}; + float cp, cy, sp, sy; + vec_t yaw; vec3_t light; - int i, j; + int i; // all components of light should be identical in software if (currententity->flags & RF_FULLBRIGHT) { @@ -531,15 +520,19 @@ static void R_AliasSetupLighting(void) for (i = 0; i < 3; i++) clamp(light[i], 0, 1); - j = LUMINANCE(light[0], light[1], light[2]) * 256; - - r_ambientlight = 0; - r_shadelight = j << 8; + r_aliasblendcolor[0] = light[0] * 255; + r_aliasblendcolor[1] = light[1] * 255; + r_aliasblendcolor[2] = light[2] * 255; // rotate the lighting vector into the model's frame of reference - r_plightvec[0] = DotProduct(lightvec, s_alias_forward); - r_plightvec[1] = -DotProduct(lightvec, s_alias_right); - r_plightvec[2] = DotProduct(lightvec, s_alias_up); + yaw = -DEG2RAD(currententity->angles[YAW]); + cy = cos(yaw); + sy = sin(yaw); + cp = cos(-M_PI / 4); + sp = sin(-M_PI / 4); + r_plightvec[0] = cp * cy; + r_plightvec[1] = cp * sy; + r_plightvec[2] = -sp; } diff --git a/src/refresh/sw/polyset.c b/src/refresh/sw/polyset.c index e1f2716..98f3ed4 100644 --- a/src/refresh/sw/polyset.c +++ b/src/refresh/sw/polyset.c @@ -378,9 +378,15 @@ void R_PolysetDrawSpans8_Blended(spanpackage_t *pspanpackage) do { if ((lzi >> 16) >= *lpz) { - tmp[0] = (lptex[0] * llight) >> 16; - tmp[1] = (lptex[1] * llight) >> 16; - tmp[2] = (lptex[2] * llight) >> 16; + tmp[0] = (r_aliasblendcolor[0] * llight) >> 15; + tmp[1] = (r_aliasblendcolor[1] * llight) >> 15; + tmp[2] = (r_aliasblendcolor[2] * llight) >> 15; + if (tmp[0] > 255) tmp[0] = 255; + if (tmp[1] > 255) tmp[1] = 255; + if (tmp[2] > 255) tmp[2] = 255; + tmp[0] = (lptex[0] * tmp[0]) >> 8; + tmp[1] = (lptex[1] * tmp[1]) >> 8; + tmp[2] = (lptex[2] * tmp[2]) >> 8; lpdest[0] = (lpdest[0] * r_alias_one_minus_alpha + tmp[2] * r_alias_alpha) >> 8; lpdest[1] = (lpdest[1] * r_alias_one_minus_alpha + tmp[1] * r_alias_alpha) >> 8; lpdest[2] = (lpdest[2] * r_alias_one_minus_alpha + tmp[0] * r_alias_alpha) >> 8; @@ -467,6 +473,7 @@ void R_PolysetDrawSpans8_Opaque(spanpackage_t *pspanpackage) int llight; int lzi; short *lpz; + int tmp[3]; lpdest = pspanpackage->pdest; lptex = pspanpackage->ptex; @@ -478,9 +485,15 @@ void R_PolysetDrawSpans8_Opaque(spanpackage_t *pspanpackage) do { if ((lzi >> 16) >= *lpz) { - lpdest[0] = (lptex[2] * llight) >> 16; - lpdest[1] = (lptex[1] * llight) >> 16; - lpdest[2] = (lptex[0] * llight) >> 16; + tmp[0] = (r_aliasblendcolor[0] * llight) >> 15; + tmp[1] = (r_aliasblendcolor[1] * llight) >> 15; + tmp[2] = (r_aliasblendcolor[2] * llight) >> 15; + if (tmp[0] > 255) tmp[0] = 255; + if (tmp[1] > 255) tmp[1] = 255; + if (tmp[2] > 255) tmp[2] = 255; + lpdest[0] = (lptex[2] * tmp[2]) >> 8; + lpdest[1] = (lptex[1] * tmp[1]) >> 8; + lpdest[2] = (lptex[0] * tmp[0]) >> 8; *lpz = lzi >> 16; } lpdest += VID_BYTES; |