View Full Version : How to display a colored 3d mesh using Phong shader?

07-25-2014, 05:29 PM
Dear All:
I am a beginner. I want to display a colored 3d facial mesh using phong shader. The facial mesh is obtained by 3d scanning, and every vertex has its own color(RGB).Please tell me this: can I display the mesh based on its own color, and simultaneously using phong shader.
I have read some reference documents about GLSL, I learned that in the fragment shader file the phong shader can be done, but how to lead the vertex color into the phong shader?
Thanks a lot!

Agent D
07-26-2014, 08:28 AM
Assuming you are using GLSL >=130:
You can write the vertex color (a variable declared with an "in" specifier in the vertex shader) into a variable declared as "out" in the vertex shader. You then declare a same named variable in the fragment shader (with an "in" specifier). The out veriables of several vertices are interpolated across a primtive and the in variable of the fragment shader holds the interpolated result for the current fragment.

Assuming you are using GLSL <=120:
The name of the specifier is "varying"

You use the interpolated color value in the fragment shader for your lighting calculations.

07-26-2014, 11:46 PM
Thank you! I will try.
Sorry about cross post, because it's my first time to use this forum, I did not find the area of shading language in the beginning.