; ** Type 1: transform and light the vertices **
; Input: As declared
; v0=position
; v1=normal
; v2=textureUV
; Constants:
; c[0].x=0 c[0].y=1 c[0].z=0.5 c[0].w=ambient light
; c[1] object colour
; c[2]-c[5] combined worldviewproj transformation matrix
; c[6]-c[8] world transformation matrix
; c[9]-c[11] view transformation matrix
; c[12] perspective transformation matrix
; c[13] light 1 position (.w=radius)
; c[14] light 1 colour
; c[15] light 2 position (.w=radius)
; c[16] light 2 colour
; c[17] light 3 position (.w=radius)
; c[18] light 3 colour
; Move value to oFog.x for fog (=1=off)

vs.1.1
dcl_position v0
dcl_normal v1
dcl_texcoord v2

; Transform position (after this screen pos=r0)
dp4 r0.x, v0, c[2]
dp4 r0.y, v0, c[3]
dp4 r0.z, v0, c[4]
dp4 r0.w, v0, c[5]
mov oPos, r0

; Transform normal to world space (after this normal=r1)
dp3 r1.x, v1, c[6]
dp3 r1.y, v1, c[7]
dp3 r1.z, v1, c[8]

; Before we can light transform coords to world space (after this world=r2)
dp4 r2.x, v0, c[6]
dp4 r2.y, v0, c[7]
dp4 r2.z, v0, c[8]

; Light 1: Get direction to light
sub r4.xyz, c[13].xyz, r2.xyz
; LIGHT: normalise light direction and calc lighting
dp3 r4.w, r4, r4
rsq r4.w, r4.w												
mul r4, r4, r4.w	
; Put diffuse factor into r4.x
dp3 r4.x, r1, r4
; Limit r4.x to positive (c[0].x=0)
max r4.x, r4.x, c[0].x
; APPLY: Result = (objectcolour*r4.x)*lightcolour
; for multiple lights, use mad r5, r4, c[x], r5 for future lights
mul r5, r4.x, c[14]

; Light 2: Get direction to light
sub r4.xyz, c[15].xyz, r2.xyz
; LIGHT: normalise light direction and calc lighting
dp3 r4.w, r4, r4
rsq r4.w, r4.w												
mul r4, r4, r4.w	
; Put diffuse factor into r4.x
dp3 r4.x, r1, r4
; Limit r4.x to positive (c[0].x=0)
max r4.x, r4.x, c[0].x
; APPLY: Result = (objectcolour*r4.x)*lightcolour+r5
mad r5, r4.x, c[16], r5

; Light 3: Get direction to light
sub r4.xyz, c[17].xyz, r2.xyz
; LIGHT: normalise light direction and calc lighting
dp3 r4.w, r4, r4
rsq r4.w, r4.w												
mul r4, r4, r4.w	
; Put diffuse factor into r4.x
dp3 r4.x, r1, r4
; Limit r4.x to positive (c[0].x=0)
max r4.x, r4.x, c[0].x
; APPLY: Result = (objectcolour*r4.x)*lightcolour+r5
mad r5, r4.x, c[18], r5

; Ambient
add oD0, r5, c[0].w

; Move object colour alpha direct to surface alpha
mov oD0.w, c[1].w

; Move texture coords to output
mov oT0, v2

; Transform normal to camera space and perform reflection mapping
;dp3 r2.x, r1, c[9]
;dp3 r2.y, r1, c[10]
;mad oT1.xy, r2.xy, c[0].z, c[0].z
; Build relection map texture coords using u=(Nx*0.5)+0.5 v=(Ny*0.5)+0.5
mad oT1.xy, r1.xy, c[0].z, c[0].z
