Merge branch 'BatchedDrawCalls'

This commit is contained in:
Vincent Lejeune 2014-04-10 23:28:42 +02:00
commit cbc677febb
23 changed files with 1461 additions and 1327 deletions

View File

@ -1,6 +1,14 @@
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
uniform vec3 windDir;
uniform mat4 ViewProjectionMatrix;
uniform mat4 InverseViewMatrix;
in vec3 Origin;
in vec3 Orientation;
@ -21,7 +29,7 @@ void main()
{
mat4 ModelMatrix = getWorldMatrix(Origin + windDir * Color.r, Orientation, Scale);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin + windDir * Color.r, Orientation, Scale) * InverseViewMatrix);
gl_Position = ViewProjectionMatrix * ModelMatrix * vec4(Position, 1.);
gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
uv = Texcoord;
}

View File

@ -1,5 +1,11 @@
uniform mat4 ViewProjectionMatrix;
uniform mat4 InverseViewMatrix;
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
in vec3 Origin;
in vec3 Orientation;
@ -19,7 +25,7 @@ void main(void)
{
mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * InverseViewMatrix);
gl_Position = ViewProjectionMatrix * ModelMatrix * vec4(Position, 1.);
gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
uv = Texcoord;
}

View File

@ -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.;
}

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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.);
}

View File

@ -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.);

View File

@ -1,6 +1,10 @@
layout (std140) uniform MatrixesData
{
mat4 ViewProjectionMatrix[4];
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#if __VERSION__ >= 400
@ -20,7 +24,7 @@ void emitToLayer(int layerId)
for(int i=0; i<3; i++)
{
uv = tc[i];
gl_Position = ViewProjectionMatrix[layerId] * gl_in[i].gl_Position;
gl_Position = ShadowViewProjMatrixes[layerId] * gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();

View File

@ -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.);

View File

@ -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.);
}

View File

@ -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.);
}

View File

