Modelise Beer Lambert absorption for fog

This commit is contained in:
Vincent Lejeune 2014-11-20 21:23:33 +01:00
parent 10ffb5411e
commit a78b889b05
5 changed files with 18 additions and 15 deletions

View File

@ -15,7 +15,9 @@ void main()
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix); vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
float dist = length(xpos.xyz); float dist = length(xpos.xyz);
vec3 fog = col * (1. - exp(- density * dist)); float factor = (1. - exp(- density * dist));
vec3 fog = col * factor;
FragColor = vec4(fog, 1.); // fog is scattering component, factor is the beer lambert absorption
FragColor = vec4(fog, factor);
} }

View File

@ -7,7 +7,7 @@ uniform float sigma;
layout (local_size_x = 8, local_size_y = 8) in; layout (local_size_x = 8, local_size_y = 8) in;
shared vec3 local_src[8 + 2 * 6][8]; shared vec4 local_src[8 + 2 * 6][8];
void main() void main()
{ {
@ -17,9 +17,9 @@ void main()
vec2 uv = iuv * pixel; vec2 uv = iuv * pixel;
vec2 uv_p = (iuv + ivec2(6, 0)) * pixel; vec2 uv_p = (iuv + ivec2(6, 0)) * pixel;
local_src[x][y] = texture(source, uv_m).rgb; local_src[x][y] = texture(source, uv_m);
local_src[x + 6][y] = texture(source, uv).rgb; local_src[x + 6][y] = texture(source, uv);
local_src[x + 12][y] = texture(source, uv_p).rgb; local_src[x + 12][y] = texture(source, uv_p);
barrier(); barrier();
@ -27,7 +27,7 @@ void main()
g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma); g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma);
g1 = exp(-0.5 / (sigma * sigma)); g1 = exp(-0.5 / (sigma * sigma));
g2 = g1 * g1; g2 = g1 * g1;
vec3 sum = local_src[x + 6][y] * g0; vec4 sum = local_src[x + 6][y] * g0;
g0 *= g1; g0 *= g1;
g1 *= g2; g1 *= g2;
for (int i = 1; i < 6; i++) { for (int i = 1; i < 6; i++) {
@ -37,5 +37,5 @@ void main()
g1 *= g2; g1 *= g2;
} }
imageStore(dest, iuv, vec4(sum, 0.)); imageStore(dest, iuv, sum);
} }

View File

@ -7,7 +7,7 @@ uniform float sigma;
layout (local_size_x = 8, local_size_y = 8) in; layout (local_size_x = 8, local_size_y = 8) in;
shared vec3 local_src[8][8 + 2 * 6]; shared vec4 local_src[8][8 + 2 * 6];
void main() void main()
{ {
@ -17,9 +17,9 @@ void main()
vec2 uv = iuv * pixel; vec2 uv = iuv * pixel;
vec2 uv_p = (iuv + ivec2(0, 6)) * pixel; vec2 uv_p = (iuv + ivec2(0, 6)) * pixel;
local_src[x][y] = texture(source, uv_m).rgb; local_src[x][y] = texture(source, uv_m);
local_src[x][y + 6] = texture(source, uv).rgb; local_src[x][y + 6] = texture(source, uv);
local_src[x][y + 12] = texture(source, uv_p).rgb; local_src[x][y + 12] = texture(source, uv_p);
barrier(); barrier();
@ -27,7 +27,7 @@ void main()
g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma); g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma);
g1 = exp(-0.5 / (sigma * sigma)); g1 = exp(-0.5 / (sigma * sigma));
g2 = g1 * g1; g2 = g1 * g1;
vec3 sum = local_src[x][y + 6] * g0; vec4 sum = local_src[x][y + 6] * g0;
g0 *= g1; g0 *= g1;
g1 *= g2; g1 *= g2;
for (int i = 1; i < 6; i++) { for (int i = 1; i < 6; i++) {
@ -37,5 +37,5 @@ void main()
g1 *= g2; g1 *= g2;
} }
imageStore(dest, iuv, vec4(sum, 0.)); imageStore(dest, iuv, sum);
} }

View File

@ -42,5 +42,5 @@ void main()
xpos += stepsize * eyedir; xpos += stepsize * eyedir;
} }
Fog = vec4(fogcol * fog, 1.); Fog = vec4(fogcol * fog, 0.);
} }

View File

@ -221,6 +221,7 @@ void IrrDriver::renderLightsScatter(unsigned pointlightcount)
glEnable(GL_BLEND); glEnable(GL_BLEND);
// *** // ***
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
getFBO(FBO_COLORS).Bind(); getFBO(FBO_COLORS).Bind();
m_post_processing->renderPassThrough(getRenderTargetTexture(RTT_HALF1)); m_post_processing->renderPassThrough(getRenderTargetTexture(RTT_HALF1));
} }