//final pass  shading object to backsurface
//input GBuffer diffuse map, lighting map
void DeferredDemo::shadingPass(void)
{
    md3dDevice->IASetInputLayout(InputLayout::PosTex);

    m_diffuseVar->SetResource(m_diffusespecRT->GetSRV());
    m_lightingVar->SetResource(m_lightRT->GetSRV());
    ID3D10EffectPass* pass = m_shadingTech->GetPassByIndex(0);
    pass->Apply(0);
    m_finalQuad->draw();
    //debug window
    switch(dm){
    case DI_NORM:
        mfxDrawShadowMapTexVar->SetResource(m_normalRT->GetSRV());
        break;
    case DI_DIFFUSE:
        mfxDrawShadowMapTexVar->SetResource(m_diffusespecRT->GetSRV());
        break;
    case DI_DEPTH:
        mfxDrawShadowMapTexVar->SetResource(m_depthTex.depthMap());
        break;
    case DI_LIGHT:
        mfxDrawShadowMapTexVar->SetResource(m_lightRT->GetSRV());

    }
	pass = mDrawShadowMapTech->GetPassByIndex(0);
	pass->Apply(0);
    m_quad->draw();
}
Exemple #2
0
void Cube::Draw(ID3D10Effect* effects, D3DXMATRIX& view_matrix, D3DXMATRIX& proj_matrix, D3DXVECTOR3& eye_pos)
{
	 // Obtain shader variables
	texture_id_        = effects->GetVariableByName("TextureId")->AsScalar();
 	wvp_matrix_ = effects->GetVariableByName("WVPMatrix")->AsMatrix();

	// Set world view projection matrix
	D3DXMATRIX wvp_matrix = world_matrix_ * view_matrix * proj_matrix;
	wvp_matrix_->SetMatrix((float*)wvp_matrix);

	// Set vertex buffer
	UINT stride = sizeof(Vertex);
	UINT offset = 0;
	d3d_device_->IASetVertexBuffers(0, 1, &vertex_buffer_, &stride, &offset);

	// Set geometry type
	d3d_device_->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

	// Obtain the technique
    ID3D10EffectTechnique* technique = effects->GetTechniqueByName("Render");
	if (technique == NULL)
	{
		MessageBox(NULL, L"Get technique failed", L"Error", 0);
	}

	// Apply each pass in technique and draw triangle.
	D3D10_TECHNIQUE_DESC techDesc;
	technique->GetDesc(&techDesc);
	for (unsigned int i = 0; i < techDesc.Passes; ++i)
	{
		ID3D10EffectPass* pass = technique->GetPassByIndex(i);
		pass->Apply(0);
		
		// Draw cube by draw every face of the cube
		for(int i = 0; i < kNumFaces_; ++i)
		{
			// Set texture id
			texture_id_->SetInt(textureId[i]);

			// Set index buffer
			d3d_device_->IASetIndexBuffer(pIB[i], DXGI_FORMAT_R16_UINT, 0);

			pass->Apply(0);
			
			d3d_device_->DrawIndexed(4, 0, 0);
		}
	}
}
Exemple #3
0
// Render the frame
HRESULT DxWidget::Render()
{
	HRESULT hrResult = E_FAIL;
	HRESULT hrRetCode = E_FAIL;

    float ClearColor[4] = {1.0f, 1.0f, 1.0f, 1.0f};
    m_pd3dDevice->ClearRenderTargetView(m_pRenderTargetView, ClearColor);
    D3D10_TECHNIQUE_DESC techDesc;
    hrRetCode = m_pTechnique->GetDesc(&techDesc);
	KE_COM_PROCESS_ERROR(hrRetCode);
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		ID3D10EffectPass* effectPass = m_pTechnique->GetPassByIndex(p);
		KE_PROCESS_ERROR(effectPass);
        hrRetCode = effectPass->Apply(0);
		KE_COM_PROCESS_ERROR(hrRetCode);

        m_pd3dDevice->Draw(m_nVertexCounter, 0);
    }
    hrRetCode = m_pSwapChain->Present(0, 0);
	KE_COM_PROCESS_ERROR(hrRetCode);

	hrResult = S_OK;