@ -229,6 +229,7 @@ GLuint LoadShader(const char * file, unsigned type)
sprintf(versionString, "#version %d\n", irr_driver->getGLSLVersion());
std::string Code = versionString;
std::ifstream Stream(file, std::ios::in);
Code += "//" + std::string(file) + "\n";
if (Stream.is_open())
{
std::string Line = "";

View File

@ -226,6 +226,8 @@ private:
void renderSolidSecondPass();
void renderTransparent();
void renderParticles();
void computeCameraMatrix(scene::ICameraSceneNode * const camnode,
Camera * const camera);
void renderShadows(//ShadowImportanceProvider * const sicb,
scene::ICameraSceneNode * const camnode,
//video::SOverrideMaterial &overridemat,

View File

@ -164,11 +164,9 @@ void IrrDriver::renderGLSL(float dt)
}*/
// Get Projection and view matrix
irr_driver->setPhase(SOLID_NORMAL_AND_DEPTH_PASS);
m_scene_manager->drawAll(scene::ESNRP_CAMERA);
irr_driver->setProjMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION));
irr_driver->setViewMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW));
irr_driver->genProjViewMatrix();
computeCameraMatrix(camnode, camera);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO);
// Fire up the MRT
PROFILER_PUSH_CPU_MARKER("- Solid Pass 1", 0xFF, 0x00, 0x00);
@ -424,8 +422,27 @@ void IrrDriver::renderSolidFirstPass()
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
irr_driver->setPhase(SOLID_NORMAL_AND_DEPTH_PASS);
GroupedFPSM<FPSM_DEFAULT>::reset();
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::reset();
GroupedFPSM<FPSM_NORMAL_MAP>::reset();
m_scene_manager->drawAll(scene::ESNRP_SOLID);
glUseProgram(MeshShader::ObjectPass1Shader::Program);
for (unsigned i = 0; i < GroupedFPSM<FPSM_DEFAULT>::MeshSet.size(); ++i)
{
drawObjectPass1(*GroupedFPSM<FPSM_DEFAULT>::MeshSet[i], GroupedFPSM<FPSM_DEFAULT>::MVPSet[i], GroupedFPSM<FPSM_DEFAULT>::TIMVSet[i]);
}
glUseProgram(MeshShader::ObjectRefPass1Shader::Program);
for (unsigned i = 0; i < GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet.size(); ++i)
{
drawObjectRefPass1(*GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet[i], GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MVPSet[i], GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::TIMVSet[i], GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet[i]->TextureMatrix);
}
glUseProgram(MeshShader::NormalMapShader::Program);
for (unsigned i = 0; i < GroupedFPSM<FPSM_NORMAL_MAP>::MeshSet.size(); ++i)
{
drawNormalPass(*GroupedFPSM<FPSM_NORMAL_MAP>::MeshSet[i], GroupedFPSM<FPSM_NORMAL_MAP>::MVPSet[i], GroupedFPSM<FPSM_NORMAL_MAP>::TIMVSet[i]);
}
}
void IrrDriver::renderSolidSecondPass()
@ -440,10 +457,51 @@ void IrrDriver::renderSolidSecondPass()
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
GroupedSM<SM_DEFAULT>::reset();
GroupedSM<SM_ALPHA_REF_TEXTURE>::reset();
GroupedSM<SM_RIMLIT>::reset();
GroupedSM<SM_SPHEREMAP>::reset();
GroupedSM<SM_SPLATTING>::reset();
GroupedSM<SM_UNLIT>::reset();
GroupedSM<SM_DETAILS>::reset();
GroupedSM<SM_UNTEXTURED>::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);
m_scene_manager->drawAll(scene::ESNRP_SOLID);
glUseProgram(MeshShader::ObjectPass2Shader::Program);
for (unsigned i = 0; i < GroupedSM<SM_DEFAULT>::MeshSet.size(); i++)
drawObjectPass2(*GroupedSM<SM_DEFAULT>::MeshSet[i], GroupedSM<SM_DEFAULT>::MVPSet[i], GroupedSM<SM_DEFAULT>::MeshSet[i]->TextureMatrix);
glUseProgram(MeshShader::ObjectRefPass2Shader::Program);
for (unsigned i = 0; i < GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet.size(); i++)
drawObjectRefPass2(*GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet[i], GroupedSM<SM_ALPHA_REF_TEXTURE>::MVPSet[i], GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet[i]->TextureMatrix);
glUseProgram(MeshShader::ObjectRimLimitShader::Program);
for (unsigned i = 0; i < GroupedSM<SM_RIMLIT>::MeshSet.size(); i++)
drawObjectRimLimit(*GroupedSM<SM_RIMLIT>::MeshSet[i], GroupedSM<SM_RIMLIT>::MVPSet[i], GroupedSM<SM_RIMLIT>::TIMVSet[i], GroupedSM<SM_RIMLIT>::MeshSet[i]->TextureMatrix);
glUseProgram(MeshShader::SphereMapShader::Program);
for (unsigned i = 0; i < GroupedSM<SM_SPHEREMAP>::MeshSet.size(); i++)
drawSphereMap(*GroupedSM<SM_SPHEREMAP>::MeshSet[i], GroupedSM<SM_SPHEREMAP>::MVPSet[i], GroupedSM<SM_SPHEREMAP>::TIMVSet[i]);
glUseProgram(MeshShader::SplattingShader::Program);
for (unsigned i = 0; i < GroupedSM<SM_SPLATTING>::MeshSet.size(); i++)
drawSplatting(*GroupedSM<SM_SPLATTING>::MeshSet[i], GroupedSM<SM_SPLATTING>::MVPSet[i]);
glUseProgram(MeshShader::ObjectUnlitShader::Program);
for (unsigned i = 0; i < GroupedSM<SM_UNLIT>::MeshSet.size(); i++)
drawObjectUnlit(*GroupedSM<SM_UNLIT>::MeshSet[i], GroupedSM<SM_UNLIT>::MVPSet[i]);
glUseProgram(MeshShader::DetailledObjectPass2Shader::Program);
for (unsigned i = 0; i < GroupedSM<SM_DETAILS>::MeshSet.size(); i++)
drawDetailledObjectPass2(*GroupedSM<SM_DETAILS>::MeshSet[i], GroupedSM<SM_DETAILS>::MVPSet[i]);
glUseProgram(MeshShader::UntexturedObjectShader::Program);
for (unsigned i = 0; i < GroupedSM<SM_UNTEXTURED>::MeshSet.size(); i++)
drawUntexturedObject(*GroupedSM<SM_UNTEXTURED>::MeshSet[i], GroupedSM<SM_UNTEXTURED>::MVPSet[i]);
}
void IrrDriver::renderTransparent()
@ -469,10 +527,8 @@ void IrrDriver::renderParticles()
m_scene_manager->drawAll(scene::ESNRP_TRANSPARENT_EFFECT);
}
void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb,
scene::ICameraSceneNode * const camnode,
//video::SOverrideMaterial &overridemat,
Camera * const camera)
void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode,
Camera * const camera)
{
m_scene_manager->setCurrentRendertime(scene::ESNRP_SOLID);
@ -556,6 +612,35 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb,
sun_ortho_matrix.push_back(getVideoDriver()->getTransform(video::ETS_PROJECTION) * getVideoDriver()->getTransform(video::ETS_VIEW));
}
assert(sun_ortho_matrix.size() == 4);
camnode->setNearValue(oldnear);
camnode->setFarValue(oldfar);
camnode->render();
camera->activate();
m_scene_manager->drawAll(scene::ESNRP_CAMERA);
irr_driver->setProjMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION));
irr_driver->setViewMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW));
irr_driver->genProjViewMatrix();
float *tmp = new float[16 * 8];
memcpy(tmp, irr_driver->getViewMatrix().pointer(), 16 * sizeof(float));
memcpy(&tmp[16], irr_driver->getProjMatrix().pointer(), 16 * sizeof(float));
memcpy(&tmp[32], irr_driver->getInvViewMatrix().pointer(), 16 * sizeof(float));
memcpy(&tmp[48], irr_driver->getInvProjMatrix().pointer(), 16 * sizeof(float));
size_t size = irr_driver->getShadowViewProj().size();
for (unsigned i = 0; i < size; i++)
memcpy(&tmp[16 * i + 64], irr_driver->getShadowViewProj()[i].pointer(), 16 * sizeof(float));
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO);
glBufferSubData(GL_UNIFORM_BUFFER, 0, 16 * 8 * sizeof(float), tmp);
delete tmp;
}
void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb,
scene::ICameraSceneNode * const camnode,
//video::SOverrideMaterial &overridemat,
Camera * const camera)
{
irr_driver->setPhase(SHADOW_PASS);
glDisable(GL_BLEND);
@ -566,25 +651,11 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb,
glClear(GL_DEPTH_BUFFER_BIT);
glDrawBuffer(GL_NONE);
size_t size = irr_driver->getShadowViewProj().size();
float *tmp = new float[16 * size];
for (unsigned i = 0; i < size; i++) {
memcpy(&tmp[16 * i], irr_driver->getShadowViewProj()[i].pointer(), 16 * sizeof(float));
}
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO);
glBufferSubData(GL_UNIFORM_BUFFER, 0, 16 * 4 * sizeof(float), tmp);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO);
delete tmp;
m_scene_manager->drawAll(scene::ESNRP_SOLID);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glCullFace(GL_BACK);
camnode->setNearValue(oldnear);
camnode->setFarValue(oldfar);
camnode->render();
camera->activate();
m_scene_manager->drawAll(scene::ESNRP_CAMERA);
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
@ -1262,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());
@ -1270,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);
@ -1279,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);
}

