Jump to content
  • Advertisement
Sign in to follow this  
cherryyosh

GLSL - Directional Light

This topic is 3517 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, I am working on a directional light, but cant seem to get it working right.. Currently The light moves with the camera ( I have both a spot and point light using hte same code that do not do this) and the light only works on side walls. leaving the floor black.. Heres the code
Quote:
void DirectionalLight( in int i, in vec3 position, in vec3 normal, inout vec3 color ){ float nDotL, nDotHV; vec3 direction; direction = normalize(gl_LightSource.position.xyz); nDotL = dot( normal, direction ); if( nDotL > 0.0 ){ color *= ( gl_LightSource.diffuse.rgb * nDotL ); nDotHV = max(dot(normal, halfV), 0.0 ); color += 0.2 * gl_LightSource.specular.rgb * pow( nDotHV, 1.0 ); //0.4 = spec power, 1.0 = shineyness } }

Share this post


Link to post
Share on other sites
Advertisement
Sorry, I was gone for a bit..

The normals are correct, as is the position, negating the direction only makes the problem worse, full black screen.

Share this post


Link to post
Share on other sites
nDotL = dot( normal, direction ); // make sure these both are in the same space
(usually world-space)
Did you forget to multiply "normal" with gl_NormalMatrix ?

Share this post


Link to post
Share on other sites
Quote:
Original post by idinev
nDotL = dot( normal, direction ); // make sure these both are in the same space
(usually world-space)
Did you forget to multiply "normal" with gl_NormalMatrix ?


As i've said before i have a point and a spot light function that both work fine. The normal and position are both correct.

EDIT:
Ok, I know both the position and normal are in eye space, the direction and half vectors I am not sure about.

The direction, for point and spot lights, is calculated by normalize( ...position.xyz - position );

and the half vector is by normalize(direction + position)

for the directional, right now I have halfV being
normalize( gl_LightSource[0].halfVector.xyz); in the vertex shader which is then interpolated in the fragment...

[Edited by - cherryyosh on December 27, 2008 12:56:55 PM]

Share this post


Link to post
Share on other sites
what colour is the floor (not black? haha)?
that that negating the normal in the 'direction' calculation produces no colour at all... this means your normals point into the walls. However, when you calculate the specular, you treat the normals as if they point into the same halfspace as the halfvector; should that maybe not be?:

nDotHV = max(dot(-normal, halfV), 0.0 );

Share this post


Link to post
Share on other sites
Make sure you apply the lighting AFTER you do the Camera transformations. Lighting is applied to Eye Coordinates. So if you do it before you make your transformations, it will move with them.

Share this post


Link to post
Share on other sites
Quote:
Original post by rewolfer
what colour is the floor (not black? haha)?
that that negating the normal in the 'direction' calculation produces no colour at all... this means your normals point into the walls. However, when you calculate the specular, you treat the normals as if they point into the same halfspace as the halfvector; should that maybe not be?:

nDotHV = max(dot(-normal, halfV), 0.0 );


Would the floor being black matter at all? After all the light should hit everything and thuse effect everything a little making it none black. As I've said before, the normals are correct, using the same code I have a working point and spot light that do as they should. Negating the normal in the nDotHV do nothing but make the whole screen black. (IE, no lighting is applyed )

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!