SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
VulkanInternal.hpp
Go to the documentation of this file.
1#ifndef _VULKANINTERNAL_HPP_
2#define _VULKANINTERNAL_HPP_
3
4#include <cmath>
5#include <algorithm>
6
7namespace Sleak {
8namespace RenderEngine {
9
10/// Halton low-discrepancy sequence value for TAA sub-pixel jitter.
11inline float HaltonSeq(int index, int base) {
12 float result = 0.0f;
13 float f = 1.0f;
14 for (int i = index; i > 0; i /= base) {
15 f /= static_cast<float>(base);
16 result += f * static_cast<float>(i % base);
17 }
18 return result;
19}
20
21/// Row-major mat4 multiply: C = A * B.
22inline void MatMul4(const float A[16], const float B[16], float C[16]) {
23 for (int r = 0; r < 4; ++r)
24 for (int c = 0; c < 4; ++c) {
25 float s = 0.0f;
26 for (int k = 0; k < 4; ++k) s += A[r * 4 + k] * B[k * 4 + c];
27 C[r * 4 + c] = s;
28 }
29}
30
31/// Row-major 4x4 inverse via Gauss-Jordan elimination.
32inline bool InvertMat4(const float M[16], float out[16]) {
33 float m[4][8];
34 for (int r = 0; r < 4; ++r) {
35 for (int c = 0; c < 4; ++c) m[r][c] = M[r * 4 + c];
36 for (int c = 0; c < 4; ++c) m[r][4 + c] = (r == c) ? 1.0f : 0.0f;
37 }
38 for (int col = 0; col < 4; ++col) {
39 int pivot = -1; float maxv = 0.0f;
40 for (int row = col; row < 4; ++row) {
41 float v = std::abs(m[row][col]);
42 if (v > maxv) { maxv = v; pivot = row; }
43 }
44 if (pivot < 0 || maxv < 1e-7f) return false;
45 if (pivot != col) std::swap(m[col], m[pivot]);
46 float inv = 1.0f / m[col][col];
47 for (int c = 0; c < 8; ++c) m[col][c] *= inv;
48 for (int row = 0; row < 4; ++row) {
49 if (row == col) continue;
50 float f = m[row][col];
51 for (int c = 0; c < 8; ++c) m[row][c] -= f * m[col][c];
52 }
53 }
54 for (int r = 0; r < 4; ++r)
55 for (int c = 0; c < 4; ++c)
56 out[r * 4 + c] = m[r][4 + c];
57 return true;
58}
59
60} // namespace RenderEngine
61} // namespace Sleak
62
63#endif
Backend-facing rendering layer shared by the four graphics backends.
bool InvertMat4(const float M[16], float out[16])
Row-major 4x4 inverse via Gauss-Jordan elimination.
void MatMul4(const float A[16], const float B[16], float C[16])
Row-major mat4 multiply: C = A * B.
float HaltonSeq(int index, int base)
Halton low-discrepancy sequence value for TAA sub-pixel jitter.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10