File diff suppressed because it is too large Load Diff

View File

@ -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
@ -83,10 +83,10 @@ class InstancedObjectPass1Shader
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_origin, attrib_orientation, attrib_scale;
static GLuint uniform_MP, uniform_VM, uniform_tex;
static GLuint uniform_tex;
static void init();
static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &ViewMatrix, unsigned TU_tex);
static void setUniforms(unsigned TU_tex);
};
class InstancedObjectRefPass1Shader
@ -94,10 +94,10 @@ class InstancedObjectRefPass1Shader
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_texcoord, attrib_origin, attrib_orientation, attrib_scale;
static GLuint uniform_MP, uniform_VM, uniform_tex;
static GLuint uniform_tex;
static void init();
static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &ViewMatrix, unsigned TU_tex);
static void setUniforms(unsigned TU_tex);
};
class InstancedGrassPass1Shader
@ -105,10 +105,10 @@ class InstancedGrassPass1Shader
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_origin, attrib_orientation, attrib_scale, attrib_color, attrib_texcoord;
static GLuint uniform_MP, uniform_IVM, uniform_windDir, uniform_tex;
static GLuint uniform_windDir, uniform_tex;
static void init();
static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &InverseViewMatrix, const core::vector3df &windDir, unsigned TU_tex);
static void setUniforms(const core::vector3df &windDir, unsigned TU_tex);
};
class ObjectPass2Shader
@ -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);
};
}

