From 56059156e0f4b4170f59440b1609e05231cf5562 Mon Sep 17 00:00:00 2001 From: ducphamhong Date: Mon, 5 Oct 2020 21:12:10 +0700 Subject: [PATCH] #86 Setup default linear space color on forwarder rp --- .../Particles/Renderers/CQuadRenderer.cpp | 1 + .../Engine/Source/Material/CMaterial.h | 14 +++- .../Source/RenderPipeline/CForwardRP.cpp | 31 +++++-- .../Engine/Source/RenderPipeline/CForwardRP.h | 6 +- .../Source/RenderPipeline/CLinearColorRP.cpp | 82 ------------------- .../Source/RenderPipeline/CLinearColorRP.h | 52 ------------ Projects/Template/Source/SkylichtEngine.h | 1 - .../Source/SampleDrawPrimitives.cpp | 4 + Samples/Materials/Source/SampleMaterials.cpp | 9 +- Samples/Materials/Source/SampleMaterials.h | 1 - Samples/Noise2D/Source/SampleNoise2D.cpp | 1 + Samples/Noise3D/Source/SampleNoise3D.cpp | 4 + Samples/Particles/Source/SampleParticles.cpp | 4 + .../Source/SampleParticlesExplosion.cpp | 4 + .../Source/SampleParticlesMagicSkill.cpp | 4 + .../Source/SampleParticlesVortex.cpp | 4 + Samples/Shader/Source/SampleShader.cpp | 6 -- Samples/Shader/Source/SampleShader.h | 1 - .../SkinnedMesh/Source/SampleSkinnedMesh.cpp | 6 -- .../SkinnedMesh/Source/SampleSkinnedMesh.h | 1 - Scripts/Template.cpp | 6 -- Scripts/Template.h | 2 - 22 files changed, 68 insertions(+), 176 deletions(-) delete mode 100644 Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.cpp delete mode 100644 Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.h diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/Particles/Renderers/CQuadRenderer.cpp b/Projects/Skylicht/Components/Source/ParticleSystem/Particles/Renderers/CQuadRenderer.cpp index 1467e58e4..8f0eaffe9 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/Particles/Renderers/CQuadRenderer.cpp +++ b/Projects/Skylicht/Components/Source/ParticleSystem/Particles/Renderers/CQuadRenderer.cpp @@ -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); } diff --git a/Projects/Skylicht/Engine/Source/Material/CMaterial.h b/Projects/Skylicht/Engine/Source/Material/CMaterial.h index 9425bed82..39837a403 100644 --- a/Projects/Skylicht/Engine/Source/Material/CMaterial.h +++ b/Projects/Skylicht/Engine/Source/Material/CMaterial.h @@ -163,7 +163,7 @@ namespace Skylicht } CMaterial* clone(CGameObject *gameObject); - + void deleteAllParams(); void deleteExtramParams(); @@ -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); @@ -258,7 +268,7 @@ namespace Skylicht void applyMaterial(SMaterial& mat); - void updateTexture(SMaterial& mat); + void updateTexture(SMaterial& mat); void updateShaderParams(); diff --git a/Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.cpp b/Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.cpp index 01cc0bd1b..3abc05a6b 100644 --- a/Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.cpp +++ b/Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.cpp @@ -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) { @@ -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) @@ -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; @@ -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); } } } \ No newline at end of file diff --git a/Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.h b/Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.h index 87b5b5a67..85625cb72 100644 --- a/Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.h +++ b/Projects/Skylicht/Engine/Source/RenderPipeline/CForwardRP.h @@ -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(); diff --git a/Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.cpp b/Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.cpp deleted file mode 100644 index 70b86318d..000000000 --- a/Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* -!@ -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); - } -} \ No newline at end of file diff --git a/Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.h b/Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.h deleted file mode 100644 index 49b6b35fd..000000000 --- a/Projects/Skylicht/Engine/Source/RenderPipeline/CLinearColorRP.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -!@ -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); - }; -} \ No newline at end of file diff --git a/Projects/Template/Source/SkylichtEngine.h b/Projects/Template/Source/SkylichtEngine.h index 2b3ad3643..e2807d903 100644 --- a/Projects/Template/Source/SkylichtEngine.h +++ b/Projects/Template/Source/SkylichtEngine.h @@ -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" diff --git a/Samples/DrawPrimitives/Source/SampleDrawPrimitives.cpp b/Samples/DrawPrimitives/Source/SampleDrawPrimitives.cpp index 3cbd8152f..b9c89d71d 100644 --- a/Samples/DrawPrimitives/Source/SampleDrawPrimitives.cpp +++ b/Samples/DrawPrimitives/Source/SampleDrawPrimitives.cpp @@ -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() diff --git a/Samples/Materials/Source/SampleMaterials.cpp b/Samples/Materials/Source/SampleMaterials.cpp index 30bb3d1f1..ff40b9b79 100644 --- a/Samples/Materials/Source/SampleMaterials.cpp +++ b/Samples/Materials/Source/SampleMaterials.cpp @@ -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(); } @@ -29,7 +28,6 @@ SampleMaterials::~SampleMaterials() delete m_scene; delete m_forwardRP; - delete m_postProcessRP; Lightmapper::CLightmapper::releaseInstance(); } @@ -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() diff --git a/Samples/Materials/Source/SampleMaterials.h b/Samples/Materials/Source/SampleMaterials.h index e4fb5b7b8..d0a091b8e 100644 --- a/Samples/Materials/Source/SampleMaterials.h +++ b/Samples/Materials/Source/SampleMaterials.h @@ -9,7 +9,6 @@ class SampleMaterials : public IApplicationEventReceiver CCamera *m_guiCamera; CCamera *m_camera; CForwardRP *m_forwardRP; - CLinearColorRP *m_postProcessRP; bool m_bakeSHLighting; diff --git a/Samples/Noise2D/Source/SampleNoise2D.cpp b/Samples/Noise2D/Source/SampleNoise2D.cpp index 4e6598257..d616959cb 100644 --- a/Samples/Noise2D/Source/SampleNoise2D.cpp +++ b/Samples/Noise2D/Source/SampleNoise2D.cpp @@ -151,6 +151,7 @@ void SampleNoise2D::onInitApp() // rendering pipe line m_forwardRP = new CForwardRP(); + m_forwardRP->initRender(w, h); } void SampleNoise2D::onUpdate() diff --git a/Samples/Noise3D/Source/SampleNoise3D.cpp b/Samples/Noise3D/Source/SampleNoise3D.cpp index 7b374583a..452386ab3 100644 --- a/Samples/Noise3D/Source/SampleNoise3D.cpp +++ b/Samples/Noise3D/Source/SampleNoise3D.cpp @@ -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() diff --git a/Samples/Particles/Source/SampleParticles.cpp b/Samples/Particles/Source/SampleParticles.cpp index c68a5bc63..ee0a8157f 100644 --- a/Samples/Particles/Source/SampleParticles.cpp +++ b/Samples/Particles/Source/SampleParticles.cpp @@ -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) diff --git a/Samples/ParticlesExplosion/Source/SampleParticlesExplosion.cpp b/Samples/ParticlesExplosion/Source/SampleParticlesExplosion.cpp index c66f87fce..8736f3435 100644 --- a/Samples/ParticlesExplosion/Source/SampleParticlesExplosion.cpp +++ b/Samples/ParticlesExplosion/Source/SampleParticlesExplosion.cpp @@ -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) diff --git a/Samples/ParticlesMagicSkill/Source/SampleParticlesMagicSkill.cpp b/Samples/ParticlesMagicSkill/Source/SampleParticlesMagicSkill.cpp index 44242d437..b94f5cae8 100644 --- a/Samples/ParticlesMagicSkill/Source/SampleParticlesMagicSkill.cpp +++ b/Samples/ParticlesMagicSkill/Source/SampleParticlesMagicSkill.cpp @@ -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) diff --git a/Samples/ParticlesVortex/Source/SampleParticlesVortex.cpp b/Samples/ParticlesVortex/Source/SampleParticlesVortex.cpp index a337f2228..ba3384295 100644 --- a/Samples/ParticlesVortex/Source/SampleParticlesVortex.cpp +++ b/Samples/ParticlesVortex/Source/SampleParticlesVortex.cpp @@ -70,7 +70,11 @@ void SampleParticlesVortex::onInitApp() initParticleSystem(m_currentParticleObj->addComponent()); // 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) diff --git a/Samples/Shader/Source/SampleShader.cpp b/Samples/Shader/Source/SampleShader.cpp index 5822770ea..748ca8d7a 100644 --- a/Samples/Shader/Source/SampleShader.cpp +++ b/Samples/Shader/Source/SampleShader.cpp @@ -36,7 +36,6 @@ SampleShader::~SampleShader() Lightmapper::CLightmapper::releaseInstance(); delete m_forwardRP; - delete m_postProcessRP; } void SampleShader::onInitApp() @@ -136,11 +135,6 @@ void SampleShader::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 SampleShader::initTestNormalMapShader(CEntityPrefab *prefab, ArrayMaterial& materials) diff --git a/Samples/Shader/Source/SampleShader.h b/Samples/Shader/Source/SampleShader.h index 63684035e..7e62c2a4c 100644 --- a/Samples/Shader/Source/SampleShader.h +++ b/Samples/Shader/Source/SampleShader.h @@ -9,7 +9,6 @@ class SampleShader : public IApplicationEventReceiver CCamera *m_guiCamera; CCamera *m_camera; CForwardRP *m_forwardRP; - CLinearColorRP *m_postProcessRP; CReflectionProbe *m_reflectionProbe; diff --git a/Samples/SkinnedMesh/Source/SampleSkinnedMesh.cpp b/Samples/SkinnedMesh/Source/SampleSkinnedMesh.cpp index f63bcb5b4..46b1115f5 100644 --- a/Samples/SkinnedMesh/Source/SampleSkinnedMesh.cpp +++ b/Samples/SkinnedMesh/Source/SampleSkinnedMesh.cpp @@ -29,7 +29,6 @@ SampleSkinnedMesh::~SampleSkinnedMesh() { delete m_scene; delete m_forwardRP; - delete m_postProcessRP; Lightmapper::CLightmapper::releaseInstance(); } @@ -183,11 +182,6 @@ void SampleSkinnedMesh::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 SampleSkinnedMesh::onUpdate() diff --git a/Samples/SkinnedMesh/Source/SampleSkinnedMesh.h b/Samples/SkinnedMesh/Source/SampleSkinnedMesh.h index 07e63b271..a272957af 100644 --- a/Samples/SkinnedMesh/Source/SampleSkinnedMesh.h +++ b/Samples/SkinnedMesh/Source/SampleSkinnedMesh.h @@ -10,7 +10,6 @@ class SampleSkinnedMesh : public IApplicationEventReceiver CCamera *m_camera; CForwardRP *m_forwardRP; - CLinearColorRP *m_postProcessRP; bool m_bakeSHLighting; diff --git a/Scripts/Template.cpp b/Scripts/Template.cpp index b0c28d03b..33260b9da 100644 --- a/Scripts/Template.cpp +++ b/Scripts/Template.cpp @@ -27,7 +27,6 @@ void installApplication(const std::vector& argv) delete m_largeFont; #endif delete m_forwardRP; - delete m_postProcessRP; } void @project_name@::onInitApp() @@ -104,11 +103,6 @@ void @project_name@::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 @project_name@::onUpdate() diff --git a/Scripts/Template.h b/Scripts/Template.h index b8743964a..96ac76860 100644 --- a/Scripts/Template.h +++ b/Scripts/Template.h @@ -14,8 +14,6 @@ class @project_name@ : public IApplicationEventReceiver #endif CForwardRP *m_forwardRP; - CLinearColorRP *m_postProcessRP; - public: @project_name@(); virtual ~@project_name@();