/* LightFX Shader

DimapLimapEmmapAm.fx

Created	: 08.08.06
Modified: 08.08.06
Author	: Dirk Bialluch
Copyright 2006, Lightstorm3D

Features:
	diffuse map
	light map
	emissive map
	ambient
*/

// input parameters

shared float4x4 Model;
int AlphaRef = 100;

shared float4		MatAmbient;
shared float4		MatDiffuse;
shared float4		MatEmissive;

float CullMode = 2;

shared texture		DiffMap0;
shared texture		DiffMap1;
shared texture		DiffMap2;

shared float4x4 TextureTransform0 = {1.0f, 0.0f, 0.0f, 0.0f,
                              0.0f, 1.0f, 0.0f, 0.0f, 
                              0.0f, 0.0f, 1.0f, 0.0f,
                              0.0f, 0.0f, 0.0f, 1.0f };
shared float4x4 TextureTransform1 = {1.0f, 0.0f, 0.0f, 0.0f,
                              0.0f, 1.0f, 0.0f, 0.0f, 
                              0.0f, 0.0f, 1.0f, 0.0f,
                              0.0f, 0.0f, 0.0f, 1.0f };

// texture sampler

sampler diffuseMapSampler = sampler_state
{
	Texture = <DiffMap0>;
	AddressU  = Wrap;
	AddressV  = Wrap;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
	MipMapLodBias = -0.75;
};

sampler lightMapSampler = sampler_state
{
	Texture = <DiffMap1>;
	AddressU  = Wrap;
	AddressV  = Wrap;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
	MipMapLodBias = -0.75;    
};

sampler emissiveMapSampler = sampler_state
{
	Texture = <DiffMap2>;
	AddressU  = Wrap;
	AddressV  = Wrap;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
	MipMapLodBias = -0.75;
};

// technique and passes
technique textured
{

	pass p0
	{
		worldTransform[0]   		= <Model>;
        TextureTransform[0]			= <TextureTransform0>;
        TextureTransform[1]			= <TextureTransform1>;

        AlphaRef					= <AlphaRef>;
		CullMode            		= <CullMode>;

        Lighting = false;

        FVF = XYZ | NORMAL | TEX2;

        TexCoordIndex[0] = 0;
        //TextureTransformFlags[0] = Count2;
        TexCoordIndex[1] = 1;
        //TextureTransformFlags[1] = Count2;
		texCoordIndex[2] = 0;
        //TextureTransformFlags[2] = Count2;

		materialDiffuse     		= <MatDiffuse>;
		materialAmbient     		= <MatAmbient>;
		materialEmissive 			= <MatEmissive>;

		sampler[0] 					= <diffuseMapSampler>;
		colorOp[0]   				= SelectArg1;
		colorArg1[0] 				= Texture;
		colorArg2[0] 				= 0;
		alphaOp[0]					= SelectArg1;
		alphaArg1[0]				= Texture;

		sampler[1] 					= <lightMapSampler>;
		colorOp[1]   				= Modulate2x;
		colorArg1[1] 				= Texture;
		colorArg2[1]	 			= Current;
		alphaOp[1]					= SelectArg1;
		alphaArg1[1]				= Current;

		sampler[2] 					= <emissiveMapSampler>;
		colorOp[2]   				= Add;
		colorArg1[2] 				= Current;
		colorArg2[2] 				= Texture;
		alphaOp[2]					= SelectArg1;
		alphaArg1[2]				= Current;

		alphaOp[3]					= Disable;
		colorOp[3]  			 	= Disable;

	}
}

technique lightmapped
{
    pass p0
    {
        WorldTransform[0]   = <Model>;
        //TextureTransform[0] = <TextureTransform0>;
        //TextureTransform[1] = <TextureTransform1>;
        
        AlphaRef            = <AlphaRef>;
        CullMode            = <CullMode>;
 
        Lighting = false;
        
        FVF = XYZ | NORMAL | TEX2;
        
        TexCoordIndex[0] = 0;
        //TextureTransformFlags[0] = Count2;

        TexCoordIndex[1] = 1;
        //TextureTransformFlags[1] = Count2;
                
        Sampler[0] = <diffuseMapSampler>;
        Sampler[1] = <lightMapSampler>;
        
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        ColorArg2[0] = 0;
        
        ColorOp[1]   = Modulate2x;
        ColorArg1[1] = Texture;
        ColorArg2[1] = Current;

        ColorOp[2]   = Disable;
    }
}

technique lightmapped2x
{
    pass p0
    {
        WorldTransform[0]   = <Model>;
        //TextureTransform[0] = <TextureTransform0>;
        //TextureTransform[1] = <TextureTransform1>;
        
        AlphaRef            = <AlphaRef>;
        CullMode            = <CullMode>;
 
        Lighting = false;
        
        FVF = XYZ | NORMAL | TEX2;
        
        TexCoordIndex[0] = 0;
        //TextureTransformFlags[0] = Count2;

        TexCoordIndex[1] = 1;
        //TextureTransformFlags[1] = Count2;
                
        Sampler[0] = <diffuseMapSampler>;
        Sampler[1] = <lightMapSampler>;
        
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        ColorArg2[0] = 0;
        
        ColorOp[1]   = Modulate2x;
        ColorArg1[1] = Texture;
        ColorArg2[1] = Current;

        ColorOp[2]   = Disable;
    }
}

technique lightmapped2x_atest
{
    pass p0
    {
        WorldTransform[0]   = <Model>;
        //TextureTransform[0] = <TextureTransform0>;
        //TextureTransform[1] = <TextureTransform1>;
        
        AlphaRef            = <AlphaRef>;
        CullMode            = <CullMode>;
 
        Lighting = false;
        
        FVF = XYZ | NORMAL | TEX2;
        
        TexCoordIndex[0] = 0;
        //TextureTransformFlags[0] = Count2;

        TexCoordIndex[1] = 1;
        //TextureTransformFlags[1] = Count2;
                
        Sampler[0] = <diffuseMapSampler>;
        Sampler[1] = <lightMapSampler>;
        Sampler[2] = <lightMapSampler>;
        
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        ColorArg2[0] = 0;
        
        ColorOp[1]   = Modulate4x;
        ColorArg1[1] = Texture;
        ColorArg2[1] = Current;


        ColorOp[2]   = Disable;
    }
}


technique tStatic
{
    pass p0
    {        
        WorldTransform[0]   = <Model>;
        //TextureTransform[0] = <TextureTransform0>;
        //TextureTransformFlags[0] = Count2;
        
        CullMode            = <CullMode>;
        MaterialDiffuse     = <MatDiffuse>;
        MaterialEmissive    = <MatEmissive>;
        MaterialAmbient     = {1.0, 1.0, 1.0, 1.0};                

        FVF = XYZ | NORMAL | TEX1;

        TexCoordIndex[0] = 0;

        Sampler[0] = <diffuseMapSampler>;

        ColorOp[0]   = Modulate;
        ColorArg1[0] = Texture;
        ColorArg2[0] = Diffuse;

        ColorOp[1]   = Disable;
    }
}
