stk-code_catmod/data/shaders/water.frag
vincentlj 42c16b32cb OGL32CTX: Replace deprecated "varying" by in/out semantic and make them explicit.
gl_Texcoord[]/gl_Color should be explocitly passed as in/out.
Compilers can pack varyings if the architecture does benefit from it (for instance intel mesa driver) but on the other hand they usually don't change size of varying even if there is only a single component used.
So storing vec2 into vec4 may waste performances.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14974 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2014-01-09 00:17:28 +00:00

58 lines
1.6 KiB
GLSL

// Shader based on work by Fabien Sanglard
// Released under the terms of CC-BY 3.0
#version 130
uniform sampler2D BumpTex1; // Normal map 1
uniform sampler2D BumpTex2; // Normal map 2
uniform sampler2D DecalTex; //The texture
uniform vec2 delta1;
uniform vec2 delta2;
noperspective in vec3 lightVec;
noperspective in vec3 halfVec;
noperspective in vec3 eyeVec;
in vec2 uv;
void main()
{
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
vec3 normal = 2.0 * texture2D (BumpTex1, uv + delta1).rgb - 1.0;
vec3 normal2 = 2.0 * texture2D (BumpTex2, uv + 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, uv + vec2(delta1.x, 0.0));
diffuseLight = vec4(1.0, 1.0, 1.0, 1.0);
vec3 col = diffuseMaterial.xyz * (0.3 + lamberFactor*0.7);
// specular (phong)
vec3 R = normalize(reflect(lightVec, normal));
float specular = max(dot(R, eyeVec), 0.0);
// weak specular
specular = specular*specular;
specular = specular*specular;
float specular_weak = specular*0.05;
col += vec3(specular_weak, specular_weak, specular_weak);
// strong specular
specular = specular*specular;
float specular_strong = specular*0.3;
col += vec3(specular_strong, specular_strong, specular_strong);
float summed = dot(vec3(1.0), col) / 3.0;
float alpha = 0.9 + 0.1 * smoothstep(0.0, 1.0, summed);
gl_FragColor = vec4(col, alpha);
}