2d bump mapping + light

Started by
-1 comments, last by DJLink 12 years, 4 months ago
Hi there.

I'm trying to achieve this effect, not the deferred lights nor the cones, just the bump map effect when the light moves.

http://www.youtube.c...h?v=ppXk2FekRp8


I did this using bits from here and there I found on the Internet and so far I get this:
As you can see, apart from not looking very good it only work if I have my mouse inside that square, other that that it gets black.
Can anyone help out?

3s09.png

Vertex Shader

varying vec2 vTexCoord;
varying vec3 v_vertPos3D;

void main(void)
{
vTexCoord = gl_MultiTexCoord0.st;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
v_vertPos3D = gl_Position.xyz;
}


And my fragment shader


uniform sampler2D diffuse; // Normal Color Texture
uniform sampler2D normalMap; // Normal Map texture
uniform float squaredRange; // Squared range distance of the ligth
uniform vec3 lightPos; // Light Position
uniform vec4 lightColor; // Light Color


varying vec2 vTexCoord;
varying vec3 v_vertPos3D;

void main()
{

lowp vec4 diffuseColor = texture2D(diffuse, vTexCoord);
lowp vec3 normalColor = texture2D(normalMap, vTexCoord).xyz;

vec3 lightVec = v_vertPos3D - lightPos;

normalColor = -(2.0 * (normalColor - 0.5));

lowp float diffuseLight = dot(normalize(lightVec), normalColor);

float squaredDist = dot(lightVec, lightVec);

squaredDist = min(squaredDist, squaredRange);
mediump float attenBias = 1.0 - (squaredDist / squaredRange);

gl_FragColor = (diffuseColor * lightColor) * attenBias * diffuseLight;
}

[twitter]DJ_Link[/twitter]
Blog

This topic is closed to new replies.

Advertisement