More tweaking + UI for the correction stuff

This commit is contained in:
Emmanuel BENOîT 2017-10-05 17:13:58 +02:00
parent 6bb35ae40e
commit 57feeca7b3
4 changed files with 9 additions and 4 deletions

View file

@ -50,6 +50,7 @@ void T_Raymarcher::render( )
U_NEAR_PLANE = 5 , U_NEAR_PLANE = 5 ,
U_RAYMARCHER = 6 , U_RAYMARCHER = 6 ,
U_FOG = 7 , U_FOG = 7 ,
U_CORRECTION = 8
}; };
const auto id( program_.program( E_ShaderType::FRAGMENT ) ); const auto id( program_.program( E_ShaderType::FRAGMENT ) );
@ -64,6 +65,7 @@ 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 ); glProgramUniform1f( id , U_FOG , fog );
glProgramUniform1i( id , U_CORRECTION , correction_ );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 ); glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
@ -83,6 +85,7 @@ void T_Raymarcher::makeUI( )
-10 , -0.5 , "10 ^ %.2f" ) ) { -10 , -0.5 , "10 ^ %.2f" ) ) {
rmEpsilon = pow( 10 , epsLog ); rmEpsilon = pow( 10 , epsLog );
} }
ImGui::DragInt( "Correction" , &correction_ , .001 , 0 , 50 );
ImGui::DragFloat( "Fog" , &fog , .000001 , 0 , 1 , "%.5f" ); ImGui::DragFloat( "Fog" , &fog , .000001 , 0 , 1 , "%.5f" );
} }
} }

View file

@ -35,8 +35,9 @@ struct T_Raymarcher
int rmIterations = 256; int rmIterations = 256;
float rmStep = 1.2; float rmStep = 1.2;
float rmEpsilon = .001; float rmEpsilon = .00001;
float rmMaxDist = 250; float rmMaxDist = 250;
float fog = .00015; float fog = .00015;
int correction_ = 10;
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 vec4 u_Render; layout( location = 6 ) uniform vec4 u_Render;
layout( location = 7 ) uniform float u_FogAttenuation; layout( location = 7 ) uniform float u_FogAttenuation;
layout( location = 8 ) uniform int u_Correction;
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;

View file

@ -58,8 +58,8 @@ vec2 RM_Map( vec3 pos )
sin( 1 ) , cos( 1 ) ); sin( 1 ) , cos( 1 ) );
return vec2( mix( box( q , vec3( 1.5 ) ) , return vec2( mix( box( q , vec3( 1.5 ) ) ,
length( q ) - 1.5 , length( q ) - 1.5 ,
.5 ) , .35 ) ,
step( 0. , 1.9 - length( pos.xy ) ) ); step( 0. , 3 - length( pos.xy ) ) );
} }
@ -105,7 +105,7 @@ void main( )
if ( r.y >= 0. ) { if ( r.y >= 0. ) {
const vec3 hitPos = RM_ReduceDiscontinuity( const vec3 hitPos = RM_ReduceDiscontinuity(
u_CamPos , rayDir , r.x , u_CamPos , rayDir , r.x ,
tanPhi , 10 ); tanPhi , u_Correction );
const vec3 normal = RM_GetNormal( hitPos ); const vec3 normal = RM_GetNormal( hitPos );
const int midx = int( r.y ); const int midx = int( r.y );