Factorize transparent shaders.
This commit is contained in:
parent
8ec57b7683
commit
c71a2c131f
@ -717,16 +717,16 @@ void IrrDriver::renderTransparent()
|
||||
if (World::getWorld() && World::getWorld()->isFogEnabled())
|
||||
{
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
// renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>({ MeshShader::TransparentFogShader::TU_tex }, ListBlendTransparentFog::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>(MeshShader::TransparentFogShaderInstance, { MeshShader::TransparentFogShaderInstance->TU_tex }, ListBlendTransparentFog::Arguments);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
// renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>({ MeshShader::TransparentFogShader::TU_tex }, ListAdditiveTransparentFog::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>(MeshShader::TransparentFogShaderInstance, { MeshShader::TransparentFogShaderInstance->TU_tex }, ListAdditiveTransparentFog::Arguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
// renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>({ MeshShader::TransparentShader::TU_tex }, ListBlendTransparent::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>(MeshShader::TransparentShaderInstance, { MeshShader::TransparentShaderInstance->TU_tex }, ListBlendTransparent::Arguments);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
// renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>({ MeshShader::TransparentShader::TU_tex }, ListAdditiveTransparent::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>(MeshShader::TransparentShaderInstance, { MeshShader::TransparentShaderInstance->TU_tex }, ListAdditiveTransparent::Arguments);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,8 +343,8 @@ void Shaders::loadShaders()
|
||||
MeshShader::GrassPass1Shader::init();
|
||||
MeshShader::GrassPass2Shader::init();
|
||||
MeshShader::BubbleShader::init();
|
||||
MeshShader::TransparentShader::init();
|
||||
MeshShader::TransparentFogShader::init();
|
||||
MeshShader::TransparentShaderInstance = new MeshShader::TransparentShader();
|
||||
MeshShader::TransparentFogShaderInstance = new MeshShader::TransparentFogShader();
|
||||
MeshShader::BillboardShader::init();
|
||||
LightShader::PointLightShader::init();
|
||||
MeshShader::DisplaceShader::init();
|
||||
@ -474,6 +474,11 @@ void glUniform3fWraper(GLuint a, float b, float c, float d)
|
||||
glUniform3f(a, b, c, d);
|
||||
}
|
||||
|
||||
void glUniform1fWrapper(GLuint a, float b)
|
||||
{
|
||||
glUniform1f(a, b);
|
||||
}
|
||||
|
||||
namespace MeshShader
|
||||
{
|
||||
|
||||
@ -931,18 +936,12 @@ namespace MeshShader
|
||||
glUniform1f(uniform_transparency, transparency);
|
||||
}
|
||||
|
||||
GLuint TransparentShader::Program;
|
||||
GLuint TransparentShader::uniform_MVP;
|
||||
GLuint TransparentShader::uniform_TM;
|
||||
GLuint TransparentShader::TU_tex;
|
||||
|
||||
void TransparentShader::init()
|
||||
TransparentShader::TransparentShader()
|
||||
{
|
||||
Program = LoadProgram(
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparent.frag").c_str());
|
||||
uniform_MVP = glGetUniformLocation(Program, "ModelMatrix");
|
||||
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
|
||||
AssignUniforms(Program, uniforms, {"ModelMatrix", "TextureMatrix" });
|
||||
if (!UserConfigParams::m_ubo_disabled)
|
||||
{
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
@ -953,36 +952,14 @@ namespace MeshShader
|
||||
AssignTextureUnit(Program, { { TU_tex, "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());
|
||||
}
|
||||
TransparentShader *TransparentShaderInstance;
|
||||
|
||||
GLuint TransparentFogShader::Program;
|
||||
GLuint TransparentFogShader::uniform_MVP;
|
||||
GLuint TransparentFogShader::uniform_TM;
|
||||
GLuint TransparentFogShader::TU_tex;
|
||||
GLuint TransparentFogShader::uniform_fogmax;
|
||||
GLuint TransparentFogShader::uniform_startH;
|
||||
GLuint TransparentFogShader::uniform_endH;
|
||||
GLuint TransparentFogShader::uniform_start;
|
||||
GLuint TransparentFogShader::uniform_end;
|
||||
GLuint TransparentFogShader::uniform_col;
|
||||
|
||||
void TransparentFogShader::init()
|
||||
TransparentFogShader::TransparentFogShader()
|
||||
{
|
||||
Program = LoadProgram(
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparentfog.frag").c_str());
|
||||
uniform_MVP = glGetUniformLocation(Program, "ModelMatrix");
|
||||
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
|
||||
uniform_fogmax = glGetUniformLocation(Program, "fogmax");
|
||||
uniform_startH = glGetUniformLocation(Program, "startH");
|
||||
uniform_endH = glGetUniformLocation(Program, "endH");
|
||||
uniform_start = glGetUniformLocation(Program, "start");
|
||||
uniform_end = glGetUniformLocation(Program, "end");
|
||||
uniform_col = glGetUniformLocation(Program, "col");
|
||||
AssignUniforms(Program, uniforms, { "ModelMatrix", "TextureMatrix", "fogmax", "startH", "endH", "start", "end", "col" });
|
||||
if (!UserConfigParams::m_ubo_disabled)
|
||||
{
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
@ -993,17 +970,7 @@ namespace MeshShader
|
||||
AssignTextureUnit(Program, { { TU_tex, "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());
|
||||
glUniform1f(uniform_fogmax, fogmax);
|
||||
glUniform1f(uniform_startH, startH);
|
||||
glUniform1f(uniform_endH, endH);
|
||||
glUniform1f(uniform_start, start);
|
||||
glUniform1f(uniform_end, end);
|
||||
glUniform3f(uniform_col, col.X, col.Y, col.Z);
|
||||
}
|
||||
TransparentFogShader *TransparentFogShaderInstance;
|
||||
|
||||
GLuint BillboardShader::Program;
|
||||
GLuint BillboardShader::attrib_corner;
|
||||
|
@ -74,6 +74,15 @@ void setUniformsHelper(const std::vector<GLuint> &uniforms, const video::SColorf
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
void glUniform1fWrapper(GLuint, float);
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
void setUniformsHelper(const std::vector<GLuint> &uniforms, float f, Args... arg)
|
||||
{
|
||||
glUniform1fWrapper(uniforms[N], f);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
void bypassUBO(GLuint Program);
|
||||
|
||||
template<typename... Args>
|
||||
@ -277,28 +286,26 @@ public:
|
||||
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex, float time, float transparency);
|
||||
};
|
||||
|
||||
class TransparentShader
|
||||
class TransparentShader : public ShaderHelper<core::matrix4, core::matrix4>
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint uniform_MVP, uniform_TM;
|
||||
static GLuint TU_tex;
|
||||
GLuint TU_tex;
|
||||
|
||||
static void init();
|
||||
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix);
|
||||
TransparentShader();
|
||||
};
|
||||
|
||||
class TransparentFogShader
|
||||
extern TransparentShader *TransparentShaderInstance;
|
||||
|
||||
class TransparentFogShader : public ShaderHelper<core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf>
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint uniform_MVP, uniform_TM, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col;
|
||||
static GLuint TU_tex;
|
||||
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);
|
||||
TransparentFogShader();
|
||||
};
|
||||
|
||||
extern TransparentFogShader *TransparentFogShaderInstance;
|
||||
|
||||
class BillboardShader
|
||||
{
|
||||
public:
|
||||
|
@ -201,20 +201,18 @@ void STKAnimatedMesh::render()
|
||||
const float end = track->getFogEnd();
|
||||
const video::SColor tmpcol = track->getFogColor();
|
||||
|
||||
core::vector3df col(tmpcol.getRed() / 255.0f,
|
||||
video::SColorf 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()));
|
||||
fogmax, startH, endH, start, end, col));
|
||||
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()));
|
||||
fogmax, startH, endH, start, end, col));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -378,5 +378,5 @@ std::vector<std::tuple<GLMesh *, core::matrix4> > ListUnlitSM::Arguments;
|
||||
std::vector<std::tuple<GLMesh *, core::matrix4, video::SColorf> > 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;
|
||||
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf> > ListBlendTransparentFog::Arguments;
|
||||
std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf> > ListAdditiveTransparentFog::Arguments;
|
||||
|
@ -203,13 +203,13 @@ public:
|
||||
class ListBlendTransparentFog
|
||||
{
|
||||
public:
|
||||
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, core::vector3df, core::vector3df> > Arguments;
|
||||
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf> > Arguments;
|
||||
};
|
||||
|
||||
class ListAdditiveTransparentFog
|
||||
{
|
||||
public:
|
||||
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, core::vector3df, core::vector3df> > Arguments;
|
||||
static std::vector<std::tuple<GLMesh *, core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf> > Arguments;
|
||||
};
|
||||
|
||||
template<enum ShadedMaterial T>
|
||||
|
@ -391,7 +391,7 @@ void STKMeshSceneNode::render()
|
||||
|
||||
if (World::getWorld() && World::getWorld()->isFogEnabled())
|
||||
{
|
||||
glUseProgram(MeshShader::TransparentFogShader::Program);
|
||||
glUseProgram(MeshShader::TransparentFogShaderInstance->Program);
|
||||
for (unsigned i = 0; i < GLmeshes.size(); i++)
|
||||
{
|
||||
GLMesh &mesh = GLmeshes[i];
|
||||
@ -410,13 +410,13 @@ void STKMeshSceneNode::render()
|
||||
const float end = track->getFogEnd();
|
||||
const video::SColor tmpcol = track->getFogColor();
|
||||
|
||||
core::vector3df col(tmpcol.getRed() / 255.0f,
|
||||
video::SColorf col(tmpcol.getRed() / 255.0f,
|
||||
tmpcol.getGreen() / 255.0f,
|
||||
tmpcol.getBlue() / 255.0f);
|
||||
|
||||
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());
|
||||
MeshShader::TransparentFogShaderInstance->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, fogmax, startH, endH, start, end, col);
|
||||
|
||||
assert(mesh.vao);
|
||||
glBindVertexArray(mesh.vao);
|
||||
@ -426,7 +426,7 @@ void STKMeshSceneNode::render()
|
||||
}
|
||||
else
|
||||
{
|
||||
glUseProgram(MeshShader::TransparentShader::Program);
|
||||
glUseProgram(MeshShader::TransparentShaderInstance->Program);
|
||||
for (unsigned i = 0; i < GLmeshes.size(); i++)
|
||||
{
|
||||
irr_driver->IncreaseObjectCount();
|
||||
@ -436,9 +436,9 @@ void STKMeshSceneNode::render()
|
||||
size_t count = mesh.IndexCount;
|
||||
|
||||
compressTexture(mesh.textures[0], true);
|
||||
setTexture(MeshShader::TransparentShader::TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||
setTexture(MeshShader::TransparentShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||
|
||||
MeshShader::TransparentShader::setUniforms(AbsoluteTransformation, mesh.TextureMatrix);
|
||||
MeshShader::TransparentShaderInstance->setUniforms(AbsoluteTransformation, mesh.TextureMatrix);
|
||||
assert(mesh.vao);
|
||||
glBindVertexArray(mesh.vao);
|
||||
glDrawElements(ptype, count, itype, 0);
|
||||
@ -462,20 +462,18 @@ void STKMeshSceneNode::render()
|
||||
const float end = track->getFogEnd();
|
||||
const video::SColor tmpcol = track->getFogColor();
|
||||
|
||||
core::vector3df col(tmpcol.getRed() / 255.0f,
|
||||
video::SColorf 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()));
|
||||
fogmax, startH, endH, start, end, col));
|
||||
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()));
|
||||
fogmax, startH, endH, start, end, col));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user