Two color maps and a light map in use! I found a better tool from aligning the images in the atlas. I'm still getting some seams where it's getting portions of the texture beside it however. I have mipmaps turned off (was a lot worse before I did that).
Anyway here is some screen shots of what I have:
The Vertex shader hasn't changed.
The current Fragment shader:
Code: Select all
uniform sampler2D splatMap;
uniform sampler2D textureAtlas;
void main(){
//Layer 1
vec4 SplatCol=texture2D(splatMap,gl_TexCoord[0].xy/4);
vec4 RedCol=texture2D(textureAtlas,(fract(gl_TexCoord[1].xy) * 0.25));
vec4 GreenCol=texture2D(textureAtlas,(fract(gl_TexCoord[1].xy) * 0.25) + vec2(.25,0));
vec4 BlueCol=texture2D(textureAtlas,(fract(gl_TexCoord[1].xy) * 0.25) + vec2(.50,0));
vec4 layer1 = (vec4(SplatCol.r*RedCol+SplatCol.g*GreenCol+SplatCol.b*BlueCol)*vec4(1,1,1,SplatCol.a));
//Layer 2
SplatCol=texture2D(splatMap,gl_TexCoord[0].xy/4 + vec2(.25,0));
RedCol=texture2D(textureAtlas,(fract(gl_TexCoord[1].xy) * 0.25) + vec2(.75,0));
GreenCol=texture2D(textureAtlas,(fract(gl_TexCoord[1].xy) * 0.25) + vec2(0,.25));
BlueCol=texture2D(textureAtlas,(fract(gl_TexCoord[1].xy) * 0.25) + vec2(.25,.25));
vec4 layer2 = (vec4(SplatCol.r*RedCol+SplatCol.g*GreenCol+SplatCol.b*BlueCol)*vec4(1,1,1,SplatCol.a));
//Lightmap
vec4 LightMapCol =texture2D(splatMap,gl_TexCoord[0].xy/4 + vec2(.50,0));
gl_FragColor= mix(layer1,layer2,SplatCol.a) - LightMapCol/2;
}
I'm going to change it around so that it's looping through the splat maps rather than being manually hard coded.
EDIT -
I fixed the seams I turned of mipmaps when loading the terrain atlases and then turned it back on. I also added this line for each texture: terrain->getMaterial(0).TextureLayer[1].BilinearFilter = false;
Also I added normal mapping to the shader. It only uses one light source at the moment and its location is hard coded but it should be easy to have the class I'm using for the callback to provide it with the closest light source.