/*
	You may have to meddle around with this procedure. I am using my own 
	data structures for light data. Maybe you can replace them with your own.
	
	All I need for the light data is it's world position, color, intensity, and attenuation.
	also final color = (color*intensity).

	Replace multiple SetVertexShaderConstant calls by a single one.
*/
static void __fastcall LoadPlaneBlendConstants(IDirect3DDevice8* pdevice, D3DXMATRIX* world, 
			D3DXMATRIX* LeftPlaneMat, D3DXMATRIX* RightPlaneMat)
{
	D3DXMATRIX		trans, matTransposed, TransposedWorld ;
	D3DXMATRIX		LeftPlaneMatTransposed, RightPlaneMatTransposed ;
	D3DXMATRIX		view, proj ;
	float			fUpload[4*12] = { 1.0f } ;
	float			fUploadFourZeroes[4] = { 0 } ;
	D3DLIGHT8*		light8 ;
	extern LightHdr	g_lightHdr ;
	LightProp*		ltProp ;
	float			c4[4] = { 4.0f, CV_BONE_MATRICES_START_FLT, 1.0f, 0.0f } ;

	pdevice->lpVtbl->GetTransform(pdevice, D3DTS_VIEW, &view) ;
	pdevice->lpVtbl->GetTransform(pdevice, D3DTS_PROJECTION, &proj) ;

	// view x projection
	MulMatrix(&trans, &view, &proj) ;
	
	D3DXMatrixTranspose(&matTransposed, &trans) ;
	D3DXMatrixTranspose(&TransposedWorld, (D3DXMATRIX*)world) ;

	// c0 = utility constants
	pdevice->lpVtbl->SetVertexShaderConstant(pdevice, 0, c4, 1) ;

	// c1 = Zeroes
	pdevice->lpVtbl->SetVertexShaderConstant(pdevice, 1, fUploadFourZeroes, 1) ;

	// c14 to c17 = world matrix
	pdevice->lpVtbl->SetVertexShaderConstant(pdevice, CV_WORLD_0, &TransposedWorld, 4) ;

	// c18 to c21 = View x Projection
	pdevice->lpVtbl->SetVertexShaderConstant(pdevice, CV_VIEWPROJ_0, &matTransposed, 4) ;


	light8 = GetLightProperties(0) ;
	ltProp = &g_lightHdr.lp[0] ;
	
	// c2 to c4 = light 1
	CopyMemory(&fUpload[0], &light8->Position, sizeof(D3DVECTOR)) ;
	CopyMemory(&fUpload[4], &light8->Attenuation0, sizeof(D3DVECTOR)) ;
	fUpload[8] = light8->Diffuse.r * ltProp->rIntensity ;
	fUpload[9] = light8->Diffuse.g * ltProp->gIntensity ;
	fUpload[10] = light8->Diffuse.b * ltProp->bIntensity ;
	fUpload[11] = 1.0f ;

	light8 = GetLightProperties(1) ;
	ltProp = &g_lightHdr.lp[1] ;
	// c5 to c7 = light 2
	CopyMemory(&fUpload[12], &light8->Position, sizeof(D3DVECTOR)) ;
	CopyMemory(&fUpload[16], &light8->Attenuation0, sizeof(D3DVECTOR)) ;
	fUpload[20] = light8->Diffuse.r * ltProp->rIntensity ;
	fUpload[21] = light8->Diffuse.g * ltProp->gIntensity ;
	fUpload[22] = light8->Diffuse.b * ltProp->bIntensity ;
	fUpload[23] = 1.0f ;

	// upload light data
	pdevice->lpVtbl->SetVertexShaderConstant(pdevice, 2, fUpload, 12) ;

	
	D3DXMatrixTranspose(&LeftPlaneMatTransposed, (D3DXMATRIX*)LeftPlaneMat) ;
	D3DXMatrixTranspose(&RightPlaneMatTransposed, (D3DXMATRIX*)RightPlaneMat) ;

	// upload the left and right transposed plane rotation matrices
	pdevice->lpVtbl->SetVertexShaderConstant(pdevice, CV_PLANE_BLEND_LEFT_MATRIX, 
		&LeftPlaneMatTransposed, 4) ;
	pdevice->lpVtbl->SetVertexShaderConstant(pdevice, CV_PLANE_BLEND_RIGHT_MATRIX, 
		&RightPlaneMatTransposed, 4) ;
}