void MySample::Render(double deltaSeconds) { CPUTRenderParameters renderParams; if(isInstanced) SetEffectVals( 0 ); else SetEffectVals( 1 ); renderParams.mpPerFrameConstants = mpPerFrameConstantBuffer; renderParams.mpPerModelConstants = mpPerModelConstantBuffer; renderParams.mpCamera = mpCamera; UpdatePerFrameConstantBuffer(renderParams, deltaSeconds); int width,height; mpWindow->GetClientDimensions(&width, &height); // Set default viewport glViewport( 0, 0, width, height ); GL_CHECK(glClearColor ( 0.7f, 0.7f, 0.7f, 1.0f )); GL_CHECK(glClearDepthf(0.0f)); GL_CHECK(glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )); mpScene->Render( renderParams); #ifdef ENABLE_GUI CPUTDrawGUI(); #endif }
//----------------------------------------------------------------------------- void MySample::Render(double deltaSeconds) { CPUTRenderParameters renderParams; const int DEFAULT_MATERIAL = 0; const int SHADOW_MATERIAL = 1; renderParams.mpShadowCamera = NULL; renderParams.mpCamera = mpShadowCamera; renderParams.mpPerFrameConstants = (CPUTBuffer*)mpPerFrameConstantBuffer; renderParams.mpPerModelConstants = (CPUTBuffer*)mpPerModelConstantBuffer; //Animation renderParams.mpSkinningData = (CPUTBuffer*)mpSkinningDataConstantBuffer; int windowWidth, windowHeight; mpWindow->GetClientDimensions( &windowWidth, &windowHeight); renderParams.mWidth = windowWidth; renderParams.mHeight = windowHeight; renderParams.mRenderOnlyVisibleModels = false; //******************************* // Draw the shadow scene //******************************* UpdatePerFrameConstantBuffer(renderParams, deltaSeconds); renderParams.mWidth = windowWidth; renderParams.mHeight = windowHeight; renderParams.mpCamera = mpCamera; renderParams.mpShadowCamera = mpShadowCamera; UpdatePerFrameConstantBuffer(renderParams, deltaSeconds); // Clear back buffer const float clearColor[] = { 0.0993f, 0.0993f, 0.0993f, 1.0f }; mpContext->ClearRenderTargetView( mpBackBufferRTV, clearColor ); mpContext->ClearDepthStencilView( mpDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0); if(mpCameraController->GetCamera() == mpShadowCamera) { mpDebugSprite->DrawSprite(renderParams); } MenuController_Render(renderParams); CPUTDrawGUI(); ImGui::Render(); }
//#include "xnamath.h" //static ID3D11UnorderedAccessView *gpNullUAVs[CPUT_MATERIAL_MAX_TEXTURE_SLOTS] = {0}; //----------------------------------------------------------------------------- void MySample::Render(double deltaSeconds) { CPUTRenderParametersDX renderParams(mpContext); // If mViewBoundingBox is enabled then draw the axis aligned bounding box // for all the model in the scene. FYI This will affect frame rate. if(mViewBoundingBox) { renderParams.mShowBoundingBoxes = true; } else { renderParams.mShowBoundingBoxes = false; } if(mEnableCulling) { if(!mFirstFrame) { UINT tmpId = mCurrId; mCurrId = mPrevId; mPrevId = tmpId; } } mCameraCopy[mCurrId] = *mpCamera; // Clear back buffer const float clearColor[] = { 0.0993f, 0.0993f, 0.0993f, 1.0f }; mpContext->ClearRenderTargetView( mpBackBufferRTV, clearColor ); mpContext->ClearDepthStencilView( mpDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0); // Set the camera transforms so that the occluders can be transformed mpDBR->SetViewProj(mCameraCopy[mCurrId].GetViewMatrix(), (float4x4*)mCameraCopy[mCurrId].GetProjectionMatrix(), mCurrId); // Set the camera transforms so that the occludee abix aligned bounding boxes (AABB) can be transformed mpAABB->SetViewProjMatrix(mCameraCopy[mCurrId].GetViewMatrix(), (float4x4*)mCameraCopy[mCurrId].GetProjectionMatrix(), mCurrId); // If view frustum culling is enabled then determine which occluders and occludees are // inside the view frustum and run the software occlusion culling on only the those models if(mEnableFCulling) { renderParams.mRenderOnlyVisibleModels = true; } else { renderParams.mRenderOnlyVisibleModels = false; } // if software occlusion culling is enabled if(mEnableCulling) { // Set the Depth Buffer mpCPURenderTargetPixels = (UINT*)mpCPUDepthBuf[mCurrId]; mpDBR->SetCPURenderTargetPixels(mpCPURenderTargetPixels, mCurrId); // Transform the occluder models and rasterize them to the depth buffer mpDBR->TransformModelsAndRasterizeToDepthBuffer(&mCameraCopy[mCurrId], mCurrId); mpAABB->SetCPURenderTargetPixels(mpCPURenderTargetPixels, mCurrId); // Transform the occludee AABB, rasterize and depth test to determine is occludee is visible or occluded mpAABB->TransformAABBoxAndDepthTest(&mCameraCopy[mCurrId], mCurrId); if(mEnableTasks) { if(mPipeline) { if(mFirstFrame) { mFirstFrame = false; } else { if(!gTaskMgr.IsSetComplete(gAABBoxDepthTest[mPrevId])) { mpAABB->WaitForTaskToFinish(mPrevId); } mpAABB->ReleaseTaskHandles(mPrevId); } } else { mpAABB->WaitForTaskToFinish(mCurrId); mpAABB->ReleaseTaskHandles(mCurrId); } } } // If mViewDepthBuffer is enabled then blit the CPU rasterized depth buffer to the frame buffer if(mViewDepthBuffer) { mpShowDepthBufMtrl->SetRenderStates(renderParams); if(mEnableCulling && mEnableTasks && mPipeline) { // Update the GPU-side depth buffer UpdateGPUDepthBuf(mPrevId); mpContext->UpdateSubresource(mpCPURenderTarget[mPrevId], 0, NULL, mpGPUDepthBuf, rowPitch, 0); } else { // Update the GPU-side depth buffer UpdateGPUDepthBuf(mCurrId); mpContext->UpdateSubresource(mpCPURenderTarget[mCurrId], 0, NULL, mpGPUDepthBuf, rowPitch, 0); } mpContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); mpContext->Draw(3, 0); } // else render the (frustum culled) occluders and only the visible occludees else { CPUTMeshDX11::ResetDrawCallCount(); if(mpAssetSetAABB) { // if occlusion culling is enabled then render only the visible occludees in the scene if(mEnableCulling) { if(mEnableTasks && mPipeline) { renderParams.mpCamera = &mCameraCopy[mPrevId]; mpAABB->RenderVisible(mpAssetSetAABB, renderParams, OCCLUDEE_SETS, mPrevId); } else { renderParams.mpCamera = &mCameraCopy[mCurrId]; mpAABB->RenderVisible(mpAssetSetAABB, renderParams, OCCLUDEE_SETS, mCurrId); } } // else render all the (25,000) occludee models in the scene else { renderParams.mpCamera = &mCameraCopy[mCurrId]; mpAABB->Render(mpAssetSetAABB, renderParams, OCCLUDEE_SETS, mCurrId); } if(mpAssetSetSky) { mpAssetSetSky->RenderRecursive(renderParams); } } mNumDrawCalls = CPUTMeshDX11::GetDrawCallCount(); } wchar_t string[CPUT_MAX_STRING_LENGTH]; if(mEnableCulling) { if(mEnableTasks && mPipeline) { mpDBR->ComputeR2DBTime(mPrevId); mNumOccludersR2DB = mpDBR->GetNumOccludersR2DB(mPrevId); mNumOccluderRasterizedTris = mpDBR->GetNumRasterizedTriangles(mPrevId); mNumCulled = mpAABB->GetNumCulled(mPrevId); mNumOccludeeCulledTris = mpAABB->GetNumCulledTriangles(mPrevId); } else { mpDBR->ComputeR2DBTime(mCurrId); mNumOccludersR2DB = mpDBR->GetNumOccludersR2DB(mCurrId); mNumOccluderRasterizedTris = mpDBR->GetNumRasterizedTriangles(mCurrId); mNumCulled = mpAABB->GetNumCulled(mCurrId); mNumOccludeeCulledTris = mpAABB->GetNumCulledTriangles(mCurrId); } mRasterizeTime = mpDBR->GetRasterizeTime(); mNumVisible = mNumOccludees - mNumCulled; mNumOccludeeVisibleTris = mNumOccludeeTris - mNumOccludeeCulledTris; mDepthTestTime = mpAABB->GetDepthTestTime(); mTotalCullTime = mRasterizeTime + mDepthTestTime; swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tDepth rasterized models: %d"), mNumOccludersR2DB); mpOccludersR2DBText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tDepth rasterized tris: \t%d"), (int)mNumOccluderRasterizedTris); mpOccluderRasterizedTrisText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tDepth rasterizer time: \t%0.2f ms"), mRasterizeTime * 1000.0f); mpRasterizeTimeText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tModels culled: \t\t%d"), mNumCulled); mpCulledText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tModels visible: \t\t%d"), mNumVisible); mpVisibleText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tCulled tris: \t\t%d"), (int)mNumOccludeeCulledTris); mpCulledTrisText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tVisible tris: \t\t%d"), (int)mNumOccludeeVisibleTris); mpVisibleTrisText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tDepth test time: \t%0.2f ms"), mDepthTestTime * 1000.0f); mpDepthTestTimeText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tTotal Cull time: \t%0.2f ms"), mTotalCullTime * 1000.0f); mpTotalCullTimeText->SetText(string); } else { UINT fCullCount = 0; if(mEnableFCulling) { fCullCount = mpAABB->GetNumFCullCount(); } mNumCulled = mpAABB->GetNumCulled(mCurrId) + fCullCount; mNumOccludeeVisibleTris = mpAABB->GetNumTrisRendered(); mNumOccludeeCulledTris = mNumOccludeeTris - mNumOccludeeVisibleTris; mNumVisible = mNumOccludees - mNumCulled; swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tModels culled: \t\t%d"), mNumCulled); mpCulledText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tModels visible: \t\t%d"), mNumVisible); mpVisibleText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tCulled tris: \t\t%d"), (int)mNumOccludeeCulledTris); mpCulledTrisText->SetText(string); swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("\tVisible tris: \t\t%d"), (int)mNumOccludeeVisibleTris); mpVisibleTrisText->SetText(string); } swprintf_s(&string[0], CPUT_MAX_STRING_LENGTH, _L("Number of draw calls: \t\t %d"), mNumDrawCalls); mpDrawCallsText->SetText(string); CPUTDrawGUI(); }