Jump to content
  • Advertisement
Sign in to follow this  
DJLink

2d bump mapping + light

This topic is 2571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!