From d35f7350fe10bb05c8d9dc95fa69d5a6f1d487c5 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Mon, 30 Mar 2020 10:40:38 +0200 Subject: [PATCH] GLSL: Some rendering tweaks (default gl_ldr and gl_halflambert (new) to 1) --- src/gs-entbase/server/basemonster.cpp | 3 +- src/gs-entbase/server/basenpc.cpp | 3 +- valve/data.pk3dir/glsl/defaultskin.glsl | 19 +++++--- valve/data.pk3dir/glsl/defaultwall.glsl | 64 ++++++++++++++++++------- 4 files changed, 63 insertions(+), 26 deletions(-) diff --git a/src/gs-entbase/server/basemonster.cpp b/src/gs-entbase/server/basemonster.cpp index 548003f0..899a2c31 100644 --- a/src/gs-entbase/server/basemonster.cpp +++ b/src/gs-entbase/server/basemonster.cpp @@ -312,10 +312,9 @@ void CBaseMonster::Physics(void) } /* support for think/nextthink */ - if (think && nextthink > 0.0) { + if (think && nextthink > 0.0f) { if (nextthink < time) { nextthink = 0.0f; - print("^2CBaseMonster::Physics: Trigger think()\n"); think(); } } diff --git a/src/gs-entbase/server/basenpc.cpp b/src/gs-entbase/server/basenpc.cpp index 4d07c656..495e2d2c 100644 --- a/src/gs-entbase/server/basenpc.cpp +++ b/src/gs-entbase/server/basenpc.cpp @@ -517,10 +517,9 @@ CBaseNPC::Physics(void) } /* support for think/nextthink */ - if (think && nextthink > 0.0) { + if (think && nextthink > 0.0f) { if (nextthink < time) { nextthink = 0.0f; - print("^2CBaseMonster::Physics: Trigger think()\n"); think(); } } diff --git a/valve/data.pk3dir/glsl/defaultskin.glsl b/valve/data.pk3dir/glsl/defaultskin.glsl index ea5e63bb..a32f8ac3 100644 --- a/valve/data.pk3dir/glsl/defaultskin.glsl +++ b/valve/data.pk3dir/glsl/defaultskin.glsl @@ -4,7 +4,8 @@ !!permu FOG !!samps diffuse reflectcube !!cvardf gl_affinemodels=0 -!!cvardf gl_ldr=0 +!!cvardf gl_ldr=1 +!!cvardf gl_halflambert=1 #include "sys/defs.h" @@ -25,7 +26,10 @@ varying vec3 light; #ifdef VERTEX_SHADER #include "sys/skeletal.h" - float hl( vec3 normal, vec3 dir ) { + float lambert( vec3 normal, vec3 dir ) { + return dot( normal, dir ); + } + float halflambert( vec3 normal, vec3 dir ) { return ( dot( normal, dir ) * 0.5 ) + 0.5; } @@ -50,12 +54,15 @@ varying vec3 light; vec3 n, s, t, w; gl_Position = skeletaltransform_wnst(w,n,s,t); tex_c = v_texcoord; - light = e_light_ambient + (e_light_mul * hl(n, e_light_dir)); + + if (gl_halflambert == 1.0) { + light = e_light_ambient + (e_light_mul * halflambert(n, e_light_dir)); + } else { + light = e_light_ambient + (e_light_mul * lambert(n, e_light_dir)); + } if (gl_ldr == 1.0) { - if (light.r > 1.0) light.r = 1.0; - if (light.g > 1.0) light.g = 1.0; - if (light.b > 1.0) light.b = 1.0; + light *= 0.75; } #ifdef CHROME vec3 rorg = rlv(vec3(0,0,0), w, e_light_dir); diff --git a/valve/data.pk3dir/glsl/defaultwall.glsl b/valve/data.pk3dir/glsl/defaultwall.glsl index 2dd20328..ab8b4a38 100644 --- a/valve/data.pk3dir/glsl/defaultwall.glsl +++ b/valve/data.pk3dir/glsl/defaultwall.glsl @@ -1,10 +1,18 @@ !!ver 110 -!!samps diffuse lightmap reflectcube normalmap +!!permu LIGHTSTYLED +!!samps diffuse reflectcube normalmap + +!!samps lightmap +!!samps =LIGHTSTYLED lightmap1 lightmap2 lightmap3 #include "sys/defs.h" varying vec2 tex_c; -varying vec2 lm_c; + +varying vec2 lm0; +#ifdef LIGHTSTYLED +varying vec2 lm1, lm2, lm3; +#endif #ifdef REFLECTCUBE varying vec3 eyevector; @@ -12,10 +20,20 @@ varying mat3 invsurface; #endif #ifdef VERTEX_SHADER + void lightmapped_init(void) + { + lm0 = v_lmcoord; + #ifdef LIGHTSTYLED + lm1 = v_lmcoord2; + lm2 = v_lmcoord3; + lm3 = v_lmcoord4; + #endif + } + void main () { + lightmapped_init(); tex_c = v_texcoord; - lm_c = v_lmcoord; gl_Position = ftetransform(); #ifdef REFLECTCUBE @@ -31,10 +49,34 @@ varying mat3 invsurface; #endif #ifdef FRAGMENT_SHADER + + vec3 lightmap_fragment(void) + { + vec3 lightmaps; + +#ifdef LIGHTSTYLED + lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb; + lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb; + lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb; + lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb; +#else + lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb; +#endif + return lightmaps; + } + void main ( void ) { vec4 diffuse_f = texture2D(s_diffuse, tex_c); - vec3 light = texture2D(s_lightmap, lm_c).rgb * e_lmscale.rgb; + +/* get the alphatesting out of the way first */ +#ifdef MASK + if (diffuse_f.a < 0.6) { + discard; + } +#endif + /* lighting */ + diffuse_f.rgb *= lightmap_fragment(); #ifdef REFLECTCUBE #ifdef BUMP @@ -53,24 +95,14 @@ varying mat3 invsurface; vec3 normal_f = vec3(0, 0, 1); #endif vec3 cube_c; - vec4 out_f = vec4( 1.0, 1.0, 1.0, 1.0 ); - diffuse_f.rgb *= light.rgb; cube_c = reflect( normalize(-eyevector), normal_f); cube_c = cube_c.x * invsurface[0] + cube_c.y * invsurface[1] + cube_c.z * invsurface[2]; cube_c = ( m_model * vec4(cube_c.xyz, 0.0)).xyz; - out_f.rgb = mix( textureCube(s_reflectcube, cube_c ).rgb, diffuse_f.rgb, diffuse_f.a); - diffuse_f = out_f; -#else - diffuse_f.rgb *= light.rgb; -#ifdef MASK - if (diffuse_f.a < e_colourident.a) { - discard; - } + diffuse_f.rgb = mix( textureCube(s_reflectcube, cube_c ).rgb, diffuse_f.rgb, diffuse_f.a); #endif -#endif - diffuse_f *= e_colourident; + diffuse_f *= e_colourident; gl_FragColor = diffuse_f; }