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:
Properties {
_MainTex ("RGB = Color Masks, A = Texture", 2D) = "" {}
_RedColor ("Color for Red Texture Channel", Color) = (1,1,1)
_GreenColor ("Color for Green Texture Channel", Color) = (1,1,1)
_BlueColor ("Color for Blue Texture Channel", Color) = (1,1,1)
}
SubShader {Pass {
GLSLPROGRAM
varying lowp vec2 uv;
#ifdef VERTEX
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
uv = gl_MultiTexCoord0.xy;
}
#endif
#ifdef FRAGMENT
uniform lowp sampler2D _MainTex;
uniform lowp vec3 _RedColor, _GreenColor, _BlueColor;
void main() {
lowp vec4 masks_texture = texture2D(_MainTex, uv);
gl_FragColor = vec4(
mat3(_RedColor, _GreenColor, _BlueColor)
* masks_texture.rgb * masks_texture.a,
1
);
}
#endif
ENDGLSL
}}
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! ;-)