crystal-of-rhylil/assets/shaders/shader_bump_fragment.txt
2013-01-19 22:25:53 +00:00

35 lines
858 B
Plaintext

precision lowp float;
uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform float Transparency;
varying vec2 texCoord;
varying vec2 posCoord;
void main()
{
vec3 lightPos = vec3(400.0, 200.0, 200.0);
vec3 lVec = normalize(lightPos - vec3(posCoord, 0.0));
vec3 texParam = texture2D(NormalMap, texCoord.st).rgb;
vec3 normVec;
if (texParam.x == 0.0 && texParam.y == 0.0 && texParam.z == 0.0)
{
normVec = vec3(0.0,0.0,1.0);
}
else
{
normVec = (texture2D(NormalMap, texCoord.st).rgb - 0.5)* 2.0;
}
vec4 diffuse = vec4(1.0, 1.0, 1.0, 1.0) * max( dot(lVec, normVec), 0.0) * 0.5;
//vec4 diffuse = vec4(1.0, 1.0, 1.0, 1.0) * 0.5;
vec4 color = texture2D(Texture, texCoord).rgba * 0.5 + texture2D(Texture, texCoord).rgba * diffuse;
gl_FragColor = vec4(color.rgb, color.a * Transparency);
}