Archived

This topic is now archived and is closed to further replies.

Lights problem

This topic is 5795 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

I''ve a little problem with lights as u can see here: http://www.geocities.com/gnomorinco/Image1.jpg I think that the problem is the vector of textures... I''ve made this 2D engine in OpenGL,i use flat planes with the some Z and tiles are made with texture.Lights are at the Z of tiles + something. Thanks

Share this post


Link to post
Share on other sites
To my mind, 3 possibilities :
1- you don''t define the same normals in the upper and lower planes.
2- you don''t define the same material properties (ambient, diffuse, specular, etc) in the planes.
3- you don''t split your geometry identically, eg see figure below :
  
+--------+-------+--------+
^ | | | |
| | | | |
upper| | | |
plane| | | |
| | | | |
V | | | |
+--------+---+---+--------+
^ | | |
| | | |
lower| | |
plane| | |
| | | |
V | | |
+------------+------------+


There woul be other possibilities, but the 3 above are the most "probable" IMHO.

Share this post


Link to post
Share on other sites
I don''t think so.
The problem clearly seems to be lighting.

The only way that textures could produce this effect would be if textures contained explicitly faked colors.

Share this post


Link to post
Share on other sites
Isn''t this just caused by the fact that gouraud shading (ie the shading most cards use for lighting) is per-vertex, not per-pixel?

So basically, the card calculates the brightness of the light at each vertex, then just interpolates. So even though there should be a bright spot, it doesn''t show up.

Share this post


Link to post
Share on other sites
Well, if it is a lighting problem, and I''m correct in assuming that your game world is flat, then the normals for each vertex would be identical (straight at the camera).
However, to me it looks like a texture tiling issue - though I may be mistaken, have you checked that the textures tile seamlessly (a little trickier when you have different texture sizes)?

Share this post


Link to post
Share on other sites
Lord Kranus : the probelm is not due to the texture. In fact, texture may have "seam" problems, but there would not "look" like that.

There is only one solution for per-vertex ligthing (assuming you don''t choose the solution to disable lighting ) : split your geometry so that polygons'' vertices match between upper and lower part.

Do you see the figure that I drew above ?
Well, that''s exactly the problem. You have to split the horizontal middle line, for both upper and lower part, like that :
  
+--------+---*---+--------+
^ | | * | |
| | | * | |
upper| | * | |
plane| | * | |
| | | * | |
V | | * | |
+--------+---+---+--------+
^ | * | * |
| | * | * |
lower| * | * |
plane| * | * |
| | * | * |
V | * | * |
+--------*---+---*--------+


asterisks (*) shows what have to be done. Imagine those asterisks represents lines.

Share this post


Link to post
Share on other sites
Textures are ok without lights, the problem is the light.
Now i draw tiles in this way:

glNormal3f( 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);// Draw Our Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-Dim, -Dim, LACOSTANTE);
glTexCoord2f(1.0f, 0.0f); glVertex3f(+Dim, -Dim, LACOSTANTE);
glTexCoord2f(1.0f, 1.0f); glVertex3f(+Dim, Dim, LACOSTANTE);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-Dim, Dim, LACOSTANTE);
glEnd();

Share this post


Link to post
Share on other sites
vincoof i''ve tryed to use the some tile and place like in your picture, now the problem doesn''t exist, but i cant use only texture with the some size and place in that order...is possible to use per-pixel light?

Share this post


Link to post
Share on other sites
what an awful english
j/k last time I listened to an Italian speaking english, I thought he was speaking Japanese. lol
well, hum, I apologize. back on topic...

You can not use per-pixel lighting. In fact, it is possible but it is either very slow or very very difficult to use.

I agree that if you set texture coordinates with the 4 corners, there''s a problem.
If you split the geometry (like I recommended) you have to define different texture coordinates than 0.0f or 1.0f.

For example :
glNormal3f( 0.0f, 0.0f, 1.0f);
glBegin(GL_QUAD_STRIP);// Draw Our Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-Dim, -Dim, LACOSTANTE);
glTexCoord2f(1.0f, 0.0f); glVertex3f(+Dim, -Dim, LACOSTANTE);
glTexCoord2f(0.0f, 0.75f); glVertex3f(-Dim, Dim/2, LACOSTANTE);
glTexCoord2f(1.0f, 0.75f); glVertex3f(+Dim, Dim/2, LACOSTANTE);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-Dim, Dim, LACOSTANTE);
glTexCoord2f(1.0f, 1.0f); glVertex3f(+Dim, Dim, LACOSTANTE);
glEnd();

be careful of the calling order, because these are quad strips and not quads

Share this post


Link to post
Share on other sites
The best thing to do would be to avoid T-junctions with your polygons.

By T-junctions, I mean where the edges of polys make a T-shape. There should never be an edge touching a vertex. Split the edge!

- Pete

Share this post


Link to post
Share on other sites