tangent space normal mapping added:
Click to reveal..
Code:
//==========================================//
//#define USE_NORMALMAPPING

#define USE_COLOR_INTENSITY_SHIFT
#define USE_COLOR_INTENSITY_MASK

const float max_colorintensity=4;

const float max_sunintensity=1.1;
const float min_sunintensity=0.1;

#define USE_OUTLINES
#define USE_PIXELSIZED_OUTLINES
//#define USE_COLORED_OUTLINES

const float outline_thickness=1.5;
const float3 outline_color=float3(0.5,0.6,0.8);//RGB in range 0..1 (instead of 0..255)

//#define USE_LIGHTING_ON_OUTLINES
#define USE_TEXTURED_OUTLINES
//#define USE_ALPHA_FOR_OUTLINES

const float texoutline_brightness=0.5;//0..darker..1..brighter..
const float texoutline_intensity=2;//0..less..1..more..
//==========================================//

bool AUTORELOAD;

float4x4 matWorldViewProj;
float4x4 matWorld;
float4x4 matWorldView;
float4x4 matView;

float4 vecSunDir;		
float4 vecSunColor;		
float4 vecViewPort;		

texture entSkin1;
texture entSkin3;

texture mtlSkin1;

sampler BUMP_SAMPLER = sampler_state { Texture   = <entSkin3>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
sampler COLOR_SAMPLER = sampler_state { Texture   = <entSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
sampler LGRAD_SAMPLER = sampler_state { Texture   = <mtlSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };

#ifdef USE_COLOR_INTENSITY_SHIFT
	#ifdef USE_COLOR_INTENSITY_MASK
		texture entSkin2;
		sampler MASK_SAMPLER = sampler_state { Texture   = <entSkin2>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
	#endif
#endif

////////////////////////////////////////////
#ifndef USE_COLORED_OUTLINES
	#undef USE_LIGHTING_ON_OUTLINES
	#undef USE_TEXTURED_OUTLINES
	#undef USE_ALPHA_FOR_OUTLINES
#endif

#ifdef USE_ALPHA_FOR_OUTLINES
	#define USE_TEXTURED_OUTLINES
#endif
////////////////////////////////////////////
void VS(		
in float4 vPos		   : POSITION,
in float3 normal	   : NORMAL,
in float2 InTex	   : TEXCOORD0,

#ifdef USE_NORMALMAPPING
	in float4 InTangent	: TEXCOORD2,
#endif

out float2 OutTex	      : TEXCOORD0,

#ifndef USE_NORMALMAPPING		
	out float3 outnormal    : TEXCOORD1,
	#else
	out float3 SunDir    : TEXCOORD1,
#endif

out float4 Pos	         : POSITION
)
{
	
	#ifndef USE_NORMALMAPPING		
		outnormal=mul(normal,matWorld);
		#else
		float3x3 matTangent;

		matTangent[0] = mul(InTangent.xyz,matWorld);	
		matTangent[1] = mul(cross(InTangent.xyz,normal),matWorld)*InTangent.w;
		matTangent[2] = mul(normal,matWorld);
		
		SunDir       = normalize(mul( matTangent,vecSunDir.xyz));			
	#endif

	Pos = mul(vPos,matWorldViewProj);
	
	OutTex = InTex;
}

void PS(	
in float2 Tex	      : TEXCOORD0,

#ifndef USE_NORMALMAPPING		
	in float3 normal    : TEXCOORD1,
	#else
	in float3 SunDir    : TEXCOORD1,
#endif

out float4 COL :COLOR0
) 
{
	#ifndef USE_NORMALMAPPING		
		normal      = normalize(normal);
		#else
		vecSunDir.xyz      = normalize(SunDir);
		float3 normal = normalize(tex2D(BUMP_SAMPLER,Tex).xyz*2.f-1.f);
	#endif

	COL = tex2D(COLOR_SAMPLER,Tex);
//	COL = tex2D(BUMP_SAMPLER,Tex);

	float sun_blub=dot(vecSunDir,normal)*0.5f+0.5f;

	float sun_diff=tex1D(LGRAD_SAMPLER,sun_blub);
	sun_diff=lerp(min_sunintensity,max_sunintensity,sun_diff);

	#ifdef USE_COLOR_INTENSITY_SHIFT

		#ifdef USE_COLOR_INTENSITY_MASK
			COL.rgb=lerp(COL.rgb,pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff))),tex2D(MASK_SAMPLER,Tex));
			#else
			COL.rgb=pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff)));
		#endif

	#endif
	
	COL.rgb=COL.rgb*sun_diff;//*vecSunColor;
	//	COL.rgb=tex2D(MASK_SAMPLER,Tex);
}