View File

@ -54,47 +54,6 @@ void STKAnimatedMesh::setMesh(scene::IAnimatedMesh* mesh)
CAnimatedMeshSceneNode::setMesh(mesh);
}
void STKAnimatedMesh::drawSolidPass1(const GLMesh &mesh, GeometricMaterial type)
{
switch (type)
{
case FPSM_ALPHA_REF_TEXTURE:
drawObjectRefPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, mesh.TextureMatrix);
break;
case FPSM_DEFAULT:
drawObjectPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
break;
default:
assert(0 && "Wrong geometric material");
break;
}
}
void STKAnimatedMesh::drawSolidPass2(const GLMesh &mesh, ShadedMaterial type)
{
switch (type)
{
case SM_ALPHA_REF_TEXTURE:
drawObjectRefPass2(mesh, ModelViewProjectionMatrix, mesh.TextureMatrix);
break;
case SM_RIMLIT:
drawObjectRimLimit(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, mesh.TextureMatrix);
break;
case SM_UNLIT:
drawObjectUnlit(mesh, ModelViewProjectionMatrix);
break;
case SM_DETAILS:
drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix);
break;
case SM_DEFAULT:
drawObjectPass2(mesh, ModelViewProjectionMatrix, mesh.TextureMatrix);
break;
default:
assert(0 && "Wrong shaded material");
break;
}
}
void STKAnimatedMesh::render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
@ -186,46 +145,65 @@ void STKAnimatedMesh::render()
{
ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation);
TransposeInverseModelView = computeTIMV(AbsoluteTransformation);
core::matrix4 invmodel;
AbsoluteTransformation.getInverse(invmodel);
if (!GeometricMesh[FPSM_DEFAULT].empty())
glUseProgram(MeshShader::ObjectPass1Shader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++)
drawSolidPass1(*GeometricMesh[FPSM_DEFAULT][i], FPSM_DEFAULT);
{
GroupedFPSM<FPSM_DEFAULT>::MeshSet.push_back(GeometricMesh[FPSM_DEFAULT][i]);
GroupedFPSM<FPSM_DEFAULT>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_DEFAULT>::TIMVSet.push_back(invmodel);
}
if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty())
glUseProgram(MeshShader::ObjectRefPass1Shader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++)
drawSolidPass1(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], FPSM_ALPHA_REF_TEXTURE);
{
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet.push_back(GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i]);
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::TIMVSet.push_back(invmodel);
}
return;
}
if (irr_driver->getPhase() == SOLID_LIT_PASS)
{
if (!ShadedMesh[SM_DEFAULT].empty())
glUseProgram(MeshShader::ObjectPass2Shader::Program);
core::matrix4 invmodel;
AbsoluteTransformation.getInverse(invmodel);
for (unsigned i = 0; i < ShadedMesh[SM_DEFAULT].size(); i++)
drawSolidPass2(*ShadedMesh[SM_DEFAULT][i], SM_DEFAULT);
{
GroupedSM<SM_DEFAULT>::MeshSet.push_back(ShadedMesh[SM_DEFAULT][i]);
GroupedSM<SM_DEFAULT>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_DEFAULT>::TIMVSet.push_back(invmodel);
}
if (!ShadedMesh[SM_ALPHA_REF_TEXTURE].empty())
glUseProgram(MeshShader::ObjectRefPass2Shader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++)
drawSolidPass2(*ShadedMesh[SM_ALPHA_REF_TEXTURE][i], SM_ALPHA_REF_TEXTURE);
{
GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet.push_back(ShadedMesh[SM_ALPHA_REF_TEXTURE][i]);
GroupedSM<SM_ALPHA_REF_TEXTURE>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_ALPHA_REF_TEXTURE>::TIMVSet.push_back(invmodel);
}
if (!ShadedMesh[SM_RIMLIT].empty())
glUseProgram(MeshShader::ObjectRimLimitShader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_RIMLIT].size(); i++)
drawSolidPass2(*ShadedMesh[SM_RIMLIT][i], SM_RIMLIT);
{
GroupedSM<SM_RIMLIT>::MeshSet.push_back(ShadedMesh[SM_RIMLIT][i]);
GroupedSM<SM_RIMLIT>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_RIMLIT>::TIMVSet.push_back(invmodel);
}
if (!ShadedMesh[SM_UNLIT].empty())
glUseProgram(MeshShader::ObjectUnlitShader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_UNLIT].size(); i++)
drawSolidPass2(*ShadedMesh[SM_UNLIT][i], SM_UNLIT);
for (GLMesh *mesh : ShadedMesh[SM_UNLIT])
{
GroupedSM<SM_UNLIT>::MeshSet.push_back(mesh);
GroupedSM<SM_UNLIT>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_UNLIT>::TIMVSet.push_back(invmodel);
}
if (!ShadedMesh[SM_DETAILS].empty())
glUseProgram(MeshShader::DetailledObjectPass2Shader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_DETAILS].size(); i++)
drawSolidPass2(*ShadedMesh[SM_DETAILS][i], SM_DETAILS);
for (GLMesh *mesh : ShadedMesh[SM_DETAILS])
{
GroupedSM<SM_DETAILS>::MeshSet.push_back(mesh);
GroupedSM<SM_DETAILS>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_DETAILS>::TIMVSet.push_back(invmodel);
}
return;
}

