1
0
Fork 0
forked from fte/fteqw

HL2: Quick support for $envmaptint and $envmapsaturation

This commit is contained in:
Marco Cawthorne 2024-11-20 14:15:27 -08:00
parent d89d7aa8be
commit 5a98bf1ef0
4 changed files with 151 additions and 20 deletions

View file

@ -20,6 +20,14 @@
!!cvardf r_glsl_pcf !!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap !!samps =FAKESHADOWS shadowmap
#ifndef ENVTINT
#define ENVTINT 1.0,1.0,1.0
#endif
#ifndef ENVSAT
#define ENVSAT 1.0,1.0,1.0
#endif
#include "sys/defs.h" #include "sys/defs.h"
varying vec2 tex_c; varying vec2 tex_c;
@ -104,6 +112,11 @@ varying vec2 lm1, lm2, lm3;
return lightmaps; return lightmaps;
} }
vec3 env_saturation(vec3 rgb, float adjustment) {
vec3 intensity = vec3(dot(rgb, vec3(0.2126,0.7152,0.0722)));
return mix(intensity, rgb, adjustment);
}
void main (void) void main (void)
{ {
vec4 diffuse_f; vec4 diffuse_f;
@ -155,9 +168,15 @@ varying vec2 lm1, lm2, lm3;
vec3 cube_c = reflect(-eyevector, normal_f.rgb); vec3 cube_c = reflect(-eyevector, normal_f.rgb);
vec3 cube_tint = vec3(ENVTINT);
vec3 cube_sat = vec3(ENVSAT);
cube_c = cube_c.x * invsurface[0] + cube_c.y * invsurface[1] + cube_c.z * invsurface[2]; 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; cube_c = (m_model * vec4(cube_c.xyz, 0.0)).xyz;
diffuse_f.rgb += (textureCube(s_reflectcube, cube_c).rgb * vec3(refl,refl,refl)); vec3 cube_t = env_saturation(textureCube(s_reflectcube, cube_c).rgb, cube_sat.r);
cube_t.r *= cube_tint.r;
cube_t.g *= cube_tint.g;
cube_t.b *= cube_tint.b;
diffuse_f.rgb += (cube_t * vec3(refl,refl,refl));
#endif #endif
#ifdef FULLBRIGHT #ifdef FULLBRIGHT

View file

@ -16,7 +16,6 @@
// envmaps only // envmaps only
!!samps =REFLECTCUBEMASK reflectmask reflectcube !!samps =REFLECTCUBEMASK reflectmask reflectcube
!!cvardf r_skipDiffuse !!cvardf r_skipDiffuse
#include "sys/defs.h" #include "sys/defs.h"
@ -29,8 +28,18 @@ varying vec4 light;
#ifdef REFLECTCUBEMASK #ifdef REFLECTCUBEMASK
varying vec3 eyevector; varying vec3 eyevector;
varying mat3 invsurface; varying mat3 invsurface;
#endif #endif
#ifndef ENVTINT
#define ENVTINT 1.0,1.0,1.0
#endif
#ifndef ENVSAT
#define ENVSAT 1.0
#endif
#ifdef FAKESHADOWS #ifdef FAKESHADOWS
varying vec4 vtexprojcoord; varying vec4 vtexprojcoord;
#endif #endif
@ -93,6 +102,11 @@ varying vec4 light;
#include "sys/fog.h" #include "sys/fog.h"
#include "sys/pcf.h" #include "sys/pcf.h"
vec3 env_saturation(vec3 rgb, float adjustment) {
vec3 intensity = vec3(dot(rgb, vec3(0.2126,0.7152,0.0722)));
return mix(intensity, rgb, adjustment);
}
void main (void) void main (void)
{ {
vec4 diffuse_f = texture2D(s_diffuse, tex_c); vec4 diffuse_f = texture2D(s_diffuse, tex_c);
@ -133,9 +147,15 @@ varying vec4 light;
#endif #endif
vec3 cube_c = reflect(-eyevector, normal_f.rgb); vec3 cube_c = reflect(-eyevector, normal_f.rgb);
vec3 cube_tint = vec3(ENVTINT);
vec3 cube_sat = vec3(ENVSAT);
cube_c = cube_c.x * invsurface[0] + cube_c.y * invsurface[1] + cube_c.z * invsurface[2]; 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; cube_c = (m_model * vec4(cube_c.xyz, 0.0)).xyz;
diffuse_f.rgb += (textureCube(s_reflectcube, cube_c).rgb * vec3(refl,refl,refl)); vec3 cube_t = env_saturation(textureCube(s_reflectcube, cube_c).rgb, cube_sat.r);
cube_t.r *= cube_tint.r;
cube_t.g *= cube_tint.g;
cube_t.b *= cube_tint.b;
diffuse_f.rgb += (cube_t * vec3(refl,refl,refl));
#endif #endif
diffuse_f.rgb *= light.rgb * e_colourident.rgb; diffuse_f.rgb *= light.rgb * e_colourident.rgb;

View file

@ -24,6 +24,12 @@ typedef struct
char envfromnorm; char envfromnorm;
char halflambert; char halflambert;
float envmaptint_r;
float envmaptint_g;
float envmaptint_b;
float envmapsat_r;
float envmapsat_g;
float envmapsat_b;
float alphatestref; float alphatestref;
char *blendfunc; char *blendfunc;
qboolean alphatest; qboolean alphatest;
@ -166,10 +172,7 @@ static char *VMT_ParseBlock(const char *fname, vmtstate_t *st, char *line)
else if (!Q_strcasecmp(key, "$basetexturetransform")) else if (!Q_strcasecmp(key, "$basetexturetransform"))
; ;
else if (!Q_strcasecmp(key, "$bumpmap")) // same as normalmap ~eukara else if (!Q_strcasecmp(key, "$bumpmap")) // same as normalmap ~eukara
{
Q_strlcpy(st->normalmap, value, sizeof(st->normalmap)); 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 else if (!Q_strcasecmp(key, "$dudvmap")) // refractions only
{ {
Q_strlcpy(st->dudvmap, value, sizeof(st->dudvmap)); Q_strlcpy(st->dudvmap, value, sizeof(st->dudvmap));
@ -237,9 +240,39 @@ static char *VMT_ParseBlock(const char *fname, vmtstate_t *st, char *line)
else if (!Q_strcasecmp(key, "$envmapcontrast")) else if (!Q_strcasecmp(key, "$envmapcontrast"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value); Con_DPrintf("%s: %s \"%s\"\n", fname, key, value);
else if (!Q_strcasecmp(key, "$envmaptint")) else if (!Q_strcasecmp(key, "$envmaptint"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value); {
char tok[64];
char *tintline;
tintline = cmdfuncs->ParsePunctuation(value, "[", tok, sizeof(tok), 0);
if (!strcmp(tok, "[")) {
tintline = cmdfuncs->ParseToken(tintline, tok, sizeof(tok), 0);
st->envmaptint_r = strtof(tok, NULL);
tintline = cmdfuncs->ParseToken(tintline, tok, sizeof(tok), 0);
st->envmaptint_g = strtof(tok, NULL);
tintline = cmdfuncs->ParsePunctuation(tintline, "]", tok, sizeof(tok), 0);
st->envmaptint_b = strtof(tok, NULL);
} else {
st->envmaptint_r = st->envmaptint_g = st->envmaptint_b = atof(value);
}
}
else if (!Q_strcasecmp(key, "$envmapsaturation")) else if (!Q_strcasecmp(key, "$envmapsaturation"))
Con_DPrintf("%s: %s \"%s\"\n", fname, key, value); {
char tok[64];
char *tintline;
tintline = cmdfuncs->ParsePunctuation(value, "[", tok, sizeof(tok), 0);
if (!strcmp(tok, "[")) {
tintline = cmdfuncs->ParseToken(tintline, tok, sizeof(tok), 0);
st->envmapsat_r = strtof(tok, NULL);
tintline = cmdfuncs->ParseToken(tintline, tok, sizeof(tok), 0);
st->envmapsat_g = strtof(tok, NULL);
tintline = cmdfuncs->ParsePunctuation(tintline, "]", tok, sizeof(tok), 0);
st->envmapsat_b = strtof(tok, NULL);
} else {
st->envmapsat_r = st->envmapsat_g = st->envmapsat_b = atof(value);
}
}
else if (!Q_strcasecmp(key, "$basealphaenvmapmask")) else if (!Q_strcasecmp(key, "$basealphaenvmapmask"))
st->envfrombase=1; st->envfrombase=1;
else if (!Q_strcasecmp(key, "$normalmapalphaenvmapmask")) else if (!Q_strcasecmp(key, "$normalmapalphaenvmapmask"))
@ -346,6 +379,8 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
{ {
size_t offset = 0; size_t offset = 0;
char script[8192]; char script[8192];
char envmaptint[128];
char envmapsat[128];
char *progargs = ""; char *progargs = "";
if (!*st->tex[0].name) //fill in a default... if (!*st->tex[0].name) //fill in a default...
@ -357,6 +392,20 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
if (st->nofog) if (st->nofog)
progargs = "#NOFOG"; progargs = "#NOFOG";
/* FIXME: check proper */
if (st->envmaptint_b > 0.0f) {
Q_snprintfz(envmaptint, sizeof(envmaptint), "#ENVTINT=%f,%f,%f", st->envmaptint_r, st->envmaptint_g, st->envmaptint_b);
} else {
Q_snprintfz(envmaptint, sizeof(envmaptint), "");
}
/* FIXME: check proper */
if (st->envmapsat_r > 0.0f) {
Q_snprintfz(envmapsat, sizeof(envmapsat), "#ENVSAT=%f,%f,%f", st->envmapsat_r, st->envmapsat_g, st->envmapsat_b);
} else {
Q_snprintfz(envmapsat, sizeof(envmapsat), "");
}
Q_strlcatfz(script, &offset, sizeof(script), "\n"); Q_strlcatfz(script, &offset, sizeof(script), "\n");
if (st->nodraw) if (st->nodraw)
@ -433,12 +482,16 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
} }
else if (!Q_strcasecmp(st->type, "DecalModulate")) else if (!Q_strcasecmp(st->type, "DecalModulate"))
{ {
Q_strlcatfz(script, &offset, sizeof(script), Q_strlcatfz(script, &offset, sizeof(script), "\t{\n");
"\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);
"\t\tprogram \"vmt/vertexlit%s\"\n"
"\t\tblendFunc gl_dst_color gl_one_minus_src_alpha\n" if (!st->mod2x) {
"\t}\n", progargs); Q_strlcatfz(script, &offset, sizeof(script),"\t\tblendFunc gl_dst_color gl_src_color\n");
Q_strlcatfz(script, &offset, sizeof(script), "\tdiffusemap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name); } 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");
Q_strlcatfz(script, &offset, sizeof(script), "\tpolygonOffset 1\n"); Q_strlcatfz(script, &offset, sizeof(script), "\tpolygonOffset 1\n");
} }
else if (!Q_strcasecmp(st->type, "Modulate")) else if (!Q_strcasecmp(st->type, "Modulate"))
@ -447,7 +500,7 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
Q_strlcatfz(script, &offset, sizeof(script), "\t{\n"); 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); 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) { if (!st->mod2x) {
Q_strlcatfz(script, &offset, sizeof(script),"\t\tblendFunc gl_dst_color gl_src_color\n"); Q_strlcatfz(script, &offset, sizeof(script),"\t\tblendFunc gl_dst_color gl_src_color\n");
} else { } 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\tblendFunc gl_dst_color gl_one_minus_src_alpha\n");
@ -519,7 +572,7 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
Q_strlcpy(st->type, "vmt/vertexlit", sizeof(st->type)); 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%s%s\"\n", st->type, progargs, envmaptint, envmapsat);
} }
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), "\tdiffusemap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);
@ -556,7 +609,7 @@ static void Shader_GenerateFromVMT(parsestate_t *ps, vmtstate_t *st, const char
else /* take from normalmap */ else /* take from normalmap */
Q_strlcpy(st->type, "vmt/lightmapped", sizeof(st->type)); 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%s%s\"\n", st->type, progargs, envmaptint, envmapsat);
} }
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), "\tdiffusemap \"%s%s.vtf\"\n", strcmp(st->tex[0].name, "materials/")?"materials/":"", st->tex[0].name);

View file

@ -27,6 +27,14 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"!!cvardf r_glsl_pcf\n" "!!cvardf r_glsl_pcf\n"
"!!samps =FAKESHADOWS shadowmap\n" "!!samps =FAKESHADOWS shadowmap\n"
"#ifndef ENVTINT\n"
"#define ENVTINT 1.0,1.0,1.0\n"
"#endif\n"
"#ifndef ENVSAT\n"
"#define ENVSAT 1.0,1.0,1.0\n"
"#endif\n"
"#include \"sys/defs.h\"\n" "#include \"sys/defs.h\"\n"
"varying vec2 tex_c;\n" "varying vec2 tex_c;\n"
@ -111,6 +119,11 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"return lightmaps;\n" "return lightmaps;\n"
"}\n" "}\n"
"vec3 env_saturation(vec3 rgb, float adjustment) {\n"
"vec3 intensity = vec3(dot(rgb, vec3(0.2126,0.7152,0.0722)));\n"
"return mix(intensity, rgb, adjustment);\n"
"}\n"
"void main (void)\n" "void main (void)\n"
"{\n" "{\n"
"vec4 diffuse_f;\n" "vec4 diffuse_f;\n"
@ -162,9 +175,15 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"vec3 cube_c = reflect(-eyevector, normal_f.rgb);\n" "vec3 cube_c = reflect(-eyevector, normal_f.rgb);\n"
"vec3 cube_tint = vec3(ENVTINT);\n"
"vec3 cube_sat = vec3(ENVSAT);\n"
"cube_c = cube_c.x * invsurface[0] + cube_c.y * invsurface[1] + cube_c.z * invsurface[2];\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" "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" "vec3 cube_t = env_saturation(textureCube(s_reflectcube, cube_c).rgb, cube_sat.r);\n"
"cube_t.r *= cube_tint.r;\n"
"cube_t.g *= cube_tint.g;\n"
"cube_t.b *= cube_tint.b;\n"
"diffuse_f.rgb += (cube_t * vec3(refl,refl,refl));\n"
"#endif\n" "#endif\n"
"#ifdef FULLBRIGHT\n" "#ifdef FULLBRIGHT\n"
@ -460,7 +479,6 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
// envmaps only // envmaps only
"!!samps =REFLECTCUBEMASK reflectmask reflectcube\n" "!!samps =REFLECTCUBEMASK reflectmask reflectcube\n"
"!!cvardf r_skipDiffuse\n" "!!cvardf r_skipDiffuse\n"
"#include \"sys/defs.h\"\n" "#include \"sys/defs.h\"\n"
@ -473,8 +491,18 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#ifdef REFLECTCUBEMASK\n" "#ifdef REFLECTCUBEMASK\n"
"varying vec3 eyevector;\n" "varying vec3 eyevector;\n"
"varying mat3 invsurface;\n" "varying mat3 invsurface;\n"
"#endif\n" "#endif\n"
"#ifndef ENVTINT\n"
"#define ENVTINT 1.0,1.0,1.0\n"
"#endif\n"
"#ifndef ENVSAT\n"
"#define ENVSAT 1.0\n"
"#endif\n"
"#ifdef FAKESHADOWS\n" "#ifdef FAKESHADOWS\n"
"varying vec4 vtexprojcoord;\n" "varying vec4 vtexprojcoord;\n"
"#endif\n" "#endif\n"
@ -537,6 +565,11 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#include \"sys/fog.h\"\n" "#include \"sys/fog.h\"\n"
"#include \"sys/pcf.h\"\n" "#include \"sys/pcf.h\"\n"
"vec3 env_saturation(vec3 rgb, float adjustment) {\n"
"vec3 intensity = vec3(dot(rgb, vec3(0.2126,0.7152,0.0722)));\n"
"return mix(intensity, rgb, adjustment);\n"
"}\n"
"void main (void)\n" "void main (void)\n"
"{\n" "{\n"
"vec4 diffuse_f = texture2D(s_diffuse, tex_c);\n" "vec4 diffuse_f = texture2D(s_diffuse, tex_c);\n"
@ -577,9 +610,15 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND
"#endif\n" "#endif\n"
"vec3 cube_c = reflect(-eyevector, normal_f.rgb);\n" "vec3 cube_c = reflect(-eyevector, normal_f.rgb);\n"
"vec3 cube_tint = vec3(ENVTINT);\n"
"vec3 cube_sat = vec3(ENVSAT);\n"
"cube_c = cube_c.x * invsurface[0] + cube_c.y * invsurface[1] + cube_c.z * invsurface[2];\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" "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" "vec3 cube_t = env_saturation(textureCube(s_reflectcube, cube_c).rgb, cube_sat.r);\n"
"cube_t.r *= cube_tint.r;\n"
"cube_t.g *= cube_tint.g;\n"
"cube_t.b *= cube_tint.b;\n"
"diffuse_f.rgb += (cube_t * vec3(refl,refl,refl));\n"
"#endif\n" "#endif\n"
"diffuse_f.rgb *= light.rgb * e_colourident.rgb;\n" "diffuse_f.rgb *= light.rgb * e_colourident.rgb;\n"