1
0
Fork 0
forked from fte/fteqw

HL2 Plugin Improvements (#290)

* HL2 plugin: bunch of vmt parsing additions, and a hack to load old Left4Dead .vpk files.
This commit is contained in:
Marco Cawthorne 2024-10-20 20:17:40 -07:00 committed by GitHub
parent 2b2ff7a6fa
commit e4c4938efe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 530 additions and 228 deletions

View file

@ -1,6 +1,6 @@
all: mat_vmt_progs.h
VMTPROGSBASE=lightmapped refract transition unlit vertexlit water
VMTPROGSBASE=lightmapped refract transition unlit vertexlit water rt
VMTPROGS:=$(foreach p,$(VMTPROGSBASE),vmt/$p)
VMTPROGSFILES:=$(foreach p,$(VMTPROGS),glsl/$p.glsl)
mat_vmt_progs.h: $(VMTPROGSFILES)

View file

@ -433,6 +433,7 @@ static searchpathfuncs_t *QDECL FSVPK_LoadArchive (vfsfile_t *file, searchpathfu
int read;
qbyte *tree;
unsigned int frag;
unsigned int tablesize;
packhandle = file;
if (packhandle == NULL)
@ -454,21 +455,30 @@ static searchpathfuncs_t *QDECL FSVPK_LoadArchive (vfsfile_t *file, searchpathfu
if (read < 12 || header.magic != 0x55aa1234 || header.tablesize <= 0)
{ //this will include the non-dir files too.
// Con_Printf("%s is not a vpk\n", desc);
return NULL;
}
i = LittleLong(header.version);
if (i == 2)
;//VFS_SEEK(packhandle, 7*sizeof(int));
else if (i == 1)
VFS_SEEK(packhandle, 3*sizeof(int));
else
{
Con_Printf("vpk %s is version %x (unspported)\n", desc, i);
return NULL;
}
tree = plugfuncs->Malloc(header.tablesize);
read = VFS_READ(packhandle, tree, header.tablesize);
/* HACK: pre 2009 Left4Dead */
if (header.magic == 7630198) {
VFS_SEEK(packhandle, 0);
tablesize = 1313113;
} else {
return NULL;
}
} else {
i = LittleLong(header.version);
if (i == 2)
;//VFS_SEEK(packhandle, 7*sizeof(int));
else if (i == 1)
VFS_SEEK(packhandle, 3*sizeof(int));
else
{
Con_Printf("vpk %s is version %x (unspported)\n", desc, i);
return NULL;
}
tablesize = header.tablesize;
}
tree = plugfuncs->Malloc(tablesize);
read = VFS_READ(packhandle, tree, tablesize);
numpackfiles = FSVPK_WalkTree(NULL, tree, tree+read);

View file

@ -2,13 +2,16 @@
!!permu FOG
!!permu BUMP
!!permu LIGHTSTYLED
!!permu FULLBRIGHT
!!permu REFLECTCUBEMASK
!!permu NOFOG
!!samps diffuse
!!samps lightmap
!!samps =LIGHTSTYLED lightmap1 lightmap2 lightmap3
!!samps =BUMP normalmap
!!samps =FULLBRIGHT fullbright
// envmaps only
!!samps =REFLECTCUBEMASK reflectmask reflectcube
@ -98,18 +101,6 @@ varying vec2 lm1, lm2, lm3;
#else
lightmaps = LIGHTMAP * e_lmscale.rgb;
#endif
/* the light we're getting is always too bright */
lightmaps *= 0.75;
/* clamp at 1.5 */
if (lightmaps.r > 1.5)
lightmaps.r = 1.5;
if (lightmaps.g > 1.5)
lightmaps.g = 1.5;
if (lightmaps.b > 1.5)
lightmaps.b = 1.5;
return lightmaps;
}
@ -118,6 +109,7 @@ varying vec2 lm1, lm2, lm3;
vec4 diffuse_f;
diffuse_f = texture2D(s_diffuse, tex_c);
diffuse_f.rgb *= e_colourident.rgb;
#ifdef MASKLT
if (diffuse_f.a < float(MASK))
@ -137,12 +129,13 @@ varying vec2 lm1, lm2, lm3;
#ifdef BUMP
/* Source's normalmaps are in the DX format where the green channel is flipped */
vec4 normal_f = texture2D(s_normalmap, tex_c);
normal_f.g *= -1.0;
normal_f.g = 1.0 - normal_f.g;
normal_f.rgb = normalize(normal_f.rgb - 0.5);
#else
vec4 normal_f = vec4(0.0,0.0,1.0,0.0);
#endif
#if defined(ENVFROMMASK)
/* We have a dedicated reflectmask */
#define refl texture2D(s_reflectmask, tex_c).r
@ -151,16 +144,30 @@ varying vec2 lm1, lm2, lm3;
#if defined(ENVFROMBASE) || !defined(BUMP)
#define refl 1.0 - diffuse_f.a
#else
#define refl normal_f.a * 0.5
/* when ENVFROMNORM is set, we don't invert the refl */
#if defined(ENVFROMNORM)
#define refl texture2D(s_normalmap, tex_c).a
#else
#define refl 1.0 - texture2D(s_normalmap, tex_c).a
#endif
#endif
#endif
vec3 cube_c = reflect(normalize(-eyevector), normal_f.rgb);
vec3 cube_c = reflect(-eyevector, normal_f.rgb);
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;
diffuse_f.rgb += (textureCube(s_reflectcube, cube_c).rgb * vec3(refl,refl,refl));
#endif
#ifdef FULLBRIGHT
diffuse_f.rgb += texture2D(s_fullbright, tex_c).rgb * texture2D(s_fullbright, tex_c).a;
#endif
#ifdef NOFOG
gl_FragColor = diffuse_f;
#else
gl_FragColor = fog4(diffuse_f);
#endif
}
#endif

View file

@ -1,8 +1,8 @@
!!ver 110
!!permu BUMP
!!samps diffuse
!!samps =BUMP normalmap
!!samps =REFLECTCUBEMASK reflectmask reflectcube
!!samps refraction=0
!!samps refraction=0 dudvmap=1
#include "sys/defs.h"
@ -29,18 +29,20 @@ varying vec3 eyeminusvertex;
{
vec2 refl_c;
vec3 refr_f;
vec3 norm_f;
vec3 dudv_f;
vec4 out_f = vec4( 1.0, 1.0, 1.0, 1.0 );
norm_f = ( texture2D( s_normalmap, tex_c).xyz);
norm_f.g *= -1.0;
norm_f = normalize( norm_f );
dudv_f = ( texture2D( s_dudvmap, tex_c).xyz);
dudv_f += ( texture2D( s_dudvmap, tex_c).xyz);
dudv_f -= 1.0 - ( 4.0 / 256.0 );
dudv_f = normalize( dudv_f );
// Reflection/View coordinates
refl_c = ( 1.0 + ( tf_c.xy / tf_c.w ) ) * 0.5;
refr_f = texture2D(s_refraction, refl_c + (norm_f.st) ).rgb;
out_f.rgb = refr_f * texture2D(s_diffuse, tex_c).rgb;
refr_f = texture2D( s_refraction, refl_c + ( dudv_f.st) ).rgb;
out_f.rgb = refr_f;
out_f.rgb *= texture2D( s_diffuse, tex_c).rgb;
gl_FragColor = out_f;
}

