Example #1
0
void Terrain::Render()
{
	rootNode->EvaluateVisibility();

	terrainShader.effect->SetTechnique("Terrain");
	terrainShader.effect->SetMatrix("matWVP", &(LocalToWorldMatrix()*scene.mainCamera.ViewMatrix()*scene.mainCamera.ProjMatrix()));
	terrainShader.effect->SetMatrix("matWorld", &(LocalToWorldMatrix()));
	terrainShader.effect->SetMatrix("matUVTransform", &UVTransformMatrix());
	terrainShader.effect->SetRawValue("ambientLight", &(scene.ambientLight->intensity * scene.ambientLight->color), 0 , sizeof(Vector3));
	terrainShader.effect->SetRawValue("directionalLights", directionalLightsData, 0, sizeof(directionalLightsData));
	terrainShader.effect->SetRawValue("pointLights", pointLightsData, 0, sizeof(pointLightsData));
	terrainShader.effect->SetTexture("colorTex0", colorTexes[0]);
	terrainShader.effect->SetTexture("colorTex1", colorTexes[1]);
	terrainShader.effect->SetTexture("colorTex2", colorTexes[2]);
	terrainShader.effect->SetTexture("colorTex3", colorTexes[3]);
	terrainShader.effect->SetTexture("splatMapTex", splatMapTex);
	terrainShader.effect->SetInt("numTexes", numTexes);
	terrainShader.effect->SetRawValue("mtlDiffuse", &diffuse, 0, sizeof(D3DXCOLOR));

	terrainShader.effect->Begin(0, 0);
	terrainShader.effect->BeginPass(0);

	culledChunks = 0;
	for(vector<Chunk>::iterator iter = chunks.begin(); iter != chunks.end(); ++iter){
		//if(scene.mainCamera.isVisible((*iter).mesh.boundingBox)){
		if((*iter).node->isInFrustum){
			(*iter).mesh.SetStream();
			(*iter).mesh.SetVertexDeclaration();
			(*iter).mesh.Draw();
		}
		else{
			culledChunks++;
		}
	}
	//printf("%d chunks culled\n", culledChunks);

	terrainShader.effect->EndPass();
	terrainShader.effect->End();
}
Example #2
0
void Gizmo::Draw(Vector3 perspectivePos)
{
	CaculatePosition(perspectivePos, scene.mainCamera.ViewMatrix(), scene.mainCamera.ProjMatrix(), scene.mainCamera.OrthoProjMatrix());
	
	// TODO:存在一个问题,gizmo本身的z顺序。
	D3DDevice->SetRenderState(D3DRS_ZENABLE, false);

	// axis - line
	/*axisX.Draw(LocalToWorldMatrix() * scene.mainCamera.ViewMatrix() * scene.mainCamera.OrthoProjMatrix());
	axisZ.Draw(LocalToWorldMatrix() * scene.mainCamera.ViewMatrix() * scene.mainCamera.OrthoProjMatrix());
	axisY.Draw(LocalToWorldMatrix() * scene.mainCamera.ViewMatrix() * scene.mainCamera.OrthoProjMatrix());*/

	// axisX
	axisX.SetStream();
	axisX.SetVertexDeclaration();

	gizmoShader.effect->SetTechnique("Gizmo");
	gizmoShader.effect->SetMatrix("matWVP", &(axisX.LocalToWorldMatrix()*LocalToWorldMatrix()*scene.mainCamera.ViewMatrix()*scene.mainCamera.OrthoProjMatrix()));
	gizmoShader.effect->SetMatrix("matWorld", &(axisX.LocalToWorldMatrix()*LocalToWorldMatrix()));
	gizmoShader.effect->SetRawValue("mainColor", &(axisX.color), 0, sizeof(D3DXCOLOR));
	gizmoShader.effect->SetRawValue("eyePos", &(scene.mainCamera.position), 0, sizeof(Vector3));

	gizmoShader.effect->Begin(0, 0);
	gizmoShader.effect->BeginPass(0);

	axisX.Draw();

	gizmoShader.effect->EndPass();
	gizmoShader.effect->End();
	
	// axisY
	axisY.SetStream();
	axisY.SetVertexDeclaration();

	gizmoShader.effect->SetTechnique("Gizmo");
	gizmoShader.effect->SetMatrix("matWVP", &(axisY.LocalToWorldMatrix()*LocalToWorldMatrix()*scene.mainCamera.ViewMatrix()*scene.mainCamera.OrthoProjMatrix()));
	gizmoShader.effect->SetMatrix("matWorld", &(axisY.LocalToWorldMatrix()*LocalToWorldMatrix()));
	gizmoShader.effect->SetRawValue("mainColor", &(axisY.color), 0, sizeof(D3DXCOLOR));
	gizmoShader.effect->SetRawValue("eyePos", &(scene.mainCamera.position), 0, sizeof(Vector3));

	gizmoShader.effect->Begin(0, 0);
	gizmoShader.effect->BeginPass(0);

	axisY.Draw();

	gizmoShader.effect->EndPass();
	gizmoShader.effect->End();

	// axisZ
	axisZ.SetStream();
	axisZ.SetVertexDeclaration();

	gizmoShader.effect->SetTechnique("Gizmo");
	gizmoShader.effect->SetMatrix("matWVP", &(axisZ.LocalToWorldMatrix()*LocalToWorldMatrix()*scene.mainCamera.ViewMatrix()*scene.mainCamera.OrthoProjMatrix()));
	gizmoShader.effect->SetMatrix("matWorld", &(axisZ.LocalToWorldMatrix()*LocalToWorldMatrix()));
	gizmoShader.effect->SetRawValue("mainColor", &(axisZ.color), 0, sizeof(D3DXCOLOR));
	gizmoShader.effect->SetRawValue("eyePos", &(scene.mainCamera.position), 0, sizeof(Vector3));

	gizmoShader.effect->Begin(0, 0);
	gizmoShader.effect->BeginPass(0);

	axisZ.Draw();

	gizmoShader.effect->EndPass();
	gizmoShader.effect->End();
		
	// coneX
	coneX.SetStream();
	coneX.SetVertexDeclaration();

	gizmoShader.effect->SetTechnique("Gizmo");
	gizmoShader.effect->SetMatrix("matWVP", &(coneX.LocalToWorldMatrix()*LocalToWorldMatrix()*scene.mainCamera.ViewMatrix()*scene.mainCamera.OrthoProjMatrix()));
	gizmoShader.effect->SetMatrix("matWorld", &(coneX.LocalToWorldMatrix()*LocalToWorldMatrix()));
	gizmoShader.effect->SetRawValue("mainColor", &(coneX.color), 0, sizeof(D3DXCOLOR));
	gizmoShader.effect->SetRawValue("eyePos", &(scene.mainCamera.position), 0, sizeof(Vector3));

	gizmoShader.effect->Begin(0, 0);
	gizmoShader.effect->BeginPass(0);

	coneX.Draw();

	gizmoShader.effect->EndPass();
	gizmoShader.effect->End();
		
	// coneY
	coneY.SetStream();
	coneY.SetVertexDeclaration();

	gizmoShader.effect->SetTechnique("Gizmo");
	gizmoShader.effect->SetMatrix("matWVP", &(coneY.LocalToWorldMatrix()*LocalToWorldMatrix()*scene.mainCamera.ViewMatrix()*scene.mainCamera.OrthoProjMatrix()));
	gizmoShader.effect->SetMatrix("matWorld", &(coneY.LocalToWorldMatrix()*LocalToWorldMatrix()));
	gizmoShader.effect->SetRawValue("mainColor", &(coneY.color), 0, sizeof(D3DXCOLOR));
	gizmoShader.effect->SetRawValue("eyePos", &(scene.mainCamera.position), 0, sizeof(Vector3));

	gizmoShader.effect->Begin(0, 0);
	gizmoShader.effect->BeginPass(0);

	coneY.Draw();

	gizmoShader.effect->EndPass();
	gizmoShader.effect->End();
		
	// coneZ
	coneZ.SetStream();
	coneZ.SetVertexDeclaration();

	gizmoShader.effect->SetTechnique("Gizmo");
	gizmoShader.effect->SetMatrix("matWVP", &(coneZ.LocalToWorldMatrix()*LocalToWorldMatrix()*scene.mainCamera.ViewMatrix()*scene.mainCamera.OrthoProjMatrix()));
	gizmoShader.effect->SetMatrix("matWorld", &(coneZ.LocalToWorldMatrix()*LocalToWorldMatrix()));
	gizmoShader.effect->SetRawValue("mainColor", &(coneZ.color), 0, sizeof(D3DXCOLOR));
	gizmoShader.effect->SetRawValue("eyePos", &(scene.mainCamera.position), 0, sizeof(Vector3));

	gizmoShader.effect->Begin(0, 0);
	gizmoShader.effect->BeginPass(0);

	coneZ.Draw();

	gizmoShader.effect->EndPass();
	gizmoShader.effect->End();

	D3DDevice->SetRenderState(D3DRS_ZENABLE, true);
}
Example #3
0
	FMatrix4 FTransform::WorldToLocalMatrix() const
	{
		return LocalToWorldMatrix().GetInverse();
	}