View File

@ -16,8 +16,6 @@ protected:
std::vector<GLMesh *> TransparentMesh[TM_COUNT];
std::vector<GLMesh> GLmeshes;
core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView;
void drawSolidPass1(const GLMesh &mesh, GeometricMaterial type);
void drawSolidPass2(const GLMesh &mesh, ShadedMaterial type);
void cleanGLMeshes();
public:
STKAnimatedMesh(irr::scene::IAnimatedMesh* mesh, irr::scene::ISceneNode* parent,

View File

@ -179,7 +179,7 @@ void STKInstancedSceneNode::addInstance(const core::vector3df &origin, const cor
instance_pos.push_back(scale.Z);
}
static void drawFSPMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count)
static void drawFSPMDefault(GLMesh &mesh, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
@ -187,7 +187,7 @@ static void drawFSPMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjecti
size_t count = mesh.IndexCount;
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedObjectPass1Shader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvViewMatrix(), 0);
MeshShader::InstancedObjectPass1Shader::setUniforms(0);
glBindVertexArray(mesh.vao_first_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -207,7 +207,7 @@ static void drawShadowDefault(GLMesh &mesh, size_t instance_count)
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawFSPMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count)
static void drawFSPMAlphaRefTexture(GLMesh &mesh, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
@ -215,7 +215,7 @@ static void drawFSPMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelView
size_t count = mesh.IndexCount;
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedObjectRefPass1Shader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvViewMatrix(), 0);
MeshShader::InstancedObjectRefPass1Shader::setUniforms(0);
glBindVertexArray(mesh.vao_first_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -236,7 +236,7 @@ static void drawShadowAlphaRefTexture(GLMesh &mesh, size_t instance_count)
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
}
static void drawFSPMGrass(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDir, size_t instance_count)
static void drawFSPMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t instance_count)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
@ -244,7 +244,7 @@ static void drawFSPMGrass(GLMesh &mesh, const core::matrix4 &ModelViewProjection
size_t count = mesh.IndexCount;
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedGrassPass1Shader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvViewMatrix(), windDir, 0);
MeshShader::InstancedGrassPass1Shader::setUniforms(windDir, 0);
glBindVertexArray(mesh.vao_first_pass);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -315,18 +315,18 @@ void STKInstancedSceneNode::render()
if (!GeometricMesh[FPSM_DEFAULT].empty())
glUseProgram(MeshShader::InstancedObjectPass1Shader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++)
drawFSPMDefault(*GeometricMesh[FPSM_DEFAULT][i], ModelViewProjectionMatrix, instance_pos.size() / 9);
drawFSPMDefault(*GeometricMesh[FPSM_DEFAULT][i], instance_pos.size() / 9);
if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty())
glUseProgram(MeshShader::InstancedObjectRefPass1Shader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++)
drawFSPMAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], ModelViewProjectionMatrix, instance_pos.size() / 9);
drawFSPMAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], instance_pos.size() / 9);
windDir = getWind();
if (!GeometricMesh[FPSM_GRASS].empty())
glUseProgram(MeshShader::InstancedGrassPass1Shader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_GRASS].size(); i++)
drawFSPMGrass(*GeometricMesh[FPSM_GRASS][i], ModelViewProjectionMatrix, windDir, instance_pos.size() / 9);
drawFSPMGrass(*GeometricMesh[FPSM_GRASS][i], windDir, instance_pos.size() / 9);
return;
}

