Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Prefix for variables [core]

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    8

    Prefix for variables [core]

    I have an input to the vertex program called vertex_colour and I want to pass this value on to the fragment program. How should I call the variable that is an output to the vertex program and an input to the fragment program? Should I call it something like fragment_colour or varying_colour?
    Last edited by thecodinguniverse; 08-01-2012 at 05:10 AM. Reason: clarified question

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,728
    First, you can prefix them however you want.

    Most importantly secondly, you should never name variables so blandly. "colour" means nothing; you might as well use "c". "diffuseColour" means something. "lightReflectance" means something. These would be the names of the fragment shader input and the fragment shader output respectively, since that's likely what your shader is computing.

    Or, to put it another way, if your names need prefixes in order to not conflict, you're naming things wrong.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    8
    I might have phrased the question wrong. Let's say I have an input to the vertex program called vertex_colour and I want to pass this value on to the fragment program. How should I call the variable that is an output to the vertex program and an input to the fragment program? (e.g.: varying_vertex_colour, fragment_vertex_colour, varying_colour) Thanks for the help.
    Last edited by thecodinguniverse; 08-01-2012 at 05:09 AM. Reason: added thanks

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,728
    Exactly as I said: name it by what it means.

    Colors aren't just colors. They have a meaning; they have a purpose. Is it the diffuse surface reflectance? The specular reflectance? Something else? What does it mean? Once you know what it means, you can give it a name that reflects that meaning.

    "vertex_color" doesn't have a meaning; it's too generic. Don't use names like that.

    Do you also name your samplers "texture0" and "texture1"?

  5. #5
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    258
    Quote Originally Posted by Alfonse Reinheart View Post
    "vertex_color" doesn't have a meaning; it's too generic. Don't use names like that.
    Well, it could well have good enough meaning in a shader that does just solid fill with said colour.
    Either way, as i understand OP question is more of conventions people use for avoiding name collisions with attributes/varyings/fragouts.

    And the answer to this is: 'its up to you'. Its just a convention. Pick one that you like and stick with it.
    Just prefix your varyings with var/varying/interpolated and youre set. You could also try to play around with interface blocks.

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    8
    Quote Originally Posted by kyle_ View Post
    You could also try to play around with interface blocks.
    Thanks for mentioning interface blocks. They seem like just what I need.

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    8
    How would I call a specific material colour assigned to a vertex then? vertex_material_colour? Thanks for the help.

Posting Permissions

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