Exit0:
	return hrResult;
}
Exemple #4
0
void Sky::draw()
{
	D3DXVECTOR3 eyePos = GetCamera().position();

	// center Sky about eye in world space
	D3DXMATRIX W;
	D3DXMatrixTranslation(&W, eyePos.x, eyePos.y, eyePos.z);

	D3DXMATRIX V = GetCamera().view();
	D3DXMATRIX P = GetCamera().proj();

	D3DXMATRIX WVP = W*V*P;

	HR(mfxWVPVar->SetMatrix((float*)WVP));
	HR(mfxCubeMapVar->SetResource(mCubeMap));

	UINT stride = sizeof(SkyVertex);
    UINT offset = 0;
    md3dDevice->IASetVertexBuffers(0, 1, &mVB, &stride, &offset);
	md3dDevice->IASetIndexBuffer(mIB, DXGI_FORMAT_R32_UINT, 0);
	md3dDevice->IASetInputLayout(InputLayout::Pos);
	md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	
	D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );

    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex(p);

		pass->Apply(0);
		md3dDevice->DrawIndexed(mNumIndices, 0, 0);
	}
}
Exemple #5
0
void Sky::Render(D3DXMATRIX VP)
{
	gd3dDev->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	gd3dDev->IASetInputLayout(InputLayout::ILPos);

	D3DXMATRIX World;
	//D3DXMatrixTranslation(&World, GetCamera().Pos().x, GetCamera().Pos().y, GetCamera().Pos().z);
	D3DXMatrixIdentity(&World);

	D3DXMATRIX SkyWVP;
	//SkyWVP = World * GetCamera().ViewMatrix()*GetCamera().ProjMatrix();
	SkyWVP = World * VP;

	HR(mfxSkyWVP->SetMatrix((float*)&SkyWVP));
	HR(mfxCubeTex->SetResource(mCubeTexSRV));
	
	D3D10_TECHNIQUE_DESC TechDesc;
	HR(mfxSkyTech->GetDesc(&TechDesc));

	for(UINT i = 0; i < TechDesc.Passes; i++)
	{
		ID3D10EffectPass* Pass = mfxSkyTech->GetPassByIndex(i);

		HR(Pass->Apply(0));
		HR(mSphere->DrawSubset(0));
	}
}
Exemple #6
0
void CubeMapApp::drawScene()
{
	D3DApp::drawScene();
	
	
	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);
	
	md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dDevice->IASetInputLayout(InputLayout::PosNormalTex);

	// Set per frame constants.
	mfxEyePosVar->SetRawValue(&GetCamera().position(), 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mParallelLight, 0, sizeof(Light));
	
	mfxCubeMapVar->SetResource(mEnvMapRV);
	

	D3DXMATRIX view = GetCamera().view();
	D3DXMATRIX proj = GetCamera().proj();

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );

    for(UINT i = 0; i < techDesc.Passes; ++i)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex(i);

		//
		// draw center ball
		//
		D3DXMATRIX centerBallWVP = mCenterBallWorld*view*proj;
		mfxWVPVar->SetMatrix((float*)&centerBallWVP);
		mfxWorldVar->SetMatrix((float*)&mCenterBallWorld);
		mfxTexMtxVar->SetMatrix((float*)&mIdentityTexMtx);
		mfxDiffuseMapVar->SetResource(mBallMapRV);
		mfxSpecMapVar->SetResource(mDefaultSpecMapRV);
		mfxCubeMapEnabledVar->SetBool(true);
		mfxReflectMtrlVar->SetFloatVector((float*)&mReflectAll);
		pass->Apply(0);
		mBall.draw();		
    }

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	md3dDevice->RSSetState(0);
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, WHITE);

	mSwapChain->Present(0, 0);
}
void Terrain::draw(const D3DXMATRIX& world)
{
	md3dDevice->IASetInputLayout(InputLayout::PosNormalTex);

	UINT stride = sizeof(TerrainVertex);
    UINT offset = 0;
    md3dDevice->IASetVertexBuffers(0, 1, &mVB, &stride, &offset);
	md3dDevice->IASetIndexBuffer(mIB, DXGI_FORMAT_R32_UINT, 0);

	D3DXMATRIX view = GetCamera().view();
	D3DXMATRIX proj = GetCamera().proj();

	D3DXMATRIX WVP = world*view*proj;


	mfxWVPVar->SetMatrix((float*)&WVP);
	mfxWorldVar->SetMatrix((float*)&world);

	mfxLayer0Var->SetResource(mLayer0);
	mfxLayer1Var->SetResource(mLayer1);
	mfxLayer2Var->SetResource(mLayer2);
	mfxLayer3Var->SetResource(mLayer3);
	mfxLayer4Var->SetResource(mLayer4);
	mfxBlendMapVar->SetResource(mBlendMap);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );

    for(UINT i = 0; i < techDesc.Passes; ++i)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex(i);
		pass->Apply(0);

		md3dDevice->DrawIndexed(mNumFaces*3, 0, 0);
	}	
}
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();

	//Step through animation frame
	animationTimeElapsed += mTimer.getGameTime() - animationTimePrev;
	animationTimePrev = mTimer.getGameTime();
	if(animationTimeElapsed > 0.0666f)
	{
		animationTimeElapsed = 0.0f;
		frameOfAnimation++;
		if(frameOfAnimation > fireFrameCount-1)
		{
			frameOfAnimation = 0;
		}
	}

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Set per frame constants
	mfxEyePosVar->SetRawValue(&mCameraPos, 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mLights[0], 0, sizeof(Light));
	mfxLightVar2->SetRawValue(&mLights[1], 0, sizeof(Light));

	mfxCubeMapVR->SetResource(mCubeMapRV);
   
	// set constants
	mWVP = mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP); //set gWVP in color.fx to mWVP

	mTree.setEyePos(mCameraPos);
	mTree.setLights(mLights, 2);
	mTree.draw(mView, mProj);
	mObjBox.setEyePos(mCameraPos);
	mObjBox.setLights(mLights, 2);
	mObjBox.draw(mView, mProj);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex( p ); //zero is always used in D3D10
		D3DXMATRIX texMtx;
        
		mWVP = mBoxWorld*mView*mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&mBoxWorld);
		mfxDiffuseMapVar->SetResource(mCrateMapRV);
		//mfxDiffuseMapVar->SetResource(mFireAnimationMapRVs[frameOfAnimation]);
		mfxSpecularMapVar->SetResource(mSpecularMapRV);
		mfxNormalMapVR->SetResource(mDefaultNormalMapRV);
		mfxReflectEnabledVar->SetBool(false);
		D3DXMatrixIdentity(&texMtx);
		mfxTexMtxVar->SetMatrix((float*)&texMtx);
		pass->Apply(0);
		mBox.draw();

		mWVP = mPlaneWorld*mView*mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&mPlaneWorld);
		mfxDiffuseMapVar->SetResource(mGrassMapRV);
		mfxNormalMapVR->SetResource(mBrickNormalMapRV);
		mfxReflectEnabledVar->SetBool(true);
		D3DXMATRIX s;
		D3DXMatrixScaling(&s, 5.0f, 5.0f, 1.0f);
		texMtx = s;
		D3DXMatrixIdentity(&texMtx);
		mfxTexMtxVar->SetMatrix((float*)&texMtx);
		pass->Apply(0);
		mPlane.draw();
    }

	mSky.draw(mWVP);

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	md3dDevice->RSSetState(0);
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);

	mSwapChain->Present(0, 0);
}
//lighting pass renderring lighting information to lighting texture
//input GBuffer normal map
void DeferredDemo::lightingPass(void)
{
    //per light source
    //this->resetOMTargetsAndViewport();
    ID3D10RenderTargetView * rt = m_lightRT->GetRTV();
    this->bindRenderTargets(1, &rt, NULL);
    this->bindViewport(m_lightRT->GetViewPort());
    	
    D3DXMATRIX view = GetCamera().view();
    D3DXMATRIX proj = GetCamera().proj();

    m_pointLightVar->SetRawValue(&m_pointLight,0, sizeof(m_pointLight));

    m_depthVar->SetResource(m_depthTex.depthMap());
    m_gbufferVar->SetResource(m_normalRT->GetSRV());

    D3DXMATRIX mtx;
    D3DXMatrixTranslation(&mtx,m_pointLight.pos.x, m_pointLight.pos.y, m_pointLight.pos.z);

    D3DXMATRIX mvp = (mtx*view*proj);
    m_pointLightWVPVar->SetMatrix((float*)&mvp);
    D3DXVECTOR4 lightposview;
    ::D3DXVec3Transform(&lightposview, &m_pointLight.pos, &(view)); 
    D3DXVECTOR3 l ;
    l.x = lightposview.x;
    l.y = lightposview.y; 
    l.z = lightposview.z;

    m_lightPosVVar->SetRawValue(&l,0, sizeof(D3DXVECTOR4));
  
    m_pointLightWVVar->SetMatrix((float*)&(mtx*view));

    D3D10_TECHNIQUE_DESC techDesc;

    m_pointLightTech->GetDesc( &techDesc );

    for(uint32_t i = 0 ; i < techDesc.Passes; ++i)
    {
        ID3D10EffectPass * pass = m_pointLightTech->GetPassByIndex(i);
        

        pass->Apply(0);
        m_pointLightMesh->Draw();

    }


    for(int i = 0 ;  i < 5; ++i)
    {
        D3DXMATRIX mtx;
        D3DXMatrixTranslation(&mtx,m_pointLights[i].pos.x, m_pointLights[i].pos.y, m_pointLights[i].pos.z);

        m_pointLightVar->SetRawValue(&m_pointLights[i], 0 ,sizeof(m_pointLights[i]));
        D3DXMATRIX mvp = (mtx*view*proj);
        m_pointLightWVPVar->SetMatrix((float*)&mvp);
        D3DXVECTOR4 lightposview;
        ::D3DXVec3Transform(&lightposview, &m_pointLights[i].pos, &(view)); 
        D3DXVECTOR3 l ;
        l.x = lightposview.x;
        l.y = lightposview.y; 
        l.z = lightposview.z;
    
        m_lightPosVVar->SetRawValue(&l,0, sizeof(D3DXVECTOR4));
      
        m_pointLightWVVar->SetMatrix((float*)&(mtx*view));

        ID3D10EffectPass * pass = m_pointLightTech->GetPassByIndex(0);
        

        pass->Apply(0);
        m_pointLightMesh->Draw();
    }
    //m_pointLightWVPVar->SetMatrix
    m_pointLightVar->SetRawValue(&mParallelLight,0, sizeof(Light));
    D3DXVECTOR4 l_dir_es;
    D3DXVECTOR4 l_dir_ws;
    l_dir_ws.x = mParallelLight.dir.x;
    l_dir_ws.y = mParallelLight.dir.y;
    l_dir_ws.z = mParallelLight.dir.z;
    l_dir_ws.w = 0;
    
    ::D3DXVec4Transform(&l_dir_es, &l_dir_ws, &view);
    m_lightDirVar->SetRawValue(&l_dir_es, 0, sizeof(D3DXVECTOR3));
    m_parallelLightTech->GetDesc( &techDesc);
    for(uint32_t i = 0; i < techDesc.Passes; ++i)
    {
        ID3D10EffectPass * pass = m_parallelLightTech->GetPassByIndex(i);
        pass->Apply(0);
        m_pointLightMesh->Draw();
    }

    md3dDevice->RSSetState(m_solidMode);
    float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);

    //draw light source mesh
    m_lightSourceTech->GetDesc(&techDesc);
    D3DXMATRIX scale;
    ::D3DXMatrixScaling(&scale,0.001f,0.001f,0.001f);
    m_pointLightWVPVar->SetMatrix((float*)&(scale * mvp));
    ID3D10EffectPass * pass = m_lightSourceTech->GetPassByIndex(0);
    pass->Apply(0);
    m_pointLightMesh->Draw();

    for(int i = 0 ; i < 5; ++i)
    {
        D3DXMATRIX scale;
        ::D3DXMatrixScaling(&scale,0.001f,0.001f,0.001f);
        D3DXMATRIX mtx;
        D3DXMatrixTranslation(&mtx,m_pointLights[i].pos.x, m_pointLights[i].pos.y, m_pointLights[i].pos.z);

        m_pointLightVar->SetRawValue(&m_pointLights[i], 0 ,sizeof(Light));
        D3DXMATRIX mvp = (mtx*view*proj);
        m_pointLightWVPVar->SetMatrix((float*)&(scale * mvp));
        ID3D10EffectPass * pass = m_lightSourceTech->GetPassByIndex(0);
        pass->Apply(0);
        m_pointLightMesh->Draw();
    }
}
void DeferredDemo::genGBufferPass(void)
{       	
    md3dDevice->IASetInputLayout(InputLayout::PosTangentNormalTex);

	// Set per frame constants.
 
	D3DXMATRIX view = GetCamera().view();
    D3DXMATRIX proj = GetCamera().proj();
    D3D10_TECHNIQUE_DESC techDesc;
    m_genGBufferTech->GetDesc( &techDesc );
    m_CameraProjVar->SetMatrix((float*)&proj);
    m_CameraViewVar->SetMatrix((float*)&view);
    m_CubeMapVar->SetResource(mEnvMapRV);
    m_EyePosVar->SetRawValue(&GetCamera().position(), 0, sizeof(D3DXVECTOR3));

    for(UINT i = 0; i < techDesc.Passes; ++i)
    {
        ID3D10EffectPass* pass = m_genGBufferTech->GetPassByIndex(i);

        
		//
		// draw floor
		//
        m_ObjectModelVar->SetMatrix((float*)&mFloorWorld);
        m_TexMtx->SetMatrix((float*)&mFloorTexMtx);
        m_DiffuseMapVar ->SetResource(mFloorMapRV);
        m_SpecMapVar->SetResource(mSpecMapRV);
        m_NormalMapVar->SetResource(mFloorNormalMapRV);
        m_CubeMapEnabledVar->SetBool(false);
        m_Shininese ->SetFloat(1.0f);
		pass->Apply(0);
		mFloor.draw();
		//
		// draw base
		//
		
        m_ObjectModelVar->SetMatrix((float*)&mBaseWorld);
        m_TexMtx->SetMatrix((float*)&mIdentityTexMtx);
        m_DiffuseMapVar->SetResource(mBaseMapRV);
        m_SpecMapVar->SetResource(mSpecMapRV);
        m_NormalMapVar->SetResource(mBaseNormalMapRV);
        m_CubeMapEnabledVar->SetBool(false);
        m_Shininese->SetFloat(1.0f);
		pass->Apply(0);
		mBase.draw();

		//
		// draw center ball
		//
        m_ObjectModelVar->SetMatrix((float*)&mCenterBallWorld);
        m_TexMtx->SetMatrix((float*)&mIdentityTexMtx);
        m_DiffuseMapVar->SetResource(mBallMapRV);
        m_NormalMapVar->SetResource(mDefaultNormalMapRV);
        m_SpecMapVar->SetResource(mDefaultSpecMapRV);
        m_CubeMapEnabledVar->SetBool(true);
        m_Shininese->SetFloat(1.0f);
		pass->Apply(0);
		mBall.draw();

		//
		// draw columns
		//
        m_TexMtx->SetMatrix((float*)&mIdentityTexMtx);
        m_DiffuseMapVar->SetResource(mColumnMapRV);
        m_SpecMapVar->SetResource(mDefaultSpecMapRV);
        m_CubeMapEnabledVar->SetBool(false);
        m_NormalMapVar->SetResource(mColumnNormalMapRV);
        m_Shininese->SetFloat(1.0f);
		for(int i = 0; i < 10; ++i)
		{
			//m_CameraWVVar->SetMatrix((float*)&(mColumnWorld[i]*view));
            m_ObjectModelVar->SetMatrix((float*)&mColumnWorld[i]);
	    	
			pass->Apply(0);
			mColumn.draw();
		}	
		//
		// draw balls
		//
        m_TexMtx->SetMatrix((float*)&mIdentityTexMtx);
        m_DiffuseMapVar->SetResource(mBallMapRV);
        m_SpecMapVar->SetResource(mDefaultSpecMapRV);
        m_CubeMapEnabledVar->SetBool(true);
        m_NormalMapVar->SetResource(mDefaultNormalMapRV);
        m_Shininese->SetFloat(1.0f);
		for(int i = 0; i < 10; ++i)
		{
			//m_CameraWVVar->SetMatrix((float*)&(mBallWorld[i]*view));
            m_ObjectModelVar->SetMatrix((float*)&mBallWorld[i]);
            m_TexMtx->SetMatrix((float*)&mIdentityTexMtx);
			
			pass->Apply(0);
			mBall.draw();
		}

    }
}
void Scene::DrawScene()
{
	MyD3D10Code::Direct3D10Class::DrawScene();

	// Restore Default states, input layout and primitive topology 
	// as m_Font->DrawText changes them. Note that we can restore
	// the default states by passing null
	m_Direct3DDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	m_Direct3DDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
	m_Direct3DDevice->IASetInputLayout(m_VertexLayout);									// Bind input layout to the device
	m_Direct3DDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);	// Set primitive topology to triangle list

	D3DXMATRIX view = GetCamera().view();
	D3DXMATRIX proj = GetCamera().proj();

	/////////////////////////
	// Set constants 
	/////////////////////////
	m_fxDiffuseMapVar->SetResource(m_DiffuseMapRV);

	m_FxSpecMapVar->SetResource(m_SpecMapRV);
	m_FxEyePosVar->SetRawValue(&GetCamera().position(), 0, sizeof(D3DXVECTOR3) );
	m_FxLightVar->SetRawValue(&m_ParallelLight, 0, sizeof(Light) );
	
	D3DXMATRIX texMat;
	D3DXMatrixIdentity(&texMat);
	m_FxTexMatVar->SetMatrix((float*)&texMat);
	
	///////////////////////////
	// End constants 
	///////////////////////////

	D3D10_TECHNIQUE_DESC techDescription;
	m_Tech->GetDesc( &techDescription );

	for( UINT p = 0; p < techDescription.Passes; ++p)
	{
		//m_Tech->GetPassByIndex( p )->Apply(0);
		ID3D10EffectPass* pass = m_Tech->GetPassByIndex(p);
		
		m_fxDiffuseMapVar->SetResource(m_DiffuseMapRV);
		m_WorldViewProjection = m_Box.ReturnWorldMatrix()*view*proj;
		m_fxWVPVar->SetMatrix( (float*)&m_WorldViewProjection );		// Updates WVP matrix in the internal cache of the effect object
		m_FxBoxWorldVar->SetMatrix((float*)&m_Box.ReturnWorldMatrix() );
		pass->Apply(0);
		m_Box.Draw(m_Direct3DDevice);

		m_fxDiffuseMapVar->SetResource(m_RoofTilesRV);						// Load tile texture
		m_WorldViewProjection = m_Box.ReturnWorldMatrix()*view*proj;		// Using the boxes world on pupose as we want the roof to move at the same time as the box
		m_fxWVPVar->SetMatrix( (float*)&m_WorldViewProjection );			// Updates WVP matrix in the internal cache of the effect object 
		m_FxBoxWorldVar->SetMatrix((float*)&m_Box.ReturnWorldMatrix() );	// Using the boxes world on pupose as we want the roof to move at the same time as the box
		pass->Apply(0);
		m_Roof.Draw(m_Direct3DDevice);

		m_fxDiffuseMapVar->SetResource(m_GrassRV);	
		m_WorldViewProjection = m_Floor.ReturnWorldMatrix()*view*proj;	
		m_fxWVPVar->SetMatrix( (float*)&m_WorldViewProjection );			// Updates WVP matrix in the internal cache of the effect object 
		m_FxBoxWorldVar->SetMatrix((float*)&m_Floor.ReturnWorldMatrix() );	
		pass->Apply(0);
		m_Floor.Draw(m_Direct3DDevice);
	}

	m_Sky.draw();	// Draw the sky
	
	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	m_Direct3DDevice->RSSetState(0);										// Set the rasterization state to the default state
	m_Font->DrawText(0, m_FrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);

	// Took this out and put it in Coloured cube DrawScene
	m_SwapChain->Present(0, 0);
}
void WaterLandscapeDemoScene::OnRender(DXRenderer& dx, TimeT currentTime, TimeT deltaTime) const
{
    // Set the device up for rendering our landscape mesh.
    dx.GetDevice()->IASetInputLayout(mVertexLayout.Get());
    dx.GetDevice()->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    D3DXMATRIX projectionMatrix = mCamera->GetProjectionMatrix();
    
    // Load the landscape technique.
    ID3D10EffectTechnique * pTechnique = mLandscapeEffect->GetTechniqueByName("LandscapeTechnique");

    // Grab the shader variables we'll need.
    ID3D10EffectMatrixVariable * pWVP = mLandscapeEffect->GetVariableByName("gWVP")->AsMatrix();
    ID3D10EffectMatrixVariable * pWorldVar = mLandscapeEffect->GetVariableByName("gWorld")->AsMatrix();
    ID3D10EffectVariable * pFxEyePosVar = mLandscapeEffect->GetVariableByName("gEyePosW");
    ID3D10EffectVariable * pFxLightVar = mLandscapeEffect->GetVariableByName("gLight");
    ID3D10EffectScalarVariable * pFxLightType = mLandscapeEffect->GetVariableByName("gLightType")->AsScalar();

    // Set per frame constants
    D3DXVECTOR3 eyePos = mCamera->Position();
    D3DMATRIX view = mCamera->GetViewMatrix();
    Light selectedLight = mLights[mLightType];

    pFxEyePosVar->SetRawValue(&eyePos, 0, sizeof(D3DXVECTOR3));
    pFxLightVar->SetRawValue(&selectedLight, 0, sizeof(Light));
    pFxLightType->SetInt(mLightType);

    // Load the effect technique for cube
    D3D10_TECHNIQUE_DESC technique;
    pTechnique->GetDesc(&technique);

    // Apply the landscape technique.
    D3DXMATRIX landTransform;
    D3DXMATRIX waterTransform;

    D3DXMatrixIdentity(&landTransform);
    D3DXMatrixIdentity(&waterTransform);

    for (unsigned int passIndex = 0; passIndex < technique.Passes; ++passIndex)
    {
        ID3D10EffectPass * pPass = pTechnique->GetPassByIndex(passIndex);
        dx.SetDefaultRendering();

        // Draw the landscape mesh first
        D3DXMATRIX wvp = landTransform * view * projectionMatrix;

        pWVP->SetMatrix((float*)&wvp);
        pWorldVar->SetMatrix((float*)&landTransform);

        pPass->Apply(0);
        mTerrainMesh->Draw(dx.GetDevice());

        // Draw the water mesh
        wvp = waterTransform * view * projectionMatrix;

        pWVP->SetMatrix((float*)&wvp);
        pWorldVar->SetMatrix((float*)&waterTransform);

        pPass->Apply(0);
        mWaterMesh->Draw(dx.GetDevice());
    }
}