From 4c3db6ca594de194abe8e678f0d623186578f265 Mon Sep 17 00:00:00 2001 From: vlj Date: Wed, 9 Jul 2014 03:41:08 +0200 Subject: [PATCH] Mix texture for displace. --- data/shaders/displace.frag | 6 +++++- src/graphics/shaders.cpp | 5 ++++- src/graphics/shaders.hpp | 4 ++-- src/graphics/stkmeshscenenode.cpp | 9 +++++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/data/shaders/displace.frag b/data/shaders/displace.frag index 7ddcb9f9a..84fe29b60 100644 --- a/data/shaders/displace.frag +++ b/data/shaders/displace.frag @@ -1,6 +1,7 @@ uniform sampler2D displacement_tex; uniform sampler2D mask_tex; uniform sampler2D color_tex; +uniform sampler2D tex; uniform vec2 dir; uniform vec2 dir2; @@ -64,5 +65,8 @@ void main() float mask = texture(mask_tex, tc + shift).x; tc += (mask < 1.) ? vec2(0.) : shift; - FragColor = texture(color_tex, tc); + vec4 col = texture(color_tex, tc); + vec4 blend_tex = texture(tex, uv); + col.rgb = blend_tex.rgb * blend_tex.a + (1. - blend_tex.a) * col.rgb; + FragColor = vec4(col.rgb, 1.); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 02d759383..ec8e40dc6 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1537,6 +1537,7 @@ namespace MeshShader GLuint DisplaceShader::uniform_displacement_tex; GLuint DisplaceShader::uniform_mask_tex; GLuint DisplaceShader::uniform_color_tex; + GLuint DisplaceShader::uniform_tex; GLuint DisplaceShader::uniform_dir; GLuint DisplaceShader::uniform_dir2; @@ -1551,11 +1552,12 @@ namespace MeshShader uniform_mask_tex = glGetUniformLocation(Program, "mask_tex"); uniform_dir = glGetUniformLocation(Program, "dir"); uniform_dir2 = glGetUniformLocation(Program, "dir2"); + uniform_tex = glGetUniformLocation(Program, "tex"); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void DisplaceShader::setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex) + void DisplaceShader::setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex, unsigned TU_tex) { glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer()); glUniform2f(uniform_dir, dir.X, dir.Y); @@ -1563,6 +1565,7 @@ namespace MeshShader glUniform1i(uniform_displacement_tex, TU_displacement_tex); glUniform1i(uniform_mask_tex, TU_mask_tex); glUniform1i(uniform_color_tex, TU_color_tex); + glUniform1i(uniform_tex, TU_tex); } GLuint SkyboxShader::Program; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index f82277126..4e7cc7c50 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -375,10 +375,10 @@ class DisplaceShader { public: static GLuint Program; - static GLuint uniform_MVP, uniform_displacement_tex, uniform_mask_tex, uniform_color_tex, uniform_dir, uniform_dir2; + static GLuint uniform_MVP, uniform_displacement_tex, uniform_mask_tex, uniform_color_tex, uniform_tex, uniform_dir, uniform_dir2; static void init(); - static void setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex, unsigned TU_tex); }; class SkyboxShader diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index 8835412b9..a1524022f 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -141,7 +141,7 @@ void STKMeshSceneNode::drawGlow(const GLMesh &mesh) size_t count = mesh.IndexCount; MeshShader::ColorizeShader::setUniforms(AbsoluteTransformation, cb->getRed(), cb->getGreen(), cb->getBlue()); - glDrawElementsInstancedBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, 4, mesh.vaoBaseVertex); + glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex); } static video::ITexture *displaceTex = 0; @@ -166,7 +166,7 @@ void STKMeshSceneNode::drawDisplace(const GLMesh &mesh) glUseProgram(MeshShader::DisplaceMaskShader::Program); MeshShader::DisplaceMaskShader::setUniforms(AbsoluteTransformation); - glDrawElementsInstancedBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, 4, mesh.vaoBaseVertex); + glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex); // Render the effect if (!displaceTex) @@ -175,15 +175,16 @@ void STKMeshSceneNode::drawDisplace(const GLMesh &mesh) setTexture(0, getTextureGLuint(displaceTex), GL_LINEAR, GL_LINEAR, true); setTexture(1, irr_driver->getRenderTargetTexture(RTT_TMP1), GL_LINEAR, GL_LINEAR, true); setTexture(2, irr_driver->getRenderTargetTexture(RTT_COLOR), GL_LINEAR, GL_LINEAR, true); + setTexture(3, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR, true); glUseProgram(MeshShader::DisplaceShader::Program); MeshShader::DisplaceShader::setUniforms(AbsoluteTransformation, core::vector2df(cb->getDirX(), cb->getDirY()), core::vector2df(cb->getDir2X(), cb->getDir2Y()), core::vector2df(float(UserConfigParams::m_width), float(UserConfigParams::m_height)), - 0, 1, 2); + 0, 1, 2, 3); - glDrawElementsInstancedBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, 4, mesh.vaoBaseVertex); + glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex); } void STKMeshSceneNode::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type)