diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index a5ea8f5c6..6f89753b8 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -45,7 +45,7 @@ void Editor::Initialize() { // Call this before Maincomponent::Initialize if you want to load shaders from an other directory! // otherwise, shaders will be loaded from the working directory - wiRenderer::SHADERPATH = wiHelper::GetOriginalWorkingDirectory() + "../WickedEngine/shaders/"; + wiRenderer::GetShaderPath() = wiHelper::GetOriginalWorkingDirectory() + "../WickedEngine/shaders/"; wiFont::FONTPATH = wiHelper::GetOriginalWorkingDirectory() + "../WickedEngine/fonts/"; // search for fonts elsewhere MainComponent::Initialize(); @@ -56,9 +56,7 @@ void Editor::Initialize() infoDisplay.resolution = true; wiRenderer::GetDevice()->SetVSyncEnabled(true); - wiRenderer::EMITTERSENABLED = true; - wiRenderer::HAIRPARTICLEENABLED = true; - wiRenderer::physicsEngine = new wiBULLET(); + //wiRenderer::physicsEngine = new wiBULLET(); wiRenderer::SetOcclusionCullingEnabled(true); wiInputManager::GetInstance()->addXInput(new wiXInput()); diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index b6b848042..e076b96e7 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -108,7 +108,7 @@ ObjectWindow::ObjectWindow(wiGUI* gui) : GUI(gui) RigidBodyPhysicsComponent& rigidbody = scene.rigidbodies.Create(entity); rigidbody.kinematic = kinematicCheckBox->GetCheck(); rigidbody.shape = (RigidBodyPhysicsComponent::CollisionShape)collisionShapeComboBox->GetSelected(); - wiRenderer::physicsEngine->addRigidBody(rigidbody, *mesh, *transform); + //wiRenderer::physicsEngine->addRigidBody(rigidbody, *mesh, *transform); } } } @@ -117,8 +117,8 @@ ObjectWindow::ObjectWindow(wiGUI* gui) : GUI(gui) RigidBodyPhysicsComponent* physicscomponent = wiRenderer::GetScene().rigidbodies.GetComponent(entity); if (physicscomponent != nullptr) { - wiRenderer::physicsEngine->removeRigidBody(*physicscomponent); - scene.rigidbodies.Remove(entity); + //wiRenderer::physicsEngine->removeRigidBody(*physicscomponent); + //scene.rigidbodies.Remove(entity); } } }); diff --git a/Editor/RendererWindow.cpp b/Editor/RendererWindow.cpp index d18137c2c..791872e64 100644 --- a/Editor/RendererWindow.cpp +++ b/Editor/RendererWindow.cpp @@ -222,29 +222,29 @@ RendererWindow::RendererWindow(wiGUI* gui, Renderable3DComponent* component) : G shadowProps2DComboBox->AddItem("2048"); shadowProps2DComboBox->AddItem("4096"); shadowProps2DComboBox->OnSelect([&](wiEventArgs args) { - wiRenderer::SHADOWCOUNT_2D = 11; + switch (args.iValue) { case 0: - wiRenderer::SetShadowProps2D(128, 0, wiRenderer::SOFTSHADOWQUALITY_2D); + wiRenderer::SetShadowProps2D(64, 0, -1); break; case 1: - wiRenderer::SetShadowProps2D(128, wiRenderer::SHADOWCOUNT_2D, wiRenderer::SOFTSHADOWQUALITY_2D); + wiRenderer::SetShadowProps2D(128, -1, -1); break; case 2: - wiRenderer::SetShadowProps2D(256, wiRenderer::SHADOWCOUNT_2D, wiRenderer::SOFTSHADOWQUALITY_2D); + wiRenderer::SetShadowProps2D(256, -1, -1); break; case 3: - wiRenderer::SetShadowProps2D(512, wiRenderer::SHADOWCOUNT_2D, wiRenderer::SOFTSHADOWQUALITY_2D); + wiRenderer::SetShadowProps2D(512, -1, -1); break; case 4: - wiRenderer::SetShadowProps2D(1024, wiRenderer::SHADOWCOUNT_2D, wiRenderer::SOFTSHADOWQUALITY_2D); + wiRenderer::SetShadowProps2D(1024, -1, -1); break; case 5: - wiRenderer::SetShadowProps2D(2048, wiRenderer::SHADOWCOUNT_2D, wiRenderer::SOFTSHADOWQUALITY_2D); + wiRenderer::SetShadowProps2D(2048, -1, -1); break; case 6: - wiRenderer::SetShadowProps2D(4096, wiRenderer::SHADOWCOUNT_2D, wiRenderer::SOFTSHADOWQUALITY_2D); + wiRenderer::SetShadowProps2D(4096, -1, -1); break; default: break; @@ -267,29 +267,28 @@ RendererWindow::RendererWindow(wiGUI* gui, Renderable3DComponent* component) : G shadowPropsCubeComboBox->AddItem("2048"); shadowPropsCubeComboBox->AddItem("4096"); shadowPropsCubeComboBox->OnSelect([&](wiEventArgs args) { - wiRenderer::SHADOWCOUNT_CUBE = 5; switch (args.iValue) { case 0: wiRenderer::SetShadowPropsCube(128, 0); break; case 1: - wiRenderer::SetShadowPropsCube(128, wiRenderer::SHADOWCOUNT_CUBE); + wiRenderer::SetShadowPropsCube(128, -1); break; case 2: - wiRenderer::SetShadowPropsCube(256, wiRenderer::SHADOWCOUNT_CUBE); + wiRenderer::SetShadowPropsCube(256, -1); break; case 3: - wiRenderer::SetShadowPropsCube(512, wiRenderer::SHADOWCOUNT_CUBE); + wiRenderer::SetShadowPropsCube(512, -1); break; case 4: - wiRenderer::SetShadowPropsCube(1024, wiRenderer::SHADOWCOUNT_CUBE); + wiRenderer::SetShadowPropsCube(1024, -1); break; case 5: - wiRenderer::SetShadowPropsCube(2048, wiRenderer::SHADOWCOUNT_CUBE); + wiRenderer::SetShadowPropsCube(2048, -1); break; case 6: - wiRenderer::SetShadowPropsCube(4096, wiRenderer::SHADOWCOUNT_CUBE); + wiRenderer::SetShadowPropsCube(4096, -1); break; default: break; @@ -359,8 +358,7 @@ RendererWindow::RendererWindow(wiGUI* gui, Renderable3DComponent* component) : G textureQualityComboBox->AddItem("Trilinear"); textureQualityComboBox->AddItem("Anisotropic"); textureQualityComboBox->OnSelect([&](wiEventArgs args) { - wiGraphicsTypes::SamplerDesc desc = wiRenderer::samplers[SSLOT_OBJECTSHADER]->GetDesc(); - SAFE_DELETE(wiRenderer::samplers[SSLOT_OBJECTSHADER]); + wiGraphicsTypes::SamplerDesc desc = wiRenderer::GetSampler(SSLOT_OBJECTSHADER)->GetDesc(); switch (args.iValue) { @@ -380,8 +378,8 @@ RendererWindow::RendererWindow(wiGUI* gui, Renderable3DComponent* component) : G break; } - wiRenderer::samplers[SSLOT_OBJECTSHADER] = new wiGraphicsTypes::Sampler; - wiRenderer::GetDevice()->CreateSamplerState(&desc, wiRenderer::samplers[SSLOT_OBJECTSHADER]); + wiRenderer::ModifySampler(desc, SSLOT_OBJECTSHADER); + }); textureQualityComboBox->SetSelected(3); textureQualityComboBox->SetEnabled(true); @@ -393,11 +391,9 @@ RendererWindow::RendererWindow(wiGUI* gui, Renderable3DComponent* component) : G mipLodBiasSlider->SetSize(XMFLOAT2(100, 30)); mipLodBiasSlider->SetPos(XMFLOAT2(x, y += 30)); mipLodBiasSlider->OnSlide([&](wiEventArgs args) { - wiGraphicsTypes::SamplerDesc desc = wiRenderer::samplers[SSLOT_OBJECTSHADER]->GetDesc(); - SAFE_DELETE(wiRenderer::samplers[SSLOT_OBJECTSHADER]); + wiGraphicsTypes::SamplerDesc desc = wiRenderer::GetSampler(SSLOT_OBJECTSHADER)->GetDesc(); desc.MipLODBias = args.fValue; - wiRenderer::samplers[SSLOT_OBJECTSHADER] = new wiGraphicsTypes::Sampler; - wiRenderer::GetDevice()->CreateSamplerState(&desc, wiRenderer::samplers[SSLOT_OBJECTSHADER]); + wiRenderer::ModifySampler(desc, SSLOT_OBJECTSHADER); }); rendererWindow->AddWidget(mipLodBiasSlider); diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp index 894773274..63279e846 100644 --- a/Editor/Translator.cpp +++ b/Editor/Translator.cpp @@ -28,12 +28,12 @@ void Translator::LoadShaders() { GraphicsPSODesc desc; - desc.vs = wiRenderer::vertexShaders[VSTYPE_LINE]; - desc.ps = wiRenderer::pixelShaders[PSTYPE_LINE]; - desc.il = wiRenderer::vertexLayouts[VLTYPE_LINE]; - desc.dss = wiRenderer::depthStencils[DSSTYPE_XRAY]; - desc.rs = wiRenderer::rasterizers[RSTYPE_DOUBLESIDED]; - desc.bs = wiRenderer::blendStates[BSTYPE_ADDITIVE]; + desc.vs = wiRenderer::GetVertexShader(VSTYPE_LINE); + desc.ps = wiRenderer::GetPixelShader(PSTYPE_LINE); + desc.il = wiRenderer::GetVertexLayout(VLTYPE_LINE); + desc.dss = wiRenderer::GetDepthStencilState(DSSTYPE_XRAY); + desc.rs = wiRenderer::GetRasterizerState(RSTYPE_DOUBLESIDED); + desc.bs = wiRenderer::GetBlendState(BSTYPE_ADDITIVE); desc.pt = TRIANGLELIST; pso_solidpart = new GraphicsPSO; @@ -43,12 +43,12 @@ void Translator::LoadShaders() { GraphicsPSODesc desc; - desc.vs = wiRenderer::vertexShaders[VSTYPE_LINE]; - desc.ps = wiRenderer::pixelShaders[PSTYPE_LINE]; - desc.il = wiRenderer::vertexLayouts[VLTYPE_LINE]; - desc.dss = wiRenderer::depthStencils[DSSTYPE_XRAY]; - desc.rs = wiRenderer::rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]; - desc.bs = wiRenderer::blendStates[BSTYPE_TRANSPARENT]; + desc.vs = wiRenderer::GetVertexShader(VSTYPE_LINE); + desc.ps = wiRenderer::GetPixelShader(PSTYPE_LINE); + desc.il = wiRenderer::GetVertexLayout(VLTYPE_LINE); + desc.dss = wiRenderer::GetDepthStencilState(DSSTYPE_XRAY); + desc.rs = wiRenderer::GetRasterizerState(RSTYPE_WIRE_DOUBLESIDED_SMOOTH); + desc.bs = wiRenderer::GetBlendState(BSTYPE_TRANSPARENT); desc.pt = LINELIST; pso_wirepart = new GraphicsPSO; @@ -472,19 +472,19 @@ void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) // xy XMStoreFloat4x4(&sb.g_xTransform, matX); sb.g_xColor = state == TRANSLATOR_XY ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); - device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); device->Draw(vertexCount_Plane, 0, threadID); // xz XMStoreFloat4x4(&sb.g_xTransform, matZ); sb.g_xColor = state == TRANSLATOR_XZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); - device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); device->Draw(vertexCount_Plane, 0, threadID); // yz XMStoreFloat4x4(&sb.g_xTransform, matY); sb.g_xColor = state == TRANSLATOR_YZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); - device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); device->Draw(vertexCount_Plane, 0, threadID); // Lines: @@ -502,19 +502,19 @@ void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) // x XMStoreFloat4x4(&sb.g_xTransform, matX); sb.g_xColor = state == TRANSLATOR_X ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(1, 0, 0, 1); - device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); device->Draw(vertexCount_Axis, 0, threadID); // y XMStoreFloat4x4(&sb.g_xTransform, matY); sb.g_xColor = state == TRANSLATOR_Y ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0, 1, 0, 1); - device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); device->Draw(vertexCount_Axis, 0, threadID); // z XMStoreFloat4x4(&sb.g_xTransform, matZ); sb.g_xColor = state == TRANSLATOR_Z ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0, 0, 1, 1); - device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); device->Draw(vertexCount_Axis, 0, threadID); // Origin: @@ -529,7 +529,7 @@ void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(mat)); sb.g_xColor = state == TRANSLATOR_XYZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.25f, 0.25f, 0.25f, 1); - device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); device->Draw(vertexCount_Origin, 0, threadID); } diff --git a/Editor/main.cpp b/Editor/main.cpp index a7e980ab4..6214cbbe5 100644 --- a/Editor/main.cpp +++ b/Editor/main.cpp @@ -208,7 +208,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_SIZE: { - if (wiRenderer::graphicsDevice) + if (wiRenderer::GetDevice() != nullptr) { int width = LOWORD(lParam); int height = HIWORD(lParam); diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index a40016b66..8aa77859f 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -53,7 +53,7 @@ void MainComponent::Initialize() { // User can also create a graphics device if custom logic is desired, but he must do before this function! - if (wiRenderer::graphicsDevice == nullptr) + if (wiRenderer::GetDevice() == nullptr) { bool debugdevice = wiStartupArguments::HasArgument("debugdevice"); @@ -61,8 +61,8 @@ void MainComponent::Initialize() if (wiStartupArguments::HasArgument("vulkan")) { #ifdef WICKEDENGINE_BUILD_VULKAN - wiRenderer::SHADERPATH += "spirv/"; - wiRenderer::graphicsDevice = new GraphicsDevice_Vulkan(window, fullscreen, debugdevice); + wiRenderer::GetShaderPath() += "spirv/"; + wiRenderer::SetDevice(new GraphicsDevice_Vulkan(window, fullscreen, debugdevice)); #else wiHelper::messageBox("Vulkan SDK not found during building the application! Vulkan API disabled!", "Error"); #endif @@ -71,13 +71,13 @@ void MainComponent::Initialize() { if (wiStartupArguments::HasArgument("hlsl6")) { - wiRenderer::SHADERPATH += "hlsl6/"; + wiRenderer::GetShaderPath() += "hlsl6/"; } - wiRenderer::graphicsDevice = new GraphicsDevice_DX12(window, fullscreen, debugdevice); + wiRenderer::SetDevice(new GraphicsDevice_DX12(window, fullscreen, debugdevice)); } else { - wiRenderer::graphicsDevice = new GraphicsDevice_DX11(window, fullscreen, debugdevice); + wiRenderer::SetDevice(new GraphicsDevice_DX11(window, fullscreen, debugdevice)); } } @@ -159,13 +159,21 @@ void MainComponent::Run() Update((float)elapsedTime); wiProfiler::GetInstance().EndRange(); // Update + wiProfiler::GetInstance().BeginRange("Render", wiProfiler::DOMAIN_CPU); Render(); wiProfiler::GetInstance().EndRange(); // Render wiProfiler::GetInstance().EndRange(); // CPU Frame - wiRenderer::Present(bind(&MainComponent::Compose, this)); + + wiProfiler::GetInstance().BeginRange("Compose", wiProfiler::DOMAIN_CPU); + wiRenderer::GetDevice()->PresentBegin(); + Compose(); + wiRenderer::GetDevice()->PresentEnd(); + wiProfiler::GetInstance().EndRange(); // Compose + + wiRenderer::EndFrame(); static bool startupScriptProcessed = false; if (!startupScriptProcessed) { diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index 44242c8c5..6d1c8d860 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -203,9 +203,6 @@ void Renderable3DComponent::Initialize() void Renderable3DComponent::Load() { Renderable2DComponent::Load(); - - wiRenderer::HAIRPARTICLEENABLED = getHairParticlesEnabled(); - wiRenderer::EMITTERSENABLED = getEmittedParticlesEnabled(); } void Renderable3DComponent::Start() @@ -233,7 +230,7 @@ void Renderable3DComponent::Compose() if (wiRenderer::GetDebugLightCulling()) { - wiImage::Draw((Texture2D*)wiRenderer::textures[TEXTYPE_2D_DEBUGUAV], wiImageEffects((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()), GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw((Texture2D*)wiRenderer::GetTexture(TEXTYPE_2D_DEBUGUAV), wiImageEffects((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()), GRAPHICSTHREAD_IMMEDIATE); } Renderable2DComponent::Compose(); diff --git a/WickedEngine/TiledDeferredRenderableComponent.cpp b/WickedEngine/TiledDeferredRenderableComponent.cpp index 7329eb115..87340b513 100644 --- a/WickedEngine/TiledDeferredRenderableComponent.cpp +++ b/WickedEngine/TiledDeferredRenderableComponent.cpp @@ -139,7 +139,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) fx.process.setSSSS(dir); if (i == 0) { - wiImage::Draw(static_cast(wiRenderer::textures[TEXTYPE_2D_TILEDDEFERRED_DIFFUSEUAV]), fx, threadID); + wiImage::Draw(static_cast(wiRenderer::GetTexture(TEXTYPE_2D_TILEDDEFERRED_DIFFUSEUAV)), fx, threadID); } else { @@ -157,7 +157,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) fx.stencilComp = STENCILMODE_DISABLED; fx.presentFullScreen = true; fx.hdr = true; - wiImage::Draw(static_cast(wiRenderer::textures[TEXTYPE_2D_TILEDDEFERRED_DIFFUSEUAV]), fx, threadID); + wiImage::Draw(static_cast(wiRenderer::GetTexture(TEXTYPE_2D_TILEDDEFERRED_DIFFUSEUAV)), fx, threadID); fx.stencilRef = STENCILREF_SKIN; fx.stencilComp = STENCILMODE_LESS; wiImage::Draw(rtSSS[1].GetTexture(), fx, threadID); @@ -169,8 +169,8 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) } rtDeferred.Activate(threadID, rtGBuffer.depth); { - wiImage::DrawDeferred((getSSSEnabled() ? rtSSS[0].GetTexture(0) : static_cast(wiRenderer::textures[TEXTYPE_2D_TILEDDEFERRED_DIFFUSEUAV])), - static_cast(wiRenderer::textures[TEXTYPE_2D_TILEDDEFERRED_SPECULARUAV]) + wiImage::DrawDeferred((getSSSEnabled() ? rtSSS[0].GetTexture(0) : static_cast(wiRenderer::GetTexture(TEXTYPE_2D_TILEDDEFERRED_DIFFUSEUAV))), + static_cast(wiRenderer::GetTexture(TEXTYPE_2D_TILEDDEFERRED_SPECULARUAV)) , getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getInstance()->getWhite() , threadID, STENCILREF_DEFAULT); wiRenderer::DrawSky(threadID); diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index 4e61d2762..cea3be88e 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -591,28 +591,27 @@ void wiEmittedParticle::Draw(const CameraComponent& camera, const MaterialCompon void wiEmittedParticle::LoadShaders() { - vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticleVS.cso", wiResourceManager::VERTEXSHADER)); - + std::string path = wiRenderer::GetShaderPath(); - - pixelShader[SOFT] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticlePS_soft.cso", wiResourceManager::PIXELSHADER)); - pixelShader[SOFT_DISTORTION] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticlePS_soft_distortion.cso", wiResourceManager::PIXELSHADER)); - pixelShader[SIMPLEST] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticlePS_simplest.cso", wiResourceManager::PIXELSHADER)); + vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticleVS.cso", wiResourceManager::VERTEXSHADER)); + pixelShader[SOFT] = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticlePS_soft.cso", wiResourceManager::PIXELSHADER)); + pixelShader[SOFT_DISTORTION] = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticlePS_soft_distortion.cso", wiResourceManager::PIXELSHADER)); + pixelShader[SIMPLEST] = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticlePS_simplest.cso", wiResourceManager::PIXELSHADER)); - kickoffUpdateCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_kickoffUpdateCS.cso", wiResourceManager::COMPUTESHADER)); - finishUpdateCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_finishUpdateCS.cso", wiResourceManager::COMPUTESHADER)); - emitCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_emitCS.cso", wiResourceManager::COMPUTESHADER)); - emitCS_FROMMESH = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_emitCS_FROMMESH.cso", wiResourceManager::COMPUTESHADER)); - sphpartitionCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_sphpartitionCS.cso", wiResourceManager::COMPUTESHADER)); - sphpartitionoffsetsCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_sphpartitionoffsetsCS.cso", wiResourceManager::COMPUTESHADER)); - sphpartitionoffsetsresetCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_sphpartitionoffsetsresetCS.cso", wiResourceManager::COMPUTESHADER)); - sphdensityCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_sphdensityCS.cso", wiResourceManager::COMPUTESHADER)); - sphforceCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_sphforceCS.cso", wiResourceManager::COMPUTESHADER)); - simulateCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_simulateCS.cso", wiResourceManager::COMPUTESHADER)); - simulateCS_SORTING = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_simulateCS_SORTING.cso", wiResourceManager::COMPUTESHADER)); - simulateCS_DEPTHCOLLISIONS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_simulateCS_DEPTHCOLLISIONS.cso", wiResourceManager::COMPUTESHADER)); - simulateCS_SORTING_DEPTHCOLLISIONS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_simulateCS_SORTING_DEPTHCOLLISIONS.cso", wiResourceManager::COMPUTESHADER)); + kickoffUpdateCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_kickoffUpdateCS.cso", wiResourceManager::COMPUTESHADER)); + finishUpdateCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_finishUpdateCS.cso", wiResourceManager::COMPUTESHADER)); + emitCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_emitCS.cso", wiResourceManager::COMPUTESHADER)); + emitCS_FROMMESH = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_emitCS_FROMMESH.cso", wiResourceManager::COMPUTESHADER)); + sphpartitionCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_sphpartitionCS.cso", wiResourceManager::COMPUTESHADER)); + sphpartitionoffsetsCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_sphpartitionoffsetsCS.cso", wiResourceManager::COMPUTESHADER)); + sphpartitionoffsetsresetCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_sphpartitionoffsetsresetCS.cso", wiResourceManager::COMPUTESHADER)); + sphdensityCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_sphdensityCS.cso", wiResourceManager::COMPUTESHADER)); + sphforceCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_sphforceCS.cso", wiResourceManager::COMPUTESHADER)); + simulateCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_simulateCS.cso", wiResourceManager::COMPUTESHADER)); + simulateCS_SORTING = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_simulateCS_SORTING.cso", wiResourceManager::COMPUTESHADER)); + simulateCS_DEPTHCOLLISIONS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_simulateCS_DEPTHCOLLISIONS.cso", wiResourceManager::COMPUTESHADER)); + simulateCS_SORTING_DEPTHCOLLISIONS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_simulateCS_SORTING_DEPTHCOLLISIONS.cso", wiResourceManager::COMPUTESHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/wiFFTGenerator.cpp b/WickedEngine/wiFFTGenerator.cpp index 4bbabb5f7..3c2bb1530 100644 --- a/WickedEngine/wiFFTGenerator.cpp +++ b/WickedEngine/wiFFTGenerator.cpp @@ -230,9 +230,10 @@ void fft512x512_destroy_plan(CSFFT512x512_Plan* plan) void CSFFT_512x512_Data_t::LoadShaders() { + std::string path = wiRenderer::GetShaderPath(); - pRadix008A_CS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "fft_512x512_c2c_CS.cso", wiResourceManager::COMPUTESHADER)); - pRadix008A_CS2 = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "fft_512x512_c2c_v2_CS.cso", wiResourceManager::COMPUTESHADER)); + pRadix008A_CS = static_cast(wiResourceManager::GetShaderManager()->add(path+ "fft_512x512_c2c_CS.cso", wiResourceManager::COMPUTESHADER)); + pRadix008A_CS2 = static_cast(wiResourceManager::GetShaderManager()->add(path + "fft_512x512_c2c_v2_CS.cso", wiResourceManager::COMPUTESHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index 70c6ec814..83d29b57c 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -37,11 +37,33 @@ wiFont::wiFont(const std::wstring& text, wiFontProps props, int style) : text(te } wiFont::~wiFont() { - } void wiFont::Initialize() { + SetUpStates(); + LoadShaders(); + LoadVertexBuffer(); + LoadIndices(); + + // add default font: + addFontStyle("default_font"); +} +void wiFont::CleanUp() +{ + for (unsigned int i = 0; i(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "fontVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "fontVS.cso", wiResourceManager::VERTEXSHADER)); vertexLayout = new VertexLayout; wiRenderer::GetDevice()->CreateInputLayout(layout, ARRAYSIZE(layout), vertexShader->code.data, vertexShader->code.size, vertexLayout); - pixelShader = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "fontPS.cso", wiResourceManager::PIXELSHADER)); + pixelShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "fontPS.cso", wiResourceManager::PIXELSHADER)); GraphicsPSODesc desc; @@ -151,32 +174,6 @@ void wiFont::LoadShaders() PSO = new GraphicsPSO; wiRenderer::GetDevice()->CreateGraphicsPSO(&desc, PSO); } -void wiFont::SetUpStaticComponents() -{ - SetUpStates(); - LoadShaders(); - LoadVertexBuffer(); - LoadIndices(); - - // add default font: - addFontStyle("default_font"); -} -void wiFont::CleanUpStatic() -{ - for(unsigned int i=0;iGetScreenProjection() )); cb.g_xColor = float4(newProps.shadowColor.R, newProps.shadowColor.G, newProps.shadowColor.B, newProps.shadowColor.A); - device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); + device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &cb, threadID); device->DrawIndexed((int)text.length() * 6, 0, 0, threadID); } @@ -336,7 +333,7 @@ void wiFont::Draw(GRAPHICSTHREAD threadID) * device->GetScreenProjection() )); cb.g_xColor = float4(newProps.color.R, newProps.color.G, newProps.color.B, newProps.color.A); - device->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); + device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &cb, threadID); device->DrawIndexed((int)text.length() * 6, 0, 0, threadID); @@ -466,7 +463,3 @@ int wiFont::getFontStyleByName( const std::string& get ){ return 0; } -void wiFont::CleanUp() -{ - -} diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index 0c63e1e3a..5d26fdfe1 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -91,8 +91,7 @@ private: public: static void Initialize(); - static void SetUpStaticComponents(); - static void CleanUpStatic(); + static void CleanUp(); std::wstring text; wiFontProps props; @@ -116,6 +115,4 @@ public: void SetText(const std::wstring& text); std::wstring GetText(); std::string GetTextA(); - - void CleanUp(); }; diff --git a/WickedEngine/wiGPUSortLib.cpp b/WickedEngine/wiGPUSortLib.cpp index fe4d65111..da86f8465 100644 --- a/WickedEngine/wiGPUSortLib.cpp +++ b/WickedEngine/wiGPUSortLib.cpp @@ -41,15 +41,16 @@ void wiGPUSortLib::Initialize() void wiGPUSortLib::LoadShaders() { + std::string path = wiRenderer::GetShaderPath(); + + kickoffSortCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "gpusortlib_kickoffSortCS.cso", wiResourceManager::COMPUTESHADER)); + sortCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "gpusortlib_sortCS.cso", wiResourceManager::COMPUTESHADER)); + sortInnerCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "gpusortlib_sortInnerCS.cso", wiResourceManager::COMPUTESHADER)); + sortStepCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "gpusortlib_sortStepCS.cso", wiResourceManager::COMPUTESHADER)); + + GraphicsDevice* device = wiRenderer::GetDevice(); - kickoffSortCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "gpusortlib_kickoffSortCS.cso", wiResourceManager::COMPUTESHADER)); - sortCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "gpusortlib_sortCS.cso", wiResourceManager::COMPUTESHADER)); - sortInnerCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "gpusortlib_sortInnerCS.cso", wiResourceManager::COMPUTESHADER)); - sortStepCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "gpusortlib_sortStepCS.cso", wiResourceManager::COMPUTESHADER)); - - - ComputePSODesc desc; desc.cs = kickoffSortCS; diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index dca08fa83..7cba35ece 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -41,7 +41,9 @@ void wiHairParticle::CleanUpStatic() } void wiHairParticle::LoadShaders() { - vs = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "hairparticleVS.cso", wiResourceManager::VERTEXSHADER)); + std::string path = wiRenderer::GetShaderPath(); + + vs = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticleVS.cso", wiResourceManager::VERTEXSHADER)); for (int i = 0; i < SHADERTYPE_COUNT; ++i) @@ -49,10 +51,10 @@ void wiHairParticle::LoadShaders() SAFE_INIT(ps[i]); } - ps[SHADERTYPE_DEPTHONLY] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "hairparticlePS_alphatestonly.cso", wiResourceManager::PIXELSHADER)); - ps[SHADERTYPE_DEFERRED] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "hairparticlePS_deferred.cso", wiResourceManager::PIXELSHADER)); - ps[SHADERTYPE_FORWARD] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "hairparticlePS_forward.cso", wiResourceManager::PIXELSHADER)); - ps[SHADERTYPE_TILEDFORWARD] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "hairparticlePS_tiledforward.cso", wiResourceManager::PIXELSHADER)); + ps[SHADERTYPE_DEPTHONLY] = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticlePS_alphatestonly.cso", wiResourceManager::PIXELSHADER)); + ps[SHADERTYPE_DEFERRED] = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticlePS_deferred.cso", wiResourceManager::PIXELSHADER)); + ps[SHADERTYPE_FORWARD] = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticlePS_forward.cso", wiResourceManager::PIXELSHADER)); + ps[SHADERTYPE_TILEDFORWARD] = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticlePS_tiledforward.cso", wiResourceManager::PIXELSHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); @@ -118,7 +120,7 @@ void wiHairParticle::LoadShaders() } SAFE_INIT(ps_simplest); - ps_simplest = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "hairparticlePS_simplest.cso", wiResourceManager::PIXELSHADER)); + ps_simplest = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticlePS_simplest.cso", wiResourceManager::PIXELSHADER)); { GraphicsPSODesc desc; @@ -134,7 +136,7 @@ void wiHairParticle::LoadShaders() } SAFE_INIT(cs_simulate); - cs_simulate = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "hairparticle_simulateCS.cso", wiResourceManager::COMPUTESHADER)); + cs_simulate = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticle_simulateCS.cso", wiResourceManager::COMPUTESHADER)); { ComputePSODesc desc; diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index 4c6f5ebba..f6282690a 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -61,37 +61,39 @@ void wiImage::LoadBuffers() void wiImage::LoadShaders() { - vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "imageVS.cso", wiResourceManager::VERTEXSHADER)); - screenVS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "screenVS.cso", wiResourceManager::VERTEXSHADER)); + std::string path = wiRenderer::GetShaderPath(); - imagePS[IMAGE_SHADER_STANDARD] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "imagePS.cso", wiResourceManager::PIXELSHADER)); - imagePS[IMAGE_SHADER_SEPARATENORMALMAP] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "imagePS_separatenormalmap.cso", wiResourceManager::PIXELSHADER)); - imagePS[IMAGE_SHADER_DISTORTION] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "imagePS_distortion.cso", wiResourceManager::PIXELSHADER)); - imagePS[IMAGE_SHADER_DISTORTION_MASKED] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "imagePS_distortion_masked.cso", wiResourceManager::PIXELSHADER)); - imagePS[IMAGE_SHADER_MASKED] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "imagePS_masked.cso", wiResourceManager::PIXELSHADER)); - imagePS[IMAGE_SHADER_FULLSCREEN] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "screenPS.cso", wiResourceManager::PIXELSHADER)); + vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "imageVS.cso", wiResourceManager::VERTEXSHADER)); + screenVS = static_cast(wiResourceManager::GetShaderManager()->add(path + "screenVS.cso", wiResourceManager::VERTEXSHADER)); - postprocessPS[POSTPROCESS_BLUR_H] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "horizontalBlurPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_BLUR_V] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "verticalBlurPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_LIGHTSHAFT] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "lightShaftPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_OUTLINE] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "outlinePS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_DEPTHOFFIELD] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "depthofFieldPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_MOTIONBLUR] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "motionBlurPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_BLOOMSEPARATE] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "bloomSeparatePS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_FXAA] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "fxaa.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_SSAO] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "ssao.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_SSSS] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "ssss.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_LINEARDEPTH] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "linDepthPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_COLORGRADE] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "colorGradePS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_SSR] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "ssr.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_STEREOGRAM] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "stereogramPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_TONEMAP] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "toneMapPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_REPROJECTDEPTHBUFFER] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "reprojectDepthBufferPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_DOWNSAMPLEDEPTHBUFFER] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "downsampleDepthBuffer4xPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_TEMPORALAA] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "temporalAAResolvePS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_SHARPEN] = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "sharpenPS.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_STANDARD] = static_cast(wiResourceManager::GetShaderManager()->add(path + "imagePS.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_SEPARATENORMALMAP] = static_cast(wiResourceManager::GetShaderManager()->add(path + "imagePS_separatenormalmap.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_DISTORTION] = static_cast(wiResourceManager::GetShaderManager()->add(path + "imagePS_distortion.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_DISTORTION_MASKED] = static_cast(wiResourceManager::GetShaderManager()->add(path + "imagePS_distortion_masked.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_MASKED] = static_cast(wiResourceManager::GetShaderManager()->add(path + "imagePS_masked.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_FULLSCREEN] = static_cast(wiResourceManager::GetShaderManager()->add(path + "screenPS.cso", wiResourceManager::PIXELSHADER)); - deferredPS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "deferredPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_BLUR_H] = static_cast(wiResourceManager::GetShaderManager()->add(path + "horizontalBlurPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_BLUR_V] = static_cast(wiResourceManager::GetShaderManager()->add(path + "verticalBlurPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_LIGHTSHAFT] = static_cast(wiResourceManager::GetShaderManager()->add(path + "lightShaftPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_OUTLINE] = static_cast(wiResourceManager::GetShaderManager()->add(path + "outlinePS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_DEPTHOFFIELD] = static_cast(wiResourceManager::GetShaderManager()->add(path + "depthofFieldPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_MOTIONBLUR] = static_cast(wiResourceManager::GetShaderManager()->add(path + "motionBlurPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_BLOOMSEPARATE] = static_cast(wiResourceManager::GetShaderManager()->add(path + "bloomSeparatePS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_FXAA] = static_cast(wiResourceManager::GetShaderManager()->add(path + "fxaa.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_SSAO] = static_cast(wiResourceManager::GetShaderManager()->add(path + "ssao.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_SSSS] = static_cast(wiResourceManager::GetShaderManager()->add(path + "ssss.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_LINEARDEPTH] = static_cast(wiResourceManager::GetShaderManager()->add(path + "linDepthPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_COLORGRADE] = static_cast(wiResourceManager::GetShaderManager()->add(path + "colorGradePS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_SSR] = static_cast(wiResourceManager::GetShaderManager()->add(path + "ssr.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_STEREOGRAM] = static_cast(wiResourceManager::GetShaderManager()->add(path + "stereogramPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_TONEMAP] = static_cast(wiResourceManager::GetShaderManager()->add(path + "toneMapPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_REPROJECTDEPTHBUFFER] = static_cast(wiResourceManager::GetShaderManager()->add(path + "reprojectDepthBufferPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_DOWNSAMPLEDEPTHBUFFER] = static_cast(wiResourceManager::GetShaderManager()->add(path + "downsampleDepthBuffer4xPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_TEMPORALAA] = static_cast(wiResourceManager::GetShaderManager()->add(path + "temporalAAResolvePS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_SHARPEN] = static_cast(wiResourceManager::GetShaderManager()->add(path + "sharpenPS.cso", wiResourceManager::PIXELSHADER)); + + deferredPS = static_cast(wiResourceManager::GetShaderManager()->add(path + "deferredPS.cso", wiResourceManager::PIXELSHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); @@ -355,29 +357,29 @@ void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHR if (effects.quality == QUALITY_NEAREST) { if (effects.sampleFlag == SAMPLEMODE_MIRROR) - device->BindSampler(PS, wiRenderer::samplers[SSLOT_POINT_MIRROR], SSLOT_ONDEMAND0, threadID); + device->BindSampler(PS, wiRenderer::GetSampler(SSLOT_POINT_MIRROR), SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_WRAP) - device->BindSampler(PS, wiRenderer::samplers[SSLOT_POINT_WRAP], SSLOT_ONDEMAND0, threadID); + device->BindSampler(PS, wiRenderer::GetSampler(SSLOT_POINT_WRAP), SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_CLAMP) - device->BindSampler(PS, wiRenderer::samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindSampler(PS, wiRenderer::GetSampler(SSLOT_POINT_CLAMP), SSLOT_ONDEMAND0, threadID); } else if (effects.quality == QUALITY_BILINEAR) { if (effects.sampleFlag == SAMPLEMODE_MIRROR) - device->BindSampler(PS, wiRenderer::samplers[SSLOT_LINEAR_MIRROR], SSLOT_ONDEMAND0, threadID); + device->BindSampler(PS, wiRenderer::GetSampler(SSLOT_LINEAR_MIRROR), SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_WRAP) - device->BindSampler(PS, wiRenderer::samplers[SSLOT_LINEAR_WRAP], SSLOT_ONDEMAND0, threadID); + device->BindSampler(PS, wiRenderer::GetSampler(SSLOT_LINEAR_WRAP), SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_CLAMP) - device->BindSampler(PS, wiRenderer::samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindSampler(PS, wiRenderer::GetSampler(SSLOT_LINEAR_CLAMP), SSLOT_ONDEMAND0, threadID); } else if (effects.quality == QUALITY_ANISOTROPIC) { if (effects.sampleFlag == SAMPLEMODE_MIRROR) - device->BindSampler(PS, wiRenderer::samplers[SSLOT_ANISO_MIRROR], SSLOT_ONDEMAND0, threadID); + device->BindSampler(PS, wiRenderer::GetSampler(SSLOT_ANISO_MIRROR), SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_WRAP) - device->BindSampler(PS, wiRenderer::samplers[SSLOT_ANISO_WRAP], SSLOT_ONDEMAND0, threadID); + device->BindSampler(PS, wiRenderer::GetSampler(SSLOT_ANISO_WRAP), SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_CLAMP) - device->BindSampler(PS, wiRenderer::samplers[SSLOT_ANISO_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindSampler(PS, wiRenderer::GetSampler(SSLOT_ANISO_CLAMP), SSLOT_ONDEMAND0, threadID); } if (effects.presentFullScreen) @@ -670,7 +672,7 @@ void wiImage::DrawDeferred(Texture2D* lightmap_diffuse, Texture2D* lightmap_spec } -void wiImage::Load() +void wiImage::Initialize() { LoadBuffers(); SetUpStates(); diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h index 30be1d13f..17c568be6 100644 --- a/WickedEngine/wiImage.h +++ b/WickedEngine/wiImage.h @@ -100,7 +100,7 @@ public: static void DrawDeferred(wiGraphicsTypes::Texture2D* lightmap_diffuse, wiGraphicsTypes::Texture2D* lightmap_specular, wiGraphicsTypes::Texture2D* ao, GRAPHICSTHREAD threadID, int stencilref = 0); - static void Load(); + static void Initialize(); static void CleanUp(); }; diff --git a/WickedEngine/wiInitializer.cpp b/WickedEngine/wiInitializer.cpp index e1a3bcc23..433e34605 100644 --- a/WickedEngine/wiInitializer.cpp +++ b/WickedEngine/wiInitializer.cpp @@ -23,18 +23,13 @@ namespace wiInitializer wiFrameRate::Initialize(); wiCpuInfo::Initialize(); - wiRenderer::SetUpStaticComponents(); + wiRenderer::Initialize(); wiLensFlare::Initialize(); - - wiImage::Load(); - + wiImage::Initialize(); wiFont::Initialize(); - wiFont::SetUpStaticComponents(); - - wiOcean::SetUpStatic(); + wiOcean::Initialize(); wiWidget::LoadShaders(); - wiGPUSortLib::LoadShaders(); if (FAILED(wiSoundEffect::Initialize()) || FAILED(wiMusic::Initialize())) diff --git a/WickedEngine/wiLensFlare.cpp b/WickedEngine/wiLensFlare.cpp index 448867d7f..698417089 100644 --- a/WickedEngine/wiLensFlare.cpp +++ b/WickedEngine/wiLensFlare.cpp @@ -67,12 +67,13 @@ void wiLensFlare::Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, const void wiLensFlare::LoadShaders() { - vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "lensFlareVS.cso", wiResourceManager::VERTEXSHADER)); + std::string path = wiRenderer::GetShaderPath(); + + vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(path+ "lensFlareVS.cso", wiResourceManager::VERTEXSHADER)); + pixelShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "lensFlarePS.cso", wiResourceManager::PIXELSHADER)); - pixelShader = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "lensFlarePS.cso", wiResourceManager::PIXELSHADER)); - - geometryShader = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "lensFlareGS.cso", wiResourceManager::GEOMETRYSHADER)); + geometryShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "lensFlareGS.cso", wiResourceManager::GEOMETRYSHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/wiOcean.cpp b/WickedEngine/wiOcean.cpp index 68ec90c34..2da06accb 100644 --- a/WickedEngine/wiOcean.cpp +++ b/WickedEngine/wiOcean.cpp @@ -371,15 +371,17 @@ void wiOcean::Render(const CameraComponent& camera, float time, GRAPHICSTHREAD t void wiOcean::LoadShaders() { - m_pUpdateSpectrumCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanSimulatorCS.cso", wiResourceManager::COMPUTESHADER)); - m_pUpdateDisplacementMapCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanUpdateDisplacementMapCS.cso", wiResourceManager::COMPUTESHADER)); - m_pUpdateGradientFoldingCS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanUpdateGradientFoldingCS.cso", wiResourceManager::COMPUTESHADER)); + std::string path = wiRenderer::GetShaderPath(); + + m_pUpdateSpectrumCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanSimulatorCS.cso", wiResourceManager::COMPUTESHADER)); + m_pUpdateDisplacementMapCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanUpdateDisplacementMapCS.cso", wiResourceManager::COMPUTESHADER)); + m_pUpdateGradientFoldingCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanUpdateGradientFoldingCS.cso", wiResourceManager::COMPUTESHADER)); - g_pOceanSurfVS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanSurfaceVS.cso", wiResourceManager::VERTEXSHADER)); + g_pOceanSurfVS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanSurfaceVS.cso", wiResourceManager::VERTEXSHADER)); - g_pOceanSurfPS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanSurfacePS.cso", wiResourceManager::PIXELSHADER)); - g_pWireframePS = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanSurfaceSimplePS.cso", wiResourceManager::PIXELSHADER)); + g_pOceanSurfPS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanSurfacePS.cso", wiResourceManager::PIXELSHADER)); + g_pWireframePS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanSurfaceSimplePS.cso", wiResourceManager::PIXELSHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); @@ -412,7 +414,7 @@ void wiOcean::LoadShaders() } } -void wiOcean::SetUpStatic() +void wiOcean::Initialize() { GraphicsDevice* device = wiRenderer::GetDevice(); @@ -472,7 +474,7 @@ void wiOcean::SetUpStatic() fft512x512_create_plan(&m_fft_plan, 3); } -void wiOcean::CleanUpStatic() +void wiOcean::CleanUp() { fft512x512_destroy_plan(&m_fft_plan); diff --git a/WickedEngine/wiOcean.h b/WickedEngine/wiOcean.h index fc8bd801b..478207908 100644 --- a/WickedEngine/wiOcean.h +++ b/WickedEngine/wiOcean.h @@ -68,9 +68,10 @@ public: const wiOceanParameter& getParameters(); + + static void Initialize(); + static void CleanUp(); static void LoadShaders(); - static void SetUpStatic(); - static void CleanUpStatic(); XMFLOAT3 waterColor = XMFLOAT3(powf(0.07f, 1.0f / 2.2f), powf(0.15f, 1.0f / 2.2f), powf(0.2f, 1.0f / 2.2f)); float waterHeight = 0.0f; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 75869ce85..311c30e4c 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -31,6 +31,8 @@ #include "wiGPUSortLib.h" #include +#include +#include #include @@ -39,76 +41,116 @@ using namespace wiGraphicsTypes; using namespace wiSceneSystem; using namespace wiECS; -#pragma region STATICS -GraphicsDevice* wiRenderer::graphicsDevice = nullptr; -Sampler *wiRenderer::samplers[SSLOT_COUNT]; -VertexShader *wiRenderer::vertexShaders[VSTYPE_LAST]; -PixelShader *wiRenderer::pixelShaders[PSTYPE_LAST]; -GeometryShader *wiRenderer::geometryShaders[GSTYPE_LAST]; -HullShader *wiRenderer::hullShaders[HSTYPE_LAST]; -DomainShader *wiRenderer::domainShaders[DSTYPE_LAST]; -ComputeShader *wiRenderer::computeShaders[CSTYPE_LAST]; -VertexLayout *wiRenderer::vertexLayouts[VLTYPE_LAST]; -RasterizerState *wiRenderer::rasterizers[RSTYPE_LAST]; -DepthStencilState *wiRenderer::depthStencils[DSSTYPE_LAST]; -BlendState *wiRenderer::blendStates[BSTYPE_LAST]; -GPUBuffer *wiRenderer::constantBuffers[CBTYPE_LAST]; -GPUBuffer *wiRenderer::resourceBuffers[RBTYPE_LAST]; -Texture *wiRenderer::textures[TEXTYPE_LAST]; -Sampler *wiRenderer::customsamplers[SSTYPE_LAST]; +namespace wiRenderer +{ -GPURingBuffer *wiRenderer::dynamicVertexBufferPool; +GraphicsDevice* graphicsDevice = nullptr; -float wiRenderer::GAMMA = 2.2f; -int wiRenderer::SHADOWRES_2D = 1024, wiRenderer::SHADOWRES_CUBE = 256, wiRenderer::SHADOWCOUNT_2D = 5 + 3 + 3, wiRenderer::SHADOWCOUNT_CUBE = 5, wiRenderer::SOFTSHADOWQUALITY_2D = 2; -bool wiRenderer::HAIRPARTICLEENABLED=true,wiRenderer::EMITTERSENABLED=true; -bool wiRenderer::TRANSPARENTSHADOWSENABLED = false; -bool wiRenderer::ALPHACOMPOSITIONENABLED = false; -bool wiRenderer::wireRender = false, wiRenderer::debugBoneLines = false, wiRenderer::debugPartitionTree = false, wiRenderer::debugEmitters = false, wiRenderer::freezeCullingCamera = false -, wiRenderer::debugEnvProbes = false, wiRenderer::debugForceFields = false, wiRenderer::debugCameras = false, wiRenderer::gridHelper = false, wiRenderer::voxelHelper = false, wiRenderer::requestReflectionRendering = false, wiRenderer::advancedLightCulling = true -, wiRenderer::advancedRefractions = false; -bool wiRenderer::ldsSkinningEnabled = true; -float wiRenderer::SPECULARAA = 0.0f; -float wiRenderer::renderTime = 0, wiRenderer::renderTime_Prev = 0, wiRenderer::deltaTime = 0; -XMFLOAT2 wiRenderer::temporalAAJitter = XMFLOAT2(0, 0), wiRenderer::temporalAAJitterPrev = XMFLOAT2(0, 0); -float wiRenderer::RESOLUTIONSCALE = 1.0f; -GPUQuery wiRenderer::occlusionQueries[]; -UINT wiRenderer::entityArrayOffset_Lights = 0, wiRenderer::entityArrayCount_Lights = 0; -UINT wiRenderer::entityArrayOffset_Decals = 0, wiRenderer::entityArrayCount_Decals = 0; -UINT wiRenderer::entityArrayOffset_ForceFields = 0, wiRenderer::entityArrayCount_ForceFields = 0; -UINT wiRenderer::entityArrayOffset_EnvProbes = 0, wiRenderer::entityArrayCount_EnvProbes = 0; +Sampler *samplers[SSLOT_COUNT] = {}; +VertexShader *vertexShaders[VSTYPE_LAST] = {}; +PixelShader *pixelShaders[PSTYPE_LAST] = {}; +GeometryShader *geometryShaders[GSTYPE_LAST] = {}; +HullShader *hullShaders[HSTYPE_LAST] = {}; +DomainShader *domainShaders[DSTYPE_LAST] = {}; +ComputeShader *computeShaders[CSTYPE_LAST] = {}; +VertexLayout *vertexLayouts[VLTYPE_LAST] = {}; +RasterizerState *rasterizers[RSTYPE_LAST] = {}; +DepthStencilState *depthStencils[DSSTYPE_LAST] = {}; +BlendState *blendStates[BSTYPE_LAST] = {}; +GPUBuffer *constantBuffers[CBTYPE_LAST] = {}; +GPUBuffer *resourceBuffers[RBTYPE_LAST] = {}; +Texture *textures[TEXTYPE_LAST] = {}; +Sampler *customsamplers[SSTYPE_LAST] = {}; +GPURingBuffer *dynamicVertexBufferPool = nullptr; -Texture2D* wiRenderer::enviroMap = nullptr; -float wiRenderer::GameSpeed=1; -bool wiRenderer::debugLightCulling = false; -bool wiRenderer::occlusionCulling = false; -bool wiRenderer::temporalAA = false, wiRenderer::temporalAADEBUG = false; -wiRenderer::VoxelizedSceneData wiRenderer::voxelSceneData = VoxelizedSceneData(); -PHYSICS* wiRenderer::physicsEngine = nullptr; -wiOcean* wiRenderer::ocean = nullptr; +string SHADERPATH = "shaders/"; + +float GAMMA = 2.2f; +int SHADOWRES_2D = 1024; +int SHADOWRES_CUBE = 256; +int SHADOWCOUNT_2D = 5 + 3 + 3; +int SHADOWCOUNT_CUBE = 5; +int SOFTSHADOWQUALITY_2D = 2; +bool TRANSPARENTSHADOWSENABLED = false; +bool ALPHACOMPOSITIONENABLED = false; +bool wireRender = false; +bool debugBoneLines = false; +bool debugPartitionTree = false; +bool debugEmitters = false; +bool freezeCullingCamera = false; +bool debugEnvProbes = false; +bool debugForceFields = false; +bool debugCameras = false; +bool gridHelper = false; +bool voxelHelper = false; +bool requestReflectionRendering = false; +bool advancedLightCulling = true; +bool advancedRefractions = false; +bool ldsSkinningEnabled = true; +float SPECULARAA = 0.0f; +float renderTime = 0; +float renderTime_Prev = 0; +float deltaTime = 0; +XMFLOAT2 temporalAAJitter = XMFLOAT2(0, 0); +XMFLOAT2 temporalAAJitterPrev = XMFLOAT2(0, 0); +float RESOLUTIONSCALE = 1.0f; +GPUQuery occlusionQueries[256]; +UINT entityArrayOffset_Lights = 0; +UINT entityArrayCount_Lights = 0; +UINT entityArrayOffset_Decals = 0; +UINT entityArrayCount_Decals = 0; +UINT entityArrayOffset_ForceFields = 0; +UINT entityArrayCount_ForceFields = 0; +UINT entityArrayOffset_EnvProbes = 0; +UINT entityArrayCount_EnvProbes = 0; +Texture2D* enviroMap = nullptr; +float GameSpeed = 1; +bool debugLightCulling = false; +bool occlusionCulling = false; +bool temporalAA = false; +bool temporalAADEBUG = false; + +struct VoxelizedSceneData +{ + bool enabled = false; + int res = 128; + float voxelsize = 1; + XMFLOAT3 center = XMFLOAT3(0, 0, 0); + XMFLOAT3 extents = XMFLOAT3(0, 0, 0); + int numCones = 8; + float rayStepSize = 0.5f; + bool secondaryBounceEnabled = true; + bool reflectionsEnabled = false; + bool centerChangedThisFrame = true; + UINT mips = 7; +} voxelSceneData; + +PHYSICS* physicsEngine = nullptr; +wiOcean* ocean = nullptr; Texture2D* shadowMapArray_2D = nullptr; Texture2D* shadowMapArray_Cube = nullptr; Texture2D* shadowMapArray_Transparent = nullptr; -string wiRenderer::SHADERPATH = "shaders/"; -#pragma endregion +deque waterRipples; -#pragma region STATIC TEMP +std::vector> renderableBoxes; +std::vector renderableLines; -deque wiRenderer::waterRipples; - -Scene* wiRenderer::scene = nullptr; - -std::vector> wiRenderer::renderableBoxes; -std::vector wiRenderer::renderableLines; - -XMFLOAT4 wiRenderer::waterPlane = XMFLOAT4(0, 1, 0, 0); +XMFLOAT4 waterPlane = XMFLOAT4(0, 1, 0, 0); wiSpinLock deferredMIPGenLock; unordered_set deferredMIPGens; -#pragma endregion + +void SetDevice(wiGraphicsTypes::GraphicsDevice* newDevice) +{ + graphicsDevice = newDevice; +} +GraphicsDevice* GetDevice() +{ + return graphicsDevice; +} struct FrameCulling @@ -233,27 +275,112 @@ GPUBuffer impostorVB_POS; GPUBuffer impostorVB_TEX; -void wiRenderer::Present(function drawToScreen1,function drawToScreen2,function drawToScreen3) +Sampler* GetSampler(int slot) { - GetDevice()->PresentBegin(); - - if(drawToScreen1!=nullptr) - drawToScreen1(); - if(drawToScreen2!=nullptr) - drawToScreen2(); - if(drawToScreen3!=nullptr) - drawToScreen3(); + return samplers[slot]; +} +VertexShader* GetVertexShader(VSTYPES id) +{ + return vertexShaders[id]; +} +HullShader* GetHullShader(VSTYPES id) +{ + return hullShaders[id]; +} +DomainShader* GetDomainShader(VSTYPES id) +{ + return domainShaders[id]; +} +GeometryShader* GetGeometryShader(VSTYPES id) +{ + return geometryShaders[id]; +} +PixelShader* GetPixelShader(PSTYPES id) +{ + return pixelShaders[id]; +} +ComputeShader* GetComputeShader(VSTYPES id) +{ + return computeShaders[id]; +} +VertexLayout* GetVertexLayout(VLTYPES id) +{ + return vertexLayouts[id]; +} +RasterizerState* GetRasterizerState(RSTYPES id) +{ + return rasterizers[id]; +} +DepthStencilState* GetDepthStencilState(DSSTYPES id) +{ + return depthStencils[id]; +} +BlendState* GetBlendState(BSTYPES id) +{ + return blendStates[id]; +} +GPUBuffer* GetConstantBuffer(CBTYPES id) +{ + return constantBuffers[id]; +} +Texture* GetTexture(TEXTYPES id) +{ + return textures[id]; +} - GetDevice()->PresentEnd(); +void ModifySampler(const SamplerDesc& desc, int slot) +{ + SAFE_DELETE(samplers[slot]); + samplers[slot] = new wiGraphicsTypes::Sampler; + GetDevice()->CreateSamplerState(&desc, samplers[slot]); +} - OcclusionCulling_Read(); +std::string& GetShaderPath() +{ + return SHADERPATH; +} +void ReloadShaders(const std::string& path) +{ + GetShaderPath() = path; - wiFrameRate::Frame(); + GetDevice()->WaitForGPU(); + wiResourceManager::GetShaderManager()->CleanUp(); + LoadShaders(); + wiHairParticle::LoadShaders(); + wiEmittedParticle::LoadShaders(); + wiFont::LoadShaders(); + wiImage::LoadShaders(); + wiLensFlare::LoadShaders(); + wiOcean::LoadShaders(); + CSFFT_512x512_Data_t::LoadShaders(); + wiWidget::LoadShaders(); + wiGPUSortLib::LoadShaders(); +} + +Scene& GetScene() +{ + static Scene scene; + return scene; +} +CameraComponent& GetCamera() +{ + static CameraComponent camera; + return camera; +} +CameraComponent& GetPrevCamera() +{ + static CameraComponent camera; + return camera; +} +CameraComponent& GetRefCamera() +{ + static CameraComponent camera; + return camera; } -void wiRenderer::SetUpStaticComponents() +void Initialize() { for (int i = 0; i < VSTYPE_LAST; ++i) { @@ -312,7 +439,7 @@ void wiRenderer::SetUpStaticComponents() SAFE_INIT(customsamplers[i]); } - GetCamera().CreatePerspective((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800); + GetCamera().CreatePerspective((float)GetInternalResolution().x, (float)GetInternalResolution().y, 0.1f, 800); SetUpStates(); LoadBuffers(); @@ -326,223 +453,13 @@ void wiRenderer::SetUpStaticComponents() SetShadowProps2D(SHADOWRES_2D, SHADOWCOUNT_2D, SOFTSHADOWQUALITY_2D); SetShadowPropsCube(SHADOWRES_CUBE, SHADOWCOUNT_CUBE); - // Set up impostor resources: - { - if (!impostorMaterialCB.IsValid()) - { - MaterialCB mcb; - ZeroMemory(&mcb, sizeof(mcb)); - mcb.baseColor = XMFLOAT4(1, 1, 1, 1); - mcb.texMulAdd = XMFLOAT4(1, 1, 0, 0); - mcb.normalMapStrength = 1.0f; - mcb.roughness = 1.0f; - mcb.reflectance = 1.0f; - mcb.metalness = 1.0f; - - GPUBufferDesc bd; - bd.BindFlags = BIND_CONSTANT_BUFFER; - bd.Usage = USAGE_IMMUTABLE; - bd.CPUAccessFlags = 0; - bd.ByteWidth = sizeof(MaterialCB); - SubresourceData initData; - initData.pSysMem = &mcb; - - GetDevice()->CreateBuffer(&bd, &initData, &impostorMaterialCB); - } - if (!impostorVB_POS.IsValid()) - { - const int count = 6 * 6; - - XMFLOAT3 impostorVertices_pos[count]; - XMFLOAT3 impostorVertices_nor[count]; - XMFLOAT2 impostorVertices_tex[count]; - - float stepX = 1.f / 6.f; - - // front - impostorVertices_pos[0] = XMFLOAT3(-1, 1, 0); - impostorVertices_nor[0] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[0] = XMFLOAT2(0, 0); - - impostorVertices_pos[1] = XMFLOAT3(-1, -1, 0); - impostorVertices_nor[1] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[1] = XMFLOAT2(0, 1); - - impostorVertices_pos[2] = XMFLOAT3(1, 1, 0); - impostorVertices_nor[2] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[2] = XMFLOAT2(stepX, 0); - - impostorVertices_pos[3] = XMFLOAT3(-1, -1, 0); - impostorVertices_nor[3] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[3] = XMFLOAT2(0, 1); - - impostorVertices_pos[4] = XMFLOAT3(1, -1, 0); - impostorVertices_nor[4] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[4] = XMFLOAT2(stepX, 1); - - impostorVertices_pos[5] = XMFLOAT3(1, 1, 0); - impostorVertices_nor[5] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[5] = XMFLOAT2(stepX, 0); - - // right - impostorVertices_pos[6] = XMFLOAT3(0, 1, -1); - impostorVertices_nor[6] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[6] = XMFLOAT2(stepX, 0); - - impostorVertices_pos[7] = XMFLOAT3(0, -1, -1); - impostorVertices_nor[7] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[7] = XMFLOAT2(stepX, 1); - - impostorVertices_pos[8] = XMFLOAT3(0, 1, 1); - impostorVertices_nor[8] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[8] = XMFLOAT2(stepX * 2, 0); - - impostorVertices_pos[9] = XMFLOAT3(0, -1, -1); - impostorVertices_nor[9] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[9] = XMFLOAT2(stepX, 1); - - impostorVertices_pos[10] = XMFLOAT3(0, -1, 1); - impostorVertices_nor[10] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[10] = XMFLOAT2(stepX * 2, 1); - - impostorVertices_pos[11] = XMFLOAT3(0, 1, 1); - impostorVertices_nor[11] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[11] = XMFLOAT2(stepX * 2, 0); - - // back - impostorVertices_pos[12] = XMFLOAT3(-1, 1, 0); - impostorVertices_nor[12] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[12] = XMFLOAT2(stepX * 3, 0); - - impostorVertices_pos[13] = XMFLOAT3(1, 1, 0); - impostorVertices_nor[13] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[13] = XMFLOAT2(stepX * 2, 0); - - impostorVertices_pos[14] = XMFLOAT3(-1, -1, 0); - impostorVertices_nor[14] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[14] = XMFLOAT2(stepX * 3, 1); - - impostorVertices_pos[15] = XMFLOAT3(-1, -1, 0); - impostorVertices_nor[15] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[15] = XMFLOAT2(stepX * 3, 1); - - impostorVertices_pos[16] = XMFLOAT3(1, 1, 0); - impostorVertices_nor[16] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[16] = XMFLOAT2(stepX * 2, 0); - - impostorVertices_pos[17] = XMFLOAT3(1, -1, 0); - impostorVertices_nor[17] = XMFLOAT3(0, 0, -1); - impostorVertices_tex[17] = XMFLOAT2(stepX * 2, 1); - - // left - impostorVertices_pos[18] = XMFLOAT3(0, 1, -1); - impostorVertices_nor[18] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[18] = XMFLOAT2(stepX * 4, 0); - - impostorVertices_pos[19] = XMFLOAT3(0, 1, 1); - impostorVertices_nor[19] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[19] = XMFLOAT2(stepX * 3, 0); - - impostorVertices_pos[20] = XMFLOAT3(0, -1, -1); - impostorVertices_nor[20] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[20] = XMFLOAT2(stepX * 4, 1); - - impostorVertices_pos[21] = XMFLOAT3(0, -1, -1); - impostorVertices_nor[21] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[21] = XMFLOAT2(stepX * 4, 1); - - impostorVertices_pos[22] = XMFLOAT3(0, 1, 1); - impostorVertices_nor[22] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[22] = XMFLOAT2(stepX * 3, 0); - - impostorVertices_pos[23] = XMFLOAT3(0, -1, 1); - impostorVertices_nor[23] = XMFLOAT3(1, 0, 0); - impostorVertices_tex[23] = XMFLOAT2(stepX * 3, 1); - - // bottom - impostorVertices_pos[24] = XMFLOAT3(-1, 0, 1); - impostorVertices_nor[24] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[24] = XMFLOAT2(stepX * 4, 0); - - impostorVertices_pos[25] = XMFLOAT3(1, 0, 1); - impostorVertices_nor[25] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[25] = XMFLOAT2(stepX * 5, 0); - - impostorVertices_pos[26] = XMFLOAT3(-1, 0, -1); - impostorVertices_nor[26] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[26] = XMFLOAT2(stepX * 4, 1); - - impostorVertices_pos[27] = XMFLOAT3(-1, 0, -1); - impostorVertices_nor[27] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[27] = XMFLOAT2(stepX * 4, 1); - - impostorVertices_pos[28] = XMFLOAT3(1, 0, 1); - impostorVertices_nor[28] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[28] = XMFLOAT2(stepX * 5, 0); - - impostorVertices_pos[29] = XMFLOAT3(1, 0, -1); - impostorVertices_nor[29] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[29] = XMFLOAT2(stepX * 5, 1); - - // top - impostorVertices_pos[30] = XMFLOAT3(-1, 0, 1); - impostorVertices_nor[30] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[30] = XMFLOAT2(stepX * 5, 0); - - impostorVertices_pos[31] = XMFLOAT3(-1, 0, -1); - impostorVertices_nor[31] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[31] = XMFLOAT2(stepX * 5, 1); - - impostorVertices_pos[32] = XMFLOAT3(1, 0, 1); - impostorVertices_nor[32] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[32] = XMFLOAT2(stepX * 6, 0); - - impostorVertices_pos[33] = XMFLOAT3(-1, 0, -1); - impostorVertices_nor[33] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[33] = XMFLOAT2(stepX * 5, 1); - - impostorVertices_pos[34] = XMFLOAT3(1, 0, -1); - impostorVertices_nor[34] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[34] = XMFLOAT2(stepX * 6, 1); - - impostorVertices_pos[35] = XMFLOAT3(1, 0, 1); - impostorVertices_nor[35] = XMFLOAT3(0, 1, 0); - impostorVertices_tex[35] = XMFLOAT2(stepX * 6, 0); - - - MeshComponent::Vertex_POS impostorVertices_POS[count]; - MeshComponent::Vertex_TEX impostorVertices_TEX[count]; - for (int i = 0; i < count; ++i) - { - impostorVertices_POS[i].FromFULL(impostorVertices_pos[i], impostorVertices_nor[i], 0); - impostorVertices_TEX[i].FromFULL(impostorVertices_tex[i]); - } - - - GPUBufferDesc bd; - ZeroMemory(&bd, sizeof(bd)); - bd.Usage = USAGE_IMMUTABLE; - bd.BindFlags = BIND_VERTEX_BUFFER; - bd.CPUAccessFlags = 0; - SubresourceData InitData; - ZeroMemory(&InitData, sizeof(InitData)); - InitData.pSysMem = impostorVertices_POS; - bd.ByteWidth = sizeof(impostorVertices_POS); - wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVB_POS); - InitData.pSysMem = impostorVertices_TEX; - bd.ByteWidth = sizeof(impostorVertices_TEX); - wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVB_TEX); - } - } } -void wiRenderer::CleanUpStatic() +void CleanUp() { - wiHairParticle::CleanUpStatic(); wiEmittedParticle::CleanUpStatic(); Cube::CleanUpStatic(); - for (int i = 0; i < VSTYPE_LAST; ++i) { SAFE_DELETE(vertexShaders[i]); @@ -610,7 +527,7 @@ void wiRenderer::CleanUpStatic() SAFE_DELETE(graphicsDevice); } -void wiRenderer::ClearWorld() +void ClearWorld() { GetDevice()->WaitForGPU(); @@ -629,143 +546,6 @@ void wiRenderer::ClearWorld() deferredMIPGens.clear(); deferredMIPGenLock.unlock(); } -float wiRenderer::GetGameSpeed() { return GameSpeed; } - - -bool wiRenderer::ResolutionChanged() -{ - //detect internal resolution change: - static float _savedresscale = GetResolutionScale(); - static uint64_t lastFrameInternalResChange = 0; - if (_savedresscale != GetResolutionScale() || lastFrameInternalResChange == GetDevice()->GetFrameCount()) - { - _savedresscale = GetResolutionScale(); - lastFrameInternalResChange = GetDevice()->GetFrameCount(); - return true; - } - - // detect device resolution change: - return GetDevice()->ResolutionChanged(); -} - - -void wiRenderer::LoadBuffers() -{ - GPUBufferDesc bd; - - // Ring buffer allows fast allocation of dynamic buffers for one frame: - dynamicVertexBufferPool = new GPURingBuffer; - bd.BindFlags = BIND_VERTEX_BUFFER; - bd.ByteWidth = 1024 * 1024 * 64; - bd.Usage = USAGE_DYNAMIC; - bd.CPUAccessFlags = CPU_ACCESS_WRITE; - bd.MiscFlags = 0; - GetDevice()->CreateBuffer(&bd, nullptr, dynamicVertexBufferPool); - GetDevice()->SetName(dynamicVertexBufferPool, "DynamicVertexBufferPool"); - - - for (int i = 0; i < CBTYPE_LAST; ++i) - { - constantBuffers[i] = new GPUBuffer; - } - - ZeroMemory( &bd, sizeof(bd) ); - bd.BindFlags = BIND_CONSTANT_BUFFER; - - //Persistent buffers... - - // Per World Constant buffer will be updated occasionally, so it should reside in DEFAULT GPU memory! - bd.CPUAccessFlags = 0; - bd.Usage = USAGE_DEFAULT; - bd.ByteWidth = sizeof(WorldCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_WORLD]); - GetDevice()->SetName(constantBuffers[CBTYPE_WORLD], "PerWorldConstantBuffer"); - - bd.ByteWidth = sizeof(FrameCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_FRAME]); - GetDevice()->SetName(constantBuffers[CBTYPE_FRAME], "PerFrameConstantBuffer"); - - // The other constant buffers will be updated frequently (> per frame) so they should reside in DYNAMIC GPU memory! - bd.Usage = USAGE_DYNAMIC; - bd.CPUAccessFlags = CPU_ACCESS_WRITE; - - bd.ByteWidth = sizeof(CameraCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_CAMERA]); - GetDevice()->SetName(constantBuffers[CBTYPE_FRAME], "PerFrameConstantBuffer"); - - bd.ByteWidth = sizeof(MiscCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_MISC]); - GetDevice()->SetName(constantBuffers[CBTYPE_MISC], "MiscConstantBuffer"); - - bd.ByteWidth = sizeof(APICB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_API]); - GetDevice()->SetName(constantBuffers[CBTYPE_API], "APIConstantBuffer"); - - - // On demand buffers... - - bd.ByteWidth = sizeof(VolumeLightCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_VOLUMELIGHT]); - - bd.ByteWidth = sizeof(DecalCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_DECAL]); - - bd.ByteWidth = sizeof(CubemapRenderCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_CUBEMAPRENDER]); - - bd.ByteWidth = sizeof(TessellationCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_TESSELLATION]); - - bd.ByteWidth = sizeof(DispatchParamsCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_DISPATCHPARAMS]); - - bd.ByteWidth = sizeof(CloudGeneratorCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_CLOUDGENERATOR]); - - bd.ByteWidth = sizeof(TracedRenderingCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_RAYTRACE]); - - bd.ByteWidth = sizeof(BVHCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_BVH]); - - bd.ByteWidth = sizeof(GenerateMIPChainCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_MIPGEN]); - - bd.ByteWidth = sizeof(FilterEnvmapCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_FILTERENVMAP]); - - bd.ByteWidth = sizeof(CopyTextureCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_COPYTEXTURE]); - - - - - - // Resource Buffers: - - for (int i = 0; i < RBTYPE_LAST; ++i) - { - resourceBuffers[i] = new GPUBuffer; - } - - bd.Usage = USAGE_DEFAULT; - bd.CPUAccessFlags = 0; - - - bd.ByteWidth = sizeof(ShaderEntityType) * MAX_SHADER_ENTITY_COUNT; - bd.BindFlags = BIND_SHADER_RESOURCE; - bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; - bd.StructureByteStride = sizeof(ShaderEntityType); - GetDevice()->CreateBuffer(&bd, nullptr, resourceBuffers[RBTYPE_ENTITYARRAY]); - - bd.ByteWidth = sizeof(XMMATRIX) * MATRIXARRAY_COUNT; - bd.BindFlags = BIND_SHADER_RESOURCE; - bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; - bd.StructureByteStride = sizeof(XMMATRIX); - GetDevice()->CreateBuffer(&bd, nullptr, resourceBuffers[RBTYPE_MATRIXARRAY]); - - SAFE_DELETE(resourceBuffers[RBTYPE_VOXELSCENE]); // lazy init on request -} enum OBJECTRENDERING_DOUBLESIDED { @@ -814,7 +594,7 @@ GraphicsPSO* PSO_object_water[SHADERTYPE_COUNT] = {}; GraphicsPSO* PSO_object_wire = nullptr; GraphicsPSO* GetObjectPSO(SHADERTYPE shaderType, bool doublesided, bool tessellation, const MaterialComponent& material, bool forceAlphaTestForDithering) { - if (wiRenderer::IsWireRender()) + if (IsWireRender()) { switch (shaderType) { @@ -1275,7 +1055,7 @@ GraphicsPSO* PSO_impostor[SHADERTYPE_COUNT] = {}; GraphicsPSO* PSO_captureimpostor = nullptr; GraphicsPSO* GetImpostorPSO(SHADERTYPE shaderType) { - if (wiRenderer::IsWireRender()) + if (IsWireRender()) { switch (shaderType) { @@ -1342,7 +1122,7 @@ enum TILEDLIGHTING_DEBUG ComputePSO* CPSO_tiledlighting[TILEDLIGHTING_TYPE_COUNT][TILEDLIGHTING_CULLING_COUNT][TILEDLIGHTING_DEBUG_COUNT] = {}; ComputePSO* CPSO[CSTYPE_LAST] = {}; -void wiRenderer::LoadShaders() +void LoadShaders() { GraphicsDevice* device = GetDevice(); @@ -2333,32 +2113,124 @@ void wiRenderer::LoadShaders() } thread_pool.clear(); } - -void wiRenderer::ReloadShaders(const std::string& path) +void LoadBuffers() { + GPUBufferDesc bd; - if (path.length() > 0) + // Ring buffer allows fast allocation of dynamic buffers for one frame: + dynamicVertexBufferPool = new GPURingBuffer; + bd.BindFlags = BIND_VERTEX_BUFFER; + bd.ByteWidth = 1024 * 1024 * 64; + bd.Usage = USAGE_DYNAMIC; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; + bd.MiscFlags = 0; + GetDevice()->CreateBuffer(&bd, nullptr, dynamicVertexBufferPool); + GetDevice()->SetName(dynamicVertexBufferPool, "DynamicVertexBufferPool"); + + + for (int i = 0; i < CBTYPE_LAST; ++i) { - SHADERPATH = path; + constantBuffers[i] = new GPUBuffer; } - GetDevice()->WaitForGPU(); + ZeroMemory(&bd, sizeof(bd)); + bd.BindFlags = BIND_CONSTANT_BUFFER; - wiResourceManager::GetShaderManager()->CleanUp(); - LoadShaders(); - wiHairParticle::LoadShaders(); - wiEmittedParticle::LoadShaders(); - wiFont::LoadShaders(); - wiImage::LoadShaders(); - wiLensFlare::LoadShaders(); - wiOcean::LoadShaders(); - CSFFT_512x512_Data_t::LoadShaders(); - wiWidget::LoadShaders(); - wiGPUSortLib::LoadShaders(); + //Persistent buffers... + + // Per World Constant buffer will be updated occasionally, so it should reside in DEFAULT GPU memory! + bd.CPUAccessFlags = 0; + bd.Usage = USAGE_DEFAULT; + bd.ByteWidth = sizeof(WorldCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_WORLD]); + GetDevice()->SetName(constantBuffers[CBTYPE_WORLD], "PerWorldConstantBuffer"); + + bd.ByteWidth = sizeof(FrameCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_FRAME]); + GetDevice()->SetName(constantBuffers[CBTYPE_FRAME], "PerFrameConstantBuffer"); + + // The other constant buffers will be updated frequently (> per frame) so they should reside in DYNAMIC GPU memory! + bd.Usage = USAGE_DYNAMIC; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; + + bd.ByteWidth = sizeof(CameraCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_CAMERA]); + GetDevice()->SetName(constantBuffers[CBTYPE_FRAME], "PerFrameConstantBuffer"); + + bd.ByteWidth = sizeof(MiscCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_MISC]); + GetDevice()->SetName(constantBuffers[CBTYPE_MISC], "MiscConstantBuffer"); + + bd.ByteWidth = sizeof(APICB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_API]); + GetDevice()->SetName(constantBuffers[CBTYPE_API], "APIConstantBuffer"); + + + // On demand buffers... + + bd.ByteWidth = sizeof(VolumeLightCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_VOLUMELIGHT]); + + bd.ByteWidth = sizeof(DecalCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_DECAL]); + + bd.ByteWidth = sizeof(CubemapRenderCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_CUBEMAPRENDER]); + + bd.ByteWidth = sizeof(TessellationCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_TESSELLATION]); + + bd.ByteWidth = sizeof(DispatchParamsCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_DISPATCHPARAMS]); + + bd.ByteWidth = sizeof(CloudGeneratorCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_CLOUDGENERATOR]); + + bd.ByteWidth = sizeof(TracedRenderingCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_RAYTRACE]); + + bd.ByteWidth = sizeof(BVHCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_BVH]); + + bd.ByteWidth = sizeof(GenerateMIPChainCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_MIPGEN]); + + bd.ByteWidth = sizeof(FilterEnvmapCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_FILTERENVMAP]); + + bd.ByteWidth = sizeof(CopyTextureCB); + GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_COPYTEXTURE]); + + + + + + // Resource Buffers: + + for (int i = 0; i < RBTYPE_LAST; ++i) + { + resourceBuffers[i] = new GPUBuffer; + } + + bd.Usage = USAGE_DEFAULT; + bd.CPUAccessFlags = 0; + + + bd.ByteWidth = sizeof(ShaderEntityType) * MAX_SHADER_ENTITY_COUNT; + bd.BindFlags = BIND_SHADER_RESOURCE; + bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; + bd.StructureByteStride = sizeof(ShaderEntityType); + GetDevice()->CreateBuffer(&bd, nullptr, resourceBuffers[RBTYPE_ENTITYARRAY]); + + bd.ByteWidth = sizeof(XMMATRIX) * MATRIXARRAY_COUNT; + bd.BindFlags = BIND_SHADER_RESOURCE; + bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; + bd.StructureByteStride = sizeof(XMMATRIX); + GetDevice()->CreateBuffer(&bd, nullptr, resourceBuffers[RBTYPE_MATRIXARRAY]); + + SAFE_DELETE(resourceBuffers[RBTYPE_VOXELSCENE]); // lazy init on request } - - -void wiRenderer::SetUpStates() +void SetUpStates() { for (int i = 0; i < SSLOT_COUNT; ++i) { @@ -2853,57 +2725,12 @@ void wiRenderer::SetUpStates() GetDevice()->CreateBlendState(&bd, blendStates[BSTYPE_TRANSPARENTSHADOWMAP]); } -void wiRenderer::BindPersistentState(GRAPHICSTHREAD threadID) -{ - GraphicsDevice* device = GetDevice(); - - for (int i = 0; i < SSLOT_COUNT; ++i) - { - device->BindSampler(PS, samplers[i], i, threadID); - device->BindSampler(VS, samplers[i], i, threadID); - device->BindSampler(GS, samplers[i], i, threadID); - device->BindSampler(DS, samplers[i], i, threadID); - device->BindSampler(HS, samplers[i], i, threadID); - device->BindSampler(CS, samplers[i], i, threadID); - } - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - device->BindConstantBuffer(VS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - device->BindConstantBuffer(GS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - device->BindConstantBuffer(HS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - device->BindConstantBuffer(DS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - device->BindConstantBuffer(VS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - device->BindConstantBuffer(GS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - device->BindConstantBuffer(HS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - device->BindConstantBuffer(DS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - device->BindConstantBuffer(VS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - device->BindConstantBuffer(GS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - device->BindConstantBuffer(HS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - device->BindConstantBuffer(DS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - - device->BindConstantBuffer(VS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - device->BindConstantBuffer(GS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - device->BindConstantBuffer(DS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - device->BindConstantBuffer(HS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - - device->BindConstantBuffer(VS, constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID); - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID); -} - -void wiRenderer::FixedUpdate() +void FixedUpdate() { } -void wiRenderer::UpdatePerFrameData(float dt) +void UpdatePerFrameData(float dt) { Scene& scene = GetScene(); @@ -3103,7 +2930,7 @@ void wiRenderer::UpdatePerFrameData(float dt) renderTime += dt * GetGameSpeed(); deltaTime = dt; } -void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) +void UpdateRenderData(GRAPHICSTHREAD threadID) { GraphicsDevice* device = GetDevice(); Scene& scene = GetScene(); @@ -3523,7 +3350,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) // Render out of date environment probes: RefreshEnvProbes(threadID); } -void wiRenderer::OcclusionCulling_Render(GRAPHICSTHREAD threadID) +void OcclusionCulling_Render(GRAPHICSTHREAD threadID) { if (!GetOcclusionCullingEnabled() || GetFreezeCullingCameraEnabled()) { @@ -3598,7 +3425,7 @@ void wiRenderer::OcclusionCulling_Render(GRAPHICSTHREAD threadID) wiProfiler::GetInstance().EndRange(threadID); // Occlusion Culling Render } -void wiRenderer::OcclusionCulling_Read() +void OcclusionCulling_Read() { if (!GetOcclusionCullingEnabled() || GetFreezeCullingCameraEnabled()) { @@ -3653,7 +3480,13 @@ void wiRenderer::OcclusionCulling_Read() wiProfiler::GetInstance().EndRange(); // Occlusion Culling Read } -void wiRenderer::PutWaterRipple(const std::string& image, const XMFLOAT3& pos) +void EndFrame() +{ + OcclusionCulling_Read(); + wiFrameRate::Frame(); +} + +void PutWaterRipple(const std::string& image, const XMFLOAT3& pos) { wiSprite* img=new wiSprite("","",image); img->anim.fad=0.01f; @@ -3669,14 +3502,14 @@ void wiRenderer::PutWaterRipple(const std::string& image, const XMFLOAT3& pos) img->effects.lookAt.w=1; waterRipples.push_back(img); } -void wiRenderer::ManageWaterRipples(){ +void ManageWaterRipples(){ while( !waterRipples.empty() && (waterRipples.front()->effects.opacity <= 0 + FLT_EPSILON || waterRipples.front()->effects.fade==1) ) waterRipples.pop_front(); } -void wiRenderer::DrawWaterRipples(GRAPHICSTHREAD threadID) +void DrawWaterRipples(GRAPHICSTHREAD threadID) { GetDevice()->EventBegin("Water Ripples", threadID); for(wiSprite* i:waterRipples){ @@ -3685,433 +3518,8 @@ void wiRenderer::DrawWaterRipples(GRAPHICSTHREAD threadID) GetDevice()->EventEnd(threadID); } -void wiRenderer::DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) -{ - GraphicsDevice* device = GetDevice(); - Scene& scene = GetScene(); - - device->EventBegin("DrawDebugWorld", threadID); - - if (debugBoneLines) - { - device->EventBegin("DebugBoneLines", threadID); - - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); - - MiscCB sb; - XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); - sb.g_xColor = XMFLOAT4(1, 1, 1, 1); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - - for (size_t i = 0; i < scene.armatures.GetCount(); ++i) - { - const ArmatureComponent& armature = scene.armatures[i]; - - if (armature.boneCollection.empty()) - { - continue; - } - - struct LineSegment - { - XMFLOAT4 a, colorA, b, colorB; - }; - UINT offset; - void* mem = device->AllocateFromRingBuffer(dynamicVertexBufferPool, sizeof(LineSegment) * armature.boneCollection.size(), offset, threadID); - - int j = 0; - for (Entity entity : armature.boneCollection) - { - const TransformComponent& transform = *scene.transforms.GetComponent(entity); - - XMMATRIX world = XMLoadFloat4x4(&transform.world); - XMVECTOR a = XMVectorSet(0, 0, 0, 1); - XMVECTOR b = XMVectorSet(0, 0, 1, 1); - - a = XMVector4Transform(a, world); - b = XMVector4Transform(b, world); - - - LineSegment segment; - XMStoreFloat4(&segment.a, a); - XMStoreFloat4(&segment.b, b); - - memcpy((void*)((size_t)mem + j * sizeof(LineSegment)), &segment, sizeof(LineSegment)); - j++; - } - - device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); - - GPUBuffer* vbs[] = { - dynamicVertexBufferPool, - }; - const UINT strides[] = { - sizeof(XMFLOAT4) + sizeof(XMFLOAT4), - }; - const UINT offsets[] = { - offset, - }; - device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID); - - device->Draw(2 * j, 0, threadID); - - } - - device->EventEnd(threadID); - } - - if (!renderableLines.empty()) - { - device->EventBegin("DebugLines", threadID); - - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); - - MiscCB sb; - XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); - sb.g_xColor = XMFLOAT4(1, 1, 1, 1); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - - struct LineSegment - { - XMFLOAT4 a, colorA, b, colorB; - }; - UINT offset; - void* mem = device->AllocateFromRingBuffer(dynamicVertexBufferPool, sizeof(LineSegment) * renderableLines.size(), offset, threadID); - - int i = 0; - for (auto& line : renderableLines) - { - LineSegment segment; - segment.a = XMFLOAT4(line.start.x, line.start.y, line.start.z, 1); - segment.b = XMFLOAT4(line.end.x, line.end.y, line.end.z, 1); - segment.colorA = segment.colorB = line.color; - - memcpy((void*)((size_t)mem + i * sizeof(LineSegment)), &segment, sizeof(LineSegment)); - i++; - } - - device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); - - GPUBuffer* vbs[] = { - dynamicVertexBufferPool, - }; - const UINT strides[] = { - sizeof(XMFLOAT4) + sizeof(XMFLOAT4), - }; - const UINT offsets[] = { - offset, - }; - device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID); - - device->Draw(2 * i, 0, threadID); - - renderableLines.clear(); - - device->EventEnd(threadID); - } - - if (!renderableBoxes.empty()) - { - device->EventBegin("DebugBoxes", threadID); - - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); - - GPUBuffer* vbs[] = { - &Cube::vertexBuffer, - }; - const UINT strides[] = { - sizeof(XMFLOAT4) + sizeof(XMFLOAT4), - }; - device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); - - MiscCB sb; - - for (auto& x : renderableBoxes) - { - XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&x.first)*camera.GetViewProjection())); - sb.g_xColor = x.second; - - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - - device->DrawIndexed(24, 0, 0, threadID); - } - renderableBoxes.clear(); - - device->EventEnd(threadID); - } - - - if (debugEnvProbes) - { - device->EventBegin("Debug EnvProbes", threadID); - // Envmap spheres: - - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_ENVPROBE], threadID); - - MiscCB sb; - for (size_t i = 0; i < scene.probes.GetCount(); ++i) - { - EnvironmentProbeComponent& probe = scene.probes[i]; - - XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&probe.position)))); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - - if (probe.textureIndex < 0) - { - device->BindResource(PS, wiTextureHelper::getInstance()->getBlackCubeMap(), TEXSLOT_ONDEMAND0, threadID); - } - else - { - device->BindResource(PS, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], TEXSLOT_ONDEMAND0, threadID, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]->GetDesc().MipLevels + probe.textureIndex); - } - - device->Draw(2880, 0, threadID); // uv-sphere - } - - - // Local proxy boxes: - - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); - - GPUBuffer* vbs[] = { - &Cube::vertexBuffer, - }; - const UINT strides[] = { - sizeof(XMFLOAT4) + sizeof(XMFLOAT4), - }; - device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); - - for (size_t i = 0; i < scene.probes.GetCount(); ++i) - { - EnvironmentProbeComponent& probe = scene.probes[i]; - - if (probe.textureIndex < 0) - { - continue; - } - - Entity entity = scene.probes.GetEntity(i); - const TransformComponent& transform = *scene.transforms.GetComponent(entity); - - XMStoreFloat4x4(&sb.g_xTransform , XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection())); - sb.g_xColor = float4(0, 1, 1, 1); - - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - - device->DrawIndexed(24, 0, 0, threadID); - } - - device->EventEnd(threadID); - } - - - if (gridHelper) - { - device->EventBegin("GridHelper", threadID); - - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_GRID], threadID); - - static float col = 0.7f; - static int gridVertexCount = 0; - static GPUBuffer* grid = nullptr; - if (grid == nullptr) - { - const float h = 0.01f; // avoid z-fight with zero plane - const int a = 20; - XMFLOAT4 verts[((a + 1) * 2 + (a + 1) * 2) * 2]; - - int count = 0; - for (int i = 0; i <= a; ++i) - { - verts[count++] = XMFLOAT4(i - a * 0.5f, h, -a * 0.5f, 1); - verts[count++] = (i == a / 2 ? XMFLOAT4(0, 0, 1, 1) : XMFLOAT4(col, col, col, 1)); - - verts[count++] = XMFLOAT4(i - a * 0.5f, h, +a * 0.5f, 1); - verts[count++] = (i == a / 2 ? XMFLOAT4(0, 0, 1, 1) : XMFLOAT4(col, col, col, 1)); - } - for (int j = 0; j <= a; ++j) - { - verts[count++] = XMFLOAT4(-a * 0.5f, h, j - a * 0.5f, 1); - verts[count++] = (j == a / 2 ? XMFLOAT4(1, 0, 0, 1) : XMFLOAT4(col, col, col, 1)); - - verts[count++] = XMFLOAT4(+a * 0.5f, h, j - a * 0.5f, 1); - verts[count++] = (j == a / 2 ? XMFLOAT4(1, 0, 0, 1) : XMFLOAT4(col, col, col, 1)); - } - - gridVertexCount = ARRAYSIZE(verts) / 2; - - GPUBufferDesc bd; - ZeroMemory(&bd, sizeof(bd)); - bd.Usage = USAGE_IMMUTABLE; - bd.ByteWidth = sizeof(verts); - bd.BindFlags = BIND_VERTEX_BUFFER; - bd.CPUAccessFlags = 0; - SubresourceData InitData; - ZeroMemory(&InitData, sizeof(InitData)); - InitData.pSysMem = verts; - grid = new GPUBuffer; - device->CreateBuffer(&bd, &InitData, grid); - } - - MiscCB sb; - XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); - sb.g_xColor = float4(1, 1, 1, 1); - - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - - GPUBuffer* vbs[] = { - grid, - }; - const UINT strides[] = { - sizeof(XMFLOAT4) + sizeof(XMFLOAT4), - }; - device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - device->Draw(gridVertexCount, 0, threadID); - - device->EventEnd(threadID); - } - - if (voxelHelper && textures[TEXTYPE_3D_VOXELRADIANCE] != nullptr) - { - device->EventBegin("Debug Voxels", threadID); - - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_VOXEL], threadID); - - - MiscCB sb; - XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&voxelSceneData.center)) * camera.GetViewProjection())); - sb.g_xColor = float4(1, 1, 1, 1); - - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - - device->Draw(voxelSceneData.res * voxelSceneData.res * voxelSceneData.res, 0, threadID); - - device->EventEnd(threadID); - } - - if (debugEmitters) - { - device->EventBegin("DebugEmitters", threadID); - - MiscCB sb; - for (size_t i = 0; i < scene.emitters.GetCount(); ++i) - { - const wiEmittedParticle& emitter = scene.emitters[i]; - Entity entity = scene.emitters.GetEntity(i); - const TransformComponent& transform = *scene.transforms.GetComponent(entity); - const MeshComponent* mesh = scene.meshes.GetComponent(emitter.meshID); - - XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection())); - sb.g_xColor = float4(0, 1, 0, 1); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - - if (mesh == nullptr) - { - // No mesh, just draw a box: - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); - GPUBuffer* vbs[] = { - &Cube::vertexBuffer, - }; - const UINT strides[] = { - sizeof(XMFLOAT4) + sizeof(XMFLOAT4), - }; - device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); - device->DrawIndexed(24, 0, 0, threadID); - } - else - { - // Draw mesh wireframe: - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_EMITTER], threadID); - GPUBuffer* vbs[] = { - mesh->streamoutBuffer_POS != nullptr ? mesh->streamoutBuffer_POS.get() : mesh->vertexBuffer_POS.get(), - }; - const UINT strides[] = { - sizeof(MeshComponent::Vertex_POS), - }; - device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - device->BindIndexBuffer(mesh->indexBuffer.get(), mesh->GetIndexFormat(), 0, threadID); - - device->DrawIndexed((int)mesh->indices.size(), 0, 0, threadID); - } - } - - device->EventEnd(threadID); - } - - - if (debugForceFields) - { - device->EventBegin("DebugForceFields", threadID); - - MiscCB sb; - for (size_t i = 0; i < scene.forces.GetCount(); ++i) - { - ForceFieldComponent& force = scene.forces[i]; - - XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); - sb.g_xColor = XMFLOAT4(camera.Eye.x, camera.Eye.y, camera.Eye.z, (float)i); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - - switch (force.type) - { - case ENTITY_TYPE_FORCEFIELD_POINT: - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_FORCEFIELD_POINT], threadID); - device->Draw(2880, 0, threadID); // uv-sphere - break; - case ENTITY_TYPE_FORCEFIELD_PLANE: - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_FORCEFIELD_PLANE], threadID); - device->Draw(14, 0, threadID); // box - break; - } - - ++i; - } - - device->EventEnd(threadID); - } - - - if (debugCameras) - { - device->EventBegin("DebugCameras", threadID); - - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); - - GPUBuffer* vbs[] = { - &Cube::vertexBuffer, - }; - const UINT strides[] = { - sizeof(XMFLOAT4) + sizeof(XMFLOAT4), - }; - device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); - - MiscCB sb; - sb.g_xColor = XMFLOAT4(1, 1, 1, 1); - - for(size_t i = 0; i < scene.cameras.GetCount(); ++i) - { - const CameraComponent& cam = scene.cameras[i]; - Entity entity = scene.cameras.GetEntity(i); - - XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(cam.GetInvView()*camera.GetViewProjection())); - - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - - device->DrawIndexed(24, 0, 0, threadID); - } - - device->EventEnd(threadID); - } - - device->EventEnd(threadID); -} - -void wiRenderer::DrawSoftParticles(const CameraComponent& camera, bool distortion, GRAPHICSTHREAD threadID) +void DrawSoftParticles(const CameraComponent& camera, bool distortion, GRAPHICSTHREAD threadID) { Scene& scene = GetScene(); @@ -4132,7 +3540,7 @@ void wiRenderer::DrawSoftParticles(const CameraComponent& camera, bool distortio } } -void wiRenderer::DrawTrails(GRAPHICSTHREAD threadID, Texture2D* refracRes) +void DrawTrails(GRAPHICSTHREAD threadID, Texture2D* refracRes) { //if (objectsWithTrails.empty()) //{ @@ -4226,7 +3634,7 @@ void wiRenderer::DrawTrails(GRAPHICSTHREAD threadID, Texture2D* refracRes) //GetDevice()->EventEnd(threadID); } -void wiRenderer::DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) +void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) { const FrameCulling& culling = frameCullings[&camera]; const auto& culledLights = culling.culledLights; @@ -4303,7 +3711,7 @@ void wiRenderer::DrawLights(const CameraComponent& camera, GRAPHICSTHREAD thread wiProfiler::GetInstance().EndRange(threadID); GetDevice()->EventEnd(threadID); } -void wiRenderer::DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID) +void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID) { Scene& scene = GetScene(); @@ -4418,7 +3826,7 @@ void wiRenderer::DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHR } -void wiRenderer::DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) +void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) { const FrameCulling& culling = frameCullings[&camera]; const auto& culledLights = culling.culledLights; @@ -4500,7 +3908,7 @@ void wiRenderer::DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD } -void wiRenderer::DrawLensFlares(GRAPHICSTHREAD threadID) +void DrawLensFlares(GRAPHICSTHREAD threadID) { const CameraComponent& camera = GetCamera(); @@ -4538,66 +3946,90 @@ void wiRenderer::DrawLensFlares(GRAPHICSTHREAD threadID) } } -void wiRenderer::SetShadowProps2D(int resolution, int count, int softShadowQuality) +void SetShadowProps2D(int resolution, int count, int softShadowQuality) { - SHADOWRES_2D = resolution; - SHADOWCOUNT_2D = count; - SOFTSHADOWQUALITY_2D = softShadowQuality; + if (resolution >= 0) + { + SHADOWRES_2D = resolution; + } + if (count >= 0) + { + SHADOWCOUNT_2D = count; + } + if (softShadowQuality >= 0) + { + SOFTSHADOWQUALITY_2D = softShadowQuality; + } - SAFE_DELETE(shadowMapArray_2D); - shadowMapArray_2D = new Texture2D; - shadowMapArray_2D->RequestIndependentRenderTargetArraySlices(true); + if (SHADOWCOUNT_2D > 0) + { + SAFE_DELETE(shadowMapArray_2D); + shadowMapArray_2D = new Texture2D; + shadowMapArray_2D->RequestIndependentRenderTargetArraySlices(true); - SAFE_DELETE(shadowMapArray_Transparent); - shadowMapArray_Transparent = new Texture2D; - shadowMapArray_Transparent->RequestIndependentRenderTargetArraySlices(true); + SAFE_DELETE(shadowMapArray_Transparent); + shadowMapArray_Transparent = new Texture2D; + shadowMapArray_Transparent->RequestIndependentRenderTargetArraySlices(true); - TextureDesc desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Width = SHADOWRES_2D; - desc.Height = SHADOWRES_2D; - desc.MipLevels = 1; - desc.ArraySize = SHADOWCOUNT_2D; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = USAGE_DEFAULT; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; + TextureDesc desc; + ZeroMemory(&desc, sizeof(desc)); + desc.Width = SHADOWRES_2D; + desc.Height = SHADOWRES_2D; + desc.MipLevels = 1; + desc.ArraySize = SHADOWCOUNT_2D; + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; + desc.Usage = USAGE_DEFAULT; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; - desc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE; - desc.Format = DSFormat_small_alias; - GetDevice()->CreateTexture2D(&desc, nullptr, &shadowMapArray_2D); + desc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE; + desc.Format = DSFormat_small_alias; + GetDevice()->CreateTexture2D(&desc, nullptr, &shadowMapArray_2D); + + desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; + desc.Format = RTFormat_ldr; + GetDevice()->CreateTexture2D(&desc, nullptr, &shadowMapArray_Transparent); + } - desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; - desc.Format = RTFormat_ldr; - GetDevice()->CreateTexture2D(&desc, nullptr, &shadowMapArray_Transparent); } -void wiRenderer::SetShadowPropsCube(int resolution, int count) +void SetShadowPropsCube(int resolution, int count) { - SHADOWRES_CUBE = resolution; - SHADOWCOUNT_CUBE = count; + if (resolution >= 0) + { + SHADOWRES_CUBE = resolution; + } + if (count >= 0) + { + SHADOWCOUNT_CUBE = count; + } - SAFE_DELETE(shadowMapArray_Cube); - shadowMapArray_Cube = new Texture2D; - shadowMapArray_Cube->RequestIndependentRenderTargetArraySlices(true); - shadowMapArray_Cube->RequestIndependentRenderTargetCubemapFaces(false); + if (SHADOWCOUNT_CUBE > 0) + { + + SAFE_DELETE(shadowMapArray_Cube); + shadowMapArray_Cube = new Texture2D; + shadowMapArray_Cube->RequestIndependentRenderTargetArraySlices(true); + shadowMapArray_Cube->RequestIndependentRenderTargetCubemapFaces(false); + + TextureDesc desc; + ZeroMemory(&desc, sizeof(desc)); + desc.Width = SHADOWRES_CUBE; + desc.Height = SHADOWRES_CUBE; + desc.MipLevels = 1; + desc.ArraySize = 6 * SHADOWCOUNT_CUBE; + desc.Format = DSFormat_small_alias; + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; + desc.Usage = USAGE_DEFAULT; + desc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + desc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; + GetDevice()->CreateTexture2D(&desc, nullptr, &shadowMapArray_Cube); + } - TextureDesc desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Width = SHADOWRES_CUBE; - desc.Height = SHADOWRES_CUBE; - desc.MipLevels = 1; - desc.ArraySize = 6 * SHADOWCOUNT_CUBE; - desc.Format = DSFormat_small_alias; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = USAGE_DEFAULT; - desc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = 0; - desc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; - GetDevice()->CreateTexture2D(&desc, nullptr, &shadowMapArray_Cube); } -void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask) +void DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask) { if (wireRender) return; @@ -4876,7 +4308,7 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask) } } -void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culledRenderer, SHADERTYPE shaderType, UINT renderTypeFlags, GRAPHICSTHREAD threadID, +void RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culledRenderer, SHADERTYPE shaderType, UINT renderTypeFlags, GRAPHICSTHREAD threadID, bool tessellation, bool occlusionCulling, uint32_t layerMask) { // Intensive section, refactor and optimize! @@ -5315,7 +4747,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle } } -void wiRenderer::DrawWorld(const CameraComponent& camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling, uint32_t layerMask) +void DrawWorld(const CameraComponent& camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling, uint32_t layerMask) { const FrameCulling& culling = frameCullings[&camera]; @@ -5359,7 +4791,7 @@ void wiRenderer::DrawWorld(const CameraComponent& camera, bool tessellation, GRA } -void wiRenderer::DrawWorldTransparent(const CameraComponent& camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling, uint32_t layerMask) +void DrawWorldTransparent(const CameraComponent& camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling, uint32_t layerMask) { const FrameCulling& culling = frameCullings[&camera]; @@ -5402,8 +4834,433 @@ void wiRenderer::DrawWorldTransparent(const CameraComponent& camera, SHADERTYPE GetDevice()->EventEnd(threadID); } +void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) +{ + GraphicsDevice* device = GetDevice(); -void wiRenderer::DrawSky(GRAPHICSTHREAD threadID) + Scene& scene = GetScene(); + + device->EventBegin("DrawDebugWorld", threadID); + + if (debugBoneLines) + { + device->EventBegin("DebugBoneLines", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); + + MiscCB sb; + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); + sb.g_xColor = XMFLOAT4(1, 1, 1, 1); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + for (size_t i = 0; i < scene.armatures.GetCount(); ++i) + { + const ArmatureComponent& armature = scene.armatures[i]; + + if (armature.boneCollection.empty()) + { + continue; + } + + struct LineSegment + { + XMFLOAT4 a, colorA, b, colorB; + }; + UINT offset; + void* mem = device->AllocateFromRingBuffer(dynamicVertexBufferPool, sizeof(LineSegment) * armature.boneCollection.size(), offset, threadID); + + int j = 0; + for (Entity entity : armature.boneCollection) + { + const TransformComponent& transform = *scene.transforms.GetComponent(entity); + + XMMATRIX world = XMLoadFloat4x4(&transform.world); + XMVECTOR a = XMVectorSet(0, 0, 0, 1); + XMVECTOR b = XMVectorSet(0, 0, 1, 1); + + a = XMVector4Transform(a, world); + b = XMVector4Transform(b, world); + + + LineSegment segment; + XMStoreFloat4(&segment.a, a); + XMStoreFloat4(&segment.b, b); + + memcpy((void*)((size_t)mem + j * sizeof(LineSegment)), &segment, sizeof(LineSegment)); + j++; + } + + device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); + + GPUBuffer* vbs[] = { + dynamicVertexBufferPool, + }; + const UINT strides[] = { + sizeof(XMFLOAT4) + sizeof(XMFLOAT4), + }; + const UINT offsets[] = { + offset, + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID); + + device->Draw(2 * j, 0, threadID); + + } + + device->EventEnd(threadID); + } + + if (!renderableLines.empty()) + { + device->EventBegin("DebugLines", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); + + MiscCB sb; + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); + sb.g_xColor = XMFLOAT4(1, 1, 1, 1); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + struct LineSegment + { + XMFLOAT4 a, colorA, b, colorB; + }; + UINT offset; + void* mem = device->AllocateFromRingBuffer(dynamicVertexBufferPool, sizeof(LineSegment) * renderableLines.size(), offset, threadID); + + int i = 0; + for (auto& line : renderableLines) + { + LineSegment segment; + segment.a = XMFLOAT4(line.start.x, line.start.y, line.start.z, 1); + segment.b = XMFLOAT4(line.end.x, line.end.y, line.end.z, 1); + segment.colorA = segment.colorB = line.color; + + memcpy((void*)((size_t)mem + i * sizeof(LineSegment)), &segment, sizeof(LineSegment)); + i++; + } + + device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); + + GPUBuffer* vbs[] = { + dynamicVertexBufferPool, + }; + const UINT strides[] = { + sizeof(XMFLOAT4) + sizeof(XMFLOAT4), + }; + const UINT offsets[] = { + offset, + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID); + + device->Draw(2 * i, 0, threadID); + + renderableLines.clear(); + + device->EventEnd(threadID); + } + + if (!renderableBoxes.empty()) + { + device->EventBegin("DebugBoxes", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + + GPUBuffer* vbs[] = { + &Cube::vertexBuffer, + }; + const UINT strides[] = { + sizeof(XMFLOAT4) + sizeof(XMFLOAT4), + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); + + MiscCB sb; + + for (auto& x : renderableBoxes) + { + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&x.first)*camera.GetViewProjection())); + sb.g_xColor = x.second; + + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + device->DrawIndexed(24, 0, 0, threadID); + } + renderableBoxes.clear(); + + device->EventEnd(threadID); + } + + + if (debugEnvProbes) + { + device->EventBegin("Debug EnvProbes", threadID); + // Envmap spheres: + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_ENVPROBE], threadID); + + MiscCB sb; + for (size_t i = 0; i < scene.probes.GetCount(); ++i) + { + EnvironmentProbeComponent& probe = scene.probes[i]; + + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&probe.position)))); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + if (probe.textureIndex < 0) + { + device->BindResource(PS, wiTextureHelper::getInstance()->getBlackCubeMap(), TEXSLOT_ONDEMAND0, threadID); + } + else + { + device->BindResource(PS, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], TEXSLOT_ONDEMAND0, threadID, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]->GetDesc().MipLevels + probe.textureIndex); + } + + device->Draw(2880, 0, threadID); // uv-sphere + } + + + // Local proxy boxes: + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + + GPUBuffer* vbs[] = { + &Cube::vertexBuffer, + }; + const UINT strides[] = { + sizeof(XMFLOAT4) + sizeof(XMFLOAT4), + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); + + for (size_t i = 0; i < scene.probes.GetCount(); ++i) + { + EnvironmentProbeComponent& probe = scene.probes[i]; + + if (probe.textureIndex < 0) + { + continue; + } + + Entity entity = scene.probes.GetEntity(i); + const TransformComponent& transform = *scene.transforms.GetComponent(entity); + + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection())); + sb.g_xColor = float4(0, 1, 1, 1); + + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + device->DrawIndexed(24, 0, 0, threadID); + } + + device->EventEnd(threadID); + } + + + if (gridHelper) + { + device->EventBegin("GridHelper", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_GRID], threadID); + + static float col = 0.7f; + static int gridVertexCount = 0; + static GPUBuffer* grid = nullptr; + if (grid == nullptr) + { + const float h = 0.01f; // avoid z-fight with zero plane + const int a = 20; + XMFLOAT4 verts[((a + 1) * 2 + (a + 1) * 2) * 2]; + + int count = 0; + for (int i = 0; i <= a; ++i) + { + verts[count++] = XMFLOAT4(i - a * 0.5f, h, -a * 0.5f, 1); + verts[count++] = (i == a / 2 ? XMFLOAT4(0, 0, 1, 1) : XMFLOAT4(col, col, col, 1)); + + verts[count++] = XMFLOAT4(i - a * 0.5f, h, +a * 0.5f, 1); + verts[count++] = (i == a / 2 ? XMFLOAT4(0, 0, 1, 1) : XMFLOAT4(col, col, col, 1)); + } + for (int j = 0; j <= a; ++j) + { + verts[count++] = XMFLOAT4(-a * 0.5f, h, j - a * 0.5f, 1); + verts[count++] = (j == a / 2 ? XMFLOAT4(1, 0, 0, 1) : XMFLOAT4(col, col, col, 1)); + + verts[count++] = XMFLOAT4(+a * 0.5f, h, j - a * 0.5f, 1); + verts[count++] = (j == a / 2 ? XMFLOAT4(1, 0, 0, 1) : XMFLOAT4(col, col, col, 1)); + } + + gridVertexCount = ARRAYSIZE(verts) / 2; + + GPUBufferDesc bd; + ZeroMemory(&bd, sizeof(bd)); + bd.Usage = USAGE_IMMUTABLE; + bd.ByteWidth = sizeof(verts); + bd.BindFlags = BIND_VERTEX_BUFFER; + bd.CPUAccessFlags = 0; + SubresourceData InitData; + ZeroMemory(&InitData, sizeof(InitData)); + InitData.pSysMem = verts; + grid = new GPUBuffer; + device->CreateBuffer(&bd, &InitData, grid); + } + + MiscCB sb; + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); + sb.g_xColor = float4(1, 1, 1, 1); + + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + GPUBuffer* vbs[] = { + grid, + }; + const UINT strides[] = { + sizeof(XMFLOAT4) + sizeof(XMFLOAT4), + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->Draw(gridVertexCount, 0, threadID); + + device->EventEnd(threadID); + } + + if (voxelHelper && textures[TEXTYPE_3D_VOXELRADIANCE] != nullptr) + { + device->EventBegin("Debug Voxels", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_VOXEL], threadID); + + + MiscCB sb; + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&voxelSceneData.center)) * camera.GetViewProjection())); + sb.g_xColor = float4(1, 1, 1, 1); + + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + device->Draw(voxelSceneData.res * voxelSceneData.res * voxelSceneData.res, 0, threadID); + + device->EventEnd(threadID); + } + + if (debugEmitters) + { + device->EventBegin("DebugEmitters", threadID); + + MiscCB sb; + for (size_t i = 0; i < scene.emitters.GetCount(); ++i) + { + const wiEmittedParticle& emitter = scene.emitters[i]; + Entity entity = scene.emitters.GetEntity(i); + const TransformComponent& transform = *scene.transforms.GetComponent(entity); + const MeshComponent* mesh = scene.meshes.GetComponent(emitter.meshID); + + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection())); + sb.g_xColor = float4(0, 1, 0, 1); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + if (mesh == nullptr) + { + // No mesh, just draw a box: + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + GPUBuffer* vbs[] = { + &Cube::vertexBuffer, + }; + const UINT strides[] = { + sizeof(XMFLOAT4) + sizeof(XMFLOAT4), + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); + device->DrawIndexed(24, 0, 0, threadID); + } + else + { + // Draw mesh wireframe: + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_EMITTER], threadID); + GPUBuffer* vbs[] = { + mesh->streamoutBuffer_POS != nullptr ? mesh->streamoutBuffer_POS.get() : mesh->vertexBuffer_POS.get(), + }; + const UINT strides[] = { + sizeof(MeshComponent::Vertex_POS), + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindIndexBuffer(mesh->indexBuffer.get(), mesh->GetIndexFormat(), 0, threadID); + + device->DrawIndexed((int)mesh->indices.size(), 0, 0, threadID); + } + } + + device->EventEnd(threadID); + } + + + if (debugForceFields) + { + device->EventBegin("DebugForceFields", threadID); + + MiscCB sb; + for (size_t i = 0; i < scene.forces.GetCount(); ++i) + { + ForceFieldComponent& force = scene.forces[i]; + + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); + sb.g_xColor = XMFLOAT4(camera.Eye.x, camera.Eye.y, camera.Eye.z, (float)i); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + switch (force.type) + { + case ENTITY_TYPE_FORCEFIELD_POINT: + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_FORCEFIELD_POINT], threadID); + device->Draw(2880, 0, threadID); // uv-sphere + break; + case ENTITY_TYPE_FORCEFIELD_PLANE: + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_FORCEFIELD_PLANE], threadID); + device->Draw(14, 0, threadID); // box + break; + } + + ++i; + } + + device->EventEnd(threadID); + } + + + if (debugCameras) + { + device->EventBegin("DebugCameras", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + + GPUBuffer* vbs[] = { + &Cube::vertexBuffer, + }; + const UINT strides[] = { + sizeof(XMFLOAT4) + sizeof(XMFLOAT4), + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); + + MiscCB sb; + sb.g_xColor = XMFLOAT4(1, 1, 1, 1); + + for (size_t i = 0; i < scene.cameras.GetCount(); ++i) + { + const CameraComponent& cam = scene.cameras[i]; + Entity entity = scene.cameras.GetEntity(i); + + XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(cam.GetInvView()*camera.GetViewProjection())); + + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + device->DrawIndexed(24, 0, 0, threadID); + } + + device->EventEnd(threadID); + } + + device->EventEnd(threadID); +} + +void DrawSky(GRAPHICSTHREAD threadID) { GetDevice()->EventBegin("DrawSky", threadID); @@ -5429,7 +5286,7 @@ void wiRenderer::DrawSky(GRAPHICSTHREAD threadID) GetDevice()->EventEnd(threadID); } -void wiRenderer::DrawSun(GRAPHICSTHREAD threadID) +void DrawSun(GRAPHICSTHREAD threadID) { GetDevice()->EventBegin("DrawSun", threadID); @@ -5449,7 +5306,7 @@ void wiRenderer::DrawSun(GRAPHICSTHREAD threadID) GetDevice()->EventEnd(threadID); } -void wiRenderer::DrawDecals(const CameraComponent& camera, GRAPHICSTHREAD threadID) +void DrawDecals(const CameraComponent& camera, GRAPHICSTHREAD threadID) { GraphicsDevice* device = GetDevice(); Scene& scene = GetScene(); @@ -5509,7 +5366,7 @@ void wiRenderer::DrawDecals(const CameraComponent& camera, GRAPHICSTHREAD thread } } -void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID) +void RefreshEnvProbes(GRAPHICSTHREAD threadID) { GetDevice()->EventBegin("EnvironmentProbe Refresh", threadID); @@ -5700,7 +5557,7 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID) GetDevice()->BindRenderTargets(0, nullptr, nullptr, threadID); //GetDevice()->GenerateMips(textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], threadID, probe->textureIndex); - wiRenderer::GenerateMipChain((Texture2D*)textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], MIPGENFILTER_LINEAR, threadID, probe.textureIndex); + GenerateMipChain((Texture2D*)textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], MIPGENFILTER_LINEAR, threadID, probe.textureIndex); // Filter the enviroment map mip chain according to BRDF: // A bit similar to MIP chain generation, but its input is the MIP-mapped texture, @@ -5752,7 +5609,7 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID) GetDevice()->EventEnd(threadID); // EnvironmentProbe Refresh } -void wiRenderer::VoxelRadiance(GRAPHICSTHREAD threadID) +void VoxelRadiance(GRAPHICSTHREAD threadID) { if (!GetVoxelRadianceEnabled()) { @@ -5907,10 +5764,18 @@ void wiRenderer::VoxelRadiance(GRAPHICSTHREAD threadID) } -void wiRenderer::ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID) + +inline XMUINT3 GetEntityCullingTileCount() +{ + return XMUINT3( + (UINT)ceilf((float)GetInternalResolution().x / (float)TILED_CULLING_BLOCKSIZE), + (UINT)ceilf((float)GetInternalResolution().y / (float)TILED_CULLING_BLOCKSIZE), + 1); +} +void ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID) { wiProfiler::GetInstance().BeginRange("Tiled Entity Processing", wiProfiler::DOMAIN_GPU, threadID); - GraphicsDevice* device = wiRenderer::GetDevice(); + GraphicsDevice* device = GetDevice(); int _width = GetInternalResolution().x; int _height = GetInternalResolution().y; @@ -6101,7 +5966,7 @@ void wiRenderer::ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID wiProfiler::GetInstance().EndRange(threadID); } -void wiRenderer::ResolveMSAADepthBuffer(Texture2D* dst, Texture2D* src, GRAPHICSTHREAD threadID) +void ResolveMSAADepthBuffer(Texture2D* dst, Texture2D* src, GRAPHICSTHREAD threadID) { GetDevice()->EventBegin("Resolve MSAA DepthBuffer", threadID); @@ -6119,11 +5984,11 @@ void wiRenderer::ResolveMSAADepthBuffer(Texture2D* dst, Texture2D* src, GRAPHICS GetDevice()->EventEnd(threadID); } -void wiRenderer::GenerateMipChain(Texture1D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex) +void GenerateMipChain(Texture1D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex) { assert(0 && "Not implemented!"); } -void wiRenderer::GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex) +void GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex) { TextureDesc desc = texture->GetDesc(); @@ -6156,17 +6021,17 @@ void wiRenderer::GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPH switch (filter) { - case wiRenderer::MIPGENFILTER_POINT: + case MIPGENFILTER_POINT: GetDevice()->EventBegin("GenerateMipChain CubeArray - PointFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); break; - case wiRenderer::MIPGENFILTER_LINEAR: + case MIPGENFILTER_LINEAR: GetDevice()->EventBegin("GenerateMipChain CubeArray - LinearFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); break; - case wiRenderer::MIPGENFILTER_LINEAR_MAXIMUM: + case MIPGENFILTER_LINEAR_MAXIMUM: GetDevice()->EventBegin("GenerateMipChain CubeArray - LinearMaxFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); @@ -6204,17 +6069,17 @@ void wiRenderer::GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPH // Cubemap switch (filter) { - case wiRenderer::MIPGENFILTER_POINT: + case MIPGENFILTER_POINT: GetDevice()->EventBegin("GenerateMipChain Cube - PointFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); break; - case wiRenderer::MIPGENFILTER_LINEAR: + case MIPGENFILTER_LINEAR: GetDevice()->EventBegin("GenerateMipChain Cube - LinearFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); break; - case wiRenderer::MIPGENFILTER_LINEAR_MAXIMUM: + case MIPGENFILTER_LINEAR_MAXIMUM: GetDevice()->EventBegin("GenerateMipChain Cube - LinearMaxFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); @@ -6254,22 +6119,22 @@ void wiRenderer::GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPH // Texture2D switch (filter) { - case wiRenderer::MIPGENFILTER_POINT: + case MIPGENFILTER_POINT: GetDevice()->EventBegin("GenerateMipChain 2D - PointFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); break; - case wiRenderer::MIPGENFILTER_LINEAR: + case MIPGENFILTER_LINEAR: GetDevice()->EventBegin("GenerateMipChain 2D - LinearFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); break; - case wiRenderer::MIPGENFILTER_LINEAR_MAXIMUM: + case MIPGENFILTER_LINEAR_MAXIMUM: GetDevice()->EventBegin("GenerateMipChain 2D - LinearMaxFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); break; - case wiRenderer::MIPGENFILTER_GAUSSIAN: + case MIPGENFILTER_GAUSSIAN: GetDevice()->EventBegin("GenerateMipChain 2D - GaussianFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN], threadID); break; @@ -6307,7 +6172,7 @@ void wiRenderer::GenerateMipChain(Texture2D* texture, MIPGENFILTER filter, GRAPH GetDevice()->EventEnd(threadID); } -void wiRenderer::GenerateMipChain(Texture3D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex) +void GenerateMipChain(Texture3D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex) { TextureDesc desc = texture->GetDesc(); @@ -6332,22 +6197,22 @@ void wiRenderer::GenerateMipChain(Texture3D* texture, MIPGENFILTER filter, GRAPH switch (filter) { - case wiRenderer::MIPGENFILTER_POINT: + case MIPGENFILTER_POINT: GetDevice()->EventBegin("GenerateMipChain 3D - PointFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); break; - case wiRenderer::MIPGENFILTER_LINEAR: + case MIPGENFILTER_LINEAR: GetDevice()->EventBegin("GenerateMipChain 3D - LinearFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); break; - case wiRenderer::MIPGENFILTER_LINEAR_MAXIMUM: + case MIPGENFILTER_LINEAR_MAXIMUM: GetDevice()->EventBegin("GenerateMipChain 3D - LinearMaxFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], threadID); GetDevice()->BindSampler(CS, customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); break; - case wiRenderer::MIPGENFILTER_GAUSSIAN: + case MIPGENFILTER_GAUSSIAN: GetDevice()->EventBegin("GenerateMipChain 3D - GaussianFilter", threadID); GetDevice()->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_GAUSSIAN : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_GAUSSIAN], threadID); break; @@ -6382,7 +6247,7 @@ void wiRenderer::GenerateMipChain(Texture3D* texture, MIPGENFILTER filter, GRAPH GetDevice()->EventEnd(threadID); } -void wiRenderer::CopyTexture2D(Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY, Texture2D* src, UINT SrcMIP, GRAPHICSTHREAD threadID, BORDEREXPANDSTYLE borderExpand) +void CopyTexture2D(Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY, Texture2D* src, UINT SrcMIP, GRAPHICSTHREAD threadID, BORDEREXPANDSTYLE borderExpand) { GraphicsDevice* device = GetDevice(); @@ -6435,19 +6300,18 @@ void wiRenderer::CopyTexture2D(Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY -// Should I care that usually buffers are not declared here? -static GPUBuffer* bvhNodeBuffer = nullptr; -static GPUBuffer* bvhAABBBuffer = nullptr; -static GPUBuffer* bvhFlagBuffer = nullptr; -static GPUBuffer* triangleBuffer = nullptr; -static GPUBuffer* clusterCounterBuffer = nullptr; -static GPUBuffer* clusterIndexBuffer = nullptr; -static GPUBuffer* clusterMortonBuffer = nullptr; -static GPUBuffer* clusterSortedMortonBuffer = nullptr; -static GPUBuffer* clusterOffsetBuffer = nullptr; -static GPUBuffer* clusterAABBBuffer = nullptr; -static GPUBuffer* clusterConeBuffer = nullptr; -void wiRenderer::BuildSceneBVH(GRAPHICSTHREAD threadID) +GPUBuffer* bvhNodeBuffer = nullptr; +GPUBuffer* bvhAABBBuffer = nullptr; +GPUBuffer* bvhFlagBuffer = nullptr; +GPUBuffer* triangleBuffer = nullptr; +GPUBuffer* clusterCounterBuffer = nullptr; +GPUBuffer* clusterIndexBuffer = nullptr; +GPUBuffer* clusterMortonBuffer = nullptr; +GPUBuffer* clusterSortedMortonBuffer = nullptr; +GPUBuffer* clusterOffsetBuffer = nullptr; +GPUBuffer* clusterAABBBuffer = nullptr; +GPUBuffer* clusterConeBuffer = nullptr; +void BuildSceneBVH(GRAPHICSTHREAD threadID) { GraphicsDevice* device = GetDevice(); Scene& scene = GetScene(); @@ -6809,10 +6673,9 @@ void wiRenderer::BuildSceneBVH(GRAPHICSTHREAD threadID) wiProfiler::GetInstance().EndRange(threadID); // BVH rebuild } - -void wiRenderer::DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICSTHREAD threadID) +void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICSTHREAD threadID) { - GraphicsDevice* device = wiRenderer::GetDevice(); + GraphicsDevice* device = GetDevice(); Scene& scene = GetScene(); device->EventBegin("DrawTracedScene", threadID); @@ -7295,7 +7158,7 @@ void wiRenderer::DrawTracedScene(const CameraComponent& camera, Texture2D* resul device->EventEnd(threadID); // DrawTracedScene } -void wiRenderer::GenerateClouds(Texture2D* dst, UINT refinementCount, float randomness, GRAPHICSTHREAD threadID) +void GenerateClouds(Texture2D* dst, UINT refinementCount, float randomness, GRAPHICSTHREAD threadID) { GetDevice()->EventBegin("Cloud Generator", threadID); @@ -7331,7 +7194,7 @@ void wiRenderer::GenerateClouds(Texture2D* dst, UINT refinementCount, float rand GetDevice()->EventEnd(threadID); } -void wiRenderer::ManageDecalAtlas(GRAPHICSTHREAD threadID) +void ManageDecalAtlas(GRAPHICSTHREAD threadID) { GraphicsDevice* device = GetDevice(); @@ -7455,7 +7318,53 @@ void wiRenderer::ManageDecalAtlas(GRAPHICSTHREAD threadID) } } -void wiRenderer::UpdateWorldCB(GRAPHICSTHREAD threadID) +void BindPersistentState(GRAPHICSTHREAD threadID) +{ + GraphicsDevice* device = GetDevice(); + + for (int i = 0; i < SSLOT_COUNT; ++i) + { + device->BindSampler(PS, samplers[i], i, threadID); + device->BindSampler(VS, samplers[i], i, threadID); + device->BindSampler(GS, samplers[i], i, threadID); + device->BindSampler(DS, samplers[i], i, threadID); + device->BindSampler(HS, samplers[i], i, threadID); + device->BindSampler(CS, samplers[i], i, threadID); + } + + + device->BindConstantBuffer(PS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + device->BindConstantBuffer(VS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + device->BindConstantBuffer(GS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + device->BindConstantBuffer(HS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + device->BindConstantBuffer(DS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + device->BindConstantBuffer(CS, constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + + device->BindConstantBuffer(PS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + device->BindConstantBuffer(VS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + device->BindConstantBuffer(GS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + device->BindConstantBuffer(HS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + device->BindConstantBuffer(DS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + device->BindConstantBuffer(CS, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + + device->BindConstantBuffer(PS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + device->BindConstantBuffer(VS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + device->BindConstantBuffer(GS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + device->BindConstantBuffer(HS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + device->BindConstantBuffer(DS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + device->BindConstantBuffer(CS, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + + device->BindConstantBuffer(VS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(GS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(DS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(HS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(CS, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + + device->BindConstantBuffer(VS, constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID); + device->BindConstantBuffer(PS, constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID); +} +void UpdateWorldCB(GRAPHICSTHREAD threadID) { const Scene& scene = GetScene(); @@ -7510,7 +7419,7 @@ void wiRenderer::UpdateWorldCB(GRAPHICSTHREAD threadID) GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_WORLD], &prevcb[threadID], threadID); } } -void wiRenderer::UpdateFrameCB(GRAPHICSTHREAD threadID) +void UpdateFrameCB(GRAPHICSTHREAD threadID) { const Scene& scene = GetScene(); @@ -7601,7 +7510,7 @@ void wiRenderer::UpdateFrameCB(GRAPHICSTHREAD threadID) GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_FRAME], &cb, threadID); } -void wiRenderer::UpdateCameraCB(const CameraComponent& camera, GRAPHICSTHREAD threadID) +void UpdateCameraCB(const CameraComponent& camera, GRAPHICSTHREAD threadID) { CameraCB cb; @@ -7614,12 +7523,12 @@ void wiRenderer::UpdateCameraCB(const CameraComponent& camera, GRAPHICSTHREAD th } APICB apiCB[GRAPHICSTHREAD_COUNT]; -void wiRenderer::SetClipPlane(const XMFLOAT4& clipPlane, GRAPHICSTHREAD threadID) +void SetClipPlane(const XMFLOAT4& clipPlane, GRAPHICSTHREAD threadID) { apiCB[threadID].g_xClipPlane = clipPlane; GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_API], &apiCB[threadID], threadID); } -void wiRenderer::SetAlphaRef(float alphaRef, GRAPHICSTHREAD threadID) +void SetAlphaRef(float alphaRef, GRAPHICSTHREAD threadID) { if (alphaRef != apiCB[threadID].g_xAlphaRef) { @@ -7627,7 +7536,7 @@ void wiRenderer::SetAlphaRef(float alphaRef, GRAPHICSTHREAD threadID) GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_API], &apiCB[threadID], threadID); } } -void wiRenderer::BindGBufferTextures(Texture2D* slot0, Texture2D* slot1, Texture2D* slot2, Texture2D* slot3, Texture2D* slot4, GRAPHICSTHREAD threadID) +void BindGBufferTextures(Texture2D* slot0, Texture2D* slot1, Texture2D* slot2, Texture2D* slot3, Texture2D* slot4, GRAPHICSTHREAD threadID) { GetDevice()->BindResource(PS, slot0, TEXSLOT_GBUFFER0, threadID); GetDevice()->BindResource(PS, slot1, TEXSLOT_GBUFFER1, threadID); @@ -7641,7 +7550,7 @@ void wiRenderer::BindGBufferTextures(Texture2D* slot0, Texture2D* slot1, Texture GetDevice()->BindResource(CS, slot3, TEXSLOT_GBUFFER3, threadID); GetDevice()->BindResource(CS, slot4, TEXSLOT_GBUFFER4, threadID); } -void wiRenderer::BindDepthTextures(Texture2D* depth, Texture2D* linearDepth, GRAPHICSTHREAD threadID) +void BindDepthTextures(Texture2D* depth, Texture2D* linearDepth, GRAPHICSTHREAD threadID) { GetDevice()->BindResource(PS, depth, TEXSLOT_DEPTH, threadID); GetDevice()->BindResource(VS, depth, TEXSLOT_DEPTH, threadID); @@ -7655,9 +7564,9 @@ void wiRenderer::BindDepthTextures(Texture2D* depth, Texture2D* linearDepth, GRA } -Texture2D* wiRenderer::GetLuminance(Texture2D* sourceImage, GRAPHICSTHREAD threadID) +Texture2D* GetLuminance(Texture2D* sourceImage, GRAPHICSTHREAD threadID) { - GraphicsDevice* device = wiRenderer::GetDevice(); + GraphicsDevice* device = GetDevice(); static Texture2D* luminance_map = nullptr; static std::vector luminance_avg(0); @@ -7736,13 +7645,13 @@ Texture2D* wiRenderer::GetLuminance(Texture2D* sourceImage, GRAPHICSTHREAD threa return nullptr; } -const XMFLOAT4& wiRenderer::GetWaterPlane() +const XMFLOAT4& GetWaterPlane() { return waterPlane; } -RAY wiRenderer::GetPickRay(long cursorX, long cursorY) +RAY GetPickRay(long cursorX, long cursorY) { const CameraComponent& camera = GetCamera(); XMMATRIX V = camera.GetView(); @@ -7754,7 +7663,7 @@ RAY wiRenderer::GetPickRay(long cursorX, long cursorY) return RAY(lineStart, rayDirection); } -wiRenderer::RayIntersectWorldResult wiRenderer::RayIntersectWorld(const RAY& ray, UINT renderTypeMask, uint32_t layerMask) +RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask, uint32_t layerMask) { Scene& scene = GetScene(); @@ -7876,16 +7785,8 @@ wiRenderer::RayIntersectWorldResult wiRenderer::RayIntersectWorld(const RAY& ray return result; } -Scene& wiRenderer::GetScene() -{ - if (scene == nullptr) - { - scene = new Scene; - } - return *scene; -} -void wiRenderer::SynchronizeWithPhysicsEngine(float dt) +void SynchronizeWithPhysicsEngine(float dt) { //if (physicsEngine && GetGameSpeed()) //{ @@ -7963,8 +7864,216 @@ void wiRenderer::SynchronizeWithPhysicsEngine(float dt) //} } -void wiRenderer::CreateImpostor(Entity entity, GRAPHICSTHREAD threadID) +void CreateImpostor(Entity entity, GRAPHICSTHREAD threadID) { + GraphicsDevice* device = GetDevice(); + + if (!impostorMaterialCB.IsValid()) + { + MaterialCB mcb; + ZeroMemory(&mcb, sizeof(mcb)); + mcb.baseColor = XMFLOAT4(1, 1, 1, 1); + mcb.texMulAdd = XMFLOAT4(1, 1, 0, 0); + mcb.normalMapStrength = 1.0f; + mcb.roughness = 1.0f; + mcb.reflectance = 1.0f; + mcb.metalness = 1.0f; + + GPUBufferDesc bd; + bd.BindFlags = BIND_CONSTANT_BUFFER; + bd.Usage = USAGE_IMMUTABLE; + bd.CPUAccessFlags = 0; + bd.ByteWidth = sizeof(MaterialCB); + SubresourceData initData; + initData.pSysMem = &mcb; + + device->CreateBuffer(&bd, &initData, &impostorMaterialCB); + } + if (!impostorVB_POS.IsValid()) + { + const int count = 6 * 6; + + XMFLOAT3 impostorVertices_pos[count]; + XMFLOAT3 impostorVertices_nor[count]; + XMFLOAT2 impostorVertices_tex[count]; + + float stepX = 1.f / 6.f; + + // front + impostorVertices_pos[0] = XMFLOAT3(-1, 1, 0); + impostorVertices_nor[0] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[0] = XMFLOAT2(0, 0); + + impostorVertices_pos[1] = XMFLOAT3(-1, -1, 0); + impostorVertices_nor[1] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[1] = XMFLOAT2(0, 1); + + impostorVertices_pos[2] = XMFLOAT3(1, 1, 0); + impostorVertices_nor[2] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[2] = XMFLOAT2(stepX, 0); + + impostorVertices_pos[3] = XMFLOAT3(-1, -1, 0); + impostorVertices_nor[3] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[3] = XMFLOAT2(0, 1); + + impostorVertices_pos[4] = XMFLOAT3(1, -1, 0); + impostorVertices_nor[4] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[4] = XMFLOAT2(stepX, 1); + + impostorVertices_pos[5] = XMFLOAT3(1, 1, 0); + impostorVertices_nor[5] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[5] = XMFLOAT2(stepX, 0); + + // right + impostorVertices_pos[6] = XMFLOAT3(0, 1, -1); + impostorVertices_nor[6] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[6] = XMFLOAT2(stepX, 0); + + impostorVertices_pos[7] = XMFLOAT3(0, -1, -1); + impostorVertices_nor[7] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[7] = XMFLOAT2(stepX, 1); + + impostorVertices_pos[8] = XMFLOAT3(0, 1, 1); + impostorVertices_nor[8] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[8] = XMFLOAT2(stepX * 2, 0); + + impostorVertices_pos[9] = XMFLOAT3(0, -1, -1); + impostorVertices_nor[9] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[9] = XMFLOAT2(stepX, 1); + + impostorVertices_pos[10] = XMFLOAT3(0, -1, 1); + impostorVertices_nor[10] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[10] = XMFLOAT2(stepX * 2, 1); + + impostorVertices_pos[11] = XMFLOAT3(0, 1, 1); + impostorVertices_nor[11] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[11] = XMFLOAT2(stepX * 2, 0); + + // back + impostorVertices_pos[12] = XMFLOAT3(-1, 1, 0); + impostorVertices_nor[12] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[12] = XMFLOAT2(stepX * 3, 0); + + impostorVertices_pos[13] = XMFLOAT3(1, 1, 0); + impostorVertices_nor[13] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[13] = XMFLOAT2(stepX * 2, 0); + + impostorVertices_pos[14] = XMFLOAT3(-1, -1, 0); + impostorVertices_nor[14] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[14] = XMFLOAT2(stepX * 3, 1); + + impostorVertices_pos[15] = XMFLOAT3(-1, -1, 0); + impostorVertices_nor[15] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[15] = XMFLOAT2(stepX * 3, 1); + + impostorVertices_pos[16] = XMFLOAT3(1, 1, 0); + impostorVertices_nor[16] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[16] = XMFLOAT2(stepX * 2, 0); + + impostorVertices_pos[17] = XMFLOAT3(1, -1, 0); + impostorVertices_nor[17] = XMFLOAT3(0, 0, -1); + impostorVertices_tex[17] = XMFLOAT2(stepX * 2, 1); + + // left + impostorVertices_pos[18] = XMFLOAT3(0, 1, -1); + impostorVertices_nor[18] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[18] = XMFLOAT2(stepX * 4, 0); + + impostorVertices_pos[19] = XMFLOAT3(0, 1, 1); + impostorVertices_nor[19] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[19] = XMFLOAT2(stepX * 3, 0); + + impostorVertices_pos[20] = XMFLOAT3(0, -1, -1); + impostorVertices_nor[20] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[20] = XMFLOAT2(stepX * 4, 1); + + impostorVertices_pos[21] = XMFLOAT3(0, -1, -1); + impostorVertices_nor[21] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[21] = XMFLOAT2(stepX * 4, 1); + + impostorVertices_pos[22] = XMFLOAT3(0, 1, 1); + impostorVertices_nor[22] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[22] = XMFLOAT2(stepX * 3, 0); + + impostorVertices_pos[23] = XMFLOAT3(0, -1, 1); + impostorVertices_nor[23] = XMFLOAT3(1, 0, 0); + impostorVertices_tex[23] = XMFLOAT2(stepX * 3, 1); + + // bottom + impostorVertices_pos[24] = XMFLOAT3(-1, 0, 1); + impostorVertices_nor[24] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[24] = XMFLOAT2(stepX * 4, 0); + + impostorVertices_pos[25] = XMFLOAT3(1, 0, 1); + impostorVertices_nor[25] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[25] = XMFLOAT2(stepX * 5, 0); + + impostorVertices_pos[26] = XMFLOAT3(-1, 0, -1); + impostorVertices_nor[26] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[26] = XMFLOAT2(stepX * 4, 1); + + impostorVertices_pos[27] = XMFLOAT3(-1, 0, -1); + impostorVertices_nor[27] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[27] = XMFLOAT2(stepX * 4, 1); + + impostorVertices_pos[28] = XMFLOAT3(1, 0, 1); + impostorVertices_nor[28] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[28] = XMFLOAT2(stepX * 5, 0); + + impostorVertices_pos[29] = XMFLOAT3(1, 0, -1); + impostorVertices_nor[29] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[29] = XMFLOAT2(stepX * 5, 1); + + // top + impostorVertices_pos[30] = XMFLOAT3(-1, 0, 1); + impostorVertices_nor[30] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[30] = XMFLOAT2(stepX * 5, 0); + + impostorVertices_pos[31] = XMFLOAT3(-1, 0, -1); + impostorVertices_nor[31] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[31] = XMFLOAT2(stepX * 5, 1); + + impostorVertices_pos[32] = XMFLOAT3(1, 0, 1); + impostorVertices_nor[32] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[32] = XMFLOAT2(stepX * 6, 0); + + impostorVertices_pos[33] = XMFLOAT3(-1, 0, -1); + impostorVertices_nor[33] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[33] = XMFLOAT2(stepX * 5, 1); + + impostorVertices_pos[34] = XMFLOAT3(1, 0, -1); + impostorVertices_nor[34] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[34] = XMFLOAT2(stepX * 6, 1); + + impostorVertices_pos[35] = XMFLOAT3(1, 0, 1); + impostorVertices_nor[35] = XMFLOAT3(0, 1, 0); + impostorVertices_tex[35] = XMFLOAT2(stepX * 6, 0); + + + MeshComponent::Vertex_POS impostorVertices_POS[count]; + MeshComponent::Vertex_TEX impostorVertices_TEX[count]; + for (int i = 0; i < count; ++i) + { + impostorVertices_POS[i].FromFULL(impostorVertices_pos[i], impostorVertices_nor[i], 0); + impostorVertices_TEX[i].FromFULL(impostorVertices_tex[i]); + } + + + GPUBufferDesc bd; + ZeroMemory(&bd, sizeof(bd)); + bd.Usage = USAGE_IMMUTABLE; + bd.BindFlags = BIND_VERTEX_BUFFER; + bd.CPUAccessFlags = 0; + SubresourceData InitData; + ZeroMemory(&InitData, sizeof(InitData)); + InitData.pSysMem = impostorVertices_POS; + bd.ByteWidth = sizeof(impostorVertices_POS); + device->CreateBuffer(&bd, &InitData, &impostorVB_POS); + InitData.pSysMem = impostorVertices_TEX; + bd.ByteWidth = sizeof(impostorVertices_TEX); + device->CreateBuffer(&bd, &InitData, &impostorVB_TEX); + } + Scene& scene = GetScene(); MeshComponent& mesh = *scene.meshes.GetComponent(entity); @@ -7992,11 +8101,11 @@ void wiRenderer::CreateImpostor(Entity entity, GRAPHICSTHREAD threadID) Instance instance; InstancePrev instancePrev; }; - UINT instancesOffset; - volatile InstBuf* buff = (volatile InstBuf*)GetDevice()->AllocateFromRingBuffer(dynamicVertexBufferPool, sizeof(InstBuf), instancesOffset, threadID); + UINT instancesOffset; + volatile InstBuf* buff = (volatile InstBuf*)device->AllocateFromRingBuffer(dynamicVertexBufferPool, sizeof(InstBuf), instancesOffset, threadID); buff->instance.Create(__identity); buff->instancePrev.Create(__identity); - GetDevice()->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); + device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); GPUBuffer* vbs[] = { mesh.IsSkinned() ? mesh.streamoutBuffer_POS.get() : mesh.vertexBuffer_POS.get(), @@ -8016,11 +8125,11 @@ void wiRenderer::CreateImpostor(Entity entity, GRAPHICSTHREAD threadID) 0, instancesOffset }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID); + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID); - GetDevice()->BindIndexBuffer(mesh.indexBuffer.get(), mesh.GetIndexFormat(), 0, threadID); + device->BindIndexBuffer(mesh.indexBuffer.get(), mesh.GetIndexFormat(), 0, threadID); - GetDevice()->BindGraphicsPSO(PSO_captureimpostor, threadID); + device->BindGraphicsPSO(PSO_captureimpostor, threadID); ViewPort savedViewPort = mesh.impostorTarget.viewPort; mesh.impostorTarget.Activate(threadID, 0, 0, 0, 0); @@ -8099,33 +8208,33 @@ void wiRenderer::CreateImpostor(Entity entity, GRAPHICSTHREAD threadID) } MaterialComponent& material = *GetScene().materials.GetComponent(subset.materialID); - GetDevice()->BindConstantBuffer(PS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID); + device->BindConstantBuffer(PS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID); - GetDevice()->BindResource(PS, material.GetBaseColorMap(), TEXSLOT_ONDEMAND0, threadID); - GetDevice()->BindResource(PS, material.GetNormalMap(), TEXSLOT_ONDEMAND1, threadID); - GetDevice()->BindResource(PS, material.GetSurfaceMap(), TEXSLOT_ONDEMAND2, threadID); + device->BindResource(PS, material.GetBaseColorMap(), TEXSLOT_ONDEMAND0, threadID); + device->BindResource(PS, material.GetNormalMap(), TEXSLOT_ONDEMAND1, threadID); + device->BindResource(PS, material.GetSurfaceMap(), TEXSLOT_ONDEMAND2, threadID); - GetDevice()->DrawIndexedInstanced((int)subset.indexCount, 1, subset.indexOffset, 0, 0, threadID); + device->DrawIndexedInstanced((int)subset.indexCount, 1, subset.indexOffset, 0, 0, threadID); } } - wiRenderer::GenerateMipChain(mesh.impostorTarget.GetTexture(), wiRenderer::MIPGENFILTER_LINEAR, threadID); + GenerateMipChain(mesh.impostorTarget.GetTexture(), MIPGENFILTER_LINEAR, threadID); mesh.impostorTarget.viewPort = savedViewPort; UpdateCameraCB(GetCamera(), threadID); } -void wiRenderer::AddRenderableBox(const XMFLOAT4X4& boxMatrix, const XMFLOAT4& color) +void AddRenderableBox(const XMFLOAT4X4& boxMatrix, const XMFLOAT4& color) { renderableBoxes.push_back(pair(boxMatrix,color)); } -void wiRenderer::AddRenderableLine(const RenderableLine& line) +void AddRenderableLine(const RenderableLine& line) { renderableLines.push_back(line); } -void wiRenderer::AddDeferredMIPGen(Texture2D* tex) +void AddDeferredMIPGen(Texture2D* tex) { deferredMIPGenLock.lock(); deferredMIPGens.insert(tex); @@ -8133,7 +8242,68 @@ void wiRenderer::AddDeferredMIPGen(Texture2D* tex) } -void wiRenderer::SetOcclusionCullingEnabled(bool value) + +void SetOceanEnabled(bool enabled, const wiOceanParameter& params) +{ + SAFE_DELETE(ocean); + + if (enabled) + { + ocean = new wiOcean(params); + } +} + + + +void SetResolutionScale(float value) { RESOLUTIONSCALE = value; } +float GetResolutionScale() { return RESOLUTIONSCALE; } +int GetShadowRes2D() { return SHADOWRES_2D; } +int GetShadowResCube() { return SHADOWRES_CUBE; } +void SetTransparentShadowsEnabled(float value) { TRANSPARENTSHADOWSENABLED = value; } +float GetTransparentShadowsEnabled() { return TRANSPARENTSHADOWSENABLED; } +XMUINT2 GetInternalResolution() { return XMUINT2((UINT)ceilf(GetDevice()->GetScreenWidth()*GetResolutionScale()), (UINT)ceilf(GetDevice()->GetScreenHeight()*GetResolutionScale())); } +bool ResolutionChanged() +{ + //detect internal resolution change: + static float _savedresscale = GetResolutionScale(); + static uint64_t lastFrameInternalResChange = 0; + if (_savedresscale != GetResolutionScale() || lastFrameInternalResChange == GetDevice()->GetFrameCount()) + { + _savedresscale = GetResolutionScale(); + lastFrameInternalResChange = GetDevice()->GetFrameCount(); + return true; + } + + // detect device resolution change: + return GetDevice()->ResolutionChanged(); +} +void SetGamma(float value) { GAMMA = value; } +float GetGamma() { return GAMMA; } +void SetWireRender(bool value) { wireRender = value; } +bool IsWireRender() { return wireRender; } +void SetToDrawDebugBoneLines(bool param) { debugBoneLines = param; } +bool GetToDrawDebugBoneLines() { return debugBoneLines; } +void SetToDrawDebugPartitionTree(bool param) { debugPartitionTree = param; } +bool GetToDrawDebugPartitionTree() { return debugPartitionTree; } +bool GetToDrawDebugEnvProbes() { return debugEnvProbes; } +void SetToDrawDebugEnvProbes(bool value) { debugEnvProbes = value; } +void SetToDrawDebugEmitters(bool param) { debugEmitters = param; } +bool GetToDrawDebugEmitters() { return debugEmitters; } +void SetToDrawDebugForceFields(bool param) { debugForceFields = param; } +bool GetToDrawDebugForceFields() { return debugForceFields; } +void SetToDrawDebugCameras(bool param) { debugCameras = param; } +bool GetToDrawDebugCameras() { return debugCameras; } +bool GetToDrawGridHelper() { return gridHelper; } +void SetToDrawGridHelper(bool value) { gridHelper = value; } +bool GetToDrawVoxelHelper() { return voxelHelper; } +void SetToDrawVoxelHelper(bool value) { voxelHelper = value; } +void SetDebugLightCulling(bool enabled) { debugLightCulling = enabled; } +bool GetDebugLightCulling() { return debugLightCulling; } +void SetAdvancedLightCulling(bool enabled) { advancedLightCulling = enabled; } +bool GetAdvancedLightCulling() { return advancedLightCulling; } +void SetAlphaCompositionEnabled(bool enabled) { ALPHACOMPOSITIONENABLED = enabled; } +bool GetAlphaCompositionEnabled() { return ALPHACOMPOSITIONENABLED; } +void SetOcclusionCullingEnabled(bool value) { static bool initialized = false; @@ -8148,42 +8318,44 @@ void wiRenderer::SetOcclusionCullingEnabled(bool value) for (int i = 0; i < ARRAYSIZE(occlusionQueries); ++i) { - wiRenderer::GetDevice()->CreateQuery(&desc, &occlusionQueries[i]); + GetDevice()->CreateQuery(&desc, &occlusionQueries[i]); occlusionQueries[i].result_passed = TRUE; } } occlusionCulling = value; } +bool GetOcclusionCullingEnabled() { return occlusionCulling; } +void SetLDSSkinningEnabled(bool enabled) { ldsSkinningEnabled = enabled; } +bool GetLDSSkinningEnabled() { return ldsSkinningEnabled; } +void SetTemporalAAEnabled(bool enabled) { temporalAA = enabled; } +bool GetTemporalAAEnabled() { return temporalAA; } +void SetTemporalAADebugEnabled(bool enabled) { temporalAADEBUG = enabled; } +bool GetTemporalAADebugEnabled() { return temporalAADEBUG; } +void SetFreezeCullingCameraEnabled(bool enabled) { freezeCullingCamera = enabled; } +bool GetFreezeCullingCameraEnabled() { return freezeCullingCamera; } +void SetVoxelRadianceEnabled(bool enabled) { voxelSceneData.enabled = enabled; } +bool GetVoxelRadianceEnabled() { return voxelSceneData.enabled; } +void SetVoxelRadianceSecondaryBounceEnabled(bool enabled) { voxelSceneData.secondaryBounceEnabled = enabled; } +bool GetVoxelRadianceSecondaryBounceEnabled() { return voxelSceneData.secondaryBounceEnabled; } +void SetVoxelRadianceReflectionsEnabled(bool enabled) { voxelSceneData.reflectionsEnabled = enabled; } +bool GetVoxelRadianceReflectionsEnabled() { return voxelSceneData.reflectionsEnabled; } +void SetVoxelRadianceVoxelSize(float value) { voxelSceneData.voxelsize = value; } +float GetVoxelRadianceVoxelSize() { return voxelSceneData.voxelsize; } +int GetVoxelRadianceResolution() { return voxelSceneData.res; } +void SetVoxelRadianceNumCones(int value) { voxelSceneData.numCones = value; } +int GetVoxelRadianceNumCones() { return voxelSceneData.numCones; } +float GetVoxelRadianceRayStepSize() { return voxelSceneData.rayStepSize; } +void SetVoxelRadianceRayStepSize(float value) { voxelSceneData.rayStepSize = value; } +void SetSpecularAAParam(float value) { SPECULARAA = value; } +float GetSpecularAAParam() { return SPECULARAA; } +void SetAdvancedRefractionsEnabled(bool value) { advancedRefractions = value; } +bool GetAdvancedRefractionsEnabled() { return advancedRefractions; } +bool IsRequestedReflectionRendering() { return requestReflectionRendering; } +void SetEnviromentMap(wiGraphicsTypes::Texture2D* tex) { enviroMap = tex; } +Texture2D* GetEnviromentMap() { return enviroMap; } +void SetGameSpeed(float value) { GameSpeed = max(0, value); } +float GetGameSpeed() { return GameSpeed; } +wiOcean* GetOcean() { return ocean; } -bool wiRenderer::GetAdvancedRefractionsEnabled() -{ - return advancedRefractions && GetDevice()->CheckCapability(GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_UNORDEREDACCESSTEXTURE_LOAD_FORMAT_EXT); -} - -void wiRenderer::SetOceanEnabled(bool enabled, const wiOceanParameter& params) -{ - SAFE_DELETE(ocean); - - if (enabled) - { - ocean = new wiOcean(params); - } -} - - -CameraComponent& wiRenderer::GetCamera() -{ - static CameraComponent camera; - return camera; -} -CameraComponent& wiRenderer::GetPrevCamera() -{ - static CameraComponent camera; - return camera; -} -CameraComponent& wiRenderer::GetRefCamera() -{ - static CameraComponent camera; - return camera; } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 3acd7e9a7..cdb6942c8 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -1,54 +1,18 @@ #pragma once #include "CommonInclude.h" -#include "ShaderInterop.h" #include "wiEnums.h" #include "wiGraphicsAPI.h" -#include "wiWindowRegistration.h" -#include "wiFrustum.h" #include "wiSceneSystem_Decl.h" #include "wiECS.h" -#include -#include - -class wiSprite; -class PHYSICS; -class wiRenderTarget; class wiOcean; struct wiOceanParameter; +struct RAY; typedef std::unordered_map> CulledCollection; -struct RAY; - -class wiRenderer +namespace wiRenderer { -public: - static wiGraphicsTypes::GraphicsDevice* graphicsDevice; - static wiGraphicsTypes::GraphicsDevice* GetDevice() { assert(graphicsDevice != nullptr); return graphicsDevice; } - - - static void Present(std::function drawToScreen1=nullptr, std::function drawToScreen2=nullptr, std::function drawToScreen3=nullptr); - - - static wiGraphicsTypes::Sampler *samplers[SSLOT_COUNT]; - static wiGraphicsTypes::VertexShader *vertexShaders[VSTYPE_LAST]; - static wiGraphicsTypes::PixelShader *pixelShaders[PSTYPE_LAST]; - static wiGraphicsTypes::GeometryShader *geometryShaders[GSTYPE_LAST]; - static wiGraphicsTypes::HullShader *hullShaders[HSTYPE_LAST]; - static wiGraphicsTypes::DomainShader *domainShaders[DSTYPE_LAST]; - static wiGraphicsTypes::ComputeShader *computeShaders[CSTYPE_LAST]; - static wiGraphicsTypes::VertexLayout *vertexLayouts[VLTYPE_LAST]; - static wiGraphicsTypes::RasterizerState *rasterizers[RSTYPE_LAST]; - static wiGraphicsTypes::DepthStencilState *depthStencils[DSSTYPE_LAST]; - static wiGraphicsTypes::BlendState *blendStates[BSTYPE_LAST]; - static wiGraphicsTypes::GPUBuffer *constantBuffers[CBTYPE_LAST]; - static wiGraphicsTypes::GPUBuffer *resourceBuffers[RBTYPE_LAST]; - static wiGraphicsTypes::Texture *textures[TEXTYPE_LAST]; - static wiGraphicsTypes::Sampler *customsamplers[SSTYPE_LAST]; - - static wiGraphicsTypes::GPURingBuffer *dynamicVertexBufferPool; - static const wiGraphicsTypes::FORMAT RTFormat_ldr = wiGraphicsTypes::FORMAT_R8G8B8A8_UNORM; static const wiGraphicsTypes::FORMAT RTFormat_hdr = wiGraphicsTypes::FORMAT_R16G16B16A16_FLOAT; static const wiGraphicsTypes::FORMAT RTFormat_gbuffer_0 = wiGraphicsTypes::FORMAT_R8G8B8A8_UNORM; @@ -73,199 +37,84 @@ public: static const wiGraphicsTypes::FORMAT DSFormat_full_alias = wiGraphicsTypes::FORMAT_R32G8X24_TYPELESS; static const wiGraphicsTypes::FORMAT DSFormat_small = wiGraphicsTypes::FORMAT_D16_UNORM; static const wiGraphicsTypes::FORMAT DSFormat_small_alias = wiGraphicsTypes::FORMAT_R16_TYPELESS; - - static float GAMMA; - static int SHADOWRES_2D, SHADOWRES_CUBE, SHADOWCOUNT_2D, SHADOWCOUNT_CUBE, SOFTSHADOWQUALITY_2D; - static bool HAIRPARTICLEENABLED, EMITTERSENABLED; - static float SPECULARAA; - static float renderTime, renderTime_Prev, deltaTime; - static XMFLOAT2 temporalAAJitter, temporalAAJitterPrev; - static float RESOLUTIONSCALE; - static bool TRANSPARENTSHADOWSENABLED; - static bool ALPHACOMPOSITIONENABLED; - static void SetShadowProps2D(int resolution, int count, int softShadowQuality); - static void SetShadowPropsCube(int resolution, int count); + wiGraphicsTypes::Sampler* GetSampler(int slot); + wiGraphicsTypes::VertexShader* GetVertexShader(VSTYPES id); + wiGraphicsTypes::HullShader* GetHullShader(VSTYPES id); + wiGraphicsTypes::DomainShader* GetDomainShader(VSTYPES id); + wiGraphicsTypes::GeometryShader* GetGeometryShader(VSTYPES id); + wiGraphicsTypes::PixelShader* GetPixelShader(PSTYPES id); + wiGraphicsTypes::ComputeShader* GetComputeShader(PSTYPES id); + wiGraphicsTypes::VertexLayout* GetVertexLayout(VLTYPES id); + wiGraphicsTypes::RasterizerState* GetRasterizerState(RSTYPES id); + wiGraphicsTypes::DepthStencilState* GetDepthStencilState(DSSTYPES id); + wiGraphicsTypes::BlendState* GetBlendState(BSTYPES id); + wiGraphicsTypes::GPUBuffer* GetConstantBuffer(CBTYPES id); + wiGraphicsTypes::Texture* GetTexture(TEXTYPES id); -protected: - - static bool wireRender, debugBoneLines, debugPartitionTree, debugEnvProbes, debugEmitters, debugForceFields, debugCameras, gridHelper, voxelHelper, advancedLightCulling, advancedRefractions; - static bool ldsSkinningEnabled; - static bool requestReflectionRendering; + void ModifySampler(const wiGraphicsTypes::SamplerDesc& desc, int slot); - static wiGraphicsTypes::Texture2D* enviroMap; - static void LoadBuffers(); - static void LoadShaders(); - static void SetUpStates(); + void Initialize(); + void CleanUp(); + void LoadBuffers(); + void LoadShaders(); + void SetUpStates(); + void ClearWorld(); + + void SetDevice(wiGraphicsTypes::GraphicsDevice* newDevice); + wiGraphicsTypes::GraphicsDevice* GetDevice(); + + std::string& GetShaderPath(); + void ReloadShaders(const std::string& path = ""); + + wiSceneSystem::Scene& GetScene(); + wiSceneSystem::CameraComponent& GetCamera(); + wiSceneSystem::CameraComponent& GetPrevCamera(); + wiSceneSystem::CameraComponent& GetRefCamera(); + + void FixedUpdate(); + void UpdatePerFrameData(float dt); + void UpdateRenderData(GRAPHICSTHREAD threadID); - static float GameSpeed; + void BindPersistentState(GRAPHICSTHREAD threadID); + void UpdateWorldCB(GRAPHICSTHREAD threadID); + void UpdateFrameCB(GRAPHICSTHREAD threadID); + void UpdateCameraCB(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); + void SetClipPlane(const XMFLOAT4& clipPlane, GRAPHICSTHREAD threadID); + void SetAlphaRef(float alphaRef, GRAPHICSTHREAD threadID); + inline void ResetAlphaRef(GRAPHICSTHREAD threadID) { SetAlphaRef(0.75f, threadID); } + void BindGBufferTextures(wiGraphicsTypes::Texture2D* slot0, wiGraphicsTypes::Texture2D* slot1, wiGraphicsTypes::Texture2D* slot2, wiGraphicsTypes::Texture2D* slot3, wiGraphicsTypes::Texture2D* slot4, GRAPHICSTHREAD threadID); + void BindDepthTextures(wiGraphicsTypes::Texture2D* depth, wiGraphicsTypes::Texture2D* linearDepth, GRAPHICSTHREAD threadID); - static wiSceneSystem::Scene* scene; - static XMFLOAT4 waterPlane; - - static bool debugLightCulling; - static bool occlusionCulling; - static bool temporalAA, temporalAADEBUG; - static bool freezeCullingCamera; - - struct VoxelizedSceneData - { - bool enabled; - int res; - float voxelsize; - XMFLOAT3 center; - XMFLOAT3 extents; - int numCones; - float rayStepSize; - bool secondaryBounceEnabled; - bool reflectionsEnabled; - bool centerChangedThisFrame; - UINT mips; - - VoxelizedSceneData() :enabled(false), res(128), voxelsize(1.0f), center(XMFLOAT3(0, 0, 0)), extents(XMFLOAT3(0, 0, 0)), numCones(8), - rayStepSize(0.5f), secondaryBounceEnabled(true), reflectionsEnabled(false), centerChangedThisFrame(true), mips(7) - {} - } static voxelSceneData; - - static wiGraphicsTypes::GPUQuery occlusionQueries[256]; - - static UINT entityArrayOffset_Lights, entityArrayCount_Lights; - static UINT entityArrayOffset_Decals, entityArrayCount_Decals; - static UINT entityArrayOffset_ForceFields, entityArrayCount_ForceFields; - static UINT entityArrayOffset_EnvProbes, entityArrayCount_EnvProbes; - -public: - static std::string SHADERPATH; - - static void SetUpStaticComponents(); - static void CleanUpStatic(); - - static void FixedUpdate(); - // Render data that needs to be updated on the main thread! - static void UpdatePerFrameData(float dt); - static void UpdateRenderData(GRAPHICSTHREAD threadID); - static void OcclusionCulling_Render(GRAPHICSTHREAD threadID); - static void OcclusionCulling_Read(); - static void PutWaterRipple(const std::string& image, const XMFLOAT3& pos); - static void ManageWaterRipples(); - static void DrawWaterRipples(GRAPHICSTHREAD threadID); - static void SetGameSpeed(float value){GameSpeed=value; if(GameSpeed<0) GameSpeed=0;}; - static float GetGameSpeed(); - static void SetResolutionScale(float value) { RESOLUTIONSCALE = value; } - static float GetResolutionScale() { return RESOLUTIONSCALE; } - static void SetTransparentShadowsEnabled(float value) { TRANSPARENTSHADOWSENABLED = value; } - static float GetTransparentShadowsEnabled() { return TRANSPARENTSHADOWSENABLED; } - static XMUINT2 GetInternalResolution() { return XMUINT2((UINT)ceilf(GetDevice()->GetScreenWidth()*GetResolutionScale()), (UINT)ceilf(GetDevice()->GetScreenHeight()*GetResolutionScale())); } - static bool ResolutionChanged(); - static void SetGamma(float value) { GAMMA = value; } - static float GetGamma() { return GAMMA; } - static void SetWireRender(bool value) { wireRender = value; } - static bool IsWireRender() { return wireRender; } - static void SetToDrawDebugBoneLines(bool param) { debugBoneLines = param; } - static bool GetToDrawDebugBoneLines() { return debugBoneLines; } - static void SetToDrawDebugPartitionTree(bool param){debugPartitionTree=param;} - static bool GetToDrawDebugPartitionTree(){return debugPartitionTree;} - static bool GetToDrawDebugEnvProbes() { return debugEnvProbes; } - static void SetToDrawDebugEnvProbes(bool value) { debugEnvProbes = value; } - static void SetToDrawDebugEmitters(bool param) { debugEmitters = param; } - static bool GetToDrawDebugEmitters() { return debugEmitters; } - static void SetToDrawDebugForceFields(bool param) { debugForceFields = param; } - static bool GetToDrawDebugForceFields() { return debugForceFields; } - static void SetToDrawDebugCameras(bool param) { debugCameras = param; } - static bool GetToDrawDebugCameras() { return debugCameras; } - static bool GetToDrawGridHelper() { return gridHelper; } - static void SetToDrawGridHelper(bool value) { gridHelper = value; } - static bool GetToDrawVoxelHelper() { return voxelHelper; } - static void SetToDrawVoxelHelper(bool value) { voxelHelper = value; } - static void SetDebugLightCulling(bool enabled) { debugLightCulling = enabled; } - static bool GetDebugLightCulling() { return debugLightCulling; } - static void SetAdvancedLightCulling(bool enabled) { advancedLightCulling = enabled; } - static bool GetAdvancedLightCulling() { return advancedLightCulling; } - static void SetAlphaCompositionEnabled(bool enabled) { ALPHACOMPOSITIONENABLED = enabled; } - static bool GetAlphaCompositionEnabled() { return ALPHACOMPOSITIONENABLED; } - static void SetOcclusionCullingEnabled(bool enabled); // also inits query pool! - static bool GetOcclusionCullingEnabled() { return occlusionCulling; } - static void SetLDSSkinningEnabled(bool enabled) { ldsSkinningEnabled = enabled; } - static bool GetLDSSkinningEnabled() { return ldsSkinningEnabled; } - static void SetTemporalAAEnabled(bool enabled) { temporalAA = enabled; } - static bool GetTemporalAAEnabled() { return temporalAA; } - static void SetTemporalAADebugEnabled(bool enabled) { temporalAADEBUG = enabled; } - static bool GetTemporalAADebugEnabled() { return temporalAADEBUG; } - static void SetFreezeCullingCameraEnabled(bool enabled) { freezeCullingCamera = enabled; } - static bool GetFreezeCullingCameraEnabled() { return freezeCullingCamera; } - static void SetVoxelRadianceEnabled(bool enabled) { voxelSceneData.enabled = enabled; } - static bool GetVoxelRadianceEnabled() { return voxelSceneData.enabled; } - static void SetVoxelRadianceSecondaryBounceEnabled(bool enabled) { voxelSceneData.secondaryBounceEnabled = enabled; } - static bool GetVoxelRadianceSecondaryBounceEnabled() { return voxelSceneData.secondaryBounceEnabled; } - static void SetVoxelRadianceReflectionsEnabled(bool enabled) { voxelSceneData.reflectionsEnabled = enabled; } - static bool GetVoxelRadianceReflectionsEnabled() { return voxelSceneData.reflectionsEnabled; } - static void SetVoxelRadianceVoxelSize(float value) { voxelSceneData.voxelsize = value; } - static float GetVoxelRadianceVoxelSize() { return voxelSceneData.voxelsize; } - //static void SetVoxelRadianceResolution(int value) { voxelSceneData.res = value; } - static int GetVoxelRadianceResolution() { return voxelSceneData.res; } - static void SetVoxelRadianceNumCones(int value) { voxelSceneData.numCones = value; } - static int GetVoxelRadianceNumCones() { return voxelSceneData.numCones; } - static float GetVoxelRadianceRayStepSize() { return voxelSceneData.rayStepSize; } - static void SetVoxelRadianceRayStepSize(float value) { voxelSceneData.rayStepSize = value; } - static void SetSpecularAAParam(float value) { SPECULARAA = value; } - static float GetSpecularAAParam() { return SPECULARAA; } - static void SetAdvancedRefractionsEnabled(bool value) { advancedRefractions = value; } - static bool GetAdvancedRefractionsEnabled(); // also needs additional driver support for now... - static bool IsRequestedReflectionRendering() { return requestReflectionRendering; } - static void SetEnviromentMap(wiGraphicsTypes::Texture2D* tex){ enviroMap = tex; } - static wiGraphicsTypes::Texture2D* GetEnviromentMap(){ return enviroMap; } - static wiGraphicsTypes::Texture2D* GetLuminance(wiGraphicsTypes::Texture2D* sourceImage, GRAPHICSTHREAD threadID); - static const XMFLOAT4& GetWaterPlane(); - - static void ReloadShaders(const std::string& path = ""); - static void BindPersistentState(GRAPHICSTHREAD threadID); - - inline static XMUINT3 GetEntityCullingTileCount() - { - return XMUINT3( - (UINT)ceilf((float)GetInternalResolution().x / (float)TILED_CULLING_BLOCKSIZE), - (UINT)ceilf((float)GetInternalResolution().y / (float)TILED_CULLING_BLOCKSIZE), - 1); - } - -public: - - - static void UpdateWorldCB(GRAPHICSTHREAD threadID); - static void UpdateFrameCB(GRAPHICSTHREAD threadID); - static void UpdateCameraCB(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); - static void SetClipPlane(const XMFLOAT4& clipPlane, GRAPHICSTHREAD threadID); - static void SetAlphaRef(float alphaRef, GRAPHICSTHREAD threadID); - static void ResetAlphaRef(GRAPHICSTHREAD threadID) { SetAlphaRef(0.75f, threadID); } - static void BindGBufferTextures(wiGraphicsTypes::Texture2D* slot0, wiGraphicsTypes::Texture2D* slot1, wiGraphicsTypes::Texture2D* slot2, wiGraphicsTypes::Texture2D* slot3, wiGraphicsTypes::Texture2D* slot4, GRAPHICSTHREAD threadID); - static void BindDepthTextures(wiGraphicsTypes::Texture2D* depth, wiGraphicsTypes::Texture2D* linearDepth, GRAPHICSTHREAD threadID); - - static void RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culledRenderer, SHADERTYPE shaderType, UINT renderTypeFlags, GRAPHICSTHREAD threadID, + void RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culledRenderer, SHADERTYPE shaderType, UINT renderTypeFlags, GRAPHICSTHREAD threadID, bool tessellation = false, bool occlusionCulling = false, uint32_t layerMask = 0xFFFFFFFF); - static void DrawSky(GRAPHICSTHREAD threadID); - static void DrawSun(GRAPHICSTHREAD threadID); - static void DrawWorld(const wiSceneSystem::CameraComponent& camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF); - static void DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask = 0xFFFFFFFF); - static void DrawWorldTransparent(const wiSceneSystem::CameraComponent& camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF); - static void DrawDebugWorld(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); - static void DrawSoftParticles(const wiSceneSystem::CameraComponent& camera, bool distortion, GRAPHICSTHREAD threadID); - static void DrawTrails(GRAPHICSTHREAD threadID, wiGraphicsTypes::Texture2D* refracRes); - static void DrawLights(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); - static void DrawLightVisualizers(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); - static void DrawVolumeLights(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); - static void DrawLensFlares(GRAPHICSTHREAD threadID); - static void DrawDecals(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); - static void RefreshEnvProbes(GRAPHICSTHREAD threadID); - static void VoxelRadiance(GRAPHICSTHREAD threadID); + void DrawSky(GRAPHICSTHREAD threadID); + void DrawSun(GRAPHICSTHREAD threadID); + void DrawWorld(const wiSceneSystem::CameraComponent& camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF); + void DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask = 0xFFFFFFFF); + void DrawWorldTransparent(const wiSceneSystem::CameraComponent& camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF); + void DrawDebugWorld(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); + void DrawSoftParticles(const wiSceneSystem::CameraComponent& camera, bool distortion, GRAPHICSTHREAD threadID); + void DrawTrails(GRAPHICSTHREAD threadID, wiGraphicsTypes::Texture2D* refracRes); + void DrawLights(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); + void DrawLightVisualizers(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); + void DrawVolumeLights(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); + void DrawLensFlares(GRAPHICSTHREAD threadID); + void DrawDecals(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID); + void RefreshEnvProbes(GRAPHICSTHREAD threadID); + void VoxelRadiance(GRAPHICSTHREAD threadID); + void ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID); + void ResolveMSAADepthBuffer(wiGraphicsTypes::Texture2D* dst, wiGraphicsTypes::Texture2D* src, GRAPHICSTHREAD threadID); + void BuildSceneBVH(GRAPHICSTHREAD threadID); + void DrawTracedScene(const wiSceneSystem::CameraComponent& camera, wiGraphicsTypes::Texture2D* result, GRAPHICSTHREAD threadID); - static void ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID); - static void ResolveMSAADepthBuffer(wiGraphicsTypes::Texture2D* dst, wiGraphicsTypes::Texture2D* src, GRAPHICSTHREAD threadID); + void OcclusionCulling_Render(GRAPHICSTHREAD threadID); + void OcclusionCulling_Read(); + void EndFrame(); - static void BuildSceneBVH(GRAPHICSTHREAD threadID); - static void DrawTracedScene(const wiSceneSystem::CameraComponent& camera, wiGraphicsTypes::Texture2D* result, GRAPHICSTHREAD threadID); enum MIPGENFILTER { @@ -274,9 +123,9 @@ public: MIPGENFILTER_LINEAR_MAXIMUM, MIPGENFILTER_GAUSSIAN, }; - static void GenerateMipChain(wiGraphicsTypes::Texture1D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex = -1); - static void GenerateMipChain(wiGraphicsTypes::Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex = -1); - static void GenerateMipChain(wiGraphicsTypes::Texture3D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex = -1); + void GenerateMipChain(wiGraphicsTypes::Texture1D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex = -1); + void GenerateMipChain(wiGraphicsTypes::Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex = -1); + void GenerateMipChain(wiGraphicsTypes::Texture3D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID, int arrayIndex = -1); enum BORDEREXPANDSTYLE { @@ -286,27 +135,104 @@ public: }; // Performs copy operation even between different texture formats // Can also expand border region according to desired sampler func - static void CopyTexture2D(wiGraphicsTypes::Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY, wiGraphicsTypes::Texture2D* src, UINT SrcMIP, GRAPHICSTHREAD threadID, + void CopyTexture2D(wiGraphicsTypes::Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY, wiGraphicsTypes::Texture2D* src, UINT SrcMIP, GRAPHICSTHREAD threadID, BORDEREXPANDSTYLE borderExpand = BORDEREXPAND_DISABLE); // dst: Texture2D with unordered access, the output will be written to this // refinementCount: 0: auto select, 1: perfect noise, greater numbers: smoother clouds, slower processing // randomness: random seed - static void GenerateClouds(wiGraphicsTypes::Texture2D* dst, UINT refinementCount, float randomness, GRAPHICSTHREAD threadID); + void GenerateClouds(wiGraphicsTypes::Texture2D* dst, UINT refinementCount, float randomness, GRAPHICSTHREAD threadID); - static void ManageDecalAtlas(GRAPHICSTHREAD threadID); + void ManageDecalAtlas(GRAPHICSTHREAD threadID); + void CreateImpostor(wiECS::Entity, GRAPHICSTHREAD threadID); - // The scene holds all models, and world information - static wiSceneSystem::Scene& GetScene(); - - static std::deque waterRipples; - static void ClearWorld(); - - static wiSceneSystem::CameraComponent& GetCamera(); - static wiSceneSystem::CameraComponent& GetPrevCamera(); - static wiSceneSystem::CameraComponent& GetRefCamera(); + void PutWaterRipple(const std::string& image, const XMFLOAT3& pos); + void ManageWaterRipples(); + void DrawWaterRipples(GRAPHICSTHREAD threadID); - static RAY GetPickRay(long cursorX, long cursorY); + + + // Set any param to -1 if don't want to modify + void SetShadowProps2D(int resolution, int count, int softShadowQuality); + // Set any param to -1 if don't want to modify + void SetShadowPropsCube(int resolution, int count); + + int GetShadowRes2D(); + int GetShadowResCube(); + + + + void SetResolutionScale(float value); + float GetResolutionScale(); + void SetTransparentShadowsEnabled(float value); + float GetTransparentShadowsEnabled(); + XMUINT2 GetInternalResolution(); + bool ResolutionChanged(); + void SetGamma(float value); + float GetGamma(); + void SetWireRender(bool value); + bool IsWireRender(); + void SetToDrawDebugBoneLines(bool param); + bool GetToDrawDebugBoneLines(); + void SetToDrawDebugPartitionTree(bool param); + bool GetToDrawDebugPartitionTree(); + bool GetToDrawDebugEnvProbes(); + void SetToDrawDebugEnvProbes(bool value); + void SetToDrawDebugEmitters(bool param); + bool GetToDrawDebugEmitters(); + void SetToDrawDebugForceFields(bool param); + bool GetToDrawDebugForceFields(); + void SetToDrawDebugCameras(bool param); + bool GetToDrawDebugCameras(); + bool GetToDrawGridHelper(); + void SetToDrawGridHelper(bool value); + bool GetToDrawVoxelHelper(); + void SetToDrawVoxelHelper(bool value); + void SetDebugLightCulling(bool enabled); + bool GetDebugLightCulling(); + void SetAdvancedLightCulling(bool enabled); + bool GetAdvancedLightCulling(); + void SetAlphaCompositionEnabled(bool enabled); + bool GetAlphaCompositionEnabled(); + void SetOcclusionCullingEnabled(bool enabled); + bool GetOcclusionCullingEnabled(); + void SetLDSSkinningEnabled(bool enabled); + bool GetLDSSkinningEnabled(); + void SetTemporalAAEnabled(bool enabled); + bool GetTemporalAAEnabled(); + void SetTemporalAADebugEnabled(bool enabled); + bool GetTemporalAADebugEnabled(); + void SetFreezeCullingCameraEnabled(bool enabled); + bool GetFreezeCullingCameraEnabled(); + void SetVoxelRadianceEnabled(bool enabled); + bool GetVoxelRadianceEnabled(); + void SetVoxelRadianceSecondaryBounceEnabled(bool enabled); + bool GetVoxelRadianceSecondaryBounceEnabled(); + void SetVoxelRadianceReflectionsEnabled(bool enabled); + bool GetVoxelRadianceReflectionsEnabled(); + void SetVoxelRadianceVoxelSize(float value); + float GetVoxelRadianceVoxelSize(); + int GetVoxelRadianceResolution(); + void SetVoxelRadianceNumCones(int value); + int GetVoxelRadianceNumCones(); + float GetVoxelRadianceRayStepSize(); + void SetVoxelRadianceRayStepSize(float value); + void SetSpecularAAParam(float value); + float GetSpecularAAParam(); + void SetAdvancedRefractionsEnabled(bool value); + bool GetAdvancedRefractionsEnabled(); + bool IsRequestedReflectionRendering(); + void SetEnviromentMap(wiGraphicsTypes::Texture2D* tex); + wiGraphicsTypes::Texture2D* GetEnviromentMap(); + wiGraphicsTypes::Texture2D* GetLuminance(wiGraphicsTypes::Texture2D* sourceImage, GRAPHICSTHREAD threadID); + const XMFLOAT4& GetWaterPlane(); + void SetGameSpeed(float value); + float GetGameSpeed(); + void SetOceanEnabled(bool enabled, const wiOceanParameter& params); + wiOcean* GetOcean(); + + + RAY GetPickRay(long cursorX, long cursorY); struct RayIntersectWorldResult { @@ -316,21 +242,14 @@ public: float distance = FLT_MAX; int subsetIndex = -1; }; - static RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask = RENDERTYPE_OPAQUE, uint32_t layerMask = ~0); + RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask = RENDERTYPE_OPAQUE, uint32_t layerMask = ~0); - static PHYSICS* physicsEngine; - static void SynchronizeWithPhysicsEngine(float dt = 1.0f / 60.0f); + void SynchronizeWithPhysicsEngine(float dt = 1.0f / 60.0f); - static wiOcean* ocean; - static void SetOceanEnabled(bool enabled, const wiOceanParameter& params); - static wiOcean* GetOcean() { return ocean; } - static void CreateImpostor(wiECS::Entity, GRAPHICSTHREAD threadID); - - static std::vector> renderableBoxes; // Add box to render in next frame - static void AddRenderableBox(const XMFLOAT4X4& boxMatrix, const XMFLOAT4& color = XMFLOAT4(1,1,1,1)); + void AddRenderableBox(const XMFLOAT4X4& boxMatrix, const XMFLOAT4& color = XMFLOAT4(1,1,1,1)); struct RenderableLine { @@ -338,10 +257,9 @@ public: XMFLOAT3 end = XMFLOAT3(0, 0, 0); XMFLOAT4 color = XMFLOAT4(1, 1, 1, 1); }; - static std::vector renderableLines; - static void AddRenderableLine(const RenderableLine& line); + void AddRenderableLine(const RenderableLine& line); - static void AddDeferredMIPGen(wiGraphicsTypes::Texture2D* tex); + void AddDeferredMIPGen(wiGraphicsTypes::Texture2D* tex); }; diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index ccdf53b66..52e842867 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -167,15 +167,16 @@ namespace wiRenderer_BindLua int argc = wiLua::SGetArgCount(L); if (argc > 0) { - wiRenderer::physicsEngine->rigidBodyPhysicsEnabled = wiLua::SGetBool(L, 1); - if (argc > 1) - { - wiRenderer::physicsEngine->softBodyPhysicsEnabled = wiLua::SGetBool(L, 2); - if (argc > 2) - { - wiRenderer::physicsEngine->softBodyIterationCount = wiLua::SGetInt(L, 3); - } - } + assert(0); + //wiRenderer::physicsEngine->rigidBodyPhysicsEnabled = wiLua::SGetBool(L, 1); + //if (argc > 1) + //{ + // wiRenderer::physicsEngine->softBodyPhysicsEnabled = wiLua::SGetBool(L, 2); + // if (argc > 2) + // { + // wiRenderer::physicsEngine->softBodyIterationCount = wiLua::SGetInt(L, 3); + // } + //} } return 0; } diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index 88d32a8c1..b25dffa6a 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -1419,46 +1419,46 @@ namespace wiSceneSystem float dt ) { - PHYSICS* physicsEngine = wiRenderer::physicsEngine; + //PHYSICS* physicsEngine = wiRenderer::physicsEngine; - if (physicsEngine != nullptr) - { - physicsEngine->Update(dt); + //if (physicsEngine != nullptr) + //{ + // physicsEngine->Update(dt); - // Rigid bodies - Objects: - for (size_t i = 0; i < rigidbodies.GetCount(); ++i) - { - RigidBodyPhysicsComponent& rigidbody = rigidbodies[i]; - Entity entity = rigidbodies.GetEntity(i); - TransformComponent& transform = *transforms.GetComponent(entity); + // // Rigid bodies - Objects: + // for (size_t i = 0; i < rigidbodies.GetCount(); ++i) + // { + // RigidBodyPhysicsComponent& rigidbody = rigidbodies[i]; + // Entity entity = rigidbodies.GetEntity(i); + // TransformComponent& transform = *transforms.GetComponent(entity); - if (rigidbody.kinematic) - { - //physicsEngine->transformBody(transform.rotation, transform.translation, rigidbody.physicsObjectID); - } - else - { - PHYSICS::PhysicsTransform* pt = physicsEngine->getObject(rigidbody.physicsObjectID); - transform.translation_local = pt->position; - transform.rotation_local = pt->rotation; - transform.SetDirty(); - } + // if (rigidbody.kinematic) + // { + // //physicsEngine->transformBody(transform.rotation, transform.translation, rigidbody.physicsObjectID); + // } + // else + // { + // PHYSICS::PhysicsTransform* pt = physicsEngine->getObject(rigidbody.physicsObjectID); + // transform.translation_local = pt->position; + // transform.rotation_local = pt->rotation; + // transform.SetDirty(); + // } - } + // } - // Soft bodies - Meshes: - for (size_t i = 0; i < softbodies.GetCount(); ++i) - { - SoftBodyPhysicsComponent& softbody = softbodies[i]; - Entity entity = softbodies.GetEntity(i); + // // Soft bodies - Meshes: + // for (size_t i = 0; i < softbodies.GetCount(); ++i) + // { + // SoftBodyPhysicsComponent& softbody = softbodies[i]; + // Entity entity = softbodies.GetEntity(i); - MeshComponent& mesh = *meshes.GetComponent(entity); - mesh.SetDynamic(true); + // MeshComponent& mesh = *meshes.GetComponent(entity); + // mesh.SetDynamic(true); - } + // } - physicsEngine->NextRunWorld(); - } + // physicsEngine->NextRunWorld(); + //} } void RunTransformUpdateSystem(ComponentManager& transforms) @@ -1805,9 +1805,9 @@ namespace wiSceneSystem XMVECTOR d = XMVector3Unproject(XMVectorSet(screen.x * 0.5f, screen.y * 0.5f, 1, 1), 0, 0, screen.x, screen.y, 0.0f, 1.0f, projection, view, world); // Avoid shadowmap texel swimming by aligning them to a discrete grid: - float f0 = light.shadowCam_dirLight[0].size / (float)wiRenderer::SHADOWRES_2D; - float f1 = light.shadowCam_dirLight[1].size / (float)wiRenderer::SHADOWRES_2D; - float f2 = light.shadowCam_dirLight[2].size / (float)wiRenderer::SHADOWRES_2D; + float f0 = light.shadowCam_dirLight[0].size / (float)wiRenderer::GetShadowRes2D(); + float f1 = light.shadowCam_dirLight[1].size / (float)wiRenderer::GetShadowRes2D(); + float f2 = light.shadowCam_dirLight[2].size / (float)wiRenderer::GetShadowRes2D(); XMVECTOR e0 = XMVectorFloor(XMVectorLerp(c, d, lerp0) / f0) * f0; XMVECTOR e1 = XMVectorFloor(XMVectorLerp(c, d, lerp1) / f1) * f1; XMVECTOR e2 = XMVectorFloor(XMVectorLerp(c, d, lerp2) / f2) * f2; diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index b750f40e0..0c439e255 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -237,12 +237,12 @@ void wiWidget::SetScissorRect(const wiGraphicsTypes::Rect& rect) void wiWidget::LoadShaders() { GraphicsPSODesc desc; - desc.vs = wiRenderer::vertexShaders[VSTYPE_LINE]; - desc.ps = wiRenderer::pixelShaders[PSTYPE_LINE]; - desc.il = wiRenderer::vertexLayouts[VLTYPE_LINE]; - desc.dss = wiRenderer::depthStencils[DSSTYPE_XRAY]; - desc.bs = wiRenderer::blendStates[BSTYPE_OPAQUE]; - desc.rs = wiRenderer::rasterizers[RSTYPE_DOUBLESIDED]; + desc.vs = wiRenderer::GetVertexShader(VSTYPE_LINE); + desc.ps = wiRenderer::GetPixelShader(PSTYPE_LINE); + desc.il = wiRenderer::GetVertexLayout(VLTYPE_LINE); + desc.dss = wiRenderer::GetDepthStencilState(DSSTYPE_XRAY); + desc.bs = wiRenderer::GetBlendState(BSTYPE_OPAQUE); + desc.rs = wiRenderer::GetRasterizerState(RSTYPE_DOUBLESIDED); desc.numRTs = 1; desc.RTFormats[0] = wiRenderer::GetDevice()->GetBackBufferFormat(); desc.pt = TRIANGLESTRIP; @@ -1768,7 +1768,7 @@ void wiColorPicker::Render(wiGUI* gui) XMMATRIX __cam = wiRenderer::GetDevice()->GetScreenProjection(); - wiRenderer::GetDevice()->BindConstantBuffer(VS, wiRenderer::constantBuffers[CBTYPE_MISC], CBSLOT_RENDERER_MISC, threadID); + wiRenderer::GetDevice()->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CBSLOT_RENDERER_MISC, threadID); wiRenderer::GetDevice()->BindGraphicsPSO(PSO_colorpicker, threadID); MiscCB cb; @@ -1787,7 +1787,7 @@ void wiColorPicker::Render(wiGUI* gui) __cam )); cb.g_xColor = XMFLOAT4(1, 1, 1, 1); - wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); + wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &cb, threadID); GPUBuffer* vbs[] = { &vb_saturation, }; @@ -1805,7 +1805,7 @@ void wiColorPicker::Render(wiGUI* gui) __cam )); cb.g_xColor = float4(1, 1, 1, 1); - wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); + wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &cb, threadID); GPUBuffer* vbs[] = { &vb_hue, }; @@ -1823,7 +1823,7 @@ void wiColorPicker::Render(wiGUI* gui) __cam )); cb.g_xColor = float4(1 - hue_color.x, 1 - hue_color.y, 1 - hue_color.z, 1); - wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); + wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &cb, threadID); GPUBuffer* vbs[] = { &vb_picker, }; @@ -1841,7 +1841,7 @@ void wiColorPicker::Render(wiGUI* gui) __cam )); cb.g_xColor = float4(1 - final_color.x, 1 - final_color.y, 1 - final_color.z, 1); - wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); + wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &cb, threadID); GPUBuffer* vbs[] = { &vb_picker, }; @@ -1859,7 +1859,7 @@ void wiColorPicker::Render(wiGUI* gui) __cam )); cb.g_xColor = GetPickColor(); - wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::constantBuffers[CBTYPE_MISC], &cb, threadID); + wiRenderer::GetDevice()->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &cb, threadID); GPUBuffer* vbs[] = { &vb_preview, };