View file

@ -0,0 +1,24 @@
!!ver 110
!!permu FOG
!!samps diffuse=0
#include "sys/defs.h"
#include "sys/fog.h"
varying vec2 tex_c;
#ifdef VERTEX_SHADER
void main ()
{
tex_c = v_texcoord;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
vec4 diffuse_f = texture2D( s_diffuse, fract(tex_c) );
gl_FragColor = fog4( diffuse_f );
}
#endif

View file

@ -135,18 +135,27 @@ varying vec2 lm1, lm2, lm3;
#ifdef BUMP
/* Source's normalmaps are in the DX format where the green channel is flipped */
vec4 normal_f = texture2D(s_normalmap, tex_c);
normal_f.g *= -1.0;
normal_f.g = 1.0 - normal_f.g;
normal_f.rgb = normalize(normal_f.rgb - 0.5);
#else
vec4 normal_f = vec4(0.0,0.0,1.0,0.0);
#endif
/* when ENVFROMBASE is set or a normal isn't present, we're getting the reflectivity info from the diffusemap's alpha channel */
#if defined(ENVFROMBASE) || !defined(BUMP)
/* since we're sampling from the diffuse = 1.0 fully visible, 0.0 = fully reflective */
#define refl 1.0 - diffuse_f.a
#if defined(ENVFROMMASK)
/* We have a dedicated reflectmask */
#define refl texture2D(s_reflectmask, tex_c).r
#else
#define refl normal_f.a * 0.5
/* when ENVFROMBASE is set or a normal isn't present, we're getting the reflectivity info from the diffusemap's alpha channel */
#if defined(ENVFROMBASE) || !defined(BUMP)
#define refl 1.0 - diffuse_f.a
#else
/* when ENVFROMNORM is set, we don't invert the refl */
#if defined(ENVFROMNORM)
#define refl texture2D(s_normalmap, tex_c).a
#else
#define refl 1.0 - texture2D(s_normalmap, tex_c).a
#endif
#endif
#endif
vec3 cube_c = reflect(normalize(-eyevector), normal_f.rgb);

View file

@ -1,10 +1,15 @@
!!ver 110
!!ver 100 150
!!permu FRAMEBLEND
!!permu BUMP
!!permu FOG
!!permu NOFOG
!!permu SKELETAL
!!permu FULLBRIGHT
!!permu AMBIENTCUBE
!!samps diffuse fullbright normalmap
!!permu REFLECTCUBEMASK
!!samps diffuse
!!samps =BUMP normalmap
!!samps =FULLBRIGHT fullbright
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
@ -18,6 +23,7 @@
varying vec2 tex_c;
varying vec3 norm;
varying vec4 light;
/* CUBEMAPS ONLY */
#ifdef REFLECTCUBEMASK
@ -32,25 +38,52 @@ varying vec3 norm;
#ifdef VERTEX_SHADER
#include "sys/skeletal.h"
float lambert(vec3 normal, vec3 dir)
{
return dot(normal, dir);
}
float halflambert(vec3 normal, vec3 dir)
{
return (dot(normal, dir) * 0.5) + 0.5;
}
void main (void)
{
vec3 n, s, t, w;
tex_c = v_texcoord;
gl_Position = skeletaltransform_wnst(w,n,s,t);
norm = n;
norm = n = normalize(n);
s = normalize(s);
t = normalize(t);
light.rgba = vec4(e_light_ambient, 1.0);
#ifdef AMBIENTCUBE
//no specular effect here. use rtlights for that.
vec3 nn = norm*norm; //FIXME: should be worldspace normal.
light.rgb = nn.x * e_light_ambientcube[(norm.x<0.0)?1:0] +
nn.y * e_light_ambientcube[(norm.y<0.0)?3:2] +
nn.z * e_light_ambientcube[(norm.z<0.0)?5:4];
#else
#ifdef HALFLAMBERT
light.rgb += max(0.0,halflambert(n,e_light_dir)) * e_light_mul;
#else
light.rgb += max(0.0,dot(n,e_light_dir)) * e_light_mul;
#endif
#endif
/* CUBEMAPS ONLY */
#ifdef REFLECTCUBEMASK
invsurface = mat3(v_svector, v_tvector, v_normal);
invsurface = mat3(s, t, n);
vec3 eyeminusvertex = e_eyepos - v_position.xyz;
eyevector.x = dot(eyeminusvertex, v_svector.xyz);
eyevector.y = dot(eyeminusvertex, v_tvector.xyz);
eyevector.z = dot(eyeminusvertex, v_normal.xyz);
vec3 eyeminusvertex = e_eyepos - w.xyz;
eyevector.x = dot(eyeminusvertex, s.xyz);
eyevector.y = dot(eyeminusvertex, t.xyz);
eyevector.z = dot(eyeminusvertex, n.xyz);
#endif
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
vtexprojcoord = (l_cubematrix*vec4(w.xyz, 1.0));
#endif
}
#endif
@ -60,20 +93,9 @@ varying vec3 norm;
#include "sys/fog.h"
#include "sys/pcf.h"
float lambert(vec3 normal, vec3 dir)
{
return max(dot(normal, dir), 0.0);
}
float halflambert(vec3 normal, vec3 dir)
{
return (lambert(normal, dir) * 0.5) + 0.5;
}
void main (void)
{
vec4 diffuse_f = texture2D(s_diffuse, tex_c);
vec3 light;
#ifdef MASKLT
if (diffuse_f.a < float(MASK))
@ -84,7 +106,7 @@ varying vec3 norm;
#ifdef BUMP
/* Source's normalmaps are in the DX format where the green channel is flipped */
vec3 normal_f = texture2D(s_normalmap, tex_c).rgb;
normal_f.g *= -1.0;
normal_f.g = 1.0 - normal_f.g;
normal_f = normalize(normal_f.rgb - 0.5);
#else
vec3 normal_f = vec3(0.0,0.0,1.0);
@ -92,49 +114,45 @@ varying vec3 norm;
/* CUBEMAPS ONLY */
#ifdef REFLECTCUBEMASK
/* when ENVFROMBASE is set or a normal isn't present, we're getting the reflectivity info from the diffusemap's alpha channel */
#if defined(ENVFROMBASE) || !defined(BUMP)
#define refl 1.0 - diffuse_f.a
#if defined(ENVFROMMASK)
/* We have a dedicated reflectmask */
#define refl texture2D(s_reflectmask, tex_c).r
#else
#define refl texture2D(s_normalmap, tex_c).a
/* when ENVFROMBASE is set or a normal isn't present, we're getting the reflectivity info from the diffusemap's alpha channel */
#if defined(ENVFROMBASE) || !defined(BUMP)
#define refl 1.0 - diffuse_f.a
#else
/* when ENVFROMNORM is set, we don't invert the refl */
#if defined(ENVFROMNORM)
#define refl texture2D(s_normalmap, tex_c).a
#else
#define refl 1.0 - texture2D(s_normalmap, tex_c).a
#endif
#endif
#endif
vec3 cube_c = reflect(normalize(-eyevector), normal_f.rgb);
vec3 cube_c = reflect(-eyevector, normal_f.rgb);
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;
diffuse_f.rgb += (textureCube(s_reflectcube, cube_c).rgb * vec3(refl,refl,refl));
#endif
#ifdef AMBIENTCUBE
//no specular effect here. use rtlights for that.
vec3 nn = norm*norm; //FIXME: should be worldspace normal.
light = nn.x * e_light_ambientcube[(norm.x<0.0)?1:0] +
nn.y * e_light_ambientcube[(norm.y<0.0)?3:2] +
nn.z * e_light_ambientcube[(norm.z<0.0)?5:4];
#else
#ifdef HALFLAMBERT
light = e_light_ambient + (e_light_mul * halflambert(norm, e_light_dir));
#else
light = e_light_ambient + (e_light_mul * lambert(norm, e_light_dir));
#endif
/* the light we're getting is always too bright */
light *= 0.75;
/* clamp at 1.5 */
if (light.r > 1.5)
light.r = 1.5;
if (light.g > 1.5)
light.g = 1.5;
if (light.b > 1.5)
light.b = 1.5;
#endif
diffuse_f.rgb *= light;
diffuse_f.rgb *= light.rgb * e_colourident.rgb;
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4(diffuse_f * e_colourident) * e_lmscale;
#ifdef FULLBRIGHT
diffuse_f.rgb += texture2D(s_fullbright, tex_c).rgb * texture2D(s_fullbright, tex_c).a;
#endif
#if 1
gl_FragColor = diffuse_f;
#else
gl_FragColor = fog4(diffuse_f);
#endif
}
#endif

