float4x4 worldViewProj : WorldViewProjection;
float4x4 viewProj : ViewProjection;
float4x4 world : World;
float4x4 worldView : WorldView;

#define BONEMODE_4x3 1

/*****************************************************************************

DepthRender

Output posView.z to floating point depth surface

******************************************************************************/

#include "..\generic.fx"

float3 campos : CAMERAPOS;

texture diffuseTexture : DiffuseTexture;
sampler DiffuseTextureSampler = sampler_state 
{
    texture = <diffuseTexture>;
    AddressU  = WRAP;        
    AddressV  = WRAP;
    AddressW  = WRAP;
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

struct vertexInputBoned {
    float4 position				: POSITION;
    float3 normal				: NORMAL;
    float2 texCoordDiffuse		: TEXCOORD0;
    float4 boneids              : BLENDINDICES;
    float4 boneweights          : BLENDWEIGHT;
};

struct vertexInputUnboned {
    float4 position				: POSITION;
    float3 normal				: NORMAL;
    float2 texCoordDiffuse		: TEXCOORD0;
};

struct vertexOutput {
    float4 hPosition		: POSITION;
    float4 posView          : TEXCOORD0;
};

vertexOutput VS_Shared(float4 pos, float4 posv )
{
    vertexOutput OUT;

    OUT.posView = posv;
    OUT.hPosition = mul( pos , viewProj);
    return OUT;
}

vertexOutput VS_TransformBoned(vertexInputBoned IN) 
{
    float4 pos;
    float4 posv;
    float3 norm;
    float weight4;
    weight4 = 1 - dot(IN.boneweights.xyz, float3(1,1,1));
    float4 weights = float4(IN.boneweights.xyz, weight4);
    
    float4 boneids = VS_ScaleBoneIDsFromD3DCOLOR(IN.boneids);
    VS_TransformBonesPN_4(IN.position, pos, IN.normal, norm, boneids, weights, world );
    VS_TransformBonesP_4(IN.position, posv, boneids, weights, worldView);
    return VS_Shared(pos, posv );
}

vertexOutput VS_TransformUnboned(vertexInputUnboned IN) 
{
    float4 pos;
    float4 posv;
    
    pos = mul(IN.position, world);
    posv = mul(IN.position, worldView);
    return VS_Shared(pos, posv );
}

float4 PS_Textured( vertexOutput IN) : Color0
{
    float depth = IN.posView.z / 4000.0f;
    float4 outColor = float4(depth, depth, depth, 1);
        
	return outColor;
}


//-----------------------------------
technique boned
{
    pass p0 
    {		
		VertexShader = compile vs_2_0 VS_TransformBoned();
		PixelShader  = compile ps_2_0 PS_Textured();
    }
}

technique unboned
{
    pass p0 
    {		
		VertexShader = compile vs_2_0 VS_TransformUnboned();
		PixelShader  = compile ps_2_0 PS_Textured();
    }
}