#ifdef USE_OUTLINES		
	void VS_OUTLINES(		
	in float4 vPos		   : POSITION,
	in float3 normal	   : NORMAL,

	#ifdef USE_TEXTURED_OUTLINES
		in float2 InTex	   : TEXCOORD0,
		out float2 OutTex	      : TEXCOORD0,
	#endif

	#ifdef USE_LIGHTING_ON_OUTLINES
		out float3 outnormal    : TEXCOORD1,
	#endif

	out float4 Pos	         : POSITION
	)
	{
		#ifdef USE_PIXELSIZED_OUTLINES
			float3 viewnormal=mul(normal,matWorldView);
			
			Pos = mul(vPos,matWorldViewProj);
			
			float2 sTex=(Pos.xy/Pos.w)*0.5f+0.5f;
			
			sTex+=viewnormal.xy*outline_thickness*vecViewPort.zw;
			
			Pos.xy=(sTex*Pos.w*2.f-Pos.w);
			#else
			Pos = mul(float4(vPos.xyz+normal*outline_thickness*0.2f,1),matWorldViewProj);
		#endif
		
		#ifdef USE_TEXTURED_OUTLINES
			OutTex = InTex;
		#endif
		
		#ifdef USE_LIGHTING_ON_OUTLINES
			outnormal=mul(normal,matWorld);
		#endif
	}

	#ifdef USE_COLORED_OUTLINES

		void PS_OUTLINES(
		#ifdef USE_TEXTURED_OUTLINES
			in float2 Tex	      : TEXCOORD0,
		#endif

		#ifdef USE_LIGHTING_ON_OUTLINES			
			in float3 normal     : TEXCOORD1,
		#endif

		out float4 COL :COLOR0
		) 
		{
			COL.a=1;
			
			#ifdef USE_TEXTURED_OUTLINES
				COL = tex2D(COLOR_SAMPLER,Tex);
				#else
				COL.rgb=outline_color;
			#endif
			
			#ifdef USE_LIGHTING_ON_OUTLINES					
				normal      = normalize(normal);

				float sun_blub=dot(vecSunDir,normal)*0.5f+0.5f;

				float sun_diff=tex1D(LGRAD_SAMPLER,sun_blub);
				sun_diff=lerp(min_sunintensity,max_sunintensity,sun_diff);

				#ifdef USE_COLOR_INTENSITY_SHIFT

					#if defined(USE_COLOR_INTENSITY_MASK) && defined(USE_TEXTURED_OUTLINES)
					COL.rgb=lerp(COL.rgb,pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff))),tex2D(MASK_SAMPLER,Tex));
					#else
					COL.rgb=pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff)));
				#endif

			#endif
			
			COL.rgb=COL.rgb*sun_diff;//*vecSunColor;
		#endif

		#ifdef USE_TEXTURED_OUTLINES	
			#ifndef USE_ALPHA_FOR_OUTLINES
				COL.rgb=pow(COL.rgb,texoutline_intensity)*texoutline_brightness;
			#endif
		#endif	

		#ifndef USE_ALPHA_FOR_OUTLINES
			COL.a=1;
		#endif	
	}
#endif
#endif

technique Shading
{
pass P0
{	
	zenable=true;
	zwriteenable=true;
	alphablendenable=false;
	alphatestenable=true;
	
	AlphaRef=0;
	AlphaFunc=Greater;
	
	VertexShader = compile vs_2_0 VS();
	PixelShader  = compile ps_2_0 PS();
}

#ifdef USE_OUTLINES		
	pass Outlines
	{
		cullmode=cw;		
		VertexShader = compile vs_2_0 VS_OUTLINES();
		

		#ifdef USE_ALPHA_FOR_OUTLINES
			zenable=true;
			zwriteenable=true;
			alphablendenable=false;
			alphatestenable=true;
			
			AlphaRef=0;
			AlphaFunc=Greater;
		#endif

		
		#ifdef USE_COLORED_OUTLINES
			PixelShader  = compile ps_2_0 PS_OUTLINES();		
		#endif
	}
#endif
}