Creating a GLSL Library
A Multi-Texturing ExampleNext up is Multi-Texturing. There is no longer a need to use any OpenGL extensions to do multi-texturing, all of it can be done within a fragment shader. You can blend together as many textures as your video card supports (call glGetIntegerv with GL_MAX_TEXTURE_UNITS to determine that information), but in our case we'll only be doing two. No changes are required to our Texturing library or the vertex shader we we're using, and we'll need to add three lines of code to our fragment shader to get two textures blended together.
/**
* \file MultiTexture.frag
*/
uniform sampler2D TexUnit0;
uniform int TexturingType0;
uniform sampler2D TexUnit1;
uniform int TexturingType1;
void main()
{
vec4 color = gl_Color;
applyTexture2D(TexUnit0, TexturingType0, 0, color);
applyTexture2D(TexUnit1, TexturingType1, 0, color);
gl_FragColor = color;
}
So all that needed to be added was another sampler2D and another integer specifying what texturing to use. So hopefully you can see how creating a library can make your shaders a lot more concise, and a lot more powerful. Now we can move onto creating a Lighting library for per-pixel lighting.
|