soft: add full color light

This commit is contained in:
Denis Pauk 2022-03-19 16:46:51 +02:00
parent a6839bc584
commit 6c80d9b987
8 changed files with 285 additions and 135 deletions

View file

@ -202,15 +202,15 @@ typedef struct
*/
typedef struct finalvert_s {
int u, v, s, t;
int l;
int l[3]; // full color light
zvalue_t zi;
int flags;
float xyz[3]; // eye space
float xyz[3]; // eye space
} finalvert_t;
typedef struct compactvert_s {
int u, v, s, t;
int l;
int l[3]; // full color light
zvalue_t zi;
} compactvert_t;
@ -431,6 +431,7 @@ extern cvar_t *r_lefthand;
extern cvar_t *r_gunfov;
extern cvar_t *r_farsee;
extern cvar_t *r_lightmap;
extern cvar_t *r_colorlight;
extern cvar_t *r_drawworld;
extern cvar_t *r_lerpmodels;
extern cvar_t *r_lightlevel;
@ -501,7 +502,7 @@ extern edge_t **removeedges;
typedef struct {
int u, v, count;
pixel_t *ptex;
int sfrac, tfrac, light;
int sfrac, tfrac, light[3];
zvalue_t zi;
} spanpackage_t;
extern spanpackage_t *triangle_spans, *triangles_max;

View file

