PietroNifosi: Nice pics! Do you have any pics with shadows on the terrain, too? Also chances are high you won't need static shadowmaps anymore with the upcoming version... wink

NeoNeper: Try this shader instead (will also automatically use the A7 shadowmap if it's a .hmp with shadows compiled in WED):
Code:
/*
Terrain-Shader by Wolfgang "BoH_Havoc" Reichardt
Automatically uses A7 lightmap if its a .hmp file instead of a .mdl

Entity Textures:
	Skin1 = Global Colormap
	Skin2 = Tile-Colormask  (RGB) + Shadow (A)
	Skin3 = Global Normalmap
	Skin4 = Tile-Normalmap (RGB) + Specularmap (A) (Quad-Texture)

Material Textures:
	Skin1 = Tile-Color (Quad-Texture @ DDS)

Usage:

	
*/

/***************************************TWEAKABLES*****************************************************/

float bumpStr = 2; //bump strength
float numTiles = 60; // number of tiles
float shadowAlpha = 0.5; //shadowalpha of bumpmapping
float texShadowAlpha = 0.25; //shadowalpha of shadowtexture
float velvStr = 0.4; //velvety strength
float specStr = 1.0; //specular Strength
float4 specPower = 10; //specular Sharpness, higher value = sharper specular lighting

//active dynamic shadows (shadowType = 0)
//#define DYNSHADOW

//activate velvety backlight
#define VELVETY

/***************************************SHADER*CODE****************************************************/

texture entSkin1; //colormap
texture entSkin2; //global normalmap + Shadow
texture entSkin3; //colormask
texture entSkin4; //normalmaps
texture mtlSkin1; //colormaps
texture LightMap; //lightmap passed by engine

matrix matWorld;
matrix matWorldInv;
matrix matViewInv;
matrix matWorldViewProj;
float4x4 matEffect1;
float4x4 matEffect2;
float4x4 matEffect3;

float4 vecSunDir;
float4 vecSunColor;
float4 vecLightPos[8];
float4 vecLightColor[8];
float4 vecViewPos;
float4 vecAmbient;
float fAmbient;



//do sunlight
#define DOSUN

sampler colorSampler = sampler_state 
{ 
   Texture = <entSkin1>; 
   MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
};

sampler maskSampler = sampler_state 
{ 
   Texture = <entSkin2>; 
   MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
}; 

sampler globalNormSampler = sampler_state 
{ 
   Texture = <entSkin3>; 
   MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
}; 

sampler normSampler = sampler_state 
{ 
   Texture = <entSkin4>; 
   MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
}; 

sampler tileColorSampler = sampler_state 
{ 
   Texture = <mtlSkin1>; 
   MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
};

sampler2D lightmapSampler = sampler_state
{
	Texture = <LightMap>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
	AddressU = WRAP;
	AddressV = WRAP;
};



#ifdef DYNSHADOW
// ShadowDepth map sampler
texture sc_map_shadowDepthSun_bmap;

sampler ShadowMapSampler = sampler_state
{
	Texture = <sc_map_shadowDepthSun_bmap>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
	AddressU = CLAMP;
	AddressV = CLAMP;
};

Texture sc_map_shadowAlpha_bmap;

sampler ShadowAlphaSampler = sampler_state
{
	texture = <sc_map_shadowAlpha_bmap>;
	magfilter = LINEAR;
	minfilter = LINEAR;
	mipfilter=LINEAR;
	AddressU = clamp;
	AddressV = clamp;
};
#endif

///////////////////////HELPER FUNCTIONS///////////////////////////////////////
// calculate the light attenuation factor
float DoLightFactor(float4 Light,float3 Pos)
{
   float fac = 0.f;
   if (Light.w > 0.f) {    
      float LD = length(Light.xyz-Pos)/Light.w;
      if (LD < 1.f)
         fac = saturate(1.f - LD);

   }
   return fac; // get the distance factor
}

// calculate the light attenuation factor on the front side
float DoLightFactor(float4 Light,float3 P,float3 N)
{
	float3 D = Light.xyz-P; // ray pointing from the light to the surface
	float NdotL = dot(N,normalize(D));   // angle between surface and light ray
	
	if (NdotL >= 0.f) 
	   return saturate(NdotL*8)*DoLightFactor(Light,P);
	else
	   return 0.f;
}

float DoLightFactorN(float4 Light,float3 P,float3 N)
{
	float3 D = Light.xyz-P; // ray pointing from the light to the surface
	float NdotL = dot(N,normalize(D));   // angle between surface and light ray
	
	if (NdotL >= 0.f) 
	   return 2 * NdotL * DoLightFactor(Light,P);
	else
	   return 0.f;
}

float4 DoPointLight(float3 P, float3 N, float4 Light, float4 LightColor)
{
	return LightColor * DoLightFactorN(Light,P,N);
}

float4 DoLight(float3 P, float3 N, int i)
{
	
	if(vecLightPos[i].w < 100000) return DoPointLight(P,N,vecLightPos[i],vecLightColor[i]);
	else return 0;
}


float4 doLighting(float3 P, float3 N, int i)
{
	if(vecLightPos[i].w < 100000)
	{
		float4 lighting = 1;
		lighting.xyz = clamp(1-distance(vecLightPos[i].xyz,P)/vecLightPos[i].w,0,1);
		lighting.xyz *= dot(N,normalize(vecLightPos[i]-P))*vecLightColor[i].xyz;
		return lighting;
	}
	else
	{ 
		return 0;
	}
	
}

float light_vsm_epsilon = 0.00003;
float light_shadow_bias = 0.0025;

float doVSM(float2 depthmap, float lightDepth)
{
     	//depthmap.y = (depthmap.x * depthmap.x);
     	float lit_factor = (lightDepth <= depthmap.x);
    	
    	// Variance shadow mapping
    	float E_x2 = depthmap.y;
    	float Ex_2 = depthmap.x * depthmap.x;
    	float variance = min(max(E_x2 - Ex_2, 0.0) + light_vsm_epsilon, 1.0);
    	float m_d = (depthmap.x - lightDepth);
    	float p = variance / (variance + m_d * m_d);
    	
    	// Adjust the light color based on the shadow attenuation
    	return 1-max(lit_factor, p);
}

void terrain_VS( 
   in float4 InPos: POSITION, 
   in float3 InNormal: NORMAL, 
   in float2 InTex: TEXCOORD0,
   in float3 InTangent : TEXCOORD0,
   out float4 OutPos: POSITION,
   out float4 OutColor : COLOR0,
   out float2 OutTex: TEXCOORD0, 
   out float4 OutLight: TEXCOORD1,
   out float3 OutViewDir: TEXCOORD2,
   out float3 OutWorldNormal	: TEXCOORD3,
	out float3 OutWorldTangent	: TEXCOORD4,
	out float3 OutWorldBinorm	: TEXCOORD5,
	#ifdef DYNSHADOW
		out float3 OutWorldPos	: TEXCOORD6,
		out float4 OutShadow	: TEXCOORD7
	#else
		out float3 OutWorldPos	: TEXCOORD6
	#endif
	) 
{ 
	// Transform the vertex from object space to clip space: 
   OutPos = mul(InPos, matWorldViewProj); 
	// Pass the texture coordinate to the pixel shader: 
   OutTex.xy = InTex.xy;
   
   float3 PosWorld = mul(InPos, matWorld);
  	
   //Light
   #ifdef DOSUN
	   OutLight.xyz = -vecSunDir.xyz;//vecSunPos - PosWorld;;
	   OutLight.w = 100000;//distance(PosWorld,vecLightPos[0])/vecLightPos[0].w;
   #else
	   OutLight.xyz = vecLightPos[0] - PosWorld;
	   OutLight.w = 0;
	   if(vecLightPos[0].w < 100000) OutLight.w = 1-distance(PosWorld,vecLightPos[0])/vecLightPos[0].w;
   #endif
  	//

	//Specular Lighting
	OutViewDir = matViewInv[3].xyz - PosWorld;
	//
	
	//Misc Output
	float3 Binormal = cross(InNormal,InTangent);
	OutWorldNormal.xyz = mul(InNormal, matWorld).xyz;
	OutWorldTangent.xyz = mul(InTangent, matWorld).xyz;
	OutWorldBinorm.xyz = mul(Binormal, matWorldInv).xyz;
	OutWorldPos = PosWorld;
	//
	
	#ifdef DYNSHADOW
	   //Shadowmapping
		float4 ShadowMapSamplingPos = mul(mul(InPos,matWorld), mul(matEffect3,matEffect1));
		float4 RealDistance = mul(mul(InPos,matWorld), matEffect3).z/matEffect2[0].w;
		
		OutShadow.x = ShadowMapSamplingPos.x;
		OutShadow.y = ShadowMapSamplingPos.y;
		OutShadow.z = ShadowMapSamplingPos.w;
		OutShadow.w = RealDistance.x;
		//
	#endif
	
	OutColor = fAmbient; // Add ambient and sun light
   #ifdef DOSUN
	for (int i=0; i<8; i++)  // Add 8 dynamic lights
		OutColor += DoLight(PosWorld,OutWorldNormal.xyz,i);
	#else
	for (int i=1; i<8; i++)  // Add 7 dynamic lights
		OutColor += DoLight(PosWorld,OutWorldNormal.xyz,i);
	#endif
	
	
}

float4 terrain_PS(
	uniform int inLM,
	in float4 InColor : COLOR0,
	float2 Tex : TEXCOORD0,
	float4 InLight: TEXCOORD1,
	float3 InViewDir: TEXCOORD2,
	float3 InWorldNormal	: TEXCOORD3,
	float3 InWorldTangent	: TEXCOORD4,
	float3 InWorldBinorm	: TEXCOORD5,
	float3 InWorldPos	: TEXCOORD6,
	in float4 InShadow	: TEXCOORD7
):COLOR0
{
	float4 Color = tex2D(colorSampler, Tex.xy);
	
	float4 colorMask = tex2D(maskSampler, Tex.xy);
	
	float2 Tile = Tex.xy*numTiles;
	Tile = frac(Tile)*(0.5-2*0.004)+0.004;
	
	float4 color = tex2D(colorSampler, Tex.xy);
	
	float4 color1 = tex2D(tileColorSampler, Tile)*colorMask.r;
	float4 color2 = tex2D(tileColorSampler, Tile+float2(0.5, 0.0))*colorMask.g;
	float4 color3 = tex2D(tileColorSampler, Tile+float2(0.0, 0.5))*colorMask.b;
		
	float4 normal1 = tex2D(normSampler, Tile)*colorMask.r;
	float4 normal2 = tex2D(normSampler, Tile+float2(0.5, 0.0))*colorMask.g;
	float4 normal3 = tex2D(normSampler, Tile+float2(0.0, 0.5))*colorMask.b;
		
	float3 Ln = normalize(InLight.xyz);
   float3 Nn = normalize(InWorldNormal);
   float3 Tn = normalize(InWorldTangent);
   float3 Bn = normalize(InWorldBinorm);
   float3 Nb = 0;
   float3 Vn = 0;
   float3 Hn = 0;
   float4 lighting = 0;
	
	float gloss = normal1.a + normal2.a + normal3.a;	
	
	float3 bumpNormal = ((normal1.rgb+normal2.rgb+normal3.rgb));
	//bumpNormal += tex2D(globalNormSampler, Tex).xyz;
	bumpNormal = lerp(bumpNormal, (tex2D(globalNormSampler, Tex.xy).xyz), 0.5);
	bumpNormal = (bumpNormal-(0.5).xxx)*bumpStr;
	
	//bumpNormal *= 2;
	Nb = Nn + (bumpNormal.x * Tn + bumpNormal.y * Bn);
   Nb = normalize(Nb);
   Vn = normalize(InViewDir);
   Hn = normalize(Vn + Ln);
   lighting = lit(dot(Ln,Nb),dot(Hn,Nb),10);
   
   
   
   
   #ifdef DYNSHADOW
	   float2 ProjectedTexCoords;
	   ProjectedTexCoords[0] = InShadow.x/InShadow.z/2.0f +0.5f;
	   ProjectedTexCoords[1] = -InShadow.y/InShadow.z/2.0f +0.5f;
	
		float blurStr = matEffect2[1].x;
		float shadowDepth = tex2D(ShadowMapSampler, ProjectedTexCoords).x;
		
		float shadow1 = doVSM(float2(shadowDepth,shadowDepth*shadowDepth),InShadow.w);
	   shadow1 = (1-shadow1);
	   
	   shadow1 *=(1-tex2D(ShadowAlphaSampler, ProjectedTexCoords));
	   shadow1 += tex2D(ShadowAlphaSampler, ProjectedTexCoords);
	   //shadow1 *= lighting.y;
	   shadow1 = clamp(shadow1,0,1);
   #else
   	float shadow1 = 1;
   #endif
   lighting.y *= shadow1;
   
   
   #ifdef VELVETY
   	float velvety1 = clamp(velvStr-dot(Vn,Nb),0,1);
   #else
   	float velvety1 = 0;
   #endif
   
   
   
	Color.rgb = saturate(clamp(lighting.y, shadowAlpha, 1)*vecSunColor*2)+(InColor.rgb);
	
	Color.rgb *= lerp(color, (color1+color2+color3), 0.5);
	Color.rgb += (lighting.z+velvety1)*specStr*gloss*Color.rgb;
	Color.rgb = clamp(Color.rgb, 0, 1);
	//Color.rgb *= clamp(colorMask.a,texShadowAlpha,1);
	if(inLM == 0)	Color.rgb *= clamp(colorMask.a,texShadowAlpha,1);
	else Color.rgb *= tex2D(lightmapSampler,Tex.xy).rgb;
	
	Color.a = 1;
	
	return float4(Color.rgb,1);
}

technique terrain
{
	pass p0
	{
		//cullmode = none;
		//zwriteenable = true;
		//alphablendenable = true;
		VertexShader = compile vs_2_0 terrain_VS();
		PixelShader = compile ps_2_a terrain_PS(int(0));
	}
}

technique terrain_lm
{
	pass p0
	{
		//cullmode = none;
		//zwriteenable = true;
		//alphablendenable = true;
		VertexShader = compile vs_2_0 terrain_VS();
		PixelShader = compile ps_2_a terrain_PS(int(1));
	}
}




Shade-C EVO Lite-C Shader Framework