Reworking VertexData
This commit is contained in:
@@ -15,8 +15,6 @@ public:
|
||||
virtual ~MeshAsset();
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
void addMesh(PMesh mesh);
|
||||
const Array<PMesh> getMeshes();
|
||||
//Workaround while no editor
|
||||
Array<PMesh> meshes;
|
||||
Component::Collider physicsMesh;
|
||||
|
||||
@@ -9,6 +9,7 @@ target_sources(Engine
|
||||
Component.h
|
||||
DirectionalLight.h
|
||||
KeyboardInput.h
|
||||
Mesh.h
|
||||
MeshCollider.h
|
||||
PointLight.h
|
||||
RigidBody.h
|
||||
@@ -16,7 +17,6 @@ target_sources(Engine
|
||||
ShapeBase.cpp
|
||||
Skybox.h
|
||||
SphereCollider.h
|
||||
StaticMesh.h
|
||||
Transform.h
|
||||
Transform.cpp)
|
||||
|
||||
@@ -32,10 +32,10 @@ target_sources(Engine
|
||||
DirectionalLight.h
|
||||
KeyboardInput.h
|
||||
MeshCollider.h
|
||||
Mesh.h
|
||||
PointLight.h
|
||||
RigidBody.h
|
||||
ShapeBase.h
|
||||
Skybox.h
|
||||
SphereCollider.h
|
||||
StaticMesh.h
|
||||
Transform.h)
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "Asset/MeshAsset.h"
|
||||
#include "Graphics/VertexData.h"
|
||||
#include "Graphics/TopologyData.h"
|
||||
#include "Material/MaterialInstance.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Component
|
||||
{
|
||||
struct Mesh
|
||||
{
|
||||
VertexData* vertexData;
|
||||
MeshId id;
|
||||
PMaterialInstance instance;
|
||||
};
|
||||
} // namespace Component
|
||||
} // namespace Seele
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
#include "Asset/MeshAsset.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Component
|
||||
{
|
||||
struct StaticMesh
|
||||
{
|
||||
StaticMesh() {}
|
||||
StaticMesh(PMeshAsset mesh) : mesh(mesh) {}
|
||||
PMeshAsset mesh;
|
||||
};
|
||||
} // namespace Component
|
||||
} // namespace Seele
|
||||
@@ -10,8 +10,6 @@ target_sources(Engine
|
||||
Graphics.cpp
|
||||
Mesh.h
|
||||
Mesh.cpp
|
||||
MeshBatch.h
|
||||
MeshBatch.cpp
|
||||
ShaderCompiler.h
|
||||
ShaderCompiler.cpp
|
||||
StaticMeshVertexData.h
|
||||
@@ -28,7 +26,6 @@ target_sources(Engine
|
||||
GraphicsEnums.h
|
||||
Graphics.h
|
||||
Mesh.h
|
||||
MeshBatch.h
|
||||
ShaderCompiler.h
|
||||
StaticMeshVertexData.h
|
||||
VertexData.h)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "MinimalEngine.h"
|
||||
#include "GraphicsResources.h"
|
||||
#include "Containers/Array.h"
|
||||
#include "VertexShaderInput.h"
|
||||
#include "ShaderCompiler.h"
|
||||
|
||||
namespace Seele
|
||||
|
||||
@@ -165,24 +165,10 @@ namespace Gfx
|
||||
{
|
||||
static constexpr bool useAsyncCompute = true;
|
||||
static constexpr bool waitIdleOnSubmit = true;
|
||||
static constexpr bool useMeshShading = true;
|
||||
static constexpr uint32 numFramesBuffered = 8;
|
||||
double getCurrentFrameDelta();
|
||||
|
||||
enum class MaterialShadingModel
|
||||
{
|
||||
Unlit,
|
||||
DefaultLit,
|
||||
Subsurface,
|
||||
PreintegratedSkin,
|
||||
ClearCoat,
|
||||
SubsurfaceProfile,
|
||||
TwoSidedFoliage,
|
||||
Hair,
|
||||
Cloth,
|
||||
Eye,
|
||||
Max
|
||||
};
|
||||
|
||||
enum class RenderPassType : uint8
|
||||
{
|
||||
DepthPrepass,
|
||||
@@ -196,14 +182,6 @@ enum class QueueType
|
||||
TRANSFER = 3,
|
||||
DEDICATED_TRANSFER = 4
|
||||
};
|
||||
enum class VertexAttribute
|
||||
{
|
||||
POSITION,
|
||||
TEXCOORD,
|
||||
NORMAL,
|
||||
TANGENT,
|
||||
BITANGENT
|
||||
};
|
||||
|
||||
typedef uint32_t SeFlags;
|
||||
typedef uint32_t SeBool32;
|
||||
|
||||
@@ -644,8 +644,8 @@ public:
|
||||
virtual void bindVertexBuffer(const Array<VertexInputStream>& streams) = 0;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0;
|
||||
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0;
|
||||
virtual void draw(const MeshBatchElement& data) = 0;
|
||||
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) = 0;
|
||||
virtual void dispatch(uint32 groupX, uint32 groupY, uint32 groupZ);
|
||||
std::string name;
|
||||
};
|
||||
DEFINE_REF(RenderCommand)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include "TopologyData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class IndexBufferTopologyData : public TopologyData
|
||||
{
|
||||
public:
|
||||
IndexBufferTopologyData();
|
||||
virtual ~IndexBufferTopologyData();
|
||||
private:
|
||||
Gfx::PIndexBuffer indices;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -1,20 +1,19 @@
|
||||
#pragma once
|
||||
#include "GraphicsResources.h"
|
||||
#include "Asset/MaterialAsset.h"
|
||||
#include "Asset/MaterialInstanceAsset.h"
|
||||
#include "VertexData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(TopologyData)
|
||||
DECLARE_REF(VertexData)
|
||||
class Mesh
|
||||
{
|
||||
public:
|
||||
Mesh();
|
||||
~Mesh();
|
||||
|
||||
PTopologyData meshlets;
|
||||
PVertexData vertexData;
|
||||
PMaterialAsset referencedMaterial;
|
||||
VertexData* vertexData;
|
||||
MeshId id;
|
||||
PMaterialInstanceAsset referencedMaterial;
|
||||
private:
|
||||
};
|
||||
DEFINE_REF(Mesh)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#include "MeshBatch.h"
|
||||
#include "GraphicsResources.h"
|
||||
#include "VertexShaderInput.h"
|
||||
#include "Material/MaterialInterface.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
MeshBatchElement::MeshBatchElement()
|
||||
: indexBuffer(nullptr)
|
||||
, firstIndex(0)
|
||||
, numPrimitives(0)
|
||||
, numInstances(1)
|
||||
, baseVertexIndex(0)
|
||||
, minVertexIndex(0)
|
||||
, maxVertexIndex(0)
|
||||
, indirectArgsBuffer(nullptr)
|
||||
{}
|
||||
MeshBatch::MeshBatch()
|
||||
: elements()
|
||||
, useReverseCulling(false)
|
||||
, isBackfaceCullingDisabled(false)
|
||||
, isCastingShadow(true)
|
||||
, useWireframe(false)
|
||||
, topology(Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
|
||||
, vertexInput(nullptr)
|
||||
, material(nullptr)
|
||||
{
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
#pragma once
|
||||
#include "GraphicsEnums.h"
|
||||
#include "Containers/Array.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(VertexShaderInput)
|
||||
DECLARE_REF(MaterialInterface)
|
||||
DECLARE_NAME_REF(Gfx, VertexBuffer)
|
||||
DECLARE_NAME_REF(Gfx, IndexBuffer)
|
||||
DECLARE_NAME_REF(Gfx, UniformBuffer)
|
||||
struct MeshBatchElement
|
||||
{
|
||||
public:
|
||||
Gfx::PIndexBuffer indexBuffer;
|
||||
|
||||
uint32 sceneDataIndex;
|
||||
uint32 firstIndex;
|
||||
uint32 numPrimitives;
|
||||
|
||||
uint32 numInstances;
|
||||
uint32 baseVertexIndex;
|
||||
uint32 minVertexIndex;
|
||||
uint32 maxVertexIndex;
|
||||
|
||||
uint8 isInstanced : 1;
|
||||
Gfx::PVertexBuffer indirectArgsBuffer;
|
||||
MeshBatchElement();
|
||||
};
|
||||
struct MeshBatch
|
||||
{
|
||||
Array<MeshBatchElement> elements;
|
||||
|
||||
uint8 useReverseCulling : 1;
|
||||
uint8 isBackfaceCullingDisabled : 1;
|
||||
uint8 isCastingShadow : 1;
|
||||
uint8 useWireframe : 1;
|
||||
|
||||
Gfx::SePrimitiveTopology topology;
|
||||
|
||||
PVertexShaderInput vertexInput;
|
||||
|
||||
PMaterialInterface material;
|
||||
|
||||
MeshBatch();
|
||||
MeshBatch(const MeshBatch& other) = default;
|
||||
MeshBatch(MeshBatch&& other) = default;
|
||||
MeshBatch& operator=(const MeshBatch& other) = default;
|
||||
MeshBatch& operator=(MeshBatch&& other) = default;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -1 +0,0 @@
|
||||
#include "MeshletTopologyData.h"
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
#include "TopologyData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class MeshletTopologyData : public TopologyData
|
||||
{
|
||||
public:
|
||||
private:
|
||||
};
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Window/Window.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Component/Mesh.h"
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
@@ -9,69 +10,8 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
BasePassMeshProcessor::BasePassMeshProcessor(Gfx::PGraphics graphics)
|
||||
: MeshProcessor(graphics)
|
||||
// , translucentBasePass(translucentBasePass)
|
||||
//, cachedPrimitiveIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
BasePassMeshProcessor::~BasePassMeshProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
void BasePassMeshProcessor::processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout baseLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 /*staticMeshId*/)
|
||||
{
|
||||
PMaterialInterface material = batch.material;
|
||||
//const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
|
||||
|
||||
const PVertexShaderInput vertexInput = batch.vertexInput;
|
||||
|
||||
const Gfx::ShaderCollection* collection = material->getShaders(Gfx::RenderPassType::BasePass, vertexInput->getType());
|
||||
if(collection == nullptr)
|
||||
{
|
||||
material->createShaders(graphics, Gfx::RenderPassType::BasePass, vertexInput->getType());
|
||||
collection = material->getShaders(Gfx::RenderPassType::BasePass, vertexInput->getType());
|
||||
}
|
||||
assert(collection != nullptr);
|
||||
|
||||
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand();
|
||||
renderCommand->setViewport(target);
|
||||
|
||||
Gfx::PPipelineLayout pipelineLayout = graphics->createPipelineLayout(baseLayout);
|
||||
pipelineLayout->addDescriptorLayout(BasePass::INDEX_MATERIAL, material->getDescriptorLayout());
|
||||
pipelineLayout->create();
|
||||
Gfx::PDescriptorSet materialSet = material->createDescriptorSet();
|
||||
descriptorSets[BasePass::INDEX_MATERIAL] = materialSet;
|
||||
for(uint32 i = 0; i < batch.elements.size(); ++i)
|
||||
{
|
||||
buildMeshDrawCommand(batch,
|
||||
renderPass,
|
||||
pipelineLayout,
|
||||
renderCommand,
|
||||
descriptorSets,
|
||||
collection->vertexShader,
|
||||
collection->controlShader,
|
||||
collection->evalutionShader,
|
||||
collection->geometryShader,
|
||||
collection->fragmentShader,
|
||||
false);
|
||||
}
|
||||
std::scoped_lock lock(commandLock);
|
||||
renderCommands.add(renderCommand);
|
||||
//co_return;
|
||||
}
|
||||
|
||||
BasePass::BasePass(Gfx::PGraphics graphics)
|
||||
: RenderPass(graphics)
|
||||
, processor(new BasePassMeshProcessor(graphics))
|
||||
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
|
||||
: RenderPass(graphics, scene)
|
||||
, descriptorSets(4)
|
||||
{
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
@@ -80,11 +20,11 @@ BasePass::BasePass(Gfx::PGraphics graphics)
|
||||
lightLayout = graphics->createDescriptorLayout("LightLayout");
|
||||
|
||||
// Directional Lights
|
||||
lightLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
lightLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
// Point Lights
|
||||
lightLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
lightLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
// Point Lights
|
||||
lightLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
lightLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
lightLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
// Light Index List
|
||||
lightLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
// Light Grid
|
||||
@@ -103,25 +43,32 @@ BasePass::BasePass(Gfx::PGraphics graphics)
|
||||
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewLayout);
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
||||
|
||||
primitiveLayout = graphics->createDescriptorLayout("PrimitiveLayout");
|
||||
primitiveLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
primitiveLayout->create();
|
||||
basePassLayout->addDescriptorLayout(INDEX_SCENE_DATA, primitiveLayout);
|
||||
basePassLayout->addPushConstants(Gfx::SePushConstantRange{
|
||||
.stageFlags = (Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT),
|
||||
.offset = 0,
|
||||
.size = sizeof(uint32),
|
||||
});
|
||||
sceneLayout = graphics->createDescriptorLayout("SceneLayout");
|
||||
sceneLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
sceneLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
sceneLayout->create();
|
||||
basePassLayout->addDescriptorLayout(INDEX_SCENE_DATA, sceneLayout);
|
||||
//basePassLayout->addPushConstants(Gfx::SePushConstantRange{
|
||||
// .stageFlags = (Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT),
|
||||
// .offset = 0,
|
||||
// .size = sizeof(uint32),
|
||||
//});
|
||||
}
|
||||
|
||||
BasePass::~BasePass()
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
void BasePass::readScene()
|
||||
{
|
||||
Array<InstanceData> instances;
|
||||
scene->view<Component::Transform, Component::Mesh>([]
|
||||
(const Component::Transform& transform, const Component::Mesh& mesh) {
|
||||
});
|
||||
}
|
||||
|
||||
void BasePass::beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
processor->clearCommands();
|
||||
primitiveLayout->reset();
|
||||
BulkResourceData uniformUpdate;
|
||||
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
@@ -134,7 +81,7 @@ void BasePass::beginFrame(const Component::Camera& cam)
|
||||
viewLayout->reset();
|
||||
lightLayout->reset();
|
||||
|
||||
descriptorSets[INDEX_SCENE_DATA] = primitiveLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_SCENE_DATA] = sceneLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_SCENE_DATA]->updateBuffer(0, passData.sceneDataBuffer);
|
||||
descriptorSets[INDEX_SCENE_DATA]->writeChanges();
|
||||
descriptorSets[INDEX_LIGHT_ENV] = lightLayout->allocateDescriptorSet();
|
||||
|
||||
@@ -1,44 +1,16 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "MeshProcessor.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class BasePassMeshProcessor : public MeshProcessor
|
||||
{
|
||||
public:
|
||||
BasePassMeshProcessor(Gfx::PGraphics graphics);
|
||||
virtual ~BasePassMeshProcessor();
|
||||
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 staticMeshId = -1) override;
|
||||
private:
|
||||
//Array<Gfx::PDescriptorSet> cachedPrimitiveSets;
|
||||
//uint8 translucentBasePass;
|
||||
//uint32 cachedPrimitiveIndex;
|
||||
};
|
||||
DEFINE_REF(BasePassMeshProcessor)
|
||||
DECLARE_REF(CameraActor)
|
||||
struct BasePassData
|
||||
{
|
||||
Array<MeshBatch> staticDrawList;
|
||||
Gfx::PShaderBuffer sceneDataBuffer;
|
||||
LightEnv lightEnv;
|
||||
};
|
||||
class BasePass : public RenderPass<BasePassData>
|
||||
class BasePass : public RenderPass
|
||||
{
|
||||
public:
|
||||
BasePass(Gfx::PGraphics graphics);
|
||||
BasePass(BasePass&& other) = default;
|
||||
BasePass(Gfx::PGraphics graphics, PScene scene);
|
||||
virtual ~BasePass();
|
||||
BasePass& operator=(BasePass&& other) = default;
|
||||
virtual void readScene() override;
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
@@ -48,7 +20,6 @@ public:
|
||||
private:
|
||||
Gfx::PRenderTargetAttachment colorAttachment;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
UPBasePassMeshProcessor processor;
|
||||
|
||||
Array<Gfx::PDescriptorSet> descriptorSets;
|
||||
PCameraActor source;
|
||||
@@ -66,9 +37,7 @@ private:
|
||||
static constexpr uint32 INDEX_MATERIAL = 2;
|
||||
// Set 3: primitive scene data
|
||||
static constexpr uint32 INDEX_SCENE_DATA = 3;
|
||||
Gfx::PDescriptorLayout primitiveLayout;
|
||||
Gfx::PUniformBuffer primitiveUniformBuffer;
|
||||
friend class BasePassMeshProcessor;
|
||||
Gfx::PDescriptorLayout sceneLayout;
|
||||
};
|
||||
DEFINE_REF(BasePass)
|
||||
} // namespace Seele
|
||||
|
||||
@@ -8,8 +8,6 @@ target_sources(Engine
|
||||
DepthPrepass.cpp
|
||||
LightCullingPass.h
|
||||
LightCullingPass.cpp
|
||||
MeshProcessor.h
|
||||
MeshProcessor.cpp
|
||||
RenderGraph.h
|
||||
RenderGraphResources.h
|
||||
RenderGraphResources.cpp
|
||||
@@ -28,7 +26,6 @@ target_sources(Engine
|
||||
DebugPass.h
|
||||
DepthPrepass.h
|
||||
LightCullingPass.h
|
||||
MeshProcessor.h
|
||||
RenderGraph.h
|
||||
RenderGraphResources.h
|
||||
RenderPass.h
|
||||
|
||||
@@ -9,11 +9,7 @@ namespace Seele
|
||||
DECLARE_REF(CameraActor)
|
||||
DECLARE_REF(Scene)
|
||||
DECLARE_REF(Viewport)
|
||||
struct DebugPassData
|
||||
{
|
||||
Array<DebugVertex> vertices;
|
||||
};
|
||||
class DebugPass : public RenderPass<DebugPassData>
|
||||
class DebugPass : public RenderPass
|
||||
{
|
||||
public:
|
||||
DebugPass(Gfx::PGraphics graphics);
|
||||
|
||||
@@ -2,77 +2,16 @@
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Window/Window.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Component/Mesh.h"
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
#include "Material/MaterialInterface.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(Gfx::PGraphics graphics)
|
||||
: MeshProcessor(graphics)
|
||||
{
|
||||
}
|
||||
|
||||
DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
void DepthPrepassMeshProcessor::processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout baseLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 /*staticMeshId*/)
|
||||
{
|
||||
//std::cout << "Depth void started" << std::endl;
|
||||
PMaterialInterface material = batch.material;
|
||||
//const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
|
||||
|
||||
const PVertexShaderInput vertexInput = batch.vertexInput;
|
||||
|
||||
const Gfx::ShaderCollection* collection = material->getShaders(Gfx::RenderPassType::DepthPrepass, vertexInput->getType());
|
||||
if (collection == nullptr)
|
||||
{
|
||||
material->createShaders(graphics, Gfx::RenderPassType::DepthPrepass, vertexInput->getType());
|
||||
collection = material->getShaders(Gfx::RenderPassType::DepthPrepass, vertexInput->getType());
|
||||
}
|
||||
assert(collection != nullptr);
|
||||
|
||||
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand();
|
||||
renderCommand->setViewport(target);
|
||||
Gfx::PPipelineLayout pipelineLayout = graphics->createPipelineLayout(baseLayout);
|
||||
pipelineLayout->addDescriptorLayout(DepthPrepass::INDEX_MATERIAL, material->getDescriptorLayout());
|
||||
pipelineLayout->create();
|
||||
Gfx::PDescriptorSet materialSet = material->createDescriptorSet();
|
||||
descriptorSets[DepthPrepass::INDEX_MATERIAL] = materialSet;
|
||||
for(uint32 i = 0; i < batch.elements.size(); ++i)
|
||||
{
|
||||
buildMeshDrawCommand(batch,
|
||||
// primitiveComponent,
|
||||
renderPass,
|
||||
pipelineLayout,
|
||||
renderCommand,
|
||||
descriptorSets,
|
||||
collection->vertexShader,
|
||||
collection->controlShader,
|
||||
collection->evalutionShader,
|
||||
collection->geometryShader,
|
||||
collection->fragmentShader,
|
||||
true);
|
||||
}
|
||||
std::scoped_lock lock(commandLock);
|
||||
renderCommands.add(renderCommand);
|
||||
//std::cout << "Finished depth job" << std::endl;
|
||||
//co_return;
|
||||
}
|
||||
|
||||
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics)
|
||||
: RenderPass(graphics)
|
||||
, processor(new DepthPrepassMeshProcessor(graphics))
|
||||
, descriptorSets(3)
|
||||
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
|
||||
: RenderPass(graphics, scene)
|
||||
, descriptorSets(4)
|
||||
{
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
|
||||
@@ -86,16 +25,6 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics)
|
||||
viewParamBuffer = graphics->createUniformBuffer(uniformInitializer);
|
||||
viewLayout->create();
|
||||
depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewLayout);
|
||||
|
||||
primitiveLayout = graphics->createDescriptorLayout("PrimitiveLayout");
|
||||
primitiveLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
primitiveLayout->create();
|
||||
depthPrepassLayout->addDescriptorLayout(INDEX_SCENE_DATA, primitiveLayout);
|
||||
depthPrepassLayout->addPushConstants(Gfx::SePushConstantRange{
|
||||
.stageFlags = (Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT),
|
||||
.offset = 0,
|
||||
.size = sizeof(uint32),
|
||||
});
|
||||
}
|
||||
|
||||
DepthPrepass::~DepthPrepass()
|
||||
@@ -104,8 +33,6 @@ DepthPrepass::~DepthPrepass()
|
||||
|
||||
void DepthPrepass::beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
processor->clearCommands();
|
||||
primitiveLayout->reset();
|
||||
BulkResourceData uniformUpdate;
|
||||
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
@@ -116,12 +43,10 @@ void DepthPrepass::beginFrame(const Component::Camera& cam)
|
||||
uniformUpdate.data = (uint8*)&viewParams;
|
||||
viewParamBuffer->updateContents(uniformUpdate);
|
||||
viewLayout->reset();
|
||||
descriptorSets[INDEX_SCENE_DATA] = primitiveLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_SCENE_DATA]->updateBuffer(0, passData.sceneDataBuffer);
|
||||
descriptorSets[INDEX_SCENE_DATA]->writeChanges();
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
|
||||
|
||||
//std::cout << "DepthPrepass beginFrame()" << std::endl;
|
||||
//co_return;
|
||||
}
|
||||
@@ -133,11 +58,39 @@ void DepthPrepass::render()
|
||||
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
|
||||
depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS);
|
||||
graphics->beginRenderPass(renderPass);
|
||||
for (const auto& meshBatch : passData.staticDrawList)
|
||||
for (VertexData* vertexData : VertexData::getList())
|
||||
{
|
||||
processor->processMeshBatch(meshBatch, viewport, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets);
|
||||
const auto& materials = vertexData->getMaterialData();
|
||||
for (const auto& [_, materialData] : materials)
|
||||
{
|
||||
// Create Pipeline(Material, VertexData)
|
||||
// Descriptors:
|
||||
// ViewData => global, static
|
||||
// Material => per material
|
||||
// VertexData => per meshtype
|
||||
// SceneData => per topology
|
||||
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
|
||||
Gfx::PPipelineLayout layout = graphics->createPipelineLayout(depthPrepassLayout);
|
||||
layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
|
||||
layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(INDEX_SCENE_DATA, vertexData->getInstanceDataLayout());
|
||||
layout->create();
|
||||
|
||||
GraphicsPipelineCreateInfo pipelineInfo;
|
||||
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInfo);
|
||||
command->bindPipeline(pipeline);
|
||||
|
||||
vertexData->bindBuffers(command);
|
||||
descriptorSets[INDEX_VERTEX_DATA] = vertexData->getVertexDataSet();
|
||||
for (const auto&[_, instance]: materialData.instances)
|
||||
{
|
||||
descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet();
|
||||
descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet;
|
||||
command->bindDescriptor(descriptorSets);
|
||||
command->dispatch(instance.numMeshes, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
graphics->executeCommands(processor->getRenderCommands());
|
||||
graphics->endRenderPass();
|
||||
//std::cout << "DepthPrepass render()" << std::endl;
|
||||
//co_return;
|
||||
@@ -175,5 +128,6 @@ void DepthPrepass::modifyRenderPassMacros(Map<const char*, const char*>& defines
|
||||
{
|
||||
defines["INDEX_VIEW_PARAMS"] = "0";
|
||||
defines["INDEX_MATERIAL"] = "1";
|
||||
defines["INDEX_SCENE_DATA"] = "2";
|
||||
defines["INDEX_VERTEX_DATA"] = "2";
|
||||
defines["INDEX_SCENE_DATA"] = "3";
|
||||
}
|
||||
|
||||
@@ -1,40 +1,14 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "MeshProcessor.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class DepthPrepassMeshProcessor : public MeshProcessor
|
||||
class DepthPrepass : public RenderPass
|
||||
{
|
||||
public:
|
||||
DepthPrepassMeshProcessor(Gfx::PGraphics graphics);
|
||||
virtual ~DepthPrepassMeshProcessor();
|
||||
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 staticMeshId = -1) override;
|
||||
|
||||
private:
|
||||
};
|
||||
DEFINE_REF(DepthPrepassMeshProcessor)
|
||||
struct DepthPrepassData
|
||||
{
|
||||
Array<MeshBatch> staticDrawList;
|
||||
Gfx::PShaderBuffer sceneDataBuffer;
|
||||
};
|
||||
class DepthPrepass : public RenderPass<DepthPrepassData>
|
||||
{
|
||||
public:
|
||||
DepthPrepass(Gfx::PGraphics graphics);
|
||||
DepthPrepass(DepthPrepass&& other) = default;
|
||||
DepthPrepass(Gfx::PGraphics graphics, PScene scene);
|
||||
~DepthPrepass();
|
||||
DepthPrepass& operator=(DepthPrepass& other) = default;
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
@@ -44,9 +18,9 @@ public:
|
||||
private:
|
||||
Gfx::PRenderTargetAttachment depthAttachment;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
UPDepthPrepassMeshProcessor processor;
|
||||
|
||||
|
||||
Array<Gfx::PDescriptorSet> descriptorSets;
|
||||
|
||||
Gfx::PPipelineLayout depthPrepassLayout;
|
||||
// Set 0: viewParameter
|
||||
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
|
||||
@@ -54,11 +28,11 @@ private:
|
||||
Gfx::PUniformBuffer viewParamBuffer;
|
||||
// Set 1: materials, generated
|
||||
static constexpr uint32 INDEX_MATERIAL = 1;
|
||||
// Set 2: primitive scene data
|
||||
static constexpr uint32 INDEX_SCENE_DATA = 2;
|
||||
Gfx::PDescriptorLayout primitiveLayout;
|
||||
Gfx::PUniformBuffer primitiveUniformBuffer;
|
||||
friend class DepthPrepassMeshProcessor;
|
||||
// Set 2: vertices, from VertexData
|
||||
static constexpr uint32 INDEX_VERTEX_DATA = 2;
|
||||
// Set 3: mesh data, either index buffer or meshlet data
|
||||
static constexpr uint32 INDEX_SCENE_DATA = 3;
|
||||
Gfx::PDescriptorLayout sceneDataLayout;
|
||||
};
|
||||
DEFINE_REF(DepthPrepass)
|
||||
} // namespace Seele
|
||||
|
||||
@@ -12,7 +12,7 @@ struct LightCullingPassData
|
||||
{
|
||||
LightEnv lightEnv;
|
||||
};
|
||||
class LightCullingPass : public RenderPass<LightCullingPassData>
|
||||
class LightCullingPass : public RenderPass
|
||||
{
|
||||
public:
|
||||
LightCullingPass(Gfx::PGraphics graphics);
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
#include "MeshProcessor.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/VertexShaderInput.h"
|
||||
#include "Graphics/Vulkan/VulkanGraphicsResources.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
MeshProcessor::MeshProcessor(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MeshProcessor::~MeshProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
void MeshProcessor::buildMeshDrawCommand(
|
||||
const MeshBatch& meshBatch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PRenderCommand drawCommand,
|
||||
const Array<Gfx::PDescriptorSet>& descriptors,
|
||||
Gfx::PVertexShader vertexShader,
|
||||
Gfx::PControlShader controlShader,
|
||||
Gfx::PEvaluationShader evaluationShader,
|
||||
Gfx::PGeometryShader geometryShader,
|
||||
Gfx::PFragmentShader fragmentShader,
|
||||
bool positionOnly)
|
||||
{
|
||||
const PVertexShaderInput vertexInput = meshBatch.vertexInput;
|
||||
|
||||
GraphicsPipelineCreateInfo pipelineInitializer;
|
||||
pipelineInitializer.topology = meshBatch.topology;
|
||||
pipelineInitializer.vertexShader = vertexShader;
|
||||
pipelineInitializer.controlShader = controlShader;
|
||||
pipelineInitializer.evalShader = evaluationShader;
|
||||
pipelineInitializer.geometryShader = geometryShader;
|
||||
pipelineInitializer.fragmentShader = fragmentShader;
|
||||
pipelineInitializer.renderPass = renderPass;
|
||||
pipelineInitializer.pipelineLayout = pipelineLayout;
|
||||
|
||||
VertexInputStreamArray vertexStreams;
|
||||
if(positionOnly)
|
||||
{
|
||||
vertexInput->getPositionOnlyStream(vertexStreams);
|
||||
pipelineInitializer.vertexDeclaration = vertexInput->getPositionDeclaration();
|
||||
}
|
||||
else
|
||||
{
|
||||
vertexInput->getStreams(vertexStreams);
|
||||
pipelineInitializer.vertexDeclaration = vertexInput->getDeclaration();
|
||||
}
|
||||
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInitializer);
|
||||
drawCommand->bindPipeline(pipeline);
|
||||
drawCommand->bindVertexBuffer(vertexStreams);
|
||||
drawCommand->bindDescriptor(descriptors);
|
||||
for(const auto& element : meshBatch.elements)
|
||||
{
|
||||
drawCommand->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(uint32), &element.sceneDataIndex);
|
||||
if(element.indexBuffer != nullptr)
|
||||
{
|
||||
drawCommand->bindIndexBuffer(element.indexBuffer);
|
||||
drawCommand->draw(element);
|
||||
}
|
||||
else
|
||||
{
|
||||
drawCommand->draw(vertexStreams[0].vertexBuffer->getNumVertices(), 1, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Array<Gfx::PRenderCommand> MeshProcessor::getRenderCommands()
|
||||
{
|
||||
return renderCommands;
|
||||
}
|
||||
|
||||
void MeshProcessor::clearCommands()
|
||||
{
|
||||
renderCommands.clear();
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "Graphics/MeshBatch.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class MeshProcessor
|
||||
{
|
||||
public:
|
||||
MeshProcessor(Gfx::PGraphics graphics);
|
||||
virtual ~MeshProcessor();
|
||||
Array<Gfx::PRenderCommand> getRenderCommands();
|
||||
void clearCommands();
|
||||
protected:
|
||||
PScene scene;
|
||||
Gfx::PGraphics graphics;
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 staticMeshId = -1) = 0;
|
||||
void buildMeshDrawCommand(
|
||||
const MeshBatch& meshBatch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PRenderCommand drawCommand,
|
||||
const Array<Gfx::PDescriptorSet>& descriptors,
|
||||
Gfx::PVertexShader vertexShader,
|
||||
Gfx::PControlShader controlShader,
|
||||
Gfx::PEvaluationShader evaluationShader,
|
||||
Gfx::PGeometryShader geometryShader,
|
||||
Gfx::PFragmentShader fragmentShader,
|
||||
bool positionOnly);
|
||||
std::mutex commandLock;
|
||||
Array<Gfx::PRenderCommand> renderCommands;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -3,24 +3,25 @@
|
||||
#include "Math/Math.h"
|
||||
#include "RenderGraphResources.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Graphics/TopologyData.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Material/MaterialInstance.h"
|
||||
#include "Graphics/VertexData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_NAME_REF(Gfx, Viewport)
|
||||
DECLARE_NAME_REF(Gfx, Graphics)
|
||||
DECLARE_NAME_REF(Gfx, RenderPass)
|
||||
template<typename RenderPassDataType>
|
||||
class RenderPass
|
||||
{
|
||||
public:
|
||||
RenderPass(Gfx::PGraphics graphics)
|
||||
RenderPass(Gfx::PGraphics graphics, PScene scene)
|
||||
: graphics(graphics)
|
||||
, scene(scene)
|
||||
{}
|
||||
virtual ~RenderPass()
|
||||
{}
|
||||
void updateViewFrame(RenderPassDataType viewFrame) {
|
||||
passData = std::move(viewFrame);
|
||||
}
|
||||
virtual void beginFrame(const Component::Camera& cam) = 0;
|
||||
virtual void render() = 0;
|
||||
virtual void endFrame() = 0;
|
||||
@@ -41,13 +42,26 @@ protected:
|
||||
Vector2 screenDimensions;
|
||||
Vector2 pad0;
|
||||
} viewParams;
|
||||
struct DrawListId
|
||||
{
|
||||
DrawListId(PMaterialInstance mat, PVertexData vertex)
|
||||
{
|
||||
id = mat->getBaseMaterial()->getName();
|
||||
}
|
||||
std::strong_ordering operator<=>(const DrawListId& other) const
|
||||
{
|
||||
return id <=> other.id;
|
||||
}
|
||||
std::string id;
|
||||
};
|
||||
Map<DrawListId, DrawListInfo> drawList;
|
||||
PRenderGraphResources resources;
|
||||
RenderPassDataType passData;
|
||||
Gfx::PRenderPass renderPass;
|
||||
Gfx::PGraphics graphics;
|
||||
Gfx::PViewport viewport;
|
||||
PScene scene;
|
||||
};
|
||||
template<typename RP, typename T>
|
||||
concept RenderPassType = std::derived_from<RP, RenderPass<T>>;
|
||||
template<typename RP>
|
||||
concept RenderPassType = std::derived_from<RP, RenderPass>;
|
||||
|
||||
} // namespace Seele
|
||||
|
||||
@@ -8,11 +8,7 @@ namespace Seele
|
||||
DECLARE_REF(CameraActor)
|
||||
DECLARE_REF(Scene)
|
||||
DECLARE_REF(Viewport)
|
||||
struct SkyboxPassData
|
||||
{
|
||||
Component::Skybox skybox;
|
||||
};
|
||||
class SkyboxRenderPass : public RenderPass<SkyboxPassData>
|
||||
class SkyboxRenderPass : public RenderPass
|
||||
{
|
||||
public:
|
||||
SkyboxRenderPass(Gfx::PGraphics graphics);
|
||||
|
||||
@@ -17,12 +17,7 @@ struct TextRender
|
||||
Vector2 position;
|
||||
float scale;
|
||||
};
|
||||
struct TextPassData
|
||||
{
|
||||
Array<TextRender> texts;
|
||||
};
|
||||
|
||||
class TextPass : public RenderPass<TextPassData>
|
||||
class TextPass : public RenderPass
|
||||
{
|
||||
public:
|
||||
TextPass(Gfx::PGraphics graphics);
|
||||
|
||||
@@ -8,7 +8,5 @@ public:
|
||||
StaticMeshVertexData();
|
||||
virtual ~StaticMeshVertexData();
|
||||
private:
|
||||
Gfx::PShaderBuffer texCoords;
|
||||
Gfx::PShaderBuffer normals;
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "GraphicsResources.h"
|
||||
#include "VertexData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -9,6 +10,8 @@ public:
|
||||
TopologyData();
|
||||
virtual ~TopologyData();
|
||||
virtual void bind() = 0;
|
||||
private:
|
||||
protected:
|
||||
VertexData* vertexData;
|
||||
};
|
||||
DEFINE_REF(TopologyData)
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,95 @@
|
||||
#include "VertexData.h"
|
||||
#include "Material/Material.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
void VertexData::resetMeshData()
|
||||
{
|
||||
materialData.clear();
|
||||
}
|
||||
|
||||
void VertexData::updateMesh(const Component::Transform& transform, const Component::Mesh& mesh)
|
||||
{
|
||||
PMaterial mat = mesh.instance->getBaseMaterial();
|
||||
MaterialData& matData = materialData[mat->getName()];
|
||||
MaterialInstanceData& matInstanceData = matData.instances[mesh.instance->getId()];
|
||||
matInstanceData.meshes.add(MeshInstanceData{
|
||||
.id = mesh.id,
|
||||
.instance = InstanceData {
|
||||
.transformMatrix = transform.toMatrix(),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void VertexData::createDescriptors()
|
||||
{
|
||||
for (const auto& [_, mat] : materialData)
|
||||
{
|
||||
for (auto& [_, matInst] : mat.instances)
|
||||
{
|
||||
Array<InstanceData> instanceData;
|
||||
Array<MeshData> meshes;
|
||||
for (const auto& inst : matInst.meshes)
|
||||
{
|
||||
for (const auto& mesh : meshData[inst.id])
|
||||
{
|
||||
instanceData.add(inst.instance);
|
||||
meshes.add(mesh);
|
||||
}
|
||||
}
|
||||
Gfx::PShaderBuffer instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.resourceData = {
|
||||
.size = sizeof(InstanceData) * instanceData.size(),
|
||||
.data = (uint8*)instanceData.data(),
|
||||
},
|
||||
.stride = sizeof(InstanceData)
|
||||
});
|
||||
Gfx::PShaderBuffer meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.resourceData = {
|
||||
.size = sizeof(MeshData) * meshes.size(),
|
||||
.data = (uint8*)meshes.data(),
|
||||
},
|
||||
.stride = sizeof(MeshData)
|
||||
});
|
||||
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
||||
matInst.descriptorSet->updateBuffer(0, instanceBuffer);
|
||||
if (Gfx::useMeshShading)
|
||||
{
|
||||
matInst.descriptorSet->updateBuffer(1, meshDataBuffer);
|
||||
matInst.descriptorSet->updateBuffer(2, meshletBuffer);
|
||||
}
|
||||
matInst.descriptorSet->writeChanges();
|
||||
matInst.numMeshes = meshes.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<VertexData*> vertexDataList;
|
||||
|
||||
List<VertexData*> VertexData::getList()
|
||||
{
|
||||
return vertexDataList;
|
||||
}
|
||||
|
||||
VertexData::VertexData(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
{
|
||||
instanceDataLayout = graphics->createDescriptorLayout("VertexDataInstanceLayout");
|
||||
instanceDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
if (Gfx::useMeshShading)
|
||||
{
|
||||
// meshData
|
||||
instanceDataLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
// meshletData
|
||||
instanceDataLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.resourceData = {
|
||||
.size = sizeof(MeshletData),
|
||||
.data = nullptr,
|
||||
},
|
||||
.bDynamic = true,
|
||||
});
|
||||
}
|
||||
instanceDataLayout->create();
|
||||
}
|
||||
@@ -1,13 +1,80 @@
|
||||
#pragma once
|
||||
#include "GraphicsResources.h"
|
||||
#include "Material/MaterialInstance.h"
|
||||
#include "Component/Mesh.h"
|
||||
#include "Component/Transform.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
struct MeshId
|
||||
{
|
||||
uint64 id;
|
||||
};
|
||||
class VertexData
|
||||
{
|
||||
public:
|
||||
private:
|
||||
Gfx::PShaderBuffer positions;
|
||||
struct InstanceData
|
||||
{
|
||||
Matrix4 transformMatrix;
|
||||
};
|
||||
struct MeshInstanceData
|
||||
{
|
||||
MeshId id;
|
||||
InstanceData instance;
|
||||
};
|
||||
struct MaterialInstanceData
|
||||
{
|
||||
PMaterialInstance materialInstance;
|
||||
Gfx::PDescriptorSet descriptorSet;
|
||||
uint32_t numMeshes; // not necessarily equal to meshes.size() if a MeshId has multiple meshes
|
||||
Array<MeshInstanceData> meshes;
|
||||
};
|
||||
struct MaterialData
|
||||
{
|
||||
PMaterial material;
|
||||
Map<uint64, MaterialInstanceData> instances;
|
||||
};
|
||||
struct MeshData
|
||||
{
|
||||
uint32 numMeshlets;
|
||||
uint32 meshletOffset;
|
||||
};
|
||||
void resetMeshData();
|
||||
void updateMesh(const Component::Transform& transform, const Component::Mesh& mesh);
|
||||
void createDescriptors();
|
||||
virtual void bindBuffers(Gfx::PRenderCommand command) = 0;
|
||||
virtual Gfx::PDescriptorLayout getVertexDataLayout() = 0;
|
||||
virtual Gfx::PDescriptorSet getVertexDataSet() = 0;
|
||||
virtual Gfx::PDescriptorLayout getInstanceDataLayout() = 0;
|
||||
virtual std::string getTypeName() const = 0;
|
||||
const Map<std::string, MaterialData>& getMaterialData() const { return materialData; }
|
||||
const Array<MeshData>& getMeshData(MeshId id) { return meshData[id]; }
|
||||
static List<VertexData*> getList();
|
||||
protected:
|
||||
struct MeshletAABB
|
||||
{
|
||||
Vector min;
|
||||
float pad0;
|
||||
Vector max;
|
||||
float pad1;
|
||||
};
|
||||
struct MeshletData
|
||||
{
|
||||
MeshletAABB boundingBox;
|
||||
uint32_t vertexCount;
|
||||
uint32_t primiticeCount;
|
||||
uint32_t vertexOffset;
|
||||
uint32_t primitiveOffset;
|
||||
};
|
||||
Map<std::string, MaterialData> materialData;
|
||||
Map<MeshId, Array<MeshData>> meshData;
|
||||
Array<MeshletData> meshlets;
|
||||
Gfx::PDescriptorLayout instanceDataLayout;
|
||||
Gfx::PGraphics graphics;
|
||||
// for mesh shading
|
||||
Gfx::PShaderBuffer meshletBuffer;
|
||||
// for legacy pipeline
|
||||
Gfx::PIndexBuffer indexBuffer;
|
||||
VertexData(Gfx::PGraphics graphics);
|
||||
};
|
||||
DEFINE_REF(VertexData)
|
||||
}
|
||||
@@ -304,18 +304,18 @@ void RenderCommand::pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStag
|
||||
vkCmdPushConstants(handle, layout.cast<PipelineLayout>()->getHandle(), stage, offset, size, data);
|
||||
}
|
||||
|
||||
void RenderCommand::draw(const MeshBatchElement& data)
|
||||
{
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
vkCmdDrawIndexed(handle, static_cast<uint32>(data.indexBuffer->getNumIndices()), data.numInstances, data.minVertexIndex, data.baseVertexIndex, 0);
|
||||
}
|
||||
|
||||
void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance)
|
||||
{
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
vkCmdDraw(handle, vertexCount, instanceCount, firstVertex, firstInstance);
|
||||
}
|
||||
|
||||
void RenderCommand::dispatch(uint32 groupX, uint32 groupY, uint32 groupZ)
|
||||
{
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
vkCmdDrawMeshTasksEXT(handle, groupX, groupY, groupZ);
|
||||
}
|
||||
|
||||
ComputeCommand::ComputeCommand(PGraphics graphics, VkCommandPool cmdPool)
|
||||
: graphics(graphics)
|
||||
, owner(cmdPool)
|
||||
|
||||
@@ -90,8 +90,8 @@ public:
|
||||
virtual void bindVertexBuffer(const Array<VertexInputStream>& streams) override;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
|
||||
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
|
||||
virtual void draw(const MeshBatchElement& data) override;
|
||||
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override;
|
||||
virtual void dispatch(uint32 groupX, uint32 groupY, uint32 groupZ) override;
|
||||
private:
|
||||
PGraphicsPipeline pipeline;
|
||||
bool ready;
|
||||
|
||||
@@ -4,8 +4,8 @@ target_sources(Engine
|
||||
Material.cpp
|
||||
MaterialInstance.h
|
||||
MaterialInstance.cpp
|
||||
MaterialInterface.h
|
||||
MaterialInterface.cpp
|
||||
|
||||
|
||||
ShaderExpression.h
|
||||
ShaderExpression.cpp)
|
||||
|
||||
@@ -14,6 +14,5 @@ target_sources(Engine
|
||||
FILES
|
||||
Material.h
|
||||
MaterialInstance.h
|
||||
MaterialInterface.h
|
||||
ShaderExpression.h)
|
||||
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
#include "Material.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "MaterialInstance.h"
|
||||
#include "Graphics/VertexShaderInput.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Gfx::ShaderMap Material::shaderMap;
|
||||
std::mutex Material::shaderMapLock;
|
||||
|
||||
Material::Material(Gfx::PGraphics graphics,
|
||||
Array<PShaderParameter> parameter,
|
||||
@@ -17,11 +14,15 @@ Material::Material(Gfx::PGraphics graphics,
|
||||
std::string materialName,
|
||||
Array<PShaderExpression> expressions,
|
||||
MaterialNode brdf)
|
||||
: MaterialInterface(graphics, parameter, uniformDataSize, uniformBinding)
|
||||
: graphics(graphics)
|
||||
, parameters(parameter)
|
||||
, uniformDataSize(uniformDataSize)
|
||||
, uniformBinding(uniformBinding)
|
||||
, layout(layout)
|
||||
, materialName(materialName)
|
||||
, codeExpressions(expressions)
|
||||
, brdf(brdf)
|
||||
, instanceId(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -129,19 +130,3 @@ void Material::compile()
|
||||
codeStream << "\t}\n";
|
||||
codeStream << "};\n";
|
||||
}
|
||||
|
||||
const Gfx::ShaderCollection* Material::getShaders(Gfx::RenderPassType renderPass, VertexInputType* vertexInput) const
|
||||
{
|
||||
Gfx::ShaderPermutation permutation;
|
||||
permutation.passType = renderPass;
|
||||
std::string vertexInputName = vertexInput->getName();
|
||||
std::strncpy(permutation.materialName, materialName.c_str(), sizeof(permutation.materialName));
|
||||
std::strncpy(permutation.vertexInputName, vertexInputName.c_str(), sizeof(permutation.vertexInputName));
|
||||
return shaderMap.findShaders(Gfx::PermutationId(permutation));
|
||||
}
|
||||
|
||||
Gfx::ShaderCollection& Material::createShaders(Gfx::PGraphics graphics, Gfx::RenderPassType renderPass, VertexInputType* vertexInput)
|
||||
{
|
||||
std::scoped_lock l(shaderMapLock);
|
||||
return shaderMap.createShaders(graphics, renderPass, this, vertexInput, false);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
#include "MaterialInterface.h"
|
||||
#include "ShaderExpression.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(MaterialInstance)
|
||||
class Material : public MaterialInterface
|
||||
class Material
|
||||
{
|
||||
public:
|
||||
Material() {}
|
||||
Material(Gfx::PGraphics graphics,
|
||||
Array<PShaderParameter> parameter,
|
||||
Gfx::PDescriptorLayout layout,
|
||||
@@ -16,30 +16,27 @@ public:
|
||||
std::string materialName,
|
||||
Array<PShaderExpression> expressions,
|
||||
MaterialNode brdf);
|
||||
virtual ~Material();
|
||||
virtual Gfx::PDescriptorSet createDescriptorSet();
|
||||
virtual Gfx::PDescriptorLayout getDescriptorLayout() const { return layout; }
|
||||
virtual const std::string& getName() { return materialName; }
|
||||
~Material();
|
||||
Gfx::PDescriptorLayout getDescriptorLayout() const { return layout; }
|
||||
PMaterialInstance instantiate();
|
||||
const std::string& getName() { return materialName; }
|
||||
|
||||
virtual void save(ArchiveBuffer& buffer) const;
|
||||
virtual void load(ArchiveBuffer& buffer);
|
||||
void save(ArchiveBuffer& buffer) const;
|
||||
void load(ArchiveBuffer& buffer);
|
||||
|
||||
void compile();
|
||||
|
||||
virtual const Gfx::ShaderCollection* getShaders(Gfx::RenderPassType renderPass, VertexInputType* vertexInput) const;
|
||||
virtual Gfx::ShaderCollection& createShaders(Gfx::PGraphics graphics, Gfx::RenderPassType renderPass, VertexInputType* vertexInput);
|
||||
private:
|
||||
static Gfx::ShaderMap shaderMap;
|
||||
static std::mutex shaderMapLock;
|
||||
|
||||
Gfx::PGraphics graphics;
|
||||
std::string brdfName;
|
||||
uint32 uniformDataSize;
|
||||
uint32 uniformBinding;
|
||||
uint64 instanceId;
|
||||
Gfx::PDescriptorLayout layout;
|
||||
std::string materialName;
|
||||
Array<PShaderExpression> codeExpressions;
|
||||
Array<PShaderParameter> parameters;
|
||||
MaterialNode brdf;
|
||||
// With draw-indirect, we batch vertex data into big vertex buffers
|
||||
// Gfx::PVertexDataManager vertexData;
|
||||
|
||||
friend class MaterialInstance;
|
||||
};
|
||||
DEFINE_REF(Material)
|
||||
|
||||
|
||||
@@ -4,52 +4,20 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
MaterialInstance::MaterialInstance(Gfx::PGraphics graphics, PMaterial baseMaterial)
|
||||
: MaterialInterface(graphics, baseMaterial->parameters, baseMaterial->uniformDataSize, baseMaterial->uniformBinding)
|
||||
, baseMaterial(baseMaterial)
|
||||
MaterialInstance::MaterialInstance(uint64 id, Gfx::PGraphics graphics, PMaterial baseMaterial, Gfx::PDescriptorSet descriptor, Array<PShaderParameter> params, uint32 uniformBinding, uint32 uniformSize)
|
||||
: id(id), graphics(graphics), baseMaterial(baseMaterial), descriptor(descriptor), parameters(params), uniformBinding(uniformBinding)
|
||||
{
|
||||
uniformBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
|
||||
.resourceData = {
|
||||
.size = uniformSize,
|
||||
},
|
||||
.bDynamic = true,
|
||||
}
|
||||
);
|
||||
uniformData.resize(uniformSize);
|
||||
}
|
||||
|
||||
MaterialInstance::~MaterialInstance()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Gfx::PDescriptorSet MaterialInstance::createDescriptorSet()
|
||||
{
|
||||
Gfx::PDescriptorSet descriptorSet = baseMaterial->layout->allocateDescriptorSet();
|
||||
BulkResourceData uniformUpdate;
|
||||
uniformUpdate.size = uniformDataSize;
|
||||
uniformUpdate.data = (uint8*)uniformData.data();
|
||||
for(auto param : parameters)
|
||||
{
|
||||
param->updateDescriptorSet(descriptorSet, uniformData.data());
|
||||
}
|
||||
if(uniformUpdate.size != 0)
|
||||
{
|
||||
uniformBuffer->updateContents(uniformUpdate);
|
||||
descriptorSet->updateBuffer(uniformBinding, uniformBuffer);
|
||||
}
|
||||
descriptorSet->writeChanges();
|
||||
return descriptorSet;
|
||||
}
|
||||
|
||||
Gfx::PDescriptorLayout MaterialInstance::getDescriptorLayout() const
|
||||
{
|
||||
return baseMaterial->getDescriptorLayout();
|
||||
}
|
||||
|
||||
const std::string& MaterialInstance::getName()
|
||||
{
|
||||
return baseMaterial->getName();
|
||||
}
|
||||
|
||||
const Gfx::ShaderCollection* Seele::MaterialInstance::getShaders(Gfx::RenderPassType renderPass, VertexInputType* vertexInput) const
|
||||
{
|
||||
return baseMaterial->getShaders(renderPass, vertexInput);
|
||||
}
|
||||
|
||||
Gfx::ShaderCollection& Seele::MaterialInstance::createShaders(Gfx::PGraphics graphics, Gfx::RenderPassType renderPass, VertexInputType* vertexInput)
|
||||
{
|
||||
return baseMaterial->createShaders(graphics, renderPass, vertexInput);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,26 @@
|
||||
#pragma once
|
||||
#include "MaterialInterface.h"
|
||||
#include "Material.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(Material)
|
||||
class MaterialInstance : public MaterialInterface
|
||||
class MaterialInstance
|
||||
{
|
||||
public:
|
||||
MaterialInstance(Gfx::PGraphics graphics, PMaterial baseMaterial);
|
||||
virtual ~MaterialInstance();
|
||||
virtual Gfx::PDescriptorSet createDescriptorSet();
|
||||
virtual Gfx::PDescriptorLayout getDescriptorLayout() const;
|
||||
|
||||
// The name of the generated material shader, opposed to the name of the .asset file
|
||||
virtual const std::string& getName();
|
||||
virtual const Gfx::ShaderCollection* getShaders(Gfx::RenderPassType renderPass, VertexInputType* vertexInput) const;
|
||||
virtual Gfx::ShaderCollection& createShaders(Gfx::PGraphics graphics, Gfx::RenderPassType renderPass, VertexInputType* vertexInput);
|
||||
|
||||
MaterialInstance(uint64 id, Gfx::PGraphics graphics, PMaterial baseMaterial, Gfx::PDescriptorSet descriptor, Array<PShaderParameter> params, uint32 uniformBinding, uint32 uniformSize);
|
||||
~MaterialInstance();
|
||||
void updateDescriptor();
|
||||
Gfx::PDescriptorSet getDescriptorSet() const;
|
||||
PMaterial getBaseMaterial() const { return baseMaterial; }
|
||||
uint64 getId() const { return id; }
|
||||
private:
|
||||
Gfx::PGraphics graphics;
|
||||
Array<uint8> uniformData;
|
||||
uint32 uniformBinding;
|
||||
Gfx::PUniformBuffer uniformBuffer;
|
||||
Array<PShaderParameter> parameters;
|
||||
Gfx::PDescriptorSet descriptor;
|
||||
PMaterial baseMaterial;
|
||||
uint64 id;
|
||||
};
|
||||
DEFINE_REF(MaterialInstance)
|
||||
} // namespace Seele
|
||||
@@ -1,79 +0,0 @@
|
||||
#include "MaterialInterface.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
MaterialInterface::MaterialInterface(Gfx::PGraphics graphics, Array<PShaderParameter> parameter, uint32 uniformDataSize, uint32 uniformBinding)
|
||||
: graphics(graphics)
|
||||
, parameters(parameter)
|
||||
, uniformDataSize(uniformDataSize)
|
||||
, uniformBinding(uniformBinding)
|
||||
{
|
||||
if(uniformDataSize != 0)
|
||||
{
|
||||
uniformData.resize(uniformDataSize);
|
||||
UniformBufferCreateInfo uniformInitializer = {
|
||||
.resourceData = {
|
||||
.size = uniformDataSize,
|
||||
.data = nullptr,
|
||||
}
|
||||
};
|
||||
uniformBuffer = graphics->createUniformBuffer(uniformInitializer);
|
||||
}
|
||||
}
|
||||
|
||||
MaterialInterface::~MaterialInterface()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PShaderParameter MaterialInterface::getParameter(const std::string& name)
|
||||
{
|
||||
for (const auto& param : parameters)
|
||||
{
|
||||
if(param->name.compare(name) == 0)
|
||||
{
|
||||
return param;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MaterialInterface::save(ArchiveBuffer& buffer) const
|
||||
{
|
||||
Serialization::save(buffer, uniformDataSize);
|
||||
Serialization::save(buffer, uniformBinding);
|
||||
uint64 length = parameters.size();
|
||||
Serialization::save(buffer, length);
|
||||
for (const auto& param : parameters)
|
||||
{
|
||||
Serialization::save(buffer, param);
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialInterface::load(ArchiveBuffer& buffer)
|
||||
{
|
||||
graphics = buffer.getGraphics();
|
||||
Serialization::load(buffer, uniformDataSize);
|
||||
Serialization::load(buffer, uniformBinding);
|
||||
|
||||
if (uniformDataSize != 0)
|
||||
{
|
||||
uniformData.resize(uniformDataSize);
|
||||
UniformBufferCreateInfo uniformInitializer = {
|
||||
.resourceData = {
|
||||
.size = uniformDataSize,
|
||||
.data = nullptr,
|
||||
}
|
||||
};
|
||||
uniformBuffer = graphics->createUniformBuffer(uniformInitializer);
|
||||
}
|
||||
uint64 length;
|
||||
Serialization::load(buffer, length);
|
||||
parameters.resize(length);
|
||||
for (auto& param : parameters)
|
||||
{
|
||||
Serialization::load(buffer, param);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
#include "ShaderExpression.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_NAME_REF(Gfx, DescriptorLayout)
|
||||
DECLARE_NAME_REF(Gfx, UniformBuffer)
|
||||
class MaterialInterface
|
||||
{
|
||||
public:
|
||||
MaterialInterface() {}
|
||||
MaterialInterface(Gfx::PGraphics graphics, Array<PShaderParameter> parameter, uint32 uniformDataSize, uint32 uniformBinding);
|
||||
virtual ~MaterialInterface();
|
||||
PShaderParameter getParameter(const std::string& name);
|
||||
virtual Gfx::PDescriptorSet createDescriptorSet() = 0;
|
||||
virtual Gfx::PDescriptorLayout getDescriptorLayout() const = 0;
|
||||
|
||||
virtual void save(ArchiveBuffer& buffer) const;
|
||||
virtual void load(ArchiveBuffer& buffer);
|
||||
|
||||
// The name of the generated material shader, opposed to the name of the .asset file
|
||||
virtual const std::string& getName() = 0;
|
||||
virtual const Gfx::ShaderCollection* getShaders(Gfx::RenderPassType renderPass, VertexInputType* vertexInput) const = 0;
|
||||
virtual Gfx::ShaderCollection& createShaders(Gfx::PGraphics graphics, Gfx::RenderPassType renderPass, VertexInputType* vertexInput) = 0;
|
||||
protected:
|
||||
Gfx::PGraphics graphics;
|
||||
std::string brdfName;
|
||||
Array<PShaderParameter> parameters;
|
||||
Gfx::PUniformBuffer uniformBuffer;
|
||||
uint32 uniformDataSize;
|
||||
Array<uint8> uniformData;
|
||||
int32 uniformBinding;
|
||||
};
|
||||
DEFINE_REF(MaterialInterface)
|
||||
} // namespace Seele
|
||||
@@ -16,7 +16,6 @@ Scene::Scene(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
, physics(registry)
|
||||
{
|
||||
|
||||
ShaderBufferCreateInfo structInfo = {
|
||||
.resourceData = {
|
||||
.size = sizeof(Component::DirectionalLight) * MAX_DIRECTIONAL_LIGHTS,
|
||||
@@ -50,59 +49,6 @@ void Scene::update(float deltaTime)
|
||||
physics.update(deltaTime);
|
||||
}
|
||||
|
||||
Array<MeshBatch> Scene::getStaticMeshes()
|
||||
{
|
||||
Array<MeshBatch> result;
|
||||
auto view = registry.view<Component::StaticMesh, Component::Transform>();
|
||||
uint32 sceneDataIndex = 0;
|
||||
sceneData.clear();
|
||||
for(auto&& [entity, mesh, transform] : view.each())
|
||||
{
|
||||
sceneData.add(PrimitiveSceneData {
|
||||
.localToWorld = transform.toMatrix(),
|
||||
.worldToLocal = glm::inverse(transform.toMatrix()),
|
||||
.actorLocation = Vector4(transform.getPosition(), 1.0f)
|
||||
});
|
||||
for(auto& m : mesh.mesh->meshes)
|
||||
{
|
||||
auto& batch = result.add();
|
||||
batch.material = m->referencedMaterial->getMaterial();
|
||||
batch.isBackfaceCullingDisabled = false;
|
||||
batch.isCastingShadow = true;
|
||||
batch.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
batch.useReverseCulling = false;
|
||||
batch.useWireframe = false;
|
||||
batch.vertexInput = m->vertexInput;
|
||||
MeshBatchElement batchElement;
|
||||
batchElement.baseVertexIndex = 0;
|
||||
batchElement.firstIndex = 0;
|
||||
batchElement.indexBuffer = m->indexBuffer;
|
||||
batchElement.indirectArgsBuffer = nullptr;
|
||||
batchElement.isInstanced = false;
|
||||
batchElement.numInstances = 1;
|
||||
batchElement.sceneDataIndex = sceneDataIndex;
|
||||
batch.elements.add(batchElement);
|
||||
}
|
||||
sceneDataIndex++;
|
||||
}
|
||||
if(sceneDataBuffer == nullptr || sceneDataBuffer->getNumElements() != sceneData.size())
|
||||
{
|
||||
ShaderBufferCreateInfo createInfo = ShaderBufferCreateInfo {
|
||||
.resourceData = {
|
||||
.size = sceneData.size() * sizeof(PrimitiveSceneData),
|
||||
.data = nullptr,
|
||||
},
|
||||
.stride = (uint32)sceneData.size(),
|
||||
};
|
||||
sceneDataBuffer = graphics->createShaderBuffer(createInfo);
|
||||
}
|
||||
sceneDataBuffer->updateContents(BulkResourceData {
|
||||
.size = sceneData.size() * sizeof(PrimitiveSceneData),
|
||||
.data = (uint8*)sceneData.data(),
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
LightEnv Scene::getLightBuffer()
|
||||
{
|
||||
StaticArray<Component::DirectionalLight, MAX_DIRECTIONAL_LIGHTS> dirLights;
|
||||
|
||||
@@ -50,26 +50,16 @@ public:
|
||||
{
|
||||
return registry.get<Component>(entity);
|
||||
}
|
||||
template<typename Component, typename Func>
|
||||
void view(Func func) requires std::is_invocable_v<Func, Component&>
|
||||
template<typename... Component, typename Func>
|
||||
void view(Func func) requires std::is_invocable_v<Func, Component&...> || std::is_invocable_v<Func, entt::entity, Component&...>
|
||||
{
|
||||
registry.view<Component>().each(func);
|
||||
registry.view<Component...>().each(func);
|
||||
}
|
||||
Array<MeshBatch> getStaticMeshes();
|
||||
LightEnv getLightBuffer();
|
||||
Component::Skybox getSkybox();
|
||||
Gfx::PShaderBuffer getSceneDataBuffer() const { return sceneDataBuffer; }
|
||||
Gfx::PGraphics getGraphics() const { return graphics; }
|
||||
entt::registry registry;
|
||||
private:
|
||||
struct PrimitiveSceneData
|
||||
{
|
||||
Matrix4 localToWorld;
|
||||
Matrix4 worldToLocal;
|
||||
Vector4 actorLocation;
|
||||
};
|
||||
Array<PrimitiveSceneData> sceneData;
|
||||
Gfx::PShaderBuffer sceneDataBuffer;
|
||||
LightEnv lightEnv;
|
||||
PhysicsSystem physics;
|
||||
Gfx::PGraphics graphics;
|
||||
|
||||
@@ -3,6 +3,8 @@ target_sources(Engine
|
||||
ComponentSystem.h
|
||||
Executor.h
|
||||
Executor.cpp
|
||||
MeshUpdater.h
|
||||
MeshUpdater.cpp
|
||||
SystemBase.h
|
||||
SystemGraph.h
|
||||
SystemGraph.cpp)
|
||||
@@ -11,6 +13,7 @@ target_sources(Engine
|
||||
PUBLIC FILE_SET HEADERS
|
||||
FILES
|
||||
ComponentSystem.h
|
||||
MeshUpdater.h
|
||||
Executor.h
|
||||
SystemBase.h
|
||||
SystemGraph.h)
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "MeshUpdater.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::System;
|
||||
|
||||
void MeshUpdater::update(Component::Transform& transform, Component::Mesh& mesh)
|
||||
{
|
||||
mesh.vertexData->updateMesh(transform, mesh);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "ComponentSystem.h"
|
||||
#include "Component/Transform.h"
|
||||
#include "Component/Mesh.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace System
|
||||
{
|
||||
class MeshUpdater : public ComponentSystem<Component::Transform, Component::Mesh>
|
||||
{
|
||||
public:
|
||||
virtual void update(Component::Transform& transform, Component::Mesh& mesh) override;
|
||||
private:
|
||||
};
|
||||
} // namespace System
|
||||
} // namespace Seele
|
||||
@@ -11,9 +11,9 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
|
||||
: View(graphics, window, createInfo, "Game")
|
||||
, gameInterface(dllPath)
|
||||
, renderGraph(RenderGraphBuilder::build(
|
||||
DepthPrepass(graphics),
|
||||
DepthPrepass(graphics, scene),
|
||||
LightCullingPass(graphics),
|
||||
BasePass(graphics),
|
||||
BasePass(graphics, scene),
|
||||
SkyboxRenderPass(graphics)
|
||||
))
|
||||
{
|
||||
@@ -33,8 +33,16 @@ void GameView::beginUpdate()
|
||||
void GameView::update()
|
||||
{
|
||||
static auto startTime = std::chrono::high_resolution_clock::now();
|
||||
for (VertexData* vd : VertexData::getList())
|
||||
{
|
||||
vd->resetMeshData();
|
||||
}
|
||||
systemGraph->run(threadPool, updateTime);
|
||||
scene->update(updateTime);
|
||||
for (VertexData* vd : VertexData::getList())
|
||||
{
|
||||
vd->createDescriptors();
|
||||
}
|
||||
auto endTime = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<float> duration = (endTime - startTime);
|
||||
updateTime = duration.count();
|
||||
@@ -43,13 +51,7 @@ void GameView::update()
|
||||
|
||||
void GameView::commitUpdate()
|
||||
{
|
||||
depthPrepassData.staticDrawList = scene->getStaticMeshes();
|
||||
depthPrepassData.sceneDataBuffer = scene->getSceneDataBuffer();
|
||||
lightCullingData.lightEnv = scene->getLightBuffer();
|
||||
basePassData.staticDrawList = scene->getStaticMeshes();
|
||||
basePassData.sceneDataBuffer = scene->getSceneDataBuffer();
|
||||
basePassData.lightEnv = scene->getLightBuffer();
|
||||
skyboxData.skybox = scene->getSkybox();
|
||||
|
||||
}
|
||||
|
||||
void GameView::prepareRender()
|
||||
@@ -59,13 +61,7 @@ void GameView::prepareRender()
|
||||
|
||||
void GameView::render()
|
||||
{
|
||||
scene->view<Component::Camera>([&](Component::Camera& cam)
|
||||
{
|
||||
if(cam.mainCamera)
|
||||
{
|
||||
renderGraph.render(cam);
|
||||
}
|
||||
});
|
||||
renderGraph.render(camera->accessComponent<Component::Camera>());
|
||||
}
|
||||
|
||||
void GameView::reloadGame()
|
||||
|
||||
@@ -36,6 +36,7 @@ private:
|
||||
BasePassData basePassData;
|
||||
SkyboxPassData skyboxData;
|
||||
|
||||
PEntity camera;
|
||||
PScene scene;
|
||||
PSystemGraph systemGraph;
|
||||
dp::thread_pool<> threadPool;
|
||||
|
||||
Reference in New Issue
Block a user