Hi, I have a problem with using the shadowmapping example from conitec.
The terrain in my level is using the material mtl_terraintex from the mtlFX.c . Now I want to use the shadowmapping code from the samples folder. It's need to apply the material mtlShadow to the Entities to show shadow. Also on my terrain. But how can I combine this both materials? Please could someone help me?

here the Schaders:
First the terrainshader and then the shadow shader

MATERIAL* mtl_terraintex =
{
effect = "terraintex.fx";
flags = PASS_SOLID; // prevent transparency of 32 bit skins
event = mtl_terrain_init;
}

Code:
//////////////////////////////////////////////////////////////////////
// terraintex.fx
// Terrain material for an unlimited number of terrain textures
// Tiled texture on RGB, mask on alpha 

Texture entSkin1; // basic tiled terrain texture
Texture LightMap; // lightmap created by the map compiler

bool PASS_SOLID; // enforce rendering on the solid pass
//bool AUTORELOAD;

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

// technique without lightmap
technique terraintex
{
	pass multi_repeat11
	{
    ZWriteEnable = True;
		AlphaBlendEnable = True;
		SrcBlend = SrcAlpha;
    DestBlend = InvSrcAlpha;
		
		Texture[0] = <entSkin1>;
		TexCoordIndex[0] = 0;
		AlphaOp[0] = SelectArg1;
		AlphaArg1[0] = Texture;
		
		Texture[1] = <entSkin1>;
		TexCoordIndex[1] = 1;
    ColorArg1[1] = Texture; 
	  ColorArg2[1]= Diffuse;
	  ColorOp[1] = Modulate2x;
	  AlphaArg1[1] = Current;
	  AlphaOp[1] = SelectArg1;

	  ColorOp[2] = Disable;
	  AlphaOp[2] = Disable;
	}
}

// technique with lightmap
technique terraintex_lm
{
	pass multi_repeat11
	{
      ZWriteEnable = True;
		AlphaBlendEnable = True;
		SrcBlend = SrcAlpha;
      DestBlend = InvSrcAlpha;
		
		Texture[0] = <entSkin1>;
		TexCoordIndex[0] = 0;
		AlphaOp[0] = SelectArg1;
		AlphaArg1[0] = Texture;
		
		Texture[1] = <LightMap>;
		TexCoordIndex[1] = 0;
      ColorArg1[1] = Texture; 
	   ColorArg2[1]= Diffuse;
	   ColorOp[1] = AddSigned;
	   AlphaArg1[1] = Current;
	   AlphaOp[1] = SelectArg1;

		Texture[2] = <entSkin1>;
		TexCoordIndex[2] = 1;
      ColorArg1[2] = Texture; 
	   ColorArg2[2]= Current;
	   ColorOp[2] = Modulate2x;
	   AlphaArg1[2] = Current;
	   AlphaOp[2] = SelectArg1;

	   ColorOp[3] = Disable;
	   AlphaOp[3] = Disable;
	}
}

// fallback if nothing works
technique fallback { pass one { } }



MATERIAL* mtlShadow =
{
effect = "Shadow.fx";
flags = AUTORELOAD;
}

Code:
////////////////////////////////////////////////////
// Simple shadow mapping shader
// Copyright (c) 2007 Conitec.
// (with reduced darkness..)
// based on modifications by Jibb Smart 
////////////////////////////////////////////////////

#define USE_PCF // use percentage closer filtering

//Tweakables
static const float fDark = 0.6;
static const float fDarkDiffuse = 0.15;
//static const float fDarkDiffuse = 0.15;
static const float fBright = 1.4;
static const float fDepthOffset = 0.99;
static const float fPCF = 0.9;

// Application fed data:
const float4x4 matWorldViewProj;	// World*view*projection matrix.
const float4x4 matWorld; // World matrix.
const float4x4 matMtl;   // Precalculated texture projection matrix
const float4 vecSunDir;	// Sun direction vector.

texture TargetMap;
texture entSkin1;
sampler DepthSampler = sampler_state { Texture = <TargetMap>; };
sampler TexSampler = sampler_state { Texture = <entSkin1>; Mipfilter = Linear; };

// Shadow mapping vertex shader
void ShadowVS (in float4 inPos: POSITION,
		in float2 inTex: TEXCOORD0,
		in float3 inNormal: NORMAL,
		out float4 outPos: POSITION,
		out float2 outTex: TEXCOORD0,
		out float3 outNormal: TEXCOORD1,
		out float4 outDepth: TEXCOORD2)
{
// Transform the vertex from object space to clip space:
	outPos = mul(inPos, matWorldViewProj);
	
// Transform the normal from object space to world space:
	outNormal = normalize(mul(inNormal,matWorld));
	
// Pass the texture coordinate to the pixel shader:
	outTex = inTex;
	
// Output the projective texture coordinates
	outDepth = mul( mul(inPos,matWorld), matMtl );
}

// distance comparison function
float fDist(float4 DepthCoord,float fDepth)
{
	return 
		tex2Dproj(DepthSampler,DepthCoord).r < (fDepth*fDepthOffset)? fDark : fBright;
}

#ifdef USE_PCF
static const float4 fTaps_PCF[9] = {
	{-1.0,-1.0, 0.0, 0.0},
	{-1.0, 0.0, 0.0, 0.0},
	{-1.0, 1.0, 0.0, 0.0},
	{ 0.0,-1.0, 0.0, 0.0},
	{ 0.0, 0.0, 0.0, 0.0},
	{ 0.0, 1.0, 0.0, 0.0},
	{ 1.0,-1.0, 0.0, 0.0},
	{ 1.0, 0.0, 0.0, 0.0},
	{ 1.0, 1.0, 0.0, 0.0}};
#endif

// Shadow mapping pixel shader
float4 ShadowPS (in float4 inPos: POSITION,
					in float2 inTex: TEXCOORD0,
					in float3 inNormal: TEXCOORD1,
					in float4 inDepth: TEXCOORD2) : COLOR0
{
// Calculate the diffuse term:

	float fDiffuse = lerp(fDarkDiffuse, fBright, saturate(dot(-vecSunDir, normalize(inNormal))));


// Calculate the shadow term
#ifdef USE_PCF
	float fShadow = 0.0;
	for (int i=0; i < 9; i++)
	{
		float4 fTap = inDepth + fPCF*fTaps_PCF[i];
		fShadow += fDist(fTap,inDepth.z)/9;
	}
#else
	float fShadow = fDist(inDepth,inDepth.z);
#endif		


		return tex2D(TexSampler,inTex) * min(fShadow, fDiffuse);
}

technique techShadow
{
	pass p0
	{
		VertexShader = compile vs_2_0 ShadowVS();
		PixelShader  = compile ps_2_0 ShadowPS();
	}
}





Last edited by Benni003; 05/11/11 08:51.