Added GLSL shaders

This commit is contained in:
jpaana 2004-04-08 12:45:56 +00:00
parent 43298d6268
commit d37ac7043f
11 changed files with 323 additions and 0 deletions

24
hardware/bump.frag Normal file
View file

@ -0,0 +1,24 @@
uniform sampler2D normalmap;
uniform sampler2D colormap;
uniform sampler3D attenuation;
void main(void)
{
vec4 normal = texture2D(normalmap, gl_TexCoord[0].xy);
normal.rgb = normal.rgb * 2.0 - 1.0;
vec3 lightvec = normalize(gl_TexCoord[1].xyz);
float diffdot = clamp(dot(normal.rgb, lightvec), 0.0, 1.0);
vec4 color = texture2D(colormap, gl_TexCoord[0].xy);
vec3 halfvec = normalize(gl_TexCoord[2].xyz);
float specdot = pow(clamp(dot(normal.rgb, halfvec), 0.0, 1.0), 16.0) * normal.a;
float selfshadow = clamp(lightvec.z * 8.0, 0.0, 1.0);
vec4 atten = texture3D(attenuation, gl_TexCoord[3].xyz);
gl_FragColor = atten * gl_Color * ( color * diffdot * selfshadow + specdot);
}

20
hardware/bump.vert Normal file
View file

@ -0,0 +1,20 @@
// Tenebrae bumpmapping without light filter vertex shader
uniform vec3 lightPos;
uniform vec3 eyePos;
void main(void)
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
vec3 lightVec = normalize(lightPos - gl_Vertex.xyz);
vec3 eyeVec = normalize(eyePos - gl_Vertex.xyz);
vec3 halfVec = (lightVec + eyeVec) * 0.5;
gl_TexCoord[1].x = dot(lightVec, gl_MultiTexCoord1.xyz);
gl_TexCoord[1].y = dot(lightVec, gl_MultiTexCoord2.xyz);
gl_TexCoord[1].z = dot(lightVec, gl_MultiTexCoord3.xyz);
gl_TexCoord[2].x = dot(halfVec, gl_MultiTexCoord1.xyz);
gl_TexCoord[2].y = dot(halfVec, gl_MultiTexCoord2.xyz);
gl_TexCoord[2].z = dot(halfVec, gl_MultiTexCoord3.xyz);
gl_TexCoord[3] = gl_TextureMatrix[2] * gl_Vertex;
gl_FrontColor = gl_Color;
}

26
hardware/bump2.frag Normal file
View file

@ -0,0 +1,26 @@
uniform sampler2D normalmap;
uniform sampler2D colormap;
uniform sampler3D attenuation;
uniform samplerCube filter;
void main(void)
{
vec4 normal = texture2D(normalmap, gl_TexCoord[0].xy);
normal.rgb = normal.rgb * 2.0 - 1.0;
vec3 lightvec = normalize(gl_TexCoord[1].xyz);
float diffdot = clamp(dot(normal.rgb, lightvec), 0.0, 1.0);
vec4 color = texture2D(colormap, gl_TexCoord[0].xy);
vec3 halfvec = normalize(gl_TexCoord[2].xyz);
float specdot = pow(clamp(dot(normal.rgb, halfvec), 0.0, 1.0), 16.0) * normal.a;
float selfshadow = clamp(lightvec.z * 8.0, 0.0, 1.0);
vec4 atten = texture3D(attenuation, gl_TexCoord[3].xyz);
vec4 light = textureCube(filter, gl_TexCoord[4].xyz);
gl_FragColor = atten * light * gl_Color * ( color * diffdot * selfshadow + specdot);
}

21
hardware/bump2.vert Normal file
View file

@ -0,0 +1,21 @@
// Tenebrae bumpmapping without light filter vertex shader
uniform vec3 lightPos;
uniform vec3 eyePos;
void main(void)
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
vec3 lightVec = normalize(lightPos - gl_Vertex.xyz);
vec3 eyeVec = normalize(eyePos - gl_Vertex.xyz);
vec3 halfVec = (lightVec + eyeVec) * 0.5;
gl_TexCoord[1].x = dot(lightVec, gl_MultiTexCoord1.xyz);
gl_TexCoord[1].y = dot(lightVec, gl_MultiTexCoord2.xyz);
gl_TexCoord[1].z = dot(lightVec, gl_MultiTexCoord3.xyz);
gl_TexCoord[2].x = dot(halfVec, gl_MultiTexCoord1.xyz);
gl_TexCoord[2].y = dot(halfVec, gl_MultiTexCoord2.xyz);
gl_TexCoord[2].z = dot(halfVec, gl_MultiTexCoord3.xyz);
gl_TexCoord[3] = gl_TextureMatrix[2] * gl_Vertex;
gl_TexCoord[4] = gl_TextureMatrix[3] * gl_Vertex;
gl_FrontColor = gl_Color;
}

