Skip to content

Commit

Permalink
#86 Add linear color rp
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Sep 21, 2020
1 parent 2cdbdde commit 4d5a2f2
Show file tree
Hide file tree
Showing 17 changed files with 295 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Projects/Skylicht/Engine/Source/RenderPipeline/CDeferredRP.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace Skylicht
float m_directMultipler;
float m_lightMultipler;

CPostProcessorRP *m_postProcessor;
IPostProcessor *m_postProcessor;

protected:

Expand All @@ -95,7 +95,7 @@ namespace Skylicht

virtual void drawMeshBuffer(CMesh *mesh, int bufferID, CEntityManager* entity, int entityID);

inline void setPostProcessor(CPostProcessorRP *pp)
inline void setPostProcessor(IPostProcessor *pp)
{
m_postProcessor = pp;
}
Expand Down
46 changes: 38 additions & 8 deletions Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,26 @@ This file is part of the "Skylicht Engine".

namespace Skylicht
{
CForwardRP::CForwardRP()
CForwardRP::CForwardRP(bool postProcessor) :
m_usePostProcessor(postProcessor),
m_postProcessor(NULL),
m_target(NULL)
{

}

CForwardRP::~CForwardRP()
{

if (m_target != NULL)
getVideoDriver()->removeTexture(m_target);
}

void CForwardRP::initRender(int w, int h)
{
m_size.set(w, h);

if (m_usePostProcessor == true)
m_target = getVideoDriver()->addRenderTargetTexture(m_size, "target", ECF_A16B16G16R16F);
}

void CForwardRP::render(ITexture *target, CCamera *camera, CEntityManager *entityManager, const core::recti& viewport)
Expand All @@ -48,11 +55,29 @@ namespace Skylicht
return;

IVideoDriver *driver = getVideoDriver();
driver->setRenderTarget(target, false, false);

// custom viewport
if (viewport.getWidth() > 0 && viewport.getHeight() > 0)
driver->setViewPort(viewport);

ITexture *currentTarget = NULL;

if (m_usePostProcessor == true && m_postProcessor != NULL)
{
driver->setRenderTarget(m_target, true, true);
currentTarget = m_target;

if (viewport.getWidth() > 0 && viewport.getHeight() > 0)
{
core::recti vp(0, 0, (int)viewport.getWidth(), (int)viewport.getHeight());
driver->setViewPort(vp);
}
}
else
{
driver->setRenderTarget(target, false, false);
currentTarget = target;

// custom viewport
if (viewport.getWidth() > 0 && viewport.getHeight() > 0)
driver->setViewPort(viewport);
}

setCamera(camera);
entityManager->setCamera(camera);
Expand All @@ -68,6 +93,11 @@ namespace Skylicht
entityManager->cullingAndRender();
}

onNext(target, camera, entityManager, viewport);
onNext(currentTarget, camera, entityManager, viewport);

if (m_usePostProcessor == true && m_postProcessor != NULL)
{
m_postProcessor->postProcessing(target, m_target, NULL, NULL, viewport);
}
}
}
17 changes: 16 additions & 1 deletion Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,33 @@ This file is part of the "Skylicht Engine".
#pragma once

#include "CBaseRP.h"
#include "CPostProcessorRP.h"

namespace Skylicht
{
class CForwardRP : public CBaseRP
{
protected:

bool m_usePostProcessor;

ITexture *m_target;
core::dimension2du m_size;

IPostProcessor *m_postProcessor;

public:
CForwardRP();
CForwardRP(bool postProcessor = true);

virtual ~CForwardRP();

virtual void initRender(int w, int h);

virtual void render(ITexture *target, CCamera *camera, CEntityManager *entityManager, const core::recti& viewport);

inline void setPostProcessor(IPostProcessor *pp)
{
m_postProcessor = pp;
}
};
}
82 changes: 82 additions & 0 deletions Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#include "pch.h"
#include "CLinearColorRP.h"
#include "Material/Shader/CShaderManager.h"

namespace Skylicht
{
CLinearColorRP::CLinearColorRP()
{

}

CLinearColorRP::~CLinearColorRP()
{
IVideoDriver *driver = getVideoDriver();
}

void CLinearColorRP::initRender(int w, int h)
{
IVideoDriver *driver = getVideoDriver();
CShaderManager *shaderMgr = CShaderManager::getInstance();

// init size of framebuffer
m_size = core::dimension2du((u32)w, (u32)h);

// init final pass shader
m_finalPass.MaterialType = shaderMgr->getShaderIDByName("TextureLinearRGB");
}

void CLinearColorRP::render(ITexture *target, CCamera *camera, CEntityManager *entityManager, const core::recti& viewport)
{
if (camera == NULL)
return;

onNext(target, camera, entityManager, viewport);
}

void CLinearColorRP::postProcessing(ITexture *finalTarget, ITexture *color, ITexture *normal, ITexture *position, const core::recti& viewport)
{
IVideoDriver *driver = getVideoDriver();

driver->setRenderTarget(finalTarget, false, false);

float renderW = (float)m_size.Width;
float renderH = (float)m_size.Height;

if (viewport.getWidth() > 0 && viewport.getHeight() > 0)
{
driver->setViewPort(viewport);
renderW = (float)viewport.getWidth();
renderH = (float)viewport.getHeight();
}

m_finalPass.setTexture(0, color);

beginRender2D(renderW, renderH);
renderBufferToTarget(0.0f, 0.0f, renderW, renderH, m_finalPass);
}
}
52 changes: 52 additions & 0 deletions Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#pragma once

