Cleanup and housekeeping
This commit is contained in:
@@ -26,7 +26,7 @@ namespace fgl::engine
|
||||
if ( m_textures.albedo )
|
||||
return m_textures.albedo->getID();
|
||||
else
|
||||
return INVALID_TEXTURE_ID;
|
||||
return constants::INVALID_TEXTURE_ID;
|
||||
}
|
||||
|
||||
TextureID Primitive::getNormalTextureID() const
|
||||
@@ -34,7 +34,7 @@ namespace fgl::engine
|
||||
if ( m_textures.normal )
|
||||
return m_textures.normal->getID();
|
||||
else
|
||||
return INVALID_TEXTURE_ID;
|
||||
return constants::INVALID_TEXTURE_ID;
|
||||
}
|
||||
|
||||
OrientedBoundingBox< CoordinateSpace::Model > Primitive::getBoundingBox() const
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// Created by kj16609 on 3/16/24.
|
||||
//
|
||||
|
||||
#include "terrainModel.hpp"
|
||||
|
||||
#include "engine/assets/model/Model.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
|
||||
std::shared_ptr< Model > generateTerrainModel( memory::Buffer& vertex_buffer, memory::Buffer& index_buffer )
|
||||
{
|
||||
std::vector< ModelVertex > verts {};
|
||||
|
||||
constexpr glm::vec3 TOP_LEFT { -0.5f, 0.5f, 0.0f };
|
||||
constexpr glm::vec3 TOP_RIGHT { 0.5f, 0.5f, 0.0f };
|
||||
constexpr glm::vec3 BOTTOM_RIGHT { 0.5f, -0.5f, 0.0f };
|
||||
constexpr glm::vec3 BOTTOM_LEFT { -0.5f, -0.5f, 0.0f };
|
||||
constexpr float dist_mulpt { 2.0f };
|
||||
|
||||
verts.emplace_back( TOP_LEFT * dist_mulpt, glm::vec3( 1.0f ), constants::WORLD_Z, glm::vec2( 0.0f, 0.0f ) );
|
||||
verts.emplace_back( TOP_RIGHT * dist_mulpt, glm::vec3( 1.0f ), constants::WORLD_Z, glm::vec2( 1.0f, 0.0f ) );
|
||||
verts
|
||||
.emplace_back( BOTTOM_RIGHT * dist_mulpt, glm::vec3( 1.0f ), constants::WORLD_Z, glm::vec2( 1.0f, 1.0f ) );
|
||||
verts.emplace_back( BOTTOM_LEFT * dist_mulpt, glm::vec3( 1.0f ), constants::WORLD_Z, glm::vec2( 0.0f, 1.0f ) );
|
||||
|
||||
std::vector< std::uint32_t > indicies { 0, 1, 2, 3 };
|
||||
|
||||
std::shared_ptr< Model > model {
|
||||
Model::createModelFromVerts( std::move( verts ), std::move( indicies ), vertex_buffer, index_buffer )
|
||||
};
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
} // namespace fgl::engine
|
||||
@@ -1,20 +0,0 @@
|
||||
//
|
||||
// Created by kj16609 on 3/16/24.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
class Model;
|
||||
|
||||
namespace memory
|
||||
{
|
||||
class Buffer;
|
||||
}
|
||||
|
||||
std::shared_ptr< Model > generateTerrainModel( memory::Buffer& vertex_buffer, memory::Buffer& index_buffer );
|
||||
|
||||
} // namespace fgl::engine
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <glm/vec3.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
namespace fgl::engine::constants
|
||||
{
|
||||
|
||||
@@ -35,10 +37,6 @@ namespace fgl::engine::constants
|
||||
constexpr float FAR_PLANE { 1000.0f };
|
||||
constexpr glm::vec3 CENTER { 0.0f, 0.0f, 0.0f };
|
||||
|
||||
constexpr auto EPSILON { std::numeric_limits< float >::epsilon() * 2 };
|
||||
|
||||
constexpr auto FRUSTUM_ORIGIN { constants::WORLD_CENTER };
|
||||
|
||||
constexpr glm::mat4 MAT4_IDENTITY { 1.0f };
|
||||
constexpr glm::mat3 MAT3_IDENTITY { 1.0f };
|
||||
|
||||
@@ -49,4 +47,8 @@ namespace fgl::engine::constants
|
||||
constexpr glm::vec3 WORLD_LEFT { -WORLD_RIGHT };
|
||||
constexpr glm::vec3 WORLD_DOWN { -WORLD_UP };
|
||||
|
||||
constexpr std::uint32_t INVALID_TEX_ID { std::numeric_limits< std::uint32_t >::max() };
|
||||
|
||||
constexpr TextureID INVALID_TEXTURE_ID { 0 };
|
||||
|
||||
} // namespace fgl::engine::constants
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tracy/Tracy.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -73,6 +75,7 @@ namespace fgl::engine
|
||||
requires is_component< T >
|
||||
bool hasComponent() const
|
||||
{
|
||||
ZoneScoped;
|
||||
for ( const GameObjectComponentPtr comp : components )
|
||||
{
|
||||
if ( comp->id() == T::ID ) return true;
|
||||
@@ -85,6 +88,7 @@ namespace fgl::engine
|
||||
requires is_component< T >
|
||||
std::vector< const T* > getComponents() const
|
||||
{
|
||||
ZoneScopedN( "Get components" );
|
||||
std::vector< const T* > temp {};
|
||||
|
||||
for ( const ComponentEngineInterface* comp : components )
|
||||
@@ -99,6 +103,7 @@ namespace fgl::engine
|
||||
requires is_component< T >
|
||||
std::vector< T* > getComponents()
|
||||
{
|
||||
ZoneScopedN( "Get components" );
|
||||
std::vector< T* > temp {};
|
||||
|
||||
for ( ComponentEngineInterface* comp : components )
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "Frustum.hpp"
|
||||
|
||||
#include <tracy/Tracy.hpp>
|
||||
|
||||
#include "engine/debug/drawers.hpp"
|
||||
#include "engine/primitives/boxes/AxisAlignedBoundingBox.hpp"
|
||||
#include "engine/primitives/boxes/AxisAlignedBoundingCube.hpp"
|
||||
@@ -16,9 +18,9 @@ namespace fgl::engine
|
||||
|
||||
Frustum operator*( const Matrix< MatrixType::ModelToWorld >& matrix, const FrustumBase& frustum )
|
||||
{
|
||||
Frustum result { matrix * frustum.near, matrix * frustum.far, matrix * frustum.top,
|
||||
matrix * frustum.bottom, matrix * frustum.right, matrix * frustum.left,
|
||||
matrix * frustum.m_position };
|
||||
const Frustum result { matrix * frustum.near, matrix * frustum.far, matrix * frustum.top,
|
||||
matrix * frustum.bottom, matrix * frustum.right, matrix * frustum.left,
|
||||
matrix * frustum.m_position };
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -27,7 +29,7 @@ namespace fgl::engine
|
||||
{
|
||||
const glm::vec3 vector_between { point.vec() - origin.vec() };
|
||||
|
||||
float dot { glm::dot( vector_between, direction.vec() ) };
|
||||
const float dot { glm::dot( vector_between, direction.vec() ) };
|
||||
|
||||
if ( std::isnan( dot ) ) return 0.0f;
|
||||
|
||||
@@ -189,7 +191,7 @@ namespace fgl::engine
|
||||
{
|
||||
const auto points { this->points() };
|
||||
|
||||
std::array< LineSegment< CoordinateSpace::World >, ( ( 4 * 2 ) / 2 ) * 3 > lines;
|
||||
std::array< LineSegment< CoordinateSpace::World >, ( ( 4 * 2 ) / 2 ) * 3 > lines {};
|
||||
|
||||
//Top
|
||||
lines[ 0 ] = LineSegment< CoordinateSpace::World >( points[ 0 ], points[ 1 ] );
|
||||
@@ -261,16 +263,15 @@ namespace fgl::engine
|
||||
std::pair< float, float > minMaxDot( const NormalVector axis, const auto points )
|
||||
{
|
||||
assert( points.size() > 2 );
|
||||
float min { glm::dot( points[ 0 ].vec(), axis.vec() ) };
|
||||
float max { glm::dot( points[ 0 ].vec(), axis.vec() ) };
|
||||
float min { std::numeric_limits< float >::infinity() };
|
||||
float max { -std::numeric_limits< float >::infinity() };
|
||||
|
||||
for ( std::size_t i = 0; i < points.size(); ++i )
|
||||
{
|
||||
const auto value { glm::dot( points[ i ].vec(), axis.vec() ) };
|
||||
if ( value < min )
|
||||
min = value;
|
||||
else if ( value > max )
|
||||
max = value;
|
||||
|
||||
min = std::min( min, value );
|
||||
max = std::max( max, value );
|
||||
}
|
||||
|
||||
return std::make_pair( min, max );
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <fstream>
|
||||
|
||||
#include "engine/FGL_DEFINES.hpp"
|
||||
#include "engine/constants.hpp"
|
||||
#include "engine/debug/logging/logging.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
@@ -118,6 +119,11 @@ namespace fgl::engine
|
||||
|
||||
options.SetVulkanRulesRelaxed( false );
|
||||
|
||||
// Add macro defs to the shader
|
||||
options.AddMacroDefinition( "INVALID_TEXTURE_ID", std::to_string( constants::INVALID_TEXTURE_ID ) );
|
||||
options.AddMacroDefinition( "NEAR_PLANE", std::to_string( constants::NEAR_PLANE ) );
|
||||
options.AddMacroDefinition( "FAR_PLANE", std::to_string( constants::FAR_PLANE ) );
|
||||
|
||||
const shaderc_shader_kind kind { getShaderKindFromName( input_name ) };
|
||||
|
||||
const auto preprocessed_source { getInstance().PreprocessGlsl(
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace fgl::engine
|
||||
{
|
||||
ZoneScoped;
|
||||
std::unordered_map< DrawKey, DrawPair > draw_pairs {};
|
||||
draw_pairs.reserve( 512 );
|
||||
|
||||
const auto nodes { root.getAllLeafsInFrustum( frustum ) };
|
||||
|
||||
@@ -89,6 +90,7 @@ namespace fgl::engine
|
||||
|
||||
if ( auto itter = draw_pairs.find( key ); itter != draw_pairs.end() )
|
||||
{
|
||||
ZoneScopedN( "Accumulate for draw pair" );
|
||||
//Draw command for this mesh already exists. Simply add a count to it
|
||||
auto& [ itter_key, pair ] = *itter;
|
||||
auto& [ existing_cmd, model_matrix ] = pair;
|
||||
@@ -99,6 +101,7 @@ namespace fgl::engine
|
||||
}
|
||||
else
|
||||
{
|
||||
ZoneScopedN( "Create new draw pair" );
|
||||
vk::DrawIndexedIndirectCommand cmd {};
|
||||
|
||||
cmd.firstIndex = primitive.m_index_buffer.getOffsetCount();
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace fgl::engine
|
||||
}
|
||||
}
|
||||
|
||||
vk::raii::CommandBuffer& EntityRendererSystem::setupSystem( FrameInfo& info )
|
||||
vk::raii::CommandBuffer& EntityRendererSystem::setupSystem( const FrameInfo& info )
|
||||
{
|
||||
auto& command_buffer { info.command_buffer };
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace fgl::engine
|
||||
texturedPass( info );
|
||||
}
|
||||
|
||||
void EntityRendererSystem::texturelessPass( FrameInfo& info )
|
||||
void EntityRendererSystem::texturelessPass( const FrameInfo& info )
|
||||
{
|
||||
ZoneScopedN( "Textureless pass" );
|
||||
auto& command_buffer { info.command_buffer };
|
||||
@@ -104,7 +104,7 @@ namespace fgl::engine
|
||||
draw_parameter_buffer->stride() );
|
||||
}
|
||||
|
||||
void EntityRendererSystem::texturedPass( FrameInfo& info )
|
||||
void EntityRendererSystem::texturedPass( const FrameInfo& info )
|
||||
{
|
||||
ZoneScopedN( "Textured pass" );
|
||||
auto& command_buffer { info.command_buffer };
|
||||
|
||||
@@ -46,13 +46,13 @@ namespace fgl::engine
|
||||
PerFrameArray< std::unique_ptr< DrawParameterBufferSuballocation > > m_draw_textured_parameter_buffers {};
|
||||
PerFrameArray< std::unique_ptr< ModelMatrixInfoBufferSuballocation > > m_textured_model_matrix_info_buffers {};
|
||||
|
||||
vk::raii::CommandBuffer& setupSystem( FrameInfo& );
|
||||
vk::raii::CommandBuffer& setupSystem( const FrameInfo& );
|
||||
|
||||
public:
|
||||
|
||||
void pass( FrameInfo& info );
|
||||
void texturelessPass( FrameInfo& info );
|
||||
void texturedPass( FrameInfo& info );
|
||||
void texturelessPass( const FrameInfo& info );
|
||||
void texturedPass( const FrameInfo& info );
|
||||
|
||||
EntityRendererSystem( Device& device, vk::raii::RenderPass& render_pass );
|
||||
~EntityRendererSystem() = default;
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "engine/assets/AssetManager.hpp"
|
||||
#include "engine/assets/image/ImageView.hpp"
|
||||
#include "engine/assets/image/Sampler.hpp"
|
||||
#include "engine/types.hpp"
|
||||
#include "engine/constants.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -35,8 +37,7 @@ namespace fgl::engine
|
||||
|
||||
using TextureStore = AssetStore< Texture >;
|
||||
|
||||
using TextureID = std::uint32_t;
|
||||
constexpr TextureID INVALID_TEXTURE_ID { 0 };
|
||||
|
||||
|
||||
//TODO: Implement texture handle map to avoid loading the same texture multiple times
|
||||
class Texture final : public AssetInterface< Texture >
|
||||
|
||||
@@ -51,10 +51,12 @@ namespace fgl::engine
|
||||
|
||||
void OctTreeNode::getAllLeafsInFrustum( const Frustum& frustum, std::vector< OctTreeNodeLeaf* >& out_leafs )
|
||||
{
|
||||
ZoneScoped;
|
||||
//Check if we are inside of the frustum.
|
||||
if ( !isInFrustum( frustum ) ) return;
|
||||
|
||||
auto& leafs { out_leafs };
|
||||
leafs.reserve( 256 );
|
||||
|
||||
switch ( m_node_data.index() )
|
||||
{
|
||||
|
||||
10
src/engine/types.hpp
Normal file
10
src/engine/types.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by kj16609 on 10/4/24.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
using TextureID = std::uint32_t;
|
||||
}
|
||||
@@ -19,25 +19,19 @@ layout (set = 1, binding = 0) uniform CameraInfo {
|
||||
|
||||
layout (set = 2, binding = 0) uniform sampler2D tex[];
|
||||
|
||||
#define NEAR_PLANE 0.01f
|
||||
#define FAR_PLANE 1000.0f
|
||||
|
||||
float linearDepth(float depth)
|
||||
{
|
||||
float z = depth * 2.0f - 1.0f;
|
||||
return (2.0f * NEAR_PLANE * FAR_PLANE) / (FAR_PLANE + NEAR_PLANE - z * (FAR_PLANE - NEAR_PLANE));
|
||||
}
|
||||
|
||||
uint INVALID_TEX_ID = 0;
|
||||
|
||||
void main()
|
||||
{
|
||||
out_position = vec4(in_world_pos, 1.0f);
|
||||
|
||||
|
||||
vec3 N = vec3(0.0f);
|
||||
|
||||
if (in_normal_idx == INVALID_TEX_ID)
|
||||
if (in_normal_idx == INVALID_TEXTURE_ID)
|
||||
{
|
||||
N = normalize(in_normal);
|
||||
}
|
||||
|
||||
@@ -17,9 +17,6 @@ layout (set = 1, binding = 0) uniform CameraInfo {
|
||||
mat4 inverse_view;
|
||||
} ubo;
|
||||
|
||||
#define NEAR_PLANE 0.01f
|
||||
#define FAR_PLANE 1000.0f
|
||||
|
||||
float linearDepth(float depth)
|
||||
{
|
||||
float z = depth * 2.0f - 1.0f;
|
||||
|
||||
Reference in New Issue
Block a user