Skip to content

Commit

Permalink
#86 Turn on/off auto exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Oct 7, 2020
1 parent e6ebf87 commit b287251
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
47 changes: 33 additions & 14 deletions Projects/Skylicht/Engine/Source/RenderPipeline/CPostProcessorRP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace Skylicht
CPostProcessorRP::CPostProcessorRP() :
m_adaptLum(NULL),
m_lumTarget(0),
m_autoExposure(true),
m_bloomEffect(false),
m_fxaa(false),
m_brightFilter(NULL),
Expand All @@ -52,9 +53,15 @@ namespace Skylicht
CPostProcessorRP::~CPostProcessorRP()
{
IVideoDriver *driver = getVideoDriver();
driver->removeTexture(m_luminance[0]);
driver->removeTexture(m_luminance[1]);
driver->removeTexture(m_adaptLum);

if (m_luminance[0] != NULL)
driver->removeTexture(m_luminance[0]);

if (m_luminance[1] != NULL)
driver->removeTexture(m_luminance[1]);

if (m_adaptLum != NULL)
driver->removeTexture(m_adaptLum);

for (int i = 0; i < 8; i++)
{
Expand Down Expand Up @@ -84,9 +91,12 @@ namespace Skylicht
m_size = core::dimension2du((u32)w, (u32)h);
m_lumSize = core::dimension2du(1024, 1024);

m_luminance[0] = driver->addRenderTargetTexture(m_lumSize, "lum_0", ECF_R16F);
m_luminance[1] = driver->addRenderTargetTexture(m_lumSize, "lum_1", ECF_R16F);
m_adaptLum = driver->addRenderTargetTexture(m_lumSize, "lum_adapt", ECF_R16F);
if (m_autoExposure == true)
{
m_luminance[0] = driver->addRenderTargetTexture(m_lumSize, "lum_0", ECF_R16F);
m_luminance[1] = driver->addRenderTargetTexture(m_lumSize, "lum_1", ECF_R16F);
m_adaptLum = driver->addRenderTargetTexture(m_lumSize, "lum_adapt", ECF_R16F);
}

// framebuffer for glow/fxaa
if (m_bloomEffect == true || m_fxaa == true)
Expand All @@ -108,6 +118,7 @@ namespace Skylicht

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

// init lum pass shader
m_lumPass.MaterialType = shaderMgr->getShaderIDByName("Luminance");
Expand Down Expand Up @@ -203,7 +214,8 @@ namespace Skylicht
renderH = (float)viewport.getHeight();
}

luminanceMapGeneration(color);
if (m_autoExposure == true)
luminanceMapGeneration(color);

if (m_bloomEffect || m_fxaa)
{
Expand All @@ -214,13 +226,20 @@ namespace Skylicht
driver->setRenderTarget(finalTarget);
}

m_luminance[m_lumTarget]->regenerateMipMapLevels();

m_finalPass.setTexture(0, color);
m_finalPass.setTexture(1, m_luminance[m_lumTarget]);

beginRender2D(renderW, renderH);
renderBufferToTarget(0.0f, 0.0f, renderW, renderH, m_finalPass);
if (m_autoExposure == true)
{
m_luminance[m_lumTarget]->regenerateMipMapLevels();
m_finalPass.setTexture(0, color);
m_finalPass.setTexture(1, m_luminance[m_lumTarget]);
beginRender2D(renderW, renderH);
renderBufferToTarget(0.0f, 0.0f, renderW, renderH, m_finalPass);
}
else
{
m_linearPass.setTexture(0, color);
beginRender2D(renderW, renderH);
renderBufferToTarget(0.0f, 0.0f, renderW, renderH, m_linearPass);
}

int colorID = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ namespace Skylicht
int m_numTarget;

SMaterial m_finalPass;
SMaterial m_linearPass;
SMaterial m_lumPass;
SMaterial m_adaptLumPass;
SMaterial m_effectPass;

bool m_autoExposure;
bool m_bloomEffect;
bool m_fxaa;

Expand Down Expand Up @@ -79,6 +81,11 @@ namespace Skylicht

void blurUp(int from, int to);

inline void enableAutoExposure(bool b)
{
m_autoExposure = b;
}

inline void enableBloomEffect(bool b)
{
m_bloomEffect = b;
Expand Down
1 change: 1 addition & 0 deletions Samples/Noise3D/Source/SampleNoise3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ void SampleNoise3D::onInitApp()
m_forwardRP->initRender(w, h);

m_postProcessorRP = new CPostProcessorRP();
m_postProcessorRP->enableAutoExposure(false);
m_postProcessorRP->enableBloomEffect(true);
m_postProcessorRP->enableFXAA(true);
m_postProcessorRP->initRender(w, h);
Expand Down

0 comments on commit b287251

Please sign in to comment.