#include "CBaseRP.h"
#include "IPostProcessor.h"

namespace Skylicht
{
class CLinearColorRP :
public CBaseRP,
public IPostProcessor
{
protected:
core::dimension2du m_size;

SMaterial m_finalPass;

public:
CLinearColorRP();

virtual ~CLinearColorRP();

virtual void initRender(int w, int h);

virtual void render(ITexture *target, CCamera *camera, CEntityManager *entityManager, const core::recti& vp);

virtual void postProcessing(ITexture *finalTarget, ITexture *color, ITexture *normal, ITexture *position, const core::recti& viewport);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ This file is part of the "Skylicht Engine".
#pragma once

#include "CBaseRP.h"
#include "IPostProcessor.h"

namespace Skylicht
{
class CPostProcessorRP : public CBaseRP
class CPostProcessorRP :
public CBaseRP,
public IPostProcessor
{
protected:
core::dimension2du m_size;
Expand Down
45 changes: 45 additions & 0 deletions Projects/Skylicht/Engine/Source/RenderPipeline/IPostProcessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
!@
MIT License
Copyright (c) 2019 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#pragma once

#include "pch.h"

namespace Skylicht
{
class IPostProcessor
{
public:
IPostProcessor()
{
}

virtual ~IPostProcessor()
{

}

virtual void postProcessing(ITexture *finalTarget, ITexture *color, ITexture *normal, ITexture *position, const core::recti& viewport) = 0;
};
}
1 change: 1 addition & 0 deletions Projects/Template/Source/SkylichtEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ This file is part of the "Skylicht Engine".
#include "RenderPipeline/CDeferredRP.h"
#include "RenderPipeline/CShadowMapRP.h"
#include "RenderPipeline/CPostProcessorRP.h"
#include "RenderPipeline/CLinearColorRP.h"

// Scene, GameObject
#include "Scene/CScene.h"
Expand Down
21 changes: 20 additions & 1 deletion Samples/Materials/Source/SampleMaterials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ void installApplication(const std::vector<std::string>& argv)

SampleMaterials::SampleMaterials() :
m_scene(NULL),
m_bakeSHLighting(true)
m_bakeSHLighting(true),
m_reflectionProbe(NULL),
m_forwardRP(NULL),
m_postProcessRP(NULL)
{
Lightmapper::CLightmapper::createGetInstance();
}
Expand Down Expand Up @@ -95,6 +98,10 @@ void SampleMaterials::onInitApp()
CIndirectLighting *indirect = sphereObj->addComponent<CIndirectLighting>();
indirect->setIndirectLightingType(CIndirectLighting::SH4);

// Reflection probe
CGameObject *reflectionProbeObj = zone->createEmptyObject();
m_reflectionProbe = reflectionProbeObj->addComponent<CReflectionProbe>();

// Load texture
CTextureManager *textureManager = CTextureManager::getInstance();
ITexture *brickDiffuse = textureManager->getTexture("SampleMaterials/Textures/brick_diff.png");
Expand All @@ -113,7 +120,16 @@ void SampleMaterials::onInitApp()
m_spheres.push_back(sphereObj);

// Rendering
u32 w = app->getWidth();
u32 h = app->getHeight();

m_forwardRP = new CForwardRP();
m_forwardRP->initRender(w, h);

m_postProcessRP = new CLinearColorRP();
m_postProcessRP->initRender(w, h);

m_forwardRP->setPostProcessor(m_postProcessRP);
}

void SampleMaterials::onUpdate()
Expand Down Expand Up @@ -158,6 +174,9 @@ void SampleMaterials::onRender()

for (CGameObject *sphere : m_spheres)
sphere->setVisible(true);

// bake environment
m_reflectionProbe->bakeProbe(bakeCamera, m_forwardRP, m_scene->getEntityManager());
}

m_forwardRP->render(NULL, m_camera, m_scene->getEntityManager(), core::recti());
Expand Down
Loading

0 comments on commit 4d5a2f2

Please # to comment.