View File

@ -219,6 +219,8 @@ core::vector3df getWind()
return m_speed * vector3df(1., 0., 0.) * cos(time);
}
void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView)
{
irr_driver->IncreaseObjectCount();
@ -267,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;
@ -277,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;
@ -304,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);
@ -474,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);

View File

@ -67,12 +67,56 @@ bool isObject(video::E_MATERIAL_TYPE type);
core::vector3df getWind();
// Pass 1 shader (ie shaders that outputs normals and depth)
template<enum GeometricMaterial T>
class GroupedFPSM
{
public:
static std::vector<GLMesh *> MeshSet;
static std::vector<core::matrix4> MVPSet, TIMVSet;
static void reset()
{
MeshSet.clear();
MVPSet.clear();
TIMVSet.clear();
}
};
template<enum GeometricMaterial T>
std::vector<GLMesh *> GroupedFPSM<T>::MeshSet;
template<enum GeometricMaterial T>
std::vector<core::matrix4> GroupedFPSM<T>::MVPSet;
template<enum GeometricMaterial T>
std::vector<core::matrix4> GroupedFPSM<T>::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);
// Pass 2 shader (ie shaders that outputs final color)
template<enum ShadedMaterial T>
class GroupedSM
{
public:
static std::vector<GLMesh *> MeshSet;
static std::vector<core::matrix4> MVPSet, TIMVSet;
static void reset()
{
MeshSet.clear();
MVPSet.clear();
TIMVSet.clear();
}
};
template<enum ShadedMaterial T>
std::vector<GLMesh *> GroupedSM<T>::MeshSet;
template<enum ShadedMaterial T>
std::vector<core::matrix4> GroupedSM<T>::MVPSet;
template<enum ShadedMaterial T>
std::vector<core::matrix4> GroupedSM<T>::TIMVSet;
void drawDetailledObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);

View File

