Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkokko committed Jan 20, 2024
1 parent 6f82e35 commit 4623792
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 370 deletions.
12 changes: 11 additions & 1 deletion csldr/studio_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,19 @@ studio_shader_t *R_StudioSelectShader(int options)
String defines = { buffer, sizeof(buffer), 0 };

if (studio_gpuskin)
StringAppend(&defines, "#version 150 compatibility\n#define GPU_SKINNING\n");
{
// we can't use glsl 1.20 because most drivers will syntax error
// on the std140 ubo. use glsl 1.50 in compat profile if we can,
// otherwise use glsl 1.20 and hope that it'll work on this card...
if (GLVersion.major >= 3 && GLVersion.minor >= 2)
StringAppend(&defines, "#version 150 compatibility\n#define GPU_SKINNING\n");
else
StringAppend(&defines, "#version 120\n#define GPU_SKINNING\n");
}
else
{
StringAppend(&defines, "#version 110\n");
}

for (size_t j = 0; j < Q_ARRAYSIZE(option_info); j++)
{
Expand Down
2 changes: 1 addition & 1 deletion shaders/studio.frag
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ uniform bool u_tex_masked;
void main()
{
vec4 tex = texture2D(u_texture, f_texcoord);

// mikkotodo should do this after applying color and fog
// but that broke everything so i didn't do it yet
#if defined(CAN_MASKED)
Expand Down
46 changes: 16 additions & 30 deletions shaders/studio.vert
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ uniform vec3 u_chromeorg;
uniform vec3 u_chromeright;
#endif

#if !defined(HAVE_ADDITIVE) && !defined(HAVE_GLOWHSELL)
#if !defined(HAVE_ADDITIVE) && !defined(HAVE_GLOWSHELL)
uniform float u_ambientlight;
uniform float u_shadelight;
uniform vec3 u_lightvec;
Expand All @@ -41,7 +41,7 @@ uniform float u_brightness;
uniform float u_g3;
#endif

#if defined(HAVE_ELIGHTS) || (!defined(HAVE_ADDITIVE) && !defined(HAVE_GLOWHSELL))
#if defined(HAVE_ELIGHTS) || (!defined(HAVE_ADDITIVE) && !defined(HAVE_GLOWSHELL))
uniform float u_invgamma;
#endif

Expand All @@ -67,7 +67,7 @@ uniform vec3 u_elight_color[MAX_ELIGHTS];
// engine's v_lambert1, doesn't change
#define LAMBERT 1.4953241

#if !defined(HAVE_ADDITIVE) && !defined(HAVE_GLOWHSELL)
#if !defined(HAVE_ADDITIVE) && !defined(HAVE_GLOWSHELL)
float gamma_correct(float value)
{
float f = pow(value, u_lightgamma) * max(u_brightness, 1.0);
Expand All @@ -91,18 +91,10 @@ void main()
{
#if defined(GPU_SKINNING)
mat3x4 bone = u_bones[int(a_bones.x)];

vec3 pos_anim = vec3(
dot(a_pos, vec3(bone[0])) + bone[0][3],
dot(a_pos, vec3(bone[1])) + bone[1][3],
dot(a_pos, vec3(bone[2])) + bone[2][3]);

mat3x4 bone_normal = u_bones[int(a_bones.y)];

vec3 normal_anim = vec3(
dot(a_normal, vec3(bone[0])),
dot(a_normal, vec3(bone[1])),
dot(a_normal, vec3(bone[2])));
vec3 pos_anim = vec4(a_pos, 1.0) * bone;
vec3 normal_anim = a_normal * mat3(bone_normal);
#else
// already animated on the cpu
vec3 pos_anim = a_pos;
Expand All @@ -124,15 +116,9 @@ void main()
vec3 up = normalize(cross(dir, u_chromeright));
vec3 side = normalize(cross(dir, up));

vec3 up_anim = vec3(
up[0] * bone_normal[0][0] + up[1] * bone_normal[1][0] + up[2] * bone_normal[2][0],
up[0] * bone_normal[0][1] + up[1] * bone_normal[1][1] + up[2] * bone_normal[2][1],
up[0] * bone_normal[0][2] + up[1] * bone_normal[1][2] + up[2] * bone_normal[2][2]);

vec3 side_anim = vec3(
side[0] * bone_normal[0][0] + side[1] * bone_normal[1][0] + side[2] * bone_normal[2][0],
side[0] * bone_normal[0][1] + side[1] * bone_normal[1][1] + side[2] * bone_normal[2][1],
side[0] * bone_normal[0][2] + side[1] * bone_normal[1][2] + side[2] * bone_normal[2][2]);
mat3 mat = transpose(mat3(bone_normal));
vec3 up_anim = up * mat;
vec3 side_anim = side * mat;

// mikkotodo why the fuck this this needed???
f_texcoord.x = 1.0 - (dot(a_normal, side_anim) + 1.0) * 0.5;
Expand All @@ -153,7 +139,7 @@ void main()
#elif defined(HAVE_ADDITIVE)
f_color = vec4(vec3(u_colormix.a), 1.0);
#else

#if defined(CAN_FULLBRIGHT)
if (u_tex_fullbright)
{
Expand Down Expand Up @@ -194,21 +180,21 @@ void main()
// add elights, if any
#if defined(HAVE_ELIGHTS)
vec3 elights = vec3(0);

for (int i = 0; i < MAX_ELIGHTS; i++)
{
vec3 dir = u_elight_pos[i].xyz - pos_anim;
float NdotL = max(dot(normal_anim, dir), 0.0); // don't normalize!!!

// wtf is this attenuation
float mag_squared = dot(dir, dir);
float rad_squared = u_elight_pos[i].w;

float atten = rad_squared / (mag_squared * sqrt(mag_squared));

elights += u_elight_color[i] * NdotL * atten;
}

f_color.rgb = elight_gamma(f_color.rgb, elights);
#endif
}
Expand All @@ -220,13 +206,13 @@ void main()
#ifdef HAVE_FOG
// wtf is gl_FogCoord
float fog_coord = result.w;

#ifdef HAVE_FOG_LINEAR
f_fog = (gl_Fog.end - fog_coord) * gl_Fog.scale;
#else
f_fog = exp(-gl_Fog.density * gl_Fog.density * fog_coord * fog_coord);
#endif

f_fog = clamp(f_fog, 0.0, 1.0);
#endif

Expand Down
60 changes: 30 additions & 30 deletions shaders/studio_frag.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@ unsigned char studio_frag[] = {
0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x28, 0x75,
0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x66, 0x5f,
0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x29, 0x3b, 0x0d, 0x0a,
0x09, 0x0d, 0x0a, 0x09, 0x2f, 0x2f, 0x20, 0x6d, 0x69, 0x6b, 0x6b, 0x6f,
0x74, 0x6f, 0x64, 0x6f, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x20,
0x64, 0x6f, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x61, 0x66, 0x74, 0x65,
0x72, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x63,
0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6f, 0x67,
0x0d, 0x0a, 0x09, 0x2f, 0x2f, 0x20, 0x62, 0x75, 0x74, 0x20, 0x74, 0x68,
0x61, 0x74, 0x20, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x20, 0x65, 0x76, 0x65,
0x72, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x6f, 0x20, 0x69,
0x20, 0x64, 0x69, 0x64, 0x6e, 0x27, 0x74, 0x20, 0x64, 0x6f, 0x20, 0x69,
0x74, 0x20, 0x79, 0x65, 0x74, 0x0d, 0x0a, 0x23, 0x69, 0x66, 0x20, 0x64,
0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x43, 0x41, 0x4e, 0x5f, 0x4d,
0x41, 0x53, 0x4b, 0x45, 0x44, 0x29, 0x0d, 0x0a, 0x09, 0x69, 0x66, 0x20,
0x28, 0x75, 0x5f, 0x74, 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x73, 0x6b, 0x65,
0x64, 0x20, 0x26, 0x26, 0x20, 0x74, 0x65, 0x78, 0x2e, 0x61, 0x20, 0x3c,
0x20, 0x30, 0x2e, 0x35, 0x29, 0x0d, 0x0a, 0x09, 0x09, 0x64, 0x69, 0x73,
0x63, 0x61, 0x72, 0x64, 0x3b, 0x0d, 0x0a, 0x23, 0x65, 0x6e, 0x64, 0x69,
0x66, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x76, 0x65, 0x63, 0x34, 0x20, 0x72,
0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x20,
0x2a, 0x20, 0x66, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0d, 0x0a,
0x0d, 0x0a, 0x23, 0x69, 0x66, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65,
0x64, 0x28, 0x48, 0x41, 0x56, 0x45, 0x5f, 0x46, 0x4f, 0x47, 0x29, 0x0d,
0x0a, 0x09, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x72, 0x67, 0x62,
0x20, 0x3d, 0x20, 0x6d, 0x69, 0x78, 0x28, 0x67, 0x6c, 0x5f, 0x46, 0x6f,
0x67, 0x2e, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x2e, 0x72, 0x67, 0x62, 0x2c,
0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x72, 0x67, 0x62, 0x2c,
0x20, 0x66, 0x5f, 0x66, 0x6f, 0x67, 0x29, 0x3b, 0x0d, 0x0a, 0x23, 0x65,
0x6e, 0x64, 0x69, 0x66, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x67, 0x6c, 0x5f,
0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20,
0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x3b, 0x0d, 0x0a, 0x7d, 0x0d, 0x0a
0x0d, 0x0a, 0x09, 0x2f, 0x2f, 0x20, 0x6d, 0x69, 0x6b, 0x6b, 0x6f, 0x74,
0x6f, 0x64, 0x6f, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x64,
0x6f, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72,
0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x63, 0x6f,
0x6c, 0x6f, 0x72, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6f, 0x67, 0x0d,
0x0a, 0x09, 0x2f, 0x2f, 0x20, 0x62, 0x75, 0x74, 0x20, 0x74, 0x68, 0x61,
0x74, 0x20, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x20, 0x65, 0x76, 0x65, 0x72,
0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x6f, 0x20, 0x69, 0x20,
0x64, 0x69, 0x64, 0x6e, 0x27, 0x74, 0x20, 0x64, 0x6f, 0x20, 0x69, 0x74,
0x20, 0x79, 0x65, 0x74, 0x0d, 0x0a, 0x23, 0x69, 0x66, 0x20, 0x64, 0x65,
0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x43, 0x41, 0x4e, 0x5f, 0x4d, 0x41,
0x53, 0x4b, 0x45, 0x44, 0x29, 0x0d, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x28,
0x75, 0x5f, 0x74, 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x73, 0x6b, 0x65, 0x64,
0x20, 0x26, 0x26, 0x20, 0x74, 0x65, 0x78, 0x2e, 0x61, 0x20, 0x3c, 0x20,
0x30, 0x2e, 0x35, 0x29, 0x0d, 0x0a, 0x09, 0x09, 0x64, 0x69, 0x73, 0x63,
0x61, 0x72, 0x64, 0x3b, 0x0d, 0x0a, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66,
0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x76, 0x65, 0x63, 0x34, 0x20, 0x72, 0x65,
0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x20, 0x2a,
0x20, 0x66, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0d, 0x0a, 0x0d,
0x0a, 0x23, 0x69, 0x66, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64,
0x28, 0x48, 0x41, 0x56, 0x45, 0x5f, 0x46, 0x4f, 0x47, 0x29, 0x0d, 0x0a,
0x09, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x72, 0x67, 0x62, 0x20,
0x3d, 0x20, 0x6d, 0x69, 0x78, 0x28, 0x67, 0x6c, 0x5f, 0x46, 0x6f, 0x67,
0x2e, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x2e, 0x72, 0x67, 0x62, 0x2c, 0x20,
0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x72, 0x67, 0x62, 0x2c, 0x20,
0x66, 0x5f, 0x66, 0x6f, 0x67, 0x29, 0x3b, 0x0d, 0x0a, 0x23, 0x65, 0x6e,
0x64, 0x69, 0x66, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x67, 0x6c, 0x5f, 0x46,
0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x72,
0x65, 0x73, 0x75, 0x6c, 0x74, 0x3b, 0x0d, 0x0a, 0x7d, 0x0d, 0x0a
};
unsigned int studio_frag_len = 612;
unsigned int studio_frag_len = 611;
Loading

0 comments on commit 4623792

Please sign in to comment.