Files
Seele/src/Engine/Scene/Scene.cpp
T

94 lines
2.9 KiB
C++
Raw Normal View History

2020-05-05 01:51:13 +02:00
#include "Scene.h"
2020-09-19 14:36:50 +02:00
#include "Graphics/Graphics.h"
2022-11-30 10:19:45 +01:00
#include "Graphics/Mesh.h"
#include "Component/StaticMesh.h"
#include "Component/Transform.h"
2023-02-01 22:13:04 +01:00
#include "Asset/AssetRegistry.h"
#include "Asset/TextureAsset.h"
2023-02-13 14:56:13 +01:00
#include "Asset/MaterialAsset.h"
2023-03-09 17:39:57 +01:00
#include "Component/PointLight.h"
#include "Component/DirectionalLight.h"
#include "Actor/PointLightActor.h"
2020-05-05 01:51:13 +02:00
using namespace Seele;
2020-09-19 14:36:50 +02:00
Scene::Scene(Gfx::PGraphics graphics)
: graphics(graphics)
2023-01-21 18:43:21 +01:00
, physics(registry)
2020-05-05 01:51:13 +02:00
{
2023-08-28 21:23:13 +02:00
ShaderBufferCreateInfo structInfo = {
2023-02-27 13:52:57 +01:00
.resourceData = {
2023-03-09 17:39:57 +01:00
.size = sizeof(Component::DirectionalLight) * MAX_DIRECTIONAL_LIGHTS,
2023-02-27 13:52:57 +01:00
.data = nullptr,
},
2023-03-09 17:39:57 +01:00
.stride = sizeof(Component::DirectionalLight),
2023-02-27 13:52:57 +01:00
.bDynamic = true,
};
2023-08-28 21:23:13 +02:00
lightEnv.directionalLights = graphics->createShaderBuffer(structInfo);
2023-03-09 17:39:57 +01:00
structInfo.resourceData.size = sizeof(Component::PointLight) * MAX_POINT_LIGHTS;
structInfo.stride = sizeof(Component::PointLight);
2023-08-28 21:23:13 +02:00
lightEnv.pointLights = graphics->createShaderBuffer(structInfo);
2023-02-27 13:52:57 +01:00
UniformBufferCreateInfo uniformInfo = {
.resourceData = {
.size = sizeof(uint32),
.data = nullptr
},
.bDynamic = true
};
lightEnv.numDirectional = graphics->createUniformBuffer(uniformInfo);
lightEnv.numPoints = graphics->createUniformBuffer(uniformInfo);
2020-05-05 01:51:13 +02:00
}
Scene::~Scene()
{
}
2023-01-21 18:43:21 +01:00
void Scene::update(float deltaTime)
2020-05-05 01:51:13 +02:00
{
2023-01-21 18:43:21 +01:00
physics.update(deltaTime);
2020-05-05 01:51:13 +02:00
}
2023-03-07 21:25:56 +01:00
LightEnv Scene::getLightBuffer()
2020-05-05 01:51:13 +02:00
{
2023-03-09 17:39:57 +01:00
StaticArray<Component::DirectionalLight, MAX_DIRECTIONAL_LIGHTS> dirLights;
uint32 numDirLights = 0;
for(auto&& [entity, light] : registry.view<Component::DirectionalLight>().each())
2023-03-07 21:25:56 +01:00
{
dirLights[numDirLights++] = light;
}
lightEnv.directionalLights->updateContents({
2023-03-09 17:39:57 +01:00
.size = sizeof(Component::DirectionalLight) * numDirLights,
2023-03-07 21:25:56 +01:00
.data = (uint8*)dirLights.data(),
});
lightEnv.numDirectional->updateContents({
.size = sizeof(uint32),
.data = (uint8*)&numDirLights,
});
2023-03-09 17:39:57 +01:00
StaticArray<Component::PointLight, MAX_POINT_LIGHTS> pointLights;
uint32 numPointLights = 0;
for(auto&& [entity, light] : registry.view<Component::PointLight>().each())
2023-03-07 21:25:56 +01:00
{
pointLights[numPointLights++] = light;
}
lightEnv.pointLights->updateContents({
2023-03-09 17:39:57 +01:00
.size = sizeof(Component::PointLight) * numPointLights,
2023-03-07 21:25:56 +01:00
.data = (uint8*)pointLights.data(),
});
lightEnv.numPoints->updateContents({
.size = sizeof(uint32),
.data = (uint8*)&numPointLights,
});
return lightEnv;
2023-02-01 22:13:04 +01:00
}
2023-02-24 22:09:07 +01:00
2023-02-01 22:13:04 +01:00
Component::Skybox Scene::getSkybox()
{
return Seele::Component::Skybox {
.day = AssetRegistry::findTexture("FS000_Day_01")->getTexture().cast<Gfx::TextureCube>(),
.night = AssetRegistry::findTexture("FS000_Night_01")->getTexture().cast<Gfx::TextureCube>(),
.fogColor = Vector(0.2, 0.1, 0.6),
.blendFactor = 0,
};
}