#include "common.h"

struct vf
{
	float4 hpos	: POSITION;
	float2 tc0	: TEXCOORD0;		// base
	float4 tc1	: TEXCOORD1;		// projected lmap
	float3 c0	: COLOR0;		// sun-color
	float4 c1	: COLOR1;		// lq-color + factor
	float  fog	: FOG;
};

uniform float4x4	m_plmap_xform;
uniform float4 		m_plmap_clamp;
uniform float4 		m_plmap_factor;

vf main (v_model v)
{
	vf 		o;

	float4 	pos 	= v.pos;
	float3  pos_w 	= mul			(m_W, pos);
	float4  pos_w4 	= float4		(pos_w,1);
	float3 	norm_w 	= normalize 		(mul(m_W,v.norm));
	float4 	plmap 	= mul			(m_plmap_xform,pos_w4);	// calc plmap tc

	o.hpos 		= mul			(m_WVP, pos);		// xform, input in world coords
	o.tc0		= v.tc.xy;					// copy tc
	o.tc1		= plmap.xyww;					// clamp(plmap.xy / plmap.w, m_plmap_clamp.xy, m_plmap_clamp.zw);
	o.c0 		= calc_sun		(norm_w);  		// sun
	o.c1 		= float4		(calc_model_lq_lighting(norm_w),m_plmap_factor.w);
	o.fog 		= calc_fogging 		(pos_w4);		// fog, input in world coords

	return o;
}
