Shadow: Support for alpha tested meshes.
This commit is contained in:
parent
19d490a26d
commit
18896ff95e
@ -259,6 +259,7 @@ void Shaders::loadShaders()
|
||||
MeshShader::BillboardShader::init();
|
||||
MeshShader::DisplaceShader::init();
|
||||
MeshShader::ShadowShader::init();
|
||||
MeshShader::RefShadowShader::init();
|
||||
ParticleShader::FlipParticleRender::init();
|
||||
ParticleShader::HeightmapSimulationShader::init();
|
||||
ParticleShader::SimpleParticleRender::init();
|
||||
@ -891,6 +892,27 @@ namespace MeshShader
|
||||
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
|
||||
}
|
||||
|
||||
GLuint RefShadowShader::Program;
|
||||
GLuint RefShadowShader::attrib_position;
|
||||
GLuint RefShadowShader::attrib_texcoord;
|
||||
GLuint RefShadowShader::uniform_MVP;
|
||||
GLuint RefShadowShader::uniform_tex;
|
||||
|
||||
void RefShadowShader::init()
|
||||
{
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/object_unlit.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
|
||||
uniform_tex = glGetUniformLocation(Program, "tex");
|
||||
}
|
||||
|
||||
void RefShadowShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex)
|
||||
{
|
||||
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
|
||||
glUniform1i(uniform_tex, TU_tex);
|
||||
}
|
||||
|
||||
GLuint DisplaceShader::Program;
|
||||
GLuint DisplaceShader::attrib_position;
|
||||
GLuint DisplaceShader::attrib_texcoord;
|
||||
|
@ -236,6 +236,17 @@ public:
|
||||
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix);
|
||||
};
|
||||
|
||||
class RefShadowShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint attrib_position, attrib_texcoord;
|
||||
static GLuint uniform_MVP, uniform_tex;
|
||||
|
||||
static void init();
|
||||
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex);
|
||||
};
|
||||
|
||||
class DisplaceShader
|
||||
{
|
||||
public:
|
||||
|
@ -723,17 +723,28 @@ void STKMesh::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
|
||||
return;
|
||||
}
|
||||
|
||||
void STKMesh::drawShadow(const GLMesh &mesh)
|
||||
void STKMesh::drawShadow(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
|
||||
{
|
||||
|
||||
GLenum ptype = mesh.PrimitiveType;
|
||||
GLenum itype = mesh.IndexType;
|
||||
size_t count = mesh.IndexCount;
|
||||
assert(irr_driver->getPhase() == SHADOW_PASS);
|
||||
|
||||
|
||||
core::matrix4 ShadowMVP;
|
||||
computeMVP(ShadowMVP);
|
||||
glUseProgram(MeshShader::ShadowShader::Program);
|
||||
MeshShader::ShadowShader::setUniforms(ShadowMVP);
|
||||
|
||||
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
|
||||
{
|
||||
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||
glUseProgram(MeshShader::RefShadowShader::Program);
|
||||
MeshShader::RefShadowShader::setUniforms(ShadowMVP, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
glUseProgram(MeshShader::ShadowShader::Program);
|
||||
MeshShader::ShadowShader::setUniforms(ShadowMVP);
|
||||
}
|
||||
glBindVertexArray(mesh.vao_shadow_pass);
|
||||
glDrawElements(ptype, count, itype, 0);
|
||||
}
|
||||
@ -928,7 +939,14 @@ void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
|
||||
case SHADOW_PASS:
|
||||
if (mesh.vao_shadow_pass)
|
||||
return;
|
||||
mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride);
|
||||
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
|
||||
{
|
||||
mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::RefShadowShader::attrib_position, MeshShader::RefShadowShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
|
||||
}
|
||||
else
|
||||
{
|
||||
mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -984,7 +1002,7 @@ void STKMesh::render()
|
||||
else if (irr_driver->getPhase() == SHADOW_PASS)
|
||||
{
|
||||
initvaostate(GLmeshes[i], material.MaterialType);
|
||||
drawShadow(GLmeshes[i]);
|
||||
drawShadow(GLmeshes[i], material.MaterialType);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ protected:
|
||||
// Misc passes shaders (glow, displace...)
|
||||
void drawGlow(const GLMesh &mesh);
|
||||
void drawDisplace(const GLMesh &mesh);
|
||||
void drawShadow(const GLMesh &mesh);
|
||||
void drawShadow(const GLMesh &mesh, video::E_MATERIAL_TYPE type);
|
||||
void createGLMeshes();
|
||||
void cleanGLMeshes();
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user