adding directional light actor
This commit is contained in:
@@ -4,12 +4,18 @@ target_sources(Engine
|
||||
Actor.h
|
||||
CameraActor.cpp
|
||||
CameraActor.h
|
||||
DirectionalLightActor.cpp
|
||||
DirectionalLightActor.h
|
||||
Entity.cpp
|
||||
Entity.h)
|
||||
Entity.h
|
||||
PointLightActor.cpp
|
||||
PointLightActor.h)
|
||||
|
||||
target_sources(Engine
|
||||
PUBLIC FILE_SET HEADERS
|
||||
FILES
|
||||
Actor.h
|
||||
CameraActor.h
|
||||
Entity.h)
|
||||
DirectionalLightActor.h
|
||||
Entity.h
|
||||
PointLightActor.h)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "DirectionalLightActor.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
DirectionalLightActor::DirectionalLightActor(PScene scene)
|
||||
: Actor(scene)
|
||||
{
|
||||
attachComponent<Component::DirectionalLight>();
|
||||
}
|
||||
|
||||
DirectionalLightActor::~DirectionalLightActor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Component::DirectionalLight& DirectionalLightActor::getDirectionalLightComponent()
|
||||
{
|
||||
return accessComponent<Component::DirectionalLight>();
|
||||
}
|
||||
|
||||
const Component::DirectionalLight& DirectionalLightActor::getDirectionalLightComponent() const
|
||||
{
|
||||
return accessComponent<Component::DirectionalLight>();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "Actor.h"
|
||||
#include "Component/DirectionalLight.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class DirectionalLightActor : public Actor
|
||||
{
|
||||
public:
|
||||
DirectionalLightActor(PScene scene);
|
||||
virtual ~DirectionalLightActor();
|
||||
Component::DirectionalLight& getDirectionalLightComponent();
|
||||
const Component::DirectionalLight& getDirectionalLightComponent() const;
|
||||
private:
|
||||
};
|
||||
DEFINE_REF(DirectionalLightActor)
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "PointLightActor.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
PointLightActor::PointLightActor(PScene scene)
|
||||
: Actor(scene)
|
||||
{
|
||||
attachComponent<Component::PointLight>();
|
||||
}
|
||||
|
||||
PointLightActor::~PointLightActor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Component::PointLight& PointLightActor::getPointLightComponent()
|
||||
{
|
||||
return accessComponent<Component::PointLight>();
|
||||
}
|
||||
|
||||
const Component::PointLight& PointLightActor::getPointLightComponent() const
|
||||
{
|
||||
return accessComponent<Component::PointLight>();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "Actor.h"
|
||||
#include "Component/PointLight.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class PointLightActor : public Actor
|
||||
{
|
||||
public:
|
||||
PointLightActor(PScene scene);
|
||||
virtual ~PointLightActor();
|
||||
Component::PointLight& getPointLightComponent();
|
||||
const Component::PointLight& getPointLightComponent() const;
|
||||
private:
|
||||
};
|
||||
DEFINE_REF(PointLightActor)
|
||||
} // namespace Seele
|
||||
@@ -7,8 +7,10 @@ target_sources(Engine
|
||||
Collider.h
|
||||
Collider.cpp
|
||||
Component.h
|
||||
DirectionalLight.h
|
||||
KeyboardInput.h
|
||||
MeshCollider.h
|
||||
PointLight.h
|
||||
RigidBody.h
|
||||
ShapeBase.h
|
||||
ShapeBase.cpp
|
||||
@@ -27,8 +29,10 @@ target_sources(Engine
|
||||
Camera.h
|
||||
Collider.h
|
||||
Component.h
|
||||
DirectionalLight.h
|
||||
KeyboardInput.h
|
||||
MeshCollider.h
|
||||
PointLight.h
|
||||
RigidBody.h
|
||||
ShapeBase.h
|
||||
Skybox.h
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "Math/Vector.h"
|
||||
namespace Seele
|
||||
{
|
||||
namespace Component
|
||||
{
|
||||
struct DirectionalLight
|
||||
{
|
||||
Vector4 color;
|
||||
Vector4 direction;
|
||||
};
|
||||
} // namespace Component
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "Math/Vector.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Component
|
||||
{
|
||||
struct PointLight
|
||||
{
|
||||
Vector4 positionWS;
|
||||
//Vector4 positionVS;
|
||||
Vector4 colorRange;
|
||||
};
|
||||
} // namespace Component
|
||||
} // namespace Seele
|
||||
@@ -154,10 +154,10 @@ void BasePass::render()
|
||||
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(0, directLightBuffer);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(1, numDirLightBuffer);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(2, pointLightBuffer);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(3, numPointLightBuffer);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(0, passData.lightEnv.directionalLights);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(1, passData.lightEnv.numDirectional);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(2, passData.lightEnv.pointLights);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(3, passData.lightEnv.numPoints);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(4, oLightIndexList);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->updateTexture(5, oLightGrid);
|
||||
descriptorSets[INDEX_LIGHT_ENV]->writeChanges();
|
||||
@@ -186,11 +186,7 @@ void BasePass::publishOutputs()
|
||||
}
|
||||
|
||||
void BasePass::createRenderPass()
|
||||
{
|
||||
directLightBuffer = resources->requestBuffer("DIRECTIONAL_LIGHTS");
|
||||
pointLightBuffer = resources->requestBuffer("POINT_LIGHTS");
|
||||
numDirLightBuffer = resources->requestUniform("NUM_DIRECTIONAL_LIGHTS");
|
||||
numPointLightBuffer = resources->requestUniform("NUM_POINT_LIGHTS");
|
||||
{
|
||||
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
|
||||
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
|
||||
colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
|
||||
@@ -30,6 +30,7 @@ struct BasePassData
|
||||
{
|
||||
Array<MeshBatch> staticDrawList;
|
||||
Gfx::PStructuredBuffer sceneDataBuffer;
|
||||
LightEnv lightEnv;
|
||||
};
|
||||
class BasePass : public RenderPass<BasePassData>
|
||||
{
|
||||
@@ -54,10 +55,6 @@ private:
|
||||
Gfx::PPipelineLayout basePassLayout;
|
||||
// Set 0: Light environment
|
||||
static constexpr uint32 INDEX_LIGHT_ENV = 0;
|
||||
Gfx::PStructuredBuffer directLightBuffer;
|
||||
Gfx::PUniformBuffer numDirLightBuffer;
|
||||
Gfx::PStructuredBuffer pointLightBuffer;
|
||||
Gfx::PUniformBuffer numPointLightBuffer;
|
||||
Gfx::PStructuredBuffer oLightIndexList;
|
||||
Gfx::PTexture oLightGrid;
|
||||
Gfx::PDescriptorLayout lightLayout;
|
||||
|
||||
@@ -188,11 +188,6 @@ void LightCullingPass::publishOutputs()
|
||||
resources->registerBufferOutput("LIGHTCULLING_OLIGHTLIST", oLightIndexList);
|
||||
resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList);
|
||||
|
||||
resources->registerBufferOutput("DIRECTIONAL_LIGHTS", passData.lightEnv.directionalLights);
|
||||
resources->registerUniformOutput("NUM_DIRECTIONAL_LIGHTS", passData.lightEnv.numDirectional);
|
||||
resources->registerBufferOutput("POINT_LIGHTS", passData.lightEnv.pointLights);
|
||||
resources->registerUniformOutput("NUM_POINT_LIGHTS", passData.lightEnv.numPoints);
|
||||
|
||||
TextureCreateInfo textureInfo = {
|
||||
.width = dispatchParams.numThreadGroups.x,
|
||||
.height = dispatchParams.numThreadGroups.y,
|
||||
|
||||
+15
-17
@@ -6,14 +6,12 @@
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/TextureAsset.h"
|
||||
#include "Asset/MaterialAsset.h"
|
||||
#include "Component/PointLight.h"
|
||||
#include "Component/DirectionalLight.h"
|
||||
#include "Actor/PointLightActor.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
inline float frand()
|
||||
{
|
||||
return (float)rand()/RAND_MAX;
|
||||
}
|
||||
|
||||
Scene::Scene(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
, physics(registry)
|
||||
@@ -21,14 +19,15 @@ Scene::Scene(Gfx::PGraphics graphics)
|
||||
|
||||
StructuredBufferCreateInfo structInfo = {
|
||||
.resourceData = {
|
||||
.size = sizeof(DirectionalLight) * MAX_DIRECTIONAL_LIGHTS,
|
||||
.size = sizeof(Component::DirectionalLight) * MAX_DIRECTIONAL_LIGHTS,
|
||||
.data = nullptr,
|
||||
},
|
||||
.stride = sizeof(DirectionalLight),
|
||||
.stride = sizeof(Component::DirectionalLight),
|
||||
.bDynamic = true,
|
||||
};
|
||||
lightEnv.directionalLights = graphics->createStructuredBuffer(structInfo);
|
||||
structInfo.resourceData.size = sizeof(PointLight) * MAX_POINT_LIGHTS;
|
||||
structInfo.resourceData.size = sizeof(Component::PointLight) * MAX_POINT_LIGHTS;
|
||||
structInfo.stride = sizeof(Component::PointLight);
|
||||
lightEnv.pointLights = graphics->createStructuredBuffer(structInfo);
|
||||
|
||||
UniformBufferCreateInfo uniformInfo = {
|
||||
@@ -40,7 +39,6 @@ Scene::Scene(Gfx::PGraphics graphics)
|
||||
};
|
||||
lightEnv.numDirectional = graphics->createUniformBuffer(uniformInfo);
|
||||
lightEnv.numPoints = graphics->createUniformBuffer(uniformInfo);
|
||||
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
@@ -107,28 +105,28 @@ Array<MeshBatch> Scene::getStaticMeshes()
|
||||
|
||||
LightEnv Scene::getLightBuffer()
|
||||
{
|
||||
StaticArray<DirectionalLight, MAX_DIRECTIONAL_LIGHTS> dirLights;
|
||||
uint32 numDirLights;
|
||||
for(auto&& [entity, light] : registry.view<DirectionalLight>().each())
|
||||
StaticArray<Component::DirectionalLight, MAX_DIRECTIONAL_LIGHTS> dirLights;
|
||||
uint32 numDirLights = 0;
|
||||
for(auto&& [entity, light] : registry.view<Component::DirectionalLight>().each())
|
||||
{
|
||||
dirLights[numDirLights++] = light;
|
||||
}
|
||||
lightEnv.directionalLights->updateContents({
|
||||
.size = sizeof(DirectionalLight) * numDirLights,
|
||||
.size = sizeof(Component::DirectionalLight) * numDirLights,
|
||||
.data = (uint8*)dirLights.data(),
|
||||
});
|
||||
lightEnv.numDirectional->updateContents({
|
||||
.size = sizeof(uint32),
|
||||
.data = (uint8*)&numDirLights,
|
||||
});
|
||||
StaticArray<PointLight, MAX_POINT_LIGHTS> pointLights;
|
||||
uint32 numPointLights;
|
||||
for(auto&& [entity, light] : registry.view<PointLight>().each())
|
||||
StaticArray<Component::PointLight, MAX_POINT_LIGHTS> pointLights;
|
||||
uint32 numPointLights = 0;
|
||||
for(auto&& [entity, light] : registry.view<Component::PointLight>().each())
|
||||
{
|
||||
pointLights[numPointLights++] = light;
|
||||
}
|
||||
lightEnv.pointLights->updateContents({
|
||||
.size = sizeof(PointLight) * numPointLights,
|
||||
.size = sizeof(Component::PointLight) * numPointLights,
|
||||
.data = (uint8*)pointLights.data(),
|
||||
});
|
||||
lightEnv.numPoints->updateContents({
|
||||
|
||||
@@ -11,19 +11,6 @@ namespace Seele
|
||||
DECLARE_REF(Material)
|
||||
DECLARE_REF(Entity)
|
||||
|
||||
struct DirectionalLight
|
||||
{
|
||||
Vector4 color;
|
||||
Vector4 direction;
|
||||
};
|
||||
|
||||
struct PointLight
|
||||
{
|
||||
Vector4 positionWS;
|
||||
//Vector4 positionVS;
|
||||
Vector4 colorRange;
|
||||
};
|
||||
|
||||
#define MAX_DIRECTIONAL_LIGHTS 4
|
||||
#define MAX_POINT_LIGHTS 256
|
||||
struct LightEnv
|
||||
|
||||
@@ -54,6 +54,7 @@ void GameView::commitUpdate()
|
||||
lightCullingData.lightEnv = scene->getLightBuffer();
|
||||
basePassData.staticDrawList = scene->getStaticMeshes();
|
||||
basePassData.sceneDataBuffer = scene->getSceneDataBuffer();
|
||||
basePassData.lightEnv = scene->getLightBuffer();
|
||||
skyboxData.skybox = scene->getSkybox();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user