Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
632 views
in Technique[技术] by (71.8m points)

graphics - What is the difference between Phong Shading and Gouraud Shading?

As I understand it, Gouraud shading calculates light color for each vertex and does interpolation on that color, whereas Phong shading interpolates the normal for each pixel and calculates light color based on that interpolated value.

However, when I tried to derive the light color mathematically, I ended up with the same formula for both ways!

figure i draw for that

(Where n1 and n2 are the normals of the two vertices, t is the coefficient for interpolation, L is the light direction, and the plane on the top and the dotted line means screen and a pixel.)

The light colors for the two methods are derived as:

  • Gouraud: L = t*dot(n1,L) + (1-t)*dot(n2,L)

  • Phong: L = dot(t*n1+(1-t)*n2,L)

and the results are the same.

Can anyone tell me what's wrong with my derivations?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

While at Gouraud shading the light is calculates per vertex (Vertex shader), at Phong shading the light is calculates per fragment (fragment shader).
Therefore, Gouraud shading calculates the light for the vertices (corners) of a primitive and interpolates the light for the fragments covered by the primitive.
With Phong shading, the light is calculated separately for each fragment.

In general a light is computed by the Bidirectional reflectance distribution function. The function computes the reflectance of the light on a surface and depends on the vector of the incident light, the point of view and the normal vector of the surface.
At Gouraud shading the vertex color (reflectance) is interpolated and at Phong shading the 3 vectors are interpolated. That won't make any difference if the function c = brdf(l, v, n) is linear, where c is the color, l is the light direction, v is the view vector and n is the normal vector (e.g. Lambertian reflectance). But if the light model is not linear (e.g. Blinn–Phong), then the linear interpolation of Gouraud shading leads to different results.

Compare Gouraud shading and Phong shading


See also:
GLSL fixed function fragment program replacement
Phong and Gouraud Shading
Gouraud shading / Phong shading


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...