@ -336,21 +336,29 @@ void STKMeshSceneNode::render()
glDisable(GL_CULL_FACE);
ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation);
TransposeInverseModelView = computeTIMV(AbsoluteTransformation);
if (!GeometricMesh[FPSM_DEFAULT].empty())
glUseProgram(MeshShader::ObjectPass1Shader::Program);
core::matrix4 invmodel;
AbsoluteTransformation.getInverse(invmodel);
for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++)
drawSolidPass1(*GeometricMesh[FPSM_DEFAULT][i], FPSM_DEFAULT);
{
GroupedFPSM<FPSM_DEFAULT>::MeshSet.push_back(GeometricMesh[FPSM_DEFAULT][i]);
GroupedFPSM<FPSM_DEFAULT>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_DEFAULT>::TIMVSet.push_back(invmodel);
}
if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty())
glUseProgram(MeshShader::ObjectRefPass1Shader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++)
drawSolidPass1(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], FPSM_ALPHA_REF_TEXTURE);
{
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet.push_back(GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i]);
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::TIMVSet.push_back(invmodel);
}
if (!GeometricMesh[FPSM_NORMAL_MAP].empty())
glUseProgram(MeshShader::NormalMapShader::Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_NORMAL_MAP].size(); i++)
drawSolidPass1(*GeometricMesh[FPSM_NORMAL_MAP][i], FPSM_NORMAL_MAP);
{
GroupedFPSM<FPSM_NORMAL_MAP>::MeshSet.push_back(GeometricMesh[FPSM_NORMAL_MAP][i]);
GroupedFPSM<FPSM_NORMAL_MAP>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_NORMAL_MAP>::TIMVSet.push_back(invmodel);
}
if (!GeometricMesh[FPSM_GRASS].empty())
glUseProgram(MeshShader::GrassPass1Shader::Program);
@ -367,56 +375,76 @@ void STKMeshSceneNode::render()
if (reload_each_frame)
glDisable(GL_CULL_FACE);
if (!ShadedMesh[SM_DEFAULT].empty())
glUseProgram(MeshShader::ObjectPass2Shader::Program);
core::matrix4 invmodel;
AbsoluteTransformation.getInverse(invmodel);
for (unsigned i = 0; i < ShadedMesh[SM_DEFAULT].size(); i++)
drawSolidPass2(*ShadedMesh[SM_DEFAULT][i], SM_DEFAULT);
{
GroupedSM<SM_DEFAULT>::MeshSet.push_back(ShadedMesh[SM_DEFAULT][i]);
GroupedSM<SM_DEFAULT>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_DEFAULT>::TIMVSet.push_back(invmodel);
}
if (!ShadedMesh[SM_ALPHA_REF_TEXTURE].empty())
glUseProgram(MeshShader::ObjectRefPass2Shader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++)
drawSolidPass2(*ShadedMesh[SM_ALPHA_REF_TEXTURE][i], SM_ALPHA_REF_TEXTURE);
{
GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet.push_back(ShadedMesh[SM_ALPHA_REF_TEXTURE][i]);
GroupedSM<SM_ALPHA_REF_TEXTURE>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_ALPHA_REF_TEXTURE>::TIMVSet.push_back(invmodel);
}
if (!ShadedMesh[SM_RIMLIT].empty())
glUseProgram(MeshShader::ObjectRimLimitShader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_RIMLIT].size(); i++)
drawSolidPass2(*ShadedMesh[SM_RIMLIT][i], SM_RIMLIT);
{
GroupedSM<SM_RIMLIT>::MeshSet.push_back(ShadedMesh[SM_RIMLIT][i]);
GroupedSM<SM_RIMLIT>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_RIMLIT>::TIMVSet.push_back(invmodel);
}
if (!ShadedMesh[SM_SPHEREMAP].empty())
glUseProgram(MeshShader::SphereMapShader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_SPHEREMAP].size(); i++)
drawSolidPass2(*ShadedMesh[SM_SPHEREMAP][i], SM_SPHEREMAP);
{
GroupedSM<SM_SPHEREMAP>::MeshSet.push_back(ShadedMesh[SM_SPHEREMAP][i]);
GroupedSM<SM_SPHEREMAP>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_SPHEREMAP>::TIMVSet.push_back(invmodel);
}
if (!ShadedMesh[SM_SPLATTING].empty())
glUseProgram(MeshShader::SplattingShader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_SPLATTING].size(); i++)
drawSolidPass2(*ShadedMesh[SM_SPLATTING][i], SM_SPLATTING);
for (GLMesh *mesh : ShadedMesh[SM_SPLATTING])
{
GroupedSM<SM_SPLATTING>::MeshSet.push_back(mesh);
GroupedSM<SM_SPLATTING>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_SPLATTING>::TIMVSet.push_back(invmodel);
}
for (GLMesh *mesh : ShadedMesh[SM_UNLIT])
{
GroupedSM<SM_UNLIT>::MeshSet.push_back(mesh);
GroupedSM<SM_UNLIT>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_UNLIT>::TIMVSet.push_back(invmodel);
}
for (GLMesh *mesh : ShadedMesh[SM_DETAILS])
{
GroupedSM<SM_DETAILS>::MeshSet.push_back(mesh);
GroupedSM<SM_DETAILS>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_DETAILS>::TIMVSet.push_back(invmodel);
}
for (GLMesh *mesh : ShadedMesh[SM_UNTEXTURED])
{
GroupedSM<SM_UNTEXTURED>::MeshSet.push_back(mesh);
GroupedSM<SM_UNTEXTURED>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_UNTEXTURED>::TIMVSet.push_back(invmodel);
}
if (!ShadedMesh[SM_GRASS].empty())
glUseProgram(MeshShader::GrassPass2Shader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_GRASS].size(); i++)
drawSolidPass2(*ShadedMesh[SM_GRASS][i], SM_GRASS);
if (!ShadedMesh[SM_UNLIT].empty())
glUseProgram(MeshShader::ObjectUnlitShader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_UNLIT].size(); i++)
drawSolidPass2(*ShadedMesh[SM_UNLIT][i], SM_UNLIT);
if (!ShadedMesh[SM_CAUSTICS].empty())
glUseProgram(MeshShader::CausticsShader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_CAUSTICS].size(); i++)
drawSolidPass2(*ShadedMesh[SM_CAUSTICS][i], SM_CAUSTICS);
if (!ShadedMesh[SM_DETAILS].empty())
glUseProgram(MeshShader::DetailledObjectPass2Shader::Program);
for (unsigned i = 0; i < ShadedMesh[SM_DETAILS].size(); i++)
drawSolidPass2(*ShadedMesh[SM_DETAILS][i], SM_DETAILS);
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;