ref_soft: colormap support, basic studiomodel lighting

This commit is contained in:
mittorn 2019-03-27 17:53:42 +07:00
parent 35e42a2295
commit b35415637b
8 changed files with 80 additions and 17 deletions

View File

@ -299,6 +299,9 @@ R_Set2DMode
void R_Set2DMode( qboolean enable )
{
vid.color = COLOR_WHITE;
vid.is2d = enable;
vid.alpha = 7;
if( enable )
{
// if( glState.in2DMode )

View File

@ -133,6 +133,7 @@ void R_BuildBlendMaps()
{
unsigned int r1, g1, b1;
unsigned int r2, g2, b2;
unsigned int i, j;
FOR_EACH_COLOR(1)FOR_EACH_COLOR(2)
{
@ -169,6 +170,37 @@ void R_BuildBlendMaps()
}
}
for( i = 0; i < 8192; i++ )
{
unsigned int r, g, b;
uint color = i << 3;
uint m = color >> 8;
uint j = color & 0xff;
r1 = ((m >> (8 - 3) )<< 2 ) & MASK(5);
g1 = ((m >> (8 - 3 - 3)) << 3) & MASK(6);
b1 = ((m >> (8 - 3 - 3 - 2)) << 3) & MASK(5);
r1 |= MOVE_BIT(j, 5, 1) | MOVE_BIT(j, 2, 0);
g1 |= MOVE_BIT(j, 7, 2) | MOVE_BIT(j, 4, 1) | MOVE_BIT(j, 1, 0);
b1 |= MOVE_BIT(j, 6, 2) | MOVE_BIT(j, 3, 1) | MOVE_BIT(j, 0, 0);
unsigned short index1 = i;
for( j = 0; j < 32; j++)
{
unsigned int index2 = j << 13;
unsigned int major, minor;
r = r1 * j / 32;
g = g1 * j / 32;
b = b1 * j / 32;
major = (((r >> 2) & MASK(3)) << 5) |( (( (g >> 3) & MASK(3)) << 2 ) )| (((b >> 3) & MASK(2)));
// save minor GBRGBRGB
minor = MOVE_BIT(r,1,5) | MOVE_BIT(r,0,2) | MOVE_BIT(g,2,7) | MOVE_BIT(g,1,4) | MOVE_BIT(g,0,1) | MOVE_BIT(b,2,6)| MOVE_BIT(b,1,3)|MOVE_BIT(b,0,0);
vid.colormap[index2|index1] = major << 8 | (minor & 0xFF);
}
}
}
void R_AllocScreen();

View File

@ -472,6 +472,8 @@ colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lspot, vec3_t
{
colorVec light = R_LightVecInternal( start, end, lspot, lvec );
light.r = light.g = light.b = 255;
if( lspot != NULL && lvec != NULL ) // CVAR_TO_BOOL( r_lighting_extended ) &&
{
// trying to get light from ceiling (but ignore gradient analyze)

View File

@ -133,7 +133,7 @@ typedef struct vrect_s
typedef struct
{
pixel_t *buffer; // invisible buffer
pixel_t *colormap; // 256 * VID_GRADES size
pixel_t colormap[32*8192]; // 8192 * light levels
//pixel_t *alphamap; // 256 * 256 translucency map
#ifdef SEPARATE_BLIT
pixel_t screen_minor[256];
@ -146,6 +146,7 @@ typedef struct
byte modmap[256*256];
byte alphamap[8*256*256];
pixel_t color;
qboolean is2d;
byte alpha;
// maybe compute colormask for minor byte?

View File

@ -517,6 +517,7 @@ R_SetupFrustum
*/
void R_SetupFrustum( void )
{
AngleVectors( RI.viewangles, RI.vforward, RI.vright, RI.vup );
#if 0
ref_overview_t *ov = gEngfuncs.GetOverviewParms();
@ -1034,20 +1035,27 @@ void R_DrawEntitiesOnList( void )
//R_DrawAliasModel( RI.currententity );
break;
case mod_studio:
//R_DrawStudioModel( RI.currententity );
/*{finalvert_t fv[3];
R_DrawStudioModel( RI.currententity );
#if 0
// gradient debug (for colormap testing)
{finalvert_t fv[3];
void R_AliasSetUpTransform (void);
extern void (*d_pdrawspans)(void *);
extern void R_PolysetFillSpans8 ( void * );
d_pdrawspans = R_PolysetFillSpans8;
//RI.currententity = gEngfuncs.GetEntityByIndex(0);
R_AliasSetUpTransform();
R_SetupFinalVert( &fv[0], -10, -10, 5, 0, 0, 0);
R_SetupFinalVert( &fv[1], -10, 10, 10, 0, 0, 0);
R_SetupFinalVert( &fv[2], 10, 10, -10, 0, 0, 0);
R_RenderTriangle( &fv );
}*/
R_DrawStudioModel( RI.currententity );
image_t *image = R_GetTexture(GL_LoadTexture("gfx/env/desertbk", NULL, 0, 0));
r_affinetridesc.pskin = image->pixels[0];
r_affinetridesc.skinwidth = image->width;
r_affinetridesc.skinheight = image->height;
R_SetupFinalVert( &fv[0], 0, -50, 50, 31 << 8, 0, 0);
R_SetupFinalVert( &fv[1], 0, 50, 50, 0 << 8, image->width, 0);
R_SetupFinalVert( &fv[2], 0, 0, 0, 0 << 8, image->width/2, image->height);
R_RenderTriangle( &fv[0], &fv[1], &fv[2] );
}
#endif
break;
default:

View File

@ -1145,11 +1145,11 @@ void R_PolysetFillSpans8 (spanpackage_t *pspanpackage)
#else
void R_PolysetFillSpans8 (spanpackage_t *pspanpackage)
{
int color;
//int color;
int lcount;
// FIXME: do z buffering
color = d_aflatcolor++ * 10;
//color = d_aflatcolor++ * 10;
do
{
@ -1191,8 +1191,15 @@ void R_PolysetFillSpans8 (spanpackage_t *pspanpackage)
/*if(r_newrefdef.rdflags & RDF_IRGOGGLES && RI.currententity->flags & RF_IR_VISIBLE)
*lpdest = ((byte *)vid.colormap)[irtable[*lptex]];
else*/
*lpdest = *lptex; //((byte *)vid.colormap)[*lptex + (llight & 0xFF00)];
//PGM
//*lpdest = *lptex; //((byte *)vid.colormap)[*lptex + (llight & 0xFF00)];
uint src = *lptex;
//*lpdest = //vid.colormap[src & 0xff00|(llight>>8)] << 8 | (src & llight & 0xff) | ((src & 0xff) >> 3);
// very dirty, maybe need dual colormap?
//*lpdest = (vid.colormap[src >> 8 | (llight & 0xFF00)] << 8) | src & 0xff;
// 13 bit lighting, 32 light levels
*lpdest = vid.colormap[(src >> 3) | ((llight & 0x1F00) << 5)] | src & 7;
//PGM
*lpz = lzi >> 16;
}
lpdest++;

View File

@ -1770,6 +1770,7 @@ static void R_StudioSetColorBegin(short *ptricmds, vec3_t *pstudionorms )
color[3] = tr.blend * 255;
VectorCopy( (byte*)&RI.currententity->curstate.rendercolor, color );
//pglColor4ubv( color );
TriColor4ub(color[0], color[1], color[2], color[3]);
}
else _TriColor4f( lv[0], lv[1], lv[2], tr.blend );
}

View File

@ -27,6 +27,7 @@ finalvert_t triv[3];
int vertcount, n;
int mode;
short s,t;
uint light;
/*
===============================================================
@ -145,17 +146,25 @@ void _TriColor4f( float rr, float gg, float bb, float aa )
unsigned int major, minor;
//gEngfuncs.Con_Printf("%d\n", vid.alpha);
light = (rr + gg + bb) * 31 / 3;
if( light > 31 )
light = 31;
if( !vid.is2d )
return;
vid.alpha = aa * 7;
if( vid.alpha > 7 )
vid.alpha = 7;
//gEngfuncs.Con_Printf("%d\n", vid.alpha);
if( rr == 1 && gg == 1 && bb == 1 )
{
vid.color = COLOR_WHITE;
return;
}
r = rr * 31, g = gg * 63, b = bb * 31;
@ -235,7 +244,7 @@ void TriVertex3f( float x, float y, float z )
{
if( mode == TRI_TRIANGLE_FAN )
{
R_SetupFinalVert( &triv[vertcount], x, y, z, 0,s,t);
R_SetupFinalVert( &triv[vertcount], x, y, z, light << 8,s,t);
vertcount++;
if( vertcount >= 3 )
{
@ -246,7 +255,7 @@ void TriVertex3f( float x, float y, float z )
}
if( mode == TRI_TRIANGLE_STRIP )
{
R_SetupFinalVert( &triv[n], x, y, z, 0,s,t);
R_SetupFinalVert( &triv[n], x, y, z, light << 8,s,t);
n++;
vertcount++;
if( n == 3 )