I have implemeted the terrain multitexture shader and the code is below :

/This terrainshader is a reworked version of Thorsten Kunze 's terrainshader.



//2006 By www.loopix-project.com

/////////////////////////////////////////////////////////////////////////////////////////////////////////////







// entSkin1 rgb-blendmap

// entSkin2 shadowmap

////////////////////////

bmap tex8 = <grass.bmp>; // Texture Layer Red //steep

bmap tex9 = <cliff.bmp>; // longGrass Texture Layer Green//flat

bmap tex10 = <sand.bmp>; // Texture Layer Blue//built(roads etc..)

bmap tex11 = <snow.bmp>;// Texture Layer Black///detail color

/////////////////////////////

function multirgb_roughness1()

{

bmap_to_mipmap(mtl.Skin1);

bmap_to_mipmap(mtl.Skin2);

bmap_to_mipmap(mtl.Skin3);

bmap_to_mipmap(mtl.Skin4);

}

material terra_shader2

{



flags = tangent;

skin1 = tex8;

skin2 = tex9;

skin3 = tex10;

skin4 = tex11;



event=multirgb_roughness1;



effect

"

//////////////////////////////////////////////////////////////////////////////////////////////////////

// Define your needed values

float4x4 matWorldViewProj;

float4x4 matWorld;

float4x4 matWorldInv;

float4x4 matWorldView;



float4 vecFog;



// Define your textures

texture mtlSkin1;

texture mtlSkin2;

texture mtlSkin3;

texture mtlSkin4;

texture entSkin1;

texture entSkin2;



//////////////////////////////////////////////////////////////////////////////////////////////////////

// Texture settings

sampler sTex1 = sampler_state

{

Texture = <entSkin1>; // rgb-blendmap

MipFilter = Linear;

MinFilter = Linear;

MagFilter = Linear;

AddressU = Wrap;

AddressV = Wrap;

};

sampler sTex2 = sampler_state

{

Texture = <entSkin2>; // shadowmap

MipFilter = Linear;

MinFilter = Linear;

MagFilter = Linear;

AddressU = Wrap;

AddressV = Wrap;

};



sampler sTex8 = sampler_state

{

Texture = <mtlSkin1>; // red

MipFilter = Linear;

MinFilter = Linear;

MagFilter = Linear;

AddressU = Wrap;

AddressV = Wrap;

};

sampler sTex9 = sampler_state

{

Texture = <mtlSkin2>; // green

MipFilter = Linear;

MinFilter = Linear;

MagFilter = Linear;

AddressU = Wrap;

AddressV = Wrap;

};

sampler sTex10 = sampler_state

{

Texture = <mtlSkin3>; // blue

MipFilter = Linear;

MinFilter = Linear;

MagFilter = Linear;

AddressU = Wrap;

AddressV = Wrap;

};

sampler sTex11 = sampler_state

{

Texture = <mtlSkin4>; // black

MipFilter = Linear;

MinFilter = Linear;

MagFilter = Linear;

AddressU = Wrap;

AddressV = Wrap;

};





struct TMULTI_VS_OUT // Output to the pixelshader fragment

{

float4 Pos : POSITION;

float Fog : FOG;

float2 Tex1 : TEXCOORD0;

float2 Tex2 : TEXCOORD1;

float2 Tex8 : TEXCOORD2;

float2 Tex9 : TEXCOORD3;

float2 Tex10 : TEXCOORD4;

float2 Tex11 : TEXCOORD5;



};





float DoFog(float4 Pos) {

float3 P = mul(Pos,matWorldView);// apply the linear fog formula

return saturate((vecFog.y-P.z) * vecFog.z);

}





TMULTI_VS_OUT TMulti_VS(

float4 inPos : POSITION,

float3 inNormal : NORMAL,

float2 inTexCoord0 : TEXCOORD0)

{



TMULTI_VS_OUT Out;



// transform the vector position to screen coordinates

Out.Pos = mul(inPos,matWorldViewProj);



// rotate and normalize the normal

float3 N = normalize(mul(inNormal,matWorldInv));



Out.Fog = DoFog(inPos);



// scale the texture coordinates for the masked textures

Out.Tex1 = inTexCoord0.xy; // rgb-blendmap (not tiled)

Out.Tex2 = inTexCoord0.xy; // shadowmap (not tiled)

Out.Tex8 = inTexCoord0.xy*16; // tiling texture red

Out.Tex9 = inTexCoord0.xy*16; // tiling texture green

Out.Tex10 = inTexCoord0.xy*8; // tiling texture blue

Out.Tex11 = inTexCoord0.xy*8; // tiling texture black

return Out;

}





//////////////////////////////////////////////////////////////////////////////////////////////////////

// pixelshader

float4 ps( TMULTI_VS_OUT In ) : COLOR

{

float4 BlendColor = tex2D(sTex1,In.Tex1);

float4 ShadowMap = tex2D(sTex2,In.Tex2);

float4 RedColor = tex2D(sTex8,In.Tex8);

float4 GreenColor = tex2D(sTex9,In.Tex9);

float4 BlueColor = tex2D(sTex10,In.Tex10);

float4 BlackColor = tex2D(sTex11,In.Tex11);









float4 BaseRed = lerp(BlackColor,RedColor,BlendColor.r);

float4 BaseGreen = lerp(BaseRed,GreenColor,BlendColor.g);

float4 FinalColor = lerp(BaseGreen,BlueColor,BlendColor.b);



FinalColor = FinalColor*ShadowMap; // maybe you will want to have it brighter ...*(ShadowMap+0.2)



FinalColor.a = 1.0f; // prevent transparency







return FinalColor;

}



//////////////////////////////////////////////////////////////////////////////////////////////////////

//

technique mytechnique

{

// Define your passes

pass p0

{

VertexShader = compile vs_2_0 TMulti_VS();

PixelShader = compile ps_2_0 ps();

}

}

";

}



action terrain_action

{

while(1)

{

my.material = terra_shader2;

wait(1);

}

}




The clip error that i get is shown below :


[img][IMG]http://img294.imageshack.us/img294/8379/terriancliperrvc8.th.jpg[/img][/img]







if anyone knows what is going wrong in this code , kindly let me know.

thaks in advance for any help.

Regards,
Sichlid


Last edited by Sichlid; 06/23/08 04:29.

Best Regards, Sichlid