Thanks for the excellent explanation!
Riemer's 4th tutorial is a good one for learning the second multitexture technique. I alread has a look at that and your engine to see how you guys did multitexturing.
Problem i had, was that i couldn't get the shader to work in PS 1.1. That's why i was wondering if i couldn't do it using a texturefile with multiple textures in it. But then setting the right TextCoords became a huge problem (at least for me).
BUT (after a hell of a day :-) ) i finally have the multitexture shader working in PS 1.1. Problem is that in 1.1 you can't read a TEXCOORD more than once...
So now i have 1 TextCoord i pass in the shader and there I set it to 3 seperate once, one per texture, so i can read those in the ps main call. Only thing now is that the lightning won't work anymore. That's because I now use 3 TEXCOORDS for the TextureCoords and in 1.1 you can only use 4 TEXCOORDS variables...
For anyone who has an old graphics card just like me...here's the shader for multitexturing.
//------- Technique: MultiTextured --------
struct MultiTexVertexVS
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 TextureCoords : TEXCOORD0;
float4 TerrainColorWeight : COLOR0;
};
struct MultiTexVertexPS
{
float4 Position : POSITION;
float3 Normal : TEXCOORD0;
float2 TextureCoords1 : TEXCOORD1;
float2 TextureCoords2 : TEXCOORD2;
float2 TextureCoords3 : TEXCOORD3;
float4 LightDirection : TEXCOORD4;
float4 TerrainColorWeight : COLOR0;
};
MultiTexVertexPS MultiTextured_Pass_0_Vertex_Shader_vs_main( MultiTexVertexVS Input )
{
MultiTexVertexPS Output = (MultiTexVertexPS)0;
float4x4 preViewProjection = mul (xView, xProjection);
float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
Output.Position = mul(Input.Position, preWorldViewProjection);
Output.Normal = mul(normalize(Input.Normal), xWorld);
Output.TextureCoords1 = Input.TextureCoords;
Output.TextureCoords2 = Input.TextureCoords;
Output.TextureCoords3 = Input.TextureCoords;
Output.TerrainColorWeight = Input.TerrainColorWeight;
Output.LightDirection.xyz = -xLightDirection;
Output.LightDirection.w = 1;
return Output;
}
float4 MultiTextured_Pass_0_Pixel_Shader_ps_main( MultiTexVertexPS Input ) : COLOR0
{
float lightingFactor = 1;
if (xEnableLighting)
lightingFactor = saturate(saturate(dot(Input.Normal, Input.LightDirection)) + xAmbient);
float4 Color;
Color = tex2D(SandTextureSampler, Input.TextureCoords1) * Input.TerrainColorWeight.r;
Color += tex2D(GrassTextureSampler, Input.TextureCoords2) * Input.TerrainColorWeight.g;
Color += tex2D(RockTextureSampler, Input.TextureCoords3) * Input.TerrainColorWeight.b;
//Color.rgb *= lightingFactor;
return Color;
}
//--------------------------------------------------------------//
// Technique Section for MultiTextured
//--------------------------------------------------------------//
technique MultiTextured
{
pass Pass_0
{
VertexShader = compile vs_1_1 MultiTextured_Pass_0_Vertex_Shader_vs_main();
PixelShader = compile ps_1_1 MultiTextured_Pass_0_Pixel_Shader_ps_main();
}
}