diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index 5c6c863..3475389 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -12,12 +12,10 @@ #include #include "KeyboardMovementController.hpp" -#include "buffers/HostSingleT.hpp" #include "camera/Camera.hpp" #include "camera/CameraManager.hpp" #include "engine/Average.hpp" #include "engine/assets/TransferManager.hpp" -#include "engine/debug/drawers.hpp" #include "engine/literals/size.hpp" #include "model/builders/SceneBuilder.hpp" diff --git a/src/engine/FGL_DEFINES.hpp b/src/engine/FGL_DEFINES.hpp index 069f59d..011c505 100644 --- a/src/engine/FGL_DEFINES.hpp +++ b/src/engine/FGL_DEFINES.hpp @@ -4,8 +4,6 @@ #pragma once -#include - #define FGL_DELETE_DEFAULT_CTOR( ClassName ) ClassName() = delete; #define FGL_DELETE_COPY_ASSIGN( ClassName ) ClassName& operator=( const ClassName& ) = delete; #define FGL_DELETE_COPY_CTOR( ClassName ) ClassName( const ClassName& ) = delete; @@ -36,11 +34,18 @@ //! Warns if the structure field is not alligned with a set number of bytes #define FGL_STRICT_ALIGNMENT( bytesize ) [[gnu::warn_if_not_aligned( bytesize )]] -#define FGL_ASSERT( ... ) assert( __VA_ARGS__ ); +#ifndef NDEBUG +#include +#define FGL_ASSERT( test, msg ) \ + if ( !( test ) ) throw std::runtime_error( msg ); +#else +#define FGL_ASSERT( test, msg ) +#endif #ifndef NDEBUG +#include #define FGL_UNREACHABLE() \ - FGL_ASSERT( false ); \ + FGL_ASSERT( false, "Should have been unreachable!" ); \ std::unreachable() #else #define FGL_UNREACHABLE() std::unreachable() diff --git a/src/engine/FrameInfo.cpp b/src/engine/FrameInfo.cpp index 940fc80..ba709e6 100644 --- a/src/engine/FrameInfo.cpp +++ b/src/engine/FrameInfo.cpp @@ -6,6 +6,7 @@ #include "camera/Camera.hpp" #include "camera/CameraSwapchain.hpp" +#include "pipeline/Pipeline.hpp" namespace fgl::engine { @@ -20,4 +21,9 @@ namespace fgl::engine return camera->getDescriptor( frame_idx ); } + void FrameInfo::bindCamera( internal::Pipeline& pipeline ) + { + //TODO: This + } + } // namespace fgl::engine diff --git a/src/engine/FrameInfo.hpp b/src/engine/FrameInfo.hpp index 742902f..e640b70 100644 --- a/src/engine/FrameInfo.hpp +++ b/src/engine/FrameInfo.hpp @@ -12,6 +12,7 @@ #include "descriptors/Descriptor.hpp" #include "descriptors/DescriptorSetLayout.hpp" +#include "pipeline/Pipeline.hpp" #include "primitives/Frustum.hpp" #include "rendering/types.hpp" @@ -98,6 +99,9 @@ namespace fgl::engine SwapChain& swap_chain; std::vector< std::vector< GameObject >* > in_view_leafs {}; + + //! Binds the camera descriptor to the command buffer + void bindCamera( internal::Pipeline& pipeline ); }; } // namespace fgl::engine diff --git a/src/engine/buffers/BufferSuballocation.cpp b/src/engine/buffers/BufferSuballocation.cpp index 356b9a7..62900e4 100644 --- a/src/engine/buffers/BufferSuballocation.cpp +++ b/src/engine/buffers/BufferSuballocation.cpp @@ -48,6 +48,7 @@ namespace fgl::engine::memory void* BufferSuballocation::ptr() const { assert( m_handle != nullptr ); + FGL_ASSERT( m_handle->mapped, "Buffer must be mappable to use `ptr()`" ); return m_handle->mapped; } diff --git a/src/engine/camera/CameraManager.cpp b/src/engine/camera/CameraManager.cpp index c9785c9..2fb6bdb 100644 --- a/src/engine/camera/CameraManager.cpp +++ b/src/engine/camera/CameraManager.cpp @@ -6,7 +6,6 @@ #include "Camera.hpp" #include "engine/debug/DEBUG_NAMES.hpp" -#include "engine/debug/drawers.hpp" #include "engine/literals/size.hpp" namespace fgl::engine @@ -43,8 +42,6 @@ namespace fgl::engine m_primary_camera = createCamera( { 1920, 1080 } ); m_primary_camera->setName( CAMERA_EDITOR_NAME ); - - debug::setDebugDrawingCamera( getPrimary() ); } std::shared_ptr< Camera > CameraManager::createCamera( const vk::Extent2D extent ) diff --git a/src/engine/camera/CameraRenderer.cpp b/src/engine/camera/CameraRenderer.cpp index 7b2a646..ec67908 100644 --- a/src/engine/camera/CameraRenderer.cpp +++ b/src/engine/camera/CameraRenderer.cpp @@ -140,6 +140,7 @@ namespace fgl::engine //m_terrain_system.pass( frame_info ); m_entity_renderer.pass( frame_info ); + m_line_drawer.pass( frame_info ); m_composition_system.pass( frame_info ); diff --git a/src/engine/camera/CameraRenderer.hpp b/src/engine/camera/CameraRenderer.hpp index 023b4b6..01d6a8c 100644 --- a/src/engine/camera/CameraRenderer.hpp +++ b/src/engine/camera/CameraRenderer.hpp @@ -9,6 +9,7 @@ #include "engine/systems/CompositionSystem.hpp" #include "engine/systems/CullingSystem.hpp" #include "engine/systems/EntityRendererSystem.hpp" +#include "engine/systems/LineDrawer.hpp" namespace fgl::engine { @@ -26,6 +27,7 @@ namespace fgl::engine // SubPass 0 //TerrainSystem m_terrain_system { Device::getInstance(), m_renderpass }; EntityRendererSystem m_entity_renderer { Device::getInstance(), m_renderpass }; + LineDrawer m_line_drawer { Device::getInstance(), m_renderpass }; // SubPass 1 CompositionSystem m_composition_system { Device::getInstance(), m_renderpass }; diff --git a/src/engine/debug/drawers.cpp b/src/engine/debug/drawers.cpp deleted file mode 100644 index 9e0d5b3..0000000 --- a/src/engine/debug/drawers.cpp +++ /dev/null @@ -1,340 +0,0 @@ -// -// Created by kj16609 on 1/28/24. -// - -#include "drawers.hpp" - -#include "engine/camera/Camera.hpp" -#include "engine/primitives/boxes/AxisAlignedBoundingBox.hpp" -#include "engine/primitives/boxes/AxisAlignedBoundingCube.hpp" -#include "engine/primitives/boxes/OrientedBoundingBox.hpp" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Weffc++" -#include "imgui/imgui.h" -#pragma GCC diagnostic pop - -#include - -#include "tracy_colors.hpp" - -#if ENABLE_IMGUI_DRAWERS - -namespace fgl::engine::debug -{ - inline static std::optional< std::shared_ptr< Camera > > debug_camera { std::nullopt }; - - Camera& getDebugDrawingCamera() - { - assert( debug_camera.has_value() && debug_camera.value() != nullptr && "Debug camera not set" ); - return *debug_camera.value(); - } - - void setDebugDrawingCamera( std::shared_ptr< Camera >& cam ) - { - assert( cam ); - debug_camera = cam; - } - - const ImVec2 windowSize() - { - return ImGui::GetMainViewport()->Size; - } - - Coordinate< CoordinateSpace::Screen > toScreenSpace( Coordinate< CoordinateSpace::World > world_point ) - { - const ImVec2 window_size { windowSize() }; - - const Coordinate< CoordinateSpace::Screen > screen_point { glm::projectZO( - world_point.vec(), - glm::mat4( 1.0f ), - getDebugDrawingCamera().getProjectionViewMatrix(), - glm::vec4( 0.0f, 0.0f, window_size.x, window_size.y ) ) }; - - return screen_point; - } - - ImVec2 glmToImgui( const glm::vec2 vec ) - { - return ImVec2( vec.x, vec.y ); - } - - ImVec2 glmToImgui( const Coordinate< CoordinateSpace::Screen > coordinate ) - { - return glmToImgui( coordinate.vec() ); - } - - bool isBehind( const glm::vec3 point ) - { - return point.z > 1.0f || point.z < 0.0f; - } - - bool inView( const glm::vec3 point ) - { - const ImVec2 window_size { windowSize() }; - - return !isBehind( point ) && ( point.x > 0.0f && point.x < window_size.x ) - && ( point.y > 0.0f && point.y < window_size.y ); - } - - namespace world - { - - inline void - drawLineI( const LineSegment< CoordinateSpace::World > line, const glm::vec3 color, const float thickness ) - { - //Check if the line in intersecting the frustum - if ( getDebugDrawingCamera().getFrustumBounds().intersects( line ) ) - drawLine( line, glm::vec3( 0.0f, 1.0f, 0.0f ), thickness ); - else - drawLine( line, color, thickness ); - } - - void drawBoundingBox( const OrientedBoundingBox< CoordinateSpace::World >& box, const glm::vec3 color ) - { - ZoneScopedC( TRACY_DRAWER_FUNC_COLOR ); - for ( const auto& line : box.lines() ) - { - auto p1 { line.getPosition() }; - auto p2 { line.getEnd() }; - drawLine( LineSegment( p1, p2 ), color ); - } - - for ( const auto point : box.points() ) - { - drawPointText( point, color ); - } - } - - void drawBoundingBox( const AxisAlignedBoundingBox< CoordinateSpace::World >& box, const glm::vec3 color ) - { - ZoneScopedC( TRACY_DRAWER_FUNC_COLOR ); - for ( const auto& line : box.lines() ) - { - auto p1 { line.getPosition() }; - auto p2 { line.getEnd() }; - drawLine( LineSegment( p1, p2 ), color ); - } - - for ( const auto point : box.points() ) - { - drawPointText( point, color ); - } - } - - void drawBoundingBox( const AxisAlignedBoundingCube< CoordinateSpace::World >& box, const glm::vec3 color ) - { - ZoneScopedC( TRACY_DRAWER_FUNC_COLOR ); - for ( const auto& line : box.lines() ) - { - auto p1 { line.getPosition() }; - auto p2 { line.getEnd() }; - drawLine( LineSegment( p1, p2 ), color ); - } - - for ( const auto point : box.points() ) - { - drawPointText( point, color ); - } - } - - inline void - drawLine( const LineSegment< CoordinateSpace::World > line, const glm::vec3 color, const float thickness ) - { - Coordinate< CoordinateSpace::Screen > start_screen { toScreenSpace( line.getPosition() ) }; - Coordinate< CoordinateSpace::Screen > end_screen { toScreenSpace( line.getEnd() ) }; - - if ( isBehind( start_screen.vec() ) && isBehind( end_screen.vec() ) ) return; - - const auto frustum { getDebugDrawingCamera().getFrustumBounds() }; - - if ( !frustum.intersects( line ) ) return; - - //Check if either point is behind the camera - if ( isBehind( start_screen.vec() ) ) - { - const auto new_line { line.flip() }; - - const auto new_point { frustum.intersection( new_line ) }; - - start_screen = toScreenSpace( new_point ); - } - else if ( isBehind( end_screen.vec() ) ) - { - const auto new_point { frustum.intersection( line ) }; - - end_screen = toScreenSpace( new_point ); - } - - if ( glm::any( glm::isnan( end_screen.vec() ) ) || glm::any( glm::isnan( start_screen.vec() ) ) ) return; - - ImGui::GetBackgroundDrawList()->AddLine( - glmToImgui( start_screen ), glmToImgui( end_screen ), ImColor( color.x, color.y, color.z ), thickness ); - } - - void drawLine( - const Coordinate< CoordinateSpace::World > start, - const Coordinate< CoordinateSpace::World > end, - const glm::vec3 color ) - { - drawLine( LineSegment( start, end ), color ); - } - - void drawPointText( const Coordinate< CoordinateSpace::World > point, const glm::vec3 color ) - { - const glm::vec3 screen_point { toScreenSpace( point ).vec() }; - - if ( !inView( screen_point ) ) return; - - drawPoint( point, "", color ); - - const std::string text { "World: (" + std::to_string( point.vec().x ) + ", " - + std::to_string( point.vec().y ) + ", " + std::to_string( point.vec().z ) + ")" }; - - screen::drawText( glm::vec2( screen_point.x, screen_point.y ), text, color, glm::vec2( 0.0f, 20.f ) ); - - const std::string text2 { "Screen: (" + std::to_string( screen_point.x ) + ", " - + std::to_string( screen_point.y ) + ", " + std::to_string( screen_point.z ) - + ")" }; - - screen::drawText( glm::vec2( screen_point.x, screen_point.y ), text2, color, glm::vec2( 0.0f, 30.0f ) ); - - const Frustum frustum { getDebugDrawingCamera().getFrustumBounds() }; - //const bool in_view { frustum.pointInside( point ) }; - //TODO: This - const bool in_view { false }; - - drawBoolAlpha( point, in_view, glm::vec2( 0.0f, 40.0f ) ); - } - - void drawPointLabel( const Coordinate< CoordinateSpace::World > point, const std::string label ) - { - const glm::vec3 screen_point { toScreenSpace( point ).vec() }; - - if ( !inView( screen_point ) ) return; - - screen::drawText( glm::vec2( screen_point.x, screen_point.y ), label ); - } - - void drawPoint( - const Coordinate< CoordinateSpace::World > point, const std::string label, const glm::vec3 color ) - { - const glm::vec3 screen_point { toScreenSpace( point ).vec() }; - if ( !inView( screen_point ) ) return; - - const float div { screen_point.z }; - - ImGui::GetBackgroundDrawList() - ->AddCircleFilled( glmToImgui( screen_point ), div * 5.0f, ImColor( color.x, color.y, color.z ) ); - - drawPointLabel( point, label ); - } - - void drawBoolAlpha( const Coordinate< CoordinateSpace::World > point, const bool value, const glm::vec2 offset ) - { - const auto screen_point { toScreenSpace( point ) }; - - const auto color { value ? glm::vec3( 0.0f, 1.0f, 0.0f ) : glm::vec3( 1.0f, 0.0f, 0.0f ) }; - - screen::drawText( - glm::vec2( screen_point.vec().x, screen_point.vec().y + offset.y ), value ? "true" : "false", color ); - } - - void drawVector( - const Coordinate< CoordinateSpace::World > point, - Vector vector, - const std::string label, - const glm::vec3 color ) - { - drawLine( point, point + vector, color ); - drawPoint( point + vector, label, color ); - drawPoint( point, "", color ); - //drawPointLabel( point, label ); - //drawPointText( point + glm::normalize( vector ) ); - - //Draw ending lines for the vector (two perpendicular lines) - const WorldCoordinate perpendicular_vector { - glm::normalize( glm::cross( vector.vec(), glm::vec3( 0.0f, 1.0f, 0.0f ) ) ) / 4.0f - }; - const WorldCoordinate perpendicular_vector2 { - glm::normalize( glm::cross( vector.vec(), perpendicular_vector.vec() ) ) / 4.0f - }; - - drawLine( - point + glm::normalize( vector.vec() ) + perpendicular_vector, - point + glm::normalize( vector.vec() ) - perpendicular_vector, - color ); - - drawLine( - point + glm::normalize( vector.vec() ) + perpendicular_vector2, - point + glm::normalize( vector.vec() ) - perpendicular_vector2, - color ); - } - - void drawVector( - const Coordinate< CoordinateSpace::World > point, - NormalVector vector, - const std::string label, - const glm::vec3 color ) - { - drawVector( point, Vector( vector ), label, color ); - } - - void drawFrustum( - const Frustum< CoordinateSpace::World >& frustum, [[maybe_unused]] const WorldCoordinate point ) - { - drawPlane( frustum.near, frustum.near.getPosition(), "near" ); - drawPlane( frustum.far, frustum.far.getPosition(), "far" ); - drawPlane( frustum.top, frustum.top.getPosition(), "top" ); - drawPlane( frustum.bottom, frustum.bottom.getPosition(), "bottom" ); - drawPlane( frustum.right, frustum.right.getPosition(), "right" ); - drawPlane( frustum.left, frustum.left.getPosition(), "left" ); - } - - void drawFrustum() - { - const Frustum frustum { getDebugDrawingCamera().getFrustumBounds() }; - drawFrustum( frustum, getDebugDrawingCamera().getFrustumPosition() ); - } - - void drawPlane( - const Plane< CoordinateSpace::World >& plane, - const WorldCoordinate point, - const std::string label, - const glm::vec3 color ) - { - const NormalVector normal { plane.getDirection() }; - - assert( point.vec() != constants::DEFAULT_VEC3 ); - - drawLine( point, point + normal, color ); - drawPoint( point + normal, label, color ); - } - - } // namespace world - - namespace screen - { - void - drawText( const glm::vec2 position, const std::string& text, const glm::vec3 color, const glm::vec2 offset ) - { - ImGui::GetBackgroundDrawList() - ->AddText( glmToImgui( position + offset ), ImColor( color.x, color.y, color.z ), text.c_str() ); - } - - void drawBoolAlpha( - const glm::vec2 screen_point, - [[maybe_unused]] const Camera& camera, - const bool value, - const glm::vec2 offset ) - { - const auto color { value ? glm::vec3( 0.0f, 1.0f, 0.0f ) : glm::vec3( 1.0f, 0.0f, 0.0f ) }; - drawText( glm::vec2( screen_point.x, screen_point.y + offset.y ), value ? "true" : "false", color ); - } - - } // namespace screen - -} // namespace fgl::engine::debug - -#endif diff --git a/src/engine/debug/drawers.hpp b/src/engine/debug/drawers.hpp deleted file mode 100644 index e08a66d..0000000 --- a/src/engine/debug/drawers.hpp +++ /dev/null @@ -1,203 +0,0 @@ -// -// Created by kj16609 on 1/28/24. -// - -#pragma once - -#include - -#include "engine/primitives/Frustum.hpp" -#include "engine/primitives/lines/LineSegment.hpp" -#include "engine/primitives/planes/PointPlane.hpp" -#include "engine/primitives/points/Coordinate.hpp" - -namespace fgl::engine -{ - template < CoordinateSpace type > - struct OrientedBoundingBox; - template < CoordinateSpace type > - class AxisAlignedBoundingBox; - template < CoordinateSpace type > - class AxisAlignedBoundingCube; - - template < CoordinateSpace type > - class Coordinate; - - template < CoordinateSpace type > - class LineSegment; - - class Camera; - - struct SinglePointDistancePlane; - -} // namespace fgl::engine - -#ifndef ENABLE_IMGUI_DRAWERS -#define ENABLE_IMGUI_DRAWERS 0 -#endif - -#ifndef ENABLE_IMGUI -#define ENABLE_IMGUI 0 -#endif - -#if ENABLE_IMGUI_DRAWERS -namespace fgl::engine::debug -{ - Camera& getDebugDrawingCamera(); - void setDebugDrawingCamera( std::shared_ptr< Camera >& ); - - namespace world - { - void drawBoundingBox( - const OrientedBoundingBox< CoordinateSpace::World >& box, glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - void drawBoundingBox( - const AxisAlignedBoundingBox< CoordinateSpace::World >& box, glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - void drawBoundingBox( - const AxisAlignedBoundingCube< CoordinateSpace::World >& box, glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - - void drawLine( - Coordinate< CoordinateSpace::World > start, - Coordinate< CoordinateSpace::World > end, - glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - - void drawPointLabel( Coordinate< CoordinateSpace::World > point, std::string label ); - - void drawLineI( - LineSegment< CoordinateSpace::World > line, - glm::vec3 color = { 1.0f, 1.0f, 1.0f }, - float thickness = 1.0f ); - void drawLine( - LineSegment< CoordinateSpace::World > line, - glm::vec3 color = { 1.0f, 1.0f, 1.0f }, - float thickness = 1.0f ); - - void drawPointText( Coordinate< CoordinateSpace::World > point, glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - - void drawBoolAlpha( Coordinate< CoordinateSpace::World > point, bool value, glm::vec2 offset = {} ); - void drawPoint( - Coordinate< CoordinateSpace::World > point, - std::string label = "", - glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - - void drawVector( - Coordinate< CoordinateSpace::World > point, - Vector vector, - std::string label = "", - glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - - void drawVector( - Coordinate< CoordinateSpace::World > point, - NormalVector vector, - std::string label = "", - glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - - void drawFrustum( const Frustum< CoordinateSpace::World >& frustum, WorldCoordinate coordinate ); - void drawFrustum(); - - void drawPlane( - const Plane< CoordinateSpace::World >& plane, - WorldCoordinate point, - std::string label = "", - glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - - } // namespace world - - namespace screen - { - - void drawText( - glm::vec2 position, - const std::string& text, - glm::vec3 color = { 1.0f, 1.0f, 1.0f }, - glm::vec2 offset = {} ); - - void drawBoolAlpha( glm::vec2 screen_point, const Camera& camera, bool value, glm::vec2 offset = {} ); - - } // namespace screen - -} // namespace fgl::engine::debug -#else - -namespace fgl::engine::debug -{ - inline void setDebugDrawingCamera( [[maybe_unused]] Camera& cam ) - {} - - namespace world - { - - //Dummy functions - inline void drawBoundingBox( - [[maybe_unused]] const OrientedBoundingBox< CoordinateSpace::World >&, [[maybe_unused]] const glm::vec3 ) - {} - - inline void drawBoundingBox( [[maybe_unused]] const OrientedBoundingBox< CoordinateSpace::World >& ) - {} - - inline void drawLine( - [[maybe_unused]] const Coordinate< CoordinateSpace::World >, - [[maybe_unused]] const Coordinate< CoordinateSpace::World >, - [[maybe_unused]] const glm::vec3, - [[maybe_unused]] const float ) - {} - - inline void drawPointLabel( - [[maybe_unused]] const Coordinate< CoordinateSpace::World >, [[maybe_unused]] const std::string ) - {} - - inline void drawLine( - [[maybe_unused]] const Line< CoordinateSpace::World >, - [[maybe_unused]] const glm::vec3, - [[maybe_unused]] const float ) - {} - - inline void drawPointText( - [[maybe_unused]] const Coordinate< CoordinateSpace::World >, [[maybe_unused]] const glm::vec3 ) - {} - - inline void drawBoolAlpha( - [[maybe_unused]] const Coordinate< CoordinateSpace::World >, - [[maybe_unused]] const Camera&, - [[maybe_unused]] const bool, - [[maybe_unused]] const glm::vec2 ) - {} - - inline void drawPoint( - [[maybe_unused]] const Coordinate< CoordinateSpace::World >, - [[maybe_unused]] const std::string, - [[maybe_unused]] const glm::vec3 ) - {} - - inline void drawVector( - [[maybe_unused]] const Coordinate< CoordinateSpace::World >, - [[maybe_unused]] Vector, - [[maybe_unused]] const std::string, - [[maybe_unused]] const glm::vec3 ) - {} - - inline void drawVector( - [[maybe_unused]] const Coordinate< CoordinateSpace::World >, - [[maybe_unused]] NormalVector, - [[maybe_unused]] const std::string, - [[maybe_unused]] const glm::vec3 ) - {} - - inline void drawFrustum( - [[maybe_unused]] const Frustum< CoordinateSpace::World >&, [[maybe_unused]] const WorldCoordinate ) - {} - - inline void drawFrustum() - {} - - inline void drawPlane( - [[maybe_unused]] const Plane< CoordinateSpace::World >&, - [[maybe_unused]] const WorldCoordinate, - [[maybe_unused]] const std::string, - [[maybe_unused]] const glm::vec3 ) - {} - - } // namespace world - -} // namespace fgl::engine::debug - -#endif diff --git a/src/engine/descriptors/DescriptorSetCollection.hpp b/src/engine/descriptors/DescriptorSetCollection.hpp index d3b68a3..5ea73a7 100644 --- a/src/engine/descriptors/DescriptorSetCollection.hpp +++ b/src/engine/descriptors/DescriptorSetCollection.hpp @@ -76,4 +76,30 @@ namespace fgl::engine::descriptors using PushConstantT = BindingSet< 0 >; }; + template <> + struct DescriptorSetCollection<> + { + using DescriptorSetTuple = std::tuple< void >; + + static constexpr auto SIZE { 0 }; + + static constexpr std::uint64_t DescriptorSetCount { 0 }; + + //If the first descriptor set is a constant range, then the pipeline has a constant range + static constexpr bool has_constant_range { false }; + + static constexpr std::uint16_t binding_sets { 0 }; + + static constexpr std::uint16_t max_binding_set { 0 }; + + static constexpr std::uint16_t set_count { 0 }; + + static constexpr std::uint16_t empty_sets { 0 }; + + template < std::uint64_t BindingIDX > + using BindingSet = void; + + static std::vector< vk::raii::DescriptorSetLayout > createDescriptorSets() { return {}; } + }; + } // namespace fgl::engine::descriptors \ No newline at end of file diff --git a/src/engine/descriptors/createDescriptorSets.hpp b/src/engine/descriptors/createDescriptorSets.hpp index 658833a..a338e95 100644 --- a/src/engine/descriptors/createDescriptorSets.hpp +++ b/src/engine/descriptors/createDescriptorSets.hpp @@ -4,6 +4,7 @@ #pragma once +#include "engine/FGL_DEFINES.hpp" #include "engine/concepts/is_valid_pipeline_input.hpp" namespace fgl::engine::descriptors diff --git a/src/engine/filesystem/scanner/FileScanner.cpp b/src/engine/filesystem/scanner/FileScanner.cpp index 5dcea0c..2b22419 100644 --- a/src/engine/filesystem/scanner/FileScanner.cpp +++ b/src/engine/filesystem/scanner/FileScanner.cpp @@ -16,7 +16,7 @@ namespace fgl::engine::filesystem DirInfo::DirInfo( const std::filesystem::path& path ) : m_path( path ), total_size( 0 ) { - FGL_ASSERT( std::filesystem::exists( path ) ); + FGL_ASSERT( std::filesystem::exists( path ), "Path must exist" ); for ( auto itter = std::filesystem::directory_iterator( path ); itter != std::filesystem::directory_iterator(); ++itter ) { diff --git a/src/engine/model/Primitive.cpp b/src/engine/model/Primitive.cpp index 959098f..fcdc2c7 100644 --- a/src/engine/model/Primitive.cpp +++ b/src/engine/model/Primitive.cpp @@ -37,9 +37,9 @@ namespace fgl::engine return INVALID_TEXTURE_ID; } - OrientedBoundingBox< CoordinateSpace::World > Primitive::getWorldBounds() const + OrientedBoundingBox< CoordinateSpace::Model > Primitive::getBoundingBox() const { - return m_transform->mat() * m_bounding_box; + return m_bounding_box; } } // namespace fgl::engine diff --git a/src/engine/model/Primitive.hpp b/src/engine/model/Primitive.hpp index 6add5ce..9eb1aa5 100644 --- a/src/engine/model/Primitive.hpp +++ b/src/engine/model/Primitive.hpp @@ -74,8 +74,6 @@ namespace fgl::engine PrimitiveTextures m_textures; - std::optional< TransformComponent > m_transform; - //! Returns true if the primitive is ready to be rendered (must have all textures, vertex buffer, and index buffer ready) bool ready() const { return m_textures.ready() && m_vertex_buffer.ready() && m_index_buffer.ready(); } @@ -88,9 +86,10 @@ namespace fgl::engine m_index_buffer( std::move( index_buffer ) ), m_bounding_box( bounding_box ), m_mode( mode ), - m_textures(), - m_transform() - {} + m_textures() + { + assert( m_bounding_box.scale != glm::vec3( 0.0f ) ); + } Primitive( VertexBufferSuballocation&& vertex_buffer, @@ -102,9 +101,10 @@ namespace fgl::engine m_index_buffer( std::move( index_buffer ) ), m_bounding_box( bounding_box ), m_mode( mode ), - m_textures( std::forward< decltype( m_textures ) >( textures ) ), - m_transform() - {} + m_textures( std::forward< decltype( m_textures ) >( textures ) ) + { + assert( m_bounding_box.scale != glm::vec3( 0.0f ) ); + } Primitive() = delete; Primitive( const Primitive& other ) = delete; @@ -119,7 +119,8 @@ namespace fgl::engine TextureID getAlbedoTextureID() const; TextureID getNormalTextureID() const; - OrientedBoundingBox< CoordinateSpace::World > getWorldBounds() const; + + OrientedBoundingBox< CoordinateSpace::Model > getBoundingBox() const; }; } // namespace fgl::engine diff --git a/src/engine/pipeline/PipelineConfigInfo.cpp b/src/engine/pipeline/PipelineConfigInfo.cpp index f3a25af..62174b1 100644 --- a/src/engine/pipeline/PipelineConfigInfo.cpp +++ b/src/engine/pipeline/PipelineConfigInfo.cpp @@ -19,6 +19,11 @@ namespace fgl::engine info.assembly_info.topology = vk::PrimitiveTopology::eTriangleStrip; } + void PipelineConfigInfo::setLineTopo( PipelineConfigInfo& info ) + { + info.assembly_info.topology = vk::PrimitiveTopology::eLineList; + } + void PipelineConfigInfo::setPointPatch( PipelineConfigInfo& info ) { info.assembly_info.topology = vk::PrimitiveTopology::ePatchList; diff --git a/src/engine/pipeline/PipelineConfigInfo.hpp b/src/engine/pipeline/PipelineConfigInfo.hpp index a1059ae..5b1cff8 100644 --- a/src/engine/pipeline/PipelineConfigInfo.hpp +++ b/src/engine/pipeline/PipelineConfigInfo.hpp @@ -53,8 +53,11 @@ namespace fgl::engine static void setVertexInputType( PipelineConfigInfo& info, const VertexInputType type ); static void disableVertexInput( PipelineConfigInfo& info ); + static void setTriangleListTopo( PipelineConfigInfo& info ); static void setTriangleStripTopo( PipelineConfigInfo& info ); + static void setLineTopo( PipelineConfigInfo& info ); + static void setQuadTesselation( PipelineConfigInfo& info ); static void setPointPatch( PipelineConfigInfo& info ); static void defaultConfig( PipelineConfigInfo& info ); diff --git a/src/engine/pipeline/PipelineT.hpp b/src/engine/pipeline/PipelineT.hpp index e60d874..7529e05 100644 --- a/src/engine/pipeline/PipelineT.hpp +++ b/src/engine/pipeline/PipelineT.hpp @@ -21,18 +21,18 @@ namespace fgl::engine constexpr static std::uint16_t binding_sets { DescriptorSetCollection::binding_sets }; constexpr static bool has_binding_sets { binding_sets != 0 }; - //! Returns the binding type assocaited with the index - template < std::uint16_t binding_set_idx > - using BindingSet = typename DescriptorSetCollection::template BindingSet< binding_set_idx >; - constexpr static std::uint16_t max_binding_set { DescriptorSetCollection::max_binding_set }; constexpr static std::uint16_t set_count { DescriptorSetCollection::set_count }; constexpr static std::uint16_t empty_sets { DescriptorSetCollection::empty_sets }; + //! Returns the binding type assocaited with the index + template < std::uint16_t binding_set_idx > + using BindingSet = typename DescriptorSetCollection::template BindingSet< binding_set_idx >; + static_assert( - ( set_count == 0 && has_constant_range ) || ( set_count == ( max_binding_set + 1 ) ), + set_count == 0 || ( set_count == ( max_binding_set + 1 ) ), "Binding sets must not have any spaces (Use EmptySet)" ); template < std::uint16_t idx > diff --git a/src/engine/primitives/Frustum.cpp b/src/engine/primitives/Frustum.cpp index 29f7c6b..9f4af9f 100644 --- a/src/engine/primitives/Frustum.cpp +++ b/src/engine/primitives/Frustum.cpp @@ -4,11 +4,11 @@ #include "Frustum.hpp" -#include "engine/debug/drawers.hpp" #include "engine/primitives/boxes/AxisAlignedBoundingBox.hpp" #include "engine/primitives/boxes/AxisAlignedBoundingCube.hpp" #include "engine/primitives/boxes/OrientedBoundingBox.hpp" #include "lines/InfiniteLine.hpp" +#include "lines/LineSegment.hpp" namespace fgl::engine { @@ -19,15 +19,16 @@ namespace fgl::engine float dot { glm::dot( vector_between, direction.vec() ) }; - assert( !std::isnan( dot ) ); + if ( std::isnan( dot ) ) return 0.0f; + assert( !std::isinf( dot ) ); return dot; } void processPlane( - const Plane< CoordinateSpace::World > plane, - const LineSegment< CoordinateSpace::World > line, + const Plane< CoordinateSpace::World >& plane, + const LineSegment< CoordinateSpace::World >& line, std::vector< WorldCoordinate >& out_enter_intersections, std::vector< WorldCoordinate >& out_exit_intersections ) { @@ -54,7 +55,7 @@ namespace fgl::engine } WorldCoordinate getFirstExit( - const std::vector< WorldCoordinate >& exit_intersections, const LineSegment< CoordinateSpace::World > line ) + const std::vector< WorldCoordinate >& exit_intersections, const LineSegment< CoordinateSpace::World >& line ) { assert( exit_intersections.size() > 0 ); @@ -77,7 +78,7 @@ namespace fgl::engine } WorldCoordinate getLastEnter( - const std::vector< WorldCoordinate >& enter_intersections, const LineSegment< CoordinateSpace::World > line ) + const std::vector< WorldCoordinate >& enter_intersections, const LineSegment< CoordinateSpace::World >& line ) { assert( enter_intersections.size() > 0 ); @@ -118,9 +119,6 @@ namespace fgl::engine processPlane( top, line, enter_intersections, exit_intersections ); processPlane( bottom, line, enter_intersections, exit_intersections ); - assert( enter_intersections.size() > 1 ); - assert( exit_intersections.size() > 1 ); - if ( enter_intersections.size() == 0 ) return false; if ( exit_intersections.size() == 0 ) return false; @@ -132,10 +130,7 @@ namespace fgl::engine if ( show_intersect ) [[unlikely]] { - debug::world::drawVector( - last_enter, line.getDirection(), std::to_string( distance_to_enter ), glm::vec3( 0.f, 1.f, 0.0f ) ); - debug::world::drawVector( - first_exit, line.getDirection(), std::to_string( distance_to_exit ), glm::vec3( 1.f, 0.f, 0.0f ) ); + //TODO: } return distance_to_exit >= distance_to_enter; diff --git a/src/engine/primitives/Rotation.cpp b/src/engine/primitives/Rotation.cpp index f2ef485..671d3ab 100644 --- a/src/engine/primitives/Rotation.cpp +++ b/src/engine/primitives/Rotation.cpp @@ -7,7 +7,7 @@ #define GLM_ENABLE_EXPERIMENTAL #include -#include "engine/debug/drawers.hpp" +#include namespace fgl::engine { @@ -58,9 +58,11 @@ namespace fgl::engine Rotation::Rotation( const float pitch, const float roll, const float yaw ) : glm::quat( buildQuat( { pitch, roll, yaw } ) ) { - FGL_ASSERT( ::fgl::engine::pitch( *this ) - pitch < glm::epsilon< float >() ); - FGL_ASSERT( ::fgl::engine::yaw( *this ) - yaw < glm::epsilon< float >() ); - FGL_ASSERT( ::fgl::engine::roll( *this ) - roll < glm::epsilon< float >() ); + FGL_ASSERT( + ::fgl::engine::pitch( *this ) - pitch < glm::epsilon< float >(), "Rotation axis does not match input" ); + FGL_ASSERT( ::fgl::engine::yaw( *this ) - yaw < glm::epsilon< float >(), "Rotation axis does not match input" ); + FGL_ASSERT( + ::fgl::engine::roll( *this ) - roll < glm::epsilon< float >(), "Rotation axis does not match input" ); } RotationModifier< RotationModifierType::Roll > Rotation::roll() diff --git a/src/engine/primitives/boxes/BoundingBox.hpp b/src/engine/primitives/boxes/BoundingBox.hpp index 675ff0e..52bae09 100644 --- a/src/engine/primitives/boxes/BoundingBox.hpp +++ b/src/engine/primitives/boxes/BoundingBox.hpp @@ -9,7 +9,7 @@ namespace fgl::engine::interface { - class NormalVector; + struct NormalVector; //! Dummy class to allow for inheriting to pass 'is_bounding_box[ struct BoundingBox diff --git a/src/engine/primitives/matricies/Matrix.hpp b/src/engine/primitives/matricies/Matrix.hpp index 9a097db..c193568 100644 --- a/src/engine/primitives/matricies/Matrix.hpp +++ b/src/engine/primitives/matricies/Matrix.hpp @@ -28,7 +28,7 @@ namespace fgl::engine //Vectors class Vector; - class NormalVector; + struct NormalVector; template < MatrixType MType > class Matrix : public glm::mat4 diff --git a/src/engine/primitives/matricies/RotationMatrix.hpp b/src/engine/primitives/matricies/RotationMatrix.hpp index 3230b2b..b9c5184 100644 --- a/src/engine/primitives/matricies/RotationMatrix.hpp +++ b/src/engine/primitives/matricies/RotationMatrix.hpp @@ -12,7 +12,7 @@ namespace fgl::engine { - class NormalVector; + struct NormalVector; class Vector; class RotationMatrix : public glm::mat3 diff --git a/src/engine/primitives/planes/concepts.hpp b/src/engine/primitives/planes/concepts.hpp index 6b3deac..d5d32ab 100644 --- a/src/engine/primitives/planes/concepts.hpp +++ b/src/engine/primitives/planes/concepts.hpp @@ -17,7 +17,7 @@ namespace fgl::engine class Coordinate; class Vector; - class NormalVector; + struct NormalVector; template < typename T > concept is_plane = requires( T t ) { diff --git a/src/engine/primitives/points/Coordinate.hpp b/src/engine/primitives/points/Coordinate.hpp index 1d9fbd8..c57b355 100644 --- a/src/engine/primitives/points/Coordinate.hpp +++ b/src/engine/primitives/points/Coordinate.hpp @@ -17,7 +17,7 @@ namespace fgl::engine { class Vector; - class NormalVector; + struct NormalVector; template < CoordinateSpace CType > class Coordinate : private glm::vec3 diff --git a/src/engine/primitives/vectors/Vector.hpp b/src/engine/primitives/vectors/Vector.hpp index 48d47f7..b64dc7f 100644 --- a/src/engine/primitives/vectors/Vector.hpp +++ b/src/engine/primitives/vectors/Vector.hpp @@ -19,7 +19,7 @@ namespace fgl::engine template < CoordinateSpace type > class Coordinate; - class NormalVector; + struct NormalVector; //TODO: Make normalized form of Vector class Vector : private glm::vec3 diff --git a/src/engine/rendering/SwapChain.hpp b/src/engine/rendering/SwapChain.hpp index c5c6e60..cc9361b 100644 --- a/src/engine/rendering/SwapChain.hpp +++ b/src/engine/rendering/SwapChain.hpp @@ -111,4 +111,7 @@ namespace fgl::engine submitCommandBuffers( const vk::raii::CommandBuffer& buffers, PresentIndex present_index ); }; + template < typename T > + using PerFrameArray = std::array< T, SwapChain::MAX_FRAMES_IN_FLIGHT >; + } // namespace fgl::engine diff --git a/src/engine/shaders/Compiler.cpp b/src/engine/shaders/Compiler.cpp index 0b183af..0f4c7de 100644 --- a/src/engine/shaders/Compiler.cpp +++ b/src/engine/shaders/Compiler.cpp @@ -22,7 +22,7 @@ namespace fgl::engine compiler = std::make_unique< shaderc::Compiler >(); } - FGL_ASSERT( compiler ); + FGL_ASSERT( compiler, "Compiler invalid!" ); return *compiler; } diff --git a/src/engine/systems/DrawPair.cpp b/src/engine/systems/DrawPair.cpp index a91abad..07d5c99 100644 --- a/src/engine/systems/DrawPair.cpp +++ b/src/engine/systems/DrawPair.cpp @@ -44,13 +44,15 @@ namespace fgl::engine for ( const auto* model_component_ptr : model_components ) { + const auto& model_transform { model_component_ptr->m_transform }; + const auto& comp { *model_component_ptr }; for ( const Primitive& primitive : comp->m_primitives ) { if ( !primitive.ready() ) continue; // Does this primitive pass the bounds check - if ( !frustum.intersects( primitive.getWorldBounds() ) ) continue; + if ( !frustum.intersects( model_transform.mat() * primitive.getBoundingBox() ) ) continue; //assert( primitive.m_texture ); const ModelMatrixInfo matrix_info { .model_matrix = obj.getTransform().mat4(), diff --git a/src/engine/systems/EntityRendererSystem.hpp b/src/engine/systems/EntityRendererSystem.hpp index 6d45d65..4791ed2 100644 --- a/src/engine/systems/EntityRendererSystem.hpp +++ b/src/engine/systems/EntityRendererSystem.hpp @@ -38,9 +38,6 @@ namespace fgl::engine using ModelMatrixInfoBufferSuballocation = HostVector< ModelMatrixInfo >; - template < typename T > - using PerFrameArray = std::array< T, SwapChain::MAX_FRAMES_IN_FLIGHT >; - // Simple parameter buffers PerFrameArray< std::unique_ptr< DrawParameterBufferSuballocation > > m_draw_simple_parameter_buffers {}; PerFrameArray< std::unique_ptr< ModelMatrixInfoBufferSuballocation > > m_simple_model_matrix_info_buffers {}; diff --git a/src/engine/systems/LineDrawer.cpp b/src/engine/systems/LineDrawer.cpp new file mode 100644 index 0000000..01b4a86 --- /dev/null +++ b/src/engine/systems/LineDrawer.cpp @@ -0,0 +1,93 @@ +// +// Created by kj16609 on 8/10/24. +// + +#include "LineDrawer.hpp" + +#include "engine/FrameInfo.hpp" +#include "engine/buffers/vector/HostVector.hpp" +#include "engine/camera/CameraDescriptor.hpp" +#include "engine/model/ModelVertex.hpp" +#include "engine/model/SimpleVertex.hpp" +#include "engine/primitives/points/Coordinate.hpp" + +namespace fgl::engine +{ + + struct VertexLine + { + SimpleVertex p1 {}; + SimpleVertex p2 {}; + }; + + inline static std::vector< VertexLine > m_lines {}; + + LineDrawer::LineDrawer( Device& device, vk::raii::RenderPass& render_pass ) + { + PipelineConfigInfo config { render_pass }; + + PipelineConfigInfo::addGBufferAttachmentsConfig( config ); + PipelineConfigInfo::setVertexInputType( config, Simple ); + PipelineConfigInfo::setLineTopo( config ); + + m_pipeline = std::make_unique< LinePipeline >( device, std::move( config ) ); + } + + LineDrawer::~LineDrawer() + {} + + vk::raii::CommandBuffer& LineDrawer::setupSystem( FrameInfo& info ) + { + auto& command_buffer { info.command_buffer }; + m_pipeline->bind( command_buffer ); + + m_pipeline->bindDescriptor( command_buffer, CameraDescriptorSet::m_set_idx, info.getCameraDescriptor() ); + + return command_buffer; + } + + void LineDrawer::pass( FrameInfo& info ) + { + ZoneScopedN( "Debug line drawing" ); + auto& command_buffer { setupSystem( info ) }; + TracyVkZone( info.tracy_ctx, *command_buffer, "Draw debug lines" ); + + if ( m_lines.size() == 0 ) + { + VertexLine line; + auto& [ p1, p2 ] = line; + p1.m_position = constants::WORLD_CENTER; + p2.m_position = constants::WORLD_FORWARD * 20.0f; + + m_lines.emplace_back( line ); + } + + auto& line_vertex_buffer { m_line_vertex_buffer[ info.frame_idx ] }; + + line_vertex_buffer = std::make_unique< HostVector< VertexLine > >( info.model_matrix_info_buffer, m_lines ); + + command_buffer.bindVertexBuffers( 0, line_vertex_buffer->getVkBuffer(), { line_vertex_buffer->getOffset() } ); + + command_buffer.draw( m_lines.size() * 2, m_lines.size(), 0, 0 ); + } + + void cleanupLineQueue() + { + m_lines.clear(); + } + + namespace debug + { + void drawLine( const WorldCoordinate& p1, const WorldCoordinate& p2 ) + { + VertexLine line {}; + auto& [ p1v, p2v ] = line; + + p1v.m_position = p1.vec(); + p2v.m_position = p2.vec(); + + m_lines.emplace_back( std::move( line ) ); + } + } // namespace debug + +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/systems/LineDrawer.hpp b/src/engine/systems/LineDrawer.hpp new file mode 100644 index 0000000..21a89dd --- /dev/null +++ b/src/engine/systems/LineDrawer.hpp @@ -0,0 +1,46 @@ +// +// Created by kj16609 on 8/10/24. +// + +#pragma once +#include "engine/buffers/vector/HostVector.hpp" +#include "engine/camera/CameraDescriptor.hpp" +#include "engine/descriptors/Descriptor.hpp" +#include "engine/descriptors/DescriptorSetCollection.hpp" +#include "engine/pipeline/PipelineT.hpp" +#include "engine/rendering/SwapChain.hpp" + +namespace fgl::engine +{ + struct VertexLine; + struct FrameInfo; + struct ModelVertex; + + class LineDrawer + { + using VertexShader = VertexShaderT< "shaders/line.vert" >; + using FragmentShader = FragmentShaderT< "shaders/line.frag" >; + + using LinePipeline = PipelineT< + ShaderCollection< VertexShader, FragmentShader >, + descriptors::DescriptorSetCollection< descriptors::EmptyDescriptorSet< 0 >, CameraDescriptorSet > >; + + std::unique_ptr< LinePipeline > m_pipeline {}; + + PerFrameArray< std::unique_ptr< HostVector< VertexLine > > > m_line_vertex_buffer {}; + + public: + + FGL_DELETE_ALL_Ro5( LineDrawer ); + + vk::raii::CommandBuffer& setupSystem( FrameInfo& info ); + void pass( FrameInfo& info ); + + LineDrawer( Device& device, vk::raii::RenderPass& render_pass ); + + ~LineDrawer(); + }; + + void cleanupLineQueue(); + +} // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/tree/octtree/OctTreeNode.cpp b/src/engine/tree/octtree/OctTreeNode.cpp index a6024d0..871403d 100644 --- a/src/engine/tree/octtree/OctTreeNode.cpp +++ b/src/engine/tree/octtree/OctTreeNode.cpp @@ -8,7 +8,6 @@ #include #include -#include "engine/debug/drawers.hpp" #include "engine/model/Model.hpp" #include "engine/primitives/Frustum.hpp" @@ -221,8 +220,8 @@ namespace fgl::engine { if ( ( draw_inview_bounds || std::holds_alternative< OctTreeNodeLeaf >( this->m_node_data ) ) && m_parent ) { - if ( draw_leaf_fit_bounds ) debug::world::drawBoundingBox( m_fit_bounding_box ); - if ( draw_leaf_real_bounds ) debug::world::drawBoundingBox( m_bounds ); + // if ( draw_leaf_fit_bounds ) debug::world::drawBoundingBox( m_fit_bounding_box ); + // if ( draw_leaf_real_bounds ) debug::world::drawBoundingBox( m_bounds ); } return true; diff --git a/src/shaders/include/camera.glsl b/src/shaders/include/camera.glsl new file mode 100644 index 0000000..46966c8 --- /dev/null +++ b/src/shaders/include/camera.glsl @@ -0,0 +1,5 @@ +layout (set = 1, binding = 0) uniform CameraInfo { + mat4 projection; + mat4 view; + mat4 inverse_view; +} ubo; diff --git a/src/shaders/include/gbuffer_out.glsl b/src/shaders/include/gbuffer_out.glsl new file mode 100644 index 0000000..cd50f21 --- /dev/null +++ b/src/shaders/include/gbuffer_out.glsl @@ -0,0 +1,3 @@ +layout (location = 0) out vec4 out_position; +layout (location = 1) out vec4 out_normal; +layout (location = 2) out vec4 out_albedo; diff --git a/src/shaders/line.frag b/src/shaders/line.frag new file mode 100644 index 0000000..282a0ae --- /dev/null +++ b/src/shaders/line.frag @@ -0,0 +1,7 @@ +#version 450 + +#include "include/gbuffer_out.glsl" + +void main() { + out_albedo = vec4(1.0); +} \ No newline at end of file diff --git a/src/shaders/line.vert b/src/shaders/line.vert new file mode 100644 index 0000000..ba6af57 --- /dev/null +++ b/src/shaders/line.vert @@ -0,0 +1,10 @@ +#version 450 + +layout(location = 0) in vec3 in_pos; + +#include "include/camera.glsl" + +void main() +{ + gl_Position = ubo.projection * ubo.view * vec4(in_pos, 1.0); +} diff --git a/src/shaders/textured-gbuffer.frag b/src/shaders/textured-gbuffer.frag index 07b3276..d89a0ce 100644 --- a/src/shaders/textured-gbuffer.frag +++ b/src/shaders/textured-gbuffer.frag @@ -9,9 +9,7 @@ layout (location = 3) in flat uint in_albedo_idx; layout (location = 4) in flat uint in_normal_idx; layout (location = 5) in flat uint in_metallic_roughness_idx; -layout (location = 0) out vec4 out_position; -layout (location = 1) out vec4 out_normal; -layout (location = 2) out vec4 out_albedo; +#include "include/gbuffer_out.glsl" layout (set = 1, binding = 0) uniform CameraInfo { mat4 projection; diff --git a/src/shaders/textured-gbuffer.vert b/src/shaders/textured-gbuffer.vert index 8b55537..3d8b59a 100644 --- a/src/shaders/textured-gbuffer.vert +++ b/src/shaders/textured-gbuffer.vert @@ -11,11 +11,7 @@ layout (location = 3) out flat uint out_albedo_id; layout (location = 4) out flat uint out_normal_id; layout (location = 5) out flat uint out_metallic_roughness_id; -layout (set = 1, binding = 0) uniform CameraInfo { - mat4 projection; - mat4 view; - mat4 inverse_view; -} ubo; +#include "include/camera.glsl" void main() {