Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: How to display a colored 3d mesh using Phong shader?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Jul 2014

    How to display a colored 3d mesh using Phong shader?

    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!

  2. #2
    Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Innsbruck, Austria
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2014
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts