Platform: Add some of the GLSL we use so people have something to work off of

This commit is contained in:
Marco Cawthorne 2020-09-24 12:10:04 +02:00
parent fd9912a475
commit 8ee1220a64
43 changed files with 3245 additions and 0 deletions

View file

@ -0,0 +1,37 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Blending terrain and masking its edges for a smooth transition into alpha.
//==============================================================================
!!ver 110
!!samps diffuse
#include "sys/defs.h"
varying vec2 tex1_c;
varying vec2 tex2_c;
varying vec4 vex_color;
#ifdef VERTEX_SHADER
void main ( void )
{
tex1_c = v_texcoord + vec2(e_time * 0.25, e_time * 0.25);
tex2_c = v_texcoord * 0.5 + vec2(e_time * 0.1, e_time * 0.2);
vex_color = v_colour;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ( void )
{
vec3 diffuse_f = texture2D( s_diffuse, tex1_c ).rgb * vex_color.a;
diffuse_f *= texture2D( s_diffuse, tex2_c ).rgb * vex_color.a;
gl_FragColor = vec4(diffuse_f, 1.0);
}
#endif

View file

@ -0,0 +1,39 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Blending terrain and masking its edges for a smooth transition into alpha.
//==============================================================================
!!ver 110
!!samps diffuse
#include "sys/defs.h"
varying vec2 tex1_c;
varying vec2 tex2_c;
varying vec4 vex_color;
#ifdef VERTEX_SHADER
void main ( void )
{
tex1_c = v_texcoord + vec2(e_time * 0.25, e_time * 0.25);
tex2_c = v_texcoord * 0.5 + vec2(e_time * 0.1, e_time * 0.2);
vex_color = v_colour;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ( void )
{
vec3 diffuse_f = texture2D( s_diffuse, tex1_c ).rgb;
diffuse_f *= texture2D( s_diffuse, tex2_c ).rgb;
diffuse_f = mix(diffuse_f, vec3(1.0,1.0,1.0), 1.0 - vex_color.a);
gl_FragColor = vec4(diffuse_f, 1.0);
}
#endif

View file

@ -0,0 +1,41 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Shader used for fading out surfaces after a certain distance.
// It only has a diffuse map.
//==============================================================================
!!ver 110
!!permu FOG
!!samps diffuse=0
#include "sys/defs.h"
#include "sys/fog.h"
varying vec2 tex_c;
varying float eyedist;
#ifdef VERTEX_SHADER
void main ()
{
tex_c = v_texcoord;
eyedist = abs( length( e_eyepos - v_position.xyz ) ) / 2048.0;
if (eyedist > 1.0) {
eyedist = 1.0;
} else if (eyedist < 0.0) {
eyedist = 0.0;
}
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
vec4 diffuse_f = texture2D(s_diffuse, tex_c);
gl_FragColor = vec4( diffuse_f.rgb, (1.0 - eyedist) * diffuse_f.a);
}
#endif

View file

@ -0,0 +1,56 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// The diffusemap (monochrome) decides the reflectivity of a surface.
// Using a cube environmentmap as a source for reflectivity.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps diffuse normalmap reflectcube
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 eyevector;
varying mat3 invsurface;
varying vec2 wat_c;
#ifdef VERTEX_SHADER
void main (void)
{
invsurface[0] = v_svector;
invsurface[1] = v_tvector;
invsurface[2] = v_normal;
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);
tex_c = v_texcoord;
wat_c = tex_c + vec2(e_time * 0.01, sin(e_time) * 0.005);
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
void main (void)
{
vec3 cube_c;
vec4 out_f = vec4(1.0, 1.0, 1.0, 1.0);
vec4 diffuse_f = texture2D(s_diffuse, tex_c);
cube_c = reflect(normalize(-eyevector), texture2D(s_normalmap, wat_c).rgb * 0.35);
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 = textureCube(s_reflectcube, cube_c).rgb;
out_f.rgb *= diffuse_f.r + diffuse_f.b + diffuse_f.g / 3.0;
// Add fog to the final fragment
gl_FragColor = fog4(out_f);
}
#endif

View file

@ -0,0 +1,29 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// None.
//==============================================================================
!!ver 110
!!permu FRAMEBLEND
!!permu SKELETAL
#include "sys/defs.h"
#ifdef VERTEX_SHADER
#include "sys/skeletal.h"
void main ()
{
gl_Position = skeletaltransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
gl_FragColor = vec4(0, 0, 0, 1);
}
#endif

View file

@ -0,0 +1,39 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Fades surfaces in with distance. It's the opposite of the clutter shader.
//==============================================================================
!!ver 110
!!samps diffuse=0
#include "sys/defs.h"
#include "sys/fog.h"
varying vec2 tex_c;
varying float eyedist;
#ifdef VERTEX_SHADER
void main ()
{
tex_c = v_texcoord;
eyedist = abs( length( e_eyepos - v_position.xyz ) ) / 1024.0;
if (eyedist > 1.0) {
eyedist = 1.0;
} else if (eyedist < 0.0) {
eyedist = 0.0;
}
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
gl_FragColor = vec4( texture2D( s_diffuse, tex_c ).rgb * eyedist, eyedist );
gl_FragColor *= e_colourident;
}
#endif

View file

@ -0,0 +1,33 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Fills any surface with a diffuse texture and applies vertex colors.
//==============================================================================
!!ver 110
!!samps tex=0
varying vec2 tc;
varying vec4 vc;
#ifdef VERTEX_SHADER
attribute vec2 v_texcoord;
attribute vec4 v_colour;
void main ()
{
tc = v_texcoord;
vc = v_colour;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
vec4 f = vc;
f.rgb *= f.a;
f *= texture2D(s_tex, tc);
gl_FragColor = f;
}
#endif

View file

@ -0,0 +1,33 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Shader used for fading out surfaces after a certain distance.
// It only has a diffuse map.
//==============================================================================
!!ver 110
!!samps diffuse=0
#include "sys/defs.h"
#include "sys/fog.h"
varying vec2 tex_c;
varying vec4 vex_color;
#ifdef VERTEX_SHADER
void main ()
{
tex_c = v_texcoord;
vex_color = v_colour;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
vec4 diffuse_f = texture2D(s_diffuse, tex_c) * vex_color.a;
gl_FragColor = diffuse_f;
}
#endif

View file

@ -0,0 +1,100 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightmapped surface.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!permu LIGHTSTYLED
!!samps 2
!!samps lightmap
!!samps =LIGHTSTYLED lightmap1 lightmap2 lightmap3
!!samps =DELUXE deluxemap
!!samps =LIGHTSTYLED =DELUXE deluxemap1 deluxemap2 deluxemap3
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipdiffuse
!!cvardf dev_skipnormal
#include "sys/defs.h"
varying vec2 tex_c;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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;
gl_Position = ftetransform();
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main (void)
{
vec4 diffuse_f = texture2D(s_t0, tex_c);
vec3 normal_f = normalize(texture2D(s_t1, tex_c).rgb - 0.5);
if (float(dev_skipdiffuse) == 1.0) {
diffuse_f = vec4(1.0,1.0,1.0,1.0);
}
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
diffuse_f.rgb *= lightmap_fragment(normal_f);
gl_FragColor = fog4(diffuse_f);
}
#endif

View file

@ -0,0 +1,92 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightmapped surface of which the alpha channel decides the masking.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps diffuse normalmap lightmap deluxemap
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipnormal
#include "sys/defs.h"
varying vec2 tex_c;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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;
gl_Position = ftetransform();
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main (void)
{
vec4 diffuse_f = texture2D(s_diffuse, tex_c);
vec3 normal_f = normalize(texture2D(s_normalmap, tex_c).rgb - 0.5);
if (diffuse_f.a < 0.5) {
discard;
}
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
diffuse_f.rgb *= lightmap_fragment(normal_f);
gl_FragColor = fog4(diffuse_f);
}
#endif

View file

@ -0,0 +1,105 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightmapped surface that effectively acts as a mirror.
// Alpha channel of the diffusemap is referenced for reflectivity.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps diffuse lightmap deluxemap reflection
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
#include "sys/defs.h"
varying vec2 tex_c;
varying mat3 invsurface;
varying vec4 tf;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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 (void)
{
lightmapped_init();
invsurface[0] = v_svector;
invsurface[1] = v_tvector;
invsurface[2] = v_normal;
tf = ftetransform();
tex_c = v_texcoord;
gl_Position = tf;
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
#define s_reflect s_t0
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main (void)
{
vec2 stc;
vec4 diffuse_f = texture2D(s_diffuse, tex_c);
vec3 normal_f = normalize(texture2D(s_normalmap, tex_c).rgb - 0.5);
/* modulate the final pixel with the lightmap value */
diffuse_f.rgb *= lightmap_fragment(normal_f);
/* map the reflection buffer onto the surface */
stc = (1.0 + (tf.xy / tf.w)) * 0.5;
stc.t -= 1.5* invsurface[2].z / 1080.0;
diffuse_f.rgb = mix(texture2D(s_reflection, stc).rgb, diffuse_f.rgb, diffuse_f.a);
diffuse_f.a = 1.0;
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4(diffuse_f);
}
#endif

View file

@ -0,0 +1,110 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightmapped surface that contains an environment cube as a reflection.
// Alpha channel of the diffuse decides reflectivity.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps diffuse=0 normalmap=1 box:samplerCube=2 lightmap deluxemap
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipnormal
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 eyevector;
varying mat3 invsurface;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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 (void)
{
lightmapped_init();
invsurface[0] = v_svector;
invsurface[1] = v_tvector;
invsurface[2] = v_normal;
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);
tex_c = v_texcoord;
gl_Position = ftetransform();
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main (void)
{
vec3 cube_c;
vec4 out_f = vec4(1.0, 1.0, 1.0, 1.0);
vec4 diffuse_f = texture2D(s_t0, tex_c);
vec3 normal_f = normalize(texture2D(s_normalmap, tex_c).rgb - 0.5);
vec3 env_f;
diffuse_f.rgb *= lightmap_fragment(normal_f);
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
cube_c = reflect(normalize(-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;
env_f = textureCube(s_box, cube_c).rgb * (e_lmscale.rgb * 0.25);
out_f.rgb = mix(env_f, diffuse_f.rgb, diffuse_f.a);
// Add fog to the final fragment
gl_FragColor = fog4(out_f);
}
#endif

View file

@ -0,0 +1,107 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightmapped surface with specular highlighting. It'll assume a base value
// for specularity... this is if you want to save VRAM but really want a glow.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps diffuse normalmap lightmap deluxemap
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipnormal
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 eyevector;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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;
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);
gl_Position = ftetransform();
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main (void)
{
vec4 diffuse_f = texture2D(s_diffuse, tex_c);
vec3 normal_f = normalize(texture2D(s_normalmap, tex_c).rgb - 0.5);
float gloss = texture2D(s_normalmap, tex_c).a * 0.1;
float spec;
if (diffuse_f.a < 0.5) {
discard;
}
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
diffuse_f.rgb *= lightmap_fragment(normal_f);
vec3 halfdir = normalize(normalize(eyevector) - e_light_dir);
spec = pow(max(dot(halfdir, normal_f), 0.0), FTE_SPECULAR_EXPONENT);
spec *= 0.05;
diffuse_f.rgb += spec;
gl_FragColor = fog4(diffuse_f);
}
#endif

View file

@ -0,0 +1,108 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightmapped surface, normalmap's alpha contains the reference for how
// specular it should be.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps diffuse normalmap lightmap deluxemap
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipnormal
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 eyevector;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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;
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);
gl_Position = ftetransform();
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main (void)
{
vec4 diffuse_f = texture2D(s_diffuse, tex_c);
vec3 normal_f = normalize(texture2D(s_normalmap, tex_c).rgb - 0.5);
float gloss = texture2D(s_normalmap, tex_c).a * 0.1;
if (diffuse_f.a < 0.5) {
discard;
}
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
/* lightmap */
diffuse_f.rgb *= lightmap_fragment(normal_f);
/* specular */
vec3 halfdir = normalize(normalize(eyevector) - e_light_dir);
float spec = pow(max(dot(halfdir, normal_f), 0.0), FTE_SPECULAR_EXPONENT);
spec *= gloss;
diffuse_f.rgb += spec;
gl_FragColor = fog4(diffuse_f);
}
#endif

View file

@ -0,0 +1,114 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightmapped surface that will use its normalmap alpha for both specularity
// as well as environment cube reflectivity.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps diffuse normalmap lightmap deluxemap reflectcube
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipnormal
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 eyevector;
varying mat3 invsurface;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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 (void)
{
lightmapped_init();
invsurface[0] = v_svector;
invsurface[1] = v_tvector;
invsurface[2] = v_normal;
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);
tex_c = v_texcoord;
gl_Position = ftetransform();
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main (void)
{
vec3 cube_c;
vec4 out_f = vec4(1.0, 1.0, 1.0, 1.0);
vec4 diffuse_f = texture2D(s_diffuse, tex_c);
vec3 normal_f = normalize(texture2D(s_normalmap, tex_c).rgb - 0.5);
float gloss = texture2D(s_normalmap, tex_c).a;
float spec;
vec3 halfdir = normalize(normalize(eyevector) - e_light_dir);
spec = pow(max(dot(halfdir, normal_f), 0.0), FTE_SPECULAR_EXPONENT);
spec *= (gloss * 0.1);
diffuse_f.rgb *= lightmap_fragment(normal_f);
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
cube_c = reflect(normalize(-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;
out_f.rgb = mix(textureCube(s_reflectcube, cube_c).rgb, diffuse_f.rgb, gloss);
out_f.rgb += spec;
gl_FragColor = fog4(out_f);
}
#endif

View file

@ -0,0 +1,31 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Default post-processing shader for the framebuffer.
// Does a 'dodge' filter onto the final scene.
//==============================================================================
!!samps screen=0
#ifdef VERTEX_SHADER
attribute vec2 v_texcoord;
varying vec2 texcoord;
void main()
{
texcoord = v_texcoord.xy;
texcoord.y = 1.0 - texcoord.y;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
varying vec2 texcoord;
void main()
{
vec4 colortint = vec4(COLOR);
vec3 dodged = vec3(1.0,1.0,1.0) - (colortint.rgb * colortint.a);
gl_FragColor.rgb = texture2D(s_screen, texcoord).rgb / dodged;
}
#endif

View file

@ -0,0 +1,53 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Non-lit surface that predominantly offers environment cube reflection
// modulated by the diffusemap's RGB. This is used for glass, for example.
//==============================================================================
!!ver 110
!!permu FOG
!!samps diffusemap=0 normalmap=1 cubemap:samplerCube=2
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 eyevector;
varying mat3 invsurface;
#ifdef VERTEX_SHADER
void main ()
{
tex_c = v_texcoord;
invsurface[0] = v_svector;
invsurface[1] = v_tvector;
invsurface[2] = v_normal;
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 );
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
void main ()
{
vec3 out_f;
vec3 diffuse_f = texture2D(s_diffusemap, tex_c).rgb;
vec3 normal_f = texture2D(s_normalmap, tex_c).rgb - 0.5;
normal_f.x *= 0.2;
normal_f.y *= 0.2;
normal_f = normalize(normal_f);
vec3 rtc = reflect( normalize( -eyevector ), normal_f );
rtc = rtc.x * invsurface[0] + rtc.y * invsurface[1] + rtc.z * invsurface[2];
rtc = ( m_model * vec4( rtc.xyz, 0.0 ) ).xyz;
diffuse_f = textureCube(s_cubemap, rtc).rgb * (diffuse_f * 2.5);
gl_FragColor = fog4(vec4( diffuse_f, 1.0 ));
}
#endif

View file

@ -0,0 +1,45 @@
!!ver 110
!!samps refraction=0 normalmap=1
#include "sys/defs.h"
varying vec2 tex_c;
varying mat3 invsurface;
varying vec4 tf_c;
varying vec3 eyeminusvertex;
#ifdef VERTEX_SHADER
void main ()
{
invsurface[0] = v_svector;
invsurface[1] = v_tvector;
invsurface[2] = v_normal;
tf_c = ftetransform();
tex_c = v_texcoord;
gl_Position = tf_c;
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
void main ( void )
{
vec2 refl_c;
vec3 refr_f;
vec3 norm_f;
vec4 out_f = vec4( 1.0, 1.0, 1.0, 1.0 );
norm_f = ( texture2D( s_normalmap, tex_c + vec2( e_time * 0.01, 0.0 ) ).xyz);
norm_f += ( texture2D( s_normalmap, tex_c - vec2( 0, e_time * 0.01 ) ).xyz);
norm_f -= 1.0 - ( 4.0 / 256.0 );
norm_f = normalize( norm_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;
gl_FragColor = out_f;
}
#endif

View file

@ -0,0 +1,382 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Code for all the dynamic light passes. The renderer is not aware of any
// surface properties beyond diffuse, normal and specularity.
// Alpha-masked surfaces suffer greatly because of this.
//==============================================================================
!!ver 100 300
!!permu TESS
!!permu BUMP
!!permu FRAMEBLEND
!!permu SKELETAL
!!permu UPPERLOWER
!!permu FOG
!!permu REFLECTCUBEMASK
!!cvarf r_glsl_offsetmapping_scale
!!cvardf r_glsl_pcf
!!cvardf r_tessellation_level=5
!!samps diffuse normalmap specular upper lower reflectcube reflectmask
!!samps =PCF shadowmap
!!samps =CUBE projectionmap
!!cvardf dev_skipnormal
#if defined(ORM) || defined(SG)
#define PBR
#endif
#include "sys/defs.h"
//this is the main shader responsible for realtime dlights.
//texture units:
//s0=diffuse, s1=normal, s2=specular, s3=shadowmap
//custom modifiers:
//PCF(shadowmap)
//CUBEPROJ(projected cubemap)
//SPOT(projected circle
//CUBESHADOW
#if 0 && defined(GL_ARB_texture_gather) && defined(PCF)
#extension GL_ARB_texture_gather : enable
#endif
#ifdef UPPERLOWER
#define UPPER
#define LOWER
#endif
//if there's no vertex normals known, disable some stuff.
//FIXME: this results in dupe permutations.
#ifdef NOBUMP
#undef SPECULAR
#undef BUMP
#undef OFFSETMAPPING
#endif
#if !defined(TESS_CONTROL_SHADER)
varying vec2 tcbase;
varying vec3 lightvector;
#if defined(VERTEXCOLOURS)
varying vec4 vc;
#endif
#if defined(SPECULAR) || defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
varying vec3 eyevector;
#endif
#ifdef REFLECTCUBEMASK
varying mat3 invsurface;
#endif
#if defined(PCF) || defined(CUBE) || defined(SPOT) || defined(ORTHO)
varying vec4 vtexprojcoord;
#endif
#endif
#ifdef VERTEX_SHADER
#ifdef TESS
varying vec3 vertex, normal;
#endif
#include "sys/skeletal.h"
void main ()
{
vec3 n, s, t, w;
gl_Position = skeletaltransform_wnst(w,n,s,t);
n = normalize(n);
s = normalize(s);
t = normalize(t);
tcbase = v_texcoord; //pass the texture coords straight through
#ifdef ORTHO
vec3 lightminusvertex = -l_lightdirection;
lightvector.x = dot(lightminusvertex, s.xyz);
lightvector.y = dot(lightminusvertex, t.xyz);
lightvector.z = dot(lightminusvertex, n.xyz);
#else
vec3 lightminusvertex = l_lightposition - w.xyz;
#ifdef NOBUMP
//the only important thing is distance
lightvector = lightminusvertex;
#else
//the light direction relative to the surface normal, for bumpmapping.
lightvector.x = dot(lightminusvertex, s.xyz);
lightvector.y = dot(lightminusvertex, t.xyz);
lightvector.z = dot(lightminusvertex, n.xyz);
#endif
#endif
#if defined(VERTEXCOLOURS)
vc = v_colour;
#endif
#if defined(SPECULAR)||defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
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 REFLECTCUBEMASK
invsurface = mat3(v_svector, v_tvector, v_normal);
#endif
#if defined(PCF) || defined(SPOT) || defined(CUBE) || defined(ORTHO)
//for texture projections/shadowmapping on dlights
vtexprojcoord = (l_cubematrix*vec4(w.xyz, 1.0));
#endif
#ifdef TESS
vertex = w;
normal = n;
#endif
}
#endif
#if defined(TESS_CONTROL_SHADER)
layout(vertices = 3) out;
in vec3 vertex[];
out vec3 t_vertex[];
in vec3 normal[];
out vec3 t_normal[];
in vec2 tcbase[];
out vec2 t_tcbase[];
in vec3 lightvector[];
out vec3 t_lightvector[];
#if defined(VERTEXCOLOURS)
in vec4 vc[];
out vec4 t_vc[];
#endif
#if defined(SPECULAR) || defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
in vec3 eyevector[];
out vec3 t_eyevector[];
#endif
void main()
{
//the control shader needs to pass stuff through
#define id gl_InvocationID
t_vertex[id] = vertex[id];
t_normal[id] = normal[id];
t_tcbase[id] = tcbase[id];
t_lightvector[id] = lightvector[id];
#if defined(VERTEXCOLOURS)
t_vc[id] = vc[id];
#endif
#if defined(SPECULAR) || defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
t_eyevector[id] = eyevector[id];
#endif
gl_TessLevelOuter[0] = float(r_tessellation_level);
gl_TessLevelOuter[1] = float(r_tessellation_level);
gl_TessLevelOuter[2] = float(r_tessellation_level);
gl_TessLevelInner[0] = float(r_tessellation_level);
}
#endif
#if defined(TESS_EVALUATION_SHADER)
layout(triangles) in;
in vec3 t_vertex[];
in vec3 t_normal[];
in vec2 t_tcbase[];
in vec3 t_lightvector[];
#if defined(VERTEXCOLOURS)
in vec4 t_vc[];
#endif
#if defined(SPECULAR) || defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
in vec3 t_eyevector[];
#endif
#define LERP(a) (gl_TessCoord.x*a[0] + gl_TessCoord.y*a[1] + gl_TessCoord.z*a[2])
void main()
{
#define factor 1.0
tcbase = LERP(t_tcbase);
vec3 w = LERP(t_vertex);
vec3 t0 = w - dot(w-t_vertex[0],t_normal[0])*t_normal[0];
vec3 t1 = w - dot(w-t_vertex[1],t_normal[1])*t_normal[1];
vec3 t2 = w - dot(w-t_vertex[2],t_normal[2])*t_normal[2];
w = w*(1.0-factor) + factor*(gl_TessCoord.x*t0+gl_TessCoord.y*t1+gl_TessCoord.z*t2);
#if defined(PCF) || defined(SPOT) || defined(CUBE) || defined(ORTHO)
//for texture projections/shadowmapping on dlights
vtexprojcoord = (l_cubematrix*vec4(w.xyz, 1.0));
#endif
//FIXME: we should be recalcing these here, instead of just lerping them
lightvector = LERP(t_lightvector);
#if defined(VERTEXCOLOURS)
vc = LERP(t_vc);
#endif
#if defined(SPECULAR) || defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
eyevector = LERP(t_eyevector);
#endif
gl_Position = m_modelviewprojection * vec4(w,1.0);
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
#ifdef OFFSETMAPPING
#include "sys/offsetmapping.h"
#endif
#include "sys/pbr.h"
void main ()
{
#ifdef ORTHO
float colorscale = 1.0;
#else
float colorscale = max(1.0 - (dot(lightvector, lightvector)/(l_lightradius*l_lightradius)), 0.0);
#endif
#ifdef PCF
/*filter the light by the shadowmap. logically a boolean, but we allow fractions for softer shadows*/
colorscale *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
#if defined(SPOT)
/*filter the colour by the spotlight. discard anything behind the light so we don't get a mirror image*/
if (vtexprojcoord.w < 0.0) discard;
vec2 spot = ((vtexprojcoord.st)/vtexprojcoord.w);
colorscale*=1.0-(dot(spot,spot));
#endif
//read raw texture samples (offsetmapping munges the tex coords first)
#ifdef OFFSETMAPPING
vec2 tcoffsetmap = offsetmap(s_normalmap, tcbase, eyevector);
#define tcbase tcoffsetmap
#endif
#if defined(FLAT)
vec4 bases = vec4(FLAT, FLAT, FLAT, 1.0);
#else
vec4 bases = texture2D(s_diffuse, tcbase);
#ifdef VERTEXCOLOURS
bases.rgb *= bases.a;
#endif
#endif
#ifdef UPPER
vec4 uc = texture2D(s_upper, tcbase);
bases.rgb += uc.rgb*e_uppercolour*uc.a;
#endif
#ifdef LOWER
vec4 lc = texture2D(s_lower, tcbase);
bases.rgb += lc.rgb*e_lowercolour*lc.a;
#endif
#if defined(BUMP) || defined(SPECULAR) || defined(REFLECTCUBEMASK)
vec3 bumps;
if (float(dev_skipnormal) == 0.0) {
bumps = normalize(vec3(texture2D(s_normalmap, tcbase)) - 0.5);
/* fix it up a bit */
bumps = normalize(bumps);
} else {
bumps = vec3(0.0,0.0,1.0);
}
#elif defined(REFLECTCUBEMASK)
vec3 bumps = vec3(0.0,0.0,1.0);
#endif
#ifdef SPECULAR
vec4 specs = texture2D(s_specular, tcbase);
#endif
#define dielectricSpecular 0.04
#ifdef SPECULAR
#ifdef ORM //pbr-style occlusion+roughness+metalness
#define occlusion specs.r
#define roughness clamp(specs.g, 0.04, 1.0)
#define metalness specs.b
#define gloss 1.0 //sqrt(1.0-roughness)
#define ambientrgb (specrgb+col.rgb)
vec3 specrgb = mix(vec3(dielectricSpecular), bases.rgb, metalness);
bases.rgb = bases.rgb * (1.0 - dielectricSpecular) * (1.0-metalness);
#elif defined(SG) //pbr-style specular+glossiness
//occlusion needs to be baked in. :(
#define roughness (1.0-specs.a)
#define gloss specs.a
#define specrgb specs.rgb
#define ambientrgb (specs.rgb+col.rgb)
#else //blinn-phong
#define roughness (1.0-specs.a)
#define gloss specs.a
#define specrgb specs.rgb
#define ambientrgb col.rgb
#endif
#else
#define roughness 0.3
#define specrgb 1.0 //vec3(dielectricSpecular)
#endif
#ifdef PBR
vec3 diff = DoPBR(bumps, normalize(eyevector), normalize(lightvector), roughness, bases.rgb, specrgb, l_lightcolourscale);
#else
vec3 diff;
#ifdef NOBUMP
//surface can only support ambient lighting, even for lights that try to avoid it.
diff = bases.rgb * (l_lightcolourscale.x+l_lightcolourscale.y);
#else
vec3 nl = normalize(lightvector);
#ifdef BUMP
diff = bases.rgb * (l_lightcolourscale.x + l_lightcolourscale.y * max(dot(bumps, nl), 0.0));
#else
//we still do bumpmapping even without bumps to ensure colours are always sane. light.exe does it too.
diff = bases.rgb * (l_lightcolourscale.x + l_lightcolourscale.y * max(dot(vec3(0.0, 0.0, 1.0), nl), 0.0));
#endif
#endif
#ifdef SPECULAR
vec3 halfdir = normalize(normalize(eyevector) + nl);
float spec = pow(max(dot(halfdir, bumps), 0.0), FTE_SPECULAR_EXPONENT * gloss)*float(SPECMUL);
diff += l_lightcolourscale.z * spec * specrgb;
#endif
#endif
#ifdef REFLECTCUBEMASK
vec3 rtc = reflect(-eyevector, bumps);
rtc = rtc.x*invsurface[0] + rtc.y*invsurface[1] + rtc.z*invsurface[2];
rtc = (m_model * vec4(rtc.xyz,0.0)).xyz;
diff += texture2D(s_reflectmask, tcbase).rgb * textureCube(s_reflectcube, rtc).rgb;
#endif
#ifdef CUBE
/*filter the colour by the cubemap projection*/
diff *= textureCube(s_projectionmap, vtexprojcoord.xyz).rgb;
#endif
#if defined(PROJECTION)
/*2d projection, not used*/
// diff *= texture2d(s_projectionmap, shadowcoord);
#endif
#if defined(occlusion) && !defined(NOOCCLUDE)
diff *= occlusion;
#endif
#if defined(VERTEXCOLOURS)
diff *= vc.rgb * vc.a;
#endif
diff *= colorscale*l_lightcolour;
gl_FragColor = vec4(fog3additive(diff), 1.0);
}
#endif

View file

@ -0,0 +1,47 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Basic skybox shader with two clouds rendered on top using a dodge filter.
//==============================================================================
!!ver 110
!!permu FOG
!!samps box:samplerCube=0 cloudA=1 cloudB=2
#include "sys/defs.h"
#include "sys/fog.h"
varying vec3 cloudpos;
varying vec3 boxpos;
#ifdef VERTEX_SHADER
void main ()
{
boxpos = v_position.xyz - e_eyepos;
cloudpos = v_position.xyz;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
#define s_cloud1 s_t0
#define s_cloud2 s_t1
void main ()
{
vec4 skybox = textureCube( s_box, boxpos );
vec2 tccoord;
vec3 dir = cloudpos - e_eyepos;
dir.z *= 3.0;
dir.xy /= 0.5 * length( dir );
tccoord = ( dir.xy + e_time * 0.015 );
vec4 cloud1_f = texture2D( s_cloudA, tccoord );
tccoord = ( dir.xy + e_time * 0.02 );
vec4 cloud2_f = texture2D( s_cloudB, tccoord );
vec3 dodged = vec3(1.0,1.0,1.0) - (cloud1_f.rgb * vec3(cloud1_f.a, cloud1_f.a, cloud1_f.a));
gl_FragColor.rgb = skybox.rgb / dodged;
gl_FragColor *= e_lmscale;
}
#endif

View file

@ -0,0 +1,49 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Basic skybox shader with two clouds rendered on top using a dodge filter.
//==============================================================================
!!ver 110
!!permu FOG
!!samps box:samplerCube=0 cloudA=1 cloudB=2
#include "sys/defs.h"
#include "sys/fog.h"
varying vec3 cloudpos;
varying vec3 boxpos;
#ifdef VERTEX_SHADER
void main ()
{
boxpos = v_position.xyz - e_eyepos;
boxpos.y = -boxpos.y;
cloudpos = v_position.xyz;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
#define s_cloud1 s_t0
#define s_cloud2 s_t1
void main ()
{
vec4 skybox = textureCube( s_box, boxpos );
vec2 tccoord;
vec3 dir = cloudpos - e_eyepos;
dir.z *= 3.0;
dir.xy /= 0.5 * length( dir );
tccoord = ( dir.xy + e_time * 0.015 );
vec4 cloud1_f = texture2D( s_cloudA, tccoord );
tccoord = ( dir.xy + e_time * 0.02 );
vec4 cloud2_f = texture2D( s_cloudB, tccoord );
vec3 dodged = vec3(1.0,1.0,1.0) - (cloud1_f.rgb * vec3(cloud1_f.a, cloud1_f.a, cloud1_f.a));
gl_FragColor.rgb = skybox.rgb / dodged;
gl_FragColor *= e_lmscale;
gl_FragColor.rgb = fog3(gl_FragColor.rgb);
}
#endif

View file

@ -0,0 +1,57 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Basic skybox shader with two clouds rendered on top using a dodge filter.
//==============================================================================
!!ver 110
!!permu FOG
!!samps hdr_40:samplerCube=0 hdr_250:samplerCube=1 hdr_1600:samplerCube=2 cloudA=3 cloudB=4
#include "sys/defs.h"
#include "sys/fog.h"
varying vec3 cloudpos;
varying vec3 boxpos;
#ifdef VERTEX_SHADER
void main ()
{
boxpos = v_position.xyz - e_eyepos;
cloudpos = v_position.xyz;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
float hdr_scale;
vec3 sky_out;
vec3 skybox_40 = textureCube( s_hdr_40, boxpos ).rgb;
vec3 skybox_250 = textureCube( s_hdr_250, boxpos ).rgb;
vec3 skybox_1600 = textureCube( s_hdr_1600, boxpos ).rgb;
hdr_scale = (e_lmscale.r + e_lmscale.g + e_lmscale.b) / 3.0;
if (hdr_scale > 1.0) {
sky_out = mix(skybox_250, skybox_40, hdr_scale - 1.0);
} else {
sky_out = mix(skybox_1600, skybox_250, hdr_scale);
}
/* the cloud bits */
vec2 tccoord;
vec3 dir = cloudpos - e_eyepos;
dir.z *= 3.0;
dir.xy /= 0.5 * length( dir );
tccoord = ( dir.xy + e_time * 0.015 );
vec4 cloud1_f = texture2D( s_cloudA, tccoord );
tccoord = ( dir.xy + e_time * 0.02 );
vec4 cloud2_f = texture2D( s_cloudB, tccoord );
vec3 dodged = vec3(1.0,1.0,1.0) - (cloud1_f.rgb * vec3(cloud1_f.a, cloud1_f.a, cloud1_f.a));
gl_FragColor.rgb = sky_out / dodged;
//gl_FragColor *= e_lmscale;
}
#endif

View file

@ -0,0 +1,49 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// A skybox cube with two cloud layers, which get occluded by a blended
// second skybox cube.
//==============================================================================
!!ver 110
!!samps cloudA=0 cloudB=1 box:samplerCube=2 mountains:samplerCube=3
#include "sys/defs.h"
#include "sys/fog.h"
varying vec3 cloudpos;
varying vec3 boxpos;
#ifdef VERTEX_SHADER
void main ()
{
boxpos = v_position.xyz - e_eyepos;
cloudpos = v_position.xyz;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
vec4 mountains = textureCube( s_mountains, boxpos );
vec4 box = textureCube( s_box, boxpos );
vec2 tccoord;
vec3 dir = cloudpos - e_eyepos;
dir.z *= 3.0;
dir.xy /= 0.5 * length( dir );
tccoord = ( dir.xy + e_time * 0.015 );
vec4 cloud1_f = texture2D( s_cloudA, tccoord );
tccoord = ( dir.xy + e_time * 0.02 );
vec4 cloud2_f = texture2D( s_cloudA, tccoord );
gl_FragColor.rgb = mix( box.rgb, cloud1_f.rgb, cloud1_f.a );
gl_FragColor = vec4( mix( gl_FragColor.rgb, cloud2_f.rgb, cloud2_f.a ), 1.0 );
if (mountains.a > 0.9) {
gl_FragColor.rgb = mix( gl_FragColor.rgb, mountains.rgb, mountains.a);
}
gl_FragColor *= e_lmscale;
}
#endif

View file

@ -0,0 +1,47 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Terrain shader for tw_valley's skyroom.
//==============================================================================
!!ver 110
!!permu FOG
!!samps box:samplerCube=0 cloudA=1 cloudB=2
#include "sys/defs.h"
#include "sys/fog.h"
varying vec3 cloudpos;
varying vec3 boxpos;
#ifdef VERTEX_SHADER
void main ()
{
boxpos = v_position.xyz - e_eyepos;
cloudpos = v_position.xyz;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
#define s_cloud1 s_t0
#define s_cloud2 s_t1
void main ()
{
vec4 skybox = textureCube( s_box, boxpos );
vec2 tccoord;
vec3 dir = cloudpos - e_eyepos;
dir.z *= 4.0;
dir.xy /= 0.5 * length( dir );
tccoord = ( dir.xy + e_time * 0.015 ) * 0.75;
vec4 cloud1_f = texture2D( s_cloudA, tccoord );
tccoord = ( dir.xy + e_time * 0.02 ) * 0.75;
vec4 cloud2_f = texture2D( s_cloudB, tccoord );
vec3 dodged = vec3(1.0,1.0,1.0) - (cloud1_f.rgb * vec3(cloud1_f.a, cloud1_f.a, cloud1_f.a));
gl_FragColor.rgb = skybox.rgb / dodged;
gl_FragColor *= e_lmscale;
}
#endif

View file

@ -0,0 +1,33 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Trisoup whose diffusemap multiplies against the glColor values.
//==============================================================================
!!ver 110
!!samps diffuse
varying vec2 tex_c;
varying vec4 vex_color;
#ifdef VERTEX_SHADER
attribute vec2 v_texcoord;
attribute vec4 v_colour;
void main ()
{
tex_c = v_texcoord;
vex_color = v_colour;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
vec4 diffuse_f = vex_color;
diffuse_f.rgb *= diffuse_f.a;
diffuse_f *= texture2D(s_diffuse, tex_c);
gl_FragColor = diffuse_f;
}
#endif

View file

@ -0,0 +1,33 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Trisoup whose diffusemap multiplies against the glColor values.
//==============================================================================
!!ver 110
!!samps diffuse
varying vec2 tex_c;
varying vec4 vex_color;
#ifdef VERTEX_SHADER
attribute vec2 v_texcoord;
attribute vec4 v_colour;
void main ()
{
tex_c = v_texcoord;
vex_color = v_colour;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
vec4 diffuse_f = vex_color;
diffuse_f.rgb *= diffuse_f.a;
diffuse_f *= texture2D(s_diffuse, tex_c);
gl_FragColor = diffuse_f;
}
#endif

View file

@ -0,0 +1,34 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Trisoup whose diffusemap multiplies against the glColor values.
//==============================================================================
!!ver 110
!!samps diffuse
#include "sys/defs.h"
varying vec2 tex_c;
varying vec4 vex_color;
#ifdef VERTEX_SHADER
void main ()
{
tex_c = v_texcoord;
tex_c.y -= e_time;
vex_color = v_colour;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
void main ()
{
vec4 diffuse_f = vex_color;
diffuse_f.rgb *= diffuse_f.a;
diffuse_f *= texture2D(s_diffuse, tex_c);
gl_FragColor = diffuse_f;
}
#endif

View file

@ -0,0 +1,110 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Default terrain shader that blends between two surfaces and creates a
// realistic transition using the diffusemaps' monochrome channel for masking.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps 6
!!samps lightmap
!!samps =LIGHTSTYLED lightmap1 lightmap2 lightmap3
!!samps =DELUXE deluxemap
!!samps =LIGHTSTYLED =DELUXE deluxemap1 deluxemap2 deluxemap3
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipnormal
#include "sys/defs.h"
varying vec2 tex_c;
varying vec4 vex_color;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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 ( void )
{
lightmapped_init();
tex_c = v_texcoord;
vex_color = v_colour;
gl_Position = ftetransform();
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main ( void )
{
vec4 diff1_f = texture2D( s_t0, tex_c);
vec4 diff2_f = texture2D( s_t1, tex_c);
vec3 normal1_f = normalize(texture2D(s_t4, tex_c).rgb - 0.5);
vec3 normal2_f = normalize(texture2D(s_t5, tex_c).rgb - 0.5);
float alpha = 1.0;
float bw = 1.0 - (diff2_f.r + diff2_f.g + diff2_f.b) / 3.0;
if (vex_color.a < 1.0) {
if (bw > vex_color.a) {
alpha = vex_color.a;
}
}
/* light */
diff1_f.rgb *= lightmap_fragment(normal1_f);
diff2_f.rgb *= lightmap_fragment(normal2_f);
vec3 output_f = mix( diff1_f.rgb, diff2_f.rgb, alpha );
#ifdef FAKESHADOWS
output_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4( vec4( output_f.rgb, 1.0 ) );
}
#endif

View file

@ -0,0 +1,105 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Blending terrain and masking its edges for a smooth transition into alpha.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps diffuse normalmap
!!samps lightmap
!!samps =LIGHTSTYLED lightmap1 lightmap2 lightmap3
!!samps =DELUXE deluxemap
!!samps =LIGHTSTYLED =DELUXE deluxemap1 deluxemap2 deluxemap3
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipnormal
#include "sys/defs.h"
varying vec2 tex_c;
varying vec4 vex_color;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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 ( void )
{
lightmapped_init();
tex_c = v_texcoord;
vex_color = v_colour;
gl_Position = ftetransform();
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main ( void )
{
vec3 diffuse_f = texture2D( s_diffuse, tex_c ).rgb;
float bw = 1.0 - (diffuse_f.r + diffuse_f.g + diffuse_f.b) / 3.0;
vec3 normal_f = normalize(texture2D(s_normalmap, tex_c).rgb - 0.5);
vec4 vcol = vex_color;
if (vcol.a < 1.0) {
if (bw > vcol.a) {
discard;
}
}
diffuse_f *= lightmap_fragment(normal_f);
#ifdef FAKESHADOWS
diffuse_f *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4( vec4(diffuse_f, 1.0) );
}
#endif

View file

@ -0,0 +1,109 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Alternative way of blending/masking terrain between to diffuse textures.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps diffuse normalmap
!!samps lightmap
!!samps =LIGHTSTYLED lightmap1 lightmap2 lightmap3
!!samps =DELUXE deluxemap
!!samps =LIGHTSTYLED =DELUXE deluxemap1 deluxemap2 deluxemap3
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipnormal
#include "sys/defs.h"
varying vec2 tex_c;
varying vec4 vex_color;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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 ( void )
{
lightmapped_init();
tex_c = v_texcoord;
vex_color = v_colour;
gl_Position = ftetransform();
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main ( void )
{
vec3 diffuse_f = texture2D( s_diffuse, tex_c ).rgb;
vec3 normal_f = normalize(texture2D(s_normalmap, tex_c).rgb - 0.5);
float bw = (diffuse_f.r + diffuse_f.g + diffuse_f.b) / 3.0;
vec4 vcol = vex_color;
float alpha = 1.0;
if (vcol.a < 1.0) {
if (bw > vcol.a) {
discard;
}
}
if (bw > (vcol.a * 0.25))
alpha = vcol.a;
diffuse_f *= lightmap_fragment(normal_f);
#ifdef FAKESHADOWS
diffuse_f *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4( vec4(diffuse_f, alpha) );
}
#endif

View file

@ -0,0 +1,73 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Terrain shader used for skyroom surfaces.
//==============================================================================
!!ver 110
!!permu FOG
!!permu BUMP
!!permu DELUXE
!!samps 4 diffuse
!!samps lightmap
!!samps =LIGHTSTYLED lightmap1 lightmap2 lightmap3
!!samps =DELUXE deluxemap
!!samps =LIGHTSTYLED =DELUXE deluxemap1 deluxemap2 deluxemap3
#include "sys/defs.h"
#include "sys/fog.h"
varying vec2 tex_c;
varying vec4 vex_color;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#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 ()
{
tex_c = v_texcoord;
lm_c = v_lmcoord;
vex_color = v_colour;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main ()
{
vec4 diff1_f = texture2D( s_t0, tex_c );
vec4 diff2_f = texture2D( s_t1, tex_c );
vec3 output_f = mix( diff1_f.rgb, diff2_f.rgb, vex_color.a ) * lightmap_fragment(normal_f);
gl_FragColor = fog4( vec4( output_f.rgb, 1.0 ) );
}
#endif

View file

@ -0,0 +1,103 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Terrain shader exclusive to tw_valley. One of the few surfaces that do not
// draw a normalmap as it's too expensive.
//==============================================================================
!!ver 110
!!permu FOG
!!samps 6
!!samps lightmap
!!samps =LIGHTSTYLED lightmap1 lightmap2 lightmap3
!!samps =DELUXE deluxemap
!!samps =LIGHTSTYLED =DELUXE deluxemap1 deluxemap2 deluxemap3
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
#include "sys/defs.h"
varying vec2 tex_c;
varying vec2 detail_c;
varying vec4 vex_color;
varying vec2 lm0;
#ifdef LIGHTSTYLED
varying vec2 lm1, lm2, lm3;
#endif
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#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 ( void )
{
tex_c = v_texcoord * 2.5;
detail_c = tex_c * 7.5;
lm_c = v_lmcoord;
vex_color = v_colour;
gl_Position = ftetransform();
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
#include "sys/pcf.h"
vec3 lightmap_fragment (vec3 normal_f)
{
vec3 lightmaps;
#ifdef LIGHTSTYLED
lightmaps = texture2D(s_lightmap0, lm0).rgb * e_lmscale[0].rgb * dot(normal_f, (texture2D(s_deluxemap0, lm0).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap1, lm1).rgb * e_lmscale[1].rgb * dot(normal_f, (texture2D(s_deluxemap1, lm1).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap2, lm2).rgb * e_lmscale[2].rgb * dot(normal_f, (texture2D(s_deluxemap2, lm2).rgb - 0.5) * 2.0);
lightmaps += texture2D(s_lightmap3, lm3).rgb * e_lmscale[3].rgb * dot(normal_f, (texture2D(s_deluxemap3, lm3).rgb - 0.5) * 2.0);
#else
lightmaps = texture2D(s_lightmap, lm0).rgb * e_lmscale.rgb * dot(normal_f, (texture2D(s_deluxemap, lm0).rgb - 0.5) * 2.0);
#endif
return lightmaps;
}
void main ( void )
{
vec4 diff1_f = texture2D( s_t0, tex_c);
vec4 diff2_f = texture2D( s_t1, tex_c);
vec3 lm1_f = texture2D( s_lightmap, lm_c ).rgb * e_lmscale.rgb;
vec3 d1_f = texture2D(s_t2, detail_c).rgb;
vec3 d2_f = texture2D(s_t3, detail_c).rgb;
diff1_f.rgb *= d1_f;
diff2_f.rgb *= d2_f;
diff1_f.rgb *= * lightmap_fragment(normal_f);
diff2_f.rgb *= * lightmap_fragment(normal_f);
vec3 output_f = mix( diff1_f.rgb, diff2_f.rgb, vex_color.a );
#ifdef FAKESHADOWS
output_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4( vec4( output_f.rgb, 1.0 ) );
}
#endif

View file

@ -0,0 +1,31 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Unlit surface.
//==============================================================================
!!ver 110
!!permu FOG
!!samps diffuse
#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 d_f = texture2D( s_diffuse, tex_c );
gl_FragColor = fog4( d_f );
}
#endif

View file

@ -0,0 +1,87 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Basic lightgrid-lit surface. Also supports a fullbrightmap.
//==============================================================================
!!ver 110
!!permu FRAMEBLEND
!!permu BUMP
!!permu FOG
!!permu SKELETAL
!!samps diffuse fullbright normalmap
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipdiffuse
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 norm;
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#endif
#ifdef VERTEX_SHADER
#include "sys/skeletal.h"
void main (void)
{
vec3 n, s, t, w;
tex_c = v_texcoord;
gl_Position = skeletaltransform_wnst(w,n,s,t);
norm = n;
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#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 diff_f = texture2D(s_diffuse, tex_c);
vec4 fb_f = texture2D(s_fullbright, tex_c);
vec3 normal_f = (texture2D(s_normalmap, tex_c).rgb - 0.5) * 2.0;
vec3 light;
if (diff_f.a < 0.5) {
discard;
}
#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
diff_f.rgb *= light;
diff_f.rgb += fb_f.rgb;
#ifdef FAKESHADOWS
diff_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4(diff_f * e_colourident) * e_lmscale;
}
#endif

View file

@ -0,0 +1,108 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightgrid-lit surface, normalmap's alpha contains environment cube reflec-
// tivity.
//==============================================================================
!!ver 110
!!permu FRAMEBLEND
!!permu FOG
!!permu SKELETAL
!!samps diffuse reflectcube normalmap
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipenvmaps
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 eyevector;
varying vec3 norm;
varying mat3 invsurface;
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#endif
#ifdef VERTEX_SHADER
#include "sys/skeletal.h"
void main ()
{
vec3 n, s, t, w;
gl_Position = skeletaltransform_wnst(w,n,s,t);
norm = n;
n = normalize(n);
s = normalize(s);
t = normalize(t);
tex_c = v_texcoord;
/* normalmap */
invsurface = mat3(s, t, n);
/* reflect */
vec3 eyeminusvertex = e_eyepos - w.xyz;
eyevector.x = dot(eyeminusvertex, s.xyz);
eyevector.y = dot(eyeminusvertex, t.xyz);
eyevector.z = dot(eyeminusvertex, n.xyz);
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#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)
{
vec3 cube_c;
vec4 out_f = vec4(1.0, 1.0, 1.0, 1.0);
vec4 diff_f = texture2D(s_diffuse, tex_c);
vec4 normal_f = (texture2D(s_normalmap, tex_c) - 0.5) * 2.0;
vec3 light;
if (diff_f.a < 0.5) {
discard;
}
#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
if (float(dev_skipenvmaps) == 0.0) {
cube_c = reflect(normalize(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;
diff_f.rgb = mix(textureCube(s_reflectcube, cube_c).rgb, diff_f.rgb, diff_f.a);
}
diff_f.rgb *= light;
out_f.rgb = mix(textureCube(s_reflectcube, cube_c).rgb, diff_f.rgb, normal_f.a);
#ifdef FAKESHADOWS
out_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4(out_f * e_colourident) * e_lmscale;
}
#endif

View file

@ -0,0 +1,108 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightgrid-lit surface, normalmap's alpha contains specularity information.
//==============================================================================
!!ver 110
!!permu FRAMEBLEND
!!permu FOG
!!permu SKELETAL
!!cvarf gl_specular
!!samps diffuse fullbright normalmap
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipdiffuse
!!cvardf dev_skipspecular
!!cvardf dev_skipenvmaps
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 eyevector;
varying vec3 norm;
varying mat3 invsurface;
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#endif
#ifdef VERTEX_SHADER
#include "sys/skeletal.h"
void main ()
{
vec3 n, s, t, w;
gl_Position = skeletaltransform_wnst(w,n,s,t);
norm = n;
n = normalize(n);
s = normalize(s);
t = normalize(t);
tex_c = v_texcoord;
/* normalmap */
invsurface = mat3(s, t, n);
/* reflect */
eyevector = e_eyepos - w.xyz;
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#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 ()
{
vec4 diffuse_f = texture2D( s_diffuse, tex_c );
vec3 normal_f = (texture2D(s_normalmap, tex_c).rgb - 0.5) * 2.0;
vec4 fb_f = texture2D(s_fullbright, tex_c);
float gloss = texture2D( s_normalmap, tex_c ).a;
vec3 new_e_light_dir = vec3(cos(e_time), sin(e_time), 0);
vec3 light;
if (diffuse_f.a < 0.5) {
discard;
}
#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
if (float(dev_skipspecular) == 0.0) {
vec3 halfdir = normalize(normalize(eyevector) + e_light_dir);
vec3 bumps = normalize(invsurface * (normal_f));
float spec = pow(max(dot(halfdir, bumps), 0.0), FTE_SPECULAR_EXPONENT);
spec *= 5.0 * (1.0 - gloss);
diffuse_f.rgb += spec;
}
diffuse_f.rgb *= light;
diffuse_f.rgb += fb_f.rgb;
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4( diffuse_f * e_colourident ) * e_lmscale;
}
#endif

View file

@ -0,0 +1,106 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightgrid-lit surface that contains environment cube reflectivity in the
// diffusemaps' alpha channel and specularity in the normalmaps' alpha channel.
//==============================================================================
!!ver 110
!!permu FRAMEBLEND
!!permu FOG
!!permu SKELETAL
!!cvarf gl_specular
!!samps diffuse normalmap reflectcube
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipnormal
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 eyevector;
varying vec3 norm;
varying mat3 invsurface;
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#endif
#ifdef VERTEX_SHADER
#include "sys/skeletal.h"
void main ()
{
vec3 n, s, t, w;
gl_Position = skeletaltransform_wnst(w,n,s,t);
norm = n;
n = normalize(n);
s = normalize(s);
t = normalize(t);
tex_c = v_texcoord;
/* normalmap */
invsurface = mat3(s, t, n);
/* reflect */
eyevector = e_eyepos - w.xyz;
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#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 ()
{
vec3 cube_c;
vec4 diffuse_f = texture2D( s_diffuse, tex_c );
vec3 normal_f = (texture2D(s_normalmap, tex_c).rgb - 0.5) * 2.0;
float gloss = texture2D( s_normalmap, tex_c ).a;
vec3 new_e_light_dir = vec3(cos(e_time), sin(e_time), 0);
vec3 light;
#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
/* specular */
vec3 halfdir = normalize(normalize(eyevector) + e_light_dir);
vec3 bumps = normalize(invsurface * (normal_f));
float spec = pow(max(dot(halfdir, bumps), 0.0), FTE_SPECULAR_EXPONENT);
spec *= 5.0 * (1.0 - gloss);
diffuse_f.rgb += spec * diffuse_f.a;
/* reflectcube */
cube_c = reflect(normalize(-eyevector), normal_f.rgb * 0.5);
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 = mix(textureCube(s_reflectcube, cube_c).rgb, diffuse_f.rgb, diffuse_f.a);
diffuse_f.rgb *= light;
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4( diffuse_f * e_colourident ) * e_lmscale;
}
#endif

View file

@ -0,0 +1,111 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Lightgrid-lit surface, normalmap alpha contains specularity & reflectivity.
//==============================================================================
!!ver 110
!!permu FRAMEBLEND
!!permu FOG
!!permu SKELETAL
!!cvarf gl_specular
!!samps diffuse normalmap reflectcube
!!permu FAKESHADOWS
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap
!!cvardf dev_skipdiffuse
!!cvardf dev_skipnormal
!!cvardf dev_skipspecular
!!cvardf dev_skipenvmaps
#include "sys/defs.h"
varying vec2 tex_c;
varying vec3 eyevector;
varying vec3 norm;
varying mat3 invsurface;
#ifdef FAKESHADOWS
varying vec4 vtexprojcoord;
#endif
#ifdef VERTEX_SHADER
#include "sys/skeletal.h"
void main ()
{
vec3 n, s, t, w;
gl_Position = skeletaltransform_wnst(w,n,s,t);
norm = n;
n = normalize(n);
s = normalize(s);
t = normalize(t);
tex_c = v_texcoord;
/* normalmap */
invsurface = mat3(s, t, n);
/* reflect */
eyevector = e_eyepos - w.xyz;
#ifdef FAKESHADOWS
vtexprojcoord = (l_cubematrix*vec4(v_position.xyz, 1.0));
#endif
}
#endif
#ifdef FRAGMENT_SHADER
#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 ()
{
vec3 cube_c;
vec4 diffuse_f = texture2D( s_diffuse, tex_c );
vec3 normal_f = (texture2D(s_normalmap, tex_c).rgb - 0.5) * 2.0;
float gloss = texture2D( s_normalmap, tex_c ).a;
vec3 new_e_light_dir = vec3(cos(e_time), sin(e_time), 0);
vec3 light;
#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
if (float(dev_skipspecular) == 0.0) {
vec3 halfdir = normalize(normalize(eyevector) + e_light_dir);
vec3 bumps = normalize(invsurface * (normal_f));
float spec = pow(max(dot(halfdir, bumps), 0.0), FTE_SPECULAR_EXPONENT);
spec *= 5.0 * (1.0 - gloss);
diffuse_f.rgb += spec;
}
if (float(dev_skipenvmaps) == 0.0) {
cube_c = reflect(normalize(-eyevector), normal_f.rgb * 0.5);
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 = mix(textureCube(s_reflectcube, cube_c).rgb, diffuse_f.rgb, gloss);
}
diffuse_f.rgb *= light;
#ifdef FAKESHADOWS
diffuse_f.rgb *= ShadowmapFilter(s_shadowmap, vtexprojcoord);
#endif
gl_FragColor = fog4( diffuse_f * e_colourident ) * e_lmscale;
}
#endif

View file

@ -0,0 +1,36 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Trisoup whose diffusemap multiplies against the glColor values.
//==============================================================================
!!ver 110
!!permu FRAMEBLEND
!!permu FOG
!!samps diffuse
#include "sys/defs.h"
varying vec2 tex_c;
varying vec4 vex_color;
#ifdef VERTEX_SHADER
void main ()
{
tex_c = v_texcoord;
vex_color = v_colour;
gl_Position = ftetransform();
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
void main ()
{
vec4 diffuse_f = texture2D( s_diffuse, tex_c );
diffuse_f.rgb *= vex_color.rgb;
gl_FragColor = fog4( diffuse_f );
}
#endif

View file

@ -0,0 +1,70 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Basic water shader, No diffuse texture, just pure normalmap + refraction
//==============================================================================
!!ver 110
!!permu FOG
!!samps 2 normalmap reflectcube
#include "sys/defs.h"
varying mat3 invsurface;
varying vec4 tf_c;
varying vec3 eyeminusvertex;
varying vec3 eyevector;
varying vec2 shift1;
varying vec2 shift2;
#ifdef VERTEX_SHADER
void main ()
{
invsurface[0] = v_svector;
invsurface[1] = v_tvector;
invsurface[2] = v_normal;
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 );
tf_c = ftetransform();
tf_c.z += 0.1; /* hack to get rid of refraction artifacts */
shift1 = v_texcoord + vec2( e_time * 0.1, 0.0 );
shift2 = v_texcoord - vec2( 0, e_time * -0.01 );
gl_Position = tf_c;
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
void main ( void )
{
float fres;
vec2 refl_c;
vec3 refl_f;
vec3 refr_f;
vec3 norm_f;
vec4 out_f = vec4( 1.0, 1.0, 1.0, 1.0 );
// Use the normalmap to shift the refraction
norm_f = ( texture2D( s_normalmap, shift1 ).xyz);
norm_f += ( texture2D( s_normalmap, shift2 ).xyz);
norm_f -= 1.0 - ( 4.0 / 256.0 );
norm_f = normalize( norm_f ) * 0.05;
// Reflection/View coordinates
refl_c = ( 1.0 + ( tf_c.xy / tf_c.w ) ) * 0.5;
refl_c.t -= 1.5 * invsurface[2].z / 1080.0;
vec3 cube_c = reflect( normalize( -eyevector ), texture2D( s_normalmap, shift2).rgb * 0.35 );
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;
refl_f = textureCube( s_reflectcube, cube_c ).rgb;
refr_f = texture2D( s_t1, refl_c + ( norm_f.st * 0.1 ) ).rgb;
fres = pow( 1.0 - abs( dot( norm_f, normalize( eyeminusvertex ) ) ), 5.0 );
out_f.rgb = mix( refr_f, refl_f, fres * 0.25 );
gl_FragColor = fog4( out_f );
}
#endif

View file

@ -0,0 +1,59 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Dirty water shader (diffuse and normalmap only) where a refraction-ish effect
// is applied onto the diffusemap itself.
//==============================================================================
!!ver 110
!!permu FOG
!!samps diffuse normalmap
#include "sys/defs.h"
varying vec2 tex_c;
varying vec2 lm_c;
varying vec3 invsurface;
varying vec4 tf_c;
varying vec3 eyeminusvertex;
varying vec2 wat1_c;
varying vec2 wat2_c;
#ifdef VERTEX_SHADER
void main(void)
{
invsurface = v_normal;
eyeminusvertex = e_eyepos - v_position.xyz;
tf_c = ftetransform();
tex_c = v_texcoord;
gl_Position = tf_c;
wat1_c = tex_c + vec2(e_time * 0.05, 0.0);
wat2_c = tex_c - vec2(0, e_time * 0.05);
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
void main(void)
{
vec3 norm_f;
vec4 out_f = vec4(1.0, 1.0, 1.0, 1.0);
vec2 wat3_c;
// Use the normalmap to shift the refraction
norm_f = (texture2D(s_normalmap, wat1_c).xyz);
norm_f += (texture2D(s_normalmap, wat2_c).xyz);
norm_f -= 1.0 - (4.0 / 256.0);
norm_f = normalize(norm_f);
wat3_c = tex_c + (norm_f.st * 0.025) + vec2(sin(e_time * 0.1), 0);
// Load reflection and refraction based on our new coords
out_f.rgb = texture2D(s_diffuse, wat3_c).rgb;
gl_FragColor = fog4(out_f);
}
#endif

View file

@ -0,0 +1,54 @@
!!ver 110
!!permu FOG
!!samps reflection=0 refraction=1 normalmap=2
#include "sys/defs.h"
varying vec2 tex_c;
varying mat3 invsurface;
varying vec4 tf_c;
varying vec3 eyeminusvertex;
#ifdef VERTEX_SHADER
void main ()
{
invsurface[0] = v_svector;
invsurface[1] = v_tvector;
invsurface[2] = v_normal;
eyeminusvertex = e_eyepos - v_position.xyz;
tf_c = ftetransform();
tf_c.z += 0.1; /* hack to get rid of refraction artifacts */
tex_c = v_texcoord;
gl_Position = tf_c;
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
void main ( void )
{
float fres;
vec2 refl_c;
vec3 refl_f;
vec3 refr_f;
vec3 norm_f;
vec4 out_f = vec4( 1.0, 1.0, 1.0, 1.0 );
norm_f = ( texture2D( s_normalmap, tex_c + vec2( e_time * 0.01, 0.0 ) ).xyz);
norm_f += ( texture2D( s_normalmap, tex_c - vec2( 0, e_time * 0.01 ) ).xyz);
norm_f -= 1.0 - ( 4.0 / 256.0 );
norm_f = normalize( norm_f );
// Reflection/View coordinates
refl_c = ( 1.0 + ( tf_c.xy / tf_c.w ) ) * 0.5;
refl_c.t -= 1.5 * invsurface[2].z / 1080.0;
refl_f = texture2D( s_reflection, refl_c ).rgb;
refr_f = texture2D( s_refraction, refl_c + ( norm_f.st) ).rgb;
fres = pow( 1.0 - abs( dot( norm_f, normalize( eyeminusvertex ) ) ), 5.0 );
out_f.rgb = mix( refr_f, refl_f, fres );
gl_FragColor = fog4( out_f );
}
#endif

View file

@ -0,0 +1,72 @@
//======= Copyright (c) 2015-2020 Vera Visions LLC. All rights reserved. =======
//
// Purpose:
//
// Water shader (normalmap only) where there's only refraction.
//==============================================================================
!!ver 110
!!permu FOG
!!samps 2 diffuse normalmap reflectcube
#include "sys/defs.h"
varying vec2 tex_c;
varying vec2 lm_c;
varying mat3 invsurface;
varying vec4 tf_c;
varying vec3 eyeminusvertex;
varying vec3 eyevector;
varying vec2 shift1;
varying vec2 shift2;
#ifdef VERTEX_SHADER
void main ()
{
invsurface[0] = v_svector;
invsurface[1] = v_tvector;
invsurface[2] = v_normal;
eyeminusvertex = e_eyepos - v_position.xyz;
tf_c = ftetransform();
tf_c.z += 0.1;
shift1 = v_texcoord + vec2( e_time * 0.025, 0.0 );
shift2 = v_texcoord - vec2( 0, e_time * -0.025 );
tex_c = v_texcoord;
gl_Position = tf_c;
}
#endif
#ifdef FRAGMENT_SHADER
#include "sys/fog.h"
void main ( void )
{
float fres;
vec2 refl_c;
vec3 refl_f;
vec3 refr_f;
vec3 norm_f;
vec4 out_f = vec4( 1.0, 1.0, 1.0, 1.0 );
// Use the normalmap to shift the refraction
norm_f = ( texture2D( s_normalmap, shift1 ).xyz);
norm_f += ( texture2D( s_normalmap, shift2 ).xyz);
norm_f -= 1.0 - ( 4.0 / 1024.0 );
norm_f = normalize( norm_f ) * 0.1;
// Reflection/View coordinates
refl_c = ( 1.0 + ( tf_c.xy / tf_c.w ) ) * 0.5;
refl_c.t -= 1.5 * invsurface[2].z / 1080.0;
// Load reflection and refraction based on our new coords
refl_f = texture2D( s_t0, refl_c).rgb;
refr_f = texture2D( s_t1, refl_c + ( norm_f.st * 0.1 ) ).rgb;
fres = pow( 1.0 - abs( dot( norm_f, normalize( eyeminusvertex ) ) ), 5.0 );
out_f.rgb = refr_f;
gl_FragColor = fog4(out_f);
}
#endif