working on chunk generation

This commit is contained in:
Kbz-8
2025-05-09 18:29:41 +02:00
parent 332ef1fc41
commit 694009e6e4
10 changed files with 221 additions and 23 deletions

View File

@@ -1,6 +1,47 @@
#ifndef BLOCK_H
#define BLOCK_H
#include <vector>
#include <ScopGraphics.h>
static const std::vector<Scop::Vertex> BLOCK_MESH = {
Scop::Vertex{ Scop::Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec2f{ 0, 0 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec2f{ 1, 0 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec2f{ 1, 1 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec2f{ 1, 1 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec2f{ 0, 1 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec2f{ 0, 0 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, -1.0f, 1.0f }, Scop::Vec2f{ 0, 0 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, -1.0f, 1.0f }, Scop::Vec2f{ 1, 0 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, -1.0f, 1.0f }, Scop::Vec2f{ 1, 1 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, -1.0f, 1.0f }, Scop::Vec2f{ 1, 1 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 1.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, -1.0f, 1.0f }, Scop::Vec2f{ 0, 1 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, 0.0f, -1.0f, 1.0f }, Scop::Vec2f{ 0, 0 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 1.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, -1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 0 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, -1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 1 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, -1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 1 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, -1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 1 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, -1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 0 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 1.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, -1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 0 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 0 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 1 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 1 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec4f{ 0.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 1 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 0 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f }, Scop::Vec4f{ 0.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 0 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec4f{ -1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 1 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec4f{ -1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 1 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec4f{ -1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 0 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec4f{ -1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 0 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 0.0f, 1.0f, 1.0f }, Scop::Vec4f{ -1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 0 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec4f{ -1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 1 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec4f{ 1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 1 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec4f{ 1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 1 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f }, Scop::Vec4f{ 1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 0 } },
Scop::Vertex{ Scop::Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f }, Scop::Vec4f{ 1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 1, 0 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 1.0f, 1.0f, 1.0f }, Scop::Vec4f{ 1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 0 } },
Scop::Vertex{ Scop::Vec4f{ 0.0f, 1.0f, 0.0f, 1.0f }, Scop::Vec4f{ 1.0f, 0.0f, 0.0f, 1.0f }, Scop::Vec2f{ 0, 1 } }
};
#endif

View File

@@ -1,29 +1,137 @@
#include <Chunk.h>
#include <algorithm>
#include <Block.h>
#include <World.h>
Chunk::Chunk(Scop::Scene& world, Scop::Vec2ui offset) : m_data(CHUNK_VOLUME), m_offset(offset), m_position(std::move(offset) * Scop::Vec2ui{ CHUNK_SIZE })
#include <cmath>
Chunk::Chunk(World& world, Scop::Vec2i offset) : m_offset(offset), m_position(std::move(offset) * Scop::Vec2i{ CHUNK_SIZE.x, CHUNK_SIZE.z }), m_world(world)
{
m_data.resize(CHUNK_SIZE.x);
for(auto& z: m_data)
{
z.resize(CHUNK_SIZE.z);
for(auto& y: z)
y.resize(CHUNK_SIZE.y);
}
}
void Chunk::GenerateChunk()
{
std::fill(m_data.begin(), m_data.end(), 0);
for(auto& z: m_data)
{
for(auto& y: z)
std::fill(y.begin(), y.end(), 0);
}
std::vector<Scop::Vertex> mesh_data;
std::vector<std::uint32_t> indices;
for(std::uint32_t x = 0; x < CHUNK_SIZE.x; x++)
{
for(std::uint32_t z = 0; z < CHUNK_SIZE.z; z++)
{
std::uint32_t pos_x = m_position.x + x;
std::uint32_t pos_z = m_position.y + z;
// Implement noise here
std::uint32_t height = 4 + std::sin(x) + std::cos(z);
for(std::uint32_t y = 0; y < height; y++)
m_data[x][z][y] = 1;
}
}
for(std::uint32_t x = 0; x < CHUNK_SIZE.x; x++)
{
for(std::uint32_t z = 0; z < CHUNK_SIZE.z; z++)
{
for(std::uint32_t y = 0; y < CHUNK_SIZE.y; y++)
{
std::uint32_t index = (z * CHUNK_SIZE.x * CHUNK_SIZE.y) + (y * CHUNK_SIZE.x) + x;
if(!GetBlock(Scop::Vec3i(x, y, z)))
continue;
if(!GetBlock(Scop::Vec3i(x, y, static_cast<std::int32_t>(z) - 1)))
{
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[0].position + Scop::Vec3f(x, y, z), BLOCK_MESH[0].normal, BLOCK_MESH[0].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[1].position + Scop::Vec3f(x, y, z), BLOCK_MESH[1].normal, BLOCK_MESH[1].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[2].position + Scop::Vec3f(x, y, z), BLOCK_MESH[2].normal, BLOCK_MESH[2].uv));
// Implement noise here
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[3].position + Scop::Vec3f(x, y, z), BLOCK_MESH[3].normal, BLOCK_MESH[3].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[4].position + Scop::Vec3f(x, y, z), BLOCK_MESH[4].normal, BLOCK_MESH[4].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[5].position + Scop::Vec3f(x, y, z), BLOCK_MESH[5].normal, BLOCK_MESH[5].uv));
}
m_data[index] = y < 10 ? 1 : 0;
if(!GetBlock(Scop::Vec3i(x, y, z + 1)))
{
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[6].position + Scop::Vec3f(x, y, z), BLOCK_MESH[6].normal, BLOCK_MESH[6].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[7].position + Scop::Vec3f(x, y, z), BLOCK_MESH[7].normal, BLOCK_MESH[7].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[8].position + Scop::Vec3f(x, y, z), BLOCK_MESH[8].normal, BLOCK_MESH[8].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[9].position + Scop::Vec3f(x, y, z), BLOCK_MESH[9].normal, BLOCK_MESH[9].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[10].position + Scop::Vec3f(x, y, z), BLOCK_MESH[10].normal, BLOCK_MESH[10].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[11].position + Scop::Vec3f(x, y, z), BLOCK_MESH[11].normal, BLOCK_MESH[11].uv));
}
if(!GetBlock(Scop::Vec3i(static_cast<std::int32_t>(x) - 1, y, z)))
{
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[12].position + Scop::Vec3f(x, y, z), BLOCK_MESH[12].normal, BLOCK_MESH[12].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[13].position + Scop::Vec3f(x, y, z), BLOCK_MESH[13].normal, BLOCK_MESH[13].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[14].position + Scop::Vec3f(x, y, z), BLOCK_MESH[14].normal, BLOCK_MESH[14].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[15].position + Scop::Vec3f(x, y, z), BLOCK_MESH[15].normal, BLOCK_MESH[15].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[16].position + Scop::Vec3f(x, y, z), BLOCK_MESH[16].normal, BLOCK_MESH[16].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[17].position + Scop::Vec3f(x, y, z), BLOCK_MESH[17].normal, BLOCK_MESH[17].uv));
}
if(!GetBlock(Scop::Vec3i(x + 1, y, z)))
{
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[18].position + Scop::Vec3f(x, y, z), BLOCK_MESH[18].normal, BLOCK_MESH[18].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[19].position + Scop::Vec3f(x, y, z), BLOCK_MESH[19].normal, BLOCK_MESH[19].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[20].position + Scop::Vec3f(x, y, z), BLOCK_MESH[20].normal, BLOCK_MESH[20].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[21].position + Scop::Vec3f(x, y, z), BLOCK_MESH[21].normal, BLOCK_MESH[21].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[22].position + Scop::Vec3f(x, y, z), BLOCK_MESH[22].normal, BLOCK_MESH[22].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[23].position + Scop::Vec3f(x, y, z), BLOCK_MESH[23].normal, BLOCK_MESH[23].uv));
}
if(!GetBlock(Scop::Vec3i(x, static_cast<std::int32_t>(y) - 1, z)))
{
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[24].position + Scop::Vec3f(x, y, z), BLOCK_MESH[24].normal, BLOCK_MESH[24].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[25].position + Scop::Vec3f(x, y, z), BLOCK_MESH[25].normal, BLOCK_MESH[25].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[26].position + Scop::Vec3f(x, y, z), BLOCK_MESH[26].normal, BLOCK_MESH[26].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[27].position + Scop::Vec3f(x, y, z), BLOCK_MESH[27].normal, BLOCK_MESH[27].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[28].position + Scop::Vec3f(x, y, z), BLOCK_MESH[28].normal, BLOCK_MESH[28].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[29].position + Scop::Vec3f(x, y, z), BLOCK_MESH[29].normal, BLOCK_MESH[29].uv));
}
if(!GetBlock(Scop::Vec3i(x, y + 1, z)))
{
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[30].position + Scop::Vec3f(x, y, z), BLOCK_MESH[30].normal, BLOCK_MESH[30].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[31].position + Scop::Vec3f(x, y, z), BLOCK_MESH[31].normal, BLOCK_MESH[31].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[32].position + Scop::Vec3f(x, y, z), BLOCK_MESH[32].normal, BLOCK_MESH[32].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[33].position + Scop::Vec3f(x, y, z), BLOCK_MESH[33].normal, BLOCK_MESH[33].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[34].position + Scop::Vec3f(x, y, z), BLOCK_MESH[34].normal, BLOCK_MESH[34].uv));
mesh_data.push_back(Scop::Vertex(BLOCK_MESH[35].position + Scop::Vec3f(x, y, z), BLOCK_MESH[35].normal, BLOCK_MESH[35].uv));
}
}
}
}
for(std::uint32_t i = 0; i < mesh_data.size(); i++)
indices.push_back(i);
std::shared_ptr<Scop::Mesh> mesh = std::make_shared<Scop::Mesh>();
mesh->AddSubMesh({ std::move(mesh_data), std::move(indices) });
Scop::Actor& actor = m_world.GetScene().CreateActor(mesh);
actor.GetModelRef().SetMaterial(m_world.GetBlockMaterial(), 0);
actor.SetScale(Scop::Vec3f{ 2.0f });
actor.SetPosition(Scop::Vec3f(m_position.x, 0.0f, m_position.y));
p_actor = &actor;
}
std::uint32_t Chunk::GetBlock(Scop::Vec3i position) const noexcept
{
//if(position.x < 0 || position.x >= m_data.size() || position.z < 0 || position.z >= m_data[position.x >= m_data.size() ? m_data.size() - 1 : position.x].size() || position.y < 0)
// return 1;
if(position.x < m_data.size() && position.z < m_data[position.x].size() && position.y < m_data[position.x][position.z].size())
return m_data[position.x][position.z][position.y];
return 0;
}

