Skip to content

Commit

Permalink
Merge pull request #69 from hotstreams/feature/frustum_culling
Browse files Browse the repository at this point in the history
Feature/frustum culling
  • Loading branch information
hotstreams authored Aug 27, 2024
2 parents 0976ea3 + 8e8ca63 commit 244232c
Show file tree
Hide file tree
Showing 162 changed files with 2,276 additions and 2,069 deletions.
55 changes: 24 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ set(ENGINE_UTIL
src/limitless/util/sorter.cpp
src/limitless/util/renderer_helper.cpp
src/limitless/util/color_picker.cpp
src/limitless/util/frustum.cpp
)

set(ENGINE_MS
Expand Down Expand Up @@ -157,39 +158,31 @@ set(ENGINE_FX
src/limitless/fx/effect_shader_define_replacer.cpp
)

set(ENGINE_PIPELINE
src/limitless/pipeline/pipeline.cpp
src/limitless/pipeline/pipeline_pass.cpp
src/limitless/pipeline/forward/color_pass.cpp
src/limitless/pipeline/forward/particle_pass.cpp
src/limitless/pipeline/forward/framebuffer_pass.cpp
src/limitless/pipeline/common/shadow_pass.cpp
src/limitless/pipeline/common/sceneupdate_pass.cpp
src/limitless/pipeline/common/skybox_pass.cpp
src/limitless/pipeline/forward/postprocessing_pass.cpp
src/limitless/pipeline/forward/forward.cpp
src/limitless/pipeline/forward/postprocessing.cpp
set(ENGINE_RENDERER
src/limitless/renderer/renderer_pass.cpp
src/limitless/renderer/shadow_pass.cpp
src/limitless/renderer/sceneupdate_pass.cpp
src/limitless/renderer/skybox_pass.cpp
src/limitless/renderer/renderer.cpp
src/limitless/renderer/instance_renderer.cpp
src/limitless/renderer/render_settings_shader_definer.cpp
src/limitless/renderer/renderer_settings.cpp
src/limitless/pipeline/common/scene_data.cpp
src/limitless/pipeline/deferred/effectupdate_pass.cpp
src/limitless/pipeline/deferred/deferred_framebuffer_pass.cpp
src/limitless/pipeline/deferred/gbuffer_pass.cpp
src/limitless/pipeline/deferred/deferred_lighting_pass.cpp
src/limitless/pipeline/deferred/deferred.cpp
src/limitless/pipeline/deferred/depth_pass.cpp
src/limitless/pipeline/deferred/translucent_pass.cpp
src/limitless/pipeline/common/bloom_pass.cpp
src/limitless/pipeline/deferred/composite_pass.cpp
src/limitless/pipeline/common/ssao_pass.cpp
src/limitless/pipeline/common/fxaa_pass.cpp
src/limitless/pipeline/common/quad_pass.cpp
src/limitless/pipeline/common/render_debug_pass.cpp
src/limitless/pipeline/common/dof_pass.cpp
src/limitless/pipeline/common/outline_pass.cpp
src/limitless/pipeline/common/ssr_pass.cpp
src/limitless/pipeline/deferred/decal_pass.cpp
src/limitless/renderer/scene_data.cpp
src/limitless/renderer/deferred_framebuffer_pass.cpp
src/limitless/renderer/gbuffer_pass.cpp
src/limitless/renderer/deferred_lighting_pass.cpp
src/limitless/renderer/depth_pass.cpp
src/limitless/renderer/translucent_pass.cpp
src/limitless/renderer/bloom_pass.cpp
src/limitless/renderer/composite_pass.cpp
# src/limitless/pipeline/common/ssao_pass.cpp
# src/limitless/pipeline/common/fxaa_pass.cpp
src/limitless/renderer/screen_pass.cpp
src/limitless/renderer/render_debug_pass.cpp
# src/limitless/pipeline/common/dof_pass.cpp
src/limitless/renderer/outline_pass.cpp
# src/limitless/pipeline/common/ssr_pass.cpp
src/limitless/renderer/decal_pass.cpp
src/limitless/postprocessing/blur.cpp
src/limitless/postprocessing/bloom.cpp
src/limitless/postprocessing/ssao.cpp
Expand All @@ -207,7 +200,7 @@ set(ENGINE_SRC
${ENGINE_MODELS}
${ENGINE_UTIL}
${ENGINE_TEXT}
${ENGINE_PIPELINE}
${ENGINE_RENDERER}

src/limitless/camera.cpp
src/limitless/shader_storage.cpp
Expand Down
14 changes: 14 additions & 0 deletions include/limitless/core/vertex_stream_visitor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace Limitless {
class ExtensionTexture;
class BindlessTexture;

class VertexStreamVisitor {
public:
virtual void visit(VertexStream& texture) noexcept = 0;
virtual void visit(ExtensionTexture& texture) noexcept = 0;

virtual ~VertexStreamVisitor() = default;
};
}
3 changes: 1 addition & 2 deletions include/limitless/fx/effect_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Limitless {
class Context;
class Assets;

using Instances = std::vector<std::reference_wrapper<Instance>>;
using Instances = std::vector<std::shared_ptr<Instance>>;

namespace ms {
enum class Blending;
Expand All @@ -29,7 +29,6 @@ namespace Limitless::fx {
void updateRenderers(const Instances& instances) noexcept;
static void visitEmitters(const Instances& instances, EmitterVisitor& visitor) noexcept;
public:
explicit EffectRenderer(Context& context) noexcept;
~EffectRenderer() = default;

void update(const Instances& instances);
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/emitters/abstract_emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Limitless::fx {
virtual void ressurect() noexcept = 0;

[[nodiscard]] virtual AbstractEmitter* clone() const = 0;
virtual void update(Context& ctx, const Camera& camera) = 0;
virtual void update(const Camera &camera) = 0;
virtual void accept(EmitterVisitor& visitor) noexcept = 0;

virtual bool& getLocalSpace() noexcept = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/emitters/emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace Limitless::fx {
[[nodiscard]] UniqueEmitterRenderer getUniqueRendererType() const noexcept override { return { type, std::nullopt, nullptr }; }

[[nodiscard]] Emitter* clone() const override;
void update(Context& ctx, const Camera& camera) override;
void update(const Camera &camera) override;
void accept(EmitterVisitor& visitor) noexcept override;

bool& getLocalSpace() noexcept override;
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/emitters/mesh_emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Limitless::fx {

[[nodiscard]] MeshEmitter* clone() const override;

void update(Context& context, const Camera& camera) override;
void update(const Camera &camera) override;
void accept(EmitterVisitor& visitor) noexcept override;
};
}
2 changes: 1 addition & 1 deletion include/limitless/fx/emitters/unique_emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <memory>
#include <set>
#include <limitless/pipeline/shader_type.hpp>
#include <limitless/renderer/shader_type.hpp>
#include <optional>

namespace Limitless::ms {
Expand Down
9 changes: 5 additions & 4 deletions include/limitless/fx/modules/beam_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ namespace Limitless::fx {
private:
std::vector<BeamParticleMapping> beam_particles;

void generate(BeamParticle& particle, Context& ctx, const Camera& camera) {
void generate(BeamParticle& particle, const Camera& camera) {
constexpr auto DOT_PRODUCT_RANGE = glm::vec2(0.2f, 0.8f);
const auto resolution = glm::vec2(ctx.getSize().x, ctx.getSize().y);
auto size = Context::getCurrentContext()->getSize();
const auto resolution = glm::vec2(size.x, size.y);
const auto& line = particle.derivative_line;

for (uint32_t i = 0; i < 6 * (line.size() - 2 - 1); ++i) {
Expand Down Expand Up @@ -143,7 +144,7 @@ namespace Limitless::fx {
return beam_particles;
}

void update([[maybe_unused]] AbstractEmitter& emitter, std::vector<Particle>& particles, [[maybe_unused]] float dt, Context& ctx, const Camera& camera) noexcept override {
void update([[maybe_unused]] AbstractEmitter &emitter, std::vector<Particle> &particles, [[maybe_unused]] float dt, const Camera &camera) noexcept override {
beam_particles.clear();

for (auto& particle : particles) {
Expand All @@ -169,7 +170,7 @@ namespace Limitless::fx {
particle.last_rebuild = current;
}

generate(particle, ctx, camera);
generate(particle, camera);
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/modules/beam_speed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Limitless::fx {
return new BeamSpeed(*this);
}

void update([[maybe_unused]] AbstractEmitter& emitter, std::vector<Particle>& particles, [[maybe_unused]] float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update([[maybe_unused]] AbstractEmitter &emitter, std::vector<Particle> &particles, [[maybe_unused]] float dt, [[maybe_unused]] const Camera &camera) noexcept override {
using namespace std::chrono;
for (auto& particle : particles) {
const auto current_time = steady_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/modules/color_by_life.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Limitless::fx {
: Module<Particle>(module.type)
, distribution {module.distribution->clone()} {}

void update([[maybe_unused]] AbstractEmitter& emitter, std::vector<Particle>& particles, float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update([[maybe_unused]] AbstractEmitter &emitter, std::vector<Particle> &particles, float dt, [[maybe_unused]] const Camera &camera) noexcept override {
for (auto& particle : particles) {
const auto tick = particle.lifetime / dt;
const auto tick_color = (distribution->get() - particle.color) / tick;
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/modules/custom_material_by_life.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Limitless::fx {
auto& getProperties() noexcept { return properties; }
const auto& getProperties() const noexcept { return properties; }

void update([[maybe_unused]] AbstractEmitter& emitter, std::vector<Particle>& particles, float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update([[maybe_unused]] AbstractEmitter &emitter, std::vector<Particle> &particles, float dt, [[maybe_unused]] const Camera &camera) noexcept override {
for (auto& particle : particles) {
for (size_t i = 0; i < properties.size(); ++i) {
if (properties[i]) {
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/modules/lifetime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Limitless::fx {
particle.lifetime = distribution->get();
}

void update([[maybe_unused]] AbstractEmitter& emitter, std::vector<Particle>& particles, float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update([[maybe_unused]] AbstractEmitter &emitter, std::vector<Particle> &particles, float dt, [[maybe_unused]] const Camera &camera) noexcept override {
for (auto& particle : particles) {
particle.lifetime -= dt;
}
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/modules/mesh_location_attachment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace Limitless::fx {
return new MeshLocationAttachment<Particle>(*this);
}

void update([[maybe_unused]] AbstractEmitter& emitter, std::vector<Particle>& particles, [[maybe_unused]] float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update([[maybe_unused]] AbstractEmitter &emitter, std::vector<Particle> &particles, [[maybe_unused]] float dt, [[maybe_unused]] const Camera &camera) noexcept override {
for (size_t i = 0; i < particles.size(); ++i) {
auto& [selected_mesh, vertex_index, triangle, last_position] = cache[i];
const auto mesh_position = this->getPositionOnMesh(selected_mesh, vertex_index, triangle.first, triangle.second);
Expand Down
6 changes: 1 addition & 5 deletions include/limitless/fx/modules/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ namespace Limitless::fx {

virtual void deinitialize([[maybe_unused]] const std::vector<size_t>& indices) {}

virtual void update([[maybe_unused]] AbstractEmitter& emitter,
[[maybe_unused]] std::vector<Particle>& particles,
[[maybe_unused]] float dt,
[[maybe_unused]] Context& ctx,
[[maybe_unused]] const Camera& camera) noexcept {}
virtual void update([[maybe_unused]] AbstractEmitter &emitter, [[maybe_unused]] std::vector<Particle> &particles, [[maybe_unused]] float dt, [[maybe_unused]] const Camera &camera) noexcept {}
};
}
2 changes: 1 addition & 1 deletion include/limitless/fx/modules/rotation_rate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Limitless::fx {
: Module<Particle>(module.type)
, distribution {module.distribution->clone()} {}

void update(AbstractEmitter& emitter, std::vector<Particle>& particles, float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update(AbstractEmitter &emitter, std::vector<Particle> &particles, float dt, [[maybe_unused]] const Camera &camera) noexcept override {
const auto rot = emitter.getRotation() * emitter.getLocalRotation();
for (auto& particle : particles) {
particle.rotation += (distribution->get() * rot) * dt;
Expand Down
4 changes: 2 additions & 2 deletions include/limitless/fx/modules/size_by_life.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Limitless::fx {
: Module<Particle>(module.type)
, distribution {module.distribution->clone()} {}

void update([[maybe_unused]] AbstractEmitter& emitter, std::vector<Particle>& particles, float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update([[maybe_unused]] AbstractEmitter &emitter, std::vector<Particle> &particles, float dt, [[maybe_unused]] const Camera &camera) noexcept override {
for (auto& particle : particles) {
const auto tick = particle.lifetime / dt;
const auto tick_size = (distribution->get() - particle.size) / tick;
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace Limitless::fx {
: Module<MeshParticle>(module.type)
, distribution {module.distribution->clone()} {}

void update([[maybe_unused]] AbstractEmitter& emitter, std::vector<MeshParticle>& particles, float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update([[maybe_unused]] AbstractEmitter &emitter, std::vector<MeshParticle> &particles, float dt, [[maybe_unused]] const Camera &camera) noexcept override {
for (auto& particle : particles) {
const auto tick = particle.lifetime / dt;
const auto tick_size = (distribution->get() - particle.size) / tick;
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/modules/subuv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace Limitless::fx {
particle.subUV.w = frames[0].y;
}

void update([[maybe_unused]] AbstractEmitter& emitter, std::vector<Particle>& particles, [[maybe_unused]] float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update([[maybe_unused]] AbstractEmitter &emitter, std::vector<Particle> &particles, [[maybe_unused]] float dt, [[maybe_unused]] const Camera &camera) noexcept override {
if (first_update) {
last_time = std::chrono::steady_clock::now();
first_update = false;
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/modules/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Limitless::fx {
particle.time = 0.0f;
}

void update([[maybe_unused]] AbstractEmitter& emitter, std::vector<Particle>& particles, float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update([[maybe_unused]] AbstractEmitter &emitter, std::vector<Particle> &particles, float dt, [[maybe_unused]] const Camera &camera) noexcept override {
for (auto& particle : particles) {
particle.time += dt;
}
Expand Down
2 changes: 1 addition & 1 deletion include/limitless/fx/modules/velocity_by_life.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Limitless::fx {
: Module<Particle>(module.type)
, distribution {module.distribution->clone()} {}

void update(AbstractEmitter& emitter, std::vector<Particle>& particles, float dt, [[maybe_unused]] Context& ctx, [[maybe_unused]] const Camera& camera) noexcept override {
void update(AbstractEmitter &emitter, std::vector<Particle> &particles, float dt, [[maybe_unused]] const Camera &camera) noexcept override {
const auto rot = emitter.getRotation() * emitter.getLocalRotation();
for (auto& particle : particles) {
const auto tick = particle.lifetime / dt;
Expand Down
9 changes: 6 additions & 3 deletions include/limitless/instances/decal_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ namespace Limitless {
private:
std::shared_ptr<AbstractModel> model;
std::shared_ptr<ms::Material> material;
uint8_t projection_mask {0xFF};
public:
DecalInstance(std::shared_ptr<AbstractModel> model, std::shared_ptr<ms::Material> material, const glm::vec3& position);
DecalInstance(std::shared_ptr<AbstractModel> model, const std::shared_ptr<ms::Material>& material, const glm::vec3& position);

DecalInstance(const DecalInstance&);

void updateBoundingBox() noexcept override;
std::unique_ptr<Instance> clone() noexcept override;

void setMaterial(std::shared_ptr<ms::Material> new_material);
void setMaterial(const std::shared_ptr<ms::Material>& new_material);

void draw(Context& ctx, const Assets& assets, ShaderType shader_type, ms::Blending blending, const UniformSetter& uniform_set) override;
auto& getMaterial() noexcept { return material; }
auto& getModel() noexcept { return model; }
auto& getProjectionMask() noexcept { return projection_mask; }
};
}
13 changes: 2 additions & 11 deletions include/limitless/instances/effect_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ namespace Limitless {
*/
bool isDone() const noexcept;

void updateBoundingBox() noexcept override;
void updateEmitters(Context& context, const Camera& camera) const noexcept;
void updateEmitters(const Camera& camera) const noexcept;

friend class fx::EffectBuilder;
friend class EffectSerializer;
Expand All @@ -71,20 +70,12 @@ namespace Limitless {
/**
* Updates instance and then emitters
*/
void update(Context& context, const Camera& camera) override;

/**
* Does NOT draw effect
*
* use EffectRenderer instead
*/
void draw(Context& ctx, const Assets& assets, ShaderType shader_type, ms::Blending blending, const UniformSetter& uniform_set) override;
void update(const Camera &camera) override;

const auto& getEmitters() const noexcept { return emitters; }
auto& getEmitters() noexcept { return emitters; }
const auto& getName() const noexcept { return name; }


/**
* Gets emitter with specified name and type
*/
Expand Down
Loading

0 comments on commit 244232c

Please sign in to comment.