Menu-FN & GLSL: Hack to allow for .colormap style top/bottom color

onto vertexlit entities. Requires .colormod[2] to be 2.
Used by the menu with MODEL_PREVIEW.
This commit is contained in:
Marco Cawthorne 2021-08-27 21:52:41 +02:00
parent 6de82ca18c
commit 4952e7fbe0
3 changed files with 78 additions and 3 deletions

View File

@ -133,6 +133,65 @@ varying vec3 light;
return texture2D(targ, texc + coord_ofs * size);
}
vec3 hsv2rgb(float h, float s, float v)
{
int i;
float f,p,q,t;
vec3 col = vec3(0,0,0);
h = max(0.0, min(360.0, h));
s = max(0.0, min(100.0, s));
v = max(0.0, min(100.0, v));
s /= 100;
v /= 100;
if (s == 0) {
col.x= col.y = col.z = int(v*255);
return col / 255.0;
}
h /= 60;
i = int(floor(h));
f = h - i;
p = v * (1 - s);
q = v * (1 - s * f);
t = v * (1 - s * (1 - f));
switch (i) {
case 0:
col[0] = int(255*v);
col[1] = int(255*t);
col[2] = int(255*p);
break;
case 1:
col[0] = int(255*q);
col[1] = int(255*v);
col[2] = int(255*p);
break;
case 2:
col[0] = int(255*p);
col[1] = int(255*v);
col[2] = int(255*t);
break;
case 3:
col[0] = int(255*p);
col[1] = int(255*q);
col[2] = int(255*v);
break;
case 4:
col[0] = int(255*t);
col[1] = int(255*p);
col[2] = int(255*v);
break;
default:
col[0] = int(255*v);
col[1] = int(255*p);
col[2] = int(255*q);
}
return col / 255.0;
}
void main ()
{
vec4 diffuse_f;
@ -149,11 +208,24 @@ varying vec3 light;
#ifdef UPPER
vec4 uc = texture2D(s_upper, tex_c);
diffuse_f.rgb += uc.rgb*e_uppercolour*uc.a;
if (e_colourident.z == 2.0) {
vec3 topcolor = hsv2rgb(e_colourident.x * 360, 100, 100);
diffuse_f.rgb += uc.rgb*topcolor*uc.a;
} else {
diffuse_f.rgb += uc.rgb*e_uppercolour*uc.a;
}
#endif
#ifdef LOWER
vec4 lc = texture2D(s_lower, tex_c);
diffuse_f.rgb += lc.rgb*e_lowercolour*lc.a;
if (e_colourident.z == 2.0) {
vec3 bottomcolor = hsv2rgb(e_colourident.y * 360, 100, 100);
diffuse_f.rgb += lc.rgb*bottomcolor*lc.a;
} else {
diffuse_f.rgb += lc.rgb*e_lowercolour*lc.a;
}
#endif
diffuse_f.rgb *= light;
@ -169,7 +241,9 @@ varying vec3 light;
diffuse_f = out_f;
#endif
if (e_colourident.z != 2.0) {
diffuse_f *= e_colourident;
}
#if gl_stipplealpha==1
float alpha = e_colourident.a;

View File

@ -258,7 +258,6 @@ menu_customize_init(void)
static vector vecDistance = [ 45, 0, 0 ];
static void ModelPreview_SetModel( string strModel ) {
setmodel( eModel, strModel );
eModel.colormap = 0;
AngleVectors( cz_3dModel.Get3DAngles() );
cz_3dModel.Set3DPos( v_forward * -vecDistance[0] + v_right * vecDistance[1] + v_up * vecDistance[2] );
}
@ -272,6 +271,7 @@ menu_customize_init(void)
}
addentity( eModel );
eModel.frame1time += frametime;
eModel.colormod = [cz_sldTopcolor.m_value, cz_sldBottomcolor.m_value, 2.0];
}
static void ModelPreview_Input ( float type, float x, float y, float flDevID ) {
if (type == IE_KEYUP && x == K_MOUSE1 && Util_CheckMouse(414, 340, 64, 24) == TRUE) {

View File

@ -1,4 +1,5 @@
noref .vector colormod;
noref .vector angles;
noref .float colormap;
noref .float frame, frame2, lerpfrac, renderflags, frame1time;