View File

@@ -6,21 +6,22 @@
#include <ScopMaths.h>
constexpr Scop::Vec3ui CHUNK_SIZE = Scop::Vec3ui{ 16, 256, 16 };
constexpr std::uint32_t CHUNK_VOLUME = CHUNK_SIZE.x * CHUNK_SIZE.y * CHUNK_SIZE.z;
class Chunk
{
public:
Chunk(Scop::Scene& world, Scop::Vec2ui offset);
Chunk(class World& world, Scop::Vec2i offset);
void GenerateChunk();
std::uint32_t GetBlock(Scop::Vec3i position) const noexcept;
~Chunk() = default;
private:
std::vector<std::uint32_t> m_data;
Scop::Vec2ui m_offset; // In chunks
Scop::Vec2ui m_position; // In blocks
std::vector<std::vector<std::vector<std::uint32_t>>> m_data; // Should be a flat array but I cannot manage to flatten the 3D coordinates correctly
Scop::Vec2i m_offset; // In chunks
Scop::Vec2i m_position; // In blocks
class World& m_world;
Scop::NonOwningPtr<Scop::Actor> p_actor = nullptr;
};

View File

@@ -10,9 +10,27 @@ World::World(Scop::Scene& scene) : m_scene(scene), m_narrator(scene.CreateNarrat
material_params.albedo = std::make_shared<Scop::Texture>(Scop::LoadBMPFile(GetResourcesPath() / "prototype.bmp", map_size), map_size.x, map_size.y);
p_block_material = std::make_shared<Scop::Material>(material_params);
auto narrator_update = [](Scop::NonOwningPtr<Scop::Scene> scene, Scop::Inputs& input, float delta)
auto narrator_update = [this](Scop::NonOwningPtr<Scop::Scene> scene, Scop::Inputs& input, float delta)
{
if(m_chunks.empty())
GenerateWorld();
};
m_narrator.AttachScript(std::make_shared<Scop::NativeNarratorScript>(std::function<void()>{}, narrator_update, std::function<void()>{}));
}
[[nodiscard]] Chunk& World::GetChunk(Scop::Vec2i position)
{
}
void World::GenerateWorld()
{
for(std::int32_t x = 0; x < 4; x++)
{
for(std::int32_t z = 0; z < 4; z++)
{
m_chunks.emplace_back(*this, Scop::Vec2i{ x, z });
m_chunks.back().GenerateChunk();
}
}
}

