Jump to content
  • Advertisement
Goyira

3D Fragment shader and normals.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement

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. 

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Posted (edited)
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).

 

Edited by JoeJ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!