Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
FrameConstants.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
19#pragma once
20
21#include "../../core/Types.hpp"
22#include "../rhi/GfxEnums.hpp"
23
24#include <glm/glm.hpp>
25
26#include <cmath>
27
28namespace esengine {
29
38 glm::mat4 viewProjection{1.0f};
39 glm::vec4 camera{0.0f, 0.0f, 1.0f, 0.0f};
46 glm::mat4 inverseViewProjection{1.0f};
48 glm::vec4 renderOrigin{0.0f};
49};
50
59inline glm::vec4 cameraFromViewProjection(const glm::mat4& viewProjection) {
60 const glm::vec4 axis = glm::inverse(viewProjection)[2];
61 if (std::abs(axis.w) > 1e-6f) return glm::vec4(glm::vec3(axis) / axis.w, 1.0f);
62 const f32 len = glm::length(glm::vec3(axis));
63 if (len < 1e-12f) return glm::vec4(0.0f, 0.0f, 1.0f, 0.0f);
64 return glm::vec4(-glm::vec3(axis) / len, 0.0f);
65}
66
75inline glm::mat4 toClipDepthRange(const glm::mat4& p, ClipDepthRange range) {
76 if (range == ClipDepthRange::MinusOneToOne) return p;
77 glm::mat4 out = p;
78 for (int col = 0; col < 4; ++col) out[col][2] = (p[col][2] + p[col][3]) * 0.5f;
79 return out;
80}
81
83inline constexpr u32 FRAME_CONSTANTS_BINDING = 0;
84
86inline constexpr const char* FRAME_CONSTANTS_BLOCK = "FrameConstants";
87
95 glm::vec4 time{0.0f};
96 glm::vec4 viewport{0.0f};
97 glm::vec4 quality{0.0f};
98};
99
100inline constexpr u32 TIME_CONSTANTS_BINDING = 3;
101inline constexpr const char* TIME_CONSTANTS_BLOCK = "TimeConstants";
102
103} // namespace esengine
Backend-agnostic graphics enumerations.
Core type definitions and utilities for ESEngine.
constexpr u32 FRAME_CONSTANTS_BINDING
Indexed uniform binding point the FrameConstants block is bound to.
constexpr const char * FRAME_CONSTANTS_BLOCK
GLSL block name; must match the shader declarations and Shader::compile lookup.
ClipDepthRange
What a device's clip volume does with depth.
Definition GfxEnums.hpp:562
@ MinusOneToOne
OpenGL / OpenGL ES / WebGL.
Definition GfxEnums.hpp:563
constexpr u32 TIME_CONSTANTS_BINDING
glm::mat4 toClipDepthRange(const glm::mat4 &p, ClipDepthRange range)
The projection p as a device keeping range wants it.
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
constexpr const char * TIME_CONSTANTS_BLOCK
glm::vec4 cameraFromViewProjection(const glm::mat4 &viewProjection)
Where the frame is seen from, read out of the matrix that projects it.
float f32
32-bit floating point
Definition Types.hpp:59
CPU mirror of the GLSL FrameConstants block (std140).
glm::vec4 renderOrigin
The render origin (RenderOrigin.hpp): a world position is the one the shader holds plus this,...
CPU mirror of the injected TimeConstants block (std140).