Question

How can I get hard edges on my terain. I have a simple ambient and diffuse shader in GLSL. I think that the fragment shader is interpolating the vertex normals and causing smooth shading. Do you guys need my code or is there maybe some setting I can enable?

Current terain without hard edges: http://twirlbound.com/uploads/terain.png

Was it helpful?

Solution

In your vertex shader, do something like this:

flat out vec3 v_normal;

In your fragment shader, something like this:

flat in vec3 v_normal;

flat tells the GL to give all the fragments rasterized for a triangle the same value. Which vertex's normal is used depends on the current 'provoking vertex', set by calling glProvokingVertex.

OTHER TIPS

To get hard edges like you are asking for you need to specify per triangle normals that are perpendicular to the triangles direction. For this you will need to send them as triangles, as apposed to quads or similar.

You should also need to set the following before your drawing routine to get flat shading.

glEnable(GL_FLAT);
glShadeModel(GL_FLAT);

You can set the shading back to smooth after with

glEnable(GL_SMOOTH);
glShadeModel(GL_SMOOTH);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top