View File

@@ -13,13 +13,18 @@ class World
World(Scop::Scene& scene);
[[nodiscard]] inline Scop::Scene& GetScene() noexcept { return m_scene; }
[[nodiscard]] inline std::shared_ptr<Scop::Material> GetBlockMaterial() const { return p_block_material; }
[[nodiscard]] Chunk& GetChunk(Scop::Vec2i position);
~World() = default;
private:
void GenerateWorld();
private:
static inline constexpr std::size_t CHUNKS_SIZE = 16;
std::vector<std::vector<Chunk>> m_chunks;
std::vector<Chunk> m_chunks;
std::shared_ptr<Scop::Material> p_block_material;
Scop::Narrator& m_narrator;
Scop::Scene& m_scene;

View File

@@ -14,6 +14,7 @@ int main(int ac, char** av)
Scop::SceneDescriptor main_scene_desc;
main_scene_desc.fragment_shader = Scop::RenderCore::Get().GetDefaultFragmentShader();
main_scene_desc.camera = std::make_shared<Scop::FirstPerson3D>(Scop::Vec3f{ -10.0f, 0.0f, 0.0f }, 80.f);
main_scene_desc.culling = Scop::CullMode::None;
Scop::Scene& main_scene = splash_scene->AddChildScene("main", std::move(main_scene_desc));
Scop::Vec2ui32 skybox_size;
@@ -21,14 +22,6 @@ int main(int ac, char** av)
World world(main_scene);
Scop::Actor& object = main_scene.CreateActor(Scop::CreateCube());
Scop::Vec2ui32 map_size;
Scop::MaterialTextures material_params;
material_params.albedo = std::make_shared<Scop::Texture>(Scop::LoadBMPFile(GetResourcesPath() / "prototype.bmp", map_size), map_size.x, map_size.y);
std::shared_ptr<Scop::Material> material = std::make_shared<Scop::Material>(material_params);
object.GetModelRef().SetMaterial(material, 0);
engine.RegisterMainScene(splash_scene.get());
engine.Run();
return 0;

