overhauled physics engine
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
DebugVertex.h
|
||||
GraphicsResources.h
|
||||
GraphicsResources.cpp
|
||||
GraphicsInitializer.h
|
||||
@@ -23,6 +24,7 @@ target_sources(Engine
|
||||
target_sources(Engine
|
||||
PUBLIC FILE_SET HEADERS
|
||||
FILES
|
||||
DebugVertex.h
|
||||
GraphicsResources.h
|
||||
GraphicsInitializer.h
|
||||
GraphicsEnums.h
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "Math/Vector.h"
|
||||
#include "Containers/Array.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
struct DebugVertex
|
||||
{
|
||||
Vector position;
|
||||
Vector color;
|
||||
};
|
||||
extern Array<DebugVertex> gDebugVertices;
|
||||
} // namespace Seele
|
||||
@@ -18,10 +18,10 @@ PVertexBuffer Graphics::getNullVertexBuffer()
|
||||
{
|
||||
VertexBufferCreateInfo createInfo;
|
||||
createInfo.numVertices = 1;
|
||||
createInfo.vertexSize = sizeof(Math::Vector4);
|
||||
Math::Vector4 data = Math::Vector4(1, 1, 1, 1);
|
||||
createInfo.vertexSize = sizeof(Vector4);
|
||||
Vector4 data = Vector4(1, 1, 1, 1);
|
||||
createInfo.resourceData.data = reinterpret_cast<uint8*>(&data);
|
||||
createInfo.resourceData.size = sizeof(Math::Vector4);
|
||||
createInfo.resourceData.size = sizeof(Vector4);
|
||||
nullVertexBuffer = createVertexBuffer(createInfo);
|
||||
}
|
||||
return nullVertexBuffer;
|
||||
|
||||
@@ -42,7 +42,7 @@ struct WindowCreateInfo
|
||||
};
|
||||
struct ViewportCreateInfo
|
||||
{
|
||||
Math::URect dimensions;
|
||||
URect dimensions;
|
||||
float fieldOfView = 1.222f; // 70 deg
|
||||
};
|
||||
// doesnt own the data, only proxy it
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "Graphics.h"
|
||||
#include "RenderPass/DepthPrepass.h"
|
||||
#include "RenderPass/BasePass.h"
|
||||
#include "Material/MaterialAsset.h"
|
||||
#include "Material/Material.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Gfx;
|
||||
@@ -54,7 +54,7 @@ const ShaderCollection* ShaderMap::findShaders(PermutationId&& id) const
|
||||
ShaderCollection& ShaderMap::createShaders(
|
||||
PGraphics graphics,
|
||||
RenderPassType renderPass,
|
||||
PMaterialAsset material,
|
||||
PMaterial material,
|
||||
VertexInputType* vertexInput,
|
||||
bool /*bPositionOnly*/)
|
||||
{
|
||||
@@ -195,10 +195,11 @@ bool UniformBuffer::updateContents(const BulkResourceData& resourceData)
|
||||
return true;
|
||||
}
|
||||
|
||||
StructuredBuffer::StructuredBuffer(QueueFamilyMapping mapping, uint32 stride, const BulkResourceData& resourceData)
|
||||
StructuredBuffer::StructuredBuffer(QueueFamilyMapping mapping, uint32 stride, uint32 numElements, const BulkResourceData& resourceData)
|
||||
: Buffer(mapping, resourceData.owner)
|
||||
, contents(resourceData.size)
|
||||
, stride(stride)
|
||||
, numElements(numElements)
|
||||
{
|
||||
if(resourceData.data != nullptr)
|
||||
{
|
||||
@@ -515,7 +516,7 @@ Viewport::~Viewport()
|
||||
{
|
||||
}
|
||||
|
||||
Math::Matrix4 Viewport::getProjectionMatrix() const
|
||||
Matrix4 Viewport::getProjectionMatrix() const
|
||||
{
|
||||
if(fieldOfView > 0.0f)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ struct VertexInputStream;
|
||||
struct VertexStreamComponent;
|
||||
class VertexInputType;
|
||||
struct MeshBatchElement;
|
||||
DECLARE_REF(MaterialAsset)
|
||||
DECLARE_REF(Material)
|
||||
namespace Gfx
|
||||
{
|
||||
DECLARE_REF(Graphics)
|
||||
@@ -97,11 +97,11 @@ struct PermutationId
|
||||
{
|
||||
uint32 hash;
|
||||
PermutationId()
|
||||
: hash(0)
|
||||
{}
|
||||
PermutationId(ShaderPermutation permutation)
|
||||
{
|
||||
hash = CRC::Calculate(&permutation, sizeof(ShaderPermutation), CRC::CRC_32());
|
||||
}
|
||||
: hash(CRC::Calculate(&permutation, sizeof(ShaderPermutation), CRC::CRC_32()))
|
||||
{}
|
||||
friend inline bool operator==(const PermutationId& lhs, const PermutationId& rhs)
|
||||
{
|
||||
return lhs.hash == rhs.hash;
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
ShaderCollection& createShaders(
|
||||
PGraphics graphics,
|
||||
RenderPassType passName,
|
||||
PMaterialAsset material,
|
||||
PMaterial material,
|
||||
VertexInputType* vertexInput,
|
||||
bool bPositionOnly);
|
||||
private:
|
||||
@@ -409,7 +409,7 @@ DEFINE_REF(IndexBuffer)
|
||||
class StructuredBuffer : public Buffer
|
||||
{
|
||||
public:
|
||||
StructuredBuffer(QueueFamilyMapping mapping, uint32 stride, const BulkResourceData& bulkResourceData);
|
||||
StructuredBuffer(QueueFamilyMapping mapping, uint32 stride, uint32 numElements, const BulkResourceData& bulkResourceData);
|
||||
virtual ~StructuredBuffer();
|
||||
virtual bool updateContents(const BulkResourceData& resourceData);
|
||||
bool isDataEquals(StructuredBuffer* other)
|
||||
@@ -428,6 +428,10 @@ public:
|
||||
}
|
||||
return true;
|
||||
}
|
||||
constexpr uint32 getNumElements() const
|
||||
{
|
||||
return numElements;
|
||||
}
|
||||
constexpr uint32 getStride() const
|
||||
{
|
||||
return stride;
|
||||
@@ -439,6 +443,7 @@ protected:
|
||||
SeAccessFlags dstAccess, SePipelineStageFlags dstStage) = 0;
|
||||
|
||||
Array<uint8> contents;
|
||||
uint32 numElements;
|
||||
uint32 stride;
|
||||
};
|
||||
DEFINE_REF(StructuredBuffer)
|
||||
@@ -655,7 +660,7 @@ public:
|
||||
constexpr uint32 getSizeY() const {return sizeY;}
|
||||
constexpr uint32 getOffsetX() const {return offsetX;}
|
||||
constexpr uint32 getOffsetY() const {return offsetY;}
|
||||
Math::Matrix4 getProjectionMatrix() const;
|
||||
Matrix4 getProjectionMatrix() const;
|
||||
protected:
|
||||
uint32 sizeX;
|
||||
uint32 sizeY;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
using namespace Seele;
|
||||
|
||||
Mesh::Mesh(PVertexShaderInput vertexInput, Gfx::PIndexBuffer indexBuffer)
|
||||
: indexBuffer(indexBuffer)
|
||||
, vertexInput(vertexInput)
|
||||
: vertexInput(vertexInput)
|
||||
, indexBuffer(indexBuffer)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
#include "GraphicsResources.h"
|
||||
#include "Material/MaterialAsset.h"
|
||||
#include "Material/MaterialInterface.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(MaterialAsset)
|
||||
DECLARE_REF(VertexShaderInput)
|
||||
DECLARE_NAME_REF(Gfx, IndexBuffer)
|
||||
class Mesh
|
||||
{
|
||||
public:
|
||||
@@ -13,7 +14,7 @@ public:
|
||||
|
||||
Gfx::PIndexBuffer indexBuffer;
|
||||
PVertexShaderInput vertexInput;
|
||||
PMaterialAsset referencedMaterial;
|
||||
PMaterialInterface referencedMaterial;
|
||||
private:
|
||||
};
|
||||
DEFINE_REF(Mesh)
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#include "MeshBatch.h"
|
||||
#include "GraphicsResources.h"
|
||||
#include "VertexShaderInput.h"
|
||||
#include "Material/MaterialAsset.h"
|
||||
#include "Material/MaterialInterface.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
MeshBatchElement::MeshBatchElement()
|
||||
: uniformBuffer(nullptr)
|
||||
, indexBuffer(nullptr)
|
||||
: indexBuffer(nullptr)
|
||||
, firstIndex(0)
|
||||
, numPrimitives(0)
|
||||
, numInstances(1)
|
||||
|
||||
@@ -4,22 +4,16 @@
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(VertexShaderInput)
|
||||
DECLARE_REF(MaterialAsset)
|
||||
DECLARE_REF(MaterialInterface)
|
||||
DECLARE_NAME_REF(Gfx, VertexBuffer)
|
||||
DECLARE_NAME_REF(Gfx, IndexBuffer)
|
||||
DECLARE_NAME_REF(Gfx, UniformBuffer)
|
||||
struct MeshBatchElement
|
||||
{
|
||||
public:
|
||||
Gfx::PUniformBuffer uniformBuffer;
|
||||
Gfx::PIndexBuffer indexBuffer;
|
||||
|
||||
union
|
||||
{
|
||||
uint32* instanceRuns;
|
||||
};
|
||||
|
||||
|
||||
uint32 sceneDataIndex;
|
||||
uint32 firstIndex;
|
||||
uint32 numPrimitives;
|
||||
|
||||
@@ -45,27 +39,7 @@ struct MeshBatch
|
||||
|
||||
PVertexShaderInput vertexInput;
|
||||
|
||||
PMaterialAsset material;
|
||||
|
||||
inline int32 getNumPrimitives() const
|
||||
{
|
||||
int32 count = 0;
|
||||
for(uint32 index = 0; index < elements.size(); ++index)
|
||||
{
|
||||
if(elements[index].isInstanced && elements[index].instanceRuns)
|
||||
{
|
||||
for(uint32 run = 0; run < elements[index].numInstances; ++run)
|
||||
{
|
||||
count += elements[index].numPrimitives * (elements[index].instanceRuns[run * 2 + 1] - elements[index].instanceRuns[run * 2] - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
count += elements[index].numPrimitives * elements[index].numInstances;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
PMaterialInterface material;
|
||||
|
||||
MeshBatch();
|
||||
MeshBatch(const MeshBatch& other) = default;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
#include "Material/MaterialAsset.h"
|
||||
#include "Material/MaterialInstance.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -29,7 +29,7 @@ void BasePassMeshProcessor::processMeshBatch(
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 /*staticMeshId*/)
|
||||
{
|
||||
PMaterialAsset material = batch.material;
|
||||
PMaterialInterface material = batch.material;
|
||||
//const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
|
||||
|
||||
const PVertexShaderInput vertexInput = batch.vertexInput;
|
||||
@@ -47,12 +47,7 @@ void BasePassMeshProcessor::processMeshBatch(
|
||||
descriptorSets[BasePass::INDEX_MATERIAL] = materialSet;
|
||||
for(uint32 i = 0; i < batch.elements.size(); ++i)
|
||||
{
|
||||
Gfx::PDescriptorSet descriptorSet = primitiveLayout->allocateDescriptorSet();
|
||||
descriptorSet->updateBuffer(0, batch.elements[i].uniformBuffer);
|
||||
descriptorSet->writeChanges();
|
||||
descriptorSets[BasePass::INDEX_SCENE_DATA] = descriptorSet;
|
||||
buildMeshDrawCommand(batch,
|
||||
// primitiveComponent,
|
||||
renderPass,
|
||||
pipelineLayout,
|
||||
renderCommand,
|
||||
@@ -104,9 +99,14 @@ BasePass::BasePass(Gfx::PGraphics graphics)
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
||||
|
||||
primitiveLayout = graphics->createDescriptorLayout("PrimitiveLayout");
|
||||
primitiveLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
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),
|
||||
});
|
||||
}
|
||||
|
||||
BasePass::~BasePass()
|
||||
@@ -121,13 +121,17 @@ void BasePass::beginFrame(const Component::Camera& cam)
|
||||
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
viewParams.projectionMatrix = viewport->getProjectionMatrix();
|
||||
viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0);
|
||||
viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
|
||||
viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 0);
|
||||
viewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
|
||||
uniformUpdate.size = sizeof(ViewParameter);
|
||||
uniformUpdate.data = (uint8*)&viewParams;
|
||||
viewParamBuffer->updateContents(uniformUpdate);
|
||||
viewLayout->reset();
|
||||
lightLayout->reset();
|
||||
|
||||
descriptorSets[INDEX_SCENE_DATA] = primitiveLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_SCENE_DATA]->updateBuffer(0, passData.sceneDataBuffer);
|
||||
descriptorSets[INDEX_SCENE_DATA]->writeChanges();
|
||||
descriptorSets[INDEX_LIGHT_ENV] = lightLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
|
||||
@@ -152,6 +156,7 @@ void BasePass::render()
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(4, oLightIndexList);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateTexture(5, oLightGrid);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->writeChanges();
|
||||
|
||||
graphics->beginRenderPass(renderPass);
|
||||
for (auto &&meshBatch : passData.staticDrawList)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@ DECLARE_REF(CameraActor)
|
||||
struct BasePassData
|
||||
{
|
||||
Array<StaticMeshBatch> staticDrawList;
|
||||
Gfx::PStructuredBuffer sceneDataBuffer;
|
||||
};
|
||||
class BasePass : public RenderPass<BasePassData>
|
||||
{
|
||||
|
||||
@@ -2,6 +2,8 @@ target_sources(Engine
|
||||
PRIVATE
|
||||
BasePass.h
|
||||
BasePass.cpp
|
||||
DebugPass.h
|
||||
DebugPass.cpp
|
||||
DepthPrepass.h
|
||||
DepthPrepass.cpp
|
||||
LightCullingPass.h
|
||||
@@ -21,6 +23,7 @@ target_sources(Engine
|
||||
PUBLIC FILE_SET HEADERS
|
||||
FILES
|
||||
BasePass.h
|
||||
DebugPass.h
|
||||
DepthPrepass.h
|
||||
LightCullingPass.h
|
||||
MeshProcessor.h
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
#include "DebugPass.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Array<DebugVertex> Seele::gDebugVertices;
|
||||
|
||||
DebugPass::DebugPass(Gfx::PGraphics graphics)
|
||||
: RenderPass(graphics)
|
||||
{
|
||||
|
||||
}
|
||||
DebugPass::~DebugPass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DebugPass::beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
BulkResourceData uniformUpdate;
|
||||
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
viewParams.projectionMatrix = viewport->getProjectionMatrix();
|
||||
viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 0);
|
||||
viewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
|
||||
uniformUpdate.size = sizeof(ViewParameter);
|
||||
uniformUpdate.data = (uint8*)&viewParams;
|
||||
viewParamsBuffer->updateContents(uniformUpdate);
|
||||
descriptorLayout->reset();
|
||||
descriptorSet = descriptorLayout->allocateDescriptorSet();
|
||||
descriptorSet->updateBuffer(0, viewParamsBuffer);
|
||||
descriptorSet->writeChanges();
|
||||
|
||||
VertexBufferCreateInfo vertexBufferInfo = {
|
||||
.resourceData = {
|
||||
.size = sizeof(DebugVertex) * passData.vertices.size(),
|
||||
.data = (uint8*)passData.vertices.data(),
|
||||
},
|
||||
.vertexSize = sizeof(DebugVertex),
|
||||
.numVertices = (uint32)passData.vertices.size(),
|
||||
};
|
||||
debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
|
||||
|
||||
}
|
||||
|
||||
void DebugPass::render()
|
||||
{
|
||||
graphics->beginRenderPass(renderPass);
|
||||
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("DebugRender");
|
||||
renderCommand->setViewport(viewport);
|
||||
renderCommand->bindPipeline(pipeline);
|
||||
renderCommand->bindDescriptor(descriptorSet);
|
||||
renderCommand->bindVertexBuffer({VertexInputStream(0, 0, debugVertices)});
|
||||
renderCommand->draw((uint32)passData.vertices.size(), 1, 0, 0);
|
||||
graphics->executeCommands(Array{renderCommand});
|
||||
graphics->endRenderPass();
|
||||
}
|
||||
|
||||
void DebugPass::endFrame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DebugPass::publishOutputs()
|
||||
{
|
||||
UniformBufferCreateInfo viewCreateInfo = {
|
||||
.resourceData = BulkResourceData {
|
||||
.size = sizeof(ViewParameter),
|
||||
.data = nullptr,
|
||||
},
|
||||
.bDynamic = true
|
||||
};
|
||||
viewParamsBuffer = graphics->createUniformBuffer(viewCreateInfo);
|
||||
|
||||
descriptorLayout = graphics->createDescriptorLayout("DebugDescLayout");
|
||||
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
descriptorLayout->create();
|
||||
|
||||
pipelineLayout = graphics->createPipelineLayout();
|
||||
pipelineLayout->addDescriptorLayout(0, descriptorLayout);
|
||||
pipelineLayout->create();
|
||||
}
|
||||
|
||||
void DebugPass::createRenderPass()
|
||||
{
|
||||
Gfx::PRenderTargetAttachment baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
|
||||
baseColorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
|
||||
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
|
||||
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
|
||||
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(baseColorAttachment, depthAttachment);
|
||||
renderPass = graphics->createRenderPass(layout, viewport);
|
||||
|
||||
ShaderCreateInfo createInfo;
|
||||
createInfo.name = "DebugVertex";
|
||||
createInfo.mainModule = "Debug";
|
||||
createInfo.entryPoint = "vertexMain";
|
||||
createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
|
||||
Gfx::PVertexShader vertexShader = graphics->createVertexShader(createInfo);
|
||||
|
||||
createInfo.name = "DebugFragment";
|
||||
|
||||
createInfo.entryPoint = "fragmentMain";
|
||||
Gfx::PFragmentShader fragmentShader = graphics->createFragmentShader(createInfo);
|
||||
|
||||
Gfx::PVertexDeclaration vertexDecl = graphics->createVertexDeclaration({
|
||||
Gfx::VertexElement {
|
||||
.streamIndex = 0,
|
||||
.offset = offsetof(DebugVertex, position),
|
||||
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
|
||||
.attributeIndex = 0,
|
||||
.stride = sizeof(DebugVertex),
|
||||
},
|
||||
Gfx::VertexElement {
|
||||
.streamIndex = 0,
|
||||
.offset = offsetof(DebugVertex, color),
|
||||
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
|
||||
.attributeIndex = 1,
|
||||
.stride = sizeof(DebugVertex),
|
||||
}
|
||||
});
|
||||
|
||||
GraphicsPipelineCreateInfo gfxInfo;
|
||||
gfxInfo.vertexDeclaration = vertexDecl;
|
||||
gfxInfo.vertexShader = vertexShader;
|
||||
gfxInfo.fragmentShader = fragmentShader;
|
||||
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_LINE;
|
||||
gfxInfo.rasterizationState.lineWidth = 5.f;
|
||||
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST;
|
||||
gfxInfo.pipelineLayout = pipelineLayout;
|
||||
gfxInfo.renderPass = renderPass;
|
||||
pipeline = graphics->createGraphicsPipeline(gfxInfo);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "RenderPass.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Graphics/DebugVertex.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(CameraActor)
|
||||
DECLARE_REF(Scene)
|
||||
DECLARE_REF(Viewport)
|
||||
struct DebugPassData
|
||||
{
|
||||
Array<DebugVertex> vertices;
|
||||
};
|
||||
class DebugPass : public RenderPass<DebugPassData>
|
||||
{
|
||||
public:
|
||||
DebugPass(Gfx::PGraphics graphics);
|
||||
virtual ~DebugPass();
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void publishOutputs() override;
|
||||
virtual void createRenderPass() override;
|
||||
private:
|
||||
Gfx::PVertexBuffer debugVertices;
|
||||
Gfx::PUniformBuffer viewParamsBuffer;
|
||||
Gfx::PDescriptorLayout descriptorLayout;
|
||||
Gfx::PDescriptorSet descriptorSet;
|
||||
Gfx::PPipelineLayout pipelineLayout;
|
||||
Gfx::PGraphicsPipeline pipeline;
|
||||
};
|
||||
DEFINE_REF(DebugPass)
|
||||
} // namespace Seele
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
#include "Material/MaterialAsset.h"
|
||||
#include "Material/MaterialInterface.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -28,7 +28,7 @@ void DepthPrepassMeshProcessor::processMeshBatch(
|
||||
int32 /*staticMeshId*/)
|
||||
{
|
||||
//std::cout << "Depth void started" << std::endl;
|
||||
PMaterialAsset material = batch.material;
|
||||
PMaterialInterface material = batch.material;
|
||||
//const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
|
||||
|
||||
const PVertexShaderInput vertexInput = batch.vertexInput;
|
||||
@@ -44,11 +44,7 @@ void DepthPrepassMeshProcessor::processMeshBatch(
|
||||
Gfx::PDescriptorSet materialSet = material->createDescriptorSet();
|
||||
descriptorSets[DepthPrepass::INDEX_MATERIAL] = materialSet;
|
||||
for(uint32 i = 0; i < batch.elements.size(); ++i)
|
||||
{
|
||||
Gfx::PDescriptorSet descriptorSet = primitiveLayout->allocateDescriptorSet();
|
||||
descriptorSet->updateBuffer(0, batch.elements[i].uniformBuffer);
|
||||
descriptorSet->writeChanges();
|
||||
descriptorSets[DepthPrepass::INDEX_SCENE_DATA] = descriptorSet;
|
||||
{
|
||||
buildMeshDrawCommand(batch,
|
||||
// primitiveComponent,
|
||||
renderPass,
|
||||
@@ -87,9 +83,14 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics)
|
||||
depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewLayout);
|
||||
|
||||
primitiveLayout = graphics->createDescriptorLayout("PrimitiveLayout");
|
||||
primitiveLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
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,12 +105,15 @@ void DepthPrepass::beginFrame(const Component::Camera& cam)
|
||||
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
viewParams.projectionMatrix = viewport->getProjectionMatrix();
|
||||
viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0);
|
||||
viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
|
||||
viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 0);
|
||||
viewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
|
||||
uniformUpdate.size = sizeof(ViewParameter);
|
||||
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();
|
||||
|
||||
@@ -26,6 +26,7 @@ DEFINE_REF(DepthPrepassMeshProcessor)
|
||||
struct DepthPrepassData
|
||||
{
|
||||
Array<StaticMeshBatch> staticDrawList;
|
||||
Gfx::PStructuredBuffer sceneDataBuffer;
|
||||
};
|
||||
class DepthPrepass : public RenderPass<DepthPrepassData>
|
||||
{
|
||||
|
||||
@@ -25,8 +25,8 @@ void LightCullingPass::beginFrame(const Component::Camera& cam)
|
||||
BulkResourceData uniformUpdate;
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
viewParams.projectionMatrix = viewport->getProjectionMatrix();
|
||||
viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0);
|
||||
viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewportWidth), static_cast<float>(viewportHeight));
|
||||
viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 0);
|
||||
viewParams.screenDimensions = Vector2(static_cast<float>(viewportWidth), static_cast<float>(viewportHeight));
|
||||
uniformUpdate.size = sizeof(ViewParameter);
|
||||
uniformUpdate.data = (uint8*)&viewParams;
|
||||
viewParamsBuffer->updateContents(uniformUpdate);
|
||||
@@ -261,9 +261,9 @@ void LightCullingPass::setupFrustums()
|
||||
glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(numThreads.x / (float)BLOCK_SIZE, numThreads.y / (float)BLOCK_SIZE, 1));
|
||||
|
||||
viewParams = {
|
||||
.viewMatrix = Math::Matrix4(),
|
||||
.projectionMatrix = Math::Matrix4(),
|
||||
.cameraPosition = Math::Vector4(),
|
||||
.viewMatrix = Matrix4(),
|
||||
.projectionMatrix = Matrix4(),
|
||||
.cameraPosition = Vector4(),
|
||||
.screenDimensions = glm::vec2(viewportWidth, viewportHeight),
|
||||
};
|
||||
dispatchParams.numThreads = numThreads;
|
||||
|
||||
@@ -36,7 +36,7 @@ private:
|
||||
} dispatchParams;
|
||||
struct Plane
|
||||
{
|
||||
Math::Vector n;
|
||||
Vector n;
|
||||
float d;
|
||||
};
|
||||
struct Frustum
|
||||
|
||||
@@ -56,10 +56,18 @@ void MeshProcessor::buildMeshDrawCommand(
|
||||
drawCommand->bindPipeline(pipeline);
|
||||
drawCommand->bindVertexBuffer(vertexStreams);
|
||||
drawCommand->bindDescriptor(descriptors);
|
||||
for(auto element : meshBatch.elements)
|
||||
for(const auto& element : meshBatch.elements)
|
||||
{
|
||||
drawCommand->bindIndexBuffer(element.indexBuffer);
|
||||
drawCommand->draw(element);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +35,11 @@ public:
|
||||
protected:
|
||||
struct ViewParameter
|
||||
{
|
||||
Math::Matrix4 viewMatrix;
|
||||
Math::Matrix4 projectionMatrix;
|
||||
Math::Vector4 cameraPosition;
|
||||
Math::Vector2 screenDimensions;
|
||||
Math::Vector2 pad0;
|
||||
Matrix4 viewMatrix;
|
||||
Matrix4 projectionMatrix;
|
||||
Vector4 cameraPosition;
|
||||
Vector2 screenDimensions;
|
||||
Vector2 pad0;
|
||||
} viewParams;
|
||||
PRenderGraphResources resources;
|
||||
RenderPassDataType passData;
|
||||
|
||||
@@ -27,8 +27,8 @@ void TextPass::beginFrame(const Component::Camera&)
|
||||
for(uint32 c : render.text)
|
||||
{
|
||||
const GlyphData& glyph = fd.glyphDataSet[fd.characterToGlyphIndex[c]];
|
||||
Math::Vector2 bearing = glyph.bearing;
|
||||
Math::Vector2 size = glyph.size;
|
||||
Vector2 bearing = glyph.bearing;
|
||||
Vector2 size = glyph.size;
|
||||
float xpos = x + bearing.x * render.scale;
|
||||
float ypos = y - (size.y - bearing.y) * render.scale;
|
||||
|
||||
@@ -36,8 +36,8 @@ void TextPass::beginFrame(const Component::Camera&)
|
||||
float h = size.y * render.scale;
|
||||
|
||||
instanceData.add(GlyphInstanceData{
|
||||
.position = Math::Vector2(xpos, ypos),
|
||||
.widthHeight = Math::Vector2(w, h),
|
||||
.position = Vector2(xpos, ypos),
|
||||
.widthHeight = Vector2(w, h),
|
||||
.glyphIndex = fd.characterToGlyphIndex[c],
|
||||
});
|
||||
x += (glyph.advance >> 6) * render.scale;
|
||||
@@ -61,7 +61,7 @@ void TextPass::beginFrame(const Component::Camera&)
|
||||
}
|
||||
auto proj = viewport->getProjectionMatrix();
|
||||
BulkResourceData projectionUpdate = {
|
||||
.size = sizeof(Math::Matrix4),
|
||||
.size = sizeof(Matrix4),
|
||||
.data = (uint8*)&proj,
|
||||
};
|
||||
projectionBuffer->updateContents(projectionUpdate);
|
||||
@@ -157,7 +157,7 @@ void TextPass::createRenderPass()
|
||||
|
||||
projectionBuffer = graphics->createUniformBuffer({
|
||||
.resourceData = {
|
||||
.size = sizeof(Math::Matrix4),
|
||||
.size = sizeof(Matrix4),
|
||||
.data = nullptr,
|
||||
},
|
||||
.bDynamic = true,
|
||||
|
||||
@@ -13,8 +13,8 @@ struct TextRender
|
||||
{
|
||||
std::string text;
|
||||
PFontAsset font;
|
||||
Math::Vector4 textColor;
|
||||
Math::Vector2 position;
|
||||
Vector4 textColor;
|
||||
Vector2 position;
|
||||
float scale;
|
||||
};
|
||||
struct TextPassData
|
||||
@@ -35,19 +35,19 @@ public:
|
||||
private:
|
||||
struct GlyphData
|
||||
{
|
||||
Math::Vector2 bearing;
|
||||
Math::Vector2 size;
|
||||
Vector2 bearing;
|
||||
Vector2 size;
|
||||
uint32 advance;
|
||||
};
|
||||
struct GlyphInstanceData
|
||||
{
|
||||
Math::Vector2 position;
|
||||
Math::Vector2 widthHeight;
|
||||
Vector2 position;
|
||||
Vector2 widthHeight;
|
||||
uint32 glyphIndex;
|
||||
};
|
||||
struct TextData
|
||||
{
|
||||
Math::Vector4 textColor;
|
||||
Vector4 textColor;
|
||||
float scale;
|
||||
};
|
||||
struct FontData
|
||||
|
||||
@@ -144,10 +144,10 @@ void UIPass::createRenderPass()
|
||||
descriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT | Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT);
|
||||
descriptorLayout->create();
|
||||
|
||||
Math::Matrix4 projectionMatrix = glm::ortho(0, 1, 1, 0);
|
||||
Matrix4 projectionMatrix = glm::ortho(0, 1, 1, 0);
|
||||
UniformBufferCreateInfo info = {
|
||||
.resourceData = {
|
||||
.size = sizeof(Math::Matrix4),
|
||||
.size = sizeof(Matrix4),
|
||||
.data = (uint8*)&projectionMatrix,
|
||||
},
|
||||
.bDynamic = false,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "ShaderCompiler.h"
|
||||
#include "Material/MaterialAsset.h"
|
||||
#include "VertexShaderInput.h"
|
||||
#include "Graphics.h"
|
||||
|
||||
@@ -17,7 +16,7 @@ ShaderCompiler::~ShaderCompiler()
|
||||
|
||||
}
|
||||
|
||||
void ShaderCompiler::registerMaterial(PMaterialAsset material)
|
||||
void ShaderCompiler::registerMaterial(PMaterial material)
|
||||
{
|
||||
for(auto& type : VertexInputType::getTypeList())
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "Material/Material.h"
|
||||
#include "GraphicsResources.h"
|
||||
|
||||
namespace Seele
|
||||
@@ -11,9 +12,9 @@ class ShaderCompiler
|
||||
public:
|
||||
ShaderCompiler(PGraphics graphics);
|
||||
~ShaderCompiler();
|
||||
void registerMaterial(PMaterialAsset material);
|
||||
void registerMaterial(PMaterial material);
|
||||
private:
|
||||
Array<PMaterialAsset> pendingCompiles;
|
||||
Array<PMaterial> pendingCompiles;
|
||||
PGraphics graphics;
|
||||
};
|
||||
DEFINE_REF(ShaderCompiler)
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
List<VertexInputType*> VertexInputType::globalTypeList;
|
||||
|
||||
List<VertexInputType*>& VertexInputType::getTypeList()
|
||||
{
|
||||
static List<VertexInputType*> globalTypeList;
|
||||
return globalTypeList;
|
||||
}
|
||||
|
||||
VertexInputType* VertexInputType::getVertexInputByName(const std::string& name)
|
||||
{
|
||||
for(auto type : globalTypeList)
|
||||
for(auto type : getTypeList())
|
||||
{
|
||||
if(name.compare(type->getName()) == 0)
|
||||
{
|
||||
@@ -30,12 +30,12 @@ VertexInputType::VertexInputType(const char* name,
|
||||
: name(name)
|
||||
, shaderFilename(shaderFilename)
|
||||
{
|
||||
globalTypeList.add(this);
|
||||
getTypeList().add(this);
|
||||
}
|
||||
|
||||
VertexInputType::~VertexInputType()
|
||||
{
|
||||
globalTypeList.remove(globalTypeList.find(this));
|
||||
getTypeList().remove(getTypeList().find(this));
|
||||
}
|
||||
|
||||
const char* VertexInputType::getName()
|
||||
|
||||
@@ -95,8 +95,6 @@ public:
|
||||
private:
|
||||
const char* name;
|
||||
const char* shaderFilename;
|
||||
|
||||
static List<VertexInputType*> globalTypeList;
|
||||
};
|
||||
|
||||
#define DECLARE_VERTEX_INPUT_TYPE(inputClass) \
|
||||
|
||||
@@ -95,7 +95,7 @@ PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
|
||||
VkDeviceSize allocatedOffset = it.first;
|
||||
PSubAllocation freeAllocation = it.second;
|
||||
assert(allocatedOffset == freeAllocation->allocatedOffset);
|
||||
VkDeviceSize alignedOffset = Math::align(allocatedOffset, alignment);
|
||||
VkDeviceSize alignedOffset = align(allocatedOffset, alignment);
|
||||
VkDeviceSize alignmentAdjustment = alignedOffset - allocatedOffset;
|
||||
VkDeviceSize size = alignmentAdjustment + requestedSize;
|
||||
if (freeAllocation->size == size)
|
||||
@@ -113,8 +113,8 @@ PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
|
||||
freeAllocation->alignedOffset += size;
|
||||
PSubAllocation subAlloc = new SubAllocation(this, allocatedOffset, size, alignedOffset, size);
|
||||
activeAllocations[allocatedOffset] = subAlloc.getHandle();
|
||||
freeRanges[freeAllocation->allocatedOffset] = freeAllocation;
|
||||
freeRanges.erase(allocatedOffset);
|
||||
freeRanges[freeAllocation->allocatedOffset] = freeAllocation;
|
||||
bytesUsed += size;
|
||||
return subAlloc;
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ VkAccessFlags UniformBuffer::getDestAccessMask()
|
||||
}
|
||||
|
||||
StructuredBuffer::StructuredBuffer(PGraphics graphics, const StructuredBufferCreateInfo &resourceData)
|
||||
: Gfx::StructuredBuffer(graphics->getFamilyMapping(), resourceData.stride, resourceData.resourceData)
|
||||
: Gfx::StructuredBuffer(graphics->getFamilyMapping(), resourceData.stride, resourceData.resourceData.size / resourceData.stride, resourceData.resourceData)
|
||||
, Vulkan::ShaderBuffer(graphics, resourceData.resourceData.size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, resourceData.bDynamic)
|
||||
{
|
||||
if (resourceData.resourceData.data != nullptr)
|
||||
@@ -380,6 +380,7 @@ StructuredBuffer::~StructuredBuffer()
|
||||
|
||||
bool StructuredBuffer::updateContents(const BulkResourceData &resourceData)
|
||||
{
|
||||
assert(resourceData.size <= getSize());
|
||||
Gfx::StructuredBuffer::updateContents(resourceData);
|
||||
//We always want to update, as the contents could be different on the GPU
|
||||
void* data = lock();
|
||||
|
||||
Reference in New Issue
Block a user