2020-05-05 01:51:13 +02:00
|
|
|
#include "Scene.h"
|
|
|
|
|
#include "Components/PrimitiveComponent.h"
|
2020-09-19 14:36:50 +02:00
|
|
|
#include "Components/PrimitiveUniformBufferLayout.h"
|
2020-05-05 01:51:13 +02:00
|
|
|
#include "Material/MaterialInstance.h"
|
|
|
|
|
#include "Material/Material.h"
|
2020-09-19 14:36:50 +02:00
|
|
|
#include "Graphics/Graphics.h"
|
2020-05-05 01:51:13 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
2021-05-06 17:02:10 +02:00
|
|
|
inline float frand()
|
|
|
|
|
{
|
|
|
|
|
return (float)rand()/RAND_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-19 14:36:50 +02:00
|
|
|
Scene::Scene(Gfx::PGraphics graphics)
|
|
|
|
|
: graphics(graphics)
|
2021-05-06 17:02:10 +02:00
|
|
|
, updater(new SceneUpdater())
|
2020-05-05 01:51:13 +02:00
|
|
|
{
|
2021-05-06 17:02:10 +02:00
|
|
|
lightEnv.directionalLights[0].color = Vector4(1, 1, 1, 1);
|
2021-06-04 18:27:49 +02:00
|
|
|
lightEnv.directionalLights[0].direction = Vector4(1, 1, 0, 1);
|
2021-01-19 15:30:00 +01:00
|
|
|
lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1);
|
2021-07-11 22:23:01 +02:00
|
|
|
lightEnv.numDirectionalLights = 0;
|
2021-03-31 12:18:16 +02:00
|
|
|
srand((unsigned int)time(NULL));
|
2021-08-21 18:02:53 +02:00
|
|
|
for(uint32 i = 0; i < 16; ++i)
|
2021-05-06 17:02:10 +02:00
|
|
|
{
|
|
|
|
|
lightEnv.pointLights[i].colorRange = Vector4(frand(), frand(), frand(), frand() * 30);
|
2021-06-04 18:27:49 +02:00
|
|
|
lightEnv.pointLights[i].positionWS = Vector4(frand() * 100-50, frand(), frand() * 100-50, 1);
|
2021-05-06 17:02:10 +02:00
|
|
|
}
|
2021-08-21 18:02:53 +02:00
|
|
|
lightEnv.numPointLights = 16;
|
2021-09-23 10:10:39 +02:00
|
|
|
lightEnv.pointLights[0].colorRange = Vector4(1, 1, 1, 1000);
|
2021-07-11 22:23:01 +02:00
|
|
|
lightEnv.pointLights[0].positionWS = Vector4(0, 10, 0, 1);
|
2020-05-05 01:51:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Scene::~Scene()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-25 23:43:40 +02:00
|
|
|
void Scene::tick(double deltaTime)
|
2020-05-05 01:51:13 +02:00
|
|
|
{
|
2021-05-06 17:02:10 +02:00
|
|
|
updater->runUpdates(static_cast<float>(deltaTime));
|
2021-10-16 12:59:11 +02:00
|
|
|
for(auto &&meshBatch : staticMeshes)
|
|
|
|
|
{
|
|
|
|
|
meshBatch.material->updateDescriptorData();
|
|
|
|
|
}
|
2020-05-05 01:51:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::addActor(PActor actor)
|
|
|
|
|
{
|
|
|
|
|
rootActors.add(actor);
|
|
|
|
|
actor->notifySceneAttach(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::addPrimitiveComponent(PPrimitiveComponent comp)
|
|
|
|
|
{
|
|
|
|
|
primitives.add(comp);
|
2021-04-25 23:43:40 +02:00
|
|
|
for(auto& batch : comp->getStaticMeshes())
|
2020-09-19 14:36:50 +02:00
|
|
|
{
|
|
|
|
|
PrimitiveUniformBuffer data;
|
|
|
|
|
data.actorWorldPosition = Vector4(comp->getTransform().getPosition(), 1);
|
|
|
|
|
data.localToWorld = comp->getRenderMatrix();
|
|
|
|
|
data.worldToLocal = glm::inverse(data.localToWorld);
|
2020-11-03 01:18:30 +01:00
|
|
|
UniformBufferCreateInfo createInfo;
|
|
|
|
|
createInfo.resourceData.data = reinterpret_cast<uint8*>(&data);
|
|
|
|
|
createInfo.resourceData.owner = Gfx::QueueType::GRAPHICS;
|
|
|
|
|
createInfo.resourceData.size = sizeof(data);
|
|
|
|
|
createInfo.bDynamic = true;
|
2020-09-19 14:36:50 +02:00
|
|
|
Gfx::PUniformBuffer uniformBuffer = graphics->createUniformBuffer(createInfo);
|
|
|
|
|
for(auto& element : batch.elements)
|
|
|
|
|
{
|
|
|
|
|
element.uniformBuffer = uniformBuffer;
|
|
|
|
|
}
|
|
|
|
|
staticMeshes.add(batch);
|
|
|
|
|
}
|
2020-05-05 01:51:13 +02:00
|
|
|
}
|