• ### Announcements

#### Archived

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

# Lights problem

## Recommended Posts

willyx    122
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 on other sites
vincoof    514
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 on other sites
willyx    122
I use different size for textures, some are 128*128, others 64*64 and i draw all texture in any x*y position...is that the problem?

##### Share on other sites
vincoof    514
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 on other sites
siaspete    208
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 on other sites
willyx    122
Yes this is problem...there is any way to fix it?

##### Share on other sites
Lord Karnus    122
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 on other sites
vincoof    514
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 on other sites
willyx    122
Textures are ok without lights, the problem is the light.
Now i draw tiles in this way:

glNormal3f( 0.0f, 0.0f, 1.0f);
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 on other sites
willyx    122
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 on other sites
vincoof    514
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);
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 on other sites
siaspete    208
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 on other sites
willyx    122
Thanks, I can void the problem in the background tiling, now looks better:

http://www.geocities.com/gnomorinco/Image1.jpg