Advertisement

Fragment shader and normals.

Started by October 08, 2019 11:22 AM
4 comments, last by JoeJ 5 years, 4 months ago

Why, at the fragment shader level, when it is intended to obtain normal value in a specific pixel, is it obtained by interpolating the normal vectors of the vertices that form the triangle?

Being a point on the surface of a triangle, wouldn't the normal vector directly be the normal vector of that triangle?

I think there is something I am not considering.

Thank you.

Most triangle meshes are a discrete approximation of a continuous, curved surface, so interpolated normals are just a visual trick to make them appear smooth and curvy again. 

Advertisement
1 minute ago, JoeJ said:

Most triangle meshes are a discrete approximation of a continuous, curved surface, so interpolated normals are just a visual trick to make them appear smooth and curvy again. 

Oh, you mean that when you get the value through interpolation you get an intermediate color that generates a gradient effect, and there are no abrupt changes between the colors of the different illuminated pixels?

Effectively yes. With normal calculation in the vertex stage (by using vertex- or triangle-normals) without smoothing the primitives are clearly visible. Even with some interpolation (gouraud shading) specular highlights will still have the pattern of the vertices/triangles visible because they depend much on the normals. A dense mesh can ease this a bit, but when zooming near the primitives will become visible again.

Passing the normals down the pipeline for interpolation (like one would do for the classic phong shading model) will cause a smooth interpolation, even when zooming in closer or othrwise LODing, mipmapping, etc. This is visually much more pleasing, but of course no comparison to physically based rendering.

53 minutes ago, Goyira said:

Oh, you mean that when you get the value through interpolation you get an intermediate color that generates a gradient effect, and there are no abrupt changes between the colors of the different illuminated pixels?

Yes, but do not confuse colors and normals. The color gradient is a result of interpolated normals and using them for shading to get the color. (So dpending on shading, there may be other unknown factors that affect colors and how smooth they change over the surface)

Finally it's also worth to know that even if normals form a nice gradient over a single triangle, the gradient (or slope, or derivative) itself is not continuous accross edges. Se even with interpolation and per pixel shading the tessellation can become visible unfortunately (would be too expensive to fix).

 

This topic is closed to new replies.

Advertisement