Skip to content

Commit

Permalink
Merge pull request #73 from KTStephano/v0.10
Browse files Browse the repository at this point in the history
V0.10
  • Loading branch information
KTStephano authored Aug 2, 2023
2 parents d507bf7 + 1a8736e commit 4f911ce
Show file tree
Hide file tree
Showing 25 changed files with 678 additions and 273 deletions.
11 changes: 11 additions & 0 deletions Examples/Common/LightControllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static void InitCube(const LightParams& p,
auto rc = cube->Components().GetComponent<stratus::RenderComponent>().component;
auto local = cube->Components().GetComponent<stratus::LocalTransformComponent>().component;
cube->Components().DisableComponent<stratus::LightInteractionComponent>();
//cube->Components().DisableComponent<stratus::StaticObjectComponent>();
local->SetLocalScale(glm::vec3(0.25f));
local->SetLocalPosition(p.position);
float multiplier = 1.0f;
Expand Down Expand Up @@ -187,6 +188,16 @@ static bool EntityIsRelevant(const stratus::EntityPtr& entity) {
}

void LightProcess::Process(const double deltaSeconds) {
// const auto& lights = ConvertHandlerToLightDelete(input)->entities;
// for (const auto& light : lights) {
// auto ptr = stratus::GetComponent<LightComponent>(light)->light;
// if (!ptr->IsVirtualLight()) continue;
// auto cube = stratus::GetComponent<LightCubeComponent>(light);
// if (cube) {
// stratus::GetComponent<stratus::LocalTransformComponent>(cube->cube)->SetLocalPosition(ptr->GetPosition());
// }
// }

if (ConvertHandlerToLightDelete(input)->printLights) {
ConvertHandlerToLightDelete(input)->printLights = false;
const auto& lights = ConvertHandlerToLightDelete(input)->entities;
Expand Down
2 changes: 1 addition & 1 deletion Examples/ExampleEnv02/Sponza.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Sponza : public stratus::Application {
received.clear();
int spawned = 0;
for (int x = 60; x > -30; x -= 10) {
for (int y = 15; y < 240; y += 20) {
for (int y = 0; y < 240; y += 20) {
for (int z = -140; z < 180; z += 20) {
++spawned;
LightCreator::CreateVirtualPointLight(
Expand Down
2 changes: 1 addition & 1 deletion Examples/ExampleEnv04/SanMiguel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class SanMiguel : public stratus::Application {
int spawned = 0;

for (int x = 40; x < 240; x += 10) {
for (int y = 5; y < 150; y += 20) {
for (int y = 0; y < 150; y += 20) {
for (int z = -30; z < 120; z += 20) {
++spawned;
LightCreator::CreateVirtualPointLight(
Expand Down
12 changes: 6 additions & 6 deletions Examples/ExampleEnv05/Bistro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
static void setupDayTime() {
int spawned = 0;
for (int x = -150; x < 200; x += 50) {
for (int y = 10; y < 150; y += 20) {
for (int y = 0; y < 150; y += 20) {
for (int z = -400; z < -50; z += 50) {
++spawned;
LightCreator::CreateVirtualPointLight(
Expand All @@ -37,7 +37,7 @@ static void setupDayTime() {
}

for (int x = -200; x < 95; x += 30) {
for (int y = 10; y < 150; y += 15) {
for (int y = 0; y < 150; y += 15) {
for (int z = -50; z < 200; z += 30) {
++spawned;
LightCreator::CreateVirtualPointLight(
Expand All @@ -49,7 +49,7 @@ static void setupDayTime() {
}

for (int x = 300; x < 555; x += 30) {
for (int y = 10; y < 50; y += 10) {
for (int y = 0; y < 50; y += 10) {
for (int z = 150; z < 400; z += 30) {
++spawned;
LightCreator::CreateVirtualPointLight(
Expand All @@ -61,7 +61,7 @@ static void setupDayTime() {
}

for (int x = 180; x < 310; x += 30) {
for (int y = 10; y < 160; y += 10) {
for (int y = 0; y < 160; y += 10) {
for (int z = 100; z < 265; z += 30) {
++spawned;
LightCreator::CreateVirtualPointLight(
Expand All @@ -73,7 +73,7 @@ static void setupDayTime() {
}

for (int x = 240; x < 340; x += 30) {
for (int y = 10; y < 160; y += 10) {
for (int y = 0; y < 160; y += 10) {
for (int z = 130; z < 180; z += 30) {
++spawned;
LightCreator::CreateVirtualPointLight(
Expand All @@ -85,7 +85,7 @@ static void setupDayTime() {
}

for (int x = -270; x < -160; x += 30) {
for (int y = 10; y < 160; y += 10) {
for (int y = 0; y < 160; y += 10) {
++spawned;
LightCreator::CreateVirtualPointLight(
LightParams(glm::vec3(float(x), float(y), -250.0f), glm::vec3(1.0f), 1.0f),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Because of the MPL license, any community changes made to the rendering code wil

# Downloading Sample 3D Model Data

1) A zip file containing Sponza, Interrogation Room, San Miguel, Bistro, Bathroom, etc. can be found here: [https://drive.google.com/file/d/1m56T8cWMwAOHTAIbxAn-891trehgJpzH/view?usp=drive_link](https://drive.google.com/file/d/1m56T8cWMwAOHTAIbxAn-891trehgJpzH/view?usp=drive_link)
1) A zip file containing Sponza, Interrogation Room, San Miguel, Bistro, Bathroom, etc. can be found here: [https://drive.google.com/file/d/1nVkEuhDaSK61XmTSoNOUUEU5a-U-mtKO/view?usp=share_link](https://drive.google.com/file/d/1nVkEuhDaSK61XmTSoNOUUEU5a-U-mtKO/view?usp=share_link)

2) Extract the Resources.zip folder into the root of StratusGFX. It will then be at the same level as Bin/, Examples/, Source/, Tests/. Make sure that the folder structure looks like StratusGFX/Resources/* where * will be folders such as Sponza, Bistro, etc.

Expand Down
7 changes: 7 additions & 0 deletions Source/Engine/StratusGpuCommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace stratus {

visibleCommands_ = GpuTypedBuffer<GpuDrawElementsIndirectCommand>::Create(commandBlockSize, true);
selectedLodCommands_ = GpuTypedBuffer<GpuDrawElementsIndirectCommand>::Create(commandBlockSize, true);
visibleLowestLodCommands_ = GpuTypedBuffer<GpuDrawElementsIndirectCommand>::Create(commandBlockSize, true);
prevFrameModelTransforms_ = GpuTypedBuffer<glm::mat4>::Create(commandBlockSize, true);
modelTransforms_ = GpuTypedBuffer<glm::mat4>::Create(commandBlockSize, true);
aabbs_ = GpuTypedBuffer<GpuAABB>::Create(commandBlockSize, true);
Expand Down Expand Up @@ -67,6 +68,7 @@ namespace stratus {
// Record the lod commands
visibleCommands_->Add(GpuDrawElementsIndirectCommand());
selectedLodCommands_->Add(GpuDrawElementsIndirectCommand());
visibleLowestLodCommands_->Add(GpuDrawElementsIndirectCommand());

for (size_t lod = 0; lod < NumLods(); ++lod) {
GpuDrawElementsIndirectCommand command;
Expand Down Expand Up @@ -104,6 +106,7 @@ namespace stratus {
// Remove top level data
visibleCommands_->Remove(index);
selectedLodCommands_->Remove(index);
visibleLowestLodCommands_->Remove(index);
prevFrameModelTransforms_->Remove(index);
modelTransforms_->Remove(index);
aabbs_->Remove(index);
Expand Down Expand Up @@ -276,6 +279,10 @@ namespace stratus {
return selectedLodCommands_->GetBuffer();
}

GpuBuffer GpuCommandBuffer2::GetVisibleLowestLodDrawCommandsBuffer() const {
return visibleLowestLodCommands_->GetBuffer();
}

bool GpuCommandBuffer2::InsertMeshPending_(RenderComponent* component, MeshPtr mesh)
{
if (!mesh->IsFinalized()) {
Expand Down
2 changes: 2 additions & 0 deletions Source/Engine/StratusGpuCommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace stratus {
GpuBuffer GetIndirectDrawCommandsBuffer(const size_t lod) const;
GpuBuffer GetVisibleDrawCommandsBuffer() const;
GpuBuffer GetSelectedLodDrawCommandsBuffer() const;
GpuBuffer GetVisibleLowestLodDrawCommandsBuffer() const;

static inline GpuCommandBuffer2Ptr Create(const RenderFaceCulling& cull, const size_t numLods, const size_t commandBlockSize) {
return GpuCommandBuffer2Ptr(new GpuCommandBuffer2(cull, numLods, commandBlockSize));
Expand All @@ -62,6 +63,7 @@ namespace stratus {
std::vector<GpuTypedBufferPtr<GpuDrawElementsIndirectCommand>> drawCommands_;
GpuTypedBufferPtr<GpuDrawElementsIndirectCommand> visibleCommands_;
GpuTypedBufferPtr<GpuDrawElementsIndirectCommand> selectedLodCommands_;
GpuTypedBufferPtr<GpuDrawElementsIndirectCommand> visibleLowestLodCommands_;
GpuTypedBufferPtr<glm::mat4> prevFrameModelTransforms_;
GpuTypedBufferPtr<glm::mat4> modelTransforms_;
GpuTypedBufferPtr<GpuAABB> aabbs_;
Expand Down
6 changes: 3 additions & 3 deletions Source/Engine/StratusGpuCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Synchronized with definitions in pbr.glsl
#define MAX_TOTAL_SHADOW_ATLASES (14)
#define MAX_TOTAL_SHADOWS_PER_ATLAS (300)
#define MAX_TOTAL_SHADOWS_PER_ATLAS (320)
#define MAX_TOTAL_SHADOW_MAPS (MAX_TOTAL_SHADOW_ATLASES * MAX_TOTAL_SHADOWS_PER_ATLAS)

// Once a VPL is further than this distance away it is automatically culled
Expand All @@ -31,7 +31,7 @@
#define GPU_METALLIC_ROUGHNESS_MAPPED (BITMASK_POW2(7))

// Matches the definitions in vpl_common.glsl
#define MAX_TOTAL_VPLS_BEFORE_CULLING (8192)
#define MAX_TOTAL_VPLS_BEFORE_CULLING (10000)
#define MAX_TOTAL_VPLS_PER_FRAME (MAX_TOTAL_SHADOW_MAPS)
#define MAX_VPLS_PER_TILE (12)

Expand Down Expand Up @@ -217,7 +217,7 @@ namespace stratus {
struct PACKED_STRUCT_ATTRIBUTE GpuVplData {
GpuVec position;
GpuVec color;
GpuVec placeholder1_;
GpuVec specularPosition;
float radius;
float farPlane;
float intensity;
Expand Down
50 changes: 50 additions & 0 deletions Source/Engine/StratusMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string>
#include <limits>
#include <random>
#include "StratusGpuCommon.h"

#define STRATUS_PI 3.14159265358979323846

Expand Down Expand Up @@ -361,6 +362,55 @@ namespace stratus {
return result;
}

template<typename Array>
bool IsAabbInFrustum(const GpuAABB& aabb, const Array& frustumPlanes) {
const glm::vec4& vmin = aabb.vmin;
const glm::vec4& vmax = aabb.vmax;

for (int i = 0; i < 6; ++i) {
const glm::vec4& g = frustumPlanes[i];
if ((glm::dot(g, glm::vec4(vmin.x, vmin.y, vmin.z, 1.0f)) < 0.0) &&
(glm::dot(g, glm::vec4(vmax.x, vmin.y, vmin.z, 1.0f)) < 0.0) &&
(glm::dot(g, glm::vec4(vmin.x, vmax.y, vmin.z, 1.0f)) < 0.0) &&
(glm::dot(g, glm::vec4(vmax.x, vmax.y, vmin.z, 1.0f)) < 0.0) &&
(glm::dot(g, glm::vec4(vmin.x, vmin.y, vmax.z, 1.0f)) < 0.0) &&
(glm::dot(g, glm::vec4(vmax.x, vmin.y, vmax.z, 1.0f)) < 0.0) &&
(glm::dot(g, glm::vec4(vmin.x, vmax.y, vmax.z, 1.0f)) < 0.0) &&
(glm::dot(g, glm::vec4(vmax.x, vmax.y, vmax.z, 1.0f)) < 0.0))
{
return false;
}
}

return true;
}

template<typename Array>
bool IsPointInFrustum(const glm::vec3& point, const Array& frustumPlanes) {
for (int i = 0; i < 6; ++i) {
const glm::vec4& g = frustumPlanes[i];
if (glm::dot(g, glm::vec4(point, 1.0f)) < 0.0) {
return false;
}
}

return true;
}

template<typename Array>
bool IsSphereInFrustum(const glm::vec3& center, const float radius, const Array& frustumPlanes) {
for (int i = 0; i < 6; ++i) {
const glm::vec4& g = frustumPlanes[i];
const float distance = glm::dot(g, glm::vec4(center, 1.0f));

if (distance < -radius) {
return false;
}
}

return true;
}

// These are the first 512 values of the Halton sequence. For more information see:
// https://en.wikipedia.org/wiki/Halton_sequence
// https://www.pbr-book.org/3ed-2018/Sampling_and_Reconstruction/The_Halton_Sampler
Expand Down
10 changes: 10 additions & 0 deletions Source/Engine/StratusRenderComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ namespace stratus {
if (size < 1024) break;
}

// One last lod computed more aggressively than the previous ones
auto& prevIndices = cpuData_->indicesPerLod[0];
std::vector<uint32_t> simplified(prevIndices.size());
const size_t targetIndices = std::min<size_t>(prevIndices.size(), 1024);
auto size = meshopt_simplify(simplified.data(), prevIndices.data(), prevIndices.size(), &cpuData_->vertices[0][0], numVertices_, sizeof(float) * 3, targetIndices, 0.8f);
simplified.resize(size);
meshopt_optimizeVertexCache(simplified.data(), simplified.data(), size, numVertices_);
cpuData_->indicesPerLod.push_back(std::move(simplified));
numIndicesPerLod_.push_back(size);

meshopt_optimizeVertexCache(cpuData_->indices.data(), cpuData_->indices.data(), cpuData_->indices.size(), cpuData_->vertices.size());
cpuData_->indicesPerLod[0] = cpuData_->indices;
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Engine/StratusRenderComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ namespace stratus {
uint32_t vertexOffset_; // Into global GpuBuffer
std::vector<uint32_t> numIndicesPerLod_;
std::vector<uint32_t> indexOffsetPerLod_; // Into global GpuBuffer
uint32_t numIndicesApproximateLod_;

RenderFaceCulling cullMode_ = RenderFaceCulling::CULLING_CCW;
};

Expand Down
Loading

0 comments on commit 4f911ce

Please sign in to comment.