From b35415637b47f4cefaa1abcbed109a10a381ceeb Mon Sep 17 00:00:00 2001 From: mittorn Date: Wed, 27 Mar 2019 17:53:42 +0700 Subject: [PATCH] ref_soft: colormap support, basic studiomodel lighting --- r_draw.c | 3 +++ r_glblit.c | 32 ++++++++++++++++++++++++++++++++ r_light.c | 2 ++ r_local.h | 3 ++- r_main.c | 24 ++++++++++++++++-------- r_polyse.c | 15 +++++++++++---- r_studio.c | 1 + r_triapi.c | 17 +++++++++++++---- 8 files changed, 80 insertions(+), 17 deletions(-) diff --git a/r_draw.c b/r_draw.c index 2f6fb211..bffd94b0 100644 --- a/r_draw.c +++ b/r_draw.c @@ -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 ) diff --git a/r_glblit.c b/r_glblit.c index 7b57a68e..20b33ca5 100644 --- a/r_glblit.c +++ b/r_glblit.c @@ -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(); diff --git a/r_light.c b/r_light.c index 08bd4fe3..86157006 100644 --- a/r_light.c +++ b/r_light.c @@ -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) diff --git a/r_local.h b/r_local.h index 209f4e26..56c74af5 100644 --- a/r_local.h +++ b/r_local.h @@ -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? diff --git a/r_main.c b/r_main.c index 3993f12a..d5b01986 100644 --- a/r_main.c +++ b/r_main.c @@ -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: diff --git a/r_polyse.c b/r_polyse.c index 9c760472..0852d2c5 100644 --- a/r_polyse.c +++ b/r_polyse.c @@ -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++; diff --git a/r_studio.c b/r_studio.c index 22e25915..48b2e623 100644 --- a/r_studio.c +++ b/r_studio.c @@ -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 ); } diff --git a/r_triapi.c b/r_triapi.c index cee0ae47..922fbe54 100644 --- a/r_triapi.c +++ b/r_triapi.c @@ -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 )