/*
	Shader for transforming a vertex into clip space and lighting it.
	No Blending.
	This is explained in more detail on the web page
*/

/*
CONSTANT AREA MAP

C00 = 4.0f, 22.0f, 1.0f, IndexOffset
c01 = free
c02 = light 0: position 
c03 = light 0: attenuation
c04 = light 0: color
c05 = light 1: position 
c06 = light 1: attenuation
c07 = light 1: color
c08 = light 2: position 
c09 = light 2: attenuation
c10 = light 2: color
c11 = light 3: position 
c12 = light 3: attenuation
c13 = light 3: color

c14 - c17 = world transformation matrix
c18 - c21 = (View x Projection) matrix

c22 - c96 = plane matrices
*/


#define V_POSITION		v0
#define V_WEIGHT		v1
#define V_INDICES		v2
#define V_NORMAL		v3
#define V_TEXTURE		v7

#define POS_WORLD		r9
#define	CV_ZERO	c1.xxxx

#define CV_EACH_BONEMAT_HEIGHT		c0.x
#define CV_BONE_MAT_START_INDEX		c0.y
#define CV_BONE_OFFSET				c0.w


#include ".\\Source\\PlaneBlendVS.h"

vs.1.1							; Shader version 1.1


add	r0,			V_INDICES, -CV_BONE_OFFSET			; get the effective index of influence into the matrix array
mad	r0,			r0, CV_EACH_BONEMAT_HEIGHT, CV_BONE_MAT_START_INDEX	; multiply index by 4 and add by 22
max	r0,			r0, CV_ZERO					; don't let the index go negative

; multiply the bone matrix with the input vertex co-ordinates

; first and only influence
mov	a0.x,		r0.x
dp4	r8.x,		V_POSITION, c[a0.x]		; vector1.x -- Calculate X of first influence
dp4	r8.y,		V_POSITION, c[a0.x+1]		; vector1.y -- Calculate Y of first influence
dp4	r8.z,		V_POSITION, c[a0.x+2]		; vector1.z -- Calculate Z of first influence


; 1.0f out of thin air
sge	r8.w,		c0, c0				; result.w = 1.0f


; r8 now has the final non-blended vertex position

; multiply by world transformation matrix
dp4	r9.x,		r8, c[CV_WORLD_0]			; Final world position.x
dp4	r9.y,		r8, c[CV_WORLD_1]			; Final world position.y
dp4	r9.z,		r8, c[CV_WORLD_2]			; Final world position.z
dp4	r9.w,		r8, c[CV_WORLD_3]			; Final world position.w

; multiply by (ViewxProjection) matrix
dp4	oPos.x,		r9, c[CV_VIEWPROJ_0]		; position in clip space .x
dp4	oPos.y,		r9, c[CV_VIEWPROJ_1]		; position in clip space .y
dp4	oPos.z,		r9, c[CV_VIEWPROJ_2]		; position in clip space .z
dp4	oPos.w,		r9, c[CV_VIEWPROJ_3]		; position in clip space .w

; r9 has the final world position of the vertex
