PDA

View Full Version : do i need different normals to go from flat to gouraud or per fragment shading?



a-sylum
01-31-2015, 02:10 PM
hi, i think i understand the main concepts behind gouraud. i also have managed to get some flat shaded lighting effects working on that basic monkey model in blender. i am also using open asset importer to load the normals and vertices from a file. so if my normals are perpendicular to the triangle that is being described, do i need different normals to implement gouraud or per fragment shading? and if not how do i interpolate the normals when they are all the same?
thanks
:)

Betrayal
01-31-2015, 02:57 PM
Well, actually you need normals *per vertex*, not per triangle.
Blender for sure is able to export normals per vertex.

a-sylum
01-31-2015, 03:50 PM
actually thats what i meant, it's just that all the normals are the same for each vertex in the triangle. so i don't know how to get anything but flat shading when all the normals are the same. i guess i get the idea of what gouraud shading does just not how to implement it. i'll just take a look at the tut again tomorrow.
:)

Betrayal
01-31-2015, 04:05 PM
gourad shading = light calculations happens in the vertex shader, for normals per vertex
phong shading = light calculations happens in the fragment shader, for normals per vertex. but, the vertex normals are passed (and automatically interpolated) from vertex to fragment shader.

so you see, you need normals per vertex and not per triangle. in every case, if you want more than flat shading.


sorry bro, i suck at explaining things in english.

GClements
02-01-2015, 07:48 AM
actually thats what i meant, it's just that all the normals are the same for each vertex in the triangle.
Enable smooth shading in blender before exporting. This should also reduce the size of the data for the mesh, as vertices can be shared between faces.

a-sylum
02-01-2015, 11:48 AM
Enable smooth shading in blender so just so im 100% sure, i do need to have different normals?
never mind the previous line, but is all that smooth shading does is change the normals?

GClements
02-02-2015, 09:08 AM
so just so im 100% sure, i do need to have different normals?
never mind the previous line, but is all that smooth shading does is change the normals?

Smooth shading assigns a normal to each vertex. Flat shading assigns a normal to each face.

If the data format associates normals with vertices, then flat shading will result in each face having a distinct set of vertices; when faces adjoin, their vertices will have the same position but (usually) different normals, so they can't be shared.