Skip to content

Commit

Permalink
#86 Setup default linear space color on forwarder rp
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Oct 5, 2020
1 parent 524cb54 commit 5605915
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace Skylicht
{
m_material = new CMaterial("Particle", "BuiltIn/Shader/Particle/ParticleBillboardAdditive.xml");
m_material->setBackfaceCulling(false);
m_material->setZWrite(false);

setMaterialType(m_baseShaderType, m_billboardType);
}
Expand Down
14 changes: 12 additions & 2 deletions Projects/Skylicht/Engine/Source/Material/CMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace Skylicht
}

CMaterial* clone(CGameObject *gameObject);

void deleteAllParams();
void deleteExtramParams();

Expand Down Expand Up @@ -206,6 +206,16 @@ namespace Skylicht
m_frontfaceCulling = b;
}

inline void setZWrite(bool b)
{
m_zWriteEnable = b;
}

inline void setZTest(video::E_COMPARISON_FUNC f)
{
m_zBuffer = f;
}

SUniformValue* getUniform(const char *name);

SUniformTexture* getUniformTexture(const char *name);
Expand Down Expand Up @@ -258,7 +268,7 @@ namespace Skylicht

void applyMaterial(SMaterial& mat);

void updateTexture(SMaterial& mat);
void updateTexture(SMaterial& mat);

void updateShaderParams();

Expand Down
31 changes: 25 additions & 6 deletions Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ This file is part of the "Skylicht Engine".
#include "pch.h"
#include "CForwardRP.h"

#include "Material/Shader/CShaderManager.h"

namespace Skylicht
{
CForwardRP::CForwardRP(bool postProcessor) :
m_usePostProcessor(postProcessor),
CForwardRP::CForwardRP(bool linearRGB) :
m_useLinearRGB(linearRGB),
m_postProcessor(NULL),
m_target(NULL)
{
Expand All @@ -45,8 +47,10 @@ namespace Skylicht
{
m_size.set(w, h);

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

m_finalPass.MaterialType = CShaderManager::getInstance()->getShaderIDByName("TextureLinearRGB");
}

void CForwardRP::render(ITexture *target, CCamera *camera, CEntityManager *entityManager, const core::recti& viewport)
Expand All @@ -58,7 +62,7 @@ namespace Skylicht

ITexture *currentTarget = NULL;

if (m_usePostProcessor == true && m_postProcessor != NULL)
if (m_useLinearRGB == true)
{
driver->setRenderTarget(m_target, true, true);
currentTarget = m_target;
Expand Down Expand Up @@ -95,9 +99,24 @@ namespace Skylicht

onNext(currentTarget, camera, entityManager, viewport);

if (m_usePostProcessor == true && m_postProcessor != NULL)
if (m_useLinearRGB && m_target != NULL)
{
m_postProcessor->postProcessing(target, m_target, NULL, NULL, viewport);
driver->setRenderTarget(target, 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, m_target);

beginRender2D(renderW, renderH);
renderBufferToTarget(0.0f, 0.0f, renderW, renderH, m_finalPass);
}
}
}
6 changes: 4 additions & 2 deletions Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ namespace Skylicht
{
protected:

bool m_usePostProcessor;
bool m_useLinearRGB;

ITexture *m_target;
core::dimension2du m_size;

IPostProcessor *m_postProcessor;

SMaterial m_finalPass;

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

virtual ~CForwardRP();

Expand Down
82 changes: 0 additions & 82 deletions Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.cpp

This file was deleted.

52 changes: 0 additions & 52 deletions Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.h

This file was deleted.

1 change: 0 additions & 1 deletion Projects/Template/Source/SkylichtEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ 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
4 changes: 4 additions & 0 deletions Samples/DrawPrimitives/Source/SampleDrawPrimitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ void SampleDrawPrimitives::onInitApp()
cubeObj2->getTransformEuler()->setPosition(core::vector3df(1.0f, 0.0f, 0.0f));

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

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

void SampleDrawPrimitives::onUpdate()
Expand Down
9 changes: 1 addition & 8 deletions Samples/Materials/Source/SampleMaterials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ SampleMaterials::SampleMaterials() :
m_scene(NULL),
m_bakeSHLighting(true),
m_reflectionProbe(NULL),
m_forwardRP(NULL),
m_postProcessRP(NULL)
m_forwardRP(NULL)
{
Lightmapper::CLightmapper::createGetInstance();
}
Expand All @@ -29,7 +28,6 @@ SampleMaterials::~SampleMaterials()
delete m_scene;

delete m_forwardRP;
delete m_postProcessRP;

Lightmapper::CLightmapper::releaseInstance();
}
Expand Down Expand Up @@ -128,11 +126,6 @@ void SampleMaterials::onInitApp()

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
1 change: 0 additions & 1 deletion Samples/Materials/Source/SampleMaterials.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class SampleMaterials : public IApplicationEventReceiver
CCamera *m_guiCamera;
CCamera *m_camera;
CForwardRP *m_forwardRP;
CLinearColorRP *m_postProcessRP;

bool m_bakeSHLighting;

Expand Down
1 change: 1 addition & 0 deletions Samples/Noise2D/Source/SampleNoise2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void SampleNoise2D::onInitApp()

// rendering pipe line
m_forwardRP = new CForwardRP();
m_forwardRP->initRender(w, h);
}

void SampleNoise2D::onUpdate()
Expand Down
4 changes: 4 additions & 0 deletions Samples/Noise3D/Source/SampleNoise3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ void SampleNoise3D::onInitApp()
#endif

// rendering pipe line
u32 w = app->getWidth();
u32 h = app->getHeight();

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

void SampleNoise3D::onUpdate()
Expand Down
4 changes: 4 additions & 0 deletions Samples/Particles/Source/SampleParticles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ void SampleParticles::onInitApp()
createCanvasText("", core::vector3df(0.0f, 2.0f, 0.0f));

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

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

void SampleParticles::createCanvasText(const char *text, const core::vector3df& position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ void SampleParticlesExplosion::onInitApp()
textLarge->setTextAlign(CGUIElement::Center, CGUIElement::Bottom);

// rendering pipe line
u32 w = app->getWidth();
u32 h = app->getHeight();

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

bool SampleParticlesExplosion::OnEvent(const SEvent& event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ void SampleParticlesMagicSkill::onInitApp()
textLarge->setTextAlign(CGUIElement::Center, CGUIElement::Bottom);

// rendering pipe line
u32 w = app->getWidth();
u32 h = app->getHeight();

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

bool SampleParticlesMagicSkill::OnEvent(const SEvent& event)
Expand Down
4 changes: 4 additions & 0 deletions Samples/ParticlesVortex/Source/SampleParticlesVortex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ void SampleParticlesVortex::onInitApp()
initParticleSystem(m_currentParticleObj->addComponent<Particle::CParticleComponent>());

// rendering pipe line
u32 w = app->getWidth();
u32 h = app->getHeight();

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

void SampleParticlesVortex::initParticleSystem(Particle::CParticleComponent *ps)
Expand Down
Loading

0 comments on commit 5605915

Please sign in to comment.