diff --git a/raymarcher.cc b/raymarcher.cc index c7b2ed4..d1b8db7 100644 --- a/raymarcher.cc +++ b/raymarcher.cc @@ -50,6 +50,7 @@ void T_Raymarcher::render( ) U_NEAR_PLANE = 5 , U_RAYMARCHER = 6 , U_FOG = 7 , + U_CORRECTION = 8 }; const auto id( program_.program( E_ShaderType::FRAGMENT ) ); @@ -64,6 +65,7 @@ void T_Raymarcher::render( ) glProgramUniform4f( id , U_RAYMARCHER , rmIterations , rmStep , rmEpsilon , rmMaxDist ); glProgramUniform1f( id , U_FOG , fog ); + glProgramUniform1i( id , U_CORRECTION , correction_ ); glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 ); @@ -83,6 +85,7 @@ void T_Raymarcher::makeUI( ) -10 , -0.5 , "10 ^ %.2f" ) ) { rmEpsilon = pow( 10 , epsLog ); } + ImGui::DragInt( "Correction" , &correction_ , .001 , 0 , 50 ); ImGui::DragFloat( "Fog" , &fog , .000001 , 0 , 1 , "%.5f" ); } } diff --git a/raymarcher.hh b/raymarcher.hh index a315638..9386682 100644 --- a/raymarcher.hh +++ b/raymarcher.hh @@ -35,8 +35,9 @@ struct T_Raymarcher int rmIterations = 256; float rmStep = 1.2; - float rmEpsilon = .001; + float rmEpsilon = .00001; float rmMaxDist = 250; float fog = .00015; + int correction_ = 10; float epsLog = log( rmEpsilon ) / log( 10 ); }; diff --git a/shaders/chunks/raymarcher.glsl b/shaders/chunks/raymarcher.glsl index 016bce2..a11a929 100644 --- a/shaders/chunks/raymarcher.glsl +++ b/shaders/chunks/raymarcher.glsl @@ -8,6 +8,7 @@ layout( location = 4 ) uniform vec3 u_CamUp; layout( location = 5 ) uniform float u_NearPlane; layout( location = 6 ) uniform vec4 u_Render; layout( location = 7 ) uniform float u_FogAttenuation; +layout( location = 8 ) uniform int u_Correction; layout( location = 0 ) out vec3 o_Color; layout( location = 1 ) out float o_Z; diff --git a/shaders/scene.f.glsl b/shaders/scene.f.glsl index 1609ed8..90c9bf6 100644 --- a/shaders/scene.f.glsl +++ b/shaders/scene.f.glsl @@ -58,8 +58,8 @@ vec2 RM_Map( vec3 pos ) sin( 1 ) , cos( 1 ) ); return vec2( mix( box( q , vec3( 1.5 ) ) , length( q ) - 1.5 , - .5 ) , - step( 0. , 1.9 - length( pos.xy ) ) ); + .35 ) , + step( 0. , 3 - length( pos.xy ) ) ); } @@ -105,7 +105,7 @@ void main( ) if ( r.y >= 0. ) { const vec3 hitPos = RM_ReduceDiscontinuity( u_CamPos , rayDir , r.x , - tanPhi , 10 ); + tanPhi , u_Correction ); const vec3 normal = RM_GetNormal( hitPos ); const int midx = int( r.y );