From 42482e0c41e2240e080e7369148571917d723495 Mon Sep 17 00:00:00 2001 From: vlj Date: Thu, 10 Apr 2014 17:34:57 +0200 Subject: [PATCH] Some more conversion --- data/shaders/normalmap.frag | 2 +- data/shaders/normalmap.vert | 14 +- data/shaders/object_pass.vert | 19 +- data/shaders/objectpass_rimlit.frag | 6 +- data/shaders/objectpass_rimlit.vert | 25 - data/shaders/objectpass_spheremap.frag | 15 +- data/shaders/sky.frag | 12 +- data/shaders/splatting.vert | 41 - data/shaders/untextured_object.vert | 13 +- src/graphics/render.cpp | 11 +- src/graphics/shaders.cpp | 2082 ++++++++++++------------ src/graphics/shaders.hpp | 48 +- src/graphics/stkanimatedmesh.cpp | 33 +- src/graphics/stkmesh.cpp | 12 +- src/graphics/stkmesh.hpp | 2 +- src/graphics/stkmeshscenenode.cpp | 57 +- 16 files changed, 1202 insertions(+), 1190 deletions(-) delete mode 100644 data/shaders/objectpass_rimlit.vert delete mode 100644 data/shaders/splatting.vert diff --git a/data/shaders/normalmap.frag b/data/shaders/normalmap.frag index c1d9120d9..109f35aa5 100644 --- a/data/shaders/normalmap.frag +++ b/data/shaders/normalmap.frag @@ -25,7 +25,7 @@ void main() vec3 Frag_normal = normalize(cross(Frag_tangent, bitangent)); vec3 Frag_bitangent = cross(Frag_normal, Frag_tangent); - vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal; + vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal; EncodedNormal.xy = 0.5 * EncodeNormal(normalize(FragmentNormal)) + 0.5; EncodedNormal.z = 1.; } diff --git a/data/shaders/normalmap.vert b/data/shaders/normalmap.vert index 5d5f79c21..eb5570ddd 100644 --- a/data/shaders/normalmap.vert +++ b/data/shaders/normalmap.vert @@ -1,6 +1,14 @@ -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 TransposeInverseModelView; +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; +uniform mat4 ModelMatrix; +uniform mat4 InverseModelMatrix; #if __VERSION__ >= 130 in vec3 Position; @@ -23,6 +31,8 @@ varying vec2 uv; void main() { + mat4 ModelViewProjectionMatrix = ProjectionMatrix * ViewMatrix * ModelMatrix; + mat4 TransposeInverseModelView = transpose(InverseModelMatrix * InverseViewMatrix); uv = Texcoord; tangent = (TransposeInverseModelView * vec4(Tangent, 1.)).xyz; bitangent = (TransposeInverseModelView * vec4(Bitangent, 1.)).xyz; diff --git a/data/shaders/object_pass.vert b/data/shaders/object_pass.vert index af55e8d33..8dda8cf74 100644 --- a/data/shaders/object_pass.vert +++ b/data/shaders/object_pass.vert @@ -1,5 +1,15 @@ -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 TransposeInverseModelView; +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; + +uniform mat4 ModelMatrix; +uniform mat4 InverseModelMatrix; + uniform mat4 TextureMatrix = mat4(1., 0., 0., 0., 0., 1., 0., 0., @@ -11,9 +21,11 @@ in vec3 Position; in vec2 Texcoord; in vec2 SecondTexcoord; in vec3 Normal; +in vec4 Color; out vec3 nor; out vec2 uv; out vec2 uv_bis; +out vec4 color; #else attribute vec3 Position; attribute vec3 Normal; @@ -27,6 +39,9 @@ varying vec2 uv_bis; void main(void) { + color = Color.zyxw; + mat4 ModelViewProjectionMatrix = ProjectionMatrix * ViewMatrix * ModelMatrix; + mat4 TransposeInverseModelView = transpose(InverseModelMatrix * InverseViewMatrix); gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz; uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; diff --git a/data/shaders/objectpass_rimlit.frag b/data/shaders/objectpass_rimlit.frag index 907dd8e9f..f84862947 100644 --- a/data/shaders/objectpass_rimlit.frag +++ b/data/shaders/objectpass_rimlit.frag @@ -6,17 +6,17 @@ uniform vec2 screen; uniform vec3 ambient; #if __VERSION__ >= 130 -in vec3 normal; +in vec3 nor; in vec2 uv; out vec4 FragColor; #else -varying vec3 normal; +varying vec3 nor; varying vec2 uv; #define FragColor gl_FragColor #endif void main() { - float rim = 1.0 - dot(normal, vec3(0., 0., -1)); + float rim = 1.0 - dot(nor, vec3(0., 0., -1)); rim = smoothstep(0.5, 1.5, rim) * 0.35; vec4 color = texture(Albedo, uv); diff --git a/data/shaders/objectpass_rimlit.vert b/data/shaders/objectpass_rimlit.vert deleted file mode 100644 index 59f1feab3..000000000 --- a/data/shaders/objectpass_rimlit.vert +++ /dev/null @@ -1,25 +0,0 @@ -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 TransposeInverseModelView; -uniform mat4 TextureMatrix; - -#if __VERSION__ >= 130 -in vec3 Position; -in vec3 Normal; -in vec2 Texcoord; -in vec4 Color; -out vec2 uv; -out vec3 normal; -#else -attribute vec3 Position; -attribute vec3 Normal; -attribute vec2 Texcoord; -attribute vec4 Color; -varying vec2 uv; -varying vec3 normal; -#endif - -void main() { - normal = (TransposeInverseModelView * vec4(Normal, 0)).xyz; - uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; - gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); -} diff --git a/data/shaders/objectpass_spheremap.frag b/data/shaders/objectpass_spheremap.frag index 13467bbad..c26ae5ab9 100644 --- a/data/shaders/objectpass_spheremap.frag +++ b/data/shaders/objectpass_spheremap.frag @@ -1,7 +1,14 @@ +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; + uniform samplerCube tex; -uniform mat4 invproj; uniform vec2 screen; -uniform mat4 TransposeViewMatrix; #if __VERSION__ >= 130 in vec3 nor; @@ -15,12 +22,12 @@ varying vec3 nor; void main() { vec3 fpos = gl_FragCoord.xyz / vec3(screen, 1.); vec4 xpos = 2.0 * vec4(fpos, 1.0) - 1.0; - xpos = invproj * xpos; + xpos = InverseProjectionMatrix * xpos; xpos.xyz /= xpos.w; vec3 viewSampleDir = reflect(xpos.xyz, nor); // Convert sampleDir in world space (where tex was generated) - vec4 sampleDir = TransposeViewMatrix * vec4(viewSampleDir, 0.); + vec4 sampleDir = transpose(InverseViewMatrix) * vec4(viewSampleDir, 0.); vec4 detail0 = texture(tex, sampleDir.xyz); FragColor = vec4(detail0.xyz, 1.); diff --git a/data/shaders/sky.frag b/data/shaders/sky.frag index d6e44b383..d0ee9a0d3 100644 --- a/data/shaders/sky.frag +++ b/data/shaders/sky.frag @@ -1,5 +1,13 @@ +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; + uniform samplerCube tex; -uniform mat4 InvProjView; uniform vec2 screen; @@ -14,7 +22,7 @@ void main(void) { vec3 eyedir = gl_FragCoord.xyz / vec3(screen, 1.); eyedir = 2.0 * eyedir - 1.0; - vec4 tmp = (InvProjView * vec4(eyedir, 1.)); + vec4 tmp = (InverseViewMatrix * InverseProjectionMatrix * vec4(eyedir, 1.)); eyedir = tmp.xyz / tmp.w; vec4 color = texture(tex, eyedir); FragColor = vec4(color.xyz, 1.); diff --git a/data/shaders/splatting.vert b/data/shaders/splatting.vert deleted file mode 100644 index 2e7743b19..000000000 --- a/data/shaders/splatting.vert +++ /dev/null @@ -1,41 +0,0 @@ -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2013 the SuperTuxKart team -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 TransposeInverseModelView; - -#if __VERSION__ >= 130 -in vec3 Position; -in vec2 Texcoord; -in vec2 SecondTexcoord; -out vec2 uv; -out vec2 uv_bis; -#else -attribute vec3 Position; -attribute vec2 Texcoord; -attribute vec2 SecondTexcoord; -varying vec2 uv; -varying vec2 uv_bis; -#endif - - -void main() -{ - uv = Texcoord; - uv_bis = SecondTexcoord; - gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); -} diff --git a/data/shaders/untextured_object.vert b/data/shaders/untextured_object.vert index 36020e0db..b70cb67c3 100644 --- a/data/shaders/untextured_object.vert +++ b/data/shaders/untextured_object.vert @@ -1,4 +1,13 @@ -uniform mat4 ModelViewProjectionMatrix; +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; + +uniform mat4 ModelMatrix; #if __VERSION__ >= 130 in vec3 Position; @@ -14,5 +23,5 @@ varying vec4 color; void main(void) { color = Color.zyxw; - gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); + gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(Position, 1.); } diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 09cb241a6..ce93dc9a6 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -464,6 +464,7 @@ void IrrDriver::renderSolidSecondPass() GroupedSM::reset(); GroupedSM::reset(); GroupedSM::reset(); + GroupedSM::reset(); setTexture(0, m_rtts->getRenderTarget(RTT_TMP1), GL_NEAREST, GL_NEAREST); setTexture(1, m_rtts->getRenderTarget(RTT_TMP2), GL_NEAREST, GL_NEAREST); setTexture(2, m_rtts->getRenderTarget(RTT_SSAO), GL_NEAREST, GL_NEAREST); @@ -497,6 +498,10 @@ void IrrDriver::renderSolidSecondPass() for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) drawDetailledObjectPass2(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i]); + glUseProgram(MeshShader::UntexturedObjectShader::Program); + for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) + drawUntexturedObject(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i]); + } void IrrDriver::renderTransparent() @@ -1328,7 +1333,7 @@ void IrrDriver::renderSkybox() glBindVertexArray(MeshShader::SkyboxShader::cubevao); glDisable(GL_CULL_FACE); assert(SkyboxTextures.size() == 6); - core::matrix4 transform = irr_driver->getProjViewMatrix(); + core::matrix4 translate; translate.setTranslation(camera->getAbsolutePosition()); @@ -1336,7 +1341,7 @@ void IrrDriver::renderSkybox() const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f; core::matrix4 scale; scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance)); - transform *= translate * scale; + core::matrix4 transform = translate * scale; core::matrix4 invtransform; transform.getInverse(invtransform); @@ -1345,7 +1350,7 @@ void IrrDriver::renderSkybox() glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glUseProgram(MeshShader::SkyboxShader::Program); - MeshShader::SkyboxShader::setUniforms(transform, invtransform, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height), 0); + MeshShader::SkyboxShader::setUniforms(transform, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height), 0); glDrawElements(GL_TRIANGLES, 6 * 6, GL_UNSIGNED_INT, 0); glBindVertexArray(0); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 696205dc9..99c36818a 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -49,7 +49,7 @@ Shaders::Shaders() m_callbacks[ES_SHADOWGEN] = new ShadowGenProvider(); m_callbacks[ES_DISPLACE] = new DisplaceProvider(); - for(s32 i=0 ; i < ES_COUNT ; i++) + for (s32 i = 0; i < ES_COUNT; i++) m_shaders[i] = -1; loadShaders(); @@ -59,16 +59,16 @@ GLuint quad_vbo; static void initQuadVBO() { - const float quad_vertex[] = { - -1., -1., 0., 0., // UpperLeft - -1., 1., 0., 1., // LowerLeft - 1., -1., 1., 0., // UpperRight - 1., 1., 1., 1., // LowerRight - }; - glGenBuffers(1, &quad_vbo); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); - glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + const float quad_vertex[] = { + -1., -1., 0., 0., // UpperLeft + -1., 1., 0., 1., // LowerLeft + 1., -1., 1., 0., // UpperRight + 1., 1., 1., 1., // LowerRight + }; + glGenBuffers(1, &quad_vbo); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); } // It should be possible to merge it with previous one... @@ -76,15 +76,15 @@ GLuint quad_buffer; static void initQuadBuffer() { - const float quad_vertex[] = { - -1., -1., -1., 1., // UpperLeft - -1., 1., -1., -1., // LowerLeft - 1., -1., 1., 1., // UpperRight - 1., 1., 1., -1., // LowerRight - }; - glGenBuffers(1, &quad_buffer); - glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); - glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); + const float quad_vertex[] = { + -1., -1., -1., 1., // UpperLeft + -1., 1., -1., -1., // LowerLeft + 1., -1., 1., 1., // UpperRight + 1., 1., 1., -1., // LowerRight + }; + glGenBuffers(1, &quad_buffer); + glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); + glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); } GLuint SharedObject::billboardvbo = 0; @@ -180,9 +180,9 @@ void Shaders::loadShaders() IGPUProgrammingServices * const gpu = irr_driver->getVideoDriver()->getGPUProgrammingServices(); - #define glsl(a, b, c) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) c) - #define glslmat(a, b, c, d) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) c, d) - #define glsl_noinput(a, b) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) 0) +#define glsl(a, b, c) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) c) +#define glslmat(a, b, c, d) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) c, d) +#define glsl_noinput(a, b) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) 0) // Save previous shaders (used in case some shaders don't compile) int saved_shaders[ES_COUNT]; @@ -193,41 +193,41 @@ void Shaders::loadShaders() m_shaders[ES_NORMAL_MAP_LIGHTMAP] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_SKYBOX] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_SKYBOX], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_SKYBOX], EMT_TRANSPARENT_ALPHA_CHANNEL); m_shaders[ES_SPLATTING] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_WATER] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_WATER], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_WATER], EMT_TRANSPARENT_ALPHA_CHANNEL); m_shaders[ES_WATER_SURFACE] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_WATER]); + m_callbacks[ES_WATER]); m_shaders[ES_SPHERE_MAP] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_GRASS] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL); m_shaders[ES_GRASS_REF] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL_REF); + m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL_REF); m_shaders[ES_BUBBLES] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_BUBBLES], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_BUBBLES], EMT_TRANSPARENT_ALPHA_CHANNEL); m_shaders[ES_RAIN] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_RAIN], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_RAIN], EMT_TRANSPARENT_ALPHA_CHANNEL); m_shaders[ES_MOTIONBLUR] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_MOTIONBLUR]); + m_callbacks[ES_MOTIONBLUR]); m_shaders[ES_GAUSSIAN3H] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); + m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); m_shaders[ES_GAUSSIAN3V] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GAUSSIAN3V], EMT_SOLID); + m_callbacks[ES_GAUSSIAN3V], EMT_SOLID); m_shaders[ES_MIPVIZ] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_MIPVIZ], EMT_SOLID); + m_callbacks[ES_MIPVIZ], EMT_SOLID); m_shaders[ES_COLORIZE] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_COLORIZE], EMT_SOLID); + m_callbacks[ES_COLORIZE], EMT_SOLID); m_shaders[ES_OBJECTPASS] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_OBJECT_UNLIT] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); @@ -237,36 +237,36 @@ void Shaders::loadShaders() m_shaders[ES_SUNLIGHT] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_SHADOWPASS] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_SHADOWPASS]); + m_callbacks[ES_SHADOWPASS]); m_shaders[ES_SHADOW_IMPORTANCE] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_SHADOW_IMPORTANCE]); + m_callbacks[ES_SHADOW_IMPORTANCE]); m_shaders[ES_COLLAPSE] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_COLLAPSE]); + m_callbacks[ES_COLLAPSE]); m_shaders[ES_SHADOW_WARPH] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_COLLAPSE]); + m_callbacks[ES_COLLAPSE]); m_shaders[ES_SHADOW_WARPV] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_COLLAPSE]); + m_callbacks[ES_COLLAPSE]); m_shaders[ES_MULTIPLY_ADD] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_MULTIPLY_ADD], EMT_ONETEXTURE_BLEND); + m_callbacks[ES_MULTIPLY_ADD], EMT_ONETEXTURE_BLEND); m_shaders[ES_PENUMBRAH] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); + m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); m_shaders[ES_PENUMBRAV] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); + m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); m_shaders[ES_SHADOWGEN] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_SHADOWGEN], EMT_SOLID); + m_callbacks[ES_SHADOWGEN], EMT_SOLID); m_shaders[ES_CAUSTICS] = glslmat(dir + "pass.vert", dir + "pass.frag", m_callbacks[ES_CAUSTICS], EMT_SOLID); m_shaders[ES_DISPLACE] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_DISPLACE]); + m_callbacks[ES_DISPLACE]); m_shaders[ES_PASSFAR] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_COLORIZE]); + m_callbacks[ES_COLORIZE]); // Check that all successfully loaded for (s32 i = 0; i < ES_COUNT; i++) { @@ -279,37 +279,37 @@ void Shaders::loadShaders() check(i); } - #undef glsl - #undef glslmat - #undef glsl_noinput +#undef glsl +#undef glslmat +#undef glsl_noinput // In case we're reloading and a shader didn't compile: keep the previous, working one - for(s32 i=0 ; i < ES_COUNT ; i++) + for (s32 i = 0; i < ES_COUNT; i++) { - if(m_shaders[i] == -1) + if (m_shaders[i] == -1) m_shaders[i] = saved_shaders[i]; } - initGL(); - initQuadVBO(); - initQuadBuffer(); + initGL(); + initQuadVBO(); + initQuadBuffer(); initBillboardVBO(); initCubeVBO(); initShadowVPMUBO(); - FullScreenShader::BloomBlendShader::init(); - FullScreenShader::BloomShader::init(); - FullScreenShader::ColorLevelShader::init(); - FullScreenShader::FogShader::init(); - FullScreenShader::Gaussian3HBlurShader::init(); - FullScreenShader::Gaussian3VBlurShader::init(); - FullScreenShader::Gaussian6HBlurShader::init(); - FullScreenShader::Gaussian6VBlurShader::init(); + FullScreenShader::BloomBlendShader::init(); + FullScreenShader::BloomShader::init(); + FullScreenShader::ColorLevelShader::init(); + FullScreenShader::FogShader::init(); + FullScreenShader::Gaussian3HBlurShader::init(); + FullScreenShader::Gaussian3VBlurShader::init(); + FullScreenShader::Gaussian6HBlurShader::init(); + FullScreenShader::Gaussian6VBlurShader::init(); FullScreenShader::PenumbraHShader::init(); FullScreenShader::PenumbraVShader::init(); - FullScreenShader::GlowShader::init(); - FullScreenShader::PassThroughShader::init(); - FullScreenShader::SSAOShader::init(); - FullScreenShader::SunLightShader::init(); + FullScreenShader::GlowShader::init(); + FullScreenShader::PassThroughShader::init(); + FullScreenShader::SSAOShader::init(); + FullScreenShader::SunLightShader::init(); FullScreenShader::DiffuseEnvMapShader::init(); FullScreenShader::ShadowedSunLightShader::init(); FullScreenShader::MotionBlurShader::init(); @@ -319,33 +319,33 @@ void Shaders::loadShaders() FullScreenShader::MLAAColorEdgeDetectionSHader::init(); FullScreenShader::MLAABlendWeightSHader::init(); FullScreenShader::MLAAGatherSHader::init(); - MeshShader::ColorizeShader::init(); - MeshShader::NormalMapShader::init(); - MeshShader::ObjectPass1Shader::init(); - MeshShader::ObjectRefPass1Shader::init(); + MeshShader::ColorizeShader::init(); + MeshShader::NormalMapShader::init(); + MeshShader::ObjectPass1Shader::init(); + MeshShader::ObjectRefPass1Shader::init(); MeshShader::InstancedObjectPass1Shader::init(); MeshShader::InstancedObjectRefPass1Shader::init(); MeshShader::InstancedGrassPass1Shader::init(); - MeshShader::ObjectPass2Shader::init(); + MeshShader::ObjectPass2Shader::init(); MeshShader::InstancedObjectPass2Shader::init(); MeshShader::InstancedObjectRefPass2Shader::init(); MeshShader::InstancedGrassPass2Shader::init(); - MeshShader::DetailledObjectPass2Shader::init(); - MeshShader::ObjectRimLimitShader::init(); - MeshShader::UntexturedObjectShader::init(); - MeshShader::ObjectRefPass2Shader::init(); - MeshShader::ObjectUnlitShader::init(); - MeshShader::SphereMapShader::init(); - MeshShader::SplattingShader::init(); - MeshShader::GrassPass1Shader::init(); - MeshShader::GrassPass2Shader::init(); + MeshShader::DetailledObjectPass2Shader::init(); + MeshShader::ObjectRimLimitShader::init(); + MeshShader::UntexturedObjectShader::init(); + MeshShader::ObjectRefPass2Shader::init(); + MeshShader::ObjectUnlitShader::init(); + MeshShader::SphereMapShader::init(); + MeshShader::SplattingShader::init(); + MeshShader::GrassPass1Shader::init(); + MeshShader::GrassPass2Shader::init(); MeshShader::CausticsShader::init(); - MeshShader::BubbleShader::init(); - MeshShader::TransparentShader::init(); + MeshShader::BubbleShader::init(); + MeshShader::TransparentShader::init(); MeshShader::TransparentFogShader::init(); - MeshShader::BillboardShader::init(); + MeshShader::BillboardShader::init(); LightShader::PointLightShader::init(); - MeshShader::DisplaceShader::init(); + MeshShader::DisplaceShader::init(); MeshShader::DisplaceMaskShader::init(); MeshShader::ShadowShader::init(); MeshShader::InstancedShadowShader::init(); @@ -353,13 +353,13 @@ void Shaders::loadShaders() MeshShader::InstancedRefShadowShader::init(); MeshShader::GrassShadowShader::init(); MeshShader::SkyboxShader::init(); - ParticleShader::FlipParticleRender::init(); - ParticleShader::HeightmapSimulationShader::init(); - ParticleShader::SimpleParticleRender::init(); - ParticleShader::SimpleSimulationShader::init(); - UIShader::ColoredRectShader::init(); - UIShader::ColoredTextureRectShader::init(); - UIShader::TextureRectShader::init(); + ParticleShader::FlipParticleRender::init(); + ParticleShader::HeightmapSimulationShader::init(); + ParticleShader::SimpleParticleRender::init(); + ParticleShader::SimpleSimulationShader::init(); + UIShader::ColoredRectShader::init(); + UIShader::ColoredTextureRectShader::init(); + UIShader::TextureRectShader::init(); UIShader::UniformColoredTextureRectShader::init(); } @@ -377,7 +377,7 @@ E_MATERIAL_TYPE Shaders::getShader(const ShaderType num) const { assert(num < ES_COUNT); - return (E_MATERIAL_TYPE) m_shaders[num]; + return (E_MATERIAL_TYPE)m_shaders[num]; } void Shaders::check(const int num) const @@ -385,7 +385,7 @@ void Shaders::check(const int num) const if (m_shaders[num] == -1) { Log::error("shaders", "Shader %s failed to load. Update your drivers, if the issue " - "persists, report a bug to us.", shader_names[num] + 3); + "persists, report a bug to us.", shader_names[num] + 3); } } @@ -393,66 +393,70 @@ namespace MeshShader { // Solid Normal and depth pass shaders - GLuint ObjectPass1Shader::Program; - GLuint ObjectPass1Shader::attrib_position; - GLuint ObjectPass1Shader::attrib_normal; + GLuint ObjectPass1Shader::Program; + GLuint ObjectPass1Shader::attrib_position; + GLuint ObjectPass1Shader::attrib_normal; GLuint ObjectPass1Shader::attrib_texcoord; - GLuint ObjectPass1Shader::uniform_MVP; - GLuint ObjectPass1Shader::uniform_TIMV; + GLuint ObjectPass1Shader::uniform_MM; + GLuint ObjectPass1Shader::uniform_IMM; GLuint ObjectPass1Shader::uniform_tex; - void ObjectPass1Shader::init() - { + void ObjectPass1Shader::init() + { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass1.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_normal = glGetAttribLocation(Program, "Normal"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_normal = glGetAttribLocation(Program, "Normal"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); - } + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); + } - void ObjectPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_tex) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer()); + void ObjectPass1Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_tex) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer()); glUniform1i(uniform_tex, TU_tex); - } + } - GLuint ObjectRefPass1Shader::Program; - GLuint ObjectRefPass1Shader::attrib_position; - GLuint ObjectRefPass1Shader::attrib_normal; - GLuint ObjectRefPass1Shader::attrib_texcoord; - GLuint ObjectRefPass1Shader::uniform_MVP; - GLuint ObjectRefPass1Shader::uniform_TIMV; + GLuint ObjectRefPass1Shader::Program; + GLuint ObjectRefPass1Shader::attrib_position; + GLuint ObjectRefPass1Shader::attrib_normal; + GLuint ObjectRefPass1Shader::attrib_texcoord; + GLuint ObjectRefPass1Shader::uniform_MM; + GLuint ObjectRefPass1Shader::uniform_IMM; GLuint ObjectRefPass1Shader::uniform_TM; - GLuint ObjectRefPass1Shader::uniform_tex; + GLuint ObjectRefPass1Shader::uniform_tex; - void ObjectRefPass1Shader::init() - { - Program = LoadProgram( + void ObjectRefPass1Shader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_normal = glGetAttribLocation(Program, "Normal"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_normal = glGetAttribLocation(Program, "Normal"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); - uniform_tex = glGetUniformLocation(Program, "tex"); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); + } - void ObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix, unsigned TU_tex) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + void ObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); - glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer()); - glUniform1i(uniform_tex, TU_tex); - } + glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer()); + glUniform1i(uniform_tex, TU_tex); + } GLuint GrassPass1Shader::Program; GLuint GrassPass1Shader::attrib_position; @@ -493,8 +497,8 @@ namespace MeshShader GLuint NormalMapShader::attrib_texcoord; GLuint NormalMapShader::attrib_tangent; GLuint NormalMapShader::attrib_bitangent; - GLuint NormalMapShader::uniform_MVP; - GLuint NormalMapShader::uniform_TIMV; + GLuint NormalMapShader::uniform_MM; + GLuint NormalMapShader::uniform_IMM; GLuint NormalMapShader::uniform_normalMap; void NormalMapShader::init() @@ -507,15 +511,17 @@ namespace MeshShader attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); attrib_tangent = glGetAttribLocation(Program, "Tangent"); attrib_bitangent = glGetAttribLocation(Program, "Bitangent"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix"); uniform_normalMap = glGetUniformLocation(Program, "normalMap"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void NormalMapShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_normalMap) + void NormalMapShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_normalMap) { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer()); + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer()); glUniform1i(uniform_normalMap, TU_normalMap); } @@ -620,31 +626,33 @@ namespace MeshShader // Solid Lit pass shaders - GLuint ObjectPass2Shader::Program; - GLuint ObjectPass2Shader::attrib_position; - GLuint ObjectPass2Shader::attrib_texcoord; - GLuint ObjectPass2Shader::uniform_MVP; + GLuint ObjectPass2Shader::Program; + GLuint ObjectPass2Shader::attrib_position; + GLuint ObjectPass2Shader::attrib_texcoord; + GLuint ObjectPass2Shader::uniform_MM; GLuint ObjectPass2Shader::uniform_TM; - GLuint ObjectPass2Shader::uniform_screen; - GLuint ObjectPass2Shader::uniform_ambient; + GLuint ObjectPass2Shader::uniform_screen; + GLuint ObjectPass2Shader::uniform_ambient; GLuint ObjectPass2Shader::TU_Albedo; - void ObjectPass2Shader::init() - { - Program = LoadProgram( + void ObjectPass2Shader::init() + { + 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/object_pass2.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo"); GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_Albedo = 3; glUseProgram(Program); @@ -653,16 +661,16 @@ namespace MeshShader glUniform1i(uniform_SSAO, 2); glUniform1i(uniform_Albedo, TU_Albedo); glUseProgram(0); - } + } - void ObjectPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + void ObjectPass2Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } GLuint InstancedObjectPass2Shader::Program; GLuint InstancedObjectPass2Shader::attrib_position; @@ -772,33 +780,35 @@ namespace MeshShader glUniform3f(uniform_ambient, s.r, s.g, s.b); } - GLuint DetailledObjectPass2Shader::Program; - GLuint DetailledObjectPass2Shader::attrib_position; - GLuint DetailledObjectPass2Shader::attrib_texcoord; - GLuint DetailledObjectPass2Shader::attrib_second_texcoord; - GLuint DetailledObjectPass2Shader::uniform_MVP; - GLuint DetailledObjectPass2Shader::uniform_screen; - GLuint DetailledObjectPass2Shader::uniform_ambient; + GLuint DetailledObjectPass2Shader::Program; + GLuint DetailledObjectPass2Shader::attrib_position; + GLuint DetailledObjectPass2Shader::attrib_texcoord; + GLuint DetailledObjectPass2Shader::attrib_second_texcoord; + GLuint DetailledObjectPass2Shader::uniform_MM; + GLuint DetailledObjectPass2Shader::uniform_screen; + GLuint DetailledObjectPass2Shader::uniform_ambient; GLuint DetailledObjectPass2Shader::TU_Albedo; GLuint DetailledObjectPass2Shader::TU_detail; - void DetailledObjectPass2Shader::init() - { - Program = LoadProgram( + void DetailledObjectPass2Shader::init() + { + 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/detailledobject_pass2.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo"); GLuint uniform_Detail = glGetUniformLocation(Program, "Detail"); GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_Albedo = 3; TU_detail = 4; @@ -809,71 +819,76 @@ namespace MeshShader glUniform1i(uniform_Albedo, TU_Albedo); glUniform1i(uniform_Detail, TU_detail); glUseProgram(0); - } + } - void DetailledObjectPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + void DetailledObjectPass2Shader::setUniforms(const core::matrix4 &ModelMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } - GLuint ObjectUnlitShader::Program; - GLuint ObjectUnlitShader::attrib_position; - GLuint ObjectUnlitShader::attrib_texcoord; - GLuint ObjectUnlitShader::uniform_MVP; - GLuint ObjectUnlitShader::TU_tex; + GLuint ObjectUnlitShader::Program; + GLuint ObjectUnlitShader::attrib_position; + GLuint ObjectUnlitShader::attrib_texcoord; + GLuint ObjectUnlitShader::uniform_MM; + GLuint ObjectUnlitShader::TU_tex; - void ObjectUnlitShader::init() - { - Program = LoadProgram( + void ObjectUnlitShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - GLuint uniform_tex = glGetUniformLocation(Program, "tex"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + GLuint uniform_tex = glGetUniformLocation(Program, "tex"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_tex = 3; glUseProgram(Program); glUniform1i(uniform_tex, TU_tex); glUseProgram(0); - } + } - void ObjectUnlitShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - } + void ObjectUnlitShader::setUniforms(const core::matrix4 &ModelMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + } - GLuint ObjectRimLimitShader::Program; - GLuint ObjectRimLimitShader::attrib_position; - GLuint ObjectRimLimitShader::attrib_texcoord; - GLuint ObjectRimLimitShader::attrib_normal; - GLuint ObjectRimLimitShader::uniform_MVP; - GLuint ObjectRimLimitShader::uniform_TIMV; + GLuint ObjectRimLimitShader::Program; + GLuint ObjectRimLimitShader::attrib_position; + GLuint ObjectRimLimitShader::attrib_texcoord; + GLuint ObjectRimLimitShader::attrib_normal; + GLuint ObjectRimLimitShader::uniform_MM; + GLuint ObjectRimLimitShader::uniform_IMM; GLuint ObjectRimLimitShader::uniform_TM; - GLuint ObjectRimLimitShader::uniform_screen; - GLuint ObjectRimLimitShader::uniform_ambient; + GLuint ObjectRimLimitShader::uniform_screen; + GLuint ObjectRimLimitShader::uniform_ambient; GLuint ObjectRimLimitShader::TU_Albedo; - void ObjectRimLimitShader::init() - { - Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/objectpass_rimlit.vert").c_str(), + void ObjectRimLimitShader::init() + { + Program = LoadProgram( + GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectpass_rimlit.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - attrib_normal = glGetAttribLocation(Program, "Normal"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_normal = glGetAttribLocation(Program, "Normal"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo"); GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_tex = glGetUniformLocation(Program, "tex"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_Albedo = 3; glUseProgram(Program); @@ -882,82 +897,86 @@ namespace MeshShader glUniform1i(uniform_SSAO, 2); glUniform1i(uniform_Albedo, TU_Albedo); glUseProgram(0); - } + } - void ObjectRimLimitShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer()); + void ObjectRimLimitShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } - GLuint UntexturedObjectShader::Program; - GLuint UntexturedObjectShader::attrib_position; - GLuint UntexturedObjectShader::attrib_color; - GLuint UntexturedObjectShader::uniform_MVP; - GLuint UntexturedObjectShader::uniform_screen; - GLuint UntexturedObjectShader::uniform_ambient; + GLuint UntexturedObjectShader::Program; + GLuint UntexturedObjectShader::attrib_position; + GLuint UntexturedObjectShader::attrib_color; + GLuint UntexturedObjectShader::uniform_MM; + GLuint UntexturedObjectShader::uniform_screen; + GLuint UntexturedObjectShader::uniform_ambient; - void UntexturedObjectShader::init() - { - Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/untextured_object.vert").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/untextured_object.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_color = glGetAttribLocation(Program, "Color"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); - GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); - GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + void UntexturedObjectShader::init() + { + 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/untextured_object.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_color = glGetAttribLocation(Program, "Color"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); + GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); + GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); - glUseProgram(Program); - glUniform1i(uniform_DiffuseMap, 0); - glUniform1i(uniform_SpecularMap, 1); - glUniform1i(uniform_SSAO, 2); - glUseProgram(0); - } + glUseProgram(Program); + glUniform1i(uniform_DiffuseMap, 0); + glUniform1i(uniform_SpecularMap, 1); + glUniform1i(uniform_SSAO, 2); + glUseProgram(0); + } - void UntexturedObjectShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + void UntexturedObjectShader::setUniforms(const core::matrix4 &ModelMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } - GLuint ObjectRefPass2Shader::Program; - GLuint ObjectRefPass2Shader::attrib_position; - GLuint ObjectRefPass2Shader::attrib_texcoord; - GLuint ObjectRefPass2Shader::uniform_MVP; + GLuint ObjectRefPass2Shader::Program; + GLuint ObjectRefPass2Shader::attrib_position; + GLuint ObjectRefPass2Shader::attrib_texcoord; + GLuint ObjectRefPass2Shader::uniform_MM; GLuint ObjectRefPass2Shader::uniform_TM; - GLuint ObjectRefPass2Shader::uniform_screen; - GLuint ObjectRefPass2Shader::uniform_ambient; + GLuint ObjectRefPass2Shader::uniform_screen; + GLuint ObjectRefPass2Shader::uniform_ambient; GLuint ObjectRefPass2Shader::TU_Albedo; - void ObjectRefPass2Shader::init() - { - initGL(); - Program = LoadProgram( + void ObjectRefPass2Shader::init() + { + initGL(); + 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/objectref_pass2.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo"); GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); - GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_Albedo = 3; glUseProgram(Program); @@ -966,44 +985,44 @@ namespace MeshShader glUniform1i(uniform_SSAO, 2); glUniform1i(uniform_Albedo, TU_Albedo); glUseProgram(0); - } + } - void ObjectRefPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + void ObjectRefPass2Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } - GLuint GrassPass2Shader::Program; - GLuint GrassPass2Shader::attrib_position; - GLuint GrassPass2Shader::attrib_texcoord; - GLuint GrassPass2Shader::attrib_color; - GLuint GrassPass2Shader::uniform_MVP; - GLuint GrassPass2Shader::uniform_screen; - GLuint GrassPass2Shader::uniform_ambient; - GLuint GrassPass2Shader::uniform_windDir; + GLuint GrassPass2Shader::Program; + GLuint GrassPass2Shader::attrib_position; + GLuint GrassPass2Shader::attrib_texcoord; + GLuint GrassPass2Shader::attrib_color; + GLuint GrassPass2Shader::uniform_MVP; + GLuint GrassPass2Shader::uniform_screen; + GLuint GrassPass2Shader::uniform_ambient; + GLuint GrassPass2Shader::uniform_windDir; GLuint GrassPass2Shader::TU_Albedo; - void GrassPass2Shader::init() - { - Program = LoadProgram( + void GrassPass2Shader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - attrib_color = glGetAttribLocation(Program, "Color"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_color = glGetAttribLocation(Program, "Color"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo"); GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); - uniform_windDir = glGetUniformLocation(Program, "windDir"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + uniform_windDir = glGetUniformLocation(Program, "windDir"); TU_Albedo = 3; glUseProgram(Program); @@ -1012,16 +1031,16 @@ namespace MeshShader glUniform1i(uniform_SSAO, 2); glUniform1i(uniform_Albedo, TU_Albedo); glUseProgram(0); - } + } - void GrassPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z); - } + void GrassPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z); + } GLuint InstancedGrassPass2Shader::Program; GLuint InstancedGrassPass2Shader::attrib_position; @@ -1094,67 +1113,61 @@ namespace MeshShader glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z); } - GLuint SphereMapShader::Program; - GLuint SphereMapShader::attrib_position; - GLuint SphereMapShader::attrib_normal; - GLuint SphereMapShader::uniform_MVP; - GLuint SphereMapShader::uniform_TIMV; - GLuint SphereMapShader::uniform_TVM; - GLuint SphereMapShader::uniform_invproj; + GLuint SphereMapShader::Program; + GLuint SphereMapShader::attrib_position; + GLuint SphereMapShader::attrib_normal; + GLuint SphereMapShader::uniform_MM; + GLuint SphereMapShader::uniform_IMM; GLuint SphereMapShader::uniform_screen; GLuint SphereMapShader::TU_tex; - void SphereMapShader::init() - { - Program = LoadProgram( + void SphereMapShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectpass_spheremap.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_normal = glGetAttribLocation(Program, "Normal"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView"); - uniform_TVM = glGetUniformLocation(Program, "TransposeViewMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_normal = glGetAttribLocation(Program, "Normal"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix"); GLuint uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_invproj = glGetUniformLocation(Program, "invproj"); uniform_screen = glGetUniformLocation(Program, "screen"); TU_tex = 3; glUseProgram(Program); glUniform1i(uniform_tex, TU_tex); glUseProgram(0); - } + } - void SphereMapShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeViewMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &InvProj, const core::vector2df& screen) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer()); - glUniformMatrix4fv(uniform_TVM, 1, GL_FALSE, TransposeViewMatrix.pointer()); - glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProj.pointer()); + void SphereMapShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::vector2df& screen) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer()); glUniform2f(uniform_screen, screen.X, screen.Y); - } + } - GLuint SplattingShader::Program; - GLuint SplattingShader::attrib_position; - GLuint SplattingShader::attrib_texcoord; - GLuint SplattingShader::attrib_second_texcoord; - GLuint SplattingShader::uniform_MVP; - GLuint SplattingShader::uniform_screen; - GLuint SplattingShader::uniform_ambient; + GLuint SplattingShader::Program; + GLuint SplattingShader::attrib_position; + GLuint SplattingShader::attrib_texcoord; + GLuint SplattingShader::attrib_second_texcoord; + GLuint SplattingShader::uniform_MM; + GLuint SplattingShader::uniform_screen; + GLuint SplattingShader::uniform_ambient; GLuint SplattingShader::TU_tex_layout; GLuint SplattingShader::TU_tex_detail0; GLuint SplattingShader::TU_tex_detail1; GLuint SplattingShader::TU_tex_detail2; GLuint SplattingShader::TU_tex_detail3; - void SplattingShader::init() - { - Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/splatting.vert").c_str(), + void SplattingShader::init() + { + Program = LoadProgram( + GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/splatting.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); GLuint uniform_tex_layout = glGetUniformLocation(Program, "tex_layout"); GLuint uniform_tex_detail0 = glGetUniformLocation(Program, "tex_detail0"); GLuint uniform_tex_detail1 = glGetUniformLocation(Program, "tex_detail1"); @@ -1163,8 +1176,8 @@ namespace MeshShader GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); TU_tex_layout = 3; TU_tex_detail0 = 4; TU_tex_detail1 = 5; @@ -1181,15 +1194,15 @@ namespace MeshShader glUniform1i(uniform_tex_detail2, TU_tex_detail2); glUniform1i(uniform_tex_detail3, TU_tex_detail3); glUseProgram(0); - } + } - void SplattingShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + void SplattingShader::setUniforms(const core::matrix4 &ModelMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } GLuint CausticsShader::Program; GLuint CausticsShader::attrib_position; @@ -1242,61 +1255,61 @@ namespace MeshShader glUniform3f(uniform_ambient, s.r, s.g, s.b); } - GLuint BubbleShader::Program; - GLuint BubbleShader::attrib_position; - GLuint BubbleShader::attrib_texcoord; - GLuint BubbleShader::uniform_MVP; - GLuint BubbleShader::uniform_tex; - GLuint BubbleShader::uniform_time; - GLuint BubbleShader::uniform_transparency; + GLuint BubbleShader::Program; + GLuint BubbleShader::attrib_position; + GLuint BubbleShader::attrib_texcoord; + GLuint BubbleShader::uniform_MVP; + GLuint BubbleShader::uniform_tex; + GLuint BubbleShader::uniform_time; + GLuint BubbleShader::uniform_transparency; - void BubbleShader::init() - { - Program = LoadProgram( + void BubbleShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/bubble.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bubble.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_time = glGetUniformLocation(Program, "time"); - uniform_transparency = glGetUniformLocation(Program, "transparency"); - } + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_time = glGetUniformLocation(Program, "time"); + uniform_transparency = glGetUniformLocation(Program, "transparency"); + } void BubbleShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex, float time, float transparency) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform1i(uniform_tex, TU_tex); - glUniform1f(uniform_time, time); - glUniform1f(uniform_transparency, transparency); - } + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniform1i(uniform_tex, TU_tex); + glUniform1f(uniform_time, time); + glUniform1f(uniform_transparency, transparency); + } - GLuint TransparentShader::Program; - GLuint TransparentShader::attrib_position; - GLuint TransparentShader::attrib_texcoord; + GLuint TransparentShader::Program; + GLuint TransparentShader::attrib_position; + GLuint TransparentShader::attrib_texcoord; GLuint TransparentShader::attrib_color; - GLuint TransparentShader::uniform_MVP; + GLuint TransparentShader::uniform_MVP; GLuint TransparentShader::uniform_TM; - GLuint TransparentShader::uniform_tex; + GLuint TransparentShader::uniform_tex; - void TransparentShader::init() - { - Program = LoadProgram( + void TransparentShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/transparent.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparent.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); attrib_color = glGetAttribLocation(Program, "Color"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); - uniform_tex = glGetUniformLocation(Program, "tex"); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + } void TransparentShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); - glUniform1i(uniform_tex, TU_tex); - } + glUniform1i(uniform_tex, TU_tex); + } GLuint TransparentFogShader::Program; GLuint TransparentFogShader::attrib_position; @@ -1349,59 +1362,59 @@ namespace MeshShader glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer()); glUniform1i(uniform_tex, TU_tex); } - - GLuint BillboardShader::Program; - GLuint BillboardShader::attrib_corner; - GLuint BillboardShader::attrib_texcoord; - GLuint BillboardShader::uniform_MV; - GLuint BillboardShader::uniform_P; - GLuint BillboardShader::uniform_tex; - GLuint BillboardShader::uniform_Position; - GLuint BillboardShader::uniform_Size; - void BillboardShader::init() - { - Program = LoadProgram( + GLuint BillboardShader::Program; + GLuint BillboardShader::attrib_corner; + GLuint BillboardShader::attrib_texcoord; + GLuint BillboardShader::uniform_MV; + GLuint BillboardShader::uniform_P; + GLuint BillboardShader::uniform_tex; + GLuint BillboardShader::uniform_Position; + GLuint BillboardShader::uniform_Size; + + void BillboardShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/billboard.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/billboard.frag").c_str()); - attrib_corner = glGetAttribLocation(Program, "Corner"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix"); - uniform_P = glGetUniformLocation(Program, "ProjectionMatrix"); - uniform_Position = glGetUniformLocation(Program, "Position"); - uniform_Size = glGetUniformLocation(Program, "Size"); - uniform_tex = glGetUniformLocation(Program, "tex"); - } + attrib_corner = glGetAttribLocation(Program, "Corner"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix"); + uniform_P = glGetUniformLocation(Program, "ProjectionMatrix"); + uniform_Position = glGetUniformLocation(Program, "Position"); + uniform_Size = glGetUniformLocation(Program, "Size"); + uniform_tex = glGetUniformLocation(Program, "tex"); + } - void BillboardShader::setUniforms(const core::matrix4 &ModelViewMatrix, const core::matrix4 &ProjectionMatrix, const core::vector3df &Position, const core::dimension2d &size, unsigned TU_tex) - { - glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer()); - glUniformMatrix4fv(uniform_P, 1, GL_FALSE, ProjectionMatrix.pointer()); - glUniform3f(uniform_Position, Position.X, Position.Y, Position.Z); - glUniform2f(uniform_Size, size.Width, size.Height); - glUniform1i(uniform_tex, TU_tex); - } + void BillboardShader::setUniforms(const core::matrix4 &ModelViewMatrix, const core::matrix4 &ProjectionMatrix, const core::vector3df &Position, const core::dimension2d &size, unsigned TU_tex) + { + glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer()); + glUniformMatrix4fv(uniform_P, 1, GL_FALSE, ProjectionMatrix.pointer()); + glUniform3f(uniform_Position, Position.X, Position.Y, Position.Z); + glUniform2f(uniform_Size, size.Width, size.Height); + glUniform1i(uniform_tex, TU_tex); + } - GLuint ColorizeShader::Program; - GLuint ColorizeShader::attrib_position; - GLuint ColorizeShader::uniform_MVP; - GLuint ColorizeShader::uniform_col; + GLuint ColorizeShader::Program; + GLuint ColorizeShader::attrib_position; + GLuint ColorizeShader::uniform_MVP; + GLuint ColorizeShader::uniform_col; - void ColorizeShader::init() - { - Program = LoadProgram( + void ColorizeShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/colorize.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_col = glGetUniformLocation(Program, "col"); - } + attrib_position = glGetAttribLocation(Program, "Position"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_col = glGetUniformLocation(Program, "col"); + } - void ColorizeShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, float r, float g, float b) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform3f(uniform_col, r, g, b); - } + void ColorizeShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, float r, float g, float b) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniform3f(uniform_col, r, g, b); + } GLuint ShadowShader::Program; GLuint ShadowShader::attrib_position; @@ -1578,55 +1591,54 @@ namespace MeshShader glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); } - GLuint DisplaceShader::Program; - GLuint DisplaceShader::attrib_position; - GLuint DisplaceShader::attrib_texcoord; - GLuint DisplaceShader::attrib_second_texcoord; - GLuint DisplaceShader::uniform_MVP; - GLuint DisplaceShader::uniform_MV; - GLuint DisplaceShader::uniform_displacement_tex; + GLuint DisplaceShader::Program; + GLuint DisplaceShader::attrib_position; + GLuint DisplaceShader::attrib_texcoord; + GLuint DisplaceShader::attrib_second_texcoord; + GLuint DisplaceShader::uniform_MVP; + GLuint DisplaceShader::uniform_MV; + GLuint DisplaceShader::uniform_displacement_tex; GLuint DisplaceShader::uniform_mask_tex; GLuint DisplaceShader::uniform_color_tex; - GLuint DisplaceShader::uniform_dir; - GLuint DisplaceShader::uniform_dir2; + GLuint DisplaceShader::uniform_dir; + GLuint DisplaceShader::uniform_dir2; GLuint DisplaceShader::uniform_screen; - void DisplaceShader::init() - { - Program = LoadProgram( + void DisplaceShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/displace.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/displace.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix"); - uniform_displacement_tex = glGetUniformLocation(Program, "displacement_tex"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix"); + uniform_displacement_tex = glGetUniformLocation(Program, "displacement_tex"); uniform_color_tex = glGetUniformLocation(Program, "color_tex"); uniform_mask_tex = glGetUniformLocation(Program, "mask_tex"); - uniform_dir = glGetUniformLocation(Program, "dir"); - uniform_dir2 = glGetUniformLocation(Program, "dir2"); + uniform_dir = glGetUniformLocation(Program, "dir"); + uniform_dir2 = glGetUniformLocation(Program, "dir2"); uniform_screen = glGetUniformLocation(Program, "screen"); - } + } - void DisplaceShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ModelViewMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer()); - glUniform2f(uniform_dir, dir.X, dir.Y); - glUniform2f(uniform_dir2, dir2.X, dir2.Y); + void DisplaceShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ModelViewMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer()); + glUniform2f(uniform_dir, dir.X, dir.Y); + glUniform2f(uniform_dir2, dir2.X, dir2.Y); glUniform2f(uniform_screen, screen.X, screen.Y); - glUniform1i(uniform_displacement_tex, TU_displacement_tex); + glUniform1i(uniform_displacement_tex, TU_displacement_tex); glUniform1i(uniform_mask_tex, TU_mask_tex); glUniform1i(uniform_color_tex, TU_color_tex); - } + } GLuint SkyboxShader::Program; GLuint SkyboxShader::attrib_position; - GLuint SkyboxShader::uniform_MVP; + GLuint SkyboxShader::uniform_MM; GLuint SkyboxShader::uniform_tex; GLuint SkyboxShader::uniform_screen; - GLuint SkyboxShader::uniform_InvProjView; GLuint SkyboxShader::cubevao; void SkyboxShader::init() @@ -1635,10 +1647,11 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sky.frag").c_str()); attrib_position = glGetAttribLocation(Program, "Position"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_InvProjView = glGetUniformLocation(Program, "InvProjView"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); uniform_screen = glGetUniformLocation(Program, "screen"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); glGenVertexArrays(1, &cubevao); glBindVertexArray(cubevao); @@ -1649,10 +1662,9 @@ namespace MeshShader glBindVertexArray(0); } - void SkyboxShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &InvProjView, const core::vector2df &screen, unsigned TU_tex) + void SkyboxShader::setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &screen, unsigned TU_tex) { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_InvProjView, 1, GL_FALSE, InvProjView.pointer()); + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); glUniform1i(uniform_tex, TU_tex); glUniform2f(uniform_screen, screen.X, screen.Y); } @@ -1735,306 +1747,306 @@ namespace LightShader namespace ParticleShader { - GLuint SimpleSimulationShader::Program; - GLuint SimpleSimulationShader::attrib_position; - GLuint SimpleSimulationShader::attrib_velocity; - GLuint SimpleSimulationShader::attrib_lifetime; - GLuint SimpleSimulationShader::attrib_initial_position; - GLuint SimpleSimulationShader::attrib_initial_velocity; - GLuint SimpleSimulationShader::attrib_initial_lifetime; - GLuint SimpleSimulationShader::attrib_size; - GLuint SimpleSimulationShader::attrib_initial_size; - GLuint SimpleSimulationShader::uniform_sourcematrix; - GLuint SimpleSimulationShader::uniform_dt; - GLuint SimpleSimulationShader::uniform_level; - GLuint SimpleSimulationShader::uniform_size_increase_factor; + GLuint SimpleSimulationShader::Program; + GLuint SimpleSimulationShader::attrib_position; + GLuint SimpleSimulationShader::attrib_velocity; + GLuint SimpleSimulationShader::attrib_lifetime; + GLuint SimpleSimulationShader::attrib_initial_position; + GLuint SimpleSimulationShader::attrib_initial_velocity; + GLuint SimpleSimulationShader::attrib_initial_lifetime; + GLuint SimpleSimulationShader::attrib_size; + GLuint SimpleSimulationShader::attrib_initial_size; + GLuint SimpleSimulationShader::uniform_sourcematrix; + GLuint SimpleSimulationShader::uniform_dt; + GLuint SimpleSimulationShader::uniform_level; + GLuint SimpleSimulationShader::uniform_size_increase_factor; - void SimpleSimulationShader::init() - { - const char *varyings[] = { - "new_particle_position", - "new_lifetime", - "new_particle_velocity", - "new_size", - }; - Program = LoadTFBProgram(file_manager->getAsset("shaders/pointemitter.vert").c_str(), varyings, 4); + void SimpleSimulationShader::init() + { + const char *varyings[] = { + "new_particle_position", + "new_lifetime", + "new_particle_velocity", + "new_size", + }; + Program = LoadTFBProgram(file_manager->getAsset("shaders/pointemitter.vert").c_str(), varyings, 4); - uniform_dt = glGetUniformLocation(Program, "dt"); - uniform_sourcematrix = glGetUniformLocation(Program, "sourcematrix"); - uniform_level = glGetUniformLocation(Program, "level"); - uniform_size_increase_factor = glGetUniformLocation(Program, "size_increase_factor"); + uniform_dt = glGetUniformLocation(Program, "dt"); + uniform_sourcematrix = glGetUniformLocation(Program, "sourcematrix"); + uniform_level = glGetUniformLocation(Program, "level"); + uniform_size_increase_factor = glGetUniformLocation(Program, "size_increase_factor"); - attrib_position = glGetAttribLocation(Program, "particle_position"); - attrib_lifetime = glGetAttribLocation(Program, "lifetime"); - attrib_velocity = glGetAttribLocation(Program, "particle_velocity"); - attrib_size = glGetAttribLocation(Program, "size"); - attrib_initial_position = glGetAttribLocation(Program, "particle_position_initial"); - attrib_initial_lifetime = glGetAttribLocation(Program, "lifetime_initial"); - attrib_initial_velocity = glGetAttribLocation(Program, "particle_velocity_initial"); - attrib_initial_size = glGetAttribLocation(Program, "size_initial"); - } + attrib_position = glGetAttribLocation(Program, "particle_position"); + attrib_lifetime = glGetAttribLocation(Program, "lifetime"); + attrib_velocity = glGetAttribLocation(Program, "particle_velocity"); + attrib_size = glGetAttribLocation(Program, "size"); + attrib_initial_position = glGetAttribLocation(Program, "particle_position_initial"); + attrib_initial_lifetime = glGetAttribLocation(Program, "lifetime_initial"); + attrib_initial_velocity = glGetAttribLocation(Program, "particle_velocity_initial"); + attrib_initial_size = glGetAttribLocation(Program, "size_initial"); + } - GLuint HeightmapSimulationShader::Program; - GLuint HeightmapSimulationShader::attrib_position; - GLuint HeightmapSimulationShader::attrib_velocity; - GLuint HeightmapSimulationShader::attrib_lifetime; - GLuint HeightmapSimulationShader::attrib_initial_position; - GLuint HeightmapSimulationShader::attrib_initial_velocity; - GLuint HeightmapSimulationShader::attrib_initial_lifetime; - GLuint HeightmapSimulationShader::attrib_size; - GLuint HeightmapSimulationShader::attrib_initial_size; - GLuint HeightmapSimulationShader::uniform_sourcematrix; - GLuint HeightmapSimulationShader::uniform_dt; - GLuint HeightmapSimulationShader::uniform_level; - GLuint HeightmapSimulationShader::uniform_size_increase_factor; - GLuint HeightmapSimulationShader::uniform_track_x; - GLuint HeightmapSimulationShader::uniform_track_z; - GLuint HeightmapSimulationShader::uniform_track_x_len; - GLuint HeightmapSimulationShader::uniform_track_z_len; - GLuint HeightmapSimulationShader::uniform_heightmap; + GLuint HeightmapSimulationShader::Program; + GLuint HeightmapSimulationShader::attrib_position; + GLuint HeightmapSimulationShader::attrib_velocity; + GLuint HeightmapSimulationShader::attrib_lifetime; + GLuint HeightmapSimulationShader::attrib_initial_position; + GLuint HeightmapSimulationShader::attrib_initial_velocity; + GLuint HeightmapSimulationShader::attrib_initial_lifetime; + GLuint HeightmapSimulationShader::attrib_size; + GLuint HeightmapSimulationShader::attrib_initial_size; + GLuint HeightmapSimulationShader::uniform_sourcematrix; + GLuint HeightmapSimulationShader::uniform_dt; + GLuint HeightmapSimulationShader::uniform_level; + GLuint HeightmapSimulationShader::uniform_size_increase_factor; + GLuint HeightmapSimulationShader::uniform_track_x; + GLuint HeightmapSimulationShader::uniform_track_z; + GLuint HeightmapSimulationShader::uniform_track_x_len; + GLuint HeightmapSimulationShader::uniform_track_z_len; + GLuint HeightmapSimulationShader::uniform_heightmap; - void HeightmapSimulationShader::init() - { - const char *varyings[] = { - "new_particle_position", - "new_lifetime", - "new_particle_velocity", - "new_size", - }; - Program = LoadTFBProgram(file_manager->getAsset("shaders/particlesimheightmap.vert").c_str(), varyings, 4); + void HeightmapSimulationShader::init() + { + const char *varyings[] = { + "new_particle_position", + "new_lifetime", + "new_particle_velocity", + "new_size", + }; + Program = LoadTFBProgram(file_manager->getAsset("shaders/particlesimheightmap.vert").c_str(), varyings, 4); - uniform_dt = glGetUniformLocation(Program, "dt"); - uniform_sourcematrix = glGetUniformLocation(Program, "sourcematrix"); - uniform_level = glGetUniformLocation(Program, "level"); - uniform_size_increase_factor = glGetUniformLocation(Program, "size_increase_factor"); + uniform_dt = glGetUniformLocation(Program, "dt"); + uniform_sourcematrix = glGetUniformLocation(Program, "sourcematrix"); + uniform_level = glGetUniformLocation(Program, "level"); + uniform_size_increase_factor = glGetUniformLocation(Program, "size_increase_factor"); - attrib_position = glGetAttribLocation(Program, "particle_position"); - attrib_lifetime = glGetAttribLocation(Program, "lifetime"); - attrib_velocity = glGetAttribLocation(Program, "particle_velocity"); - attrib_size = glGetAttribLocation(Program, "size"); - attrib_initial_position = glGetAttribLocation(Program, "particle_position_initial"); - attrib_initial_lifetime = glGetAttribLocation(Program, "lifetime_initial"); - attrib_initial_velocity = glGetAttribLocation(Program, "particle_velocity_initial"); - attrib_initial_size = glGetAttribLocation(Program, "size_initial"); + attrib_position = glGetAttribLocation(Program, "particle_position"); + attrib_lifetime = glGetAttribLocation(Program, "lifetime"); + attrib_velocity = glGetAttribLocation(Program, "particle_velocity"); + attrib_size = glGetAttribLocation(Program, "size"); + attrib_initial_position = glGetAttribLocation(Program, "particle_position_initial"); + attrib_initial_lifetime = glGetAttribLocation(Program, "lifetime_initial"); + attrib_initial_velocity = glGetAttribLocation(Program, "particle_velocity_initial"); + attrib_initial_size = glGetAttribLocation(Program, "size_initial"); - uniform_heightmap = glGetUniformLocation(Program, "heightmap"); - uniform_track_x = glGetUniformLocation(Program, "track_x"); - uniform_track_x_len = glGetUniformLocation(Program, "track_x_len"); - uniform_track_z = glGetUniformLocation(Program, "track_z"); - uniform_track_z_len = glGetUniformLocation(Program, "track_z_len"); - } + uniform_heightmap = glGetUniformLocation(Program, "heightmap"); + uniform_track_x = glGetUniformLocation(Program, "track_x"); + uniform_track_x_len = glGetUniformLocation(Program, "track_x_len"); + uniform_track_z = glGetUniformLocation(Program, "track_z"); + uniform_track_z_len = glGetUniformLocation(Program, "track_z_len"); + } - GLuint SimpleParticleRender::Program; - GLuint SimpleParticleRender::attrib_pos; - GLuint SimpleParticleRender::attrib_lf; - GLuint SimpleParticleRender::attrib_quadcorner; - GLuint SimpleParticleRender::attrib_texcoord; - GLuint SimpleParticleRender::attrib_sz; - GLuint SimpleParticleRender::uniform_matrix; - GLuint SimpleParticleRender::uniform_viewmatrix; - GLuint SimpleParticleRender::uniform_tex; - GLuint SimpleParticleRender::uniform_dtex; - GLuint SimpleParticleRender::uniform_screen; - GLuint SimpleParticleRender::uniform_invproj; + GLuint SimpleParticleRender::Program; + GLuint SimpleParticleRender::attrib_pos; + GLuint SimpleParticleRender::attrib_lf; + GLuint SimpleParticleRender::attrib_quadcorner; + GLuint SimpleParticleRender::attrib_texcoord; + GLuint SimpleParticleRender::attrib_sz; + GLuint SimpleParticleRender::uniform_matrix; + GLuint SimpleParticleRender::uniform_viewmatrix; + GLuint SimpleParticleRender::uniform_tex; + GLuint SimpleParticleRender::uniform_dtex; + GLuint SimpleParticleRender::uniform_screen; + GLuint SimpleParticleRender::uniform_invproj; GLuint SimpleParticleRender::uniform_color_from; GLuint SimpleParticleRender::uniform_color_to; - void SimpleParticleRender::init() - { + void SimpleParticleRender::init() + { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/particle.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/particle.frag").c_str()); - attrib_pos = glGetAttribLocation(Program, "position"); - attrib_sz = glGetAttribLocation(Program, "size"); - attrib_lf = glGetAttribLocation(Program, "lifetime"); - attrib_quadcorner = glGetAttribLocation(Program, "quadcorner"); - attrib_texcoord = glGetAttribLocation(Program, "texcoord"); + attrib_pos = glGetAttribLocation(Program, "position"); + attrib_sz = glGetAttribLocation(Program, "size"); + attrib_lf = glGetAttribLocation(Program, "lifetime"); + attrib_quadcorner = glGetAttribLocation(Program, "quadcorner"); + attrib_texcoord = glGetAttribLocation(Program, "texcoord"); - uniform_matrix = glGetUniformLocation(Program, "ProjectionMatrix"); - uniform_viewmatrix = glGetUniformLocation(Program, "ViewMatrix"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_invproj = glGetUniformLocation(Program, "invproj"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); + uniform_matrix = glGetUniformLocation(Program, "ProjectionMatrix"); + uniform_viewmatrix = glGetUniformLocation(Program, "ViewMatrix"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_invproj = glGetUniformLocation(Program, "invproj"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); uniform_color_from = glGetUniformLocation(Program, "color_from"); assert(uniform_color_from != -1); uniform_color_to = glGetUniformLocation(Program, "color_to"); assert(uniform_color_to != -1); - } + } - void SimpleParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, + void SimpleParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_dtex, const ParticleSystemProxy* particle_system) - { - glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); - glUniform2f(uniform_screen, width, height); - glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer()); - glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer()); - glUniform1i(uniform_tex, TU_tex); - glUniform1i(uniform_dtex, TU_dtex); + { + glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); + glUniform2f(uniform_screen, width, height); + glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer()); + glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer()); + glUniform1i(uniform_tex, TU_tex); + glUniform1i(uniform_dtex, TU_dtex); const float* color_from = particle_system->getColorFrom(); const float* color_to = particle_system->getColorTo(); glUniform3f(uniform_color_from, color_from[0], color_from[1], color_from[2]); glUniform3f(uniform_color_to, color_to[0], color_to[1], color_to[2]); - } + } - GLuint FlipParticleRender::Program; - GLuint FlipParticleRender::attrib_pos; - GLuint FlipParticleRender::attrib_lf; - GLuint FlipParticleRender::attrib_quadcorner; - GLuint FlipParticleRender::attrib_texcoord; - GLuint FlipParticleRender::attrib_sz; - GLuint FlipParticleRender::attrib_rotationvec; - GLuint FlipParticleRender::attrib_anglespeed; - GLuint FlipParticleRender::uniform_matrix; - GLuint FlipParticleRender::uniform_viewmatrix; - GLuint FlipParticleRender::uniform_tex; - GLuint FlipParticleRender::uniform_dtex; - GLuint FlipParticleRender::uniform_screen; - GLuint FlipParticleRender::uniform_invproj; + GLuint FlipParticleRender::Program; + GLuint FlipParticleRender::attrib_pos; + GLuint FlipParticleRender::attrib_lf; + GLuint FlipParticleRender::attrib_quadcorner; + GLuint FlipParticleRender::attrib_texcoord; + GLuint FlipParticleRender::attrib_sz; + GLuint FlipParticleRender::attrib_rotationvec; + GLuint FlipParticleRender::attrib_anglespeed; + GLuint FlipParticleRender::uniform_matrix; + GLuint FlipParticleRender::uniform_viewmatrix; + GLuint FlipParticleRender::uniform_tex; + GLuint FlipParticleRender::uniform_dtex; + GLuint FlipParticleRender::uniform_screen; + GLuint FlipParticleRender::uniform_invproj; - void FlipParticleRender::init() - { - Program = LoadProgram( + void FlipParticleRender::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/flipparticle.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/particle.frag").c_str()); - attrib_pos = glGetAttribLocation(Program, "position"); - attrib_sz = glGetAttribLocation(Program, "size"); - attrib_lf = glGetAttribLocation(Program, "lifetime"); - attrib_quadcorner = glGetAttribLocation(Program, "quadcorner"); - attrib_texcoord = glGetAttribLocation(Program, "texcoord"); - attrib_anglespeed = glGetAttribLocation(Program, "anglespeed"); - attrib_rotationvec = glGetAttribLocation(Program, "rotationvec"); + attrib_pos = glGetAttribLocation(Program, "position"); + attrib_sz = glGetAttribLocation(Program, "size"); + attrib_lf = glGetAttribLocation(Program, "lifetime"); + attrib_quadcorner = glGetAttribLocation(Program, "quadcorner"); + attrib_texcoord = glGetAttribLocation(Program, "texcoord"); + attrib_anglespeed = glGetAttribLocation(Program, "anglespeed"); + attrib_rotationvec = glGetAttribLocation(Program, "rotationvec"); - uniform_matrix = glGetUniformLocation(Program, "ProjectionMatrix"); - uniform_viewmatrix = glGetUniformLocation(Program, "ViewMatrix"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_invproj = glGetUniformLocation(Program, "invproj"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - } + uniform_matrix = glGetUniformLocation(Program, "ProjectionMatrix"); + uniform_viewmatrix = glGetUniformLocation(Program, "ViewMatrix"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_invproj = glGetUniformLocation(Program, "invproj"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); + } - void FlipParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_dtex) - { - glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); - glUniform2f(uniform_screen, width, height); - glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer()); - glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer()); - glUniform1i(uniform_tex, TU_tex); - glUniform1i(uniform_dtex, TU_dtex); - } + void FlipParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_dtex) + { + glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); + glUniform2f(uniform_screen, width, height); + glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer()); + glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer()); + glUniform1i(uniform_tex, TU_tex); + glUniform1i(uniform_dtex, TU_dtex); + } } static GLuint createVAO(GLuint Program) { - GLuint vao; - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - GLuint attrib_position = glGetAttribLocation(Program, "Position"); - GLuint attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); - glBindVertexArray(0); - return vao; + GLuint vao; + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + GLuint attrib_position = glGetAttribLocation(Program, "Position"); + GLuint attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + return vao; } namespace FullScreenShader { - GLuint BloomShader::Program; - GLuint BloomShader::uniform_texture; - GLuint BloomShader::vao; - void BloomShader::init() - { - Program = LoadProgram( + GLuint BloomShader::Program; + GLuint BloomShader::uniform_texture; + GLuint BloomShader::vao; + void BloomShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getCIEXYZ.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bloom.frag").c_str()); - uniform_texture = glGetUniformLocation(Program, "tex"); - vao = createVAO(Program); - } + uniform_texture = glGetUniformLocation(Program, "tex"); + vao = createVAO(Program); + } void BloomShader::setUniforms(unsigned TU_tex) { glUniform1i(FullScreenShader::BloomShader::uniform_texture, TU_tex); } - GLuint BloomBlendShader::Program; - GLuint BloomBlendShader::uniform_texture; - GLuint BloomBlendShader::vao; - void BloomBlendShader::init() - { - Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), + GLuint BloomBlendShader::Program; + GLuint BloomBlendShader::uniform_texture; + GLuint BloomBlendShader::vao; + void BloomBlendShader::init() + { + Program = LoadProgram( + GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bloomblend.frag").c_str()); - uniform_texture = glGetUniformLocation(Program, "tex"); - vao = createVAO(Program); - } + uniform_texture = glGetUniformLocation(Program, "tex"); + vao = createVAO(Program); + } void BloomBlendShader::setUniforms(unsigned TU_tex) { glUniform1i(FullScreenShader::BloomShader::uniform_texture, TU_tex); } - GLuint ColorLevelShader::Program; - GLuint ColorLevelShader::uniform_tex; + GLuint ColorLevelShader::Program; + GLuint ColorLevelShader::uniform_tex; GLuint ColorLevelShader::uniform_logluminancetex; - GLuint ColorLevelShader::uniform_inlevel; - GLuint ColorLevelShader::uniform_outlevel; - GLuint ColorLevelShader::vao; + GLuint ColorLevelShader::uniform_inlevel; + GLuint ColorLevelShader::uniform_outlevel; + GLuint ColorLevelShader::vao; GLuint ColorLevelShader::uniform_invprojm; GLuint ColorLevelShader::uniform_dtex; - void ColorLevelShader::init() - { + void ColorLevelShader::init() + { 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/color_levels.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_tex = glGetUniformLocation(Program, "tex"); uniform_logluminancetex = glGetUniformLocation(Program, "logluminancetex"); uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_inlevel = glGetUniformLocation(Program, "inlevel"); - uniform_outlevel = glGetUniformLocation(Program, "outlevel"); + uniform_inlevel = glGetUniformLocation(Program, "inlevel"); + uniform_outlevel = glGetUniformLocation(Program, "outlevel"); uniform_invprojm = glGetUniformLocation(Program, "invprojm"); - vao = createVAO(Program); - } + vao = createVAO(Program); + } - GLuint SunLightShader::Program; - GLuint SunLightShader::uniform_ntex; - GLuint SunLightShader::uniform_dtex; - GLuint SunLightShader::uniform_direction; - GLuint SunLightShader::uniform_col; - GLuint SunLightShader::uniform_invproj; - GLuint SunLightShader::vao; + GLuint SunLightShader::Program; + GLuint SunLightShader::uniform_ntex; + GLuint SunLightShader::uniform_dtex; + GLuint SunLightShader::uniform_direction; + GLuint SunLightShader::uniform_col; + GLuint SunLightShader::uniform_invproj; + GLuint SunLightShader::vao; - void SunLightShader::init() - { + void SunLightShader::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/sunlight.frag").c_str()); - uniform_ntex = glGetUniformLocation(Program, "ntex"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_direction = glGetUniformLocation(Program, "direction"); - uniform_col = glGetUniformLocation(Program, "col"); - uniform_invproj = glGetUniformLocation(Program, "invproj"); - vao = createVAO(Program); - } + uniform_ntex = glGetUniformLocation(Program, "ntex"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); + uniform_direction = glGetUniformLocation(Program, "direction"); + uniform_col = glGetUniformLocation(Program, "col"); + uniform_invproj = glGetUniformLocation(Program, "invproj"); + vao = createVAO(Program); + } - void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex) - { - glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); - 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); - } + void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex) + { + glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); + 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; @@ -2112,61 +2124,61 @@ namespace FullScreenShader delete[] tmp; } - GLuint Gaussian6HBlurShader::Program; - GLuint Gaussian6HBlurShader::uniform_tex; - GLuint Gaussian6HBlurShader::uniform_pixel; - GLuint Gaussian6HBlurShader::vao; - void Gaussian6HBlurShader::init() - { - Program = LoadProgram( + GLuint Gaussian6HBlurShader::Program; + GLuint Gaussian6HBlurShader::uniform_tex; + GLuint Gaussian6HBlurShader::uniform_pixel; + GLuint Gaussian6HBlurShader::vao; + void Gaussian6HBlurShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/gaussian6h.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_pixel = glGetUniformLocation(Program, "pixel"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + vao = createVAO(Program); + } - GLuint Gaussian3HBlurShader::Program; - GLuint Gaussian3HBlurShader::uniform_tex; - GLuint Gaussian3HBlurShader::uniform_pixel; - GLuint Gaussian3HBlurShader::vao; - void Gaussian3HBlurShader::init() - { - Program = LoadProgram( + GLuint Gaussian3HBlurShader::Program; + GLuint Gaussian3HBlurShader::uniform_tex; + GLuint Gaussian3HBlurShader::uniform_pixel; + GLuint Gaussian3HBlurShader::vao; + void Gaussian3HBlurShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/gaussian3h.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_pixel = glGetUniformLocation(Program, "pixel"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + vao = createVAO(Program); + } - GLuint Gaussian6VBlurShader::Program; - GLuint Gaussian6VBlurShader::uniform_tex; - GLuint Gaussian6VBlurShader::uniform_pixel; - GLuint Gaussian6VBlurShader::vao; - void Gaussian6VBlurShader::init() - { - Program = LoadProgram( + GLuint Gaussian6VBlurShader::Program; + GLuint Gaussian6VBlurShader::uniform_tex; + GLuint Gaussian6VBlurShader::uniform_pixel; + GLuint Gaussian6VBlurShader::vao; + void Gaussian6VBlurShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/gaussian6v.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_pixel = glGetUniformLocation(Program, "pixel"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + vao = createVAO(Program); + } - GLuint Gaussian3VBlurShader::Program; - GLuint Gaussian3VBlurShader::uniform_tex; - GLuint Gaussian3VBlurShader::uniform_pixel; - GLuint Gaussian3VBlurShader::vao; - void Gaussian3VBlurShader::init() - { - Program = LoadProgram( + GLuint Gaussian3VBlurShader::Program; + GLuint Gaussian3VBlurShader::uniform_tex; + GLuint Gaussian3VBlurShader::uniform_pixel; + GLuint Gaussian3VBlurShader::vao; + void Gaussian3VBlurShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/gaussian3v.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_pixel = glGetUniformLocation(Program, "pixel"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + vao = createVAO(Program); + } GLuint PenumbraHShader::Program; GLuint PenumbraHShader::uniform_tex; @@ -2216,7 +2228,7 @@ namespace FullScreenShader void ShadowGenShader::init() { Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), + GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/shadowgen.frag").c_str()); uniform_halft = glGetUniformLocation(Program, "halft"); uniform_quarter = glGetUniformLocation(Program, "quarter"); @@ -2231,217 +2243,217 @@ namespace FullScreenShader glUniform1i(uniform_height, TU_height); } - GLuint PassThroughShader::Program; - GLuint PassThroughShader::uniform_texture; - GLuint PassThroughShader::vao; - void PassThroughShader::init() - { - Program = LoadProgram( + GLuint PassThroughShader::Program; + GLuint PassThroughShader::uniform_texture; + GLuint PassThroughShader::vao; + void PassThroughShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/texturedquad.frag").c_str()); - uniform_texture = glGetUniformLocation(Program, "texture"); - vao = createVAO(Program); - } + uniform_texture = glGetUniformLocation(Program, "texture"); + vao = createVAO(Program); + } - GLuint GlowShader::Program; - GLuint GlowShader::uniform_tex; - GLuint GlowShader::vao; - void GlowShader::init() - { - Program = LoadProgram( + GLuint GlowShader::Program; + GLuint GlowShader::uniform_tex; + GLuint GlowShader::vao; + void GlowShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/glow.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + vao = createVAO(Program); + } - GLuint SSAOShader::Program; - GLuint SSAOShader::uniform_ntex; - GLuint SSAOShader::uniform_dtex; - GLuint SSAOShader::uniform_noise_texture; - GLuint SSAOShader::uniform_invprojm; - GLuint SSAOShader::uniform_projm; - GLuint SSAOShader::uniform_samplePoints; - GLuint SSAOShader::vao; - float SSAOShader::SSAOSamples[64]; + GLuint SSAOShader::Program; + GLuint SSAOShader::uniform_ntex; + GLuint SSAOShader::uniform_dtex; + GLuint SSAOShader::uniform_noise_texture; + GLuint SSAOShader::uniform_invprojm; + GLuint SSAOShader::uniform_projm; + GLuint SSAOShader::uniform_samplePoints; + GLuint SSAOShader::vao; + float SSAOShader::SSAOSamples[64]; - void SSAOShader::init() - { - Program = LoadProgram( + void SSAOShader::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/ssao.frag").c_str()); - uniform_ntex = glGetUniformLocation(Program, "ntex"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_noise_texture = glGetUniformLocation(Program, "noise_texture"); - uniform_invprojm = glGetUniformLocation(Program, "invprojm"); - uniform_projm = glGetUniformLocation(Program, "projm"); - uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]"); - vao = createVAO(Program); + uniform_ntex = glGetUniformLocation(Program, "ntex"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); + uniform_noise_texture = glGetUniformLocation(Program, "noise_texture"); + uniform_invprojm = glGetUniformLocation(Program, "invprojm"); + uniform_projm = glGetUniformLocation(Program, "projm"); + uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]"); + vao = createVAO(Program); - // SSAOSamples[4 * i] and SSAOSamples[4 * i + 1] can be negative + // 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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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; + 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; + // 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); + // 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; - }*/ - } + // 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::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise) - { - glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_invprojm, 1, GL_FALSE, invprojm.pointer()); - glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_projm, 1, GL_FALSE, projm.pointer()); - glUniform4fv(FullScreenShader::SSAOShader::uniform_samplePoints, 16, FullScreenShader::SSAOShader::SSAOSamples); + void SSAOShader::setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise) + { + glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_invprojm, 1, GL_FALSE, invprojm.pointer()); + glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_projm, 1, GL_FALSE, projm.pointer()); + glUniform4fv(FullScreenShader::SSAOShader::uniform_samplePoints, 16, FullScreenShader::SSAOShader::SSAOSamples); - glUniform1i(FullScreenShader::SSAOShader::uniform_ntex, TU_ntex); - glUniform1i(FullScreenShader::SSAOShader::uniform_dtex, TU_dtex); - glUniform1i(FullScreenShader::SSAOShader::uniform_noise_texture, TU_noise); - } + glUniform1i(FullScreenShader::SSAOShader::uniform_ntex, TU_ntex); + glUniform1i(FullScreenShader::SSAOShader::uniform_dtex, TU_dtex); + glUniform1i(FullScreenShader::SSAOShader::uniform_noise_texture, TU_noise); + } - GLuint FogShader::Program; - GLuint FogShader::uniform_tex; - GLuint FogShader::uniform_fogmax; - GLuint FogShader::uniform_startH; - GLuint FogShader::uniform_endH; - GLuint FogShader::uniform_start; - GLuint FogShader::uniform_end; - GLuint FogShader::uniform_col; - GLuint FogShader::uniform_ipvmat; - GLuint FogShader::vao; + GLuint FogShader::Program; + GLuint FogShader::uniform_tex; + GLuint FogShader::uniform_fogmax; + GLuint FogShader::uniform_startH; + GLuint FogShader::uniform_endH; + GLuint FogShader::uniform_start; + GLuint FogShader::uniform_end; + GLuint FogShader::uniform_col; + GLuint FogShader::uniform_ipvmat; + GLuint FogShader::vao; - void FogShader::init() - { - Program = LoadProgram( + void FogShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/fog.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_fogmax = glGetUniformLocation(Program, "fogmax"); - uniform_startH = glGetUniformLocation(Program, "startH"); - uniform_endH = glGetUniformLocation(Program, "endH"); - uniform_start = glGetUniformLocation(Program, "start"); - uniform_end = glGetUniformLocation(Program, "end"); - uniform_col = glGetUniformLocation(Program, "col"); - uniform_ipvmat = glGetUniformLocation(Program, "ipvmat"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_fogmax = glGetUniformLocation(Program, "fogmax"); + uniform_startH = glGetUniformLocation(Program, "startH"); + uniform_endH = glGetUniformLocation(Program, "endH"); + uniform_start = glGetUniformLocation(Program, "start"); + uniform_end = glGetUniformLocation(Program, "end"); + uniform_col = glGetUniformLocation(Program, "col"); + uniform_ipvmat = glGetUniformLocation(Program, "ipvmat"); + vao = createVAO(Program); + } - void FogShader::setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex) - { - glUniform1f(uniform_fogmax, fogmax); - glUniform1f(uniform_startH, startH); - glUniform1f(uniform_endH, endH); - glUniform1f(uniform_start, start); - glUniform1f(uniform_end, end); - glUniform3f(uniform_col, col.X, col.Y, col.Z); - glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer()); - glUniform1i(uniform_tex, TU_ntex); - } + void FogShader::setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex) + { + glUniform1f(uniform_fogmax, fogmax); + glUniform1f(uniform_startH, startH); + glUniform1f(uniform_endH, endH); + glUniform1f(uniform_start, start); + glUniform1f(uniform_end, end); + glUniform3f(uniform_col, col.X, col.Y, col.Z); + glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer()); + glUniform1i(uniform_tex, TU_ntex); + } GLuint MotionBlurShader::Program; GLuint MotionBlurShader::uniform_boost_amount; @@ -2608,47 +2620,47 @@ namespace FullScreenShader namespace UIShader { - GLuint TextureRectShader::Program; - GLuint TextureRectShader::attrib_position; - GLuint TextureRectShader::attrib_texcoord; - GLuint TextureRectShader::uniform_tex; - GLuint TextureRectShader::uniform_center; - GLuint TextureRectShader::uniform_size; - GLuint TextureRectShader::uniform_texcenter; - GLuint TextureRectShader::uniform_texsize; - GLuint TextureRectShader::vao; + GLuint TextureRectShader::Program; + GLuint TextureRectShader::attrib_position; + GLuint TextureRectShader::attrib_texcoord; + GLuint TextureRectShader::uniform_tex; + GLuint TextureRectShader::uniform_center; + GLuint TextureRectShader::uniform_size; + GLuint TextureRectShader::uniform_texcenter; + GLuint TextureRectShader::uniform_texsize; + GLuint TextureRectShader::vao; - void TextureRectShader::init() - { - Program = LoadProgram( + void TextureRectShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/texturedquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/texturedquad.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "position"); - attrib_texcoord = glGetAttribLocation(Program, "texcoord"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_center = glGetUniformLocation(Program, "center"); - uniform_size = glGetUniformLocation(Program, "size"); - uniform_texcenter = glGetUniformLocation(Program, "texcenter"); - uniform_texsize = glGetUniformLocation(Program, "texsize"); - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); - glBindVertexArray(0); - } + attrib_position = glGetAttribLocation(Program, "position"); + attrib_texcoord = glGetAttribLocation(Program, "texcoord"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_center = glGetUniformLocation(Program, "center"); + uniform_size = glGetUniformLocation(Program, "size"); + uniform_texcenter = glGetUniformLocation(Program, "texcenter"); + uniform_texsize = glGetUniformLocation(Program, "texsize"); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); + glBindVertexArray(0); + } - void TextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex) - { - glUniform1i(uniform_tex, TU_tex); - glUniform2f(uniform_center, center_pos_x, center_pos_y); - glUniform2f(uniform_size, width, height); - glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y); - glUniform2f(uniform_texsize, tex_width, tex_height); - } + void TextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex) + { + glUniform1i(uniform_tex, TU_tex); + glUniform2f(uniform_center, center_pos_x, center_pos_y); + glUniform2f(uniform_size, width, height); + glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y); + glUniform2f(uniform_texsize, tex_width, tex_height); + } GLuint UniformColoredTextureRectShader::Program; GLuint UniformColoredTextureRectShader::attrib_position; @@ -2695,90 +2707,90 @@ namespace UIShader glUniform4i(uniform_color, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); } - GLuint ColoredTextureRectShader::Program; - GLuint ColoredTextureRectShader::attrib_position; - GLuint ColoredTextureRectShader::attrib_texcoord; - GLuint ColoredTextureRectShader::attrib_color; - GLuint ColoredTextureRectShader::uniform_tex; - GLuint ColoredTextureRectShader::uniform_center; - GLuint ColoredTextureRectShader::uniform_size; - GLuint ColoredTextureRectShader::uniform_texcenter; - GLuint ColoredTextureRectShader::uniform_texsize; - GLuint ColoredTextureRectShader::colorvbo; - GLuint ColoredTextureRectShader::vao; + GLuint ColoredTextureRectShader::Program; + GLuint ColoredTextureRectShader::attrib_position; + GLuint ColoredTextureRectShader::attrib_texcoord; + GLuint ColoredTextureRectShader::attrib_color; + GLuint ColoredTextureRectShader::uniform_tex; + GLuint ColoredTextureRectShader::uniform_center; + GLuint ColoredTextureRectShader::uniform_size; + GLuint ColoredTextureRectShader::uniform_texcenter; + GLuint ColoredTextureRectShader::uniform_texsize; + GLuint ColoredTextureRectShader::colorvbo; + GLuint ColoredTextureRectShader::vao; - void ColoredTextureRectShader::init() - { + void ColoredTextureRectShader::init() + { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/colortexturedquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/colortexturedquad.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "position"); - attrib_texcoord = glGetAttribLocation(Program, "texcoord"); - attrib_color = glGetAttribLocation(Program, "color"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_center = glGetUniformLocation(Program, "center"); - uniform_size = glGetUniformLocation(Program, "size"); - uniform_texcenter = glGetUniformLocation(Program, "texcenter"); - uniform_texsize = glGetUniformLocation(Program, "texsize"); - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glEnableVertexAttribArray(attrib_color); - glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); - const unsigned quad_color[] = { - 0, 0, 0, 255, - 255, 0, 0, 255, - 0, 255, 0, 255, - 0, 0, 255, 255, - }; - glGenBuffers(1, &colorvbo); - glBindBuffer(GL_ARRAY_BUFFER, colorvbo); - glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(unsigned), quad_color, GL_DYNAMIC_DRAW); - glVertexAttribIPointer(attrib_color, 4, GL_UNSIGNED_INT, 4 * sizeof(unsigned), 0); - glBindVertexArray(0); - } + attrib_position = glGetAttribLocation(Program, "position"); + attrib_texcoord = glGetAttribLocation(Program, "texcoord"); + attrib_color = glGetAttribLocation(Program, "color"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_center = glGetUniformLocation(Program, "center"); + uniform_size = glGetUniformLocation(Program, "size"); + uniform_texcenter = glGetUniformLocation(Program, "texcenter"); + uniform_texsize = glGetUniformLocation(Program, "texsize"); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glEnableVertexAttribArray(attrib_color); + glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); + const unsigned quad_color[] = { + 0, 0, 0, 255, + 255, 0, 0, 255, + 0, 255, 0, 255, + 0, 0, 255, 255, + }; + glGenBuffers(1, &colorvbo); + glBindBuffer(GL_ARRAY_BUFFER, colorvbo); + glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(unsigned), quad_color, GL_DYNAMIC_DRAW); + glVertexAttribIPointer(attrib_color, 4, GL_UNSIGNED_INT, 4 * sizeof(unsigned), 0); + glBindVertexArray(0); + } - void ColoredTextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex) - { - glUniform1i(uniform_tex, TU_tex); - glUniform2f(uniform_center, center_pos_x, center_pos_y); - glUniform2f(uniform_size, width, height); - glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y); - glUniform2f(uniform_texsize, tex_width, tex_height); - } + void ColoredTextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex) + { + glUniform1i(uniform_tex, TU_tex); + glUniform2f(uniform_center, center_pos_x, center_pos_y); + glUniform2f(uniform_size, width, height); + glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y); + glUniform2f(uniform_texsize, tex_width, tex_height); + } - GLuint ColoredRectShader::Program; - GLuint ColoredRectShader::attrib_position; - GLuint ColoredRectShader::uniform_center; - GLuint ColoredRectShader::uniform_size; - GLuint ColoredRectShader::uniform_color; - GLuint ColoredRectShader::vao; + GLuint ColoredRectShader::Program; + GLuint ColoredRectShader::attrib_position; + GLuint ColoredRectShader::uniform_center; + GLuint ColoredRectShader::uniform_size; + GLuint ColoredRectShader::uniform_color; + GLuint ColoredRectShader::vao; - void ColoredRectShader::init() - { - Program = LoadProgram( + void ColoredRectShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/coloredquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/coloredquad.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "position"); - uniform_color = glGetUniformLocation(Program, "color"); - uniform_center = glGetUniformLocation(Program, "center"); - uniform_size = glGetUniformLocation(Program, "size"); - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glEnableVertexAttribArray(attrib_position); - glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glBindVertexArray(0); - } + attrib_position = glGetAttribLocation(Program, "position"); + uniform_color = glGetUniformLocation(Program, "color"); + uniform_center = glGetUniformLocation(Program, "center"); + uniform_size = glGetUniformLocation(Program, "size"); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glEnableVertexAttribArray(attrib_position); + glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glBindVertexArray(0); + } - void ColoredRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, const video::SColor &color) - { - glUniform2f(uniform_center, center_pos_x, center_pos_y); - glUniform2f(uniform_size, width, height); - glUniform4i(uniform_color, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); - } + void ColoredRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, const video::SColor &color) + { + glUniform2f(uniform_center, center_pos_x, center_pos_y); + glUniform2f(uniform_size, width, height); + glUniform4i(uniform_color, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); + } } diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index a9f913aa0..093780f25 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -39,10 +39,10 @@ class ObjectPass1Shader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord, attrib_normal; - static GLuint uniform_MVP, uniform_TIMV, uniform_tex; + static GLuint uniform_MM, uniform_IMM, uniform_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_tex); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_tex); }; class ObjectRefPass1Shader @@ -50,10 +50,10 @@ class ObjectRefPass1Shader public: static GLuint Program; static GLuint attrib_position, attrib_normal, attrib_texcoord; - static GLuint uniform_MVP, uniform_TM, uniform_TIMV, uniform_tex; + static GLuint uniform_MM, uniform_TM, uniform_IMM, uniform_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix, unsigned TU_texture); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_texture); }; class GrassPass1Shader @@ -72,10 +72,10 @@ class NormalMapShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord, attrib_tangent, attrib_bitangent; - static GLuint uniform_MVP, uniform_TIMV, uniform_normalMap; + static GLuint uniform_MM, uniform_IMM, uniform_normalMap; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_normalMap); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_normalMap); }; class InstancedObjectPass1Shader @@ -116,11 +116,11 @@ class ObjectPass2Shader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord; - static GLuint uniform_MVP, uniform_TM, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_TM, uniform_screen, uniform_ambient; static GLuint TU_Albedo; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix); }; class InstancedObjectPass2Shader @@ -152,11 +152,11 @@ class DetailledObjectPass2Shader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord; - static GLuint uniform_MVP, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_screen, uniform_ambient; static GLuint TU_Albedo, TU_detail; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix); }; class ObjectRimLimitShader @@ -164,11 +164,11 @@ class ObjectRimLimitShader public: static GLuint Program; static GLuint attrib_position, attrib_normal, attrib_texcoord; - static GLuint uniform_MVP, uniform_TIMV, uniform_TM, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_IMM, uniform_TM, uniform_screen, uniform_ambient; static GLuint TU_Albedo; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix); }; class UntexturedObjectShader @@ -176,10 +176,10 @@ class UntexturedObjectShader public: static GLuint Program; static GLuint attrib_position, attrib_color; - static GLuint uniform_MVP, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_screen, uniform_ambient; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix); }; class ObjectUnlitShader @@ -187,11 +187,11 @@ class ObjectUnlitShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord; - static GLuint uniform_MVP; + static GLuint uniform_MM; static GLuint TU_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix); }; class ObjectRefPass2Shader @@ -199,11 +199,11 @@ class ObjectRefPass2Shader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord; - static GLuint uniform_MVP, uniform_TM, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_TM, uniform_screen, uniform_ambient; static GLuint TU_Albedo; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix); }; class GrassPass2Shader @@ -235,11 +235,11 @@ class SphereMapShader public: static GLuint Program; static GLuint attrib_position, attrib_normal; - static GLuint uniform_MVP, uniform_TIMV, uniform_TVM, uniform_invproj, uniform_screen; + static GLuint uniform_MM, uniform_IMM, uniform_screen; static GLuint TU_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeViewMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &InvProj, const core::vector2df& screen); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::vector2df& screen); }; class SplattingShader @@ -247,11 +247,11 @@ class SplattingShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord; - static GLuint uniform_MVP, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_screen, uniform_ambient; static GLuint TU_tex_layout, TU_tex_detail0, TU_tex_detail1, TU_tex_detail2, TU_tex_detail3; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix); }; class CausticsShader @@ -403,11 +403,11 @@ class SkyboxShader public: static GLuint Program; static GLuint attrib_position; - static GLuint uniform_MVP, uniform_InvProjView, uniform_tex, uniform_screen; + static GLuint uniform_MM, uniform_tex, uniform_screen; static GLuint cubevao; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &InvProjView, const core::vector2df &screen, unsigned TU_tex); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &screen, unsigned TU_tex); }; } diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index 0a4e3352f..662db0701 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -145,19 +145,21 @@ void STKAnimatedMesh::render() { ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation); TransposeInverseModelView = computeTIMV(AbsoluteTransformation); + core::matrix4 invmodel; + AbsoluteTransformation.getInverse(invmodel); for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++) { GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_DEFAULT][i]); - GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedFPSM::MVPSet.push_back(AbsoluteTransformation); + GroupedFPSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++) { GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i]); - GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedFPSM::MVPSet.push_back(AbsoluteTransformation); + GroupedFPSM::TIMVSet.push_back(invmodel); } return; @@ -165,39 +167,42 @@ void STKAnimatedMesh::render() if (irr_driver->getPhase() == SOLID_LIT_PASS) { + core::matrix4 invmodel; + AbsoluteTransformation.getInverse(invmodel); + for (unsigned i = 0; i < ShadedMesh[SM_DEFAULT].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_DEFAULT][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_ALPHA_REF_TEXTURE][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < ShadedMesh[SM_RIMLIT].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_RIMLIT][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (GLMesh *mesh : ShadedMesh[SM_UNLIT]) { GroupedSM::MeshSet.push_back(mesh); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (GLMesh *mesh : ShadedMesh[SM_DETAILS]) { GroupedSM::MeshSet.push_back(mesh); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } return; diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 8afba6e83..d7fb19812 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -269,7 +269,7 @@ void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio glDrawElements(ptype, count, itype, 0); } -void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView) +void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelMatrix, const core::matrix4 &InverseModelMatrix) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; @@ -279,14 +279,14 @@ void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio assert(mesh.textures[1]); setTexture(0, mesh.textures[1], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - MeshShader::NormalMapShader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, 0); + MeshShader::NormalMapShader::setUniforms(ModelMatrix, InverseModelMatrix, 0); assert(mesh.vao_first_pass); glBindVertexArray(mesh.vao_first_pass); glDrawElements(ptype, count, itype, 0); } -void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView) +void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; @@ -306,7 +306,7 @@ void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionM glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } - MeshShader::SphereMapShader::setUniforms(ModelViewProjectionMatrix, irr_driver->getViewMatrix().getTransposed(), TransposeInverseModelView, irr_driver->getInvProjMatrix(), core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height)); + MeshShader::SphereMapShader::setUniforms(ModelMatrix, InverseModelMatrix, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height)); assert(mesh.vao_second_pass); glBindVertexArray(mesh.vao_second_pass); @@ -476,14 +476,14 @@ void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio glDrawElements(ptype, count, itype, 0); } -void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix) +void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelMatrix) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - MeshShader::UntexturedObjectShader::setUniforms(ModelViewProjectionMatrix); + MeshShader::UntexturedObjectShader::setUniforms(ModelMatrix); assert(mesh.vao_second_pass); glBindVertexArray(mesh.vao_second_pass); diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 919f41d18..5a53da7c8 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -90,7 +90,7 @@ template std::vector GroupedFPSM::TIMVSet; void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView); -void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView); +void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelMatrix, const core::matrix4 &InverseModelMatrix); void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix); void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, core::vector3df windDir); diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index 2af9c3495..676d9d75a 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -336,26 +336,28 @@ void STKMeshSceneNode::render() glDisable(GL_CULL_FACE); ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation); TransposeInverseModelView = computeTIMV(AbsoluteTransformation); + core::matrix4 invmodel; + AbsoluteTransformation.getInverse(invmodel); for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++) { GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_DEFAULT][i]); - GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedFPSM::MVPSet.push_back(AbsoluteTransformation); + GroupedFPSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++) { GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i]); - GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedFPSM::MVPSet.push_back(AbsoluteTransformation); + GroupedFPSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < GeometricMesh[FPSM_NORMAL_MAP].size(); i++) { GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_NORMAL_MAP][i]); - GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedFPSM::MVPSet.push_back(AbsoluteTransformation); + GroupedFPSM::TIMVSet.push_back(invmodel); } if (!GeometricMesh[FPSM_GRASS].empty()) @@ -373,54 +375,64 @@ void STKMeshSceneNode::render() if (reload_each_frame) glDisable(GL_CULL_FACE); + core::matrix4 invmodel; + AbsoluteTransformation.getInverse(invmodel); + for (unsigned i = 0; i < ShadedMesh[SM_DEFAULT].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_DEFAULT][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_ALPHA_REF_TEXTURE][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < ShadedMesh[SM_RIMLIT].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_RIMLIT][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < ShadedMesh[SM_SPHEREMAP].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_SPHEREMAP][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (GLMesh *mesh : ShadedMesh[SM_SPLATTING]) { GroupedSM::MeshSet.push_back(mesh); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (GLMesh *mesh : ShadedMesh[SM_UNLIT]) { GroupedSM::MeshSet.push_back(mesh); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (GLMesh *mesh : ShadedMesh[SM_DETAILS]) { GroupedSM::MeshSet.push_back(mesh); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); + } + + for (GLMesh *mesh : ShadedMesh[SM_UNTEXTURED]) + { + GroupedSM::MeshSet.push_back(mesh); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } if (!ShadedMesh[SM_GRASS].empty()) @@ -433,11 +445,6 @@ void STKMeshSceneNode::render() for (unsigned i = 0; i < ShadedMesh[SM_CAUSTICS].size(); i++) drawSolidPass2(*ShadedMesh[SM_CAUSTICS][i], SM_CAUSTICS); - if (!ShadedMesh[SM_UNTEXTURED].empty()) - glUseProgram(MeshShader::UntexturedObjectShader::Program); - for (unsigned i = 0; i < ShadedMesh[SM_UNTEXTURED].size(); i++) - drawSolidPass2(*ShadedMesh[SM_UNTEXTURED][i], SM_UNTEXTURED); - if (reload_each_frame) glEnable(GL_CULL_FACE); return;