Just My Life & My Work

現今多邊形的著色方法基本的有這三種:flat、Gouraud、Phong Shading,它們之間有何差別呢?喜歡玩遊戲的人一定要知道Gouraud Shading,這是PC最常使用的著色法,因為效能好、效果還不錯。而近年來,隨著GPU快速的發展,Phong Shading逐漸應用在更真實的著色上。

從一張圖可以看出他們的各自的特色:(a: Flat→b: Gouraud→c: Phong)

從古早到現代:Flat→Gouraud→Phong Shading。

從簡單到複雜:Flat→Gouraud→Phong Shading。

觀察三者所呈現的效果,可以歸納出下列結論:

  • flat shading: constant surface shading
  • Gouraud shading: color interpolation shading
  • Phong shading: vertex normal interpolation shading

用簡單的中文來解釋原理

  • flat shading:三角形的頂點沒有法向量,三角形整個面才有法向量,打光時整個三角形只呈現一種顏色。
  • Gouraud shading:三角形的頂點都有各自的法向量,打光時三個頂點有各自的顏色,接著做雙線性內插(bilinear interpolation)來求得顏色,使整個三角形有漸層的顏色變化。
  • Phong shading:三角形的頂點都有各自的法向量,先對三角形整個面作法向量的雙線性內插,接著打光來求整個三角形的顏色。

然後我們來分析各自的複雜度

假設三角形面積為A。三角形個數為N。而且我們知道打一次光需要6次乘法和2次加法和1次查表的運算,此設定為L。雙線性內插設定為B

  • flat shading的複雜度:N * L
  • Gouraud shading 的複雜度:N * (3 * L + b * A)
  • Phong shading的複雜度:(B + L) * N * A

數學好的人很容易計算出複雜度:Flat<Gouraud<Phong Shading。這裡也因此說明了為何早期電腦都只支援Gouraud shading,就算已經知道Phong shading的效果比Gouraud shading好,但還是選擇效能好而效果不錯的Gouraud shading!如今GPU發展迅速,Phong Shading的效能已得到提昇。

參考:flat shadingGouraud shadingPhong shading

Comments on: "flat、Gouraud、Phong Shading的差別 (Comparison flat, Gouraud, Phong shading)" (9)

  1. Funny, the first image (comparison) if from my prof 😉

  2. 你也有再寫OpenGL ?

  3. Hi HappyMan,

    i find your blog very interesting. i’m working with blender, but i am not sure whether smooth shading in blender actually implements Gouraud or Phong. do you know it?

    many thanks!

    • Hi Seong Ping:

      I think it implements both.
      You may refer to [Blender] 鏡射光著色器 (Specular Shader) of my article.

      Although it just displays Phong and the other four kind. Since it implements complex one (Phong), Blender should implement the simple one. 🙂

      • thanks for your quick response, appreciate it. but what i meant is this: http://wiki.blender.org/index.php/Doc:2.6/Manual/Modeling/Meshes/Smoothing

        there are options of “Smooth" and “Flat" in Shading. i just couldn’t find any description to tell whether the “Smooth" option implements Gouraud or Phong interpolation… do you know it?

        many thanks for your kind help. 🙂

        p/s: i can read Chinese. please feel free to reply in Chinese. i just have no Chinese input in my linux PC..

        • In fact, I have the same question that time, but I still have no idea which way Blender implemets the smooth shading.
          I think it is good method to find out the solution by using less triangle. To observe the light reflects on the object. 😉
          Are you a Taiwanese? And live in Taiwan? I live Taipei now. 😀

          • i guess it is not a concern when material and texture are considered. i’m not in this area..

            thanks for your help anyway. 🙂 i’m a malaysian currently based in singapore. but i once studied in taipei.

          • It is good to hear you are a Malaysian, You are so lucky to have the chance to study in Taipei, and work in Singapore. Maybe one day I will achieve the goal that travel along work. 😀
            So may I have your E-mail? Maybe one day in the future we have the opportunity to meet up. 😉

隨意留個言吧:)~

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料

標籤雲