29
hardware/bump2_c.frag Normal file
View file

@ -0,0 +1,29 @@
uniform sampler2D normalmap;
uniform sampler2D colormap;
uniform sampler3D attenuation;
uniform samplerCube filter;
uniform sampler2D glossmap;
void main(void)
{
vec4 normal = texture2D(normalmap, gl_TexCoord[0].xy);
normal.rgb = normal.rgb * 2.0 - 1.0;
vec3 lightvec = normalize(gl_TexCoord[1].xyz);
float diffdot = clamp(dot(normal.rgb, lightvec), 0.0, 1.0);
vec4 color = texture2D(colormap, gl_TexCoord[0].xy);
vec3 halfvec = normalize(gl_TexCoord[2].xyz);
float specdot = pow(clamp(dot(normal.rgb, halfvec), 0.0, 1.0), 16.0);
vec4 gloss = texture2D(glossmap, gl_TexCoord[0].xy);
gloss = gloss * specdot;
float selfshadow = clamp(lightvec.z * 8.0, 0.0, 1.0);
vec4 atten = texture3D(attenuation, gl_TexCoord[3].xyz);
vec4 light = textureCube(filter, gl_TexCoord[4].xyz);
gl_FragColor = atten * light * gl_Color * ( color * diffdot * selfshadow + gloss );
}

26
hardware/bump3.frag Normal file
View file

@ -0,0 +1,26 @@
uniform sampler2D normalmap;
uniform sampler2D colormap;
uniform sampler3D attenuation;
uniform sampler2D filter;
void main(void)
{
vec4 normal = texture2D(normalmap, gl_TexCoord[0].xy);
normal.rgb = normal.rgb * 2.0 - 1.0;
vec3 lightvec = normalize(gl_TexCoord[1].xyz);
float diffdot = clamp(dot(normal.rgb, lightvec), 0.0, 1.0);
vec4 color = texture2D(colormap, gl_TexCoord[0].xy);
vec3 halfvec = normalize(gl_TexCoord[2].xyz);
float specdot = pow(clamp(dot(normal.rgb, halfvec), 0.0, 1.0), 16.0) * normal.a;
float selfshadow = clamp(lightvec.z * 8.0, 0.0, 1.0);
vec4 atten = texture3D(attenuation, gl_TexCoord[3].xyz);
vec4 light = texture2D(filter, gl_TexCoord[4].xy);
gl_FragColor = atten * light * gl_Color * ( color * diffdot * selfshadow + specdot);
}

29
hardware/bump3_c.frag Normal file
View file

@ -0,0 +1,29 @@
uniform sampler2D normalmap;
uniform sampler2D colormap;
uniform sampler3D attenuation;
uniform sampler2D filter;
uniform sampler2D glossmap;
void main(void)
{
vec4 normal = texture2D(normalmap, gl_TexCoord[0].xy);
normal.rgb = normal.rgb * 2.0 - 1.0;
vec3 lightvec = normalize(gl_TexCoord[1].xyz);
float diffdot = clamp(dot(normal.rgb, lightvec), 0.0, 1.0);
vec4 color = texture2D(colormap, gl_TexCoord[0].xy);
vec3 halfvec = normalize(gl_TexCoord[2].xyz);
float specdot = pow(clamp(dot(normal.rgb, halfvec), 0.0, 1.0), 16.0);
vec4 gloss = texture2D(glossmap, gl_TexCoord[0].xy);
gloss = gloss * specdot;
float selfshadow = clamp(lightvec.z * 8.0, 0.0, 1.0);
vec4 atten = texture3D(attenuation, gl_TexCoord[3].xyz);
vec4 light = texture2D(filter, gl_TexCoord[4].xy);
gl_FragColor = atten * light * gl_Color * ( color * diffdot * selfshadow + gloss );
}

27
hardware/bump_c.frag Normal file
View file

@ -0,0 +1,27 @@
uniform sampler2D normalmap;
uniform sampler2D colormap;
uniform sampler3D attenuation;
uniform sampler2D glossmap;
void main(void)
{
vec4 normal = texture2D(normalmap, gl_TexCoord[0].xy);
normal.rgb = normal.rgb * 2.0 - 1.0;
vec3 lightvec = normalize(gl_TexCoord[1].xyz);
float diffdot = clamp(dot(normal.rgb, lightvec), 0.0, 1.0);
vec4 color = texture2D(colormap, gl_TexCoord[0].xy);
vec3 halfvec = normalize(gl_TexCoord[2].xyz);
float specdot = pow(clamp(dot(normal.rgb, halfvec), 0.0, 1.0), 16.0);
vec4 gloss = texture2D(glossmap, gl_TexCoord[0].xy);
gloss = gloss * specdot;
float selfshadow = clamp(lightvec.z * 8.0, 0.0, 1.0);
vec4 atten = texture3D(attenuation, gl_TexCoord[3].xyz);
gl_FragColor = atten * gl_Color * ( color * diffdot * selfshadow + gloss);
}

