Add Splatting RSM shader type.

This commit is contained in:
Vincent Lejeune 2014-08-08 01:07:55 +02:00
parent 60f76ee612
commit 8db09a55cd
6 changed files with 78 additions and 9 deletions

View File

@ -8,6 +8,7 @@ layout (location = 1) out vec3 RSMNormals;
void main()
{
if (texture(tex, uv).a < .5) discard;
RSMColor = texture(tex, uv).xyz * color.rgb;
RSMNormals = .5 * normalize(nor) + .5;
}

View File

@ -1,22 +1,29 @@
uniform mat4 ModelMatrix;
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
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
layout(location = 2) in vec4 Color;
layout(location = 3) in vec2 Texcoord;
layout(location = 4) in vec2 SecondTexcoord;
#else
in vec3 Position;
in vec3 Normal;
in vec4 Color;
in vec2 Texcoord;
in vec2 SecondTexcoord;
#endif
out vec3 nor;
out vec2 uv;
out vec2 uv_bis;
out vec4 color;
@ -27,5 +34,6 @@ void main(void)
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
nor = (TransposeInverseModel * vec4(Normal, 0.)).xyz;
uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy;
uv_bis = SecondTexcoord;
color = Color.zyxw;
}

View File

@ -0,0 +1,27 @@
uniform sampler2D tex_layout;
uniform sampler2D tex_detail0;
uniform sampler2D tex_detail1;
uniform sampler2D tex_detail2;
uniform sampler2D tex_detail3;
in vec2 uv;
in vec2 uv_bis;
in vec3 nor;
layout (location = 0) out vec3 RSMColor;
layout (location = 1) out vec3 RSMNormals;
void main()
{
vec4 splatting = texture(tex_layout, uv_bis);
vec4 detail0 = texture(tex_detail0, uv);
vec4 detail1 = texture(tex_detail1, uv);
vec4 detail2 = texture(tex_detail2, uv);
vec4 detail3 = texture(tex_detail3, uv);
vec4 splatted = splatting.r * detail0 +
splatting.g * detail1 +
splatting.b * detail2 +
max(0., (1.0 - splatting.r - splatting.g - splatting.b)) * detail3;
RSMColor = splatted.rgb;
RSMNormals = .5 * normalize(nor) + .5;
}

View File

@ -534,10 +534,10 @@ struct rsm_custom_unroll_args<N, List...>
template<enum E_VERTEX_TYPE VertexType, int... Selector, typename... Args>
template<typename T, 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)
{
glUseProgram(MeshShader::RSMShader::getInstance()->Program);
glUseProgram(T::getInstance()->Program);
glBindVertexArray(getVAO(VertexType));
for (unsigned i = 0; i < t.size(); i++)
{
@ -549,7 +549,7 @@ void drawRSM(const core::matrix4 & rsm_matrix, const std::vector<GLuint> Texture
compressTexture(mesh->textures[j], true);
setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
}
rsm_custom_unroll_args<Selector...>::template exec<MeshShader::RSMShader>(rsm_matrix, t[i]);
rsm_custom_unroll_args<Selector...>::template exec<T>(rsm_matrix, t[i]);
}
}
@ -595,10 +595,18 @@ void IrrDriver::renderShadows()
m_rtts->getRSM().Bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawRSM<EVT_STANDARD, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDefault::Arguments);
// drawRSM<EVT_STANDARD, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatAlphaRef::Arguments);
drawRSM<MeshShader::RSMShader, EVT_STANDARD, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDefault::Arguments);
drawRSM<MeshShader::RSMShader, EVT_STANDARD, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatAlphaRef::Arguments);
// drawRSM<EVT_STANDARD, 2, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatSphereMap::Arguments);
drawRSM<EVT_STANDARD, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatUnlit::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);
drawRSM<MeshShader::RSMShader, EVT_STANDARD, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatUnlit::Arguments);
drawRSM<MeshShader::RSMShader, EVT_2TCOORDS, 3, 1>(rsm_matrix, std::vector<GLuint>{ MeshShader::RSMShader::getInstance()->TU_tex }, ListMatDetails::Arguments);
drawRSM<MeshShader::SplattingRSMShader, EVT_2TCOORDS, 1>(rsm_matrix,
std::vector<GLuint>{
8,
MeshShader::SplattingRSMShader::getInstance()->TU_layout,
MeshShader::SplattingRSMShader::getInstance()->TU_detail0,
MeshShader::SplattingRSMShader::getInstance()->TU_detail1,
MeshShader::SplattingRSMShader::getInstance()->TU_detail2,
MeshShader::SplattingRSMShader::getInstance()->TU_detail3},
ListMatSplatting::Arguments);
}

View File

@ -1015,6 +1015,23 @@ namespace MeshShader
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
SplattingRSMShader::SplattingRSMShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/rsm.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/splatting_rsm.frag").c_str());
TU_layout = 0;
TU_detail0 = 1;
TU_detail1 = 2;
TU_detail2 = 3;
TU_detail3 = 4;
AssignUniforms("ModelMatrix", "RSMMatrix");
AssignTextureUnit(Program, TexUnit(TU_layout, "tex_layout"), TexUnit(TU_detail0, "tex_detail0"), TexUnit(TU_detail1, "tex_detail1"), TexUnit(TU_detail2, "tex_detail2"), TexUnit(TU_detail3, "tex_detail3"));
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
InstancedShadowShader::InstancedShadowShader()
{
// Geometry shader needed

View File

@ -339,6 +339,14 @@ public:
RSMShader();
};
class SplattingRSMShader : public ShaderHelperSingleton<SplattingRSMShader, core::matrix4, core::matrix4>
{
public:
GLuint TU_layout, TU_detail0, TU_detail1, TU_detail2, TU_detail3;
SplattingRSMShader();
};
class InstancedShadowShader : public ShaderHelperSingleton<InstancedShadowShader>
{
public: