void RenderManager::Render() { char buf[50]; _itoa_s(fps, buf, 10); sText = std::string("FPS: ") + buf; std::string hair = "+"; // Convert the pos to a w string std::string xs,ys,zs; std::stringstream posx,posy,posz; posx << mCam->GetPosition().x; xs = posx.str(); posy << mCam->GetPosition().y; ys = posy.str(); posz << mCam->GetPosition().z; zs = posz.str(); std::string pos = xs + ", " + ys + ", " + zs; // Calculate the text width. int textWidth = 0; for(UINT i = 0; i < sText.length(); ++i) { WCHAR character = sText[i]; if(character == ' ') { textWidth += mFont.GetSpaceWidth(); } else{ const CD3D11_RECT& r = mFont.GetCharRect(sText[i]); textWidth += (r.right - r.left + 1); } } // Calculate the hair width. int hairWidth = 0; for(UINT i = 0; i < hair.size(); ++i) { WCHAR character = hair[i]; if(character == ' ') { hairWidth += mFont.GetSpaceWidth(); } else{ const CD3D11_RECT& r = mFont.GetCharRect(hair[i]); hairWidth += (r.right - r.left); } } // Calculate the pos width int posWidth = 0; for(UINT i = 0; i < pos.size(); ++i) { WCHAR character = pos[i]; if(character == ' ') { hairWidth += mFont.GetSpaceWidth(); } else{ const CD3D11_RECT& r = mFont.GetCharRect(pos[i]); posWidth += (r.right - r.left + 1); } } //COSMIC BOOOWLAN if((mCurrentScene == CurrentScene::BOWLING) && (cosmicFactor % 41 == 0) && PartyMode == 1) { int colorNum; for(int i = 0; i < 21; i++) { srand(cosmicFactor++); colorNum = rand() % 5; if(colorNum == 0) scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::Red; if(colorNum == 1) scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::Blue; if(colorNum == 2) scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::Green; if(colorNum == 3) scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::Cyan; if(colorNum == 4) scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::Magenta; scene[mCurrentScene]->mPointLights[i].Ambient = Colors::Black; scene[mCurrentScene]->mPointLights[i].Range = 30.0f; } } else if((mCurrentScene == CurrentScene::BOWLING) && (PartyMode == 0)) { for(int i = 0; i < 21; i++) { scene[mCurrentScene]->mPointLights[i].Diffuse = Colors::NormalDiffuse; scene[mCurrentScene]->mPointLights[i].Ambient = Colors::NormalAmbient; scene[mCurrentScene]->mPointLights[i].Range = 40.0f; } PartyMode = -1; } cosmicFactor++; textPos.x = (LONG)((SCREEN_WIDTH - textWidth) - 2.0f); textPos.y = 0;//SCREEN_HEIGHT; hairPos.x = (LONG)((SCREEN_WIDTH - hairWidth) / 2.0f); hairPos.y = (LONG)((SCREEN_HEIGHT - mFont.GetCharHeight()) / 2.0f) ; posPos.x = (LONG)2.0f; posPos.y = (LONG)1.0f; // clear the back buffer to a deep blue mDevcon->ClearDepthStencilView(mZbuffer, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); mDevcon->ClearRenderTargetView(mBackbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f)); mDevcon->ClearRenderTargetView(mScreen->mTargetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f)); for( int j = 0; j < scene.size(); j++ ) for( int i = 0; i < shadows[j].size(); i++ ) mDevcon->ClearDepthStencilView(shadows[j][i]->pShadowMapDepthView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); //mDevcon->RSSetState(0); XMStoreFloat4x4(&sceneBuff.viewProj, mCam->ViewProj()); sceneBuff.camPos = mCam->GetPosition(); //sceneBuff.pad = 1.0f; mDevcon->VSSetConstantBuffers(0, 1, &sceneCBuffer); mDevcon->PSSetConstantBuffers(0, 1, &sceneCBuffer); mDevcon->UpdateSubresource(sceneCBuffer, 0, 0, &sceneBuff , 0, 0); if(mCurrentScene != CurrentScene::DARKNESS && mCurrentScene != CurrentScene::BOWLING) { //Skybox right now doesn't like zbuffers, so dont' set one for it mDevcon->OMSetRenderTargets(1, &mScreen->mTargetView, 0); mSkyBox->Render(sceneCBuffer, mCam, 0); } if(mCurrentScene == CurrentScene::DARKNESS) { scene[mCurrentScene]->mPointLights[0].Position = mCam->GetPosition(); for(int i = 0; i < 2; i++) { scene[mCurrentScene]->mPointLights[i].Range = Randomf(20.0f, 21.0f); } } mDevcon->OMSetRenderTargets(1, &mScreen->mTargetView/*mBackbuffer*/, mZbuffer); mDevcon->PSSetConstantBuffers(2, 1, &dirLightCBuffer); mDevcon->UpdateSubresource(dirLightCBuffer, 0, 0, &mDirLight, 0, 0); mDevcon->PSSetConstantBuffers(3, 1, &pointLightCBuffer); mDevcon->UpdateSubresource(pointLightCBuffer, 0, 0, &scene[mCurrentScene]->mPointLights, 0, 0); //raster.CullMode = D3D11_CULL_FRONT; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //mDevcon->RSSetState( pState ); // START SHADOW MAP RenderToShadow(); mDevcon->OMSetRenderTargets(1, &mScreen->mTargetView/*mBackbuffer*/, mZbuffer); // MUST PASS IN THE SHADER RESOURCE VIEW AFTER YOU SWITCH TEH RENDER TARGET OTHERWISE ITS NULL SetShadowSRV( 6 ); //*********************** XMStoreFloat4x4(&sceneBuff.viewProj, mCam->ViewProj()); sceneBuff.camPos = mCam->GetPosition(); mDevcon->VSSetConstantBuffers(0, 1, &sceneCBuffer); mDevcon->UpdateSubresource(sceneCBuffer, 0, 0, &sceneBuff , 0, 0); //*********************** // END SHADOW MAP mDevcon->RSSetViewports(1, mViewport); Render(0); //Render the screen quad last mDevcon->OMSetRenderTargets(1, &mBackbuffer, 0); mDevcon->PSSetShaderResources(1, 1, &mDepthShaderResourceView); SetShadowSRV( 6 ); //mDevcon->PSSetShaderResources(6, 1, &pShadowMapSRView); mDevcon->UpdateSubresource(sceneCBuffer, 0, 0, mScreenCam->ViewProj().m , 0, 0); mScreen->Render(sceneCBuffer, mScreenCam, 0); //mText.DrawString(mDevcon, mFont, sText, textPos, XMCOLOR(0xffffffff)); mText.DrawString(mDevcon, mFont, hair, hairPos, XMCOLOR(0xffffffff)); mText.DrawString(mDevcon, mFont, pos, posPos, XMCOLOR(0xffffffff)); //if(!((mCam->GetPosition().x > 6.0f || mCam->GetPosition().x < -44.0) || // (mCam->GetPosition().y > 70.0f || mCam->GetPosition().y < 20.0) || // (mCam->GetPosition().z > 231.0f || mCam->GetPosition().z < 181.0)) ){ //mSphere->IsItReflective(true); /*} else{ mSphere->IsItReflective(false); }*/ }
void Light::SetColor(FLOAT r, FLOAT g, FLOAT b, FLOAT a) { SetColor(XMCOLOR(r, g, b, a)); }
void RenderManager::Render() { char buf[50]; itoa(fps, buf, 10); sText = std::string("FPS: ") + buf; std::string hair = "+"; // Convert the pos to a w string std::string xs,ys,zs; std::stringstream posx,posy,posz; posx << mCam->GetPosition().x; xs = posx.str(); posy << mCam->GetPosition().y; ys = posy.str(); posz << mCam->GetPosition().z; zs = posz.str(); std::string pos = xs + ", " + ys + ", " + zs; // Calculate the text width. int textWidth = 0; for(UINT i = 0; i < sText.length(); ++i) { WCHAR character = sText[i]; if(character == ' ') { textWidth += mFont.GetSpaceWidth(); } else{ const CD3D11_RECT& r = mFont.GetCharRect(sText[i]); textWidth += (r.right - r.left + 1); } } // Calculate the hair width. int hairWidth = 0; for(UINT i = 0; i < hair.size(); ++i) { WCHAR character = hair[i]; if(character == ' ') { hairWidth += mFont.GetSpaceWidth(); } else{ const CD3D11_RECT& r = mFont.GetCharRect(hair[i]); hairWidth += (r.right - r.left); } } // Calculate the pos width int posWidth = 0; for(UINT i = 0; i < pos.size(); ++i) { WCHAR character = pos[i]; if(character == ' ') { hairWidth += mFont.GetSpaceWidth(); } else{ const CD3D11_RECT& r = mFont.GetCharRect(pos[i]); posWidth += (r.right - r.left + 1); } } textPos.x = (SCREEN_WIDTH - textWidth) - 2.0; textPos.y = 0;//SCREEN_HEIGHT; hairPos.x = (SCREEN_WIDTH - hairWidth) / 2; hairPos.y = (SCREEN_HEIGHT - mFont.GetCharHeight()) / 2 ; posPos.x = 2.0; posPos.y = 1.0; // clear the back buffer to a deep blue mDevcon->ClearDepthStencilView(mZbuffer, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); mDevcon->ClearRenderTargetView(mBackbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f)); mDevcon->ClearRenderTargetView(mScreen->mTargetView, D3DXCOLOR(0.0f, 1.0f, 0.4f, 1.0f)); mDevcon->ClearDepthStencilView(pShadowMapDepthView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); //mDevcon->RSSetState(0); XMStoreFloat4x4(&sceneBuff.viewProj, mCam->ViewProj()); sceneBuff.camPos = mCam->GetPosition(); //sceneBuff.pad = 1.0f; mDevcon->VSSetConstantBuffers(0, 1, &sceneCBuffer); mDevcon->PSSetConstantBuffers(0, 1, &sceneCBuffer); mDevcon->UpdateSubresource(sceneCBuffer, 0, 0, &sceneBuff , 0, 0); //Skybox right now doesn't like zbuffers, so dont' set one for it mDevcon->OMSetRenderTargets(1, &mScreen->mTargetView, 0); mSkyBox->Render(sceneCBuffer, mCam, 0); mDevcon->OMSetRenderTargets(1, &mScreen->mTargetView/*mBackbuffer*/, mZbuffer); mDevcon->PSSetConstantBuffers(2, 1, &dirLightCBuffer); mDevcon->UpdateSubresource(dirLightCBuffer, 0, 0, &mDirLight, 0, 0); mDevcon->PSSetConstantBuffers(3, 1, &pointLightCBuffer); mDevcon->UpdateSubresource(pointLightCBuffer, 0, 0, &mPointLight, 0, 0); // START SHADOW MAP mDevcon->RSSetViewports(1, &mShadowPort); mShadowCam->SetLensOrtho( -350.0, 350.0, -350.0, 350.0, 1.0, 1000); float distanceMult = 550.0f; XMFLOAT3 ShadPos = XMFLOAT3( (-mDirLight[0].Direction.x * distanceMult) + mCam->GetPosition().x, (-mDirLight[0].Direction.y * distanceMult) + mCam->GetPosition().y, (-mDirLight[0].Direction.z * distanceMult) + mCam->GetPosition().z ); mShadowCam->SetPosition(ShadPos); mShadowCam->LookAt( ShadPos, mCam->GetPosition(), XMFLOAT3(0,1,0)); mShadowCam->UpdateViewMatrix(); sceneBuff.camPos = mShadowCam->GetPosition(); XMStoreFloat4x4(&sceneBuff.viewProj, mShadowCam->ViewProj()); mDevcon->VSSetConstantBuffers(0, 1, &sceneCBuffer); mDevcon->UpdateSubresource(sceneCBuffer, 0, 0, &sceneBuff , 0, 0); shadowBuff.lightPos = mShadowCam->GetPosition(); XMStoreFloat4x4( &shadowBuff.lightViewProj, XMMatrixMultiply(mShadowCam->View(), mShadowCam->Proj()) ); //XMStoreFloat4x4( &shadowBuff.lightViewProj, XMMatrixMultiply(mShadowCam->View(), mCam->Proj()) ); shadowBuff.PADdyCake = .5; mDevcon->PSSetConstantBuffers(5, 1, &shadowCBuffer); mDevcon->VSSetConstantBuffers(5, 1, &shadowCBuffer); mDevcon->UpdateSubresource(shadowCBuffer, 0, 0, &shadowBuff , 0, 0); //********************* mDevcon->OMSetRenderTargets(0, 0, pShadowMapDepthView); //obj->Depth(sceneCBuffer, mCam, depth); for(int i = 0; i < scene[mCurrentScene]->mRenderables.size() ; i++) { scene[mCurrentScene]->mRenderables[i]->Depth(); } mDevcon->OMSetRenderTargets(1, &mScreen->mTargetView/*mBackbuffer*/, mZbuffer); // MUST PASS IN THE SHADER RESOURCE VIEW AFTER YOU SWITCH TEH RENDER TARGET OTHERWISE ITS NULL mDevcon->PSSetShaderResources(6, 1, &pShadowMapSRView); //*********************** XMStoreFloat4x4(&sceneBuff.viewProj, mCam->ViewProj()); sceneBuff.camPos = mCam->GetPosition(); mDevcon->VSSetConstantBuffers(0, 1, &sceneCBuffer); mDevcon->UpdateSubresource(sceneCBuffer, 0, 0, &sceneBuff , 0, 0); //*********************** // END SHADOW MAP mDevcon->RSSetViewports(1, mViewport); Render(0); //Render the screen quad last mDevcon->OMSetRenderTargets(1, &mBackbuffer, 0); mDevcon->PSSetShaderResources(1, 1, &mDepthShaderResourceView); mDevcon->PSSetShaderResources(6, 1, &pShadowMapSRView); mDevcon->UpdateSubresource(sceneCBuffer, 0, 0, mScreenCam->ViewProj().m , 0, 0); mScreen->Render(sceneCBuffer, mScreenCam, 0); mText.DrawString(mDevcon, mFont, sText, textPos, XMCOLOR(0xffffffff)); mText.DrawString(mDevcon, mFont, hair, hairPos, XMCOLOR(0xffffffff)); mText.DrawString(mDevcon, mFont, pos, posPos, XMCOLOR(0xffffffff)); //if(!((mCam->GetPosition().x > 6.0f || mCam->GetPosition().x < -44.0) || // (mCam->GetPosition().y > 70.0f || mCam->GetPosition().y < 20.0) || // (mCam->GetPosition().z > 231.0f || mCam->GetPosition().z < 181.0)) ){ //mSphere->IsItReflective(true); /*} else{ mSphere->IsItReflective(false); }*/ }