@ -34,6 +34,7 @@ static void
R_Alias_clip_z (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_t *out)
{
float scale;
int i;
scale = (ALIAS_Z_CLIP_PLANE - pfv0->xyz[2]) /
(pfv1->xyz[2] - pfv0->xyz[2]);
@ -44,7 +45,9 @@ R_Alias_clip_z (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_t *o
out->s = pfv0->s + (pfv1->s - pfv0->s) * scale;
out->t = pfv0->t + (pfv1->t - pfv0->t) * scale;
out->l = pfv0->l + (pfv1->l - pfv0->l) * scale;
for(i=0; i<3; i++)
out->l[i] = pfv0->l[i] + (pfv1->l[i] - pfv0->l[i]) * scale;
R_AliasProjectAndClipTestFinalVert (out);
}
@ -56,24 +59,34 @@ R_Alias_clip_left (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_t
if (pfv0->v >= pfv1->v )
{
int i;
scale = (float)(r_refdef.aliasvrect.x - pfv0->u) /
(pfv1->u - pfv0->u);
out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
for(i=0; i<3; i++)
out->l[i] = pfv1->l[i] + ( pfv0->l[i] - pfv1->l[i] ) * scale + 0.5;
out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
}
else
{
int i;
scale = (float)(r_refdef.aliasvrect.x - pfv1->u) /
(pfv0->u - pfv1->u);
out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
for(i=0; i<3; i++)
out->l[i] = pfv1->l[i] + ( pfv0->l[i] - pfv1->l[i] ) * scale + 0.5;
out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
@ -85,24 +98,34 @@ R_Alias_clip_right (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_
if ( pfv0->v >= pfv1->v )
{
int i;
scale = (float)(r_refdef.aliasvrectright - pfv0->u ) /
(pfv1->u - pfv0->u );
out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
for(i=0; i<3; i++)
out->l[i] = pfv0->l[i] + ( pfv1->l[i] - pfv0->l[i] ) * scale + 0.5;
out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
}
else
{
int i;
scale = (float)(r_refdef.aliasvrectright - pfv1->u ) /
(pfv0->u - pfv1->u );
out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
for(i=0; i<3; i++)
out->l[i] = pfv1->l[i] + ( pfv0->l[i] - pfv1->l[i] ) * scale + 0.5;
out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
@ -114,24 +137,34 @@ R_Alias_clip_top (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert_t
if (pfv0->v >= pfv1->v)
{
int i;
scale = (float)(r_refdef.aliasvrect.y - pfv0->v) /
(pfv1->v - pfv0->v);
out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
for(i=0; i<3; i++)
out->l[i] = pfv0->l[i] + ( pfv1->l[i] - pfv0->l[i] ) * scale + 0.5;
out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
}
else
{
int i;
scale = (float)(r_refdef.aliasvrect.y - pfv1->v) /
(pfv0->v - pfv1->v);
out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
for(i=0; i<3; i++)
out->l[i] = pfv1->l[i] + ( pfv0->l[i] - pfv1->l[i] ) * scale + 0.5;
out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
@ -144,6 +177,8 @@ R_Alias_clip_bottom (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert
if (pfv0->v >= pfv1->v)
{
int i;
scale = (float)(r_refdef.aliasvrectbottom - pfv0->v) /
(pfv1->v - pfv0->v);
@ -151,11 +186,16 @@ R_Alias_clip_bottom (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert
out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
for(i=0; i<3; i++)
out->l[i] = pfv0->l[i] + ( pfv1->l[i] - pfv0->l[i] ) * scale + 0.5;
out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
}
else
{
int i;
scale = (float)(r_refdef.aliasvrectbottom - pfv1->v) /
(pfv0->v - pfv1->v);
@ -163,7 +203,10 @@ R_Alias_clip_bottom (const finalvert_t *pfv0, const finalvert_t *pfv1, finalvert
out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
for(i=0; i<3; i++)
out->l[i] = pfv1->l[i] + ( pfv0->l[i] - pfv1->l[i] ) * scale + 0.5;
out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
@ -225,7 +268,7 @@ R_AliasClipTriangle(const entity_t *currententity, const finalvert_t *index0, co
{
int i, k, pingpong;
unsigned clipflags;
finalvert_t fv[2][8];
finalvert_t fv[2][8];
// copy vertexes and fix seam texture coordinates
fv[0][0] = *index0;

View file

@ -35,9 +35,9 @@ affinetridesc_t r_affinetridesc;
static vec3_t r_plightvec;
static vec3_t r_lerp_frontv, r_lerp_backv, r_lerp_move;
static int r_ambientlight;
static int r_ambientlight[3];
int r_aliasblendcolor;
static float r_shadelight;
static float r_shadelight[3];
static daliasframe_t *r_thisframe, *r_lastframe;
@ -399,7 +399,7 @@ R_AliasTransformFinalVerts(const entity_t *currententity, int numpoints, finalve
for ( i = 0; i < numpoints; i++, fv++, oldv++, newv++ )
{
int temp;
int j;
float lightcos;
const float *plightnormal;
vec3_t lerped_vert;
@ -426,20 +426,26 @@ R_AliasTransformFinalVerts(const entity_t *currententity, int numpoints, finalve
// lighting
lightcos = DotProduct (plightnormal, r_plightvec);
temp = r_ambientlight;
if (lightcos < 0)
for(j=0; j<3; j++)
{
temp += (int)(r_shadelight * lightcos);
int temp;
// clamp; because we limited the minimum ambient and shading light, we
// don't have to clamp low light, just bright
if (temp < 0)
temp = 0;
temp = r_ambientlight[j];
if (lightcos < 0)
{
temp += (int)(r_shadelight[j] * lightcos);
// clamp; because we limited the minimum ambient and shading light, we
// don't have to clamp low light, just bright
if (temp < 0)
temp = 0;
}
fv->l[j] = temp;
}
fv->l = temp;
if ( fv->xyz[2] < ALIAS_Z_CLIP_PLANE )
{
fv->flags |= ALIAS_Z_CLIP;
@ -536,7 +542,7 @@ R_AliasSetupLighting(entity_t *currententity)
{
float lightvec[3] = {-1, 0, 0};
vec3_t light;
int i, j;
int i;
// all components of light should be identical in software
if ( currententity->flags & RF_FULLBRIGHT )
@ -577,28 +583,40 @@ R_AliasSetupLighting(entity_t *currententity)
}
}
j = (light[0] + light[1] + light[2]) * 0.3333 * 255;
if(r_colorlight->value == 0)
{
float temp = (light[0] + light[1] + light[2]) / 3;
r_ambientlight = j;
r_shadelight = j;
light[0] = light[1] = light[2] = temp;
}
// clamp lighting so it doesn't overbright as much
if (r_ambientlight > 128)
r_ambientlight = 128;
if (r_ambientlight + r_shadelight > 192)
r_shadelight = 192 - r_ambientlight;
for(i=0; i<3; i++)
{
int j;
// guarantee that no vertex will ever be lit below LIGHT_MIN, so we don't have
// to clamp off the bottom
if (r_ambientlight < LIGHT_MIN)
r_ambientlight = LIGHT_MIN;
j = light[i] * 255;
r_ambientlight = (255 - r_ambientlight) << VID_CBITS;
r_ambientlight[i] = j;
r_shadelight[i] = j;
if (r_shadelight < 0)
r_shadelight = 0;
// clamp lighting so it doesn't overbright as much
if (r_ambientlight[i] > 128)
r_ambientlight[i] = 128;
if (r_ambientlight[i] + r_shadelight[i] > 192)
r_shadelight[i] = 192 - r_ambientlight[i];
r_shadelight *= VID_GRADES;
// guarantee that no vertex will ever be lit below LIGHT_MIN, so we don't have
// to clamp off the bottom
if (r_ambientlight[i] < LIGHT_MIN)
r_ambientlight[i] = LIGHT_MIN;
r_ambientlight[i] = (255 - r_ambientlight[i]) << VID_CBITS;
if (r_shadelight[i] < 0)
r_shadelight[i] = 0;
r_shadelight[i] *= VID_GRADES;
}
// rotate the lighting vector into the model's frame of reference
r_plightvec[0] = DotProduct( lightvec, s_alias_forward );

View file

@ -704,7 +704,7 @@ R_FindImage(char *name, imagetype_t type)
}
/* just return white image if show lighmap only */
if (type == it_wall && r_lightmap->value)
if ((type == it_wall || type == it_skin) && r_lightmap->value)
{
return r_whitetexture_mip;
}

View file

@ -49,7 +49,7 @@ R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist;
i = light->intensity;
if( i< 0)
if (i < 0)
i = -i;
if (dist > i) // (dist > light->intensity)
@ -57,6 +57,7 @@ R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
R_MarkLights (light, bit, node->children[0], r_dlightframecount);
return;
}
if (dist < -i) // (dist < -light->intensity)
{
R_MarkLights (light, bit, node->children[1], r_dlightframecount);
@ -288,15 +289,15 @@ R_AddDynamicLights (drawsurf_t* drawsurf)
tmax = (surf->extents[1]>>4)+1;
tex = surf->texinfo;
if (blocklight_max <= blocklights + smax*tmax)
if (blocklight_max <= blocklights + smax*tmax*3)
{
r_outoflights = true;
return;
}
for (lnum=0 ; lnum<r_newrefdef.num_dlights ; lnum++)
for (lnum=0; lnum < r_newrefdef.num_dlights; lnum++)
{
vec3_t impact, local;
vec3_t impact, local, color;
float dist, rad, minlight;
int t;
int i;
@ -310,6 +311,17 @@ R_AddDynamicLights (drawsurf_t* drawsurf)
dl = &r_newrefdef.dlights[lnum];
rad = dl->intensity;
if(r_colorlight->value == 0)
{
for(i=0; i<3; i++)
color[i] = 256;
}
else
{
for(i=0; i<3; i++)
color[i] = 256 * dl->color[i];
}
//=====
negativeLight = 0;
if(rad < 0)
@ -358,21 +370,25 @@ R_AddDynamicLights (drawsurf_t* drawsurf)
else
dist = td + (sd>>1);
//====
if(!negativeLight)
for (i=0; i<3; i++)
{
if (dist < minlight)
*plightdest += (rad - dist)*256;
//====
if(!negativeLight)
{
if (dist < minlight)
*plightdest += (rad - dist) * color[i];
}
else
{
if (dist < minlight)
*plightdest -= (rad - dist) * color[i];
if(*plightdest < minlight)
*plightdest = minlight;
}
//====
plightdest ++;
}
else
{
if (dist < minlight)
*plightdest -= (rad - dist)*256;
if(*plightdest < minlight)
*plightdest = minlight;
}
//====
plightdest ++;
}
}
}
@ -397,7 +413,7 @@ R_BuildLightMap (drawsurf_t* drawsurf)
smax = (surf->extents[0]>>4)+1;
tmax = (surf->extents[1]>>4)+1;
size = smax*tmax;
size = smax*tmax*3;
if (blocklight_max <= blocklights + size)
{
@ -430,19 +446,36 @@ R_BuildLightMap (drawsurf_t* drawsurf)
scale = drawsurf->lightadj[maps]; // 8.8 fraction
do
if(r_colorlight->value == 0)
{
byte light = sqrt((
lightmap[0] * lightmap[0] +
lightmap[1] * lightmap[1] +
lightmap[2] * lightmap[2]
) / 3);
*curr_light += light * scale;
curr_light++;
do
{
byte light = sqrt((
lightmap[0] * lightmap[0] +
lightmap[1] * lightmap[1] +
lightmap[2] * lightmap[2]
) / 3);
*curr_light += light * scale;
curr_light++;
*curr_light += light * scale;
curr_light++;
*curr_light += light * scale;
curr_light++;
lightmap += 3; /* skip to next lightmap */
lightmap += 3; /* skip to next lightmap */
}
while(curr_light < max_light);
}
else
{
do
{
*curr_light += *lightmap * scale;
curr_light++;
lightmap ++; /* skip to next lightmap */
}
while(curr_light < max_light);
}
while(curr_light < max_light);
}
}

View file

@ -135,6 +135,7 @@ cvar_t *r_lefthand;
cvar_t *r_gunfov;
cvar_t *r_farsee;
cvar_t *r_lightmap;
cvar_t *r_colorlight;
static cvar_t *sw_aliasstats;
cvar_t *sw_clearcolor;
cvar_t *sw_drawflat;
@ -396,6 +397,7 @@ R_RegisterVariables (void)
r_gunfov = ri.Cvar_Get( "r_gunfov", "80", CVAR_ARCHIVE );
r_farsee = ri.Cvar_Get("r_farsee", "0", CVAR_LATCH | CVAR_ARCHIVE);
r_lightmap = ri.Cvar_Get("r_lightmap", "0", 0);
r_colorlight = ri.Cvar_Get("r_colorlight", "0", CVAR_ARCHIVE);
r_speeds = ri.Cvar_Get ("r_speeds", "0", 0);
r_fullbright = ri.Cvar_Get ("r_fullbright", "0", 0);
r_drawentities = ri.Cvar_Get ("r_drawentities", "1", 0);

View file

@ -59,8 +59,8 @@ static edgetable edgetables[12] = {
};
// FIXME: some of these can become statics
static int a_sstepxfrac, a_tstepxfrac, r_lstepx, a_ststepxwhole;
static int r_sstepx, r_tstepx, r_lstepy, r_sstepy, r_tstepy;
static int a_sstepxfrac, a_tstepxfrac, r_lstepx[3], a_ststepxwhole;
static int r_sstepx, r_tstepx, r_lstepy[3], r_sstepy, r_tstepy;
static zvalue_t r_zistepx, r_zistepy;
static int d_aspancount;
@ -68,11 +68,11 @@ static spanpackage_t *d_pedgespanpackage;
spanpackage_t *triangle_spans, *triangles_max;
static int d_sfrac, d_tfrac, d_light;
static int d_sfrac, d_tfrac, d_light[3];
static zvalue_t d_zi;
static int d_ptexextrastep, d_sfracextrastep;
static int d_tfracextrastep, d_lightextrastep;
static int d_lightbasestep, d_ptexbasestep;
static int d_tfracextrastep, d_lightextrastep[3];
static int d_lightbasestep[3], d_ptexbasestep;
static int d_sfracbasestep, d_tfracbasestep;
static zvalue_t d_ziextrastep, d_zibasestep;
@ -189,21 +189,21 @@ R_DrawTriangle(const entity_t *currententity, const finalvert_t *a, const finalv
r_p0.v = a->v; // v
r_p0.s = a->s; // s
r_p0.t = a->t; // t
r_p0.l = a->l; // light
memcpy(r_p0.l, a->l, sizeof(int) * 3); // light
r_p0.zi = a->zi; // iz
r_p1.u = b->u;
r_p1.v = b->v;
r_p1.s = b->s;
r_p1.t = b->t;
r_p1.l = b->l;
memcpy(r_p1.l, b->l, sizeof(int) * 3); // light
r_p1.zi = b->zi;
r_p2.u = c->u;
r_p2.v = c->v;
r_p2.s = c->s;
r_p2.t = c->t;
r_p2.l = c->l;
memcpy(r_p2.l, c->l, sizeof(int) * 3); // light;
r_p2.zi = c->zi;
R_PolysetSetEdgeTable ();
@ -213,7 +213,7 @@ R_DrawTriangle(const entity_t *currententity, const finalvert_t *a, const finalv
static void
R_PushEdgesSpan(int u, int v, int count,
pixel_t* d_ptex, int d_sfrac, int d_tfrac, int d_light, zvalue_t d_zi)
pixel_t* d_ptex, int d_sfrac, int d_tfrac, int d_light[3], zvalue_t d_zi)
{
if (d_pedgespanpackage >= triangles_max)
{
@ -231,7 +231,7 @@ R_PushEdgesSpan(int u, int v, int count,
d_pedgespanpackage->tfrac = d_tfrac;
// FIXME: need to clamp l, s, t, at both ends?
d_pedgespanpackage->light = d_light;
memcpy(d_pedgespanpackage->light, d_light, sizeof(int) * 3);
d_pedgespanpackage->zi = d_zi;
d_pedgespanpackage++;
@ -257,6 +257,8 @@ R_PolysetScanLeftEdge_C(int height, pixel_t *d_ptex, int u, int v)
errorterm += erroradjustup;
if (errorterm >= 0)
{
int i;
// addtional step for compensate error
u ++;
d_aspancount ++;
@ -272,12 +274,17 @@ R_PolysetScanLeftEdge_C(int height, pixel_t *d_ptex, int u, int v)
d_ptex += r_affinetridesc.skinwidth;
d_tfrac &= 0xFFFF;
}
d_light += d_lightextrastep;
for(i=0; i<3; i++)
d_light[i] += d_lightextrastep[i];
d_zi += d_ziextrastep;
errorterm -= erroradjustdown;
}
else
{
int i;
d_ptex += d_ptexbasestep;
d_sfrac += d_sfracbasestep;
d_ptex += d_sfrac >> SHIFT16XYZ;
@ -288,7 +295,10 @@ R_PolysetScanLeftEdge_C(int height, pixel_t *d_ptex, int u, int v)
d_ptex += r_affinetridesc.skinwidth;
d_tfrac &= 0xFFFF;
}
d_light += d_lightbasestep;
for(i=0; i<3; i++)
d_light[i] += d_lightbasestep[i];
d_zi += d_zibasestep;
}
} while (--height);
@ -371,6 +381,7 @@ R_PolysetCalcGradients (int skinwidth)
{
float xstepdenominv, ystepdenominv, t0, t1;
float p01_minus_p21, p11_minus_p21, p00_minus_p20, p10_minus_p20;
int i;
p00_minus_p20 = r_p0.u - r_p2.u;
p01_minus_p21 = r_p0.v - r_p2.v;
@ -384,12 +395,15 @@ R_PolysetCalcGradients (int skinwidth)
// ceil () for light so positive steps are exaggerated, negative steps
// diminished, pushing us away from underflow toward overflow. Underflow is
// very visible, overflow is very unlikely, because of ambient lighting
t0 = r_p0.l - r_p2.l;
t1 = r_p1.l - r_p2.l;
r_lstepx = (int)
ceil((t1 * p01_minus_p21 - t0 * p11_minus_p21) * xstepdenominv);
r_lstepy = (int)
ceil((t1 * p00_minus_p20 - t0 * p10_minus_p20) * ystepdenominv);
for (i=0; i<3; i++)
{
t0 = r_p0.l[i] - r_p2.l[i];
t1 = r_p1.l[i] - r_p2.l[i];
r_lstepx[i] = (int)
ceil((t1 * p01_minus_p21 - t0 * p11_minus_p21) * xstepdenominv);
r_lstepy[i] = (int)
ceil((t1 * p00_minus_p20 - t0 * p10_minus_p20) * ystepdenominv);
}
t0 = r_p0.s - r_p2.s;
t1 = r_p1.s - r_p2.s;
@ -432,7 +446,7 @@ R_PolysetDrawSpans8_33(const entity_t *currententity, spanpackage_t *pspanpackag
pixel_t *lpdest;
pixel_t *lptex;
int lsfrac, ltfrac;
int llight;
int llight[3];
zvalue_t lzi;
zvalue_t *lpz;
@ -461,21 +475,24 @@ R_PolysetDrawSpans8_33(const entity_t *currententity, spanpackage_t *pspanpackag
lptex = pspanpackage->ptex;
lsfrac = pspanpackage->sfrac;
ltfrac = pspanpackage->tfrac;
llight = pspanpackage->light;
memcpy(llight, pspanpackage->light, sizeof(int) * 3);
lzi = pspanpackage->zi;
do
{
int i;
if ((lzi >> SHIFT16XYZ) >= *lpz)
{
int temp = vid_colormap[*lptex + ( llight & 0xFF00 )];
int temp = R_ApplyLight(*lptex, llight);
*lpdest = vid_alphamap[temp + *lpdest*256];
}
lpdest++;
lzi += r_zistepx;
lpz++;
llight += r_lstepx;
for(i=0; i<3; i++)
llight[i] += r_lstepx[i];
lptex += a_ststepxwhole;
lsfrac += a_sstepxfrac;
lptex += lsfrac >> SHIFT16XYZ;
@ -546,7 +563,7 @@ R_PolysetDrawSpans8_66(const entity_t *currententity, spanpackage_t *pspanpackag
pixel_t *lpdest;
pixel_t *lptex;
int lsfrac, ltfrac;
int llight;
int llight[3];
zvalue_t lzi;
zvalue_t *lpz;
@ -576,14 +593,16 @@ R_PolysetDrawSpans8_66(const entity_t *currententity, spanpackage_t *pspanpackag
lptex = pspanpackage->ptex;
lsfrac = pspanpackage->sfrac;
ltfrac = pspanpackage->tfrac;
llight = pspanpackage->light;
memcpy(llight, pspanpackage->light, sizeof(int) * 3);
lzi = pspanpackage->zi;
do
{
int i;
if ((lzi >> SHIFT16XYZ) >= *lpz)
{
int temp = vid_colormap[*lptex + ( llight & 0xFF00 )];
int temp = R_ApplyLight(*lptex, llight);
*lpdest = vid_alphamap[temp*256 + *lpdest];
*lpz = lzi >> SHIFT16XYZ;
@ -592,7 +611,8 @@ R_PolysetDrawSpans8_66(const entity_t *currententity, spanpackage_t *pspanpackag
lpdest++;
lzi += r_zistepx;
lpz++;
llight += r_lstepx;
for(i=0; i<3; i++)
llight[i] += r_lstepx[i];
lptex += a_ststepxwhole;
lsfrac += a_sstepxfrac;
lptex += lsfrac >> SHIFT16XYZ;
@ -700,7 +720,7 @@ R_PolysetDrawSpans8_Opaque (const entity_t *currententity, spanpackage_t *pspanp
int lsfrac, ltfrac;
pixel_t *lpdest;
pixel_t *lptex;
int llight;
int llight[3];
zvalue_t lzi;
zvalue_t *lpz;
int pos_shift = (pspanpackage->v * vid_buffer_width) + pspanpackage->u;
@ -712,28 +732,28 @@ R_PolysetDrawSpans8_Opaque (const entity_t *currententity, spanpackage_t *pspanp
lptex = pspanpackage->ptex;
lsfrac = pspanpackage->sfrac;
ltfrac = pspanpackage->tfrac;
llight = pspanpackage->light;
memcpy(llight, pspanpackage->light, sizeof(int) * 3);
lzi = pspanpackage->zi;
do
{
int i;
if ((lzi >> SHIFT16XYZ) >= *lpz)
{
int color_value;
if(r_newrefdef.rdflags & RDF_IRGOGGLES && currententity->flags & RF_IR_VISIBLE)
color_value = irtable[*lptex];
*lpdest = vid_colormap[irtable[*lptex]];
else
color_value = *lptex + (llight & 0xFF00);
*lpdest = R_ApplyLight(*lptex, llight);
*lpdest = vid_colormap[color_value];
*lpz = lzi >> SHIFT16XYZ;
zdamaged = true;
}
lpdest++;
lzi += r_zistepx;
lpz++;
llight += r_lstepx;
for(i=0; i<3; i++)
llight[i] += r_lstepx[i];
lptex += a_ststepxwhole;
lsfrac += a_sstepxfrac;
lptex += lsfrac >> SHIFT16XYZ;
@ -770,7 +790,7 @@ R_RasterizeAliasPolySmooth(const entity_t *currententity)
{
int initialleftheight, initialrightheight;
compactvert_t *plefttop, *prighttop, *pleftbottom, *prightbottom;
int working_lstepx, originalcount;
int working_lstepx[3], originalcount;
int u, v;
pixel_t *d_ptex;
@ -807,7 +827,7 @@ R_RasterizeAliasPolySmooth(const entity_t *currententity)
d_sfrac = plefttop->s & 0xFFFF;
d_tfrac = plefttop->t & 0xFFFF;
}
d_light = plefttop->l;
memcpy(d_light, plefttop->l, sizeof(int) * 3);
d_zi = plefttop->zi;
if (initialleftheight == 1)
@ -817,6 +837,8 @@ R_RasterizeAliasPolySmooth(const entity_t *currententity)
}
else
{
int i;
R_PolysetSetUpForLineScan(plefttop->u, plefttop->v,
pleftbottom->u, pleftbottom->v);
@ -826,9 +848,12 @@ R_RasterizeAliasPolySmooth(const entity_t *currententity)
// underflow (sort of turning the floor () we did in the gradient calcs into
// ceil (), but plus a little bit)
if (ubasestep < 0)
working_lstepx = r_lstepx - 1;
{
for(i=0; i<3; i++)
working_lstepx[i] = r_lstepx[i] - 1;
}
else
working_lstepx = r_lstepx;
memcpy(working_lstepx, r_lstepx, sizeof(int) * 3);
d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> SHIFT16XYZ) +
((r_tstepy + r_tstepx * ubasestep) >> SHIFT16XYZ) *
@ -837,7 +862,9 @@ R_RasterizeAliasPolySmooth(const entity_t *currententity)
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF;
d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) & 0xFFFF;
d_lightbasestep = r_lstepy + working_lstepx * ubasestep;
for(i=0; i<3; i++)
d_lightbasestep[i] = r_lstepy[i] + working_lstepx[i] * ubasestep;
d_zibasestep = r_zistepy + r_zistepx * ubasestep;
d_ptexextrastep = ((r_sstepy + r_sstepx * (ubasestep + 1)) >> SHIFT16XYZ) +
@ -847,7 +874,9 @@ R_RasterizeAliasPolySmooth(const entity_t *currententity)
d_sfracextrastep = (r_sstepy + r_sstepx*(ubasestep + 1)) & 0xFFFF;
d_tfracextrastep = (r_tstepy + r_tstepx*(ubasestep + 1)) & 0xFFFF;
d_lightextrastep = d_lightbasestep + working_lstepx;
for(i=0; i<3; i++)
d_lightextrastep[i] = d_lightbasestep[i] + working_lstepx[i];
d_ziextrastep = d_zibasestep + r_zistepx;
R_PolysetScanLeftEdge_C(initialleftheight, d_ptex, u, v);
@ -873,7 +902,7 @@ R_RasterizeAliasPolySmooth(const entity_t *currententity)
(plefttop->t >> SHIFT16XYZ) * r_affinetridesc.skinwidth;
d_sfrac = 0;
d_tfrac = 0;
d_light = plefttop->l;
memcpy(d_light, plefttop->l, sizeof(int) * 3);
d_zi = plefttop->zi;
if (height == 1)
@ -883,13 +912,18 @@ R_RasterizeAliasPolySmooth(const entity_t *currententity)
}
else
{
int i;
R_PolysetSetUpForLineScan(plefttop->u, plefttop->v,
pleftbottom->u, pleftbottom->v);
if (ubasestep < 0)
working_lstepx = r_lstepx - 1;
{
for(i=0; i<3; i++)
working_lstepx[i] = r_lstepx[i] - 1;
}
else
working_lstepx = r_lstepx;
memcpy(working_lstepx, r_lstepx, sizeof(int) * 3);
d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> SHIFT16XYZ) +
((r_tstepy + r_tstepx * ubasestep) >> SHIFT16XYZ) *
@ -898,7 +932,9 @@ R_RasterizeAliasPolySmooth(const entity_t *currententity)
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF;
d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) & 0xFFFF;
d_lightbasestep = r_lstepy + working_lstepx * ubasestep;
for(i=0; i<3; i++)
d_lightbasestep[i] = r_lstepy[i] + working_lstepx[i] * ubasestep;
d_zibasestep = r_zistepy + r_zistepx * ubasestep;
d_ptexextrastep = ((r_sstepy + r_sstepx * (ubasestep + 1)) >> SHIFT16XYZ) +
@ -908,7 +944,8 @@ R_RasterizeAliasPolySmooth(const entity_t *currententity)
d_sfracextrastep = (r_sstepy+r_sstepx*(ubasestep + 1)) & 0xFFFF;
d_tfracextrastep = (r_tstepy+r_tstepx*(ubasestep + 1)) & 0xFFFF;
d_lightextrastep = d_lightbasestep + working_lstepx;
for(i=0; i<3; i++)
d_lightextrastep[i] = d_lightbasestep[i] + working_lstepx[i];
d_ziextrastep = d_zibasestep + r_zistepx;
R_PolysetScanLeftEdge_C(height, d_ptex, u, v);

View file

@ -64,7 +64,6 @@ R_TextureAnimation (const entity_t *currententity, mtexinfo_t *tex)
return tex->image;
}
/*
================
R_DrawSurfaceBlock8_anymip
@ -73,7 +72,7 @@ R_DrawSurfaceBlock8_anymip
static void
R_DrawSurfaceBlock8_anymip (int level, int surfrowbytes)
{
int v, i, b, lightstep, lighttemp, light, size;
int v, i, b, size;
unsigned char pix, *psource, *prowdest;
size = 1 << level;
@ -82,34 +81,51 @@ R_DrawSurfaceBlock8_anymip (int level, int surfrowbytes)
for (v=0 ; v<r_numvblocks ; v++)
{
int lightleft, lightright;
int lightleftstep, lightrightstep;
int lightleft[3], lightright[3];
int lightleftstep[3], lightrightstep[3];
// FIXME: use delta rather than both right and left, like ASM?
lightleft = r_lightptr[0];
lightright = r_lightptr[1];
r_lightptr += r_lightwidth;
lightleftstep = (r_lightptr[0] - lightleft) >> level;
lightrightstep = (r_lightptr[1] - lightright) >> level;
memcpy(lightleft, r_lightptr, sizeof(int) * 3);
memcpy(lightright, r_lightptr + 3, sizeof(int) * 3);
r_lightptr += r_lightwidth * 3;
for(i=0; i<3; i++)
{
lightleftstep[i] = (r_lightptr[i] - lightleft[i]) >> level;
lightrightstep[i] = (r_lightptr[i + 3] - lightright[i]) >> level;
}
for (i=0 ; i<size ; i++)
{
lighttemp = lightleft - lightright;
lightstep = lighttemp >> level;
int lightstep[3], light[3];
int j;
light = lightright;
for(j=0; j<3; j++)
{
int lighttemp;
lighttemp = lightleft[j] - lightright[j];
lightstep[j] = lighttemp >> level;
}
memcpy(light, lightright, sizeof(int) * 3);
for (b=(size-1); b>=0; b--)
{
pix = psource[b];
prowdest[b] = ((unsigned char *)vid_colormap)
[(light & 0xFF00) + pix];
light += lightstep;
prowdest[b] = R_ApplyLight(pix, light);
for(j=0; j<3; j++)
light[j] += lightstep[j];
}
psource += sourcetstep;
lightright += lightrightstep;
lightleft += lightleftstep;
for(j=0; j<3; j++)
{
lightright[j] += lightrightstep[j];
lightleft[j] += lightleftstep[j];
}
prowdest += surfrowbytes;
}
@ -176,7 +192,7 @@ R_DrawSurface (drawsurf_t *drawsurf)
for (u=0 ; u<r_numhblocks; u++)
{
r_lightptr = blocklights + u;
r_lightptr = blocklights + u * 3;
if (r_lightptr >= blocklight_max)
{