Terrain lighting artifacts

Started by
19 comments, last by Mihumihu 9 years, 5 months ago
I generate vertex normals in vertex shader, use them for water waves and terrain and have not seen such artifacts
Advertisement
If the interpolation is the case then every mesh you render would have same artifacts.

If the interpolation is the case then every mesh you render would have same artifacts.

Every mesh does have the same artefacts. This isn't something specific to untextured low-poly terrain grids, but it just happens to be obvious in that case.

Agreed.

The ultimate case is a cube.

If you model your cube as 8 points and 12 tri's then the lighting will be awful.

All 8 verts will have normals pointing at 45 degrees away from the vert, (well 45 degrees in two planes).

To get around this you can store "face normals" but not many engines support those, or you export your cube as 24 verts with three verts having the same position, but different normals.

If you get into this position of having strange lighting effects, it's always good to think back to this extreme case and see if the same problem is causing the artifacts you are seeing.

It's a bit like writing L and R on your wellies, a handy check when you are confused. smile.png

OK maybe the artifacts can be seen if normals are not computed properly. I have not experiences such artifacts in my 10 year engine development experience. I can only remember these kind of artifacts, if using vertex lighting and not fragment shader lighting. I as stated previously check your vertex normal generation code. Also check you triangle winding, CW or CCW because i think some of the normals are negative. Check your index and vertex buffers.

I'm having similar issues with my terrain lighting. I've found multiple threads related to this very same issue, but no actual solutions. I've checked and double checked my vertex normal. I've even added the ability to render them to visually confirm they at least look correct. I've also tried using per-pixel lighting shaders from multiple tutorial websites, but I always have this diamond-like pattern artifact. Could it be my Intel HD Graphics 4000 video card?? I've got the latest drivers. Still no luck.

Can anyone please make a suggestion on what to try next?

image001.png

With mesh overlay and vertex normal

image002.png

image003.png

As has been explained several times already in this thread, this is just the way it is. When you triangulate quads and interpolate between 3 points, you will have "artifacts" that depend on how you triangulate it.

There are various mitigations:

- Sample the normals from a texture in your pixel shader. That way you'll be interpolating between 4 points, and not 3.

- Orient your triangulation along the slope line

- Increase the resolution of your height map

- Put a texture on it so it's not so noticeable

Shaders are new technology to me. I'm a bit late to the game.

I recall looking at a per-pixel lighting tutorial a few years ago. It used the standard teapot model and none of these lighting artifacts were noticable from what I remember. The quads in that teapot model mesh were also simply split into two triangles. I guess the lighting artifacts just become more and more noticeable when the curvature of the mesh increases?? Is that correct?

If you could point me to a tutorial that describes interpolating a normals texture in a pixel shader, I'd appreciate it.

Thanks.

Wouldn't using GL_QUADS instead of GL_TRIANGLES cause the pixel shader to interpolate between four points? I tried this, but the issue still exists.

Wouldn't using GL_QUADS instead of GL_TRIANGLES cause the pixel shader to interpolate between four points? I tried this, but the issue still exists.

Quads are simply converted to triangles which is why GL_QUADS was removed from the OpenGL API.

This topic is closed to new replies.

Advertisement