Merge branch 'renderFactorisation'

This commit is contained in:
vlj 2014-07-12 01:20:19 +02:00
commit e62301c9f6
8 changed files with 358 additions and 463 deletions

View File

@ -11,7 +11,7 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "STKRelease")
endif()
option(USE_WIIUSE "Support for wiimote input devices" ON)
option(USE_WIIUSE "Support for wiimote input devices" OFF)
option(USE_FRIBIDI "Support for right-to-left languages" ON)
option(CHECK_ASSETS "Check if assets are installed in ../stk-assets" ON)
@ -25,8 +25,8 @@ if(MSVC)
# which also needs an absolute path :(
option(WIIUSE_BUILD "Build wiiuse lib (only for developers)" OFF)
mark_as_advanced(WIIUSE_BUILD)
else()
set(WIIUSE_BUILD ON)
#else()
# set(WIIUSE_BUILD ON)
endif()
set(STK_SOURCE_DIR "src")
@ -124,9 +124,9 @@ if(UNIX AND USE_XRANDR)
endif()
if(UNIX)
if(USE_CPP2011)
# if(USE_CPP2011)
add_definitions("-std=c++0x")
endif()
# endif()
endif()
# OpenGL

View File

@ -53,6 +53,32 @@
#define MAX2(a, b) ((a) > (b) ? (a) : (b))
#define MIN2(a, b) ((a) > (b) ? (b) : (a))
template<unsigned N>
struct unroll_args
{
template<typename Shader, typename ...TupleTypes, typename ...Args>
static void exec(const std::tuple<TupleTypes...> &t, Args... args)
{
unroll_args<N - 1>::template exec<Shader>(t, std::get<N - 1>(t), args...);
}
};
template<>
struct unroll_args<0>
{
template<typename Shader, typename ...TupleTypes, typename ...Args>
static void exec(const std::tuple<TupleTypes...> &t, Args... args)
{
draw<Shader>(args...);
}
};
template<typename Shader, typename... TupleType>
void apply(const std::tuple<TupleType...> &arg)
{
unroll_args<std::tuple_size<std::tuple<TupleType...> >::value >::template exec<Shader>(arg);
}
void IrrDriver::renderGLSL(float dt)
{
World *world = World::getWorld(); // Never NULL.
@ -503,6 +529,32 @@ void IrrDriver::computeSunVisibility()
}
}
template<typename Shader, enum E_VERTEX_TYPE VertexType, typename... TupleType>
void renderMeshes1stPass(const std::vector<GLuint> &TexUnits, std::vector<std::tuple<TupleType...> > &meshes)
{
glUseProgram(Shader::Program);
glBindVertexArray(getVAO(VertexType));
for (unsigned i = 0; i < meshes.size(); i++)
{
GLMesh &mesh = *(std::get<0>(meshes[i]));
for (unsigned j = 0; j < TexUnits.size(); j++)
{
if (!mesh.textures[j])
mesh.textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
compressTexture(mesh.textures[j], true);
setTexture(TexUnits[j], getTextureGLuint(mesh.textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
}
if (mesh.VAOType != VertexType)
{
#ifdef DEBUG
Log::error("Materials", "Wrong vertex Type associed to pass 1 (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
#endif
continue;
}
apply<Shader>(meshes[i]);
}
}
void IrrDriver::renderSolidFirstPass()
{
m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind();
@ -516,10 +568,10 @@ void IrrDriver::renderSolidFirstPass()
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
irr_driver->setPhase(SOLID_NORMAL_AND_DEPTH_PASS);
GroupedFPSM<FPSM_DEFAULT_STANDARD>::reset();
GroupedFPSM<FPSM_DEFAULT_2TCOORD>::reset();
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::reset();
GroupedFPSM<FPSM_NORMAL_MAP>::reset();
ListDefaultStandardG::Arguments.clear();
ListDefault2TCoordG::Arguments.clear();
ListAlphaRefG::Arguments.clear();
ListNormalG::Arguments.clear();
m_scene_manager->drawAll(scene::ESNRP_SOLID);
if (!UserConfigParams::m_dynamic_lights)
@ -527,73 +579,39 @@ void IrrDriver::renderSolidFirstPass()
{
ScopedGPUTimer Timer(getGPUTimer(Q_SOLID_PASS1));
glUseProgram(MeshShader::ObjectPass1Shader::Program);
glBindVertexArray(getVAO(video::EVT_STANDARD));
for (unsigned i = 0; i < GroupedFPSM<FPSM_DEFAULT_STANDARD>::MeshSet.size(); ++i)
{
GLMesh &mesh = *GroupedFPSM<FPSM_DEFAULT_STANDARD>::MeshSet[i];
if (!mesh.textures[0])
mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::ObjectPass1Shader>(mesh, GroupedFPSM<FPSM_DEFAULT_STANDARD>::MVPSet[i], GroupedFPSM<FPSM_DEFAULT_STANDARD>::TIMVSet[i], 0);
}
glBindVertexArray(getVAO(video::EVT_2TCOORDS));
for (unsigned i = 0; i < GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MeshSet.size(); ++i)
{
GLMesh &mesh = *GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MeshSet[i];
if (!mesh.textures[0])
mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::ObjectPass1Shader>(mesh, GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MVPSet[i], GroupedFPSM<FPSM_DEFAULT_2TCOORD>::TIMVSet[i], 0);
}
glUseProgram(MeshShader::ObjectRefPass1Shader::Program);
glBindVertexArray(getVAO(EVT_STANDARD));
for (unsigned i = 0; i < GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet.size(); ++i)
{
const GLMesh &mesh = *GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet[i];
if (mesh.VAOType != video::EVT_STANDARD)
{
#ifdef DEBUG
Log::error("Materials", "Wrong vertex Type associed to alpha ref pass 1 (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
#endif
continue;
}
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::ObjectRefPass1Shader>(mesh, GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MVPSet[i], GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::TIMVSet[i], GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet[i]->TextureMatrix, 0);
}
glUseProgram(MeshShader::NormalMapShader::Program);
glBindVertexArray(getVAO(EVT_TANGENTS));
for (unsigned i = 0; i < GroupedFPSM<FPSM_NORMAL_MAP>::MeshSet.size(); ++i)
{
const GLMesh &mesh = *GroupedFPSM<FPSM_NORMAL_MAP>::MeshSet[i];
assert(mesh.VAOType == video::EVT_TANGENTS);
assert(mesh.textures[1]);
compressTexture(mesh.textures[1], false);
setTexture(0, getTextureGLuint(mesh.textures[1]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
compressTexture(mesh.textures[0], true);
setTexture(1, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::NormalMapShader>(mesh, GroupedFPSM<FPSM_NORMAL_MAP>::MVPSet[i], GroupedFPSM<FPSM_NORMAL_MAP>::TIMVSet[i], 0, 1);
}
renderMeshes1stPass<MeshShader::ObjectPass1Shader, video::EVT_STANDARD>({ MeshShader::ObjectPass1Shader::TU_tex }, ListDefaultStandardG::Arguments);
renderMeshes1stPass<MeshShader::ObjectPass1Shader, video::EVT_2TCOORDS>({ MeshShader::ObjectPass1Shader::TU_tex }, ListDefault2TCoordG::Arguments);
renderMeshes1stPass<MeshShader::ObjectRefPass1Shader, video::EVT_STANDARD>({ MeshShader::ObjectRefPass1Shader::TU_tex }, ListAlphaRefG::Arguments);
renderMeshes1stPass<MeshShader::NormalMapShader, video::EVT_TANGENTS>({ MeshShader::NormalMapShader::TU_glossy, MeshShader::NormalMapShader::TU_normalmap }, ListNormalG::Arguments);
}
}
template<typename Shader, enum E_VERTEX_TYPE VertexType>
void renderMeshes2ndPass(std::vector<GLMesh *> &meshes, const std::vector<core::matrix4> &MVPMatrixes)
template<typename Shader, enum E_VERTEX_TYPE VertexType, typename... TupleType>
void renderMeshes2ndPass(const std::vector<GLuint> &TexUnits, std::vector<std::tuple<TupleType...> > &meshes)
{
glUseProgram(Shader::Program);
glBindVertexArray(getVAO(VertexType));
for (unsigned i = 0; i < meshes.size(); i++)
{
GLMesh &mesh = *meshes[i];
if (!mesh.textures[0])
mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
GLMesh &mesh = *(std::get<0>(meshes[i]));
for (unsigned j = 0; j < TexUnits.size(); j++)
{
if (!mesh.textures[j])
mesh.textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
compressTexture(mesh.textures[j], true);
setTexture(TexUnits[j], getTextureGLuint(mesh.textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
else
{
GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
}
if (mesh.VAOType != VertexType)
{
#ifdef DEBUG
@ -601,19 +619,7 @@ void renderMeshes2ndPass(std::vector<GLMesh *> &meshes, const std::vector<core::
#endif
continue;
}
compressTexture(mesh.textures[0], true);
setTexture(MeshShader::ObjectPass2Shader::TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
else
{
GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
draw<Shader>(mesh, MVPMatrixes[i], mesh.TextureMatrix);
apply<Shader>(meshes[i]);
}
}
@ -639,13 +645,13 @@ void IrrDriver::renderSolidSecondPass()
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
GroupedSM<SM_DEFAULT_STANDARD>::reset();
GroupedSM<SM_DEFAULT_TANGENT>::reset();
GroupedSM<SM_ALPHA_REF_TEXTURE>::reset();
GroupedSM<SM_SPHEREMAP>::reset();
ListDefaultStandardSM::Arguments.clear();
ListDefaultTangentSM::Arguments.clear();
ListAlphaRefSM::Arguments.clear();
ListSphereMapSM::Arguments.clear();
ListUnlitSM::Arguments.clear();
ListDetailSM::Arguments.clear();
GroupedSM<SM_SPLATTING>::reset();
GroupedSM<SM_UNLIT>::reset();
GroupedSM<SM_DETAILS>::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_HALF1_R), GL_LINEAR, GL_LINEAR);
@ -655,86 +661,17 @@ void IrrDriver::renderSolidSecondPass()
m_scene_manager->drawAll(scene::ESNRP_SOLID);
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_STANDARD>(GroupedSM<SM_DEFAULT_STANDARD>::MeshSet, GroupedSM<SM_DEFAULT_STANDARD>::MVPSet);
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_TANGENTS>(GroupedSM<SM_DEFAULT_TANGENT>::MeshSet, GroupedSM<SM_DEFAULT_TANGENT>::MVPSet);
renderMeshes2ndPass<MeshShader::ObjectRefPass2Shader, video::EVT_STANDARD>(GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet, GroupedSM<SM_ALPHA_REF_TEXTURE>::MVPSet);
glUseProgram(MeshShader::SphereMapShader::Program);
glBindVertexArray(getVAO(EVT_STANDARD));
for (unsigned i = 0; i < GroupedSM<SM_SPHEREMAP>::MeshSet.size(); i++)
{
const GLMesh &mesh = *GroupedSM<SM_SPHEREMAP>::MeshSet[i];
assert(mesh.VAOType == EVT_STANDARD);
compressTexture(mesh.textures[0], true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
else
{
GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
setTexture(MeshShader::SphereMapShader::TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::SphereMapShader>(mesh, GroupedSM<SM_SPHEREMAP>::MVPSet[i], GroupedSM<SM_SPHEREMAP>::TIMVSet[i], irr_driver->getSceneManager()->getAmbientLight());
}
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_STANDARD>({ MeshShader::ObjectPass2Shader::TU_Albedo }, ListDefaultStandardSM::Arguments);
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_TANGENTS>({ MeshShader::ObjectPass2Shader::TU_Albedo }, ListDefaultTangentSM::Arguments);
renderMeshes2ndPass<MeshShader::ObjectRefPass2Shader, video::EVT_STANDARD>({ MeshShader::ObjectRefPass2Shader::TU_Albedo }, ListAlphaRefSM::Arguments);
renderMeshes2ndPass<MeshShader::SphereMapShader, video::EVT_STANDARD>({ MeshShader::SphereMapShader::TU_tex }, ListSphereMapSM::Arguments);
renderMeshes2ndPass<MeshShader::ObjectUnlitShader, video::EVT_STANDARD>({ MeshShader::ObjectUnlitShader::TU_tex }, ListUnlitSM::Arguments);
renderMeshes2ndPass<MeshShader::DetailledObjectPass2Shader, video::EVT_2TCOORDS>({ MeshShader::DetailledObjectPass2Shader::TU_Albedo, MeshShader::DetailledObjectPass2Shader::TU_detail }, ListDetailSM::Arguments);
glUseProgram(MeshShader::SplattingShader::Program);
glBindVertexArray(getVAO(EVT_2TCOORDS));
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);
glBindVertexArray(getVAO(EVT_STANDARD));
for (unsigned i = 0; i < GroupedSM<SM_UNLIT>::MeshSet.size(); i++)
{
const GLMesh &mesh = *GroupedSM<SM_UNLIT>::MeshSet[i];
assert(mesh.VAOType == EVT_STANDARD);
compressTexture(mesh.textures[0], true);
setTexture(MeshShader::ObjectUnlitShader::TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
else
{
GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
draw<MeshShader::ObjectUnlitShader>(mesh, GroupedSM<SM_UNLIT>::MVPSet[i]);
}
glUseProgram(MeshShader::DetailledObjectPass2Shader::Program);
glBindVertexArray(getVAO(EVT_2TCOORDS));
for (unsigned i = 0; i < GroupedSM<SM_DETAILS>::MeshSet.size(); i++)
{
GLMesh &mesh = *GroupedSM<SM_DETAILS>::MeshSet[i];
assert(mesh.VAOType == EVT_2TCOORDS);
compressTexture(mesh.textures[0], true);
setTexture(MeshShader::DetailledObjectPass2Shader::TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
else
{
GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
if (!mesh.textures[1])
{
#ifdef DEBUG
Log::error("Materials", "No detail/lightmap texture provided for detail/lightmap material.");
#endif
mesh.textures[1] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
}
compressTexture(mesh.textures[1], true);
setTexture(MeshShader::DetailledObjectPass2Shader::TU_detail, getTextureGLuint(mesh.textures[1]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::DetailledObjectPass2Shader>(mesh, GroupedSM<SM_DETAILS>::MVPSet[i]);
}
}
}
@ -747,116 +684,27 @@ void IrrDriver::renderTransparent()
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glDisable(GL_CULL_FACE);
TransparentMeshes<TM_DEFAULT>::reset();
TransparentMeshes<TM_ADDITIVE>::reset();
ListBlendTransparent::Arguments.clear();
ListAdditiveTransparent::Arguments.clear();
ListBlendTransparentFog::Arguments.clear();
ListAdditiveTransparentFog::Arguments.clear();
m_scene_manager->drawAll(scene::ESNRP_TRANSPARENT);
glBindVertexArray(getVAO(EVT_STANDARD));
if (World::getWorld() && World::getWorld()->isFogEnabled())
{
const Track * const track = World::getWorld()->getTrack();
// This function is only called once per frame - thus no need for setters.
const float fogmax = track->getFogMax();
const float startH = track->getFogStartHeight();
const float endH = track->getFogEndHeight();
const float start = track->getFogStart();
const float end = track->getFogEnd();
const video::SColor tmpcol = track->getFogColor();
core::vector3df col(tmpcol.getRed() / 255.0f,
tmpcol.getGreen() / 255.0f,
tmpcol.getBlue() / 255.0f);
glUseProgram(MeshShader::TransparentFogShader::Program);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
for (unsigned i = 0; i < TransparentMeshes<TM_DEFAULT>::MeshSet.size(); i++)
{
GLMesh &mesh = *TransparentMeshes<TM_DEFAULT>::MeshSet[i];
if (mesh.VAOType != EVT_STANDARD)
{
#ifdef DEBUG
Log::error("Materials", "Wrong vertex Type associed to fog + transparent blend (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
#endif
glBindVertexArray(getVAO(mesh.VAOType));
}
if (!mesh.textures[0])
mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::TransparentFogShader>(mesh, TransparentMeshes<TM_DEFAULT>::MVPSet[i], TransparentMeshes<TM_DEFAULT>::MeshSet[i]->TextureMatrix, fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition(), 0);
if (mesh.VAOType != EVT_STANDARD)
glBindVertexArray(getVAO(EVT_STANDARD));
}
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>({ MeshShader::TransparentFogShader::TU_tex }, ListBlendTransparentFog::Arguments);
glBlendFunc(GL_ONE, GL_ONE);
for (unsigned i = 0; i < TransparentMeshes<TM_ADDITIVE>::MeshSet.size(); i++)
{
GLMesh &mesh = *TransparentMeshes<TM_ADDITIVE>::MeshSet[i];
if (mesh.VAOType != EVT_STANDARD)
{
#ifdef DEBUG
Log::error("Materials", "Wrong vertex Type associed to fog + transparent additive (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
#endif
glBindVertexArray(getVAO(mesh.VAOType));
}
glBindVertexArray(getVAO(mesh.VAOType));
if (!mesh.textures[0])
mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::TransparentFogShader>(mesh, TransparentMeshes<TM_ADDITIVE>::MVPSet[i], TransparentMeshes<TM_ADDITIVE>::MeshSet[i]->TextureMatrix, fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition(), 0);
if (mesh.VAOType != EVT_STANDARD)
glBindVertexArray(getVAO(EVT_STANDARD));
}
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>({ MeshShader::TransparentFogShader::TU_tex }, ListAdditiveTransparentFog::Arguments);
}
else
{
glUseProgram(MeshShader::TransparentShader::Program);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
for (unsigned i = 0; i < TransparentMeshes<TM_DEFAULT>::MeshSet.size(); i++)
{
GLMesh &mesh = *TransparentMeshes<TM_DEFAULT>::MeshSet[i];
if (mesh.VAOType != EVT_STANDARD)
{
#ifdef DEBUG
Log::error("Materials", "Wrong vertex Type associed to fog + transparent additive (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
#endif
glBindVertexArray(getVAO(mesh.VAOType));
}
glBindVertexArray(getVAO(mesh.VAOType));
if (!mesh.textures[0])
mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::TransparentShader>(mesh, TransparentMeshes<TM_DEFAULT>::MVPSet[i], TransparentMeshes<TM_DEFAULT>::MeshSet[i]->TextureMatrix, 0);
if (mesh.VAOType != EVT_STANDARD)
glBindVertexArray(getVAO(EVT_STANDARD));
}
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>({ MeshShader::TransparentShader::TU_tex }, ListBlendTransparent::Arguments);
glBlendFunc(GL_ONE, GL_ONE);
for (unsigned i = 0; i < TransparentMeshes<TM_ADDITIVE>::MeshSet.size(); i++)
{
const GLMesh &mesh = *TransparentMeshes<TM_ADDITIVE>::MeshSet[i];
if (mesh.VAOType != EVT_STANDARD)
{
#ifdef DEBUG
Log::error("Materials", "Wrong vertex Type associed to fog + transparent additive (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
#endif
glBindVertexArray(getVAO(mesh.VAOType));
}
glBindVertexArray(getVAO(mesh.VAOType));
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::TransparentShader>(mesh, TransparentMeshes<TM_ADDITIVE>::MVPSet[i], TransparentMeshes<TM_ADDITIVE>::MeshSet[i]->TextureMatrix, 0);
if (mesh.VAOType != EVT_STANDARD)
glBindVertexArray(getVAO(EVT_STANDARD));
}
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>({ MeshShader::TransparentShader::TU_tex }, ListAdditiveTransparent::Arguments);
}
}
@ -1104,22 +952,22 @@ void IrrDriver::renderShadows()
glBindVertexArray(getVAO(EVT_STANDARD));
for (unsigned i = 0; i < GroupedFPSM<FPSM_DEFAULT_STANDARD>::MeshSet.size(); ++i)
{
const GLMesh mesh = *GroupedFPSM<FPSM_DEFAULT_STANDARD>::MeshSet[i];
GLMesh &mesh = *GroupedFPSM<FPSM_DEFAULT_STANDARD>::MeshSet[i];
if (!mesh.textures[0])
continue;
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::RSMShader>(mesh, rsm_matrix, GroupedFPSM<FPSM_DEFAULT_STANDARD>::MVPSet[i], 0);
draw<MeshShader::RSMShader>(&mesh, rsm_matrix, GroupedFPSM<FPSM_DEFAULT_STANDARD>::MVPSet[i], 0);
}
glBindVertexArray(getVAO(EVT_2TCOORDS));
for (unsigned i = 0; i < GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MeshSet.size(); ++i)
{
const GLMesh mesh = *GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MeshSet[i];
GLMesh &mesh = *GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MeshSet[i];
if (!mesh.textures[0])
continue;
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
draw<MeshShader::RSMShader>(mesh, rsm_matrix, GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MVPSet[i], 0);
draw<MeshShader::RSMShader>(&mesh, rsm_matrix, GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MVPSet[i], 0);
}
}

View File

@ -451,7 +451,7 @@ namespace MeshShader
GLuint ObjectPass1Shader::Program;
GLuint ObjectPass1Shader::uniform_MM;
GLuint ObjectPass1Shader::uniform_IMM;
GLuint ObjectPass1Shader::uniform_tex;
GLuint ObjectPass1Shader::TU_tex;
void ObjectPass1Shader::init()
{
@ -461,28 +461,31 @@ namespace MeshShader
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass1.frag").c_str());
uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix");
uniform_tex = glGetUniformLocation(Program, "tex");
GLuint uniform_tex = glGetUniformLocation(Program, "tex");
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
TU_tex = 0;
glUseProgram(Program);
glUniform1i(uniform_tex, TU_tex);
glUseProgram(0);
}
void ObjectPass1Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_tex)
void ObjectPass1Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
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::uniform_MM;
GLuint ObjectRefPass1Shader::uniform_IMM;
GLuint ObjectRefPass1Shader::uniform_TM;
GLuint ObjectRefPass1Shader::uniform_tex;
GLuint ObjectRefPass1Shader::TU_tex;
void ObjectRefPass1Shader::init()
{
@ -493,22 +496,25 @@ namespace MeshShader
uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix");
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
uniform_tex = glGetUniformLocation(Program, "tex");
GLuint uniform_tex = glGetUniformLocation(Program, "tex");
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
TU_tex = 0;
glUseProgram(Program);
glUniform1i(uniform_tex, TU_tex);
glUseProgram(0);
}
void ObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex)
void ObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer());
glUniform1i(uniform_tex, TU_tex);
}
GLuint GrassPass1Shader::Program;
@ -540,8 +546,8 @@ namespace MeshShader
GLuint NormalMapShader::Program;
GLuint NormalMapShader::uniform_MM;
GLuint NormalMapShader::uniform_IMM;
GLuint NormalMapShader::uniform_normalMap;
GLuint NormalMapShader::uniform_DiffuseForAlpha;
GLuint NormalMapShader::TU_normalmap;
GLuint NormalMapShader::TU_glossy;
void NormalMapShader::init()
{
@ -551,23 +557,27 @@ namespace MeshShader
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/normalmap.frag").c_str());
uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix");
uniform_normalMap = glGetUniformLocation(Program, "normalMap");
uniform_DiffuseForAlpha = glGetUniformLocation(Program, "DiffuseForAlpha");
GLuint uniform_normalMap = glGetUniformLocation(Program, "normalMap");
GLuint uniform_DiffuseForAlpha = glGetUniformLocation(Program, "DiffuseForAlpha");
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
TU_normalmap = 1;
TU_glossy = 0;
glUseProgram(Program);
glUniform1i(uniform_normalMap, TU_normalmap);
glUniform1i(uniform_DiffuseForAlpha, TU_glossy);
glUseProgram(0);
}
void NormalMapShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_normalMap, unsigned TU_uniform_DiffuseForAlpha)
void NormalMapShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer());
glUniform1i(uniform_normalMap, TU_normalMap);
glUniform1i(uniform_DiffuseForAlpha, TU_uniform_DiffuseForAlpha);
}
GLuint InstancedObjectPass1Shader::Program;
@ -1153,7 +1163,7 @@ namespace MeshShader
GLuint TransparentShader::Program;
GLuint TransparentShader::uniform_MVP;
GLuint TransparentShader::uniform_TM;
GLuint TransparentShader::uniform_tex;
GLuint TransparentShader::TU_tex;
void TransparentShader::init()
{
@ -1162,25 +1172,29 @@ namespace MeshShader
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparent.frag").c_str());
uniform_MVP = glGetUniformLocation(Program, "ModelMatrix");
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
uniform_tex = glGetUniformLocation(Program, "tex");
GLuint uniform_tex = glGetUniformLocation(Program, "tex");
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
TU_tex = 0;
glUseProgram(Program);
glUniform1i(uniform_tex, TU_tex);
glUseProgram(0);
}
void TransparentShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex)
void TransparentShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer());
glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
glUniform1i(uniform_tex, TU_tex);
}
GLuint TransparentFogShader::Program;
GLuint TransparentFogShader::uniform_MVP;
GLuint TransparentFogShader::uniform_TM;
GLuint TransparentFogShader::uniform_tex;
GLuint TransparentFogShader::TU_tex;
GLuint TransparentFogShader::uniform_fogmax;
GLuint TransparentFogShader::uniform_startH;
GLuint TransparentFogShader::uniform_endH;
@ -1195,7 +1209,7 @@ namespace MeshShader
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparentfog.frag").c_str());
uniform_MVP = glGetUniformLocation(Program, "ModelMatrix");
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
uniform_tex = glGetUniformLocation(Program, "tex");
GLuint uniform_tex = glGetUniformLocation(Program, "tex");
uniform_fogmax = glGetUniformLocation(Program, "fogmax");
uniform_startH = glGetUniformLocation(Program, "startH");
uniform_endH = glGetUniformLocation(Program, "endH");
@ -1207,9 +1221,14 @@ namespace MeshShader
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
TU_tex = 0;
glUseProgram(Program);
glUniform1i(uniform_tex, TU_tex);
glUseProgram(0);
}
void TransparentFogShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex)
void TransparentFogShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer());
glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
@ -1219,7 +1238,6 @@ namespace MeshShader
glUniform1f(uniform_start, start);
glUniform1f(uniform_end, end);
glUniform3f(uniform_col, col.X, col.Y, col.Z);
glUniform1i(uniform_tex, TU_tex);
}
GLuint BillboardShader::Program;

View File

@ -53,20 +53,22 @@ class ObjectPass1Shader
{
public:
static GLuint Program;
static GLuint uniform_MM, uniform_IMM, uniform_tex;
static GLuint uniform_MM, uniform_IMM;
static GLuint TU_tex;
static void init();
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_tex);
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix);
};
class ObjectRefPass1Shader
{
public:
static GLuint Program;
static GLuint uniform_MM, uniform_TM, uniform_IMM, uniform_tex;
static GLuint uniform_MM, uniform_TM, uniform_IMM;
static GLuint TU_tex;
static void init();
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_texture);
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix);
};
class GrassPass1Shader
@ -83,10 +85,11 @@ class NormalMapShader
{
public:
static GLuint Program;
static GLuint uniform_MM, uniform_IMM, uniform_normalMap, uniform_DiffuseForAlpha;
static GLuint uniform_MM, uniform_IMM;
static GLuint TU_normalmap, TU_glossy;
static void init();
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_normalMap, unsigned TU_uniform_DiffuseForAlpha);
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix);
};
class InstancedObjectPass1Shader
@ -253,20 +256,22 @@ class TransparentShader
{
public:
static GLuint Program;
static GLuint uniform_MVP, uniform_TM, uniform_tex;
static GLuint uniform_MVP, uniform_TM;
static GLuint TU_tex;
static void init();
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex);
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix);
};
class TransparentFogShader
{
public:
static GLuint Program;
static GLuint uniform_MVP, uniform_TM, uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col;
static GLuint uniform_MVP, uniform_TM, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col;
static GLuint TU_tex;
static void init();
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex);
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos);
};
class BillboardShader