20
ScopEngine/Runtime/Includes/Graphics/Enums.h git.filemode.normal_file
View File

@@ -0,0 +1,20 @@
#ifndef __SCOP_GRAPHICS_ENUMS__
#define __SCOP_GRAPHICS_ENUMS__
#include <cstddef>
namespace Scop
{
enum class CullMode
{
None = 0,
Back,
Front,
FrontAndBack,
EndEnum
};
constexpr std::size_t CullModeCount = static_cast<std::size_t>(CullMode::EndEnum);
}
#endif

View File

@@ -7,6 +7,7 @@
#include <Utils/NonOwningPtr.h>
#include <Graphics/Enums.h>
#include <Graphics/Actor.h>
#include <Graphics/Narrator.h>
#include <Graphics/Sprite.h>
@@ -23,6 +24,7 @@ namespace Scop
{
std::shared_ptr<Shader> fragment_shader;
std::shared_ptr<BaseCamera> camera;
CullMode culling;
bool render_3D_enabled = true;
bool render_2D_enabled = true;
bool render_skybox_enabled = true;

View File

@@ -17,6 +17,7 @@ namespace Scop
Vertex() = default;
Vertex(Vec4f p, Vec4f c, Vec4f n, Vec2f u) : position(std::move(p)), color(std::move(c)), normal(std::move(n)), uv(std::move(u)) {}
Vertex(Vec4f p, Vec4f n, Vec2f u) : position(std::move(p)), normal(std::move(n)), uv(std::move(u)) {}
[[nodiscard]] inline static VkVertexInputBindingDescription GetBindingDescription();
[[nodiscard]] inline static std::array<VkVertexInputAttributeDescription, 4> GetAttributeDescriptions();

View File

@@ -29,6 +29,15 @@ namespace Scop
pipeline_descriptor.mode = VK_POLYGON_MODE_LINE;
pipeline_descriptor.clear_color_attachments = false;
pipeline_descriptor.name = "forward_pass_pipeline";
switch(scene.GetDescription().culling)
{
case CullMode::None: pipeline_descriptor.culling = VK_CULL_MODE_NONE; break;
case CullMode::Back: pipeline_descriptor.culling = VK_CULL_MODE_BACK_BIT; break;
case CullMode::Front: pipeline_descriptor.culling = VK_CULL_MODE_FRONT_BIT; break;
case CullMode::FrontAndBack: pipeline_descriptor.culling = VK_CULL_MODE_FRONT_AND_BACK; break;
default: break;
}
pipeline.Init(pipeline_descriptor);
}