Improving Material shader code generation
This commit is contained in:
@@ -12,6 +12,29 @@ PrimitiveComponent::PrimitiveComponent()
|
||||
|
||||
PrimitiveComponent::PrimitiveComponent(PMeshAsset asset)
|
||||
{
|
||||
auto assetMeshes = asset->getMeshes();
|
||||
staticMeshes.resize(assetMeshes.size());
|
||||
for (uint32 i = 0; i < assetMeshes.size(); i++)
|
||||
{
|
||||
auto& batch = staticMeshes[i];
|
||||
batch.material = assetMeshes[i]->referencedMaterial->getRenderMaterial();
|
||||
batch.isBackfaceCullingDisabled = false;
|
||||
batch.isCastingShadow = true;
|
||||
batch.primitiveComponent = this;
|
||||
batch.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
batch.useReverseCulling = false;
|
||||
batch.useWireframe = false;
|
||||
batch.vertexInput = assetMeshes[i]->vertexInput;
|
||||
auto& batchElement = batch.elements.add();
|
||||
batchElement.baseVertexIndex = 0;
|
||||
batchElement.firstIndex = 0;
|
||||
batchElement.indexBuffer = assetMeshes[i]->indexBuffer;
|
||||
batchElement.indirectArgsBuffer = nullptr;
|
||||
batchElement.instanceRuns = nullptr;
|
||||
batchElement.isInstanced = false;
|
||||
batchElement.numInstances = 1;
|
||||
batchElement.numPrimitives = assetMeshes[i]->indexBuffer->getNumIndices() / 3; //TODO: hardcoded
|
||||
}
|
||||
}
|
||||
|
||||
PrimitiveComponent::~PrimitiveComponent()
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Seele
|
||||
struct PrimitiveUniformBuffer
|
||||
{
|
||||
Matrix4 localToWorld;
|
||||
Vector4 worldToLocal;
|
||||
Matrix4 worldToLocal;
|
||||
Vector4 actorWorldPosition;
|
||||
};
|
||||
} // namespace Seele
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#include "Scene.h"
|
||||
#include "Components/PrimitiveComponent.h"
|
||||
#include "Components/PrimitiveUniformBufferLayout.h"
|
||||
#include "Material/MaterialInstance.h"
|
||||
#include "Material/Material.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Scene::Scene()
|
||||
Scene::Scene(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -30,4 +33,21 @@ void Scene::addActor(PActor actor)
|
||||
void Scene::addPrimitiveComponent(PPrimitiveComponent comp)
|
||||
{
|
||||
primitives.add(comp);
|
||||
for(auto batch : comp->staticMeshes)
|
||||
{
|
||||
PrimitiveUniformBuffer data;
|
||||
data.actorWorldPosition = Vector4(comp->getTransform().getPosition(), 1);
|
||||
data.localToWorld = comp->getRenderMatrix();
|
||||
data.worldToLocal = glm::inverse(data.localToWorld);
|
||||
BulkResourceData createInfo;
|
||||
createInfo.data = reinterpret_cast<uint8*>(&data);
|
||||
createInfo.owner = Gfx::QueueType::GRAPHICS;
|
||||
createInfo.size = sizeof(data);
|
||||
Gfx::PUniformBuffer uniformBuffer = graphics->createUniformBuffer(createInfo);
|
||||
for(auto& element : batch.elements)
|
||||
{
|
||||
element.uniformBuffer = uniformBuffer;
|
||||
}
|
||||
staticMeshes.add(batch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,18 @@ DECLARE_REF(Material);
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene();
|
||||
Scene(Gfx::PGraphics graphics);
|
||||
~Scene();
|
||||
void tick(float deltaTime);
|
||||
void addActor(PActor actor);
|
||||
void addPrimitiveComponent(PPrimitiveComponent comp);
|
||||
|
||||
const Array<PPrimitiveComponent>& getPrimitives() const { return primitives; }
|
||||
const Array<MeshBatch>& getStaticMeshes() const { return staticMeshes; }
|
||||
private:
|
||||
Array<MeshBatch> meshBatches;
|
||||
Array<MeshBatch> staticMeshes;
|
||||
Array<PActor> rootActors;
|
||||
Array<PPrimitiveComponent> primitives;
|
||||
public:
|
||||
Gfx::PGraphics graphics;
|
||||
};
|
||||
} // namespace Seele
|
||||
Reference in New Issue
Block a user