View File

@ -6,6 +6,7 @@
#include "config/user_config.hpp"
#include "modes/world.hpp"
#include "tracks/track.hpp"
#include "graphics/camera.hpp"
#include "utils/profiler.hpp"
using namespace irr;
@ -145,25 +146,13 @@ void STKAnimatedMesh::render()
GLMesh* mesh;
for_in(mesh, GeometricMesh[FPSM_DEFAULT_STANDARD])
{
GroupedFPSM<FPSM_DEFAULT_STANDARD>::MeshSet.push_back(mesh);
GroupedFPSM<FPSM_DEFAULT_STANDARD>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_DEFAULT_STANDARD>::TIMVSet.push_back(invmodel);
}
ListDefaultStandardG::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, invmodel));
for_in(mesh, GeometricMesh[FPSM_DEFAULT_2TCOORD])
{
GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MeshSet.push_back(mesh);
GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_DEFAULT_2TCOORD>::TIMVSet.push_back(invmodel);
}
ListDefault2TCoordG::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, invmodel));
for_in(mesh, GeometricMesh[FPSM_ALPHA_REF_TEXTURE])
{
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet.push_back(mesh);
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::TIMVSet.push_back(invmodel);
}
ListAlphaRefG::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix));
return;
}
@ -175,39 +164,19 @@ void STKAnimatedMesh::render()
GLMesh* mesh;
for_in(mesh, ShadedMesh[SM_DEFAULT_STANDARD])
{
GroupedSM<SM_DEFAULT_STANDARD>::MeshSet.push_back(mesh);
GroupedSM<SM_DEFAULT_STANDARD>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_DEFAULT_STANDARD>::TIMVSet.push_back(invmodel);
}
ListDefaultStandardSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
for_in(mesh, ShadedMesh[SM_DEFAULT_TANGENT])
{
GroupedSM<SM_DEFAULT_TANGENT>::MeshSet.push_back(mesh);
GroupedSM<SM_DEFAULT_TANGENT>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_DEFAULT_TANGENT>::TIMVSet.push_back(invmodel);
}
ListDefaultTangentSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
for_in(mesh, ShadedMesh[SM_ALPHA_REF_TEXTURE])
{
GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet.push_back(mesh);
GroupedSM<SM_ALPHA_REF_TEXTURE>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_ALPHA_REF_TEXTURE>::TIMVSet.push_back(invmodel);
}
ListAlphaRefSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
for_in (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);
}
ListUnlitSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation));
for_in(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);
}
ListDetailSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation));
return;
}
@ -220,16 +189,40 @@ void STKAnimatedMesh::render()
glUseProgram(MeshShader::BubbleShader::Program);
GLMesh* mesh;
for_in(mesh, TransparentMesh[TM_DEFAULT])
if (World::getWorld() && World::getWorld()->isFogEnabled())
{
TransparentMeshes<TM_DEFAULT>::MeshSet.push_back(mesh);
TransparentMeshes<TM_DEFAULT>::MVPSet.push_back(AbsoluteTransformation);
}
const Track * const track = World::getWorld()->getTrack();
for_in(mesh, TransparentMesh[TM_ADDITIVE])
// Todo : put everything in a ubo
const float fogmax = track->getFogMax();
const float startH = track->getFogStartHeight();
const float endH = track->getFogEndHeight();
const float start = track->getFogStart();
const float end = track->getFogEnd();
const video::SColor tmpcol = track->getFogColor();
core::vector3df col(tmpcol.getRed() / 255.0f,
tmpcol.getGreen() / 255.0f,
tmpcol.getBlue() / 255.0f);
for_in(mesh, TransparentMesh[TM_DEFAULT])
ListBlendTransparentFog::Arguments.push_back(
std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix,
fogmax, startH, endH, start, end, col,
Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition()));
for_in(mesh, TransparentMesh[TM_ADDITIVE])
ListAdditiveTransparentFog::Arguments.push_back(
std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix,
fogmax, startH, endH, start, end, col,
Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition()));
}
else
{
TransparentMeshes<TM_ADDITIVE>::MeshSet.push_back(mesh);
TransparentMeshes<TM_ADDITIVE>::MVPSet.push_back(AbsoluteTransformation);
for_in(mesh, TransparentMesh[TM_DEFAULT])
ListBlendTransparent::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
for_in(mesh, TransparentMesh[TM_ADDITIVE])
ListAdditiveTransparent::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
}
return;
}

