Skip to content

Commit

Permalink
Merge pull request #209 from edunad/features/camera-switching
Browse files Browse the repository at this point in the history
[FEATURE] Improved camera support
  • Loading branch information
edunad authored Oct 14, 2024
2 parents a0950d0 + 3ee2079 commit 6b6c6b8
Show file tree
Hide file tree
Showing 42 changed files with 607 additions and 271 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This engine started as a C++ training project, with hopes of being applied in my
| **Data** | - File formats: <br/>&nbsp;&nbsp;&nbsp;&nbsp;- Meshes: <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- GLTF 2.0 (using [fastgltf](https://github.com/spnda/fastgltf))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- OBJ (using ???)<br/>- Images: <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- PNG, JPEG, BMP, TGA, GIF (using [stb](https://github.com/nothings/stb))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- SVG (using [lunasvg](https://github.com/sammycage/lunasvg))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- WEBP (using [libwebp](https://github.com/webmproject/libwebp))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- WEBM (video only) (using [libwebm](https://github.com/webmproject/libwebm))<br/>- Fonts: <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- TTF (using [stb](https://github.com/nothings/stb))<br/>- Audio (using [BASS](https://www.un4seen.com/)): <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- OGG<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- MP4<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- MP3<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- WAV<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Supports url audio<br/>- JSON (using [glaze](https://github.com/stephenberry/glaze)) |
| **Math** | - Vectors, colors, matrices & quaternions support<br/> - Bezier curve & easing<br> - Packing support (float16, etc) |
| **Physics** | - 3D multi-threaded physics (using [JoltPhysics](https://github.com/jrouwe/JoltPhysics))<br/> - 2D physics support (using [Muli](https://github.com/Sopiro/Muli)) |
| **Rendering** | - **Vulkan** & **DirectX 12** support using ([Diligent](https://github.com/DiligentGraphics/DiligentCore))<br/>- Material system similar to unity<br/>- Window & Input callbacks (using [GLFW](https://github.com/glfw/glfw)) <br/>- Clustered rendering :<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Decals (**WIP**)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Lights (point / spot/ directional)<br/>- Linux (**steamdeck**) support<br/>- Bindless rendering<br/>- Post-processing support<br/> - 2D rendering<br/> - Custom rendering plugins<br/> - GPU Picking<br/> - [IMGUI](https://github.com/ocornut/imgui) support<br/> - GPU Particle system<br/> |
| **Rendering** | - **Vulkan** & **DirectX 12** support using ([Diligent](https://github.com/DiligentGraphics/DiligentCore))<br/>- Material system similar to unity<br/>- Window & Input callbacks (using [GLFW](https://github.com/glfw/glfw)) <br/>- Clustered rendering :<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Decals (**WIP**)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Lights (point / spot/ directional)<br/>- Linux (**steamdeck**) support<br/>- Bindless rendering<br/>- Post-processing support<br/> - 2D rendering<br/> - Custom rendering plugins<br/> - Multiple camera support<br/> - GPU Picking<br/> - [IMGUI](https://github.com/ocornut/imgui) support<br/> - GPU Particle system<br/> |
| **Network** | - HTTP / HTTPS requests (using [libcpr](https://github.com/libcpr/cpr))<br/>- Packet network implementation<br/>- **NetVar** & **NetArray** support for [snapshot](https://gafferongames.com/post/snapshot_interpolation/) implementation <br/>- Simple socket implementation |
| **Scripting** | - Scripting / modding support with LUAU (using [luabridge3](https://github.com/kunitoki/LuaBridge3) + [luau](https://github.com/luau-lang/luau)) |
| **Other** | - I18N (internationalization) support<br/>- Settings support<br/>- Steamworks support<br/>- Custom UI<br/>- DEV Console with support for custom commands & scripts<br/> - Timer utils (based on [GMOD's](https://wiki.facepunch.com/gmod/timer) timers)<br/>- File watcher implementation <br/>- Threading utilities |
Expand All @@ -55,7 +55,7 @@ This engine started as a C++ training project, with hopes of being applied in my
| 007-particle-system<br/><a href='/samples/007-particle-system'><img src="https://i.rawr.dev/sample7-min.gif" width="240" /></a> | 008-ui<br/><a href='/samples/008-ui'><img src="https://i.rawr.dev/sample8-min-5.gif" width="240" /></a> | 009-gltf<br/><a href='/samples/009-gltf'><img src="https://i.rawr.dev/sample9-min-4.gif" width="240" /></a> |
| 010-bass-audio<br/><a href='/samples/010-bass-audio'><img src="https://i.rawr.dev/sample10-min.gif" width="240" /></a> | 011-physics-3D<br/><a href='/samples/011-physics-3D'><img src="https://i.rawr.dev/sample11-min-2.gif" width="240" /></a> | 012-physics-2D<br/><a href='/samples/012-physics-2D'><img src="https://i.rawr.dev/sample12-min-2.gif" width="240" /></a> |
| 013-webm<br/><a href='/samples/013-webm'><img src="https://i.rawr.dev/sample13-min-2.gif" width="240" /></a> | 014-scripting<br/><a href='/samples/014-scripting'><img src="https://i.rawr.dev/sample14-min-2.gif" width="240" /></a> | 015-gpu-picking<br/><a href='/samples/015-gpu-picking'><img src="https://i.rawr.dev/sample15-min-2.gif" width="240" /></a> |
| 016-steamworks<br/><a href='/samples/016-steamworks'><img src="https://i.rawr.dev/sample16-min.gif" width="240" /></a> | 017-imgui<br/><a href='/samples/017-imgui'><img src="https://i.rawr.dev/sample17-min-2.gif" width="240" /></a> | |
| 016-steamworks<br/><a href='/samples/016-steamworks'><img src="https://i.rawr.dev/sample16-min.gif" width="240" /></a> | 017-imgui<br/><a href='/samples/017-imgui'><img src="https://i.rawr.dev/sample17-min-2.gif" width="240" /></a> | 018-camera<br/><a href='/samples/018-camera'><img src="https://i.rawr.dev/sample18-min.gif" width="240" /></a> |

# BUILDING

Expand Down
5 changes: 4 additions & 1 deletion rawrbox.render/include/rawrbox/render/bindless.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ namespace rawrbox {

// SIGNATURES ------
static void createSignatures();
static void bindSignatures();
// -----------------

static uint32_t internalRegister(Diligent::ITextureView* view, rawrbox::TEXTURE_TYPE type);
Expand All @@ -80,6 +79,10 @@ namespace rawrbox {

static void update();

// SIGNATURES
static void bindSignatures();
// ----------------

// TEXTURES -------
static void registerTexture(rawrbox::TextureBase& texture);
static void registerTexture(rawrbox::TextureRender& texture);
Expand Down
46 changes: 39 additions & 7 deletions rawrbox.render/include/rawrbox/render/cameras/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <rawrbox/math/vector2.hpp>
#include <rawrbox/math/vector3.hpp>
#include <rawrbox/math/vector4.hpp>
#include <rawrbox/render/render_config.hpp>
#include <rawrbox/render/textures/render.hpp>
#include <rawrbox/utils/logger.hpp>

#include <RefCntAutoPtr.hpp>
Expand All @@ -11,6 +13,9 @@

#include <memory>

#define CREATE_FLAGS(name, value) \
const uint32_t name = 1 << value;

namespace rawrbox {
struct CameraStaticUniforms { // Uniforms that won't be updated that frequently
rawrbox::Matrix4x4 gProjection = {};
Expand All @@ -26,6 +31,12 @@ namespace rawrbox {
bool operator!=(const CameraStaticUniforms& other) const { return !operator==(other); }
};

namespace CameraLayers {
// USER DEFINED
RB_RENDER_CAMERA_LAYERS(CREATE_FLAGS)
// ------------
}; // namespace CameraLayers

struct CameraUniforms {
rawrbox::Matrix4x4 gView = {};
rawrbox::Matrix4x4 gViewInv = {};
Expand All @@ -47,6 +58,8 @@ namespace rawrbox {

class CameraBase {
protected:
bool _enabled = true;

rawrbox::Vector3f _pos = {};
rawrbox::Vector4f _angle = {};

Expand All @@ -55,12 +68,15 @@ namespace rawrbox {

rawrbox::Matrix4x4 _world = {};

uint32_t _layers = 0; // None by default, it's up to the user to use this or not

// Renderer ----
std::unique_ptr<rawrbox::TextureRender> _renderTarget = nullptr;
// --------------------------

float _z_near = 0.01F;
float _z_far = 100.F;

Diligent::RefCntAutoPtr<Diligent::IBuffer> _staticUniforms;
Diligent::RefCntAutoPtr<Diligent::IBuffer> _uniforms;

// LOGGER ------
std::unique_ptr<rawrbox::Logger> _logger = std::make_unique<rawrbox::Logger>("RawrBox-Camera");
// -------------
Expand All @@ -69,13 +85,15 @@ namespace rawrbox {
virtual rawrbox::CameraStaticUniforms getStaticData();

public:
virtual ~CameraBase();
static Diligent::RefCntAutoPtr<Diligent::IBuffer> staticUniforms;
static Diligent::RefCntAutoPtr<Diligent::IBuffer> uniforms;

CameraBase() = default;
CameraBase(const rawrbox::Vector2u& renderSize, bool depth = true);
CameraBase(CameraBase&&) = default;
CameraBase& operator=(CameraBase&&) = default;
CameraBase(const CameraBase&) = delete;
CameraBase& operator=(const CameraBase&) = delete;
virtual ~CameraBase();

// UTILS -----
virtual void setPos(const rawrbox::Vector3f& pos);
Expand All @@ -100,12 +118,26 @@ namespace rawrbox {

[[nodiscard]] virtual rawrbox::Vector3f worldToScreen(const rawrbox::Vector3f& pos) const;
[[nodiscard]] virtual rawrbox::Vector3f screenToWorld(const rawrbox::Vector2f& screen_pos, const rawrbox::Vector3f& origin = {0, 0, 0}) const;

virtual bool isEnabled() const;
virtual void setEnabled(bool enabled);

virtual uint32_t getLayers() const;
virtual void setLayers(uint32_t layers);
virtual bool shouldRenderLayer(uint32_t layer) const;
// ----------------

[[nodiscard]] virtual Diligent::IBuffer* uniforms() const;
[[nodiscard]] virtual Diligent::IBuffer* staticUniforms() const;
// RENDER TARGET ----
virtual void begin();
virtual void end();

[[nodiscard]] virtual Diligent::ITextureView* getDepth() const;
[[nodiscard]] virtual Diligent::ITextureView* getColor(bool rt = false) const;
[[nodiscard]] virtual rawrbox::TextureRender* getRenderTarget() const;
// ------------

virtual void initialize();
virtual void upload();

virtual void updateBuffer();
virtual void update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
namespace rawrbox {
class CameraPerspective : public rawrbox::CameraBase {
protected:
rawrbox::Vector2u _winSize = {};
float _FOV = 60.F;

void updateMtx() override;

public:
Expand All @@ -20,7 +18,7 @@ namespace rawrbox {
CameraPerspective& operator=(CameraPerspective&&) = default;
~CameraPerspective() override = default;

explicit CameraPerspective(const rawrbox::Vector2u& winSize, float FOV = 60.F, float near = 0.01F, float far = 100.F);
explicit CameraPerspective(const rawrbox::Vector2u& renderSize, float FOV = 60.F, float near = 0.01F, float far = 100.F, bool depth = true);

[[nodiscard]] rawrbox::Vector3f worldToScreen(const rawrbox::Vector3f& pos) const override;
[[nodiscard]] rawrbox::Vector3f screenToWorld(const rawrbox::Vector2f& screenPos, const rawrbox::Vector3f& origin = {0, 0, 0}) const override;
Expand Down
5 changes: 3 additions & 2 deletions rawrbox.render/include/rawrbox/render/plugins/base.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <rawrbox/math/vector2.hpp>
#include <rawrbox/render/cameras/base.hpp>
#include <rawrbox/render/enums/draw.hpp>
#include <rawrbox/render/textures/render.hpp>

Expand Down Expand Up @@ -40,8 +41,8 @@ namespace rawrbox {
virtual void resize(const rawrbox::Vector2u& renderSize);
virtual void upload();

virtual void preRender();
virtual void postRender(rawrbox::TextureRender& renderTarget);
virtual void preRender(const rawrbox::CameraBase& camera);
virtual void postRender(const rawrbox::CameraBase& camera);

virtual void update();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace rawrbox {
void signatures(std::vector<Diligent::PipelineResourceDesc>& sig) override;
void bindStatic(Diligent::IPipelineResourceSignature& sig) override;

void preRender() override;
void preRender(const rawrbox::CameraBase& camera) override;

std::string getID() override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace rawrbox {
void signatures(std::vector<Diligent::PipelineResourceDesc>& sig) override;
void bindStatic(Diligent::IPipelineResourceSignature& sig) override;

void preRender() override;
void preRender(const rawrbox::CameraBase& camera) override;

[[nodiscard]] Diligent::IPipelineResourceSignature* getSignature(bool dynamic = true) const;
[[nodiscard]] Diligent::IShaderResourceBinding* getBind(bool dynamic = true) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace rawrbox {

void signatures(std::vector<Diligent::PipelineResourceDesc>& sig) override;
void bindStatic(Diligent::IPipelineResourceSignature& sig) override;
void postRender(rawrbox::TextureRender& render) override;
void postRender(const rawrbox::CameraBase& camera) override;

// PLUGIN UTILS ----
template <class T = rawrbox::PostProcessBase, typename... CallbackArgs>
Expand Down
7 changes: 7 additions & 0 deletions rawrbox.render/include/rawrbox/render/render_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@

#define RB_RENDER_THREAD_GROUP_SIZE (RB_RENDER_CLUSTERS_X_THREADS * RB_RENDER_CLUSTERS_Y_THREADS * RB_RENDER_CLUSTERS_Z_THREADS)
// ----------------

// CAMERA -----
// Add more layers if needed, you can then check if the camera should draw your model by checking if the layer is enabled
#define RB_RENDER_CAMERA_LAYERS(flag) \
flag(LAYER_1, 1) \
flag(LAYER_2, 2)
// ----------------
Loading

0 comments on commit 6b6c6b8

Please sign in to comment.