This commit is contained in:
Emmanuel BENOîT 2017-10-05 09:07:37 +02:00
parent d5d56b094c
commit 3e6e9e1ba8
6 changed files with 29 additions and 13 deletions

View file

@ -8,6 +8,7 @@ layout( location = 4 ) uniform vec3 u_CamUp;
layout( location = 5 ) uniform float u_NearPlane;
layout( location = 6 ) uniform vec3 u_LightDir;
layout( location = 7 ) uniform vec4 u_Render;
layout( location = 8 ) uniform float u_FogAttenuation;
layout( location = 0 ) out vec3 o_Color;
layout( location = 1 ) out float o_Z;

10
shaders/lib/fog.glsl Normal file
View file

@ -0,0 +1,10 @@
//! type library
vec3 FOG_Apply(
in vec3 color ,
in float dist ,
in float attenuation ,
in vec3 background )
{
return mix( background , color , exp( - dist * dist * attenuation ) );
}

View file

@ -4,6 +4,7 @@
//! include chunks/raymarcher.glsl
//! include lib/shading-pbr.glsl
//! include lib/shading-blinnphong.glsl
//! include lib/fog.glsl
T_BPMaterial BPMaterials[1] = {
@ -64,8 +65,9 @@ void main( )
int( u_Render.x ) , u_Render.y ,
u_Render.z , .001 , u_Render.w );
vec3 hitPos = u_CamPos + rayDir * r.x;
const vec3 background = vec3( .01 );
vec3 bc = vec3( 0 );
vec3 bc = background;
if ( r.y >= 0. ) {
const int midx = int( r.y );
const vec3 normal = RM_GetNormal( hitPos );
@ -85,6 +87,7 @@ void main( )
if ( glowidx >= 0 ) {
bc += Glow[ glowidx ];
}
bc = FOG_Apply( bc , r.x , u_FogAttenuation , background );
}
o_Color = bc;