View File

@ -379,58 +379,6 @@ void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex);
}
void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::TransparentShader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, 0);
assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);
}
void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
const Track * const track = World::getWorld()->getTrack();
// This function is only called once per frame - thus no need for setters.
const float fogmax = track->getFogMax();
const float startH = track->getFogStartHeight();
const float endH = track->getFogEndHeight();
const float start = track->getFogStart();
const float end = track->getFogEnd();
const video::SColor tmpcol = track->getFogColor();
core::vector3df col(tmpcol.getRed() / 255.0f,
tmpcol.getGreen() / 255.0f,
tmpcol.getBlue() / 255.0f);
if (mesh.textures[0] != NULL)
{
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
}
glUseProgram(MeshShader::TransparentFogShader::Program);
MeshShader::TransparentFogShader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition(), 0);
assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);
}
void drawBubble(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
{
irr_driver->IncreaseObjectCount();
@ -519,3 +467,18 @@ void initvaostate(GLMesh &mesh, TransparentMaterial TranspMat)
mesh.vao = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
}
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > ListDefaultStandardG::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > ListDefault2TCoordG::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4> > ListAlphaRefG::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > ListNormalG::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > ListDefaultStandardSM::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > ListDefaultTangentSM::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > ListAlphaRefSM::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > ListSphereMapSM::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4> > ListUnlitSM::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4> > ListDetailSM::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > ListBlendTransparent::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > ListAdditiveTransparent::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, core::vector3df, core::vector3df> > ListBlendTransparentFog::Arguments;
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, core::vector3df, core::vector3df> > ListAdditiveTransparentFog::Arguments;

View File

@ -8,6 +8,7 @@
#include <IMesh.h>
#include "../lib/irrlicht/source/Irrlicht/CMeshSceneNode.h"
#include <tuple>
#include <vector>
enum GeometricMaterial
@ -70,6 +71,31 @@ bool isObject(video::E_MATERIAL_TYPE type);
core::vector3df getWind();
// Pass 1 shader (ie shaders that outputs normals and depth)
class ListDefaultStandardG
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
};
class ListDefault2TCoordG
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
};
class ListAlphaRefG
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, core::matrix4> > Arguments;
};
class ListNormalG
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
};
template<enum GeometricMaterial T>
class GroupedFPSM
{
@ -94,20 +120,80 @@ std::vector<core::matrix4> GroupedFPSM<T>::TIMVSet;
template<typename Shader, typename...uniforms>
void draw(const GLMesh &mesh, uniforms... Args)
void draw(const GLMesh *mesh, uniforms... Args)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
GLenum ptype = mesh->PrimitiveType;
GLenum itype = mesh->IndexType;
size_t count = mesh->IndexCount;
Shader::setUniforms(Args...);
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex);
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, mesh->vaoBaseVertex);
}
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)
class ListDefaultStandardSM
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
};
class ListDefaultTangentSM
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
};
class ListAlphaRefSM
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
};
class ListSphereMapSM
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, video::SColorf> > Arguments;
};
class ListUnlitSM
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4> > Arguments;
};
class ListDetailSM
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4> > Arguments;
};
class ListBlendTransparent
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
};
class ListAdditiveTransparent
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4> > Arguments;
};
class ListBlendTransparentFog
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, core::vector3df, core::vector3df> > Arguments;
};
class ListAdditiveTransparentFog
{
public:
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, core::vector3df, core::vector3df> > Arguments;
};
template<enum ShadedMaterial T>
class GroupedSM
{
@ -157,8 +243,6 @@ template<enum TransparentMaterial T>
std::vector<core::matrix4> TransparentMeshes<T>::MVPSet;
// Forward pass (for transparents meshes)
void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
void drawBubble(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
GeometricMaterial MaterialTypeToGeometricMaterial(video::E_MATERIAL_TYPE, video::E_VERTEX_TYPE);

View File

@ -268,7 +268,7 @@ void STKMeshSceneNode::render()
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
MeshShader::ObjectPass1Shader::setUniforms(AbsoluteTransformation, invmodel, 0);
MeshShader::ObjectPass1Shader::setUniforms(AbsoluteTransformation, invmodel);
assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);
@ -281,32 +281,16 @@ void STKMeshSceneNode::render()
GLMesh* mesh;
for_in(mesh, GeometricMesh[FPSM_DEFAULT_STANDARD])
{
GroupedFPSM<FPSM_DEFAULT_STANDARD>::MeshSet.push_back(mesh);
GroupedFPSM<FPSM_DEFAULT_STANDARD>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_DEFAULT_STANDARD>::TIMVSet.push_back(invmodel);
}
ListDefaultStandardG::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, invmodel));
for_in(mesh, GeometricMesh[FPSM_DEFAULT_2TCOORD])
{
GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MeshSet.push_back(mesh);
GroupedFPSM<FPSM_DEFAULT_2TCOORD>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_DEFAULT_2TCOORD>::TIMVSet.push_back(invmodel);
}
ListDefault2TCoordG::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, invmodel));
for_in(mesh, GeometricMesh[FPSM_ALPHA_REF_TEXTURE])
{
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet.push_back(mesh);
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::TIMVSet.push_back(invmodel);
}
ListAlphaRefG::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix));
for_in(mesh, GeometricMesh[FPSM_NORMAL_MAP])
{
GroupedFPSM<FPSM_NORMAL_MAP>::MeshSet.push_back(mesh);
GroupedFPSM<FPSM_NORMAL_MAP>::MVPSet.push_back(AbsoluteTransformation);
GroupedFPSM<FPSM_NORMAL_MAP>::TIMVSet.push_back(invmodel);
}
ListNormalG::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, invmodel));
if (!GeometricMesh[FPSM_GRASS].empty())
glUseProgram(MeshShader::GrassPass1Shader::Program);
@ -348,32 +332,16 @@ void STKMeshSceneNode::render()
GLMesh* mesh;
for_in(mesh, ShadedMesh[SM_DEFAULT_STANDARD])
{
GroupedSM<SM_DEFAULT_STANDARD>::MeshSet.push_back(mesh);
GroupedSM<SM_DEFAULT_STANDARD>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_DEFAULT_STANDARD>::TIMVSet.push_back(invmodel);
}
ListDefaultStandardSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
for_in(mesh, ShadedMesh[SM_DEFAULT_TANGENT])
{
GroupedSM<SM_DEFAULT_TANGENT>::MeshSet.push_back(mesh);
GroupedSM<SM_DEFAULT_TANGENT>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_DEFAULT_TANGENT>::TIMVSet.push_back(invmodel);
}
ListDefaultTangentSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
for_in(mesh, ShadedMesh[SM_ALPHA_REF_TEXTURE])
{
GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet.push_back(mesh);
GroupedSM<SM_ALPHA_REF_TEXTURE>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_ALPHA_REF_TEXTURE>::TIMVSet.push_back(invmodel);
}
ListAlphaRefSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
for_in(mesh, ShadedMesh[SM_SPHEREMAP])
{
GroupedSM<SM_SPHEREMAP>::MeshSet.push_back(mesh);
GroupedSM<SM_SPHEREMAP>::MVPSet.push_back(AbsoluteTransformation);
GroupedSM<SM_SPHEREMAP>::TIMVSet.push_back(invmodel);
}
ListSphereMapSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, invmodel, irr_driver->getSceneManager()->getAmbientLight()));
for_in(mesh, ShadedMesh[SM_SPLATTING])
{
@ -383,18 +351,10 @@ void STKMeshSceneNode::render()
}
for_in(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);
}
ListUnlitSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation));
for_in(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);
}
ListDetailSM::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation));
if (!ShadedMesh[SM_GRASS].empty())
glUseProgram(MeshShader::GrassPass2Shader::Program);
@ -455,7 +415,7 @@ void STKMeshSceneNode::render()
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::TransparentFogShader::setUniforms(AbsoluteTransformation, mesh.TextureMatrix, fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition(), 0);
MeshShader::TransparentFogShader::setUniforms(AbsoluteTransformation, mesh.TextureMatrix, fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition());
assert(mesh.vao);
glBindVertexArray(mesh.vao);
@ -475,9 +435,9 @@ void STKMeshSceneNode::render()
size_t count = mesh.IndexCount;
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
setTexture(MeshShader::TransparentShader::TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::TransparentShader::setUniforms(AbsoluteTransformation, mesh.TextureMatrix, 0);
MeshShader::TransparentShader::setUniforms(AbsoluteTransformation, mesh.TextureMatrix);
assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);
@ -489,16 +449,40 @@ void STKMeshSceneNode::render()
GLMesh* mesh;
for_in(mesh, TransparentMesh[TM_DEFAULT])
if (World::getWorld() && World::getWorld()->isFogEnabled())
{
TransparentMeshes<TM_DEFAULT>::MeshSet.push_back(mesh);
TransparentMeshes<TM_DEFAULT>::MVPSet.push_back(AbsoluteTransformation);
}
const Track * const track = World::getWorld()->getTrack();
for_in(mesh, TransparentMesh[TM_ADDITIVE])
// Todo : put everything in a ubo
const float fogmax = track->getFogMax();
const float startH = track->getFogStartHeight();
const float endH = track->getFogEndHeight();
const float start = track->getFogStart();
const float end = track->getFogEnd();
const video::SColor tmpcol = track->getFogColor();
core::vector3df col(tmpcol.getRed() / 255.0f,
tmpcol.getGreen() / 255.0f,
tmpcol.getBlue() / 255.0f);
for_in(mesh, TransparentMesh[TM_DEFAULT])
ListBlendTransparentFog::Arguments.push_back(
std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix,
fogmax, startH, endH, start, end, col,
Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition()));
for_in(mesh, TransparentMesh[TM_ADDITIVE])
ListAdditiveTransparentFog::Arguments.push_back(
std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix,
fogmax, startH, endH, start, end, col,
Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition()));
}
else
{
TransparentMeshes<TM_ADDITIVE>::MeshSet.push_back(mesh);
TransparentMeshes<TM_ADDITIVE>::MVPSet.push_back(AbsoluteTransformation);
for_in(mesh, TransparentMesh[TM_DEFAULT])
ListBlendTransparent::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
for_in(mesh, TransparentMesh[TM_ADDITIVE])
ListAdditiveTransparent::Arguments.push_back(std::make_tuple(mesh, AbsoluteTransformation, mesh->TextureMatrix));
}
if (!TransparentMesh[TM_BUBBLE].empty())