#include "externals.hh" #include "demo.hh" #include "sync.hh" #include "globals.hh" T_Demo::T_Demo( __rd__ const uint32_t width , __rd__ const uint32_t height ) : width( width ) , height( height ) { } bool T_Demo::initialise( ) { raymarcher = std::make_unique< T_Raymarcher >( width , height ); dof = std::make_unique< T_DoFPass >( raymarcher->output( ) , raymarcher->depth( ) ); bloom = std::make_unique< T_BloomPass >( raymarcher->output( ) ); combine = std::make_unique< T_CombinePass >( dof->output( ) , bloom->output( ) ); fxaa = std::make_unique< T_FXAAPass >( combine->output( ) ); Globals::Sync( ).clearInputs( ); Globals::Sync( ).addInput( "dof:sharp-distance" , 15 ); Globals::Sync( ).addInput( "dof:sharp-range" , 5 ); Globals::Sync( ).addInput( "dof:falloff" , 10 ); Globals::Sync( ).addInput( "dof:max-blur" , 16 ); Globals::Sync( ).addInput( "dof:samples" , 16 ); // XXX test curve { T_SyncCurve curve; curve.name = "dof:sharp-distance"; { T_SyncSegment seg; seg.nPoints = 4; seg.type = T_SyncSegment::SMOOTH; seg.durations.push_back( 300 ); seg.durations.push_back( 300 ); seg.durations.push_back( 300 ); seg.values.push_back( 15 ); seg.values.push_back( 30 ); seg.values.push_back( 15 ); seg.values.push_back( 15 ); curve.segments.emplace_back( std::move( seg ) ); } { T_SyncSegment seg; seg.nPoints = 2; seg.type = T_SyncSegment::LINEAR; seg.durations.push_back( 600 ); seg.values.push_back( 100 ); seg.values.push_back( 20 ); curve.segments.emplace_back( std::move( seg ) ); } Globals::Sync( ).setCurve( std::move( curve ) ); } Globals::Sync( ).updateCurveCaches( ); return true; } void T_Demo::makeUI( ) { auto const& dspSize( ImGui::GetIO( ).DisplaySize ); ImGui::SetNextWindowSize( ImVec2( 300 , dspSize.y - 300 ) , ImGuiSetCond_Once ); ImGui::SetNextWindowPos( ImVec2( 0 , 150 ) , ImGuiSetCond_Once ); ImGui::Begin( "Demo controls" ); raymarcher->makeUI( ); dof->makeUI( ); bloom->makeUI( ); combine->makeUI( ); fxaa->makeUI( ); ImGui::End( ); } void T_Demo::render( ) { auto& sync( Globals::Sync( ) ); if ( playing ) { const float time = SDL_GetTicks( ) * 1e-3; if ( playingPrevious ) { sync.timeDelta( time - lastFrame ); playing = !sync.finished( ); } lastFrame = time; } playingPrevious = playing; raymarcher->render( ); dof->render( ); bloom->render( ); combine->render( ); fxaa->render( ); } void T_Demo::handleDND( __rd__ ImVec2 const& move , __rd__ const bool hasCtrl , __rd__ const bool hasShift , __rd__ const bool lmb // Left mouse button ) { raymarcher->camera( ).handleDND( move , hasCtrl , hasShift , lmb ); } void T_Demo::handleWheel( __rd__ const float wheel , __rd__ const bool hasCtrl , __rd__ const bool hasShift ) { raymarcher->camera( ).handleWheel( wheel , hasCtrl , hasShift ); }