Here's the textures (it's approximately 9mb)
Here's the most recent shaders:
Vector Shader
Code: Select all
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
gl_Position = ftransform();
gl_FogFragCoord = gl_Position.z;
}
Code: Select all
uniform sampler2D splatMap;
uniform sampler2D textureAtlas;
uniform sampler2D normalAtlas;
uniform vec3 lightPosition;
float getDistance(vec2 p1, vec2 p2){
return length(p1 - p2);
}
void main(){
float fog = (gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale;
if (fog > .2)
{
vec2 texCoord = (fract(gl_TexCoord[1].xy)* 0.25);
vec3 light_pos = normalize(lightPosition) + vec3(1,1,0);
//Layer 1
vec3 normalRed = normalize(texture2D(normalAtlas, texCoord).rgb * 2.0 - 1.0);
vec3 normalGreen = normalize(texture2D(normalAtlas, texCoord + vec2(.25,0)).rgb * 2.0 - 1.0);
vec3 normalBlue = normalize(texture2D(normalAtlas, texCoord + vec2(.50,0)).rgb * 2.0 - 1.0);
vec4 SplatCol=texture2D(splatMap,gl_TexCoord[0].xy/4);
float diffuse = max(dot(normalRed, light_pos), 0.0);
vec4 tex = texture2D(textureAtlas,texCoord);
vec4 RedCol=vec4(diffuse * tex.rgb, tex.a);
diffuse = max(dot(normalGreen, light_pos), 0.0);
tex = texture2D(textureAtlas,texCoord + vec2(.25,0));
vec4 GreenCol=vec4(diffuse * tex.rgb, tex.a);
diffuse = max(dot(normalBlue, light_pos), 0.0);
tex = texture2D(textureAtlas,texCoord + vec2(.50,0));
vec4 BlueCol=vec4(diffuse * tex.rgb, tex.a );
vec4 layer1 = (vec4(SplatCol.r*RedCol+SplatCol.g*GreenCol+SplatCol.b*BlueCol)*vec4(1,1,1,SplatCol.a));
//Layer2
normalRed = normalize(texture2D(normalAtlas, texCoord + vec2(.75,0)).rgb * 2.0 - 1.0);
normalGreen = normalize(texture2D(normalAtlas, texCoord + vec2(0,.25)).rgb * 2.0 - 1.0);
normalBlue = normalize(texture2D(normalAtlas, texCoord + vec2(.25,.25)).rgb * 2.0 - 1.0);
SplatCol=texture2D(splatMap,gl_TexCoord[0].xy/4 + vec2(.25,0));
diffuse = max(dot(normalRed, light_pos), 0.0);
tex = texture2D(textureAtlas,texCoord + vec2(.75,0));
RedCol=vec4(diffuse * tex.rgb, tex.a);
diffuse = max(dot(normalGreen, light_pos), 0.0);
tex = texture2D(textureAtlas,texCoord + vec2(0,.25));
GreenCol=vec4(diffuse * tex.rgb, tex.a);
diffuse = max(dot(normalBlue, light_pos), 0.0);
tex = texture2D(textureAtlas,texCoord + vec2(.25,.25));
BlueCol=vec4(diffuse * tex.rgb, tex.a );
vec4 layer2 = (vec4(SplatCol.r*RedCol+SplatCol.g*GreenCol+SplatCol.b*BlueCol)*vec4(1,1,1,SplatCol.a));
//Lightmap
vec4 ambientLight = vec4(.3,.3,.3,1);
vec4 LightMapCol =texture2D(splatMap,gl_TexCoord[0].xy/4 + vec2(.50,0));
vec4 color = mix(layer1,layer2,SplatCol.a)*(ambientLight + LightMapCol);
gl_FragColor = mix(gl_Fog.color, color, fog);
}
else
{
gl_FragColor = gl_Fog.color;
}
}
As a mild optimization any pixels that'll appear mostly black are not operated on by most of the shader. I have most of the functionality I want so now I'm going to refactor it to make it cleaner and more efficient. I'm also going to wrap up a new terrain scene node class so that it'll be easier to apply everything.