YES! I did it… finally I got all the OpenGL fun stuff together and managed to dynamically (as in through OpenGL) blend all the textures of a tile.
First I had to write my own GLSL Fragment Shader (WotLK version):
uniform sampler2D Layer0;
uniform sampler2D Layer1;
uniform sampler2D Layer2;")
uniform sampler2D Layer3;")
uniform sampler2D Alpha1;")
uniform sampler2D Alpha2;")
uniform sampler2D Alpha3;")
varying vec4 texCoord;")
void main (void)
{
vec4 l0 = texture2D( Layer0, texCoord.xy * 8);
vec4 l1 = texture2D( Layer1, texCoord.xy * 8);
vec4 l2 = texture2D( Layer2, texCoord.xy * 8);
vec4 l3 = texture2D( Layer3, texCoord.xy * 8);
vec4 a1 = texture2D( Alpha1, texCoord.xy);
vec4 a2 = texture2D( Alpha2, texCoord.xy);
vec4 a3 = texture2D( Alpha3, texCoord.xy);
gl_FragColor = l0 * (1 - a1.a - a2.a - a3.a) + l1 * a1.a + l2 * a2.a + l3 * a3.a;
}
Then I had to convince my program to use it:
Gl.glShaderSource(Shader, 1, New String() {FragShad}, FragShad.Length - 1)
Gl.glCompileShader(Shader)
Progra = Gl.glCreateProgram()
Gl.glAttachShader(Progra, Shader)
Gl.glLinkProgram(Progra)
Figuring out how to pass the parameters to the shader was a major pain in the butt… here’s how it works:
1. You create your textures as you normally would:
Dim Layer0 As Bitmap
Layer0 = Bitmap.FromFile("d:\temp\test\n2525\WinterspringSnowSolid_orig.png")
Gl.glGenTextures(1, LayerID0)
Dim LayerData As Imaging.BitmapData = Layer(i).LockBits(New Rectangle(0, 0, Layer(i).Width, Layer(i).Height), Imaging.ImageLockMode.ReadOnly, Imaging.PixelFormat.Format32bppArgb)
Gl.glBindTexture(Gl.GL_TEXTURE_2D, LayerID0)
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, Layer(i).Width, Layer(i).Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, LayerData.Scan0)
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR)
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR)
Layer0.UnlockBits(LayerData)
2. Then you have to “tell” the program to use this texture (assuming it will be bound to GL_TEXTURE0):
Gl.glUseProgram(Progra)
Dim loc As Integer = Gl.glGetUniformLocation(Progra, "Layer0")
Gl.glUniform1i(loc, 0)
3. Now in the draw routine, you need to assign the texture to the selected texture slot:
Gl.glUseProgram(Progra)
Gl.glEnable(Gl.GL_TEXTURE_2D)
Gl.glActiveTexture(Gl.GL_TEXTURE0)
Gl.glBindTexture(Gl.GL_TEXTURE_2D, LayerID0)
Voila… it works… here’s the “proof” (this tile is from around the eastern end of the borean tundra):
I’ve yet to copy this code over from my test project to the wow2collada code (including all the texture fun associated with it, i.e. undoing all the precalculations I thought necessary at the time).
Cheers
Hamu























Ok, I got some nice process over the weekend on my wow2collada program:




