Please pardon me for being a n00b at GLSL. I haven't come across information about this yet, in my reading. I wrote this shader, which is kind of like a "terrain" shader, except the RGB channels are masks for colors, not textures. Take a gander first, I guess:
My concern is, that matrix of colors only needs to be created once per pass. I'm afraid that as it is, it will be created for every fragment. It's just plugging numbers in, with no calculations, so I doubt it's too big a deal, but I want to learn to write these to be as efficient as possible, and use good practice for future shaders.
Should I store the matrix as a variable outside the function? And if so, where? I don't know enough about GPUs or compilers yet; hopefully you do! ;-)
asked Mar 15 '11 at 03:02 PM
You should be able to create a uniform matrix and set the matrix or vector4 on the shader through the material.
Basically you'd calculate the matrix/color/whathave you in update and update the value in the shader. That way you compute it once a frame. If you are dealing with multipass rendering I am not quite sure what callback you should hook up with, I haven't done so myself.
In other words: Basically you just create another property with a uniform variable just as you have done for the red, green and blue colors. Then you create a similar function to mat3 in C#/JS/Boo code and call that with the values of r/g/b. Then store the result in your computed color property.