From 4faa7cf2b799ba50f0b6ad79b6342299cb798ad2 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 19:30:11 +0200 Subject: [PATCH 01/27] Store current screen size When UBO support is lacking. --- src/graphics/irr_driver.hpp | 2 ++ src/graphics/render.cpp | 2 ++ src/graphics/shaders.cpp | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index a36b1945e..890b6744d 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -221,6 +221,7 @@ private: core::vector3df rh_extend; core::matrix4 rh_matrix; core::matrix4 rsm_matrix; + core::vector2df m_current_screen_size; /** Additional details to be shown in case that a texture is not found. * This is used to specify details like: "while loading kart '...'" */ @@ -696,6 +697,7 @@ public: const core::matrix4 & getPreviousPVMatrix() { return m_previousProjViewMatrix; } const core::matrix4 &getProjViewMatrix() const { return m_ProjViewMatrix; } const core::matrix4 &getInvProjViewMatrix() const { return m_InvProjViewMatrix; } + const core::vector2df &getCurrentScreenSize() const { return m_current_screen_size; } #ifdef DEBUG /** Removes debug meshes. */ void clearDebugMesh() { m_debug_meshes.clear(); } diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 7c9a4a821..2017972c6 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -563,6 +563,8 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz irr_driver->setViewMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW)); irr_driver->genProjViewMatrix(); + m_current_screen_size = core::vector2df(float(width), float(height)); + const float oldfar = camnode->getFarValue(); const float oldnear = camnode->getNearValue(); float FarValues[] = diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 1727c3508..25759ff0a 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -457,7 +457,7 @@ void bypassUBO(GLuint Program) GLint IPM = glGetUniformLocation(Program, "InverseProjectionMatrix"); glUniformMatrix4fv(IPM, 1, GL_FALSE, irr_driver->getInvProjMatrix().pointer()); GLint Screen = glGetUniformLocation(Program, "screen"); - glUniform2f(Screen, UserConfigParams::m_width, UserConfigParams::m_height); + glUniform2f(Screen, irr_driver->getCurrentScreenSize().X, irr_driver->getCurrentScreenSize().Y); } namespace UtilShader From 160d061e84c2e77c4668c81465f392ea2aeb341c Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 19:36:32 +0200 Subject: [PATCH 02/27] Port Tonemap shader to singleton Should fix kart selection screen without UBO support. --- src/graphics/post_processing.cpp | 9 ++++----- src/graphics/shaders.cpp | 25 ++++--------------------- src/graphics/shaders.hpp | 10 ++++------ 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 24e3968fd..401f22c96 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -645,11 +645,10 @@ static void renderGodRay(GLuint tex, const core::vector2df &sunpos) static void toneMap(FrameBuffer &fbo, GLuint rtt) { fbo.Bind(); - glUseProgram(FullScreenShader::ToneMapShader::Program); - glBindVertexArray(FullScreenShader::ToneMapShader::vao); - setTexture(0, rtt, GL_NEAREST, GL_NEAREST); - setTexture(1, irr_driver->getRenderTargetTexture(RTT_LOG_LUMINANCE), GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST); - FullScreenShader::ToneMapShader::setUniforms(irr_driver->getExposure(), irr_driver->getLwhite(), 0, 1); + glUseProgram(FullScreenShader::ToneMapShader::getInstance()->Program); + glBindVertexArray(FullScreenShader::ToneMapShader::getInstance()->vao); + setTexture(FullScreenShader::ToneMapShader::getInstance()->TU_tex, rtt, GL_NEAREST, GL_NEAREST); + FullScreenShader::ToneMapShader::getInstance()->setUniforms(); glDrawArrays(GL_TRIANGLES, 0, 3); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 25759ff0a..243c55ce3 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -400,7 +400,6 @@ void Shaders::loadShaders() FullScreenShader::MotionBlurShader::init(); FullScreenShader::GodFadeShader::init(); FullScreenShader::GodRayShader::init(); - FullScreenShader::ToneMapShader::init(); FullScreenShader::MLAAColorEdgeDetectionSHader::init(); FullScreenShader::MLAABlendWeightSHader::init(); FullScreenShader::MLAAGatherSHader::init(); @@ -1588,35 +1587,19 @@ namespace FullScreenShader glUniform1i(uniform_tex_512, TU_tex_512); } - GLuint ToneMapShader::Program; - GLuint ToneMapShader::uniform_tex; - GLuint ToneMapShader::uniform_logluminancetex; - GLuint ToneMapShader::uniform_exposure; - GLuint ToneMapShader::uniform_lwhite; - GLuint ToneMapShader::vao; - - void ToneMapShader::init() + ToneMapShader::ToneMapShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getRGBfromCIEXxy.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getCIEXYZ.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/tonemap.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_logluminancetex = glGetUniformLocation(Program, "logluminancetex"); - uniform_exposure = glGetUniformLocation(Program, "exposure"); - uniform_lwhite = glGetUniformLocation(Program, "Lwhite"); + AssignUniforms(); + TU_tex = 0; + AssignTextureUnit(Program, TexUnit(TU_tex, "text")); vao = createFullScreenVAO(Program); } - void ToneMapShader::setUniforms(float exposure, float Lwhite, unsigned TU_tex, unsigned TU_loglum) - { - glUniform1i(uniform_tex, TU_tex); - glUniform1i(uniform_logluminancetex, TU_loglum); - glUniform1f(uniform_exposure, exposure); - glUniform1f(uniform_lwhite, Lwhite); - } - GLuint DepthOfFieldShader::Program; GLuint DepthOfFieldShader::uniform_tex; GLuint DepthOfFieldShader::uniform_depth; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 127de8d65..dac9ea44c 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -523,15 +523,13 @@ public: static void setUniforms(unsigned TU_tex_128, unsigned TU_tex_256, unsigned TU_tex_512); }; -class ToneMapShader +class ToneMapShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_tex, uniform_logluminancetex, uniform_exposure, uniform_lwhite; - static GLuint vao; + GLuint TU_tex; + GLuint vao; - static void init(); - static void setUniforms(float exposure, float Lwhite, unsigned TU_tex, unsigned TU_logluminance); + ToneMapShader(); }; class DepthOfFieldShader From e932638aef6e80893f87f646eebc5da28ec3c440 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 20:07:03 +0200 Subject: [PATCH 03/27] Port sunlight* shaders to singleton. --- data/shaders/sunlightshadowdebug.frag | 58 ---------------- src/graphics/post_processing.cpp | 31 +++------ src/graphics/shaders.cpp | 98 +++------------------------ src/graphics/shaders.hpp | 31 +++------ 4 files changed, 30 insertions(+), 188 deletions(-) delete mode 100644 data/shaders/sunlightshadowdebug.frag diff --git a/data/shaders/sunlightshadowdebug.frag b/data/shaders/sunlightshadowdebug.frag deleted file mode 100644 index d3ad9ac76..000000000 --- a/data/shaders/sunlightshadowdebug.frag +++ /dev/null @@ -1,58 +0,0 @@ -uniform sampler2D ntex; -uniform sampler2D dtex; -uniform sampler2DArrayShadow shadowtex; - -uniform vec3 direction; -uniform vec3 col; - -in vec2 uv; -out vec4 Diff; -out vec4 Spec; - -vec3 DecodeNormal(vec2 n); -vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness); - -vec3 getShadowFactor(vec3 pos) -{ - vec3 cascadeColor[] = vec3[]( - vec3(1., 0., 0.), - vec3(0., 1., 0.), - vec3(0., 0., 1.), - vec3(1., 1., 1.) - ); - for (int i = 0; i < 4; i++) - { - vec4 shadowcoord = (ShadowViewProjMatrixes[i] * vec4(pos, 1.0)); - shadowcoord /= shadowcoord.w; - vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; - if (shadowtexcoord.x < 0. || shadowtexcoord.x > 1. || shadowtexcoord.y < 0. || shadowtexcoord.y > 1.) - continue; - return cascadeColor[i] * texture(shadowtex, vec4(shadowtexcoord, float(i), 0.5 * shadowcoord.z + 0.5)); - } - return vec3(1.); -} - -void main() { - float z = texture(dtex, uv).x; - vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0; - xpos = InverseViewMatrix * InverseProjectionMatrix * xpos; - xpos.xyz /= xpos.w; - - vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.)); - float roughness =texture(ntex, uv).z; - vec3 eyedir = -normalize(xpos.xyz); - - // Normalized on the cpu - vec3 L = direction; - - float NdotL = max(0., dot(norm, L)); - - vec3 Specular = getSpecular(norm, eyedir, L, col, roughness) * NdotL; - vec3 outcol = NdotL * col; - - // Shadows - vec3 factor = getShadowFactor(xpos.xyz); - Diff = vec4(factor * NdotL * col, 1.); - Spec = vec4(factor * Specular, 1.); - return; -} diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 401f22c96..4e3a6eedc 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -278,11 +278,11 @@ void PostProcessing::renderSunlight() glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); - glUseProgram(FullScreenShader::SunLightShader::Program); - glBindVertexArray(FullScreenShader::SunLightShader::vao); - setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST); - setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST); - FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1); + glUseProgram(FullScreenShader::SunLightShader::getInstance()->Program); + glBindVertexArray(FullScreenShader::SunLightShader::getInstance()->vao); + setTexture(FullScreenShader::SunLightShader::getInstance()->TU_ntex, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST); + setTexture(FullScreenShader::SunLightShader::getInstance()->TU_dtex, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST); + FullScreenShader::SunLightShader::getInstance()->setUniforms(cb->getPosition(), video::SColorf(cb->getRed(), cb->getGreen(), cb->getBlue())); glDrawArrays(GL_TRIANGLES, 0, 3); glBindVertexArray(0); } @@ -296,9 +296,9 @@ void PostProcessing::renderShadowedSunlight(const std::vector &su glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); - setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST); - setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST); - glActiveTexture(GL_TEXTURE2); + setTexture(FullScreenShader::ShadowedSunLightShader::getInstance()->TU_ntex, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST); + setTexture(FullScreenShader::ShadowedSunLightShader::getInstance()->TU_dtex, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST); + glActiveTexture(GL_TEXTURE0 + FullScreenShader::ShadowedSunLightShader::getInstance()->TU_shadowtex); glBindTexture(GL_TEXTURE_2D_ARRAY, depthtex); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -307,19 +307,10 @@ void PostProcessing::renderShadowedSunlight(const std::vector &su glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - if (irr_driver->getShadowViz()) - { - glUseProgram(FullScreenShader::ShadowedSunLightDebugShader::Program); - glBindVertexArray(FullScreenShader::ShadowedSunLightDebugShader::vao); - FullScreenShader::ShadowedSunLightDebugShader::setUniforms(cb->getPosition(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2); + glUseProgram(FullScreenShader::ShadowedSunLightShader::getInstance()->Program); + glBindVertexArray(FullScreenShader::ShadowedSunLightShader::getInstance()->vao); + FullScreenShader::ShadowedSunLightShader::getInstance()->setUniforms(cb->getPosition(), video::SColorf(cb->getRed(), cb->getGreen(), cb->getBlue())); - } - else - { - glUseProgram(FullScreenShader::ShadowedSunLightShader::Program); - glBindVertexArray(FullScreenShader::ShadowedSunLightShader::vao); - FullScreenShader::ShadowedSunLightShader::setUniforms(cb->getPosition(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2); - } glDrawArrays(GL_TRIANGLES, 0, 3); glBindVertexArray(0); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 243c55ce3..f8c97c6be 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -390,10 +390,7 @@ void Shaders::loadShaders() FullScreenShader::LayerPassThroughShader::init(); FullScreenShader::LinearizeDepthShader::init(); FullScreenShader::SSAOShader::init(); - FullScreenShader::SunLightShader::init(); FullScreenShader::DiffuseEnvMapShader::init(); - FullScreenShader::ShadowedSunLightShader::init(); - FullScreenShader::ShadowedSunLightDebugShader::init(); FullScreenShader::RadianceHintsConstructionShader::init(); FullScreenShader::RHDebug::init(); FullScreenShader::GlobalIlluminationReconstructionShader::init(); @@ -1623,14 +1620,7 @@ namespace FullScreenShader glUniform1i(uniform_depth, TU_dtex); } - GLuint SunLightShader::Program; - GLuint SunLightShader::uniform_ntex; - GLuint SunLightShader::uniform_dtex; - GLuint SunLightShader::uniform_direction; - GLuint SunLightShader::uniform_col; - GLuint SunLightShader::vao; - - void SunLightShader::init() + SunLightShader::SunLightShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), @@ -1638,26 +1628,16 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlight.frag").c_str()); - uniform_ntex = glGetUniformLocation(Program, "ntex"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_direction = glGetUniformLocation(Program, "direction"); - uniform_col = glGetUniformLocation(Program, "col"); + TU_ntex = 0; + TU_dtex = 1; + AssignTextureUnit(Program, TexUnit(TU_ntex, "ntex"), TexUnit(TU_dtex, "dtex")); + AssignUniforms("direction", "col"); vao = createFullScreenVAO(Program); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void SunLightShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex) - { - if (irr_driver->needUBOWorkaround()) - bypassUBO(Program); - glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z); - glUniform3f(uniform_col, r, g, b); - glUniform1i(uniform_ntex, TU_ntex); - glUniform1i(uniform_dtex, TU_dtex); - } - GLuint DiffuseEnvMapShader::Program; GLuint DiffuseEnvMapShader::uniform_ntex; GLuint DiffuseEnvMapShader::uniform_blueLmn; @@ -1689,15 +1669,7 @@ namespace FullScreenShader glUniform1fv(uniform_redLmn, 9, redSHCoeff); } - GLuint ShadowedSunLightShader::Program; - GLuint ShadowedSunLightShader::uniform_ntex; - GLuint ShadowedSunLightShader::uniform_dtex; - GLuint ShadowedSunLightShader::uniform_shadowtex; - GLuint ShadowedSunLightShader::uniform_direction; - GLuint ShadowedSunLightShader::uniform_col; - GLuint ShadowedSunLightShader::vao; - - void ShadowedSunLightShader::init() + ShadowedSunLightShader::ShadowedSunLightShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), @@ -1705,65 +1677,17 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlightshadow.frag").c_str()); - uniform_ntex = glGetUniformLocation(Program, "ntex"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_shadowtex = glGetUniformLocation(Program, "shadowtex"); - uniform_direction = glGetUniformLocation(Program, "direction"); - uniform_col = glGetUniformLocation(Program, "col"); + TU_ntex = 0; + TU_dtex = 1; + TU_shadowtex = 2; + AssignTextureUnit(Program, TexUnit(TU_ntex, "ntex"), TexUnit(TU_dtex, "dtex"), TexUnit(TU_shadowtex, "shadowtex")); + AssignUniforms("direction", "col"); vao = createFullScreenVAO(Program); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void ShadowedSunLightShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex) - { - if (irr_driver->needUBOWorkaround()) - bypassUBO(Program); - glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z); - glUniform3f(uniform_col, r, g, b); - glUniform1i(uniform_ntex, TU_ntex); - glUniform1i(uniform_dtex, TU_dtex); - glUniform1i(uniform_shadowtex, TU_shadowtex); - } - - GLuint ShadowedSunLightDebugShader::Program; - GLuint ShadowedSunLightDebugShader::uniform_ntex; - GLuint ShadowedSunLightDebugShader::uniform_dtex; - GLuint ShadowedSunLightDebugShader::uniform_shadowtex; - GLuint ShadowedSunLightDebugShader::uniform_direction; - GLuint ShadowedSunLightDebugShader::uniform_col; - GLuint ShadowedSunLightDebugShader::vao; - - void ShadowedSunLightDebugShader::init() - { - Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlightshadowdebug.frag").c_str()); - uniform_ntex = glGetUniformLocation(Program, "ntex"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_shadowtex = glGetUniformLocation(Program, "shadowtex"); - uniform_direction = glGetUniformLocation(Program, "direction"); - uniform_col = glGetUniformLocation(Program, "col"); - vao = createVAO(Program); - - GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); - glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); - } - - void ShadowedSunLightDebugShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex) - { - if (irr_driver->needUBOWorkaround()) - bypassUBO(Program); - glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z); - glUniform3f(uniform_col, r, g, b); - glUniform1i(uniform_ntex, TU_ntex); - glUniform1i(uniform_dtex, TU_dtex); - glUniform1i(uniform_shadowtex, TU_shadowtex); - } - GLuint RadianceHintsConstructionShader::Program; GLuint RadianceHintsConstructionShader::uniform_ctex; GLuint RadianceHintsConstructionShader::uniform_ntex; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index dac9ea44c..fa30a2250 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -543,15 +543,13 @@ public: static void setUniforms(unsigned TU_tex, unsigned TU_depth); }; -class SunLightShader +class SunLightShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_ntex, uniform_dtex, uniform_direction, uniform_col; - static GLuint vao; + GLuint TU_ntex, TU_dtex; + GLuint vao; - static void init(); - static void setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex); + SunLightShader(); }; class DiffuseEnvMapShader @@ -565,26 +563,13 @@ public: static void setUniforms(const core::matrix4 &TransposeViewMatrix, const float *blueSHCoeff, const float *greenSHCoeff, const float *redSHCoeff, unsigned TU_ntex); }; -class ShadowedSunLightShader +class ShadowedSunLightShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex, uniform_direction, uniform_col; - static GLuint vao; + GLuint TU_ntex, TU_dtex, TU_shadowtex; + GLuint vao; - static void init(); - static void setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex); -}; - -class ShadowedSunLightDebugShader -{ -public: - static GLuint Program; - static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex, uniform_direction, uniform_col; - static GLuint vao; - - static void init(); - static void setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex); + ShadowedSunLightShader(); }; class RadianceHintsConstructionShader From 95fb3ea580b8db18e96d2fcb732019a0a47437c5 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 20:44:33 +0200 Subject: [PATCH 04/27] Add support moving texture in rsm. --- data/shaders/rsm.vert | 6 +---- src/graphics/render_geometry.cpp | 44 ++++++++++++++++++++++++++------ src/graphics/shaders.cpp | 23 +++++------------ src/graphics/shaders.hpp | 9 +++---- 4 files changed, 46 insertions(+), 36 deletions(-) diff --git a/data/shaders/rsm.vert b/data/shaders/rsm.vert index 69846d811..09d8c06c4 100644 --- a/data/shaders/rsm.vert +++ b/data/shaders/rsm.vert @@ -2,11 +2,7 @@ uniform mat4 ModelMatrix; uniform mat4 InverseModelMatrix; uniform mat4 RSMMatrix; -uniform mat4 TextureMatrix = - mat4(1., 0., 0., 0., - 0., 1., 0., 0., - 0., 0., 1., 0., - 0., 0., 0., 1.); +uniform mat4 TextureMatrix; #if __VERSION__ >= 330 layout(location = 0) in vec3 Position; diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 25d5204f4..59df1d13c 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -507,10 +507,37 @@ void renderShadow(const std::vector TextureUnits, const std::vector + +template +struct rsm_custom_unroll_args; + +template<> +struct rsm_custom_unroll_args<> +{ + template + static void exec(const core::matrix4 &rsm_matrix, const STK::Tuple &t, Args... args) + { + draw(T::getInstance(), STK::tuple_get<0>(t), rsm_matrix, args...); + } +}; + +template +struct rsm_custom_unroll_args +{ + template + static void exec(const core::matrix4 &rsm_matrix, const STK::Tuple &t, Args... args) + { + rsm_custom_unroll_args::template exec(rsm_matrix, t, STK::tuple_get(t), args...); + } +}; + + + + +template void drawRSM(const core::matrix4 & rsm_matrix, const std::vector TextureUnits, const std::vector >&t) { - glUseProgram(MeshShader::RSMShader::Program); + glUseProgram(MeshShader::RSMShader::getInstance()->Program); glBindVertexArray(getVAO(VertexType)); for (unsigned i = 0; i < t.size(); i++) { @@ -522,7 +549,7 @@ void drawRSM(const core::matrix4 & rsm_matrix, const std::vector Texture compressTexture(mesh->textures[j], true); setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); } - draw(mesh, rsm_matrix, STK::tuple_get<1>(t[i])); + rsm_custom_unroll_args::exec(rsm_matrix, t[i]); } } @@ -568,9 +595,10 @@ void IrrDriver::renderShadows() m_rtts->getRSM().Bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::TU_tex }, ListMatDefault::Arguments); - drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::TU_tex }, ListMatSphereMap::Arguments); - drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::TU_tex }, ListMatUnlit::Arguments); - drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::TU_tex }, ListMatDetails::Arguments); - drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::TU_tex }, ListMatSplatting::Arguments); + drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDefault::Arguments); +// drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatAlphaRef::Arguments); +// drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatSphereMap::Arguments); + drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatUnlit::Arguments); + drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDetails::Arguments); + drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatSplatting::Arguments); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index f8c97c6be..625610bff 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -402,7 +402,6 @@ void Shaders::loadShaders() FullScreenShader::MLAAGatherSHader::init(); MeshShader::BubbleShader::init(); LightShader::PointLightShader::init(); - MeshShader::RSMShader::init(); MeshShader::SkyboxShader::init(); MeshShader::ViewFrustrumShader::init(); ParticleShader::FlipParticleRender::init(); @@ -1003,27 +1002,17 @@ namespace MeshShader glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - GLuint RSMShader::Program; - GLuint RSMShader::uniform_MM; - GLuint RSMShader::uniform_RSMMatrix; - GLuint RSMShader::TU_tex; - - void RSMShader::init() + RSMShader::RSMShader() { - if (irr_driver->getGLSLVersion() < 150) - return; Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/rsm.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/rsm.frag").c_str()); - uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); - uniform_RSMMatrix = glGetUniformLocation(Program, "RSMMatrix"); - AssignTextureUnit(Program, { TexUnit(TU_tex, "tex") }); - } + TU_tex = 0; + AssignUniforms("ModelMatrix", "RSMMatrix", "TextureMatrix"); + AssignTextureUnit(Program, TexUnit(TU_tex, "tex")); - void RSMShader::setUniforms(const core::matrix4 &RSMMatrix, const core::matrix4 &ModelMatrix) - { - glUniformMatrix4fv(uniform_RSMMatrix, 1, GL_FALSE, RSMMatrix.pointer()); - glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } InstancedShadowShader::InstancedShadowShader() diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index fa30a2250..c35d9b7ff 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -331,15 +331,12 @@ public: ShadowShader(); }; -class RSMShader +class RSMShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_MM, uniform_RSMMatrix; - static GLuint TU_tex; + GLuint TU_tex; - static void init(); - static void setUniforms(const core::matrix4 &RSMMatrix, const core::matrix4 &ModelMatrix); + RSMShader(); }; class InstancedShadowShader : public ShaderHelperSingleton From dbed303d90b5cf18bcd117a14026b7932dc624a9 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 21:02:16 +0200 Subject: [PATCH 05/27] Try to fix ci --- src/graphics/render_geometry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 59df1d13c..4a204a6e8 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -549,7 +549,7 @@ void drawRSM(const core::matrix4 & rsm_matrix, const std::vector Texture compressTexture(mesh->textures[j], true); setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); } - rsm_custom_unroll_args::exec(rsm_matrix, t[i]); + rsm_custom_unroll_args::template exec(rsm_matrix, t[i]); } } From 6c3aeceb5161b3f6b3cd59c3c4074fb151b51281 Mon Sep 17 00:00:00 2001 From: vlj Date: Thu, 7 Aug 2014 22:32:42 +0200 Subject: [PATCH 06/27] Fix GI It was using wrong swizzle for depth texture. --- data/shaders/rh.frag | 4 ++-- data/shaders/rhdebug.frag | 2 +- data/shaders/rhdebug.vert | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data/shaders/rh.frag b/data/shaders/rh.frag index ed760b4ab..0e9df85c0 100644 --- a/data/shaders/rh.frag +++ b/data/shaders/rh.frag @@ -60,7 +60,7 @@ void main(void) vec2 uv = RHuv + offset * 0.01; // Get world position and normal from the RSM sample - float depth = texture(dtex, uv).z; + float depth = texture(dtex, uv).x; vec4 RSMPos = inverse(RSMMatrix) * (2. * vec4(uv, depth, 1.) - 1.); RSMPos /= RSMPos.w; vec3 RSMAlbedo = texture(ctex, uv).xyz; @@ -74,7 +74,7 @@ void main(void) float dist = distance(SamplePos, RSMPos.xyz) / R_wcs; // Determine the incident direction. // Avoid very close samples (and numerical instability problems) - vec3 RSM_to_RH_dir = (dist <= 0.00) ? vec3(0.) : normalize(SamplePos - RSMPos.xyz); + vec3 RSM_to_RH_dir = (dist <= 0.1) ? vec3(0.) : normalize(SamplePos - RSMPos.xyz); float dotprod = max(dot(RSM_to_RH_dir, normal.xyz), 0.); float factor = dotprod / (0.1 + dist * dist); diff --git a/data/shaders/rhdebug.frag b/data/shaders/rhdebug.frag index 6d31a2144..7ce357cc2 100644 --- a/data/shaders/rhdebug.frag +++ b/data/shaders/rhdebug.frag @@ -10,5 +10,5 @@ void main() float r = texture(SHR, uvw).w; float g = texture(SHG, uvw).w; float b = texture(SHB, uvw).w; - FragColor = max(vec4(r, g, b, 1.0), vec4(0.)); + FragColor = max(10. * vec4(r, g, b, 1.0), vec4(0.)); } diff --git a/data/shaders/rhdebug.vert b/data/shaders/rhdebug.vert index 42e9e654f..1edc4a37d 100644 --- a/data/shaders/rhdebug.vert +++ b/data/shaders/rhdebug.vert @@ -15,6 +15,6 @@ void main(void) uvw = vec3(gx, gy, gz) / vec3(resolution); vec3 WorldPos = (2. * uvw - 1.) * extents; gl_Position = ProjectionMatrix * ViewMatrix * RHMatrix * vec4(WorldPos, 1.); - gl_PointSize = 100. / gl_Position.w; + gl_PointSize = 500. / gl_Position.w; } \ No newline at end of file From 60f76ee612f148afb143d3de5a174eb664e87129 Mon Sep 17 00:00:00 2001 From: vlj Date: Thu, 7 Aug 2014 22:45:25 +0200 Subject: [PATCH 07/27] Fix RSM --- data/shaders/rsm.vert | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/data/shaders/rsm.vert b/data/shaders/rsm.vert index 09d8c06c4..ddec08e3a 100644 --- a/data/shaders/rsm.vert +++ b/data/shaders/rsm.vert @@ -1,5 +1,4 @@ uniform mat4 ModelMatrix; -uniform mat4 InverseModelMatrix; uniform mat4 RSMMatrix; uniform mat4 TextureMatrix; @@ -24,9 +23,9 @@ out vec4 color; void main(void) { mat4 ModelViewProjectionMatrix = RSMMatrix * ModelMatrix; - mat4 TransposeInverseModel = transpose(InverseModelMatrix); + mat4 TransposeInverseModel = transpose(inverse(ModelMatrix)); gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); - nor = (vec4(Normal, 0.)).xyz; + nor = (TransposeInverseModel * vec4(Normal, 0.)).xyz; uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; color = Color.zyxw; } From 8db09a55cd6844e19619a53361ccde871d70cf2b Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Fri, 8 Aug 2014 01:07:55 +0200 Subject: [PATCH 08/27] Add Splatting RSM shader type. --- data/shaders/rsm.frag | 1 + data/shaders/rsm.vert | 10 +++++++++- data/shaders/splatting_rsm.frag | 27 +++++++++++++++++++++++++++ src/graphics/render_geometry.cpp | 24 ++++++++++++++++-------- src/graphics/shaders.cpp | 17 +++++++++++++++++ src/graphics/shaders.hpp | 8 ++++++++ 6 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 data/shaders/splatting_rsm.frag diff --git a/data/shaders/rsm.frag b/data/shaders/rsm.frag index 05d9be685..1294e79c7 100644 --- a/data/shaders/rsm.frag +++ b/data/shaders/rsm.frag @@ -8,6 +8,7 @@ layout (location = 1) out vec3 RSMNormals; void main() { + if (texture(tex, uv).a < .5) discard; RSMColor = texture(tex, uv).xyz * color.rgb; RSMNormals = .5 * normalize(nor) + .5; } diff --git a/data/shaders/rsm.vert b/data/shaders/rsm.vert index ddec08e3a..68da61338 100644 --- a/data/shaders/rsm.vert +++ b/data/shaders/rsm.vert @@ -1,22 +1,29 @@ uniform mat4 ModelMatrix; uniform mat4 RSMMatrix; -uniform mat4 TextureMatrix; +uniform mat4 TextureMatrix = + mat4(1., 0., 0., 0., + 0., 1., 0., 0., + 0., 0., 1., 0., + 0., 0., 0., 1.); #if __VERSION__ >= 330 layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Normal; layout(location = 2) in vec4 Color; layout(location = 3) in vec2 Texcoord; +layout(location = 4) in vec2 SecondTexcoord; #else in vec3 Position; in vec3 Normal; in vec4 Color; in vec2 Texcoord; +in vec2 SecondTexcoord; #endif out vec3 nor; out vec2 uv; +out vec2 uv_bis; out vec4 color; @@ -27,5 +34,6 @@ void main(void) gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); nor = (TransposeInverseModel * vec4(Normal, 0.)).xyz; uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; + uv_bis = SecondTexcoord; color = Color.zyxw; } diff --git a/data/shaders/splatting_rsm.frag b/data/shaders/splatting_rsm.frag new file mode 100644 index 000000000..3812b6e51 --- /dev/null +++ b/data/shaders/splatting_rsm.frag @@ -0,0 +1,27 @@ +uniform sampler2D tex_layout; +uniform sampler2D tex_detail0; +uniform sampler2D tex_detail1; +uniform sampler2D tex_detail2; +uniform sampler2D tex_detail3; + +in vec2 uv; +in vec2 uv_bis; +in vec3 nor; +layout (location = 0) out vec3 RSMColor; +layout (location = 1) out vec3 RSMNormals; + +void main() +{ + vec4 splatting = texture(tex_layout, uv_bis); + vec4 detail0 = texture(tex_detail0, uv); + vec4 detail1 = texture(tex_detail1, uv); + vec4 detail2 = texture(tex_detail2, uv); + vec4 detail3 = texture(tex_detail3, uv); + + vec4 splatted = splatting.r * detail0 + + splatting.g * detail1 + + splatting.b * detail2 + + max(0., (1.0 - splatting.r - splatting.g - splatting.b)) * detail3; + RSMColor = splatted.rgb; + RSMNormals = .5 * normalize(nor) + .5; +} diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 4a204a6e8..001dcc486 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -534,10 +534,10 @@ struct rsm_custom_unroll_args -template +template void drawRSM(const core::matrix4 & rsm_matrix, const std::vector TextureUnits, const std::vector >&t) { - glUseProgram(MeshShader::RSMShader::getInstance()->Program); + glUseProgram(T::getInstance()->Program); glBindVertexArray(getVAO(VertexType)); for (unsigned i = 0; i < t.size(); i++) { @@ -549,7 +549,7 @@ void drawRSM(const core::matrix4 & rsm_matrix, const std::vector Texture compressTexture(mesh->textures[j], true); setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); } - rsm_custom_unroll_args::template exec(rsm_matrix, t[i]); + rsm_custom_unroll_args::template exec(rsm_matrix, t[i]); } } @@ -595,10 +595,18 @@ void IrrDriver::renderShadows() m_rtts->getRSM().Bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDefault::Arguments); -// drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatAlphaRef::Arguments); + drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDefault::Arguments); + drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatAlphaRef::Arguments); // drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatSphereMap::Arguments); - drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatUnlit::Arguments); - drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDetails::Arguments); - drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatSplatting::Arguments); + drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatUnlit::Arguments); + drawRSM(rsm_matrix, std::vector{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDetails::Arguments); + drawRSM(rsm_matrix, + std::vector{ + 8, + MeshShader::SplattingRSMShader::getInstance()->TU_layout, + MeshShader::SplattingRSMShader::getInstance()->TU_detail0, + MeshShader::SplattingRSMShader::getInstance()->TU_detail1, + MeshShader::SplattingRSMShader::getInstance()->TU_detail2, + MeshShader::SplattingRSMShader::getInstance()->TU_detail3}, + ListMatSplatting::Arguments); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 625610bff..c6477679f 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1015,6 +1015,23 @@ namespace MeshShader glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } + SplattingRSMShader::SplattingRSMShader() + { + Program = LoadProgram( + GL_VERTEX_SHADER, file_manager->getAsset("shaders/rsm.vert").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/splatting_rsm.frag").c_str()); + TU_layout = 0; + TU_detail0 = 1; + TU_detail1 = 2; + TU_detail2 = 3; + TU_detail3 = 4; + AssignUniforms("ModelMatrix", "RSMMatrix"); + AssignTextureUnit(Program, TexUnit(TU_layout, "tex_layout"), TexUnit(TU_detail0, "tex_detail0"), TexUnit(TU_detail1, "tex_detail1"), TexUnit(TU_detail2, "tex_detail2"), TexUnit(TU_detail3, "tex_detail3")); + + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); + } + InstancedShadowShader::InstancedShadowShader() { // Geometry shader needed diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index c35d9b7ff..5763e057e 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -339,6 +339,14 @@ public: RSMShader(); }; +class SplattingRSMShader : public ShaderHelperSingleton +{ +public: + GLuint TU_layout, TU_detail0, TU_detail1, TU_detail2, TU_detail3; + + SplattingRSMShader(); +}; + class InstancedShadowShader : public ShaderHelperSingleton { public: From 5ba2f6c97b612685ee632b5d573020de156cfc45 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Fri, 8 Aug 2014 01:47:29 +0200 Subject: [PATCH 09/27] Inadvertantly inverted RSM and model matrixes. --- src/graphics/shaders.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index c6477679f..a44122feb 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1008,7 +1008,7 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/rsm.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/rsm.frag").c_str()); TU_tex = 0; - AssignUniforms("ModelMatrix", "RSMMatrix", "TextureMatrix"); + AssignUniforms("RSMMatrix", "ModelMatrix", "TextureMatrix"); AssignTextureUnit(Program, TexUnit(TU_tex, "tex")); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); @@ -1025,7 +1025,7 @@ namespace MeshShader TU_detail1 = 2; TU_detail2 = 3; TU_detail3 = 4; - AssignUniforms("ModelMatrix", "RSMMatrix"); + AssignUniforms("RSMMatrix", "ModelMatrix"); AssignTextureUnit(Program, TexUnit(TU_layout, "tex_layout"), TexUnit(TU_detail0, "tex_detail0"), TexUnit(TU_detail1, "tex_detail1"), TexUnit(TU_detail2, "tex_detail2"), TexUnit(TU_detail3, "tex_detail3")); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); From cdb760ae51775c00ae2ea2d98528d85b7aaab7f8 Mon Sep 17 00:00:00 2001 From: vlj Date: Fri, 8 Aug 2014 21:46:55 +0200 Subject: [PATCH 10/27] Try to use lambdas. --- src/graphics/render_geometry.cpp | 95 ++++++++++++++++++++++++-------- src/utils/tuple.hpp | 11 ++-- 2 files changed, 78 insertions(+), 28 deletions(-) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 001dcc486..e54fed03e 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -31,6 +31,7 @@ #include "utils/tuple.hpp" #include +#include namespace RenderGeometry { @@ -78,19 +79,6 @@ namespace RenderGeometry } using namespace RenderGeometry; -template -void draw(const GLMesh *mesh, uniforms... Args) -{ - irr_driver->IncreaseObjectCount(); - GLenum ptype = mesh->PrimitiveType; - GLenum itype = mesh->IndexType; - size_t count = mesh->IndexCount; - - Shader::setUniforms(Args...); - glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, mesh->vaoBaseVertex); -} - - template void draw(const T *Shader, const GLMesh *mesh, uniforms... Args) { @@ -508,34 +496,94 @@ void renderShadow(const std::vector TextureUnits, const std::vector + +/*template struct rsm_custom_unroll_args; template<> struct rsm_custom_unroll_args<> { - template - static void exec(const core::matrix4 &rsm_matrix, const STK::Tuple &t, Args... args) + + template + static void exec(Type::FuncType draw_func, const std::tuple &t, Args... args) { - draw(T::getInstance(), STK::tuple_get<0>(t), rsm_matrix, args...); + draw_func(args...); } }; template struct rsm_custom_unroll_args { - template - static void exec(const core::matrix4 &rsm_matrix, const STK::Tuple &t, Args... args) + template + static void exec(std::function draw_func, const std::tuple &t, Args... args) { - rsm_custom_unroll_args::template exec(rsm_matrix, t, STK::tuple_get(t), args...); + rsm_custom_unroll_args::exec(draw_func, t, std::get(t), args...); + } +};*/ + +template +struct unroll_args; + +template<> +struct unroll_args<0> +{ + template + static void exec(std::function draw_func, const STK::Tuple &t, TupleTypes... args) + { + draw_func(args...); } }; +template +struct unroll_args +{ + template + static void exec(std::function draw_func, const STK::Tuple &t, Args... args) + { + unroll_args::template exec(draw_func, t, STK::tuple_get(t), args...); + } +}; +template +struct remap_tuple; +template<> +struct remap_tuple<> +{ + template + static STK::Tuple remap(const STK::Tuple &t, Args... args) + { + return STK::make_tuple(args...); + } +}; + +template +struct remap_tuple +{ + template + static auto remap(const STK::Tuple &t, Args... args) -> decltype(remap_tuple::template remap(t, STK::tuple_get(t), args...)) + { + return remap_tuple::template remap(t, STK::tuple_get(t), args...); + } +}; + +template +struct Lambda +{ + GLMesh *mesh; + core::matrix4 rsm_mat; + + Lambda(GLMesh *m, const core::matrix4 &mat) : mesh(m), rsm_mat(mat) {} + + template + std::function getLambda(STK::Tuple) + { + return [=](Args... args){ draw(T::getInstance(), mesh, rsm_mat, args...); }; + }; +}; template -void drawRSM(const core::matrix4 & rsm_matrix, const std::vector TextureUnits, const std::vector >&t) +void drawRSM(const core::matrix4 & rsm_matrix, const std::vector TextureUnits, const std::vector >&t) { glUseProgram(T::getInstance()->Program); glBindVertexArray(getVAO(VertexType)); @@ -549,7 +597,10 @@ void drawRSM(const core::matrix4 & rsm_matrix, const std::vector Texture compressTexture(mesh->textures[j], true); setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); } - rsm_custom_unroll_args::template exec(rsm_matrix, t[i]); +// auto remappedtuple = STK::tuple_cat(std::make_tuple(STK::tuple_get<0>(t[i]), rsm_matrix), remap_tuple::template remap(t[i])); + auto remappedtuple = remap_tuple::template remap(t[i]); + typedef decltype(remappedtuple) RemappedTypleType; + unroll_args::value >::template exec(Lambda(STK::tuple_get<0>(t[i]), rsm_matrix).getLambda(remappedtuple), remappedtuple); } } diff --git a/src/utils/tuple.hpp b/src/utils/tuple.hpp index 007bebbee..c1a2fbebf 100644 --- a/src/utils/tuple.hpp +++ b/src/utils/tuple.hpp @@ -78,14 +78,13 @@ namespace STK { // return sizeof...(T); //} + template + struct TupleSize; + template - struct TupleSize + struct TupleSize > { - int value; - TupleSize() - { - value = sizeof...(T); - } + static const int value = sizeof...(T); }; } From 99ce91dc46f2acf20d61cd7318e420db17ac9865 Mon Sep 17 00:00:00 2001 From: Deve Date: Fri, 8 Aug 2014 23:06:25 +0200 Subject: [PATCH 11/27] Strength of bouncy edges should depend on soccer ball mass. --- src/physics/physical_object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index 57d2fa1c1..9c2bae169 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -574,7 +574,7 @@ void PhysicalObject::hit(const Material *m, const Vec3 &normal) if(isSoccerBall() && m != NULL && m->getCollisionReaction() == Material::PUSH_SOCCER_BALL) { - m_body->applyCentralImpulse(normal * 100.0f); + m_body->applyCentralImpulse(normal * m_mass * 5.0f); } } // hit From 281fceee0bcf239cb33eb5b0e646f4b943cce0aa Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 9 Aug 2014 00:36:12 +0200 Subject: [PATCH 12/27] Revert "Try to use lambdas." This reverts commit cdb760ae51775c00ae2ea2d98528d85b7aaab7f8. --- src/graphics/render_geometry.cpp | 95 ++++++++------------------------ src/utils/tuple.hpp | 11 ++-- 2 files changed, 28 insertions(+), 78 deletions(-) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index e54fed03e..001dcc486 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -31,7 +31,6 @@ #include "utils/tuple.hpp" #include -#include namespace RenderGeometry { @@ -79,6 +78,19 @@ namespace RenderGeometry } using namespace RenderGeometry; +template +void draw(const GLMesh *mesh, uniforms... Args) +{ + irr_driver->IncreaseObjectCount(); + GLenum ptype = mesh->PrimitiveType; + GLenum itype = mesh->IndexType; + size_t count = mesh->IndexCount; + + Shader::setUniforms(Args...); + glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, mesh->vaoBaseVertex); +} + + template void draw(const T *Shader, const GLMesh *mesh, uniforms... Args) { @@ -496,94 +508,34 @@ void renderShadow(const std::vector TextureUnits, const std::vector +template struct rsm_custom_unroll_args; template<> struct rsm_custom_unroll_args<> { - - template - static void exec(Type::FuncType draw_func, const std::tuple &t, Args... args) + template + static void exec(const core::matrix4 &rsm_matrix, const STK::Tuple &t, Args... args) { - draw_func(args...); + draw(T::getInstance(), STK::tuple_get<0>(t), rsm_matrix, args...); } }; template struct rsm_custom_unroll_args { - template - static void exec(std::function draw_func, const std::tuple &t, Args... args) + template + static void exec(const core::matrix4 &rsm_matrix, const STK::Tuple &t, Args... args) { - rsm_custom_unroll_args::exec(draw_func, t, std::get(t), args...); - } -};*/ - -template -struct unroll_args; - -template<> -struct unroll_args<0> -{ - template - static void exec(std::function draw_func, const STK::Tuple &t, TupleTypes... args) - { - draw_func(args...); + rsm_custom_unroll_args::template exec(rsm_matrix, t, STK::tuple_get(t), args...); } }; -template -struct unroll_args -{ - template - static void exec(std::function draw_func, const STK::Tuple &t, Args... args) - { - unroll_args::template exec(draw_func, t, STK::tuple_get(t), args...); - } -}; -template -struct remap_tuple; -template<> -struct remap_tuple<> -{ - template - static STK::Tuple remap(const STK::Tuple &t, Args... args) - { - return STK::make_tuple(args...); - } -}; - -template -struct remap_tuple -{ - template - static auto remap(const STK::Tuple &t, Args... args) -> decltype(remap_tuple::template remap(t, STK::tuple_get(t), args...)) - { - return remap_tuple::template remap(t, STK::tuple_get(t), args...); - } -}; - -template -struct Lambda -{ - GLMesh *mesh; - core::matrix4 rsm_mat; - - Lambda(GLMesh *m, const core::matrix4 &mat) : mesh(m), rsm_mat(mat) {} - - template - std::function getLambda(STK::Tuple) - { - return [=](Args... args){ draw(T::getInstance(), mesh, rsm_mat, args...); }; - }; -}; template -void drawRSM(const core::matrix4 & rsm_matrix, const std::vector TextureUnits, const std::vector >&t) +void drawRSM(const core::matrix4 & rsm_matrix, const std::vector TextureUnits, const std::vector >&t) { glUseProgram(T::getInstance()->Program); glBindVertexArray(getVAO(VertexType)); @@ -597,10 +549,7 @@ void drawRSM(const core::matrix4 & rsm_matrix, const std::vector Texture compressTexture(mesh->textures[j], true); setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); } -// auto remappedtuple = STK::tuple_cat(std::make_tuple(STK::tuple_get<0>(t[i]), rsm_matrix), remap_tuple::template remap(t[i])); - auto remappedtuple = remap_tuple::template remap(t[i]); - typedef decltype(remappedtuple) RemappedTypleType; - unroll_args::value >::template exec(Lambda(STK::tuple_get<0>(t[i]), rsm_matrix).getLambda(remappedtuple), remappedtuple); + rsm_custom_unroll_args::template exec(rsm_matrix, t[i]); } } diff --git a/src/utils/tuple.hpp b/src/utils/tuple.hpp index c1a2fbebf..007bebbee 100644 --- a/src/utils/tuple.hpp +++ b/src/utils/tuple.hpp @@ -78,13 +78,14 @@ namespace STK { // return sizeof...(T); //} - template - struct TupleSize; - template - struct TupleSize > + struct TupleSize { - static const int value = sizeof...(T); + int value; + TupleSize() + { + value = sizeof...(T); + } }; } From 5dffc86d26d680dbf1756824c8985a1b7ff86870 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 9 Aug 2014 00:43:28 +0200 Subject: [PATCH 13/27] Use lambda for debug_slider instead. --- src/states_screens/dialogs/debug_slider.cpp | 18 ++++-------------- src/states_screens/dialogs/debug_slider.hpp | 10 ++++++---- src/utils/debug.cpp | 4 ++-- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/states_screens/dialogs/debug_slider.cpp b/src/states_screens/dialogs/debug_slider.cpp index bd0bb7635..4fe8c8051 100644 --- a/src/states_screens/dialogs/debug_slider.cpp +++ b/src/states_screens/dialogs/debug_slider.cpp @@ -32,8 +32,8 @@ using namespace GUIEngine; // ------------------------------------------------------------------------------------------------------ -DebugSliderDialog::DebugSliderDialog(std::string id, irr::core::stringw msg) : - ModalDialog(0.85f, 0.25f, MODAL_DIALOG_LOCATION_BOTTOM) +DebugSliderDialog::DebugSliderDialog(std::string id, irr::core::stringw msg, std::function G, std::function S) : + ModalDialog(0.85f, 0.25f, MODAL_DIALOG_LOCATION_BOTTOM), Getter(G), Setter(S) { //if (StateManager::get()->getGameState() == GUIEngine::GAME) //{ @@ -45,17 +45,10 @@ DebugSliderDialog::DebugSliderDialog(std::string id, irr::core::stringw msg) : loadFromFile("debug_slider.stkgui"); - LabelWidget* message = getWidget("title"); message->setText( msg.c_str(), false ); - float val; - if (m_id == "lwhite") - val = irr_driver->getLwhite() * 10.f; - if (m_id == "exposure") - val = irr_driver->getExposure() * 100.f; - - getWidget("value_slider")->setValue(int(val)); + getWidget("value_slider")->setValue(Getter()); } // ------------------------------------------------------------------------------------------------------ @@ -82,10 +75,7 @@ GUIEngine::EventPropagation DebugSliderDialog::processEvent(const std::string& e { int value = getWidget("value_slider")->getValue(); Log::info("DebugSlider", "Value for <%s> : %i", m_id.c_str(), value); - if (m_id == "lwhite") - irr_driver->setLwhite(value / 10.f); - if (m_id == "exposure") - irr_driver->setExposure(value / 100.f); + Setter(value); return GUIEngine::EVENT_BLOCK; } diff --git a/src/states_screens/dialogs/debug_slider.hpp b/src/states_screens/dialogs/debug_slider.hpp index 53107f8aa..fa246b339 100644 --- a/src/states_screens/dialogs/debug_slider.hpp +++ b/src/states_screens/dialogs/debug_slider.hpp @@ -22,6 +22,7 @@ #include "guiengine/modaldialog.hpp" #include "utils/cpp2011.hpp" #include "utils/leak_check.hpp" +#include /** * \brief For internal value tweaking @@ -32,18 +33,19 @@ class DebugSliderDialog : public GUIEngine::ModalDialog private: std::string m_id; + std::function Getter; + std::function Setter; public: - DebugSliderDialog(std::string id, ::core::stringw msg); - + DebugSliderDialog(std::string id, ::core::stringw msg, std::function G, std::function S); + ~DebugSliderDialog(); - + virtual void onEnterPressedInternal() OVERRIDE; virtual void onUpdate(float dt) OVERRIDE; - GUIEngine::EventPropagation processEvent(const std::string& eventSource); }; diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp index 1f711f4a6..0f3dbdfec 100644 --- a/src/utils/debug.cpp +++ b/src/utils/debug.cpp @@ -440,11 +440,11 @@ bool onEvent(const SEvent &event) } else if (cmdID == DEBUG_TWEAK_SHADER_EXPOSURE) { - new DebugSliderDialog("exposure", "Exposure"); + new DebugSliderDialog("exposure", "Exposure", [](){ return irr_driver->getExposure() * 100.f; }, [](int v){irr_driver->setExposure(v / 100.f); }); } else if (cmdID == DEBUG_TWEAK_SHADER_LWHITE) { - new DebugSliderDialog("lwhite", "LWhite"); + new DebugSliderDialog("lwhite", "LWhite", [](){ return irr_driver->getLwhite() * 10.f; }, [](int v){irr_driver->setLwhite(v / 10.f); }); } } From c8a9515ad083de03be9bc2f10ef7e657bbc8bdde Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 9 Aug 2014 01:10:19 +0200 Subject: [PATCH 14/27] Use debug slider to change ambient on the fly. --- src/graphics/irr_driver.cpp | 6 ++++++ src/graphics/irr_driver.hpp | 22 +------------------- src/tracks/track.cpp | 2 -- src/utils/debug.cpp | 41 ++++++++++++++++++++++++++++--------- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 60fe86a9c..4767794d7 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1624,8 +1624,14 @@ void IrrDriver::onUnloadWorld() void IrrDriver::setAmbientLight(const video::SColor &light) { m_scene_manager->setAmbientLight(light); + m_SH_dirty = true; } // setAmbientLight +video::SColorf IrrDriver::getAmbientLight() const +{ + return m_scene_manager->getAmbientLight(); +} + // ---------------------------------------------------------------------------- /** Displays the FPS on the screen. */ diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 890b6744d..ec358cf2a 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -213,8 +213,6 @@ private: Shaders *m_shaders; /** Wind. */ Wind *m_wind; - float m_exposure; - float m_lwhite; /** RTTs. */ RTT *m_rtts; std::vector sun_ortho_matrix; @@ -291,25 +289,7 @@ public: return hasVSLayer; } - float getExposure() const - { - return m_exposure; - } - - void setExposure(float v) - { - m_exposure = v; - } - - float getLwhite() const - { - return m_lwhite; - } - - void setLwhite(float v) - { - m_lwhite = v; - } + video::SColorf getAmbientLight() const; struct GlowData { scene::ISceneNode * node; diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 47830652d..8c8aa64dc 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -430,8 +430,6 @@ void Track::cleanup() //----------------------------------------------------------------------------- void Track::loadTrackInfo() { - irr_driver->setLwhite(1.); - irr_driver->setExposure(0.09f); // Default values m_use_fog = false; m_fog_max = 1.0f; diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp index 0f3dbdfec..18c71d5fe 100644 --- a/src/utils/debug.cpp +++ b/src/utils/debug.cpp @@ -83,8 +83,9 @@ enum DebugMenuCommand DEBUG_TOGGLE_GUI, DEBUG_HIDE_KARTS, DEBUG_THROTTLE_FPS, - DEBUG_TWEAK_SHADER_EXPOSURE, - DEBUG_TWEAK_SHADER_LWHITE + DEBUG_CHANGE_AMBIENT_RED, + DEBUG_CHANGE_AMBIENT_GREEN, + DEBUG_CHANGE_AMBIENT_BLUE, }; // ----------------------------------------------------------------------------- @@ -188,10 +189,11 @@ bool onEvent(const SEvent &event) sub->addItem(L"Anvil", DEBUG_ATTACHMENT_ANVIL); sub->addItem(L"Parachute", DEBUG_ATTACHMENT_PARACHUTE); - //mnu->addItem(L"Adjust shaders >", -1, true, true); - //sub = mnu->getSubMenu(3); - //sub->addItem(L"Exposure", DEBUG_TWEAK_SHADER_EXPOSURE); - //sub->addItem(L"LWhite", DEBUG_TWEAK_SHADER_LWHITE); + mnu->addItem(L"Adjust Ambient >", -1, true, true); + sub = mnu->getSubMenu(3); + sub->addItem(L"Red ", DEBUG_CHANGE_AMBIENT_RED); + sub->addItem(L"Green", DEBUG_CHANGE_AMBIENT_GREEN); + sub->addItem(L"Blue", DEBUG_CHANGE_AMBIENT_BLUE); mnu->addItem(L"Profiler",DEBUG_PROFILER); if (UserConfigParams::m_profiler_enabled) @@ -438,13 +440,32 @@ bool onEvent(const SEvent &event) kart->getNode()->setVisible(false); } } - else if (cmdID == DEBUG_TWEAK_SHADER_EXPOSURE) + else if (cmdID == DEBUG_CHANGE_AMBIENT_RED) { - new DebugSliderDialog("exposure", "Exposure", [](){ return irr_driver->getExposure() * 100.f; }, [](int v){irr_driver->setExposure(v / 100.f); }); + new DebugSliderDialog("Red", "Red", [](){ return irr_driver->getAmbientLight().r * 255.; }, + [](int v){ + video::SColor ambient = irr_driver->getAmbientLight().toSColor(); + ambient.setRed(v); + irr_driver->setAmbientLight(ambient); } + ); } - else if (cmdID == DEBUG_TWEAK_SHADER_LWHITE) + else if (cmdID == DEBUG_CHANGE_AMBIENT_GREEN) { - new DebugSliderDialog("lwhite", "LWhite", [](){ return irr_driver->getLwhite() * 10.f; }, [](int v){irr_driver->setLwhite(v / 10.f); }); + new DebugSliderDialog("Green", "Green", [](){ return irr_driver->getAmbientLight().g * 255.; }, + [](int v){ + video::SColor ambient = irr_driver->getAmbientLight().toSColor(); + ambient.setGreen(v); + irr_driver->setAmbientLight(ambient); } + ); + } + else if (cmdID == DEBUG_CHANGE_AMBIENT_BLUE) + { + new DebugSliderDialog("Blue", "Blue", [](){ return irr_driver->getAmbientLight().b * 255.; }, + [](int v){ + video::SColor ambient = irr_driver->getAmbientLight().toSColor(); + ambient.setBlue(v); + irr_driver->setAmbientLight(ambient); } + ); } } From 54c9f32033964f99908eca958218bc9e0fdee311 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 9 Aug 2014 01:30:36 +0200 Subject: [PATCH 15/27] Store ambientlight directly in irr_driver. --- src/graphics/irr_driver.cpp | 6 ++++-- src/graphics/irr_driver.hpp | 3 ++- src/graphics/render_skybox.cpp | 3 +-- src/utils/debug.cpp | 12 ++++++------ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 4767794d7..f964512a5 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1621,15 +1621,17 @@ void IrrDriver::onUnloadWorld() /** Sets the ambient light. * \param light The colour of the light to set. */ -void IrrDriver::setAmbientLight(const video::SColor &light) +void IrrDriver::setAmbientLight(const video::SColorf &light) { + printf("redval %f\n", light.getRed()); m_scene_manager->setAmbientLight(light); + m_ambient = light; m_SH_dirty = true; } // setAmbientLight video::SColorf IrrDriver::getAmbientLight() const { - return m_scene_manager->getAmbientLight(); + return m_ambient; } // ---------------------------------------------------------------------------- diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index ec358cf2a..ba269eb76 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -341,6 +341,7 @@ private: std::vector m_forcedbloom; std::vector m_background; + video::SColorf m_ambient; STKRenderingPass m_phase; @@ -391,7 +392,7 @@ public: const std::string& mask_path); void displayFPS(); bool OnEvent(const irr::SEvent &event); - void setAmbientLight(const video::SColor &light); + void setAmbientLight(const video::SColorf &light); std::string generateSmallerTextures(const std::string& dir); std::string getSmallerTexture(const std::string& texture); video::ITexture *getTexture(FileManager::AssetType type, diff --git a/src/graphics/render_skybox.cpp b/src/graphics/render_skybox.cpp index 17d8014b6..1460570e7 100644 --- a/src/graphics/render_skybox.cpp +++ b/src/graphics/render_skybox.cpp @@ -485,8 +485,7 @@ void IrrDriver::generateDiffuseCoefficients() int sh_w = 16; int sh_h = 16; - const video::SColorf& ambientf = irr_driver->getSceneManager()->getAmbientLight(); - video::SColor ambient = ambientf.toSColor(); + video::SColor ambient = m_ambient.toSColor(); unsigned char *sh_rgba[6]; for (unsigned i = 0; i < 6; i++) diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp index 18c71d5fe..144bf77d4 100644 --- a/src/utils/debug.cpp +++ b/src/utils/debug.cpp @@ -444,8 +444,8 @@ bool onEvent(const SEvent &event) { new DebugSliderDialog("Red", "Red", [](){ return irr_driver->getAmbientLight().r * 255.; }, [](int v){ - video::SColor ambient = irr_driver->getAmbientLight().toSColor(); - ambient.setRed(v); + video::SColorf ambient = irr_driver->getAmbientLight(); + ambient.setColorComponentValue(0, v / 255.); irr_driver->setAmbientLight(ambient); } ); } @@ -453,8 +453,8 @@ bool onEvent(const SEvent &event) { new DebugSliderDialog("Green", "Green", [](){ return irr_driver->getAmbientLight().g * 255.; }, [](int v){ - video::SColor ambient = irr_driver->getAmbientLight().toSColor(); - ambient.setGreen(v); + video::SColorf ambient = irr_driver->getAmbientLight(); + ambient.setColorComponentValue(1, v / 255.); irr_driver->setAmbientLight(ambient); } ); } @@ -462,8 +462,8 @@ bool onEvent(const SEvent &event) { new DebugSliderDialog("Blue", "Blue", [](){ return irr_driver->getAmbientLight().b * 255.; }, [](int v){ - video::SColor ambient = irr_driver->getAmbientLight().toSColor(); - ambient.setBlue(v); + video::SColorf ambient = irr_driver->getAmbientLight(); + ambient.setColorComponentValue(2, v / 255.); irr_driver->setAmbientLight(ambient); } ); } From 41cca2e56e04aa05e438f876b52de7d5c73d6c21 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 9 Aug 2014 01:41:30 +0200 Subject: [PATCH 16/27] Fix ambient handling. --- src/graphics/camera.cpp | 1 - src/graphics/irr_driver.cpp | 4 +--- src/graphics/irr_driver.hpp | 1 - src/graphics/render_skybox.cpp | 2 +- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 2ebed145a..88fa3eb92 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -669,7 +669,6 @@ void Camera::activate() { irr::scene::ISceneManager *sm = irr_driver->getSceneManager(); sm->setActiveCamera(m_camera); - sm->setAmbientLight(m_ambient_light); irr_driver->getVideoDriver()->setViewPort(m_viewport); } // activate diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index f964512a5..dcf55b666 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1623,15 +1623,13 @@ void IrrDriver::onUnloadWorld() */ void IrrDriver::setAmbientLight(const video::SColorf &light) { - printf("redval %f\n", light.getRed()); m_scene_manager->setAmbientLight(light); - m_ambient = light; m_SH_dirty = true; } // setAmbientLight video::SColorf IrrDriver::getAmbientLight() const { - return m_ambient; + return m_scene_manager->getAmbientLight(); } // ---------------------------------------------------------------------------- diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index ba269eb76..3f40ccd14 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -341,7 +341,6 @@ private: std::vector m_forcedbloom; std::vector m_background; - video::SColorf m_ambient; STKRenderingPass m_phase; diff --git a/src/graphics/render_skybox.cpp b/src/graphics/render_skybox.cpp index 1460570e7..64b5a9952 100644 --- a/src/graphics/render_skybox.cpp +++ b/src/graphics/render_skybox.cpp @@ -485,7 +485,7 @@ void IrrDriver::generateDiffuseCoefficients() int sh_w = 16; int sh_h = 16; - video::SColor ambient = m_ambient.toSColor(); + video::SColor ambient = m_scene_manager->getAmbientLight().toSColor(); unsigned char *sh_rgba[6]; for (unsigned i = 0; i < 6; i++) From 496269e73b04212c987a5f10431843dbc68f8f5f Mon Sep 17 00:00:00 2001 From: vlj Date: Sat, 9 Aug 2014 18:51:52 +0200 Subject: [PATCH 17/27] Make SSAO param changeable. --- data/shaders/ssao.frag | 7 +- src/graphics/irr_driver.hpp | 34 ++++++++ src/graphics/post_processing.cpp | 11 +-- src/graphics/shaders.cpp | 141 +------------------------------ src/graphics/shaders.hpp | 13 ++- src/tracks/track.cpp | 3 + 6 files changed, 53 insertions(+), 156 deletions(-) diff --git a/data/shaders/ssao.frag b/data/shaders/ssao.frag index 2e551ddb4..dc4b44347 100644 --- a/data/shaders/ssao.frag +++ b/data/shaders/ssao.frag @@ -2,15 +2,14 @@ // and improvements here http://graphics.cs.williams.edu/papers/SAOHPG12/ uniform sampler2D dtex; -uniform vec4 samplePoints[16]; +uniform float radius = 1.; +uniform float k = 1.5; +uniform float sigma = 1.; out float AO; -const float sigma = 1.; const float tau = 7.; const float beta = 0.002; const float epsilon = .00001; -const float radius = 1.; -const float k = 1.5; #define SAMPLES 16 diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 3f40ccd14..3c96f0caa 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -344,6 +344,10 @@ private: STKRenderingPass m_phase; + float m_ssao_radius; + float m_ssao_k; + float m_ssao_sigma; + #ifdef DEBUG /** Used to visualise skeletons. */ std::vector m_debug_meshes; @@ -678,6 +682,36 @@ public: const core::matrix4 &getProjViewMatrix() const { return m_ProjViewMatrix; } const core::matrix4 &getInvProjViewMatrix() const { return m_InvProjViewMatrix; } const core::vector2df &getCurrentScreenSize() const { return m_current_screen_size; } + // ------------------------------------------------------------------------ + float getSSAORadius() const + { + return m_ssao_radius; + } + + void setSSAORadius(float v) + { + m_ssao_radius = v; + } + + float getSSAOK() const + { + return m_ssao_k; + } + + void setSSAOK(float v) + { + m_ssao_k = v; + } + + float getSSAOSigma() const + { + return m_ssao_sigma; + } + + void setSSAOSigma(float v) + { + m_ssao_sigma = v; + } #ifdef DEBUG /** Removes debug meshes. */ void clearDebugMesh() { m_debug_meshes.clear(); } diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 4e3a6eedc..3ae8af717 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -525,16 +525,13 @@ void PostProcessing::renderSSAO() if (!noise_tex) noise_tex = irr_driver->getTexture(file_manager->getAsset("textures/noise.png").c_str()); - glUseProgram(FullScreenShader::SSAOShader::Program); - glBindVertexArray(FullScreenShader::SSAOShader::vao); + glUseProgram(FullScreenShader::SSAOShader::getInstance()->Program); + glBindVertexArray(FullScreenShader::SSAOShader::getInstance()->vao); - setTexture(0, irr_driver->getRenderTargetTexture(RTT_LINEAR_DEPTH), GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST); + setTexture(FullScreenShader::SSAOShader::getInstance()->TU_dtex, irr_driver->getRenderTargetTexture(RTT_LINEAR_DEPTH), GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST); glGenerateMipmap(GL_TEXTURE_2D); - setTexture(1, getTextureGLuint(noise_tex), GL_LINEAR, GL_LINEAR); - FullScreenShader::SSAOShader::setUniforms(core::vector2df(float(UserConfigParams::m_width), - float(UserConfigParams::m_height)), - 0, 1); + FullScreenShader::SSAOShader::getInstance()->setUniforms(irr_driver->getSSAORadius(), irr_driver->getSSAOK(), irr_driver->getSSAOSigma()); glDrawArrays(GL_TRIANGLES, 0, 3); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index a44122feb..34422cf79 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -389,7 +389,6 @@ void Shaders::loadShaders() FullScreenShader::PassThroughShader::init(); FullScreenShader::LayerPassThroughShader::init(); FullScreenShader::LinearizeDepthShader::init(); - FullScreenShader::SSAOShader::init(); FullScreenShader::DiffuseEnvMapShader::init(); FullScreenShader::RadianceHintsConstructionShader::init(); FullScreenShader::RHDebug::init(); @@ -1996,152 +1995,20 @@ namespace FullScreenShader vao = createVAO(Program); } - GLuint SSAOShader::Program; - GLuint SSAOShader::uniform_ntex; - GLuint SSAOShader::uniform_dtex; - GLuint SSAOShader::uniform_noise_texture; - GLuint SSAOShader::uniform_samplePoints; - GLuint SSAOShader::vao; - float SSAOShader::SSAOSamples[64]; - - void SSAOShader::init() + SSAOShader::SSAOShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/ssao.frag").c_str()); - uniform_ntex = glGetUniformLocation(Program, "ntex"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_noise_texture = glGetUniformLocation(Program, "noise_texture"); - uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]"); + TU_dtex = 0; + AssignTextureUnit(Program, TexUnit(TU_dtex, "dtex")); + AssignUniforms("radius", "k", "sigma"); vao = createFullScreenVAO(Program); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); - - // SSAOSamples[4 * i] and SSAOSamples[4 * i + 1] can be negative - - SSAOSamples[0] = 0.135061f; - SSAOSamples[1] = 0.207948f; - SSAOSamples[2] = 0.968770f; - SSAOSamples[3] = 0.983032f; - - SSAOSamples[4] = 0.273456f; - SSAOSamples[5] = -0.805390f; - SSAOSamples[6] = 0.525898f; - SSAOSamples[7] = 0.942808f; - - SSAOSamples[8] = 0.443450f; - SSAOSamples[9] = -0.803786f; - SSAOSamples[10] = 0.396585f; - SSAOSamples[11] = 0.007996f; - - SSAOSamples[12] = 0.742420f; - SSAOSamples[13] = -0.620072f; - SSAOSamples[14] = 0.253621f; - SSAOSamples[15] = 0.284829f; - - SSAOSamples[16] = 0.892464f; - SSAOSamples[17] = 0.046221f; - SSAOSamples[18] = 0.448744f; - SSAOSamples[19] = 0.753655f; - - SSAOSamples[20] = 0.830350f; - SSAOSamples[21] = -0.043593f; - SSAOSamples[22] = 0.555535f; - SSAOSamples[23] = 0.357463f; - - SSAOSamples[24] = -0.600612f; - SSAOSamples[25] = -0.536421f; - SSAOSamples[26] = 0.592889f; - SSAOSamples[27] = 0.670583f; - - SSAOSamples[28] = -0.280658f; - SSAOSamples[29] = 0.674894f; - SSAOSamples[30] = 0.682458f; - SSAOSamples[31] = 0.553362f; - - SSAOSamples[32] = -0.654493f; - SSAOSamples[33] = -0.140866f; - SSAOSamples[34] = 0.742830f; - SSAOSamples[35] = 0.699820f; - - SSAOSamples[36] = 0.114730f; - SSAOSamples[37] = 0.873130f; - SSAOSamples[38] = 0.473794f; - SSAOSamples[39] = 0.483901f; - - SSAOSamples[40] = 0.699167f; - SSAOSamples[41] = 0.632210f; - SSAOSamples[42] = 0.333879f; - SSAOSamples[43] = 0.010956f; - - SSAOSamples[44] = 0.904603f; - SSAOSamples[45] = 0.393410f; - SSAOSamples[46] = 0.164080f; - SSAOSamples[47] = 0.780297f; - - SSAOSamples[48] = 0.631662f; - SSAOSamples[49] = -0.405195f; - SSAOSamples[50] = 0.660924f; - SSAOSamples[51] = 0.865596f; - - SSAOSamples[52] = -0.195668f; - SSAOSamples[53] = 0.629185f; - SSAOSamples[54] = 0.752223f; - SSAOSamples[55] = 0.019013f; - - SSAOSamples[56] = -0.511316f; - SSAOSamples[57] = 0.635504f; - SSAOSamples[58] = 0.578524f; - SSAOSamples[59] = 0.605457f; - - SSAOSamples[60] = -0.898843f; - SSAOSamples[61] = 0.067382f; - SSAOSamples[62] = 0.433061f; - SSAOSamples[63] = 0.772942f; - - // Generate another random distribution, if needed - /* for (unsigned i = 0; i < 16; i++) { - // Use double to avoid denorm and get a true uniform distribution - // Generate z component between [0.1; 1] to avoid being too close from surface - double z = rand(); - z /= RAND_MAX; - z = 0.1 + 0.9 * z; - - // Now generate x,y on the unit circle - double x = rand(); - x /= RAND_MAX; - x = 2 * x - 1; - double y = rand(); - y /= RAND_MAX; - y = 2 * y - 1; - double xynorm = sqrt(x * x + y * y); - x /= xynorm; - y /= xynorm; - // Now resize x,y so that norm(x,y,z) is one - x *= sqrt(1. - z * z); - y *= sqrt(1. - z * z); - - // Norm factor - double w = rand(); - w /= RAND_MAX; - SSAOSamples[4 * i] = (float)x; - SSAOSamples[4 * i + 1] = (float)y; - SSAOSamples[4 * i + 2] = (float)z; - SSAOSamples[4 * i + 3] = (float)w; - }*/ - } - - void SSAOShader::setUniforms(const core::vector2df &screen, unsigned TU_dtex, unsigned TU_noise) - { - if (irr_driver->needUBOWorkaround()) - bypassUBO(Program); - glUniform4fv(uniform_samplePoints, 16, SSAOSamples); - - glUniform1i(uniform_dtex, TU_dtex); - glUniform1i(uniform_noise_texture, TU_noise); } GLuint FogShader::Program; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 5763e057e..491ab2f38 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -729,16 +729,13 @@ public: static void init(); }; -class SSAOShader +class SSAOShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_ntex, uniform_dtex, uniform_noise_texture, uniform_samplePoints; - static GLuint vao; - static float SSAOSamples[64]; - - static void init(); - static void setUniforms(const core::vector2df &screen, unsigned TU_dtex, unsigned TU_noise); + GLuint TU_dtex; + GLuint vao; + + SSAOShader(); }; class FogShader diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 8c8aa64dc..4cbc4040f 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -445,6 +445,9 @@ void Track::loadTrackInfo() m_sun_specular_color = video::SColor(255, 255, 255, 255); m_sun_diffuse_color = video::SColor(255, 255, 255, 255); m_sun_position = core::vector3df(0, 0, 0); + irr_driver->setSSAORadius(1.); + irr_driver->setSSAOK(1.5); + irr_driver->setSSAOSigma(1.); XMLNode *root = file_manager->createXMLTree(m_filename); if(!root || root->getName()!="track") From 768d51d0c379cf9979b30d486d6f251fabb1af28 Mon Sep 17 00:00:00 2001 From: vlj Date: Sat, 9 Aug 2014 19:22:30 +0200 Subject: [PATCH 18/27] Add sliders to change ssao parameters. --- data/gui/debug_slider.stkgui | 14 +++++- src/states_screens/dialogs/debug_slider.cpp | 35 ++++++--------- src/states_screens/dialogs/debug_slider.hpp | 9 ++-- src/utils/debug.cpp | 48 ++++++++++----------- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/data/gui/debug_slider.stkgui b/data/gui/debug_slider.stkgui index 2fb46728a..3f9d3fdf2 100644 --- a/data/gui/debug_slider.stkgui +++ b/data/gui/debug_slider.stkgui @@ -1,7 +1,17 @@
-
diff --git a/src/states_screens/dialogs/debug_slider.cpp b/src/states_screens/dialogs/debug_slider.cpp index 4fe8c8051..bcbcb25d0 100644 --- a/src/states_screens/dialogs/debug_slider.cpp +++ b/src/states_screens/dialogs/debug_slider.cpp @@ -32,23 +32,19 @@ using namespace GUIEngine; // ------------------------------------------------------------------------------------------------------ -DebugSliderDialog::DebugSliderDialog(std::string id, irr::core::stringw msg, std::function G, std::function S) : - ModalDialog(0.85f, 0.25f, MODAL_DIALOG_LOCATION_BOTTOM), Getter(G), Setter(S) +DebugSliderDialog::DebugSliderDialog() : ModalDialog(0.85f, 0.25f, MODAL_DIALOG_LOCATION_CENTER) { - //if (StateManager::get()->getGameState() == GUIEngine::GAME) - //{ - // World::getWorld()->schedulePause(World::IN_GAME_MENU_PHASE); - //} - - m_id = id; m_fade_background = false; loadFromFile("debug_slider.stkgui"); +} - LabelWidget* message = getWidget("title"); - message->setText( msg.c_str(), false ); - - getWidget("value_slider")->setValue(Getter()); +void DebugSliderDialog::setSliderHook(std::string id, unsigned min, unsigned max, std::function G, std::function S) +{ + getWidget(id.c_str())->setValue(G()); + getWidget(id.c_str())->setMin(min); + getWidget(id.c_str())->setMax(max); + Setters[id] = S; } // ------------------------------------------------------------------------------------------------------ @@ -71,15 +67,12 @@ void DebugSliderDialog::onEnterPressedInternal() GUIEngine::EventPropagation DebugSliderDialog::processEvent(const std::string& eventSource) { - if (eventSource == "value_slider") - { - int value = getWidget("value_slider")->getValue(); - Log::info("DebugSlider", "Value for <%s> : %i", m_id.c_str(), value); - Setter(value); - return GUIEngine::EVENT_BLOCK; - } - - return GUIEngine::EVENT_LET; + if (Setters.find(eventSource) == Setters.end()) + return GUIEngine::EVENT_LET; + int value = getWidget(eventSource.c_str())->getValue(); + Log::info("DebugSlider", "Value for <%s> : %i", eventSource.c_str(), value); + Setters[eventSource](value); + return GUIEngine::EVENT_BLOCK; } // ------------------------------------------------------------------------------------------------------ diff --git a/src/states_screens/dialogs/debug_slider.hpp b/src/states_screens/dialogs/debug_slider.hpp index fa246b339..5c4aaf734 100644 --- a/src/states_screens/dialogs/debug_slider.hpp +++ b/src/states_screens/dialogs/debug_slider.hpp @@ -33,16 +33,15 @@ class DebugSliderDialog : public GUIEngine::ModalDialog private: std::string m_id; - std::function Getter; - std::function Setter; + std::map >Setters; public: - - - DebugSliderDialog(std::string id, ::core::stringw msg, std::function G, std::function S); + DebugSliderDialog(); ~DebugSliderDialog(); + void setSliderHook(std::string id, unsigned min, unsigned max, std::function G, std::function S); + virtual void onEnterPressedInternal() OVERRIDE; virtual void onUpdate(float dt) OVERRIDE; diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp index 144bf77d4..57a74ec8e 100644 --- a/src/utils/debug.cpp +++ b/src/utils/debug.cpp @@ -83,9 +83,7 @@ enum DebugMenuCommand DEBUG_TOGGLE_GUI, DEBUG_HIDE_KARTS, DEBUG_THROTTLE_FPS, - DEBUG_CHANGE_AMBIENT_RED, - DEBUG_CHANGE_AMBIENT_GREEN, - DEBUG_CHANGE_AMBIENT_BLUE, + DEBUG_VISUAL_VALUES, }; // ----------------------------------------------------------------------------- @@ -189,11 +187,7 @@ bool onEvent(const SEvent &event) sub->addItem(L"Anvil", DEBUG_ATTACHMENT_ANVIL); sub->addItem(L"Parachute", DEBUG_ATTACHMENT_PARACHUTE); - mnu->addItem(L"Adjust Ambient >", -1, true, true); - sub = mnu->getSubMenu(3); - sub->addItem(L"Red ", DEBUG_CHANGE_AMBIENT_RED); - sub->addItem(L"Green", DEBUG_CHANGE_AMBIENT_GREEN); - sub->addItem(L"Blue", DEBUG_CHANGE_AMBIENT_BLUE); + mnu->addItem(L"Adjust values", DEBUG_VISUAL_VALUES); mnu->addItem(L"Profiler",DEBUG_PROFILER); if (UserConfigParams::m_profiler_enabled) @@ -440,31 +434,35 @@ bool onEvent(const SEvent &event) kart->getNode()->setVisible(false); } } - else if (cmdID == DEBUG_CHANGE_AMBIENT_RED) + else if (cmdID == DEBUG_VISUAL_VALUES) { - new DebugSliderDialog("Red", "Red", [](){ return irr_driver->getAmbientLight().r * 255.; }, + DebugSliderDialog *dsd = new DebugSliderDialog(); + dsd->setSliderHook( "red_slider", 0, 255, [](){ return irr_driver->getAmbientLight().r * 255.; }, [](int v){ video::SColorf ambient = irr_driver->getAmbientLight(); ambient.setColorComponentValue(0, v / 255.); irr_driver->setAmbientLight(ambient); } ); - } - else if (cmdID == DEBUG_CHANGE_AMBIENT_GREEN) - { - new DebugSliderDialog("Green", "Green", [](){ return irr_driver->getAmbientLight().g * 255.; }, - [](int v){ - video::SColorf ambient = irr_driver->getAmbientLight(); - ambient.setColorComponentValue(1, v / 255.); - irr_driver->setAmbientLight(ambient); } - ); - } - else if (cmdID == DEBUG_CHANGE_AMBIENT_BLUE) - { - new DebugSliderDialog("Blue", "Blue", [](){ return irr_driver->getAmbientLight().b * 255.; }, + dsd->setSliderHook("green_slider", 0, 255, [](){ return irr_driver->getAmbientLight().g * 255.; }, [](int v){ video::SColorf ambient = irr_driver->getAmbientLight(); - ambient.setColorComponentValue(2, v / 255.); - irr_driver->setAmbientLight(ambient); } + ambient.setColorComponentValue(1, v / 255.); + irr_driver->setAmbientLight(ambient); } + ); + dsd->setSliderHook("blue_slider", 0, 255, [](){ return irr_driver->getAmbientLight().b * 255.; }, + [](int v){ + video::SColorf ambient = irr_driver->getAmbientLight(); + ambient.setColorComponentValue(2, v / 255.); + irr_driver->setAmbientLight(ambient); } + ); + dsd->setSliderHook("ssao_radius", 0, 100, [](){ return irr_driver->getSSAORadius() * 10; }, + [](int v){irr_driver->setSSAORadius(v / 10.); } + ); + dsd->setSliderHook("ssao_k", 0, 100, [](){ return irr_driver->getSSAOK() * 10; }, + [](int v){irr_driver->setSSAOK(v / 10.); } + ); + dsd->setSliderHook("ssao_sigma", 0, 100, [](){ return irr_driver->getSSAOSigma() * 10; }, + [](int v){irr_driver->setSSAOSigma(v / 10.); } ); } } From bcc2196ccf3493e192af670b6b9e097413fb9d8c Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 9 Aug 2014 20:05:49 +0200 Subject: [PATCH 19/27] Fix SSAO on splatting material. --- data/shaders/splatting.frag | 36 ++++++++++++++---------------------- src/graphics/shaders.cpp | 1 + 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/data/shaders/splatting.frag b/data/shaders/splatting.frag index 10c9b8ad1..d8bdc0555 100644 --- a/data/shaders/splatting.frag +++ b/data/shaders/splatting.frag @@ -3,10 +3,6 @@ uniform sampler2D tex_detail0; uniform sampler2D tex_detail1; uniform sampler2D tex_detail2; uniform sampler2D tex_detail3; -uniform sampler2D DiffuseMap; -uniform sampler2D SpecularMap; -uniform sampler2D SSAO; -uniform vec3 ambient; #if __VERSION__ >= 130 in vec2 uv; @@ -18,26 +14,22 @@ varying vec2 uv_bis; #define FragColor gl_FragColor #endif +vec3 getLightFactor(float specMapValue); void main() { - // Splatting part - vec4 splatting = texture(tex_layout, uv_bis); - vec4 detail0 = texture(tex_detail0, uv); - vec4 detail1 = texture(tex_detail1, uv); - vec4 detail2 = texture(tex_detail2, uv); - vec4 detail3 = texture(tex_detail3, uv); - vec4 detail4 = vec4(0.0); + // Splatting part + vec4 splatting = texture(tex_layout, uv_bis); + vec4 detail0 = texture(tex_detail0, uv); + vec4 detail1 = texture(tex_detail1, uv); + vec4 detail2 = texture(tex_detail2, uv); + vec4 detail3 = texture(tex_detail3, uv); + vec4 detail4 = vec4(0.0); - vec4 splatted = splatting.r * detail0 + - splatting.g * detail1 + - splatting.b * detail2 + - max(0., (1.0 - splatting.r - splatting.g - splatting.b)) * detail3; + vec4 splatted = splatting.r * detail0 + + splatting.g * detail1 + + splatting.b * detail2 + + max(0., (1.0 - splatting.r - splatting.g - splatting.b)) * detail3; - vec2 tc = gl_FragCoord.xy / screen; - vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz; - vec3 SpecularComponent = texture(SpecularMap, tc).xyz; - float ao = texture(SSAO, tc).x; - vec3 LightFactor = ao * ambient + DiffuseComponent + SpecularComponent; - - FragColor = vec4(splatted.xyz * LightFactor, 1.); + vec3 LightFactor = getLightFactor(1.); + FragColor = vec4(splatted.xyz * LightFactor, 1.); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 34422cf79..beef0086b 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -878,6 +878,7 @@ namespace MeshShader { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/splatting.frag").c_str()); AssignUniforms("ModelMatrix"); TU_tex_layout = 3; From c07aed260aa253085d2e846f4727025007cd35eb Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 9 Aug 2014 21:09:31 +0200 Subject: [PATCH 20/27] Visualize vertex normals in normal view. --- data/shaders/normal_visualizer.geom | 20 +++++++++++++++++ src/graphics/irr_driver.hpp | 1 + src/graphics/render.cpp | 7 ++++++ src/graphics/render_geometry.cpp | 35 +++++++++++++++++++++++++++++ src/graphics/shaders.cpp | 17 ++++++++++++++ src/graphics/shaders.hpp | 14 ++++++++++++ 6 files changed, 94 insertions(+) create mode 100644 data/shaders/normal_visualizer.geom diff --git a/data/shaders/normal_visualizer.geom b/data/shaders/normal_visualizer.geom new file mode 100644 index 000000000..ea4ea08c9 --- /dev/null +++ b/data/shaders/normal_visualizer.geom @@ -0,0 +1,20 @@ +layout(triangles) in; +layout(line_strip, max_vertices = 6) out; + +in vec3 nor[]; + +void main() +{ + for(int i=0; i < gl_in.length(); i++) + { + vec4 pos = gl_in[i].gl_Position; + gl_Position = pos; + EmitVertex(); + + vec3 normal = nor[i]; + gl_Position = pos + .2 * vec4(normal, 0.); + EmitVertex(); + + EndPrimitive(); + } +} \ No newline at end of file diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 3c96f0caa..689d6b007 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -362,6 +362,7 @@ private: void renderGLSL(float dt); void renderSolidFirstPass(); void renderSolidSecondPass(); + void renderNormalsVisualisation(); void renderTransparent(); void renderParticles(); void computeSunVisibility(); diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 2017972c6..fdaaa84d7 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -318,6 +318,13 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po renderSolidSecondPass(); PROFILER_POP_CPU_MARKER(); + if (getNormals()) + { + m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind(); + renderNormalsVisualisation(); + m_rtts->getFBO(FBO_COLORS).Bind(); + } + if (UserConfigParams::m_dynamic_lights && World::getWorld() != NULL && World::getWorld()->isFogEnabled()) { diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 001dcc486..1876f5368 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -332,6 +332,41 @@ void IrrDriver::renderSolidSecondPass() } } +template +static void renderMeshNormals(std::vector > &meshes) +{ + glUseProgram(MeshShader::NormalVisualizer::getInstance()->Program); + glBindVertexArray(getVAO(VertexType)); + for (unsigned i = 0; i < meshes.size(); i++) + { + GLMesh &mesh = *(STK::tuple_get<0>(meshes[i])); + + if (mesh.VAOType != VertexType) + { +#ifdef DEBUG + Log::error("Materials", "Wrong vertex Type associed to pass 2 (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str()); +#endif + continue; + } + draw(MeshShader::NormalVisualizer::getInstance(), STK::tuple_get<0>(meshes[i]), STK::tuple_get<1>(meshes[i]), STK::tuple_get<2>(meshes[i]), video::SColor(255, 0, 255, 0)); + } +} + +void IrrDriver::renderNormalsVisualisation() +{ + renderMeshNormals(ListMatDefault::Arguments); + renderMeshNormals(ListMatAlphaRef::Arguments); + renderMeshNormals(ListMatSphereMap::Arguments); + renderMeshNormals(ListMatGrass::Arguments); + renderMeshNormals(ListMatDetails::Arguments); + renderMeshNormals(ListMatUnlit::Arguments); + renderMeshNormals(ListMatSplatting::Arguments); + renderMeshNormals(ListMatNormalMap::Arguments); + +} + + + static video::ITexture *displaceTex = 0; void IrrDriver::renderTransparent() diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index beef0086b..7c698cd12 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -572,6 +572,11 @@ void glUniform3fWraper(GLuint a, float b, float c, float d) glUniform3f(a, b, c, d); } +void glUniform4iWraper(GLuint a, int b, int c, int d, int e) +{ + glUniform4i(a, b, c, d, e); +} + void glUniform2fWraper(GLuint a, float b, float c) { glUniform2f(a, b, c); @@ -1229,6 +1234,18 @@ namespace MeshShader glUniform1i(uniform_tex, TU_tex); } + NormalVisualizer::NormalVisualizer() + { + Program = LoadProgram( + GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), + GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/normal_visualizer.geom").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/coloredquad.frag").c_str()); + AssignUniforms("ModelMatrix", "InverseModelMatrix", "color"); + + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); + } + GLuint ViewFrustrumShader::Program; GLuint ViewFrustrumShader::attrib_position; GLuint ViewFrustrumShader::uniform_color; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 491ab2f38..d0c9096f0 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -51,6 +51,7 @@ public: void glUniformMatrix4fvWraper(GLuint, size_t, unsigned, const float *mat); void glUniform3fWraper(GLuint, float, float, float); +void glUniform4iWraper(GLuint, int, int, int, int); void glUniform2fWraper(GLuint a, float b, float c); void glUniform1fWrapper(GLuint, float); bool needsUBO(); @@ -79,6 +80,13 @@ struct UniformHelper setUniformsHelper(uniforms, arg...); } + template + static void setUniformsHelper(const std::vector &uniforms, const video::SColor &col, Args... arg) + { + glUniform4iWraper(uniforms[N], col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha()); + setUniformsHelper(uniforms, arg...); + } + template static void setUniformsHelper(const std::vector &uniforms, const core::vector3df &v, Args... arg) { @@ -407,6 +415,12 @@ public: static void setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &screen, unsigned TU_tex); }; +class NormalVisualizer : public ShaderHelperSingleton +{ +public: + NormalVisualizer(); +}; + class ViewFrustrumShader { public: From c546b25ae9a5ebdfc39f828adf94113469e2556c Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 9 Aug 2014 21:19:26 +0200 Subject: [PATCH 21/27] Fix perspective in normal view. --- data/shaders/normal_visualizer.geom | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/shaders/normal_visualizer.geom b/data/shaders/normal_visualizer.geom index ea4ea08c9..50b729760 100644 --- a/data/shaders/normal_visualizer.geom +++ b/data/shaders/normal_visualizer.geom @@ -12,7 +12,9 @@ void main() EmitVertex(); vec3 normal = nor[i]; - gl_Position = pos + .2 * vec4(normal, 0.); + pos = inverse(ProjectionMatrix) * pos; + pos /= pos.w; + gl_Position = ProjectionMatrix * (pos + .2 * vec4(normal, 0.)); EmitVertex(); EndPrimitive(); From 020e939e2bfd7adc377963cfab9cfa884e8e56ad Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 9 Aug 2014 21:24:50 +0200 Subject: [PATCH 22/27] Normalize normals in normal view. --- data/shaders/normal_visualizer.geom | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/shaders/normal_visualizer.geom b/data/shaders/normal_visualizer.geom index 50b729760..0fbbfaccf 100644 --- a/data/shaders/normal_visualizer.geom +++ b/data/shaders/normal_visualizer.geom @@ -11,7 +11,7 @@ void main() gl_Position = pos; EmitVertex(); - vec3 normal = nor[i]; + vec3 normal = normalize(nor[i]); pos = inverse(ProjectionMatrix) * pos; pos /= pos.w; gl_Position = ProjectionMatrix * (pos + .2 * vec4(normal, 0.)); From e6b558262b319f30b000c144ee609f5365f36b28 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 9 Aug 2014 21:37:31 +0200 Subject: [PATCH 23/27] Do not display grass normal It requires taking account of the wind, ie another shader. --- src/graphics/render_geometry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 1876f5368..7bef2bea7 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -357,7 +357,7 @@ void IrrDriver::renderNormalsVisualisation() renderMeshNormals(ListMatDefault::Arguments); renderMeshNormals(ListMatAlphaRef::Arguments); renderMeshNormals(ListMatSphereMap::Arguments); - renderMeshNormals(ListMatGrass::Arguments); +// renderMeshNormals(ListMatGrass::Arguments); renderMeshNormals(ListMatDetails::Arguments); renderMeshNormals(ListMatUnlit::Arguments); renderMeshNormals(ListMatSplatting::Arguments); From b2e08c94a7ecbac066e3f9754821607b87f00ffe Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Sat, 9 Aug 2014 21:22:12 -0400 Subject: [PATCH 24/27] Fix physics of instanced nodes --- src/graphics/stkinstancedscenenode.cpp | 21 ++++ src/graphics/stkinstancedscenenode.hpp | 4 + src/tracks/track.cpp | 134 ++++++++++++++++--------- 3 files changed, 111 insertions(+), 48 deletions(-) diff --git a/src/graphics/stkinstancedscenenode.cpp b/src/graphics/stkinstancedscenenode.cpp index ce092faf9..d07455269 100644 --- a/src/graphics/stkinstancedscenenode.cpp +++ b/src/graphics/stkinstancedscenenode.cpp @@ -119,6 +119,27 @@ void STKInstancedSceneNode::addInstance(const core::vector3df &origin, const cor instance_pos.push_back(scale.Z); } +core::matrix4 STKInstancedSceneNode::getInstanceTransform(int id) +{ + core::matrix4 mat; + + int offset = id * 9; + mat.setTranslation(core::vector3df( + instance_pos[offset], + instance_pos[offset + 1], + instance_pos[offset + 2])); + mat.setRotationDegrees(core::vector3df( + instance_pos[offset + 3], + instance_pos[offset + 4], + instance_pos[offset + 5])); + mat.setScale(core::vector3df( + instance_pos[offset + 6], + instance_pos[offset + 7], + instance_pos[offset + 8])); + + return mat; +} + static void drawFSPMDefault(GLMesh &mesh, size_t instance_count) { irr_driver->IncreaseObjectCount(); diff --git a/src/graphics/stkinstancedscenenode.hpp b/src/graphics/stkinstancedscenenode.hpp index 5d9bbb784..4a9b9d089 100644 --- a/src/graphics/stkinstancedscenenode.hpp +++ b/src/graphics/stkinstancedscenenode.hpp @@ -28,6 +28,10 @@ public: virtual void render(); void addInstance(const core::vector3df &origin, const core::vector3df &orientation, const core::vector3df &scale); + int getInstanceCount() const { return instance_pos.size() / 9; } + + core::matrix4 getInstanceTransform(int id); + void instanceGrab() { m_ref_count++; } void instanceDrop() { diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 4cbc4040f..ab7ad31c5 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -37,6 +37,7 @@ #include "graphics/particle_emitter.hpp" #include "graphics/particle_kind.hpp" #include "graphics/particle_kind_manager.hpp" +#include "graphics/stkinstancedscenenode.hpp" #include "graphics/stk_text_billboard.hpp" #include "guiengine/scalable_font.hpp" #include "io/file_manager.hpp" @@ -729,10 +730,25 @@ void Track::convertTrackToBullet(scene::ISceneNode *node) "This track contains an empty LOD group."); return; } - node->updateAbsolutePosition(); } node->updateAbsolutePosition(); + std::vector matrices; + + STKInstancedSceneNode* instancing_node = dynamic_cast(node); + if (instancing_node != NULL) + { + int count = instancing_node->getInstanceCount(); + for (int i = 0; i < count; i++) + { + matrices.push_back(instancing_node->getInstanceTransform(i)); + } + } + else + { + matrices.push_back(node->getAbsoluteTransformation()); + } + const core::vector3df &pos = node->getAbsolutePosition(); @@ -774,14 +790,15 @@ void Track::convertTrackToBullet(scene::ISceneNode *node) return; } // switch node->getType() - core::matrix4 mat; - mat.setRotationDegrees(hpr); - mat.setTranslation(pos); - core::matrix4 mat_scale; - // Note that we can't simply call mat.setScale, since this would - // overwrite the elements on the diagonal, making any rotation incorrect. - mat_scale.setScale(scale); - mat *= mat_scale; + //core::matrix4 mat; + //mat.setRotationDegrees(hpr); + //mat.setTranslation(pos); + //core::matrix4 mat_scale; + //// Note that we can't simply call mat.setScale, since this would + //// overwrite the elements on the diagonal, making any rotation incorrect. + //mat_scale.setScale(scale); + //mat *= mat_scale; + for(unsigned int i=0; igetMeshBufferCount(); i++) { scene::IMeshBuffer *mb = mesh->getMeshBuffer(i); @@ -835,59 +852,80 @@ void Track::convertTrackToBullet(scene::ISceneNode *node) if (mb->getVertexType() == video::EVT_STANDARD) { irr::video::S3DVertex* mbVertices=(video::S3DVertex*)mb->getVertices(); - for(unsigned int j=0; jgetIndexCount(); j+=3) + for (unsigned int matrix_index = 0; matrix_index < matrices.size(); matrix_index++) { - for(unsigned int k=0; k<3; k++) + for (unsigned int j = 0; j < mb->getIndexCount(); j += 3) { - int indx=mbIndices[j+k]; - core::vector3df v = mbVertices[indx].Pos; - mat.transformVect(v); - vertices[k]=v; - normals[k]=mbVertices[indx].Normal; - } // for k - if(tmesh) tmesh->addTriangle(vertices[0], vertices[1], - vertices[2], normals[0], - normals[1], normals[2], - material ); - } // for j + for (unsigned int k = 0; k < 3; k++) + { + int indx = mbIndices[j + k]; + core::vector3df v = mbVertices[indx].Pos; + matrices[matrix_index].transformVect(v); + vertices[k] = v; + normals[k] = mbVertices[indx].Normal; + } // for k + + if (tmesh) + { + tmesh->addTriangle(vertices[0], vertices[1], + vertices[2], normals[0], + normals[1], normals[2], + material); + } + } // for j + } // for matrix_index } else if (mb->getVertexType() == video::EVT_2TCOORDS) { irr::video::S3DVertex2TCoords* mbVertices = (video::S3DVertex2TCoords*)mb->getVertices(); - for(unsigned int j=0; jgetIndexCount(); j+=3) + for (unsigned int matrix_index = 0; matrix_index < matrices.size(); matrix_index++) { - for(unsigned int k=0; k<3; k++) + for (unsigned int j = 0; j < mb->getIndexCount(); j += 3) { - int indx=mbIndices[j+k]; - core::vector3df v = mbVertices[indx].Pos; - mat.transformVect(v); - vertices[k]=v; - normals[k]=mbVertices[indx].Normal; - } // for k - if(tmesh) tmesh->addTriangle(vertices[0], vertices[1], - vertices[2], normals[0], - normals[1], normals[2], - material ); - } // for j + for (unsigned int k = 0; k < 3; k++) + { + int indx = mbIndices[j + k]; + core::vector3df v = mbVertices[indx].Pos; + matrices[matrix_index].transformVect(v); + vertices[k] = v; + normals[k] = mbVertices[indx].Normal; + } // for k + + if (tmesh) + { + tmesh->addTriangle(vertices[0], vertices[1], + vertices[2], normals[0], + normals[1], normals[2], + material); + } + } // for j + } // for matrix_index } else if (mb->getVertexType() == video::EVT_TANGENTS) { irr::video::S3DVertexTangents* mbVertices = (video::S3DVertexTangents*)mb->getVertices(); - for(unsigned int j=0; jgetIndexCount(); j+=3) + for (unsigned int matrix_index = 0; matrix_index < matrices.size(); matrix_index++) { - for(unsigned int k=0; k<3; k++) + for (unsigned int j = 0; j < mb->getIndexCount(); j += 3) { - int indx=mbIndices[j+k]; - core::vector3df v = mbVertices[indx].Pos; - mat.transformVect(v); - vertices[k]=v; - normals[k]=mbVertices[indx].Normal; - } // for k - if(tmesh) tmesh->addTriangle(vertices[0], vertices[1], - vertices[2], normals[0], - normals[1], normals[2], - material ); - } // for j + for (unsigned int k = 0; k < 3; k++) + { + int indx = mbIndices[j + k]; + core::vector3df v = mbVertices[indx].Pos; + matrices[matrix_index].transformVect(v); + vertices[k] = v; + normals[k] = mbVertices[indx].Normal; + } // for k + + if (tmesh) + { + tmesh->addTriangle(vertices[0], vertices[1], + vertices[2], normals[0], + normals[1], normals[2], + material); + } + } // for j + } // for matrix_index } } // for i Date: Sun, 10 Aug 2014 22:05:00 +0200 Subject: [PATCH 25/27] Use collision shape for RSM size. --- src/graphics/render.cpp | 13 +++++++++---- src/tracks/track.hpp | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index fdaaa84d7..6ce10f472 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -41,6 +41,7 @@ #include "items/item_manager.hpp" #include "modes/world.hpp" #include "physics/physics.hpp" +#include "physics/triangle_mesh.hpp" #include "tracks/track.hpp" #include "utils/constants.hpp" #include "utils/helpers.hpp" @@ -601,8 +602,12 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz if (World::getWorld() && World::getWorld()->getTrack()) { - const Vec3 *vmin, *vmax; - World::getWorld()->getTrack()->getAABB(&vmin, &vmax); + btVector3 btmin, btmax; + if (World::getWorld()->getTrack()->getPtrTriangleMesh()) + { + World::getWorld()->getTrack()->getTriangleMesh().getCollisionShape().getAabb(btTransform::getIdentity(), btmin, btmax); + } + const Vec3 vmin = btmin , vmax = btmax; // Build the 3 ortho projection (for the 3 shadow resolution levels) for (unsigned i = 0; i < 4; i++) @@ -640,7 +645,7 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz memcpy(m_shadows_cam[i], tmp, 24 * sizeof(float)); const core::aabbox3df smallcambox = camnode-> getViewFrustum()->getBoundingBox(); - core::aabbox3df trackbox(vmin->toIrrVector(), vmax->toIrrVector() - + core::aabbox3df trackbox(vmin.toIrrVector(), vmax.toIrrVector() - core::vector3df(0, 30, 0)); // Set up a nice ortho projection that contains our camera frustum @@ -677,7 +682,7 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz } { - core::aabbox3df trackbox(vmin->toIrrVector(), vmax->toIrrVector() - + core::aabbox3df trackbox(vmin.toIrrVector(), vmax.toIrrVector() - core::vector3df(0, 30, 0)); if (trackbox.MinEdge.X != trackbox.MaxEdge.X && trackbox.MinEdge.Y != trackbox.MaxEdge.Y && diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 7543b4248..12f88d196 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -548,6 +548,7 @@ public: float getCameraFar() const { return m_camera_far; } // ------------------------------------------------------------------------ /** Returns the triangle mesh for this track. */ + const TriangleMesh *getPtrTriangleMesh() const { return m_track_mesh; } const TriangleMesh& getTriangleMesh() const {return *m_track_mesh; } // ------------------------------------------------------------------------ /** Returns the graphical effect mesh for this track. */ From 856169794dea7f0ffdfa96f602c68e06668d6f21 Mon Sep 17 00:00:00 2001 From: vlj Date: Sun, 10 Aug 2014 22:27:26 +0200 Subject: [PATCH 26/27] Use singleton for DoF. --- src/graphics/post_processing.cpp | 10 +++++----- src/graphics/shaders.cpp | 20 +++++--------------- src/graphics/shaders.hpp | 10 ++++------ 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 3ae8af717..eabcfb4be 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -644,11 +644,11 @@ static void toneMap(FrameBuffer &fbo, GLuint rtt) static void renderDoF(FrameBuffer &fbo, GLuint rtt) { fbo.Bind(); - glUseProgram(FullScreenShader::DepthOfFieldShader::Program); - glBindVertexArray(FullScreenShader::DepthOfFieldShader::vao); - setTexture(0, rtt, GL_LINEAR, GL_LINEAR); - setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST); - FullScreenShader::DepthOfFieldShader::setUniforms(0, 1); + glUseProgram(FullScreenShader::DepthOfFieldShader::getInstance()->Program); + glBindVertexArray(FullScreenShader::DepthOfFieldShader::getInstance()->vao); + setTexture(FullScreenShader::DepthOfFieldShader::getInstance()->TU_tex, rtt, GL_LINEAR, GL_LINEAR); + setTexture(FullScreenShader::DepthOfFieldShader::getInstance()->TU_depth, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST); + FullScreenShader::DepthOfFieldShader::getInstance()->setUniforms(); glDrawArrays(GL_TRIANGLES, 0, 3); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 7c698cd12..c1b58ca06 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -375,7 +375,6 @@ void Shaders::loadShaders() initShadowVPMUBO(); FullScreenShader::BloomBlendShader::init(); FullScreenShader::BloomShader::init(); - FullScreenShader::DepthOfFieldShader::init(); FullScreenShader::FogShader::init(); FullScreenShader::Gaussian17TapHShader::init(); FullScreenShader::ComputeGaussian17TapHShader::init(); @@ -1620,29 +1619,20 @@ namespace FullScreenShader vao = createFullScreenVAO(Program); } - GLuint DepthOfFieldShader::Program; - GLuint DepthOfFieldShader::uniform_tex; - GLuint DepthOfFieldShader::uniform_depth; - GLuint DepthOfFieldShader::vao; - - void DepthOfFieldShader::init() + DepthOfFieldShader::DepthOfFieldShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/dof.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_depth = glGetUniformLocation(Program, "dtex"); + TU_tex = 0; + TU_depth = 1; + AssignUniforms(); + AssignTextureUnit(Program, TexUnit(TU_tex, "tex"), TexUnit(TU_depth, "dtex")); vao = createFullScreenVAO(Program); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void DepthOfFieldShader::setUniforms(unsigned TU_tex, unsigned TU_dtex) - { - glUniform1i(uniform_tex, TU_tex); - glUniform1i(uniform_depth, TU_dtex); - } - SunLightShader::SunLightShader() { Program = LoadProgram( diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index d0c9096f0..e6a84d1e9 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -551,15 +551,13 @@ public: ToneMapShader(); }; -class DepthOfFieldShader +class DepthOfFieldShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_tex, uniform_depth; - static GLuint vao; + GLuint TU_tex, TU_depth; + GLuint vao; - static void init(); - static void setUniforms(unsigned TU_tex, unsigned TU_depth); + DepthOfFieldShader(); }; class SunLightShader : public ShaderHelperSingleton From 495cd25d1c89d6e3a01bd396007ac289d1205e4e Mon Sep 17 00:00:00 2001 From: vlj Date: Sun, 10 Aug 2014 23:15:02 +0200 Subject: [PATCH 27/27] Do some symetry on skybox top/bottom.. --- src/graphics/render_skybox.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/graphics/render_skybox.cpp b/src/graphics/render_skybox.cpp index 64b5a9952..75fdae053 100644 --- a/src/graphics/render_skybox.cpp +++ b/src/graphics/render_skybox.cpp @@ -378,6 +378,14 @@ static void testSH(unsigned char *color[6], size_t width, size_t height, } } +static void swapPixels(char *old_img, char *new_img, unsigned stride, unsigned old_i, unsigned old_j, unsigned new_i, unsigned new_j) +{ + new_img[4 * (stride * new_i + new_j)] = old_img[4 * (stride * old_i + old_j)]; + new_img[4 * (stride * new_i + new_j) + 1] = old_img[4 * (stride * old_i + old_j) + 1]; + new_img[4 * (stride * new_i + new_j) + 2] = old_img[4 * (stride * old_i + old_j) + 2]; + new_img[4 * (stride * new_i + new_j) + 3] = old_img[4 * (stride * old_i + old_j) + 3]; +} + /** Generate an opengl cubemap texture from 6 2d textures. Out of legacy the sequence of textures maps to : - 1st texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_Y @@ -421,6 +429,19 @@ GLuint generateCubeMapFromTextures(const std::vector &texture image->copyToScaling(rgba[i], w, h); image->drop(); + if (i == 2 || i == 3) + { + char *tmp = new char[w * h * 4]; + memcpy(tmp, rgba[i], w * h * 4); + for (unsigned x = 0; x < w; x++) + { + for (unsigned y = 0; y < h; y++) + { + swapPixels(tmp, rgba[i], h, x, y, (w - y - 1), x); + } + } + } + glBindTexture(GL_TEXTURE_CUBE_MAP, result); if (UserConfigParams::m_texture_compression) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_COMPRESSED_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);