float4x4 worldView : WorldView;
float4x4 Proj : Projection;

#define BONEMODE_4x3 1

#include "generic.fx"
#include "mrt.fx"

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

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

struct vertexOutput {
    float4 hPosition		: POSITION;
    float3 normalInView     : TEXCOORD0;
};

vertexOutput VS_Shared(float4 pos, float3 norm)
{
    vertexOutput OUT;

    OUT.normalInView = -norm;
    OUT.hPosition = mul( pos , Proj);
    return OUT;
}

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

vertexOutput VS_TransformUnboned(vertexInputUnboned IN) 
{
    float4 pos;
    float3 norm;
    
    pos = mul(IN.position, worldView);
    norm = mul(IN.normal, worldView);
    return VS_Shared(pos, norm);
}

float4 PS_Textured( vertexOutput IN) : COLOR
{
    float4 nz = pow(abs(dot(IN.normalInView.z, float3(0,0,1))),2);
    return float4(nz.xyz, 1);
}


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

technique unboned
{
    pass p0 
    {		
		VertexShader = compile vs_1_1 VS_TransformUnboned();
		PixelShader  = compile ps_1_1 PS_Textured();
    }
}
