Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Opengl - Lighting problem

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 Shawn619   Members   

342
Like
0Likes
Like

Posted 22 March 2012 - 04:30 AM

My one light seems to 'jump' and not flow smoothly across my floor tile texture.

It's much better explained in this short youtube video

Note that my light is not going somewhere and coming back; it is always located half way between the camera and the cube.

This is my function for drawing the floor tiles:
void drawFloor(){
 float size = 20.0;
 float startX = -60.0f;
 float startZ = 60.0f;
 glDisable(GL_COLOR_MATERIAL);
 glPushMatrix();
 glEnable(GL_TEXTURE_2D);
 glBindTexture(GL_TEXTURE_2D, _textureId);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	   
 for(int x = 0;x < 6; x++){
  for(int z = 0;z < 6; z++){
   glBegin(GL_QUADS);
   glNormal3f(0.0f, 1.0f, 0.0f);
    glTexCoord2f(0.0f, 0.0f);
   glVertex3f(startX + size*x, 0.0f, startZ + -size*z);//bottom-left
    glTexCoord2f(1.0f, 0.0f);
   glVertex3f(startX + size + size*x, 0.0f, startZ + -size*z);//bottom-right
    glTexCoord2f(1.0f, 1.0f);
   glVertex3f(startX + size + size*x, 0.0f, startZ + -size + -size*z);//top-right
    glTexCoord2f(0.0f, 1.0f);
   glVertex3f(startX + size*x, 0.0f, startZ + -size + -size*z);//top-left
   glEnd();
  }
 }
 glDisable(GL_TEXTURE_2D);
 glPopMatrix();
 glEnable(GL_COLOR_MATERIAL);
}


Question: How can i make my light not jump and light the tiles smoothly?

#2 FXACE   Members   

182
Like
1Likes
Like

Posted 22 March 2012 - 08:18 AM

Because a default OpenGL state renderer computes a lighting per vertex (not per pixel). There are two solutions:
1: Make the floor more "high-poly".
2: Render with shaders (which computes lighting per pixel). (<< I recommend to use this).

Best wishes, FXACE.

#3 SimonForsman   Members   

7633
Like
0Likes
Like

Posted 22 March 2012 - 09:25 AM

Because a default OpenGL state renderer computes a lighting per vertex (not per pixel). There are two solutions:
1: Make the floor more "high-poly".
2: Render with shaders (which computes lighting per pixel). (<< I recommend to use this).

Best wishes, FXACE.


You can do per pixel lighting without shaders aswell, (google opengl dot3 lighting) which is useful for OpenGL ES 1.1 hardware (mainly older smartphones)
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#4 Shawn619   Members   

342
Like
0Likes
Like

Posted 22 March 2012 - 10:17 AM

Thanks for the answers guys!

I knew it was something like that, but i just couldn't explain technically like you did.

I'm going to work with getting lighting-per-pixel shaders now, thanks!




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.