diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 833ea6ed4..04ed3a5db 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -351,6 +351,47 @@ public: } // DegradedIBLShader }; // DegradedIBLShader +// ============================================================================ +class RHDebug : public Shader +{ +public: + GLuint m_tu_shr, m_tu_shg, m_tu_shb; + + RHDebug() + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "rhdebug.vert", + GL_FRAGMENT_SHADER, "rhdebug.frag"); + assignUniforms("RHMatrix", "extents"); + m_tu_shr = 0; + m_tu_shg = 1; + m_tu_shb = 2; + assignTextureUnit(m_tu_shr, "SHR", m_tu_shg, "SHG", + m_tu_shb, "SHB"); + } // RHDebug +}; // RHDebug + +// ============================================================================ +class GlobalIlluminationReconstructionShader + : public TextureShader +{ +public: + GlobalIlluminationReconstructionShader() + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert", + GL_FRAGMENT_SHADER, "utils/decodeNormal.frag", + GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag", + GL_FRAGMENT_SHADER, "gi.frag"); + + assignUniforms("RHMatrix", "InvRHMatrix", "extents"); + assignSamplerNames(0, "ntex", ST_NEAREST_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED, + 2, "SHR", ST_VOLUME_LINEAR_FILTERED, + 3, "SHG", ST_VOLUME_LINEAR_FILTERED, + 4, "SHB", ST_VOLUME_LINEAR_FILTERED); + } // GlobalIlluminationReconstructionShader +}; // GlobalIlluminationReconstructionShader + // ============================================================================ PostProcessing::PostProcessing(IVideoDriver* video_driver) @@ -571,14 +612,14 @@ void PostProcessing::renderRHDebug(unsigned SHR, unsigned SHG, unsigned SHB, const core::vector3df &rh_extend) { glEnable(GL_PROGRAM_POINT_SIZE); - FullScreenShader::RHDebug::getInstance()->use(); - glActiveTexture(GL_TEXTURE0 + FullScreenShader::RHDebug::getInstance()->TU_SHR); + RHDebug::getInstance()->use(); + glActiveTexture(GL_TEXTURE0 + RHDebug::getInstance()->m_tu_shr); glBindTexture(GL_TEXTURE_3D, SHR); - glActiveTexture(GL_TEXTURE0 + FullScreenShader::RHDebug::getInstance()->TU_SHG); + glActiveTexture(GL_TEXTURE0 + RHDebug::getInstance()->m_tu_shg); glBindTexture(GL_TEXTURE_3D, SHG); - glActiveTexture(GL_TEXTURE0 + FullScreenShader::RHDebug::getInstance()->TU_SHB); + glActiveTexture(GL_TEXTURE0 + RHDebug::getInstance()->m_tu_shb); glBindTexture(GL_TEXTURE_3D, SHB); - FullScreenShader::RHDebug::getInstance()->setUniforms(rh_matrix, rh_extend); + RHDebug::getInstance()->setUniforms(rh_matrix, rh_extend); glDrawArrays(GL_POINTS, 0, 32 * 16 * 32); glDisable(GL_PROGRAM_POINT_SIZE); } // renderRHDebug @@ -591,10 +632,10 @@ void PostProcessing::renderGI(const core::matrix4 &RHMatrix, core::matrix4 InvRHMatrix; RHMatrix.getInverse(InvRHMatrix); glDisable(GL_DEPTH_TEST); - FullScreenShader::GlobalIlluminationReconstructionShader::getInstance() + GlobalIlluminationReconstructionShader::getInstance() ->setTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture(), shr, shg, shb); - DrawFullScreenEffect + DrawFullScreenEffect (RHMatrix, InvRHMatrix, rh_extend); } // renderGI diff --git a/src/graphics/render_lighting.cpp b/src/graphics/render_lighting.cpp index a440d772c..49f5ed0da 100644 --- a/src/graphics/render_lighting.cpp +++ b/src/graphics/render_lighting.cpp @@ -185,6 +185,80 @@ public: } // ShadowedSunLightShaderPCF }; // ShadowedSunLightShaderPCF +// ============================================================================ +class ShadowedSunLightShaderESM : public TextureShader +{ +public: + ShadowedSunLightShaderESM() + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert", + GL_FRAGMENT_SHADER, "utils/decodeNormal.frag", + GL_FRAGMENT_SHADER, "utils/SpecularBRDF.frag", + GL_FRAGMENT_SHADER, "utils/DiffuseBRDF.frag", + GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag", + GL_FRAGMENT_SHADER, "utils/SunMRP.frag", + GL_FRAGMENT_SHADER, "sunlightshadowesm.frag"); + + // Use 8 to circumvent a catalyst bug when binding sampler + assignSamplerNames(0, "ntex", ST_NEAREST_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED, + 8, "shadowtex", ST_TRILINEAR_CLAMPED_ARRAY2D); + + assignUniforms("split0", "split1", "split2", "splitmax"); + } // ShadowedSunLightShaderESM +}; // ShadowedSunLightShaderESM + +// ============================================================================ +class RadianceHintsConstructionShader + : public TextureShader +{ +public: + RadianceHintsConstructionShader() + { + if (CVS->isAMDVertexShaderLayerUsable()) + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "slicedscreenquad.vert", + GL_FRAGMENT_SHADER, "rh.frag"); + } + else + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "slicedscreenquad.vert", + GL_GEOMETRY_SHADER, "rhpassthrough.geom", + GL_FRAGMENT_SHADER, "rh.frag"); + } + + assignUniforms("RSMMatrix", "RHMatrix", "extents", "suncol"); + assignSamplerNames(0, "ctex", ST_BILINEAR_FILTERED, + 1, "ntex", ST_BILINEAR_FILTERED, + 2, "dtex", ST_BILINEAR_FILTERED); + } // RadianceHintsConstructionShader +}; // RadianceHintsConstructionShader + +// ============================================================================ +// Workaround for a bug found in kepler nvidia linux and fermi nvidia windows +class NVWorkaroundRadianceHintsConstructionShader + : public TextureShader +{ +public: + NVWorkaroundRadianceHintsConstructionShader() + { + loadProgram(OBJECT,GL_VERTEX_SHADER,"slicedscreenquad_nvworkaround.vert", + GL_GEOMETRY_SHADER, "rhpassthrough.geom", + GL_FRAGMENT_SHADER, "rh.frag"); + + assignUniforms("RSMMatrix", "RHMatrix", "extents", "slice", "suncol"); + + assignSamplerNames(0, "ctex", ST_BILINEAR_FILTERED, + 1, "ntex", ST_BILINEAR_FILTERED, + 2, "dtex", ST_BILINEAR_FILTERED); + } // NVWorkaroundRadianceHintsConstructionShader +}; // NVWorkaroundRadianceHintsConstructionShader + // ============================================================================ static void renderPointLights(unsigned count) { @@ -321,32 +395,31 @@ void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow) glBindVertexArray(SharedGPUObjects::getFullScreenQuadVAO()); if (CVS->needRHWorkaround()) { - FullScreenShader::NVWorkaroundRadianceHintsConstructionShader - ::getInstance()->use(); - FullScreenShader::NVWorkaroundRadianceHintsConstructionShader - ::getInstance()->setTextureUnits( - m_rtts->getRSM().getRTT()[0], - m_rtts->getRSM().getRTT()[1], - m_rtts->getRSM().getDepthTexture()); + NVWorkaroundRadianceHintsConstructionShader::getInstance()->use(); + NVWorkaroundRadianceHintsConstructionShader::getInstance() + ->setTextureUnits( + m_rtts->getRSM().getRTT()[0], + m_rtts->getRSM().getRTT()[1], + m_rtts->getRSM().getDepthTexture()); for (unsigned i = 0; i < 32; i++) { - FullScreenShader::NVWorkaroundRadianceHintsConstructionShader - ::getInstance()->setUniforms(rsm_matrix, rh_matrix, - rh_extend, i, - irr_driver->getSunColor()); + NVWorkaroundRadianceHintsConstructionShader::getInstance() + ->setUniforms(rsm_matrix, rh_matrix, + rh_extend, i, + irr_driver->getSunColor()); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } } else { - FullScreenShader::RadianceHintsConstructionShader::getInstance()->use(); - FullScreenShader::RadianceHintsConstructionShader::getInstance() + RadianceHintsConstructionShader::getInstance()->use(); + RadianceHintsConstructionShader::getInstance() ->setTextureUnits( m_rtts->getRSM().getRTT()[0], m_rtts->getRSM().getRTT()[1], m_rtts->getRSM().getDepthTexture() ); - FullScreenShader::RadianceHintsConstructionShader::getInstance() + RadianceHintsConstructionShader::getInstance() ->setUniforms(rsm_matrix, rh_matrix, rh_extend, irr_driver->getSunColor()); glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 32); @@ -389,14 +462,15 @@ void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow) if (CVS->isESMEnabled()) { - FullScreenShader::ShadowedSunLightShaderESM::getInstance() + ShadowedSunLightShaderESM::getInstance() ->setTextureUnits( irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture(), m_rtts->getShadowFBO().getRTT()[0]); - DrawFullScreenEffect(shadowSplit[1], shadowSplit[2], - shadowSplit[3], shadowSplit[4]); + DrawFullScreenEffect(shadowSplit[1], + shadowSplit[2], + shadowSplit[3], + shadowSplit[4]); } else { diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index eb97be7cb..2c13a2f2a 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -481,88 +481,6 @@ namespace FullScreenShader - ShadowedSunLightShaderESM::ShadowedSunLightShaderESM() - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "screenquad.vert", - GL_FRAGMENT_SHADER, "utils/decodeNormal.frag", - GL_FRAGMENT_SHADER, "utils/SpecularBRDF.frag", - GL_FRAGMENT_SHADER, "utils/DiffuseBRDF.frag", - GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag", - GL_FRAGMENT_SHADER, "utils/SunMRP.frag", - GL_FRAGMENT_SHADER, "sunlightshadowesm.frag"); - - // Use 8 to circumvent a catalyst bug when binding sampler - assignSamplerNames(0, "ntex", ST_NEAREST_FILTERED, - 1, "dtex", ST_NEAREST_FILTERED, - 8, "shadowtex", ST_TRILINEAR_CLAMPED_ARRAY2D); - - assignUniforms("split0", "split1", "split2", "splitmax"); - } - - RadianceHintsConstructionShader::RadianceHintsConstructionShader() - { - if (CVS->isAMDVertexShaderLayerUsable()) - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "slicedscreenquad.vert", - GL_FRAGMENT_SHADER, "rh.frag"); - } - else - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "slicedscreenquad.vert", - GL_GEOMETRY_SHADER, "rhpassthrough.geom", - GL_FRAGMENT_SHADER, "rh.frag"); - } - - assignUniforms("RSMMatrix", "RHMatrix", "extents", "suncol"); - assignSamplerNames(0, "ctex", ST_BILINEAR_FILTERED, - 1, "ntex", ST_BILINEAR_FILTERED, - 2, "dtex", ST_BILINEAR_FILTERED); - } - - NVWorkaroundRadianceHintsConstructionShader::NVWorkaroundRadianceHintsConstructionShader() - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "slicedscreenquad_nvworkaround.vert", - GL_GEOMETRY_SHADER, "rhpassthrough.geom", - GL_FRAGMENT_SHADER, "rh.frag"); - - assignUniforms("RSMMatrix", "RHMatrix", "extents", "slice", "suncol"); - - assignSamplerNames(0, "ctex", ST_BILINEAR_FILTERED, - 1, "ntex", ST_BILINEAR_FILTERED, - 2, "dtex", ST_BILINEAR_FILTERED); - } - - RHDebug::RHDebug() - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "rhdebug.vert", - GL_FRAGMENT_SHADER, "rhdebug.frag"); - assignUniforms("RHMatrix", "extents"); - TU_SHR = 0; - TU_SHG = 1; - TU_SHB = 2; - assignTextureUnit(TU_SHR, "SHR", TU_SHG, "SHG", TU_SHB, "SHB"); - } - - GlobalIlluminationReconstructionShader::GlobalIlluminationReconstructionShader() - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "screenquad.vert", - GL_FRAGMENT_SHADER, "utils/decodeNormal.frag", - GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag", - GL_FRAGMENT_SHADER, "gi.frag"); - - assignUniforms("RHMatrix", "InvRHMatrix", "extents"); - assignSamplerNames(0, "ntex", ST_NEAREST_FILTERED, - 1, "dtex", ST_NEAREST_FILTERED, - 2, "SHR", ST_VOLUME_LINEAR_FILTERED, - 3, "SHG", ST_VOLUME_LINEAR_FILTERED, - 4, "SHB", ST_VOLUME_LINEAR_FILTERED); - } HorizontalBlurShader::HorizontalBlurShader() { diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 6703bd2c5..333df8a34 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -88,43 +88,6 @@ public: SunLightShader(); }; -class ShadowedSunLightShaderESM : public TextureShader -{ -public: - ShadowedSunLightShaderESM(); -}; - -class RadianceHintsConstructionShader : public TextureShader -{ -public: - RadianceHintsConstructionShader(); -}; - -// Workaround for a bug found in kepler nvidia linux and fermi nvidia windows -class NVWorkaroundRadianceHintsConstructionShader : public TextureShader -{ -public: - NVWorkaroundRadianceHintsConstructionShader(); -}; - -class RHDebug : public Shader -{ -public: - GLuint TU_SHR, TU_SHG, TU_SHB; - - RHDebug(); -}; - -class GlobalIlluminationReconstructionShader : public TextureShader -{ -public: - GlobalIlluminationReconstructionShader(); -}; - class HorizontalBlurShader : public TextureShader { public: