示例#1
0
//In the LoadShaderConsts method, the user specifies the method using its string name
//the appropriate consts are then set for the shaders
void CRenderer::LoadMethodConsts( CLightManager* lightMan, CMatrix4x4 &viewProjMat, 
								  CVector3 camPos, float SpecularPow )
{
	TSRenderMethIter iter;
	D3DXMATRIXA16 viewProj = ToD3DXMATRIX( viewProjMat );

// Load the constants for each render method
	
/*********** Vertex Shader for the Texture, Black and BrightenedTexture methods ****/
	vsTexture->m_ShaderConsts->SetMatrix( m_d3dDevice, "ViewProjMatrix", &viewProj );

/*********** Constants for the shaders used in PixelLighting method  ****************/
	vsPixelLighting->m_ShaderConsts->SetMatrix( m_d3dDevice, "ViewProjMatrix", &viewProj );
	psPixelLighting->m_ShaderConsts->SetFloatArray( m_d3dDevice, "AmbientColour",
															(float*)&lightMan->AmbientLight(), 3 );
	//Set up the consts for light 1
	psPixelLighting->m_ShaderConsts->SetFloatArray( m_d3dDevice, "Light1Pos",
															(float*)&lightMan->m_Lights[0].m_Pos, 3 );
	psPixelLighting->m_ShaderConsts->SetFloatArray( m_d3dDevice, "Light1Colour", 
															(float*)&lightMan->m_Lights[0].m_Colour, 4 );

	// Set up consts for pix lighting with specular highlights
	psPixelLightingSpec->m_ShaderConsts->SetFloatArray( m_d3dDevice, "Light1Pos", 
															(float*)&lightMan->m_Lights[0].m_Pos, 3 );
	psPixelLightingSpec->m_ShaderConsts->SetFloatArray( m_d3dDevice, "Light1Colour", 
															(float*)&lightMan->m_Lights[0].m_Colour, 4 );
	vsVertexLighting->m_ShaderConsts->SetFloatArray( m_d3dDevice, "CameraPosition", 
															(float*)&camPos, 3 );
	psPixelLightingSpec->m_ShaderConsts->SetFloat( m_d3dDevice, "SpecularPower", 500.0 );

/*********** Constants for the shaders used in VertexLighting method  ****************/
	vsVertexLighting->m_ShaderConsts->SetMatrix( m_d3dDevice, "ViewProjMatrix", &viewProj );
	vsVertexLighting->m_ShaderConsts->SetFloatArray( m_d3dDevice, "AmbientColour", 
															(float*)&lightMan->AmbientLight(), 3 );
	vsVertexLighting->m_ShaderConsts->SetFloatArray( m_d3dDevice, "CameraPosition", 
															(float*)&camPos, 3 );
	//light 1
	vsVertexLighting->m_ShaderConsts->SetFloatArray( m_d3dDevice, "Light1Pos", 
															(float*)&lightMan->m_Lights[0].m_Pos, 3 );
	vsVertexLighting->m_ShaderConsts->SetFloatArray( m_d3dDevice, "Light1Colour", 
															(float*)&lightMan->m_Lights[0].m_Colour, 4 );
	//Specular Power
	vsVertexLighting->m_ShaderConsts->SetFloat( m_d3dDevice, "SpecularPower", SpecularPow );

/*********** Constants for the shaders used in NormalMapping method  ****************/
	vsNormalMapping->m_ShaderConsts->SetMatrix( m_d3dDevice, "ViewProjMatrix", &viewProj );

	psNormalMapping->m_ShaderConsts->SetFloatArray( m_d3dDevice, "AmbientColour", 
															(float*)&lightMan->AmbientLight(), 3 );
	psNormalMapping->m_ShaderConsts->SetFloatArray( m_d3dDevice, "CameraPosition", 
															(float*)&camPos, 3 );
	//light 1
	psNormalMapping->m_ShaderConsts->SetFloatArray( m_d3dDevice, "Light1Pos", 
															(float*)&lightMan->m_Lights[0].m_Pos, 3 );
	psNormalMapping->m_ShaderConsts->SetFloatArray( m_d3dDevice, "Light1Colour", 
															(float*)&lightMan->m_Lights[0].m_Colour, 4 );
	psNormalMapping->m_ShaderConsts->SetFloatArray( m_d3dDevice, "Light1Brightness",
												    (float*)&lightMan->m_Lights[0].m_Brightness, 3 );
	psNormalMapping->m_ShaderConsts->SetFloat( m_d3dDevice, "SpecularPower", 256.0 );
}
示例#2
0
// Pass the world matrix and view/projection matrix to the vertex shader
void VS_XFormFn( int method, CMatrix4x4* worldMatrix, CCamera* camera )
{
	LPD3DXCONSTANTTABLE shaderConsts = renderMethods[method].vertexConsts;

	D3DXMATRIXA16 matViewProj = ToD3DXMATRIX( camera->GetViewProjMatrix() );
	shaderConsts->SetMatrix( g_pd3dDevice, "ViewProjMatrix", &matViewProj );

	D3DXMATRIX* matWorld = ToD3DXMATRIXPtr( worldMatrix );
	shaderConsts->SetMatrix( g_pd3dDevice, "WorldMatrix", matWorld );
}
示例#3
0
void CRenderer::SetMethodWorldMat( CMatrix4x4* WorldMat, ERenderMethod RenderMethod )
{
	TSRenderMethIter iter;

	D3DXMATRIXA16 worldMat = ToD3DXMATRIX( *WorldMat );

	for( iter = m_Methods.begin(); iter != m_Methods.end(); iter++ )
	{
		if( (*iter)->m_Method == RenderMethod )
		{
			(*iter)->m_vs->m_ShaderConsts->SetMatrix( m_d3dDevice, "WorldMatrix", &worldMat );
		}
	}
}
示例#4
0
// Pass data to vertex shaders that perform vertex lighting (1 point light)
// Passes full range of data - some shaders don't need all of it. This
// reduces the number of these functions at the expense of redundancy
void VS_VertLit1Fn( int method, CMatrix4x4* worldMatrix, CCamera* camera )
{
	LPD3DXCONSTANTTABLE shaderConsts = renderMethods[method].vertexConsts;

	D3DXMATRIXA16 matViewProj = ToD3DXMATRIX( camera->GetViewProjMatrix() );
	shaderConsts->SetMatrix( g_pd3dDevice, "ViewProjMatrix", &matViewProj );

	D3DXMATRIX* matWorld = ToD3DXMATRIXPtr( worldMatrix );
	shaderConsts->SetMatrix( g_pd3dDevice, "WorldMatrix", matWorld );

	D3DXVECTOR3 cameraPos = ToD3DXVECTOR( camera->Position() );
	shaderConsts->SetFloatArray( g_pd3dDevice, "CameraPosition", (FLOAT*)&cameraPos, 3 ); // If needed

	shaderConsts->SetFloatArray( g_pd3dDevice, "AmbientLight", (FLOAT*)&m_AmbientLight, 3 );
	shaderConsts->SetFloatArray( g_pd3dDevice, "LightPosition", (FLOAT*)&m_Lights[0]->GetPosition(), 3 );
	shaderConsts->SetFloatArray( g_pd3dDevice, "LightColour", (FLOAT*)&m_Lights[0]->GetColour(), 3 );
	shaderConsts->SetFloat( g_pd3dDevice, "LightBrightness", m_Lights[0]->GetBrightness() );

	shaderConsts->SetFloatArray( g_pd3dDevice, "MaterialColour", (FLOAT*)&m_DiffuseColour, 3 ); // If needed
	shaderConsts->SetFloatArray( g_pd3dDevice, "SpecularStrength", (FLOAT*)&m_SpecularColour, 3 ); // If needed
	shaderConsts->SetFloat( g_pd3dDevice, "SpecularPower", m_SpecularPower ); // If needed
}