Browse Source

ref: gl: adapt studio lightning to new gamma

* more accurate SHADE_LAMBERT value (extracted from v_lambert1 global variable)
pull/2/head
Alibek Omarov 10 months ago
parent
commit
64f92003fa
  1. 2
      ref/gl/gl_local.h
  2. 55
      ref/gl/gl_studio.c
  3. 2
      ref/soft/r_local.h

2
ref/gl/gl_local.h

@ -76,7 +76,7 @@ extern poolhandle_t r_temppool;
#define MAX_DRAW_STACK 2 // normal view and menu view #define MAX_DRAW_STACK 2 // normal view and menu view
#define SHADEDOT_QUANT 16 // precalculated dot products for quantized angles #define SHADEDOT_QUANT 16 // precalculated dot products for quantized angles
#define SHADE_LAMBERT 1.495f #define SHADE_LAMBERT 1.4953241
#define DEFAULT_ALPHATEST 0.0f #define DEFAULT_ALPHATEST 0.0f
// refparams // refparams

55
ref/gl/gl_studio.c

@ -103,7 +103,7 @@ typedef struct
int numlocallights; int numlocallights;
int lightage[MAXSTUDIOBONES]; int lightage[MAXSTUDIOBONES];
dlight_t *locallight[MAX_LOCALLIGHTS]; dlight_t *locallight[MAX_LOCALLIGHTS];
color24 locallightcolor[MAX_LOCALLIGHTS]; int locallightcolor[MAX_LOCALLIGHTS][3];
vec4_t lightpos[MAXSTUDIOVERTS][MAX_LOCALLIGHTS]; vec4_t lightpos[MAXSTUDIOVERTS][MAX_LOCALLIGHTS];
vec3_t lightbonepos[MAXSTUDIOBONES][MAX_LOCALLIGHTS]; vec3_t lightbonepos[MAXSTUDIOBONES][MAX_LOCALLIGHTS];
float locallightR2[MAX_LOCALLIGHTS]; float locallightR2[MAX_LOCALLIGHTS];
@ -1381,13 +1381,13 @@ void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight )
{ {
VectorSet( lightDir, mv->skyvec_x, mv->skyvec_y, mv->skyvec_z ); VectorSet( lightDir, mv->skyvec_x, mv->skyvec_y, mv->skyvec_z );
light.r = gEngfuncs.LightToTexGamma( bound( 0, mv->skycolor_r, 255 )); light.r = mv->skycolor_r;
light.g = gEngfuncs.LightToTexGamma( bound( 0, mv->skycolor_g, 255 )); light.g = mv->skycolor_g;
light.b = gEngfuncs.LightToTexGamma( bound( 0, mv->skycolor_b, 255 )); light.b = mv->skycolor_b;
} }
} }
if(( light.r + light.g + light.b ) < 16 ) // TESTTEST if(( light.r + light.g + light.b ) == 0 )
{ {
colorVec gcolor; colorVec gcolor;
float grad[4]; float grad[4];
@ -1466,15 +1466,15 @@ void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight )
VectorAdd( lightDir, dist, lightDir ); VectorAdd( lightDir, dist, lightDir );
finalLight[0] += gEngfuncs.LightToTexGamma( dl->color.r ) * ( add / 256.0f ) * 2.0f; finalLight[0] += dl->color.r * ( add / 256.0f );
finalLight[1] += gEngfuncs.LightToTexGamma( dl->color.g ) * ( add / 256.0f ) * 2.0f; finalLight[1] += dl->color.g * ( add / 256.0f );
finalLight[2] += gEngfuncs.LightToTexGamma( dl->color.b ) * ( add / 256.0f ) * 2.0f; finalLight[2] += dl->color.b * ( add / 256.0f );
} }
} }
if( FBitSet( ent->model->flags, STUDIO_AMBIENT_LIGHT )) if( FBitSet( ent->model->flags, STUDIO_AMBIENT_LIGHT ))
add = 0.6f; add = 0.6f;
else add = 0.9f; else add = bound( 0.75f, v_direct->value, 1.0f );
VectorScale( lightDir, add, lightDir ); VectorScale( lightDir, add, lightDir );
@ -1568,9 +1568,9 @@ void R_StudioEntityLight( alight_t *lightinfo )
if( k != -1 ) if( k != -1 )
{ {
g_studio.locallightcolor[k].r = gEngfuncs.LightToTexGamma( el->color.r ); g_studio.locallightcolor[k][0] = gEngfuncs.LinearGammaTable( el->color.r << 2 );
g_studio.locallightcolor[k].g = gEngfuncs.LightToTexGamma( el->color.g ); g_studio.locallightcolor[k][1] = gEngfuncs.LinearGammaTable( el->color.g << 2 );
g_studio.locallightcolor[k].b = gEngfuncs.LightToTexGamma( el->color.b ); g_studio.locallightcolor[k][2] = gEngfuncs.LinearGammaTable( el->color.b << 2 );
g_studio.locallightR2[k] = r2; g_studio.locallightR2[k] = r2;
g_studio.locallight[k] = el; g_studio.locallight[k] = el;
lstrength[k] = minstrength; lstrength[k] = minstrength;
@ -1665,7 +1665,8 @@ void R_StudioLighting( float *lv, int bone, int flags, vec3_t normal )
} }
illum = Q_min( illum, 255.0f ); illum = Q_min( illum, 255.0f );
*lv = illum * (1.0f / 255.0f);
*lv = gEngfuncs.LightToTexGammaEx( illum * 4 ) / 1023.0f;
} }
/* /*
@ -1685,7 +1686,7 @@ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal,
return; return;
} }
VectorCopy( color, finalLight ); VectorSet( finalLight, 0, 0, 0 );
for( i = 0; i < g_studio.numlocallights; i++ ) for( i = 0; i < g_studio.numlocallights; i++ )
{ {
@ -1709,21 +1710,29 @@ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal,
else light[i][3] = 0.0001f; else light[i][3] = 0.0001f;
} }
temp = Q_min( r * light[i][3] / 255.0f, 1.0f ); temp = r * light[i][3];
localLight[0] = (float)g_studio.locallightcolor[i].r * temp;
localLight[1] = (float)g_studio.locallightcolor[i].g * temp;
localLight[2] = (float)g_studio.locallightcolor[i].b * temp;
VectorAddScalar( g_studio.locallightcolor[i], temp, localLight );
VectorAdd( finalLight, localLight, finalLight ); VectorAdd( finalLight, localLight, finalLight );
} }
} }
VectorScale( finalLight, 255.0f, finalLight ); if( !VectorIsNull( finalLight ))
{
for( i = 0; i < 3; i++ )
{
float c = finalLight[i] + gEngfuncs.LinearGammaTable( color[i] * 1023.0f );
out[0] = Q_min( (int)( finalLight[0] ), 255 ); if( c > 1023.0f )
out[1] = Q_min( (int)( finalLight[1] ), 255 ); out[i] = 255;
out[2] = Q_min( (int)( finalLight[2] ), 255 ); else
out[i] = gEngfuncs.ScreenGammaTable( c ) >> 2;
}
}
else
{
VectorScale( color, 255.0f, out );
}
} }
static void R_StudioSetColorArray( short *ptricmds, vec3_t *pstudionorms, byte *color ) static void R_StudioSetColorArray( short *ptricmds, vec3_t *pstudionorms, byte *color )

2
ref/soft/r_local.h

@ -66,7 +66,7 @@ extern poolhandle_t r_temppool;
#define MAX_DRAW_STACK 2 // normal view and menu view #define MAX_DRAW_STACK 2 // normal view and menu view
#define SHADEDOT_QUANT 16 // precalculated dot products for quantized angles #define SHADEDOT_QUANT 16 // precalculated dot products for quantized angles
#define SHADE_LAMBERT 1.495f #define SHADE_LAMBERT 1.4953241
#define DEFAULT_ALPHATEST 0.0f #define DEFAULT_ALPHATEST 0.0f
// refparams // refparams

Loading…
Cancel
Save