Add WIP water shader. Not yet used because not satisfying
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10740 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
b57ea6a182
commit
f33cbb8dc0
58
data/shaders/water.frag
Normal file
58
data/shaders/water.frag
Normal file
@ -0,0 +1,58 @@
|
||||
// Shader based on work by Fabien Sanglard
|
||||
// Released under the terms of CC-BY 3.0
|
||||
|
||||
uniform sampler2D BumpTex1; // Normal map 1
|
||||
uniform sampler2D BumpTex2; // Normal map 2
|
||||
uniform sampler2D DecalTex; //The texture
|
||||
|
||||
uniform vec2 delta1;
|
||||
uniform vec2 delta2;
|
||||
|
||||
varying vec3 lightVec;
|
||||
varying vec3 halfVec;
|
||||
varying vec3 eyeVec;
|
||||
|
||||
void main()
|
||||
{
|
||||
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
|
||||
vec3 normal = 2.0 * texture2D (BumpTex1, gl_TexCoord[0].st + delta1).rgb - 1.0;
|
||||
vec3 normal2 = 2.0 * texture2D (BumpTex2, gl_TexCoord[0].st + delta2).rgb - 1.0;
|
||||
|
||||
// scale normals
|
||||
//normal.y = 4.0*normal.y;
|
||||
//normal2.y = 4.0*normal2.y;
|
||||
|
||||
normal = (normalize(normal) + normalize(normal2))/2.0;
|
||||
|
||||
// compute diffuse lighting
|
||||
float lamberFactor = max (dot (lightVec, normal), 0.0);
|
||||
vec4 diffuseMaterial;
|
||||
vec4 diffuseLight;
|
||||
|
||||
diffuseMaterial = texture2D (DecalTex, gl_TexCoord[0].st + vec2(delta1.x, 0.0));
|
||||
diffuseLight = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
//if (lamberFactor < 0.7)
|
||||
//{
|
||||
// lamberFactor = 0.0;
|
||||
//}
|
||||
|
||||
gl_FragColor = diffuseMaterial * (lamberFactor);
|
||||
|
||||
// specular (phong)
|
||||
vec3 R = normalize(reflect(lightVec, normal));
|
||||
float specular = max(dot(R,eyeVec),0.0);
|
||||
|
||||
if (specular > 0.0)
|
||||
{
|
||||
// weak specular
|
||||
specular = specular*specular;
|
||||
float specular03 = specular*0.2;
|
||||
gl_FragColor += vec4(specular03, specular03, specular03, 0.0);
|
||||
|
||||
// strong specular
|
||||
specular = specular*specular*specular;
|
||||
float specular06 = specular*0.5;
|
||||
gl_FragColor += vec4(specular06, specular06, specular06, 0.0);
|
||||
}
|
||||
}
|
48
data/shaders/water.vert
Normal file
48
data/shaders/water.vert
Normal file
@ -0,0 +1,48 @@
|
||||
// Shader based on work by Fabien Sanglard
|
||||
// Released under the terms of CC-BY 3.0
|
||||
|
||||
varying vec3 lightVec;
|
||||
varying vec3 halfVec;
|
||||
varying vec3 eyeVec;
|
||||
|
||||
uniform vec3 lightdir;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
|
||||
// Building the matrix Eye Space -> Tangent Space
|
||||
vec3 n = normalize (gl_NormalMatrix * gl_Normal);
|
||||
// gl_MultiTexCoord1.xyz
|
||||
vec3 t = normalize (gl_NormalMatrix * vec3(1.0, 0.0, 0.0)); // tangent
|
||||
vec3 b = cross (n, t);
|
||||
|
||||
vec3 vertexPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
|
||||
|
||||
// transform light and half angle vectors by tangent basis
|
||||
vec3 v;
|
||||
v.x = dot (lightdir, t);
|
||||
v.y = dot (lightdir, b);
|
||||
v.z = dot (lightdir, n);
|
||||
lightVec = normalize (v);
|
||||
|
||||
vertexPosition = normalize(vertexPosition);
|
||||
|
||||
eyeVec = normalize(-vertexPosition); // we are in Eye Coordinates, so EyePos is (0,0,0)
|
||||
|
||||
// Normalize the halfVector to pass it to the fragment shader
|
||||
|
||||
// No need to divide by two, the result is normalized anyway.
|
||||
// vec3 halfVector = normalize((vertexPosition + lightDir) / 2.0);
|
||||
vec3 halfVector = normalize(vertexPosition + lightdir);
|
||||
v.x = dot (halfVector, t);
|
||||
v.y = dot (halfVector, b);
|
||||
v.z = dot (halfVector, n);
|
||||
|
||||
// No need to normalize, t,b,n and halfVector are normal vectors.
|
||||
//normalize (v);
|
||||
halfVec = v ;
|
||||
|
||||
gl_Position = ftransform();
|
||||
}
|
Loading…
Reference in New Issue
Block a user