コード例 #1
0
	void EngineApp::OnUpdate()
	{

		math::Matrix44 view;
		math::Matrix44 proj;
		math::Matrix44 t;
		math::Vector3 eye(20, 20, 20);
		
		static float radius = 0;
		radius += 0.001f;

		t = math::MatrixRotationAxisY(radius);
		math::TransformCoord(eye, t);

		view = math::MatrixLookAtLH(eye, math::Vector3(0, 0, 0), math::Vector3(0, 1, 0));
		proj = math::MatrixPerspectiveFovLH(0.25f * 3.14f, 4.0f / 3.0f, 0.01f, 10000);
		
		MaterialParameterPtr pParam = m_pMaterial->GetParameterByName("v");
		pParam->SetParameterMatrix(view);

		pParam = m_pMaterial->GetParameterByName("p");
		pParam->SetParameterMatrix(proj);

		pParam = m_pMaterial->GetParameterByName("base");
		pParam->SetParameterTexture(m_pTex);

		
	/*	m_pGraphics->SetRenderTarget(m_pRenderTarget);

		m_pGraphics->ClearRenderTarget(0, math::Color4(0, 0, 0.7, 1));
		m_pGraphics->ClearDepthStencil(CLEAR_ALL, 1.0f, 0);

		m_pGraphics->SetShaderProgram(m_pProgram);


		m_pGraphics->DrawIndexed(m_pGeometry, 36, 0, 0);*/



		//param = m_pProgram->FindParameterByName("base");
		//m_pProgram->SetParameterTexture(param, m_pRenderTarget->GetTexture(0));


		m_pGraphics->ClearRenderTarget(0, math::Color4(0.3f, 0.5f, 0.7f, 1));
		m_pGraphics->ClearDepthStencil(CLEAR_ALL, 1.0f, 0);

		int n = m_pMaterial->Begin();
		for(int i = 0; i < n; ++i)
		{
			m_pMaterial->ApplyPass(i);
			m_pGraphics->DrawIndexed(m_pGeometry, 36, 0, 0);
		}
		m_pMaterial->End();

		m_pGraphics->Present();

		ShowFPS();
	}
コード例 #2
0
	void SkyLight::RenderLight(RenderManagerPtr pRenderer)
	{
		if(GetEnabled() == false)
		{
			return;
		}

		const math::Matrix44& view = pRenderer->GetViewMatrix();
		const math::Matrix44& proj = pRenderer->GetProjMatrix();

		pRenderer->SetMatrixBlock(m_pMaterial, math::MatrixIdentity());
		
		const math::Matrix44& tm = GetWorldTM();

		math::Vector3 d = tm.GetRow3(2);

		struct DirLightParam
		{
			math::Vector3 d;
			float i;
			math::Vector3 c;
		};

		DirLightParam l;
		l.d = d;
		l.i = GetIntensity();
		const math::Color4& diffClr = GetDiffuseColor();

		l.c = math::Vector3(diffClr.r, diffClr.g, diffClr.b);

		MaterialParameterPtr pParam = m_pMaterial->GetParameterByName("light");
		pParam->SetParameterBlock(&l, sizeof(DirLightParam));

		pRenderer->SetGBuffer(m_pMaterial);

		if(m_bCastShadow)
		{
			pParam = m_pMaterial->GetParameterByName("shadow_map");
		
			pParam->SetParameterTexture(m_pShadowMap->GetTexture(0));
			pParam = m_pMaterial->GetParameterByName("light_tm");
			pParam->SetParameterMatrix(m_lightTM);
		}

		pRenderer->DrawFullScreenQuad(m_pMaterial);
	}