SunLight: Use DepthBuffer
This commit is contained in:
parent
ecac127dd6
commit
dbcf60003b
@ -1,5 +1,6 @@
|
||||
#version 130
|
||||
uniform sampler2D ntex;
|
||||
uniform sampler2D dtex;
|
||||
//uniform sampler2D cloudtex;
|
||||
|
||||
uniform vec3 direction;
|
||||
@ -14,7 +15,7 @@ out vec4 Spec;
|
||||
out vec4 SpecularMap;
|
||||
|
||||
void main() {
|
||||
float z = texture(ntex, uv).a;
|
||||
float z = texture(dtex, uv).x;
|
||||
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
|
||||
xpos = invproj * xpos;
|
||||
xpos.xyz /= xpos.w;
|
||||
|
@ -335,9 +335,9 @@ void PostProcessing::renderSunlight()
|
||||
|
||||
glUseProgram(FullScreenShader::SunLightShader::Program);
|
||||
glBindVertexArray(FullScreenShader::SunLightShader::vao);
|
||||
GLuint ntex_id = static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName();
|
||||
setTexture(0, ntex_id, GL_NEAREST, GL_NEAREST);
|
||||
FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0);
|
||||
setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
|
||||
setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST);
|
||||
FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
@ -1146,6 +1146,7 @@ namespace FullScreenShader
|
||||
|
||||
GLuint SunLightShader::Program;
|
||||
GLuint SunLightShader::uniform_ntex;
|
||||
GLuint SunLightShader::uniform_dtex;
|
||||
GLuint SunLightShader::uniform_direction;
|
||||
GLuint SunLightShader::uniform_col;
|
||||
GLuint SunLightShader::uniform_invproj;
|
||||
@ -1155,18 +1156,21 @@ namespace FullScreenShader
|
||||
{
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/sunlight.frag").c_str());
|
||||
uniform_ntex = glGetUniformLocation(Program, "ntex");
|
||||
uniform_dtex = glGetUniformLocation(Program, "dtex");
|
||||
uniform_direction = glGetUniformLocation(Program, "direction");
|
||||
uniform_col = glGetUniformLocation(Program, "col");
|
||||
uniform_invproj = glGetUniformLocation(Program, "invproj");
|
||||
vao = createVAO(Program);
|
||||
printf("uniform %d\n", uniform_ntex);
|
||||
}
|
||||
|
||||
void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex)
|
||||
void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex)
|
||||
{
|
||||
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
|
||||
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
|
||||
glUniform3f(uniform_col, r, g, b);
|
||||
glUniform1i(uniform_ntex, TU_ntex);
|
||||
glUniform1i(uniform_dtex, TU_dtex);
|
||||
}
|
||||
|
||||
GLuint LightBlendShader::Program;
|
||||
|
@ -334,11 +334,11 @@ class SunLightShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint uniform_ntex, uniform_direction, uniform_col, uniform_invproj;
|
||||
static GLuint uniform_ntex, uniform_dtex, uniform_direction, uniform_col, uniform_invproj;
|
||||
static GLuint vao;
|
||||
|
||||
static void init();
|
||||
static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex);
|
||||
static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex);
|
||||
};
|
||||
|
||||
class LightBlendShader
|
||||
|
Loading…
Reference in New Issue
Block a user