Fog: Do not use camposition in the shader.

This commit is contained in:
Vincent Lejeune 2014-02-03 19:35:37 +01:00
parent 57b38b4371
commit 6e93178d68
5 changed files with 14 additions and 19 deletions

View File

@ -7,7 +7,6 @@ uniform float endH;
uniform float start;
uniform float end;
uniform vec3 col;
uniform vec3 campos;
uniform mat4 ipvmat;
in vec2 uv;
@ -24,9 +23,8 @@ void main()
xpos = ipvmat * xpos;
xpos.xyz /= xpos.w;
float dist = distance(campos, xpos.xyz);
float dist = length(xpos.xyz);
float fog = smoothstep(start, end, dist);
fog *= 1.0 - smoothstep(startH, endH, xpos.y);
fog = min(fog, fogmax);

View File

@ -495,7 +495,7 @@ void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matri
glEnable(GL_DEPTH_TEST);
}
void PostProcessing::renderFog(const core::vector3df &campos, const core::matrix4 &ipvmat)
void PostProcessing::renderFog(const core::matrix4 &ipvmat)
{
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
const Track * const track = World::getWorld()->getTrack();
@ -521,7 +521,7 @@ void PostProcessing::renderFog(const core::vector3df &campos, const core::matrix
glBindVertexArray(FullScreenShader::FogShader::vao);
setTexture(0, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST);
FullScreenShader::FogShader::setUniforms(ipvmat, fogmax, startH, endH, start, end, col, campos, 0);
FullScreenShader::FogShader::setUniforms(ipvmat, fogmax, startH, endH, start, end, col, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);

View File

@ -76,7 +76,7 @@ public:
void renderPointlight(const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy);
void renderSunlight();
void renderFog(const core::vector3df &campos, const core::matrix4 &ipvmat);
void renderFog(const core::matrix4 &ipvmat);
void renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm);
/** Blur the in texture */

View File

@ -242,7 +242,7 @@ void IrrDriver::renderGLSL(float dt)
if (World::getWorld()->getTrack()->isFogEnabled())
{
PROFILER_PUSH_CPU_MARKER("- Fog", 0xFF, 0x00, 0x00);
m_post_processing->renderFog(camnode->getAbsolutePosition(), irr_driver->getInvProjViewMatrix());
m_post_processing->renderFog(irr_driver->getInvProjMatrix());
PROFILER_POP_CPU_MARKER();
}

View File

@ -1397,7 +1397,6 @@ namespace FullScreenShader
GLuint FogShader::uniform_start;
GLuint FogShader::uniform_end;
GLuint FogShader::uniform_col;
GLuint FogShader::uniform_campos;
GLuint FogShader::uniform_ipvmat;
GLuint FogShader::vao;
@ -1411,22 +1410,20 @@ namespace FullScreenShader
uniform_start = glGetUniformLocation(Program, "start");
uniform_end = glGetUniformLocation(Program, "end");
uniform_col = glGetUniformLocation(Program, "col");
uniform_campos = glGetUniformLocation(Program, "campos");
uniform_ipvmat = glGetUniformLocation(Program, "ipvmat");
vao = createVAO(Program);
}
void FogShader::setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_ntex)
void FogShader::setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex)
{
glUniform1f(FullScreenShader::FogShader::uniform_fogmax, fogmax);
glUniform1f(FullScreenShader::FogShader::uniform_startH, startH);
glUniform1f(FullScreenShader::FogShader::uniform_endH, endH);
glUniform1f(FullScreenShader::FogShader::uniform_start, start);
glUniform1f(FullScreenShader::FogShader::uniform_end, end);
glUniform3f(FullScreenShader::FogShader::uniform_col, col.X, col.Y, col.Z);
glUniform3f(FullScreenShader::FogShader::uniform_campos, campos.X, campos.Y, campos.Z);
glUniformMatrix4fv(FullScreenShader::FogShader::uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer());
glUniform1i(FullScreenShader::FogShader::uniform_tex, TU_ntex);
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);
glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer());
glUniform1i(uniform_tex, TU_ntex);
}
}