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

1
TODO
View file

@ -1,5 +1,4 @@
Rendering: Rendering:
* "Fog"
* Improved light sources * Improved light sources
* Secondary rays * Secondary rays
* Shadows * Shadows

View file

@ -50,6 +50,7 @@ void T_Raymarcher::render( )
U_NEAR_PLANE = 5 , U_NEAR_PLANE = 5 ,
U_LIGHT_DIR = 6 , U_LIGHT_DIR = 6 ,
U_RAYMARCHER = 7 , U_RAYMARCHER = 7 ,
U_FOG = 8 ,
}; };
const auto id( program_.program( E_ShaderType::FRAGMENT ) ); const auto id( program_.program( E_ShaderType::FRAGMENT ) );
@ -66,6 +67,8 @@ void T_Raymarcher::render( )
glProgramUniform4f( id , U_RAYMARCHER , rmIterations , rmStep , glProgramUniform4f( id , U_RAYMARCHER , rmIterations , rmStep ,
rmEpsilon , rmMaxDist ); rmEpsilon , rmMaxDist );
glProgramUniform1f( id , U_FOG , fog );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 ); glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
PEND( ); PEND( );
@ -75,16 +78,15 @@ void T_Raymarcher::makeUI( )
{ {
camera_.makeUI( ); camera_.makeUI( );
if ( !ImGui::CollapsingHeader( "Raymarcher" ) ) { if ( ImGui::CollapsingHeader( "Raymarcher" ) ) {
return; ImGui::DragInt( "Iterations" , &rmIterations , .01 , 1 , 512 );
} ImGui::DragFloat( "Step" , &rmStep , .00005 , .1 , 2 );
ImGui::DragFloat( "Max. dist." , &rmMaxDist , .1f ,
ImGui::DragInt( "Iterations" , &rmIterations , .1 , 1 , 512 ); 0.01 , 1000.0 , "%.2f" );
ImGui::DragFloat( "Step" , &rmStep , .005 , .1 , 2 ); if ( ImGui::DragFloat( "Epsilon" , &epsLog , .01f ,
ImGui::DragFloat( "Max. dist." , &rmMaxDist , .1f , -10 , -0.5 , "10 ^ %.2f" ) ) {
0.01 , 1000.0 , "%.2f" ); rmEpsilon = pow( 10 , epsLog );
if ( ImGui::DragFloat( "Epsilon" , &epsLog , .01f , }
-10 , -0.5 , "10 ^ %.2f" ) ) { ImGui::DragFloat( "Fog" , &fog , .000001 , 0 , 1 , "%.5f" );
rmEpsilon = pow( 10 , epsLog );
} }
} }

View file

@ -37,5 +37,6 @@ struct T_Raymarcher
float rmStep = 1.2; float rmStep = 1.2;
float rmEpsilon = .001; float rmEpsilon = .001;
float rmMaxDist = 250; float rmMaxDist = 250;
float fog = .00015;
float epsLog = log( rmEpsilon ) / log( 10 ); float epsLog = log( rmEpsilon ) / log( 10 );
}; };

View file

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