Add support moving texture in rsm.

This commit is contained in:
Vincent Lejeune 2014-08-07 20:44:33 +02:00
parent e932638aef
commit 95fb3ea580
4 changed files with 46 additions and 36 deletions

View File

@ -2,11 +2,7 @@ uniform mat4 ModelMatrix;
uniform mat4 InverseModelMatrix; uniform mat4 InverseModelMatrix;
uniform mat4 RSMMatrix; uniform mat4 RSMMatrix;
uniform mat4 TextureMatrix = uniform mat4 TextureMatrix;
mat4(1., 0., 0., 0.,
0., 1., 0., 0.,
0., 0., 1., 0.,
0., 0., 0., 1.);
#if __VERSION__ >= 330 #if __VERSION__ >= 330
layout(location = 0) in vec3 Position; layout(location = 0) in vec3 Position;

View File

@ -507,10 +507,37 @@ void renderShadow(const std::vector<GLuint> TextureUnits, const std::vector<STK:
} }
} }
template<enum E_VERTEX_TYPE VertexType, typename... Args>
template<int...List>
struct rsm_custom_unroll_args;
template<>
struct rsm_custom_unroll_args<>
{
template<typename T, typename ...TupleTypes, typename ...Args>
static void exec(const core::matrix4 &rsm_matrix, const STK::Tuple<TupleTypes...> &t, Args... args)
{
draw<T>(T::getInstance(), STK::tuple_get<0>(t), rsm_matrix, args...);
}
};
template<int N, int...List>
struct rsm_custom_unroll_args<N, List...>
{
template<typename T, typename ...TupleTypes, typename ...Args>
static void exec(const core::matrix4 &rsm_matrix, const STK::Tuple<TupleTypes...> &t, Args... args)
{
rsm_custom_unroll_args<List...>::template exec<T>(rsm_matrix, t, STK::tuple_get<N>(t), args...);
}
};
template<enum E_VERTEX_TYPE VertexType, int... Selector, typename... Args>
void drawRSM(const core::matrix4 & rsm_matrix, const std::vector<GLuint> TextureUnits, const std::vector<STK::Tuple<GLMesh *, core::matrix4, Args...> >&t) void drawRSM(const core::matrix4 & rsm_matrix, const std::vector<GLuint> TextureUnits, const std::vector<STK::Tuple<GLMesh *, core::matrix4, Args...> >&t)
{ {
glUseProgram(MeshShader::RSMShader::Program); glUseProgram(MeshShader::RSMShader::getInstance()->Program);
glBindVertexArray(getVAO(VertexType)); glBindVertexArray(getVAO(VertexType));
for (unsigned i = 0; i < t.size(); i++) for (unsigned i = 0; i < t.size(); i++)
{ {
@ -522,7 +549,7 @@ void drawRSM(const core::matrix4 & rsm_matrix, const std::vector<GLuint> Texture
compressTexture(mesh->textures[j], true); compressTexture(mesh->textures[j], true);
setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
} }
draw<MeshShader::RSMShader>(mesh, rsm_matrix, STK::tuple_get<1>(t[i])); rsm_custom_unroll_args<Selector...>::exec<MeshShader::RSMShader>(rsm_matrix, t[i]);
} }
} }
@ -568,9 +595,10 @@ void IrrDriver::renderShadows()
m_rtts->getRSM().Bind(); m_rtts->getRSM().Bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawRSM<EVT_STANDARD>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::TU_tex }, ListMatDefault::Arguments); drawRSM<EVT_STANDARD, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDefault::Arguments);
drawRSM<EVT_STANDARD>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::TU_tex }, ListMatSphereMap::Arguments); // drawRSM<EVT_STANDARD, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatAlphaRef::Arguments);
drawRSM<EVT_STANDARD>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::TU_tex }, ListMatUnlit::Arguments); // drawRSM<EVT_STANDARD, 2, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatSphereMap::Arguments);
drawRSM<EVT_2TCOORDS>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::TU_tex }, ListMatDetails::Arguments); drawRSM<EVT_STANDARD, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatUnlit::Arguments);
drawRSM<EVT_2TCOORDS>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::TU_tex }, ListMatSplatting::Arguments); drawRSM<EVT_2TCOORDS, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDetails::Arguments);
drawRSM<EVT_2TCOORDS, 2, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatSplatting::Arguments);
} }

View File

@ -402,7 +402,6 @@ void Shaders::loadShaders()
FullScreenShader::MLAAGatherSHader::init(); FullScreenShader::MLAAGatherSHader::init();
MeshShader::BubbleShader::init(); MeshShader::BubbleShader::init();
LightShader::PointLightShader::init(); LightShader::PointLightShader::init();
MeshShader::RSMShader::init();
MeshShader::SkyboxShader::init(); MeshShader::SkyboxShader::init();
MeshShader::ViewFrustrumShader::init(); MeshShader::ViewFrustrumShader::init();
ParticleShader::FlipParticleRender::init(); ParticleShader::FlipParticleRender::init();
@ -1003,27 +1002,17 @@ namespace MeshShader
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
} }
GLuint RSMShader::Program; RSMShader::RSMShader()
GLuint RSMShader::uniform_MM;
GLuint RSMShader::uniform_RSMMatrix;
GLuint RSMShader::TU_tex;
void RSMShader::init()
{ {
if (irr_driver->getGLSLVersion() < 150)
return;
Program = LoadProgram( Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/rsm.vert").c_str(), GL_VERTEX_SHADER, file_manager->getAsset("shaders/rsm.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/rsm.frag").c_str()); GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/rsm.frag").c_str());
uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); TU_tex = 0;
uniform_RSMMatrix = glGetUniformLocation(Program, "RSMMatrix"); AssignUniforms("ModelMatrix", "RSMMatrix", "TextureMatrix");
AssignTextureUnit(Program, { TexUnit(TU_tex, "tex") }); AssignTextureUnit(Program, TexUnit(TU_tex, "tex"));
}
void RSMShader::setUniforms(const core::matrix4 &RSMMatrix, const core::matrix4 &ModelMatrix) GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
{ glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
glUniformMatrix4fv(uniform_RSMMatrix, 1, GL_FALSE, RSMMatrix.pointer());
glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
} }
InstancedShadowShader::InstancedShadowShader() InstancedShadowShader::InstancedShadowShader()

View File

@ -331,15 +331,12 @@ public:
ShadowShader(); ShadowShader();
}; };
class RSMShader class RSMShader : public ShaderHelperSingleton<RSMShader, core::matrix4, core::matrix4, core::matrix4>
{ {
public: public:
static GLuint Program; GLuint TU_tex;
static GLuint uniform_MM, uniform_RSMMatrix;
static GLuint TU_tex;
static void init(); RSMShader();
static void setUniforms(const core::matrix4 &RSMMatrix, const core::matrix4 &ModelMatrix);
}; };
class InstancedShadowShader : public ShaderHelperSingleton<InstancedShadowShader> class InstancedShadowShader : public ShaderHelperSingleton<InstancedShadowShader>