View file

@ -1,9 +1,10 @@
!!cvardf r_glsl_turbscale_reflect=1 //simpler scaler
!!cvardf r_glsl_turbscale_refract=1 //simpler scaler
!!permu REFLECTCUBEMASK
!!samps diffuse normalmap
!!samps refract=0 //always present
!!samps =REFLECT reflect=1
!!samps !REFLECT reflectcube
!!samps reflect=1
!!samps =REFLECTCUBEMASK reflectcube
!!permu FOG
#include "sys/defs.h"
@ -34,7 +35,7 @@
#define TINT 0.7,0.8,0.7
#endif
#ifndef STRENGTH
#define STRENGTH 0.1
#define STRENGTH 0.25
#endif
#ifndef TXSCALE
#define TXSCALE 1
@ -42,7 +43,7 @@
//current values (referring to legacy defaults where needed)
#ifndef FRESNEL_EXP
#define FRESNEL_EXP 4.0
#define FRESNEL_EXP 5.0
#endif
#ifndef FRESNEL_MIN
#define FRESNEL_MIN 0.0
@ -76,6 +77,7 @@ varying vec2 tc;
varying vec4 tf;
varying vec3 norm;
varying vec3 eye;
#ifdef VERTEX_SHADER
void main (void)
{
@ -86,6 +88,7 @@ void main (void)
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
@ -159,11 +162,10 @@ void main (void)
refr = mix(refr, vec3(FOGTINT), min(depth/4096.0, 1.0));
#endif
#ifdef REFLECT
//reflection/diffuse
refl = texture2D(s_reflect, stc - n.st*float(STRENGTH_REFL)*float(r_glsl_turbscale_reflect)).rgb * vec3(TINT_REFL);
#else
#ifdef LQWATER
refl = textureCube(s_reflectcube, n).rgb;// * vec3(TINT_REFL);
#else
refl = texture2D(s_reflect, stc - n.st*float(STRENGTH_REFL)*float(r_glsl_turbscale_reflect)).rgb * vec3(TINT_REFL);
#endif
//interplate by fresnel

View file

@ -14,9 +14,14 @@ typedef struct
{
char name[MAX_QPATH];
} tex[5];
char fullbrightmap[MAX_QPATH];
char envmap[MAX_QPATH];
char envmapmask[MAX_QPATH];
char dudvmap[MAX_QPATH];
char refracttinttexture[MAX_QPATH];
char color[MAX_QPATH];
char envfrombase;
char envfromnorm;
char halflambert;
float alphatestref;
@ -25,6 +30,17 @@ typedef struct
qboolean culldisable;
qboolean ignorez;
char *replaceblock;
char vertexcolor;
char vertexalpha;
char nodraw;
char additive;
char translucent;
char selfillum;
char nofog;
char mod2x; /* modulate only */
char water_cheap; /* water only */
char water_expensive; /* water only */
} vmtstate_t;
@ -154,6 +170,11 @@ static char *VMT_ParseBlock(const char *fname, vmtstate_t *st, char *line)
Q_strlcpy(st->normalmap, value, sizeof(st->normalmap));
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
}
else if (!Q_strcasecmp(key, "$dudvmap")) // refractions only
{
Q_strlcpy(st->dudvmap, value, sizeof(st->dudvmap));
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
}
else if (!Q_strcasecmp(key, "$ssbump"))
;
else if (!Q_strcasecmp(key, "$ssbumpmathfix"))
@ -183,23 +204,26 @@ static char *VMT_ParseBlock(const char *fname, vmtstate_t *st, char *line)
}
else if (!Q_strcasecmp(key, "$translucent"))
{
if (atoi(value))
st->blendfunc = "src_alpha one_minus_src_alpha\n";
st->translucent = 1;
}
else if (!Q_strcasecmp(key, "$additive"))
{
if (atoi(value))
st->blendfunc = "src_one one_minus_src_alpha\n";
st->additive = 1;
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
}
else if (!Q_strcasecmp(key, "$halflambert"))
st->halflambert = 1;
else if (!Q_strcasecmp(key, "%compiletrigger"))
st->nodraw = 1;
else if (!Q_strcasecmp(key, "lampbeam"))
st->additive = 1;
else if (!Q_strcasecmp(key, "$color"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
Q_strlcpy(st->color, value, sizeof(st->color));
else if (!Q_strcasecmp(key, "$vertexcolor"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
st->vertexcolor = 1;
else if (!Q_strcasecmp(key, "$vertexalpha"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
st->vertexalpha = 1;
else if (!Q_strcasecmp(key, "$decal"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
else if (!Q_strcasecmp(key, "$decalscale"))
@ -219,17 +243,17 @@ static char *VMT_ParseBlock(const char *fname, vmtstate_t *st, char *line)
else if (!Q_strcasecmp(key, "$basealphaenvmapmask"))
st->envfrombase=1;
else if (!Q_strcasecmp(key, "$normalmapalphaenvmapmask"))
st->envfrombase=0;
st->envfromnorm=1;
else if (!Q_strcasecmp(key, "$crackmaterial"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
else if (!Q_strcasecmp(key, "$selfillum"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
st->selfillum = 1;
else if (!Q_strcasecmp(key, "$selfillummask"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
Q_strlcpy(st->fullbrightmap, value, sizeof(st->fullbrightmap));
else if (!Q_strcasecmp(key, "$selfillumtint"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
else if (!Q_strcasecmp(key, "$nofog"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
st->nofog = 1;
else if (!Q_strcasecmp(key, "$nomip"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
else if (!Q_strcasecmp(key, "$nodecal"))
@ -253,8 +277,8 @@ static char *VMT_ParseBlock(const char *fname, vmtstate_t *st, char *line)
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
//water/reflection stuff
else if (!Q_strcasecmp(key, "$refracttinttexture"))
Q_strlcpy(st->tex[0].name, value, sizeof(st->tex[0].name));
else if (!Q_strcasecmp(key, "$REFRACTTINTTEXTURE"))
Q_strlcpy(st->refracttinttexture, value, sizeof(st->refracttinttexture));
else if (!Q_strcasecmp(key, "$refracttexture"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
else if (!Q_strcasecmp(key, "$refractamount"))
@ -273,6 +297,12 @@ static char *VMT_ParseBlock(const char *fname, vmtstate_t *st, char *line)
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
else if (!Q_strcasecmp(key, "$maxreflectivity"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
else if (!Q_strcasecmp(key, "$mod2x"))
st->mod2x = 1;
else if (!Q_strcasecmp(key, "$forcecheap"))
st->water_cheap = 1;
else if (!Q_strcasecmp(key, "$forceexpensive"))
st->water_expensive = 1;
else if (!Q_strcasecmp(key, "$normalmap"))
{
Q_strlcpy(st->normalmap, value, sizeof(st->normalmap));
@ -324,13 +354,75 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
if (st->alphatest)
progargs = "#MASK=0.5#MASKLT"; //alphamask has to be handled by glsl (when glsl is used)
if (st->nofog)
progargs = "#NOFOG";
Q_strlcatfz(script, &offset, sizeof(script), "\n");
if (!Q_strcasecmp(st->type, "WorldVertexTransition"))
{ //attempt to do terrain blending
Q_strlcpy(st->type, "vmt/transition#TWOWAY", sizeof(st->type));
if (st->nodraw)
{
Q_strlcatfz(script, &offset, sizeof(script), "\tsurfaceparm nodraw\n");
}
else if (!Q_strcasecmp(st->type, "UnlitGeneric"))
{
Q_strlcatfz(script, &offset, sizeof(script), "{\n");
Q_strlcatfz(script, &offset, sizeof(script), "\tmap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
if (st->vertexcolor)
Q_strlcatfz(script, &offset, sizeof(script), "\rrgbGen vertex\n");
if (st->vertexalpha)
Q_strlcatfz(script, &offset, sizeof(script), "\ralphaGen vertex\n");
if (st->additive)
Q_strlcatfz(script, &offset, sizeof(script), "\tblendFunc add\n");
else if (st->translucent)
Q_strlcatfz(script, &offset, sizeof(script), "\tblendFunc blend\n");
else if (st->alphatest)
Q_strlcatfz(script, &offset, sizeof(script), "\talphaFunc GE128\n");
Q_strlcatfz(script, &offset, sizeof(script), "}\n");
}
else if (!Q_strcasecmp(st->type, "WorldVertexTransition"))
{
if (*st->envmap && st->envfrombase)
Q_strlcpy(st->type, "vmt/transition#ENVFROMBASE", sizeof(st->type));
else if (*st->envmap && st->envfromnorm)
Q_strlcpy(st->type, "vmt/transition#ENVFROMNORM", sizeof(st->type));
else if (*st->envmap && *st->envmapmask) /* dedicated reflectmask */
Q_strlcpy(st->type, "vmt/transition#ENVFROMMASK", sizeof(st->type));
else /* take from normalmap */
Q_strlcpy(st->type, "vmt/transition", sizeof(st->type));
Q_strlcatfz(script, &offset, sizeof(script), "\tprogram \"%s%s\"\n", st->type, progargs);
Q_strlcatfz(script, &offset, sizeof(script), "\tdiffusemap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
Q_strlcatfz(script, &offset, sizeof(script), "\tuppermap \"%s%s.vtf\"\n", strcmp(st->tex[1].name, "materials/")?"materials/":"", st->tex[1].name);
/* there's also bumpmap2, but rtlight glsl doesn't respect it anyway. */
if (*st->normalmap)
Q_strlcatfz(script, &offset, sizeof(script), "\tnormalmap \"%s%s.vtf\"\n", strcmp(st->normalmap, "materials/")?"materials/":"", st->normalmap);
}
else if (!Q_strcasecmp(st->type, "UnlitTwoTexture"))
{
Q_strlcatfz(script, &offset, sizeof(script), "{\n");
Q_strlcatfz(script, &offset, sizeof(script), "\tmap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
if (st->mod2x) {
Q_strlcatfz(script, &offset, sizeof(script),"\t\tblendFunc gl_dst_color gl_src_color\n");
} else if (st->additive) {
Q_strlcatfz(script, &offset, sizeof(script),"\t\tblendFunc add\n");
}
Q_strlcatfz(script, &offset, sizeof(script), "}\n");
}
else if (!Q_strcasecmp(st->type, "Sprite"))
{
Q_strlcatfz(script, &offset, sizeof(script), "{\n");
Q_strlcatfz(script, &offset, sizeof(script), "\tmap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
Q_strlcatfz(script, &offset, sizeof(script), "\rrgbGen vertex\n");
Q_strlcatfz(script, &offset, sizeof(script), "\tblendFunc add\n");
Q_strlcatfz(script, &offset, sizeof(script), "}\n");
}
else if (!Q_strcasecmp(st->type, "Decal"))
{
@ -349,8 +441,27 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
Q_strlcatfz(script, &offset, sizeof(script), "\tdiffusemap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
Q_strlcatfz(script, &offset, sizeof(script), "\tpolygonOffset 1\n");
}
else if (!Q_strcasecmp(st->type, "Modulate"))
{
Q_strlcatfz(script, &offset, sizeof(script), "\t{\n");
Q_strlcatfz(script, &offset, sizeof(script), "\t\tmap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
if (st->mod2x) {
Q_strlcatfz(script, &offset, sizeof(script),"\t\tblendFunc gl_dst_color gl_src_color\n");
} else {
Q_strlcatfz(script, &offset, sizeof(script),"\t\tblendFunc gl_dst_color gl_one_minus_src_alpha\n");
}
Q_strlcatfz(script, &offset, sizeof(script), "\t}\n");
}
else if (!Q_strcasecmp(st->type, "Water"))
{
if (st->water_cheap)
progargs = "#LQWATER";
if (st->water_expensive)
progargs = "#HQWATER";
Q_strlcatfz(script, &offset, sizeof(script),
"\t{\n"
"\t\tprogram \"vmt/water%s\"\n"
@ -359,51 +470,95 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
"\t}\n", progargs);
Q_strlcatfz(script, &offset, sizeof(script), "\tdiffusemap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
Q_strlcatfz(script, &offset, sizeof(script), "\tnormalmap \"%s%s.vtf\"\n", strcmp(st->normalmap, "materials/")?"materials/":"", st->normalmap);
Q_strlcatfz(script, &offset, sizeof(script), "\tsurfaceparm nodlight\n");
Q_strlcatfz(script, &offset, sizeof(script), "\tsurfaceparm trans\n");
Q_strlcatfz(script, &offset, sizeof(script), "\tsurfaceparm alphashadow\n");
}
else if (!Q_strcasecmp(st->type, "Refract"))
{
Q_strlcatfz(script, &offset, sizeof(script),
"\t{\n"
"\t\tprogram \"vmt/refract%s\"\n"
"\t\tmap $refraction\n"
"\t}\n", progargs);
Q_strlcatfz(script, &offset, sizeof(script), "\tdiffusemap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
"\t\tmap $currentrender\n"
"\t\tmap \"%s%s.vtf\"\n"
"\t}\n", progargs, strcmp(st->normalmap, "materials/")?"materials/":"", st->normalmap);
if (*st->refracttinttexture)
Q_strlcatfz(script, &offset, sizeof(script), "\tdiffusemap \"%s%s.vtf\"\n", strcmp(st->refracttinttexture, "materials/")?"materials/":"", st->refracttinttexture);
Q_strlcatfz(script, &offset, sizeof(script), "\tnormalmap \"%s%s.vtf\"\n", strcmp(st->normalmap, "materials/")?"materials/":"", st->normalmap);
}
else if (!Q_strcasecmp(st->type, "VertexlitGeneric"))
{
if (*st->envmap && st->envfrombase)
{
if (st->halflambert)
Q_strlcpy(st->type, "vmt/vertexlit#ENVFROMBASE#HALFLAMBERT", sizeof(st->type));
if (st->translucent) {
Q_strlcatfz(script, &offset, sizeof(script),
"\t{\n"
"\t\tprogram \"vmt/vertexlit%s\"\n"
"\t\tblendFunc gl_src_alpha gl_one_minus_src_alpha\n"
"\t}\n", progargs);
} else {
if (*st->envmap && st->envfrombase)
{
if (st->halflambert)
Q_strlcpy(st->type, "vmt/vertexlit#ENVFROMBASE#HALFLAMBERT", sizeof(st->type));
else
Q_strlcpy(st->type, "vmt/vertexlit#ENVFROMBASE", sizeof(st->type));
}
else if (*st->envmap && st->envfromnorm)
{
if (st->halflambert)
Q_strlcpy(st->type, "vmt/vertexlit#ENVFROMNORM#HALFLAMBERT", sizeof(st->type));
else
Q_strlcpy(st->type, "vmt/vertexlit#ENVFROMNORM", sizeof(st->type));
}
else
Q_strlcpy(st->type, "vmt/vertexlit#ENVFROMBASE", sizeof(st->type));
}
else
{
if (st->halflambert)
Q_strlcpy(st->type, "vmt/vertexlit#HALFLAMBERT", sizeof(st->type));
else
Q_strlcpy(st->type, "vmt/vertexlit", sizeof(st->type));
{
if (st->halflambert)
Q_strlcpy(st->type, "vmt/vertexlit#HALFLAMBERT", sizeof(st->type));
else
Q_strlcpy(st->type, "vmt/vertexlit", sizeof(st->type));
}
Q_strlcatfz(script, &offset, sizeof(script), "\tprogram \"%s%s\"\n", st->type, progargs);
}
Q_strlcatfz(script, &offset, sizeof(script), "\tprogram \"%s%s\"\n", st->type, progargs);
Q_strlcatfz(script, &offset, sizeof(script), "\tdiffusemap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
if (*st->normalmap)
if (*st->normalmap) {
Q_strlcatfz(script, &offset, sizeof(script), "\tnormalmap \"%s%s.vtf\"\n", strcmp(st->normalmap, "materials/")?"materials/":"", st->normalmap);
}
#if 0
if (st->additive)
st->blendfunc = "src_one dst_one";
else if (st->translucent)
st->blendfunc = "src_alpha one_minus_src_alpha";
#endif
Q_strlcatfz(script, &offset, sizeof(script), "\treflectcube $cube:materials/skybox/sky_day03_06\n");
}
else if (!Q_strcasecmp(st->type, "LightmappedGeneric"))
{
/* reflectmask from diffuse map alpha */
if (*st->envmap && st->envfrombase)
Q_strlcpy(st->type, "vmt/lightmapped#ENVFROMBASE", sizeof(st->type));
else if (*st->envmap && *st->envmapmask) /* dedicated reflectmask */
Q_strlcpy(st->type, "vmt/lightmapped#ENVFROMMASK", sizeof(st->type));
else /* take from normalmap */
Q_strlcpy(st->type, "vmt/lightmapped", sizeof(st->type));
if (st->translucent) {
Q_strlcatfz(script, &offset, sizeof(script),
"\t{\n"
"\t\tprogram \"vmt/vertexlit%s\"\n"
"\t\tblendFunc gl_src_alpha gl_one_minus_src_alpha\n"
"\t}\n", progargs);
} else {
if (*st->envmap && st->envfrombase)
Q_strlcpy(st->type, "vmt/lightmapped#ENVFROMBASE", sizeof(st->type));
else if (*st->envmap && st->envfromnorm)
Q_strlcpy(st->type, "vmt/lightmapped#ENVFROMNORM", sizeof(st->type));
else if (*st->envmap && *st->envmapmask) /* dedicated reflectmask */
Q_strlcpy(st->type, "vmt/lightmapped#ENVFROMMASK", sizeof(st->type));
else /* take from normalmap */
Q_strlcpy(st->type, "vmt/lightmapped", sizeof(st->type));
Q_strlcatfz(script, &offset, sizeof(script), "\tprogram \"%s%s\"\n", st->type, progargs);
}
Q_strlcatfz(script, &offset, sizeof(script), "\tprogram \"%s%s\"\n", st->type, progargs);
Q_strlcatfz(script, &offset, sizeof(script), "\tdiffusemap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
if (*st->normalmap)
@ -415,6 +570,7 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
if (!Q_strcasecmp(st->tex[0].name, "_rt_Camera"))
Q_strlcatfz(script, &offset, sizeof(script),
"\t{\n"
"\t\tprogram vmt/rt\n"
"\t\tmap $rt:base\n"
"\t}\n"/*, progargs*/);
else
@ -426,6 +582,12 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
}
}
if (*st->fullbrightmap)
Q_strlcatfz(script, &offset, sizeof(script), "\tfullbrightmap \"%s%s.vtf\"\n", strcmp(st->fullbrightmap, "materials/")?"materials/":"", st->fullbrightmap);
else if (st->selfillum == 1)
Q_strlcatfz(script, &offset, sizeof(script), "\tfullbrightmap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
if (*st->envmapmask)
Q_strlcatfz(script, &offset, sizeof(script), "\treflectmask \"%s%s.vtf\"\n", strcmp(st->envmapmask, "materials/")?"materials/":"", st->envmapmask);
if (*st->envmap && strcmp(st->envmap, "env_cubemap"))
@ -438,6 +600,8 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
Q_strlcatfz(script, &offset, sizeof(script), "\tnodepth\n");
if (st->blendfunc)
Q_strlcatfz(script, &offset, sizeof(script), "\tprogblendfunc %s\n", st->blendfunc);
if (*st->color)
Q_strlcatfz(script, &offset, sizeof(script), "\trgbGen const %s\n", st->color);
Q_strlcatfz(script, &offset, sizeof(script), "}\n");
@ -551,4 +715,4 @@ qboolean VMT_Init(void)
if (!fsfuncs)
return false;
return plugfuncs->ExportInterface(plugmaterialloaderfuncs_name, &vmtfuncs, sizeof(vmtfuncs));
}
}

View file

@ -9,13 +9,16 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"!!permu FOG\n"
"!!permu BUMP\n"
"!!permu LIGHTSTYLED\n"
"!!permu FULLBRIGHT\n"
"!!permu REFLECTCUBEMASK\n"
"!!permu NOFOG\n"
"!!samps diffuse\n"
"!!samps lightmap\n"
"!!samps =LIGHTSTYLED lightmap1 lightmap2 lightmap3\n"
"!!samps =BUMP normalmap\n"
"!!samps =FULLBRIGHT fullbright\n"
// envmaps only
"!!samps =REFLECTCUBEMASK reflectmask reflectcube\n"
@ -105,18 +108,6 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#else\n"
"lightmaps = LIGHTMAP * e_lmscale.rgb;\n"
"#endif\n"
/* the light we're getting is always too bright */
"lightmaps *= 0.75;\n"
/* clamp at 1.5 */
"if (lightmaps.r > 1.5)\n"
"lightmaps.r = 1.5;\n"
"if (lightmaps.g > 1.5)\n"
"lightmaps.g = 1.5;\n"
"if (lightmaps.b > 1.5)\n"
"lightmaps.b = 1.5;\n"
"return lightmaps;\n"
"}\n"
@ -125,6 +116,7 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"vec4 diffuse_f;\n"
"diffuse_f = texture2D(s_diffuse, tex_c);\n"
"diffuse_f.rgb *= e_colourident.rgb;\n"
"#ifdef MASKLT\n"
"if (diffuse_f.a < float(MASK))\n"
@ -144,12 +136,13 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#ifdef BUMP\n"
/* Source's normalmaps are in the DX format where the green channel is flipped */
"vec4 normal_f = texture2D(s_normalmap, tex_c);\n"
"normal_f.g *= -1.0;\n"
"normal_f.g = 1.0 - normal_f.g;\n"
"normal_f.rgb = normalize(normal_f.rgb - 0.5);\n"
"#else\n"
"vec4 normal_f = vec4(0.0,0.0,1.0,0.0);\n"
"#endif\n"
"#if defined(ENVFROMMASK)\n"
/* We have a dedicated reflectmask */
"#define refl texture2D(s_reflectmask, tex_c).r\n"
@ -158,17 +151,31 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#if defined(ENVFROMBASE) || !defined(BUMP)\n"
"#define refl 1.0 - diffuse_f.a\n"
"#else\n"
"#define refl normal_f.a * 0.5\n"
/* when ENVFROMNORM is set, we don't invert the refl */
"#if defined(ENVFROMNORM)\n"
"#define refl texture2D(s_normalmap, tex_c).a\n"
"#else\n"
"#define refl 1.0 - texture2D(s_normalmap, tex_c).a\n"
"#endif\n"
"#endif\n"
"#endif\n"
"vec3 cube_c = reflect(normalize(-eyevector), normal_f.rgb);\n"
"vec3 cube_c = reflect(-eyevector, normal_f.rgb);\n"
"cube_c = cube_c.x * invsurface[0] + cube_c.y * invsurface[1] + cube_c.z * invsurface[2];\n"
"cube_c = (m_model * vec4(cube_c.xyz, 0.0)).xyz;\n"
"diffuse_f.rgb += (textureCube(s_reflectcube, cube_c).rgb * vec3(refl,refl,refl));\n"
"#endif\n"
"#ifdef FULLBRIGHT\n"
"diffuse_f.rgb += texture2D(s_fullbright, tex_c).rgb * texture2D(s_fullbright, tex_c).a;\n"
"#endif\n"
"#ifdef NOFOG\n"
"gl_FragColor = diffuse_f;\n"
"#else\n"
"gl_FragColor = fog4(diffuse_f);\n"
"#endif\n"
"}\n"
"#endif\n"
},
@ -176,10 +183,10 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
#ifdef GLQUAKE
{QR_OPENGL, 110, "vmt/refract",
"!!ver 110\n"
"!!permu BUMP\n"
"!!samps diffuse\n"
"!!samps =BUMP normalmap\n"
"!!samps =REFLECTCUBEMASK reflectmask reflectcube\n"
"!!samps refraction=0\n"
"!!samps refraction=0 dudvmap=1\n"
"#include \"sys/defs.h\"\n"
@ -206,18 +213,20 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"{\n"
"vec2 refl_c;\n"
"vec3 refr_f;\n"
"vec3 norm_f;\n"
"vec3 dudv_f;\n"
"vec4 out_f = vec4( 1.0, 1.0, 1.0, 1.0 );\n"
"norm_f = ( texture2D( s_normalmap, tex_c).xyz);\n"
"norm_f.g *= -1.0;\n"
"norm_f = normalize( norm_f );\n"
"dudv_f = ( texture2D( s_dudvmap, tex_c).xyz);\n"
"dudv_f += ( texture2D( s_dudvmap, tex_c).xyz);\n"
"dudv_f -= 1.0 - ( 4.0 / 256.0 );\n"
"dudv_f = normalize( dudv_f );\n"
// Reflection/View coordinates
"refl_c = ( 1.0 + ( tf_c.xy / tf_c.w ) ) * 0.5;\n"
"refr_f = texture2D(s_refraction, refl_c + (norm_f.st) ).rgb;\n"
"out_f.rgb = refr_f * texture2D(s_diffuse, tex_c).rgb;\n"
"refr_f = texture2D( s_refraction, refl_c + ( dudv_f.st) ).rgb;\n"
"out_f.rgb = refr_f;\n"
"out_f.rgb *= texture2D( s_diffuse, tex_c).rgb;\n"
"gl_FragColor = out_f;\n"
"}\n"
@ -363,18 +372,27 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#ifdef BUMP\n"
/* Source's normalmaps are in the DX format where the green channel is flipped */
"vec4 normal_f = texture2D(s_normalmap, tex_c);\n"
"normal_f.g *= -1.0;\n"
"normal_f.g = 1.0 - normal_f.g;\n"
"normal_f.rgb = normalize(normal_f.rgb - 0.5);\n"
"#else\n"
"vec4 normal_f = vec4(0.0,0.0,1.0,0.0);\n"
"#endif\n"
"#if defined(ENVFROMMASK)\n"
/* We have a dedicated reflectmask */
"#define refl texture2D(s_reflectmask, tex_c).r\n"
"#else\n"
/* when ENVFROMBASE is set or a normal isn't present, we're getting the reflectivity info from the diffusemap's alpha channel */
"#if defined(ENVFROMBASE) || !defined(BUMP)\n"
/* since we're sampling from the diffuse = 1.0 fully visible, 0.0 = fully reflective */
"#define refl 1.0 - diffuse_f.a\n"
"#else\n"
"#define refl normal_f.a * 0.5\n"
/* when ENVFROMNORM is set, we don't invert the refl */
"#if defined(ENVFROMNORM)\n"
"#define refl texture2D(s_normalmap, tex_c).a\n"
"#else\n"
"#define refl 1.0 - texture2D(s_normalmap, tex_c).a\n"
"#endif\n"
"#endif\n"
"#endif\n"
"vec3 cube_c = reflect(normalize(-eyevector), normal_f.rgb);\n"
@ -424,13 +442,18 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
#endif
#ifdef GLQUAKE
{QR_OPENGL, 110, "vmt/vertexlit",
"!!ver 110\n"
"!!ver 100 150\n"
"!!permu FRAMEBLEND\n"
"!!permu BUMP\n"
"!!permu FOG\n"
"!!permu NOFOG\n"
"!!permu SKELETAL\n"
"!!permu FULLBRIGHT\n"
"!!permu AMBIENTCUBE\n"
"!!samps diffuse fullbright normalmap\n"
"!!permu REFLECTCUBEMASK\n"
"!!samps diffuse\n"
"!!samps =BUMP normalmap\n"
"!!samps =FULLBRIGHT fullbright\n"
"!!permu FAKESHADOWS\n"
"!!cvardf r_glsl_pcf\n"
"!!samps =FAKESHADOWS shadowmap\n"
@ -444,6 +467,7 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"varying vec2 tex_c;\n"
"varying vec3 norm;\n"
"varying vec4 light;\n"
/* CUBEMAPS ONLY */
"#ifdef REFLECTCUBEMASK\n"
@ -458,25 +482,52 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#ifdef VERTEX_SHADER\n"
"#include \"sys/skeletal.h\"\n"
"float lambert(vec3 normal, vec3 dir)\n"
"{\n"
"return dot(normal, dir);\n"
"}\n"
"float halflambert(vec3 normal, vec3 dir)\n"
"{\n"
"return (dot(normal, dir) * 0.5) + 0.5;\n"
"}\n"
"void main (void)\n"
"{\n"
"vec3 n, s, t, w;\n"
"tex_c = v_texcoord;\n"
"gl_Position = skeletaltransform_wnst(w,n,s,t);\n"
"norm = n;\n"
"norm = n = normalize(n);\n"
"s = normalize(s);\n"
"t = normalize(t);\n"
"light.rgba = vec4(e_light_ambient, 1.0);\n"
"#ifdef AMBIENTCUBE\n"
//no specular effect here. use rtlights for that.
"vec3 nn = norm*norm; //FIXME: should be worldspace normal.\n"
"light.rgb = nn.x * e_light_ambientcube[(norm.x<0.0)?1:0] +\n"
"nn.y * e_light_ambientcube[(norm.y<0.0)?3:2] +\n"
"nn.z * e_light_ambientcube[(norm.z<0.0)?5:4];\n"
"#else\n"
"#ifdef HALFLAMBERT\n"
"light.rgb += max(0.0,halflambert(n,e_light_dir)) * e_light_mul;\n"
"#else\n"
"light.rgb += max(0.0,dot(n,e_light_dir)) * e_light_mul;\n"
"#endif\n"
"#endif\n"
/* CUBEMAPS ONLY */
"#ifdef REFLECTCUBEMASK\n"
"invsurface = mat3(v_svector, v_tvector, v_normal);\n"
"invsurface = mat3(s, t, n);\n"
"vec3 eyeminusvertex = e_eyepos - v_position.xyz;\n"
"eyevector.x = dot(eyeminusvertex, v_svector.xyz);\n"
"eyevector.y = dot(eyeminusvertex, v_tvector.xyz);\n"
"eyevector.z = dot(eyeminusvertex, v_normal.xyz);\n"
"vec3 eyeminusvertex = e_eyepos - w.xyz;\n"
"eyevector.x = dot(eyeminusvertex, s.xyz);\n"
"eyevector.y = dot(eyeminusvertex, t.xyz);\n"
"eyevector.z = dot(eyeminusvertex, n.xyz);\n"
"#endif\n"
"#ifdef FAKESHADOWS\n"
"vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));\n"
"vtexprojcoord = (l_cubematrix*vec4(w.xyz, 1.0));\n"
"#endif\n"
"}\n"
"#endif\n"
@ -486,20 +537,9 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#include \"sys/fog.h\"\n"
"#include \"sys/pcf.h\"\n"
"float lambert(vec3 normal, vec3 dir)\n"
"{\n"
"return max(dot(normal, dir), 0.0);\n"
"}\n"
"float halflambert(vec3 normal, vec3 dir)\n"
"{\n"
"return (lambert(normal, dir) * 0.5) + 0.5;\n"
"}\n"
"void main (void)\n"
"{\n"
"vec4 diffuse_f = texture2D(s_diffuse, tex_c);\n"
"vec3 light;\n"
"#ifdef MASKLT\n"
"if (diffuse_f.a < float(MASK))\n"
@ -510,7 +550,7 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#ifdef BUMP\n"
/* Source's normalmaps are in the DX format where the green channel is flipped */
"vec3 normal_f = texture2D(s_normalmap, tex_c).rgb;\n"
"normal_f.g *= -1.0;\n"
"normal_f.g = 1.0 - normal_f.g;\n"
"normal_f = normalize(normal_f.rgb - 0.5);\n"
"#else\n"
"vec3 normal_f = vec3(0.0,0.0,1.0);\n"
@ -518,50 +558,46 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
/* CUBEMAPS ONLY */
"#ifdef REFLECTCUBEMASK\n"
"#if defined(ENVFROMMASK)\n"
/* We have a dedicated reflectmask */
"#define refl texture2D(s_reflectmask, tex_c).r\n"
"#else\n"
/* when ENVFROMBASE is set or a normal isn't present, we're getting the reflectivity info from the diffusemap's alpha channel */
"#if defined(ENVFROMBASE) || !defined(BUMP)\n"
"#define refl 1.0 - diffuse_f.a\n"
"#else\n"
/* when ENVFROMNORM is set, we don't invert the refl */
"#if defined(ENVFROMNORM)\n"
"#define refl texture2D(s_normalmap, tex_c).a\n"
"#else\n"
"#define refl 1.0 - texture2D(s_normalmap, tex_c).a\n"
"#endif\n"
"vec3 cube_c = reflect(normalize(-eyevector), normal_f.rgb);\n"
"#endif\n"
"#endif\n"
"vec3 cube_c = reflect(-eyevector, normal_f.rgb);\n"
"cube_c = cube_c.x * invsurface[0] + cube_c.y * invsurface[1] + cube_c.z * invsurface[2];\n"
"cube_c = (m_model * vec4(cube_c.xyz, 0.0)).xyz;\n"
"diffuse_f.rgb += (textureCube(s_reflectcube, cube_c).rgb * vec3(refl,refl,refl));\n"
"#endif\n"
"#ifdef AMBIENTCUBE\n"
//no specular effect here. use rtlights for that.
"vec3 nn = norm*norm; //FIXME: should be worldspace normal.\n"
"light = nn.x * e_light_ambientcube[(norm.x<0.0)?1:0] +\n"
"nn.y * e_light_ambientcube[(norm.y<0.0)?3:2] +\n"
"nn.z * e_light_ambientcube[(norm.z<0.0)?5:4];\n"
"#else\n"
"#ifdef HALFLAMBERT\n"
"light = e_light_ambient + (e_light_mul * halflambert(norm, e_light_dir));\n"
"#else\n"
"light = e_light_ambient + (e_light_mul * lambert(norm, e_light_dir));\n"
"#endif\n"
/* the light we're getting is always too bright */
"light *= 0.75;\n"
/* clamp at 1.5 */
"if (light.r > 1.5)\n"
"light.r = 1.5;\n"
"if (light.g > 1.5)\n"
"light.g = 1.5;\n"
"if (light.b > 1.5)\n"
"light.b = 1.5;\n"
"#endif\n"
"diffuse_f.rgb *= light;\n"
"diffuse_f.rgb *= light.rgb * e_colourident.rgb;\n"
"#ifdef FAKESHADOWS\n"
"diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);\n"
"#endif\n"
"gl_FragColor = fog4(diffuse_f * e_colourident) * e_lmscale;\n"
"#ifdef FULLBRIGHT\n"
"diffuse_f.rgb += texture2D(s_fullbright, tex_c).rgb * texture2D(s_fullbright, tex_c).a;\n"
"#endif\n"
"#if 1\n"
"gl_FragColor = diffuse_f;\n"
"#else\n"
"gl_FragColor = fog4(diffuse_f);\n"
"#endif\n"
"}\n"
"#endif\n"
},
@ -570,10 +606,11 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
{QR_OPENGL, 110, "vmt/water",
"!!cvardf r_glsl_turbscale_reflect=1 //simpler scaler\n"
"!!cvardf r_glsl_turbscale_refract=1 //simpler scaler\n"
"!!permu REFLECTCUBEMASK\n"
"!!samps diffuse normalmap\n"
"!!samps refract=0 //always present\n"
"!!samps =REFLECT reflect=1\n"
"!!samps !REFLECT reflectcube\n"
"!!samps reflect=1\n"
"!!samps =REFLECTCUBEMASK reflectcube\n"
"!!permu FOG\n"
"#include \"sys/defs.h\"\n"
@ -604,7 +641,7 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#define TINT 0.7,0.8,0.7\n"
"#endif\n"
"#ifndef STRENGTH\n"
"#define STRENGTH 0.1\n"
"#define STRENGTH 0.25\n"
"#endif\n"
"#ifndef TXSCALE\n"
"#define TXSCALE 1\n"
@ -612,7 +649,7 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
//current values (referring to legacy defaults where needed)
"#ifndef FRESNEL_EXP\n"
"#define FRESNEL_EXP 4.0\n"
"#define FRESNEL_EXP 5.0\n"
"#endif\n"
"#ifndef FRESNEL_MIN\n"
"#define FRESNEL_MIN 0.0\n"
@ -646,6 +683,7 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"varying vec4 tf;\n"
"varying vec3 norm;\n"
"varying vec3 eye;\n"
"#ifdef VERTEX_SHADER\n"
"void main (void)\n"
"{\n"
@ -656,6 +694,7 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"gl_Position = ftetransform();\n"
"}\n"
"#endif\n"
"#ifdef FRAGMENT_SHADER\n"
"#include \"sys/fog.h\"\n"
@ -729,11 +768,10 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"refr = mix(refr, vec3(FOGTINT), min(depth/4096.0, 1.0));\n"
"#endif\n"
"#ifdef REFLECT\n"
//reflection/diffuse
"refl = texture2D(s_reflect, stc - n.st*float(STRENGTH_REFL)*float(r_glsl_turbscale_reflect)).rgb * vec3(TINT_REFL);\n"
"#else\n"
"#ifdef LQWATER\n"
"refl = textureCube(s_reflectcube, n).rgb;// * vec3(TINT_REFL);\n"
"#else\n"
"refl = texture2D(s_reflect, stc - n.st*float(STRENGTH_REFL)*float(r_glsl_turbscale_reflect)).rgb * vec3(TINT_REFL);\n"
"#endif\n"
//interplate by fresnel
@ -753,3 +791,31 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#endif\n"
},
#endif
#ifdef GLQUAKE
{QR_OPENGL, 110, "vmt/rt",
"!!ver 110\n"
"!!permu FOG\n"
"!!samps diffuse=0\n"
"#include \"sys/defs.h\"\n"
"#include \"sys/fog.h\"\n"
"varying vec2 tex_c;\n"
"#ifdef VERTEX_SHADER\n"
"void main ()\n"
"{\n"
"tex_c = v_texcoord;\n"
"gl_Position = ftetransform();\n"
"}\n"
"#endif\n"
"#ifdef FRAGMENT_SHADER\n"
"void main ()\n"
"{\n"
"vec4 diffuse_f = texture2D( s_diffuse, fract(tex_c) );\n"
"gl_FragColor = fog4( diffuse_f );\n"
"}\n"
"#endif\n"
},
#endif