Skip to content

Commit

Permalink
#149 Apply deferred rendering for editor (prepare for primitive and s…
Browse files Browse the repository at this point in the history
…pot light)
  • Loading branch information
ducphamhong committed May 11, 2022
1 parent 7bc49e4 commit 6b9bfe0
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 8 deletions.
77 changes: 71 additions & 6 deletions Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ namespace Skylicht
CSpace(window, editor),
m_scene(NULL),
m_renderRP(NULL),
m_shadowMapRendering(NULL),
m_forwardRP(NULL),
m_postProcessor(NULL),
m_viewpointRP(NULL),
m_editorCamera(NULL),
m_gridPlane(NULL),
Expand Down Expand Up @@ -246,11 +249,35 @@ namespace Skylicht

CSpaceScene::~CSpaceScene()
{
if (m_renderRP != NULL)
delete m_renderRP;

if (m_viewpointRP != NULL)
{
delete m_viewpointRP;
m_viewpointRP = NULL;
}

if (m_rendering != NULL)
{
delete m_rendering;
m_rendering = NULL;
}

if (m_shadowMapRendering != NULL)
{
delete m_shadowMapRendering;
m_shadowMapRendering = NULL;
}

if (m_forwardRP != NULL)
{
delete m_forwardRP;
m_forwardRP = NULL;
}

if (m_postProcessor != NULL)
{
delete m_postProcessor;
m_postProcessor = NULL;
}

if (m_viewpointController != NULL)
delete m_viewpointController;
Expand Down Expand Up @@ -558,13 +585,51 @@ namespace Skylicht
{
if (m_renderRP == NULL)
{
m_renderRP = new CForwardRP();
m_renderRP->initRender((int)w, (int)h);
// 1st
m_shadowMapRendering = new CShadowMapRP();
m_shadowMapRendering->initRender(w, h);

// 2nd
m_rendering = new CDeferredRP();
m_rendering->initRender(w, h);
m_rendering->enableUpdateEntity(false);

// 3rd
m_forwardRP = new CForwardRP(false);
m_forwardRP->initRender(w, h);
m_forwardRP->enableUpdateEntity(false);

// link rp
m_shadowMapRendering->setNextPipeLine(m_rendering);
m_rendering->setNextPipeLine(m_forwardRP);

// post processor
m_postProcessor = new CPostProcessorRP();
m_postProcessor->enableAutoExposure(false);
m_postProcessor->enableBloomEffect(true);
m_postProcessor->enableFXAA(true);
m_postProcessor->enableScreenSpaceReflection(true);
m_postProcessor->initRender(w, h);

// apply post processor
m_rendering->setPostProcessor(m_postProcessor);

m_renderRP = m_shadowMapRendering;
}
else
{
// resize
m_renderRP->resize((int)w, (int)h);
if (m_shadowMapRendering != NULL)
m_shadowMapRendering->resize(w, h);

if (m_rendering != NULL)
m_rendering->resize(w, h);

if (m_forwardRP != NULL)
m_forwardRP->resize(w, h);

if (m_postProcessor != NULL)
m_postProcessor->resize(w, h);
}

if (m_viewpointRP == NULL)
Expand Down
6 changes: 6 additions & 0 deletions Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ namespace Skylicht

CScene* m_scene;
CCamera* m_editorCamera;

IRenderPipeline* m_renderRP;
IRenderPipeline* m_viewpointRP;

CDeferredRP* m_rendering;
CShadowMapRP* m_shadowMapRendering;
CForwardRP* m_forwardRP;
CPostProcessorRP* m_postProcessor;

CGameObject* m_gridPlane;

bool m_leftMouseDown;
Expand Down
3 changes: 3 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CTreeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ namespace Skylicht

CTreeNode::~CTreeNode()
{
if (m_parentNode)
m_parentNode->invalidate();

delete m_textEditHelper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ namespace Skylicht

if (viewport.getWidth() > 0 && viewport.getHeight() > 0)
{
driver->setViewPort(viewport);
renderW = (float)viewport.getWidth();
renderH = (float)viewport.getHeight();
}
Expand Down Expand Up @@ -302,6 +301,8 @@ namespace Skylicht
m_lastFrameBuffer->regenerateMipMapLevels();

driver->setRenderTarget(finalTarget, false, false);
if (viewport.getWidth() > 0 && viewport.getHeight() > 0)
driver->setViewPort(viewport);
}
// END SCREEN SPACE REFLECTION

Expand All @@ -316,7 +317,11 @@ namespace Skylicht
driver->setRenderTarget(m_rtt[colorID]);
}
else
driver->setRenderTarget(finalTarget);
{
driver->setRenderTarget(finalTarget, false, false);
if (viewport.getWidth() > 0 && viewport.getHeight() > 0)
driver->setViewPort(viewport);
}

if (m_autoExposure == true)
{
Expand Down Expand Up @@ -354,6 +359,8 @@ namespace Skylicht
CShaderMaterial::setMaterial(m_fxaaFilter);

driver->setRenderTarget(finalTarget, false, false);
if (viewport.getWidth() > 0 && viewport.getHeight() > 0)
driver->setViewPort(viewport);

beginRender2D(renderW, renderH);
renderBufferToTarget(0.0f, 0.0f, renderW, renderH, m_effectPass);
Expand Down

0 comments on commit 6b9bfe0

Please sign in to comment.