57
hardware/delux.frag Normal file
View file

@ -0,0 +1,57 @@
uniform sampler2D lightMap;
uniform sampler2D deluxMap;
uniform sampler2D normalMap;
uniform sampler2D baseMap;
uniform vec3 eyePos;
void main(void)
{
//normal
vec3 normal = gl_TexCoord[4].xyz;
//tangent
vec3 tangent = gl_TexCoord[2].xyz;
//binormal
vec3 binormal = gl_TexCoord[3].xyz;
// Get the worldspace delux
vec3 wDelux = 2.0 * texture2D(deluxMap, gl_TexCoord[1].xy).xyz - 1.0;
//Put into tangent space
vec3 tDelux;
tDelux.x = dot(wDelux, tangent);
tDelux.y = dot(wDelux, binormal);
tDelux.z = dot(wDelux, normal);
tDelux = normalize(tDelux);
// Get the normal from normal map lookup
vec4 matNormal = texture2D(normalMap, gl_TexCoord[0].xy);
// Normalize normal part
matNormal.xyz = 2.0 * matNormal.xyz - 1.0;
// normal . light vector
float diffdot = clamp(dot(tDelux, matNormal.xyz),0.0,1.0);
// calculate halfvector, first eye
vec3 halfvec = eyePos - gl_TexCoord[5].xyz;
vec3 trans;
trans.x = dot(halfvec, tangent);
trans.y = dot(halfvec, binormal);
trans.z = dot(halfvec, normal);
halfvec = normalize(trans);
// Final halfvec from eye and light vectors
halfvec = (halfvec + tDelux) * 0.5;
float specdot = clamp(dot(halfvec, matNormal.xyz),0.0,1.0);
specdot = pow(specdot, 16.0);
// mul by gloss
specdot = specdot * matNormal.w;
vec3 base = texture2D(baseMap, gl_TexCoord[0].xy).xyz;
vec3 lmap = texture2D(lightMap, gl_TexCoord[1].xy).xyz;
vec3 res = ((base * diffdot) + specdot) * lmap;
gl_FragColor = res.xyzz;
}

12
hardware/delux.vert Normal file
View file

@ -0,0 +1,12 @@
void main(void)
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
gl_TexCoord[2] = gl_MultiTexCoord2;
gl_TexCoord[3] = gl_MultiTexCoord3;
gl_TexCoord[4] = gl_MultiTexCoord4;
gl_TexCoord[5] = gl_Vertex;
}

52
hardware/delux_c.frag Normal file
View file

@ -0,0 +1,52 @@
uniform sampler2D lightMap;
uniform sampler2D deluxMap;
uniform sampler2D normalMap;
uniform sampler2D baseMap;
uniform sampler2D glossmap;
uniform vec3 eyePos;
void main(void)
{
// Get the worldspace delux
vec3 wDelux = 2.0 * texture2D(deluxMap, gl_TexCoord[1].xy).xyz - 1.0;
//Put into tangent space
vec3 tDelux;
tDelux.x = dot(wDelux, gl_TexCoord[2].xyz);
tDelux.y = dot(wDelux, gl_TexCoord[3].xyz);
tDelux.z = dot(wDelux, gl_TexCoord[4].xyz);
tDelux = normalize(tDelux);
// Get the normal from normal map lookup
vec4 matNormal = texture2D(normalMap, gl_TexCoord[0].xy);
// Normalize normal part
matNormal.xyz = 2.0 * matNormal.xyz - 1.0;
// normal . light vector
float diffdot = clamp(dot(tDelux, matNormal.xyz),0.0,1.0);
// calculate halfvector, first eye
vec3 halfvec = eyePos - gl_TexCoord[5].xyz;
vec3 trans;
trans.x = dot(halfvec, gl_TexCoord[2].xyz);
trans.y = dot(halfvec, gl_TexCoord[3].xyz);
trans.z = dot(halfvec, gl_TexCoord[4].xyz);
halfvec = normalize(trans);
// Final halfvec from eye and light vectors
halfvec = (halfvec + tDelux) * 0.5;
float specdot = clamp(dot(halfvec, matNormal.xyz),0.0,1.0);
specdot = pow(specdot, 16.0);
// mul by gloss
vec3 gloss = texture2D(glossmap, gl_TexCoord[0].xy).xyz;
gloss = gloss * specdot;
vec3 base = texture2D(baseMap, gl_TexCoord[0].xy).xyz;
vec3 lmap = texture2D(lightMap, gl_TexCoord[1].xy).xyz;
vec3 res = ((base * diffdot) + gloss) * lmap;
gl_FragColor = res.xyzz;
}