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
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.
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
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"?
Well, it could well have good enough meaning in a shader that does just solid fill with said colour.
Originally Posted by Alfonse Reinheart
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.
Thanks for mentioning interface blocks. They seem like just what I need.
Originally Posted by kyle_
How would I call a specific material colour assigned to a vertex then? vertex_material_colour? Thanks for the help.