#include "externals.hh" #include "utilities.hh" #include "texture.hh" #include "rendertarget.hh" #include "raymarcher.hh" #include "profiling.hh" namespace { static const std::string Name_( "Raymarcher" ); } #define PSTART() T_Profiler::Profiler.start( Name_ ) #define PEND() do { glFinish( ); T_Profiler::Profiler.end( Name_ ); } while ( 0 ) T_Raymarcher::T_Raymarcher( __rw__ T_FilesWatcher& watcher , __rd__ const uint32_t width , __rd__ const uint32_t height ) : camera_( ) , program_( GL_FRAGMENT_SHADER , watcher ) , txOutput_( width , height , E_TexType::RGB16F ) , rtOutput_( T_RendertargetSetup( ).add( txOutput_ ).create( ) ) { program_.addFile( "raymarch-header.glsl" ); program_.addFile( "map.glsl" ); program_.addFile( "raymarcher.glsl" ); program_.load( ); } void T_Raymarcher::render( ) { PSTART( ); if ( !( program_.activate( ) && rtOutput_.activate( ) ) ) { PEND( ); return; } glClearColor( 0 , 1 , 1 , 1 ); glClear( GL_COLOR_BUFFER_BIT ); enum { U_TIME = 0 , U_RESOLUTION = 1 , U_CAM_POS = 2 , U_LOOK_AT = 3 , U_CAM_UP = 4 , U_NEAR_PLANE = 5 , U_LIGHT_DIR = 6 , U_RAYMARCHER = 7 , }; glUniform1f( U_TIME , 0 ); glUniform2f( U_RESOLUTION , rtOutput_.width( ) , rtOutput_.height( ) ); glUniform3fv( U_CAM_POS , 1 , &camera_.pos.x ); glUniform3fv( U_LOOK_AT , 1 , &camera_.lookAt.x ); glUniform3fv( U_CAM_UP , 1 , &camera_.up.x ); glUniform1f( U_NEAR_PLANE , camera_.np ); glUniform3f( U_LIGHT_DIR , 0 , 1 , 1 ); glUniform4f( U_RAYMARCHER , rmIterations , rmStep , rmEpsilon , rmMaxDist ); glRectf( -1, -1 , 1 , 1 ); PEND( ); } void T_Raymarcher::makeUI( ) { camera_.makeUI( ); if ( !ImGui::CollapsingHeader( "Raymarcher" ) ) { return; } ImGui::DragInt( "Iterations" , &rmIterations , .1 , 1 , 512 ); ImGui::DragFloat( "Step" , &rmStep , .005 , .1 , 2 ); ImGui::DragFloat( "Max. dist." , &rmMaxDist , .1f , 0.01 , 1000.0 , "%.2f" ); if ( ImGui::DragFloat( "Epsilon" , &epsLog , .01f , -10 , -0.5 , "10 ^ %.2f" ) ) { rmEpsilon = pow( 10 , epsLog ); } }