Little Lighting issue

i tried using glNormal3f instead, but the results are exactly the same.

This is beginning to fustrate me now!

Dale

If you use the same texture for both parts, do you still get a lighting issue? Or is it just that the road textures are different shades of grey? In which case you’re unlikely to ever get them to match up.

Hi Dan, welcome to the thread!

I just bound the track texture to the start t test this, but unforunately the issue is still the same.

I think this is a normals issue, i must be doing something stupid somewhere!

I have been adding normals to my normals array per vertex now, but then there is no lighting at all!

Dale

This function just computes a face normal from three points. If you pass in 3 different points to compute the normal at the same point, you’re going to get a different normal.

Here’s your track:


A--B
|  |
|  |
C--D
|  |
|  |
E  F

If, for the top quad, you compute the normal at C with A-C-D, and if for the bottom quad, you compute the normal at C with D-C-E, you’re going to end up with a different normal at C and thus a different lighting result at C for the 2 quads (unless the two quads are coplanar).

I don’t know if this is your problem, but it’s at least a possibility to consider. If so, the solution is to use the same normal for C between the two quads (and for D of course). In other words, compute your normal differently.

Normals should represent the normal of the real surface you’re trying to represent, not the tessellated representation. Then when you interpolate lighting (or even better, normals, with shaders), then you get a nice smooth result.

[quote=“Dark_Photon”]

currently, i am calculating the normals using the bottom left, using the top left and bottom right points to make the triangle. or as in your representation, for the first quad, computing the normal at b using a & d, and for the second quad, computing the normal at d using c & f.

So i should compute the normal at a different point for the second rectangle? i.e. f using d & e?

Or should creating the normals for the track as a whole, i.e. to get the normal of a, use b & f?

Thanks,

Dale

With your current code, you aren’t providing enough normals. You need 1 normal per vertex if using glNormalPointer.

So you should have the equivalent of:

GLfloat trackStartNormals[] = {normal[0],normal[1],normal[2], normal[0],normal[1],normal[2], normal[0],normal[1],normal[2], normal[0],normal[1],normal[2]} ;

Yes, i have been experimenting with this all morning, and if i pass through 4 sets of normals, i get one unified lighting effect over the whole quad, but this is probably because i am not recalculating the normals again, just copying them over.

That is what im going to do next!

Dale

Ok, so have have recalculated the normals 4 times, once for each vertex, and added to the normals array as appropriate.

However, after printing all of the normals for each vertex, the are all : (0,-1,0) for each vertex. is this what you would expect to get for a flat quad?

Dale


EDIT: I think i have this solved now, as there is no more seams in the scene!

This is mainly down to two things:
how i was declaring my normals with the normal pointer.

My mistake in assigning material properties to the objects - no light was being reflected.

The scene is now well lit and looking good!

Thanks to everyone who has helped me get this solved :slight_smile:

Dale