From ada19f828cb0e29fbc3dafb9abcadf4d591e8c1f Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 4 Mar 2014 17:52:23 +0100 Subject: [PATCH 1/5] Fix black glowing objects. --- src/graphics/render.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 66079ae0b..4f2b36645 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -1007,7 +1007,7 @@ void IrrDriver::renderDisplacement(video::SOverrideMaterial &overridemat, glDisable(GL_ALPHA_TEST); glDepthMask(GL_FALSE); glDisable(GL_BLEND); - glClear(GL_STENCIL_BITS); + glClear(GL_STENCIL_BUFFER_BIT); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 1, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); From c93c92102883b33fe4190f2a961367954f3bf87a Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 4 Mar 2014 18:42:33 +0100 Subject: [PATCH 2/5] STKMesh: Support caustic material. --- data/shaders/caustics.frag | 5 +++-- src/graphics/callbacks.cpp | 37 ------------------------------- src/graphics/callbacks.hpp | 13 ----------- src/graphics/shaders.cpp | 33 ++++++++++++++++++++++++++- src/graphics/shaders.hpp | 11 +++++++++ src/graphics/stkmesh.cpp | 24 ++++++++++++++++++++ src/graphics/stkmesh.hpp | 1 + src/graphics/stkmeshscenenode.cpp | 21 ++++++++++++++++++ src/graphics/stkmeshscenenode.hpp | 1 + 9 files changed, 93 insertions(+), 53 deletions(-) diff --git a/data/shaders/caustics.frag b/data/shaders/caustics.frag index 7fe0eecea..d071769b9 100644 --- a/data/shaders/caustics.frag +++ b/data/shaders/caustics.frag @@ -3,17 +3,18 @@ uniform sampler2D caustictex; uniform vec2 dir; uniform vec2 dir2; +in vec2 uv; out vec4 FragColor; void main() { - vec2 tc = gl_TexCoord[0].xy; + vec2 tc = uv; vec3 col = texture(tex, tc).xyz; float caustic = texture(caustictex, tc + dir).x; float caustic2 = texture(caustictex, (tc.yx + dir2 * vec2(-0.6, 0.3)) * vec2(0.6)).x; - col += caustic * caustic2 * 10.0; + col += caustic * caustic2; FragColor = vec4(col, 1.0); } diff --git a/src/graphics/callbacks.cpp b/src/graphics/callbacks.cpp index 03ddc05b9..cadd5d332 100644 --- a/src/graphics/callbacks.cpp +++ b/src/graphics/callbacks.cpp @@ -541,43 +541,6 @@ void ShadowGenProvider::OnSetConstants(IMaterialRendererServices *srv, int) //------------------------------------- -void CausticsProvider::OnSetConstants(IMaterialRendererServices *srv, int) -{ - const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f; - const float speed = World::getWorld()->getTrack()->getCausticsSpeed(); - - float strength = time; - strength = fabsf(noise2d(strength / 10.0f)) * 0.006f + 0.001f; - - vector3df wind = irr_driver->getWind() * strength * speed; - m_dir[0] += wind.X; - m_dir[1] += wind.Z; - - strength = time * 0.56f + sinf(time); - strength = fabsf(noise2d(0.0, strength / 6.0f)) * 0.0095f + 0.001f; - - wind = irr_driver->getWind() * strength * speed; - wind.rotateXZBy(cosf(time)); - m_dir2[0] += wind.X; - m_dir2[1] += wind.Z; - - srv->setVertexShaderConstant("dir", m_dir, 2); - srv->setVertexShaderConstant("dir2", m_dir2, 2); - - if (!firstdone) - { - int tex = 0; - srv->setVertexShaderConstant("tex", &tex, 1); - - tex = 1; - srv->setVertexShaderConstant("caustictex", &tex, 1); - - firstdone = true; - } -} - -//------------------------------------- - void DisplaceProvider::OnSetConstants(IMaterialRendererServices *srv, int) { core::matrix4 ProjectionMatrix = srv->getVideoDriver()->getTransform(ETS_PROJECTION); diff --git a/src/graphics/callbacks.hpp b/src/graphics/callbacks.hpp index 8eb82ef80..ab3b34503 100644 --- a/src/graphics/callbacks.hpp +++ b/src/graphics/callbacks.hpp @@ -542,19 +542,6 @@ public: // -class CausticsProvider: public CallBase -{ -public: - CausticsProvider() { m_dir[0] = m_dir[1] = m_dir2[0] = m_dir2[1] = 0; } - - virtual void OnSetConstants(video::IMaterialRendererServices *srv, int); - -private: - float m_dir[2], m_dir2[2]; -}; - -// - class DisplaceProvider: public CallBase { public: diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index aae6ef362..66234f7b3 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -183,7 +183,7 @@ void Shaders::loadShaders() m_callbacks[ES_SHADOWGEN], EMT_SOLID); m_shaders[ES_CAUSTICS] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_CAUSTICS], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_CAUSTICS], EMT_SOLID); m_shaders[ES_DISPLACE] = glsl(dir + "pass.vert", dir + "pass.frag", m_callbacks[ES_DISPLACE]); @@ -249,6 +249,7 @@ void Shaders::loadShaders() MeshShader::SplattingShader::init(); MeshShader::GrassPass1Shader::init(); MeshShader::GrassPass2Shader::init(); + MeshShader::CausticsShader::init(); MeshShader::BubbleShader::init(); MeshShader::TransparentShader::init(); MeshShader::TransparentFogShader::init(); @@ -746,6 +747,36 @@ namespace MeshShader glUniform3f(uniform_ambient, s.r, s.g, s.b); } + GLuint CausticsShader::Program; + GLuint CausticsShader::attrib_position; + GLuint CausticsShader::attrib_texcoord; + GLuint CausticsShader::uniform_MVP; + GLuint CausticsShader::uniform_dir; + GLuint CausticsShader::uniform_dir2; + GLuint CausticsShader::uniform_tex; + GLuint CausticsShader::uniform_caustictex; + + void CausticsShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/caustics.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_dir = glGetUniformLocation(Program, "dir"); + uniform_dir2 = glGetUniformLocation(Program, "dir2"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_caustictex = glGetUniformLocation(Program, "caustictex"); + } + + void CausticsShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector2df &dir, const core::vector2df &dir2, unsigned TU_tex, unsigned TU_caustictex) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniform2f(uniform_dir, dir.X, dir.Y); + glUniform2f(uniform_dir2, dir2.X, dir2.Y); + glUniform1i(uniform_tex, TU_tex); + glUniform1i(uniform_caustictex, TU_caustictex); + } + GLuint BubbleShader::Program; GLuint BubbleShader::attrib_position; GLuint BubbleShader::attrib_texcoord; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 97ea1135f..501787a58 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -169,6 +169,17 @@ public: static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex_layout, unsigned TU_tex_detail0, unsigned TU_tex_detail1, unsigned TU_tex_detail2, unsigned TU_tex_detail3, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO); }; +class CausticsShader +{ +public: + static GLuint Program; + static GLuint attrib_position, attrib_texcoord; + static GLuint uniform_MVP, uniform_dir, uniform_dir2, uniform_tex, uniform_caustictex; + + static void init(); + static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector2df &dir, const core::vector2df &dir2, unsigned TU_tex, unsigned TU_caustictex); +}; + class BubbleShader { public: diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 3104a2ffb..7a62d4a39 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -355,6 +355,23 @@ void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjec glDrawElements(ptype, count, itype, 0); } +void drawCaustics(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector2df dir, core::vector2df dir2) +{ + GLenum ptype = mesh.PrimitiveType; + GLenum itype = mesh.IndexType; + size_t count = mesh.IndexCount; + + setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + setTexture(1, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + + + glUseProgram(MeshShader::CausticsShader::Program); + MeshShader::CausticsShader::setUniforms(ModelViewProjectionMatrix, dir, dir2, 0, 1); + + glBindVertexArray(mesh.vao_second_pass); + glDrawElements(ptype, count, itype, 0); +} + void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector3df windDir) { GLenum ptype = mesh.PrimitiveType; @@ -625,6 +642,8 @@ bool isObject(video::E_MATERIAL_TYPE type) return true; if (type == irr_driver->getShader(ES_OBJECT_UNLIT)) return true; + if (type == irr_driver->getShader(ES_CAUSTICS)) + return true; if (type == video::EMT_TRANSPARENT_ALPHA_CHANNEL) return true; if (type == video::EMT_ONETEXTURE_BLEND) @@ -695,6 +714,11 @@ void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type) mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ObjectUnlitShader::attrib_position, MeshShader::ObjectUnlitShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); } + else if (type == irr_driver->getShader(ES_CAUSTICS)) + { + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, + MeshShader::CausticsShader::attrib_position, MeshShader::CausticsShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + } else if (mesh.textures[1]) { mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 66c53fb1f..f9758e86f 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -44,6 +44,7 @@ void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProj void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix); void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView); void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); +void drawCaustics(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, core::vector2df dir, core::vector2df dir2); void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector3df windDir); void drawObjectRimLimit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix); void drawObjectUnlit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index f772e2ce2..78a31083a 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -210,6 +210,27 @@ void STKMeshSceneNode::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type drawObjectRimLimit(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix); else if (type == irr_driver->getShader(ES_OBJECT_UNLIT)) drawObjectUnlit(mesh, ModelViewProjectionMatrix); + else if (type == irr_driver->getShader(ES_CAUSTICS)) + { + const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f; + const float speed = World::getWorld()->getTrack()->getCausticsSpeed(); + + float strength = time; + strength = fabsf(noise2d(strength / 10.0f)) * 0.006f + 0.001f; + + vector3df wind = irr_driver->getWind() * strength * speed; + caustic_dir.X += wind.X; + caustic_dir.Y += wind.Z; + + strength = time * 0.56f + sinf(time); + strength = fabsf(noise2d(0.0, strength / 6.0f)) * 0.0095f + 0.001f; + + wind = irr_driver->getWind() * strength * speed; + wind.rotateXZBy(cosf(time)); + caustic_dir2.X += wind.X; + caustic_dir2.Y += wind.Z; + drawCaustics(mesh, ModelViewProjectionMatrix, caustic_dir, caustic_dir2); + } else if (mesh.textures[1] && type != irr_driver->getShader(ES_NORMAL_MAP)) drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix); else if (!mesh.textures[0]) diff --git a/src/graphics/stkmeshscenenode.hpp b/src/graphics/stkmeshscenenode.hpp index eca1979d9..c10a8b0bb 100644 --- a/src/graphics/stkmeshscenenode.hpp +++ b/src/graphics/stkmeshscenenode.hpp @@ -9,6 +9,7 @@ protected: std::vector GLmeshes; core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix; core::vector3df windDir; + core::vector2df caustic_dir, caustic_dir2; void drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type); void drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type); From ada5928aa2e9f03d68a4ec593a6523247a7baa8d Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 4 Mar 2014 18:47:10 +0100 Subject: [PATCH 3/5] Forgot a hunk --- src/graphics/shaders.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 66234f7b3..adfc05e00 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -49,7 +49,6 @@ Shaders::Shaders() m_callbacks[ES_COLLAPSE] = new CollapseProvider(); m_callbacks[ES_MULTIPLY_ADD] = new MultiplyProvider(); m_callbacks[ES_SHADOWGEN] = new ShadowGenProvider(); - m_callbacks[ES_CAUSTICS] = new CausticsProvider(); m_callbacks[ES_DISPLACE] = new DisplaceProvider(); for(s32 i=0 ; i < ES_COUNT ; i++) From 8f127be9ded4b3504e64db00df257b13e268cae9 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 4 Mar 2014 22:08:34 +0100 Subject: [PATCH 4/5] Fix caustic shader not picking caustic.png --- src/graphics/stkmesh.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 7a62d4a39..c992fe0d6 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -361,8 +361,8 @@ void drawCaustics(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionM GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - setTexture(1, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR, true); + setTexture(1, getTextureGLuint(irr_driver->getTexture(file_manager->getAsset("textures/noise.png").c_str())), GL_LINEAR, GL_LINEAR, true); glUseProgram(MeshShader::CausticsShader::Program); From 718c1cacb0e25b2a26648d9c20f1d9b06d56c6b8 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 4 Mar 2014 22:30:33 +0100 Subject: [PATCH 5/5] Improved caustics effect. --- data/shaders/caustics.frag | 28 ++++++++++++++++++++-------- src/graphics/shaders.cpp | 24 ++++++++++++++++++++---- src/graphics/shaders.hpp | 4 ++-- src/graphics/stkmesh.cpp | 24 +++++++++++++++++++++--- 4 files changed, 63 insertions(+), 17 deletions(-) diff --git a/data/shaders/caustics.frag b/data/shaders/caustics.frag index d071769b9..203bd2b40 100644 --- a/data/shaders/caustics.frag +++ b/data/shaders/caustics.frag @@ -1,20 +1,32 @@ -uniform sampler2D tex; +uniform sampler2D Albedo; +uniform sampler2D DiffuseMap; +uniform sampler2D SpecularMap; +uniform sampler2D SSAO; +uniform vec2 screen; +uniform vec3 ambient; uniform sampler2D caustictex; uniform vec2 dir; uniform vec2 dir2; +#if __VERSION__ >= 130 in vec2 uv; out vec4 FragColor; +#else +varying vec2 uv; +#define FragColor gl_FragColor +#endif void main() { - vec2 tc = uv; + vec2 tc = gl_FragCoord.xy / screen; + vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz; + vec3 SpecularComponent = texture(SpecularMap, tc).xyz; + vec4 color = texture(Albedo, uv); + float ao = texture(SSAO, tc).x; - vec3 col = texture(tex, tc).xyz; - float caustic = texture(caustictex, tc + dir).x; - float caustic2 = texture(caustictex, (tc.yx + dir2 * vec2(-0.6, 0.3)) * vec2(0.6)).x; + float caustic = texture(caustictex, uv + dir).x; + float caustic2 = texture(caustictex, (uv.yx + dir2 * vec2(-0.6, 0.3)) * vec2(0.6)).x; - col += caustic * caustic2; - - FragColor = vec4(col, 1.0); + vec3 LightFactor = ao * ambient + DiffuseComponent + SpecularComponent + caustic * caustic2 * 10; + FragColor = vec4(color.xyz * LightFactor, 1.); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index adfc05e00..261a0c294 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -752,8 +752,13 @@ namespace MeshShader GLuint CausticsShader::uniform_MVP; GLuint CausticsShader::uniform_dir; GLuint CausticsShader::uniform_dir2; - GLuint CausticsShader::uniform_tex; + GLuint CausticsShader::uniform_Albedo; GLuint CausticsShader::uniform_caustictex; + GLuint CausticsShader::uniform_DiffuseMap; + GLuint CausticsShader::uniform_SpecularMap; + GLuint CausticsShader::uniform_SSAO; + GLuint CausticsShader::uniform_screen; + GLuint CausticsShader::uniform_ambient; void CausticsShader::init() { @@ -763,17 +768,28 @@ namespace MeshShader uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); uniform_dir = glGetUniformLocation(Program, "dir"); uniform_dir2 = glGetUniformLocation(Program, "dir2"); - uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_Albedo = glGetUniformLocation(Program, "Albedo"); uniform_caustictex = glGetUniformLocation(Program, "caustictex"); + uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); + uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); + uniform_SSAO = glGetUniformLocation(Program, "SSAO"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); } - void CausticsShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector2df &dir, const core::vector2df &dir2, unsigned TU_tex, unsigned TU_caustictex) + void CausticsShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_albedo, unsigned TU_DiffuseMap, unsigned TU_Specmap, unsigned TU_SSAO, unsigned TU_caustictex) { glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); glUniform2f(uniform_dir, dir.X, dir.Y); glUniform2f(uniform_dir2, dir2.X, dir2.Y); - glUniform1i(uniform_tex, TU_tex); + glUniform1i(uniform_Albedo, TU_albedo); glUniform1i(uniform_caustictex, TU_caustictex); + glUniform2f(uniform_screen, screen.X, screen.Y); + glUniform1i(uniform_DiffuseMap, TU_DiffuseMap); + glUniform1i(uniform_SpecularMap, TU_Specmap); + glUniform1i(uniform_SSAO, TU_SSAO); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); } GLuint BubbleShader::Program; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 501787a58..ce91d8922 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -174,10 +174,10 @@ class CausticsShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord; - static GLuint uniform_MVP, uniform_dir, uniform_dir2, uniform_tex, uniform_caustictex; + static GLuint uniform_MVP, uniform_dir, uniform_dir2, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient, uniform_caustictex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector2df &dir, const core::vector2df &dir2, unsigned TU_tex, unsigned TU_caustictex); + static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_albedo, unsigned TU_DiffuseMap, unsigned TU_Specmap, unsigned TU_SSAO, unsigned TU_caustictex); }; class BubbleShader diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index c992fe0d6..944753676 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -361,12 +361,30 @@ void drawCaustics(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionM GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR, true); - setTexture(1, getTextureGLuint(irr_driver->getTexture(file_manager->getAsset("textures/noise.png").c_str())), GL_LINEAR, GL_LINEAR, true); + setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + if (irr_driver->getLightViz()) + { + GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } + else + { + GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } + setTexture(1, getTextureGLuint(irr_driver->getTexture(file_manager->getAsset("textures/caustics.png").c_str())), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); + setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); + setTexture(4, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); + if (!UserConfigParams::m_ssao) + { + GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } glUseProgram(MeshShader::CausticsShader::Program); - MeshShader::CausticsShader::setUniforms(ModelViewProjectionMatrix, dir, dir2, 0, 1); + MeshShader::CausticsShader::setUniforms(ModelViewProjectionMatrix, dir, dir2, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height), 0, 2, 3, 4, 1); glBindVertexArray(mesh.vao_second_pass); glDrawElements(ptype, count, itype, 0);