Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
VoxelGI.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
24#pragma once
25
26#include "../../core/Types.hpp"
28#include "../rhi/GfxEnums.hpp"
29
30#include <glm/glm.hpp>
31#include <string>
32#include <unordered_map>
33
34namespace esengine {
35
36class GfxDevice;
37class RenderContext;
38
42 f32 intensity = 1.0f;
44 u32 rays = 8;
46 f32 voxelSize = 40.0f;
48 f32 range = 48.0f;
50 f32 maxBounce = 3.0f;
52 f32 decay = 0.93f;
54 f32 bias = 1.2f;
58 f32 debug = 0.0f;
60 f32 blend = 0.2f;
63 f32 sunAlbedo = 0.6f;
68};
69
70class VoxelGI {
71public:
72 VoxelGI(GfxDevice& device, RenderContext& context);
73 ~VoxelGI();
74
75 VoxelGI(const VoxelGI&) = delete;
76 VoxelGI& operator=(const VoxelGI&) = delete;
77
84 u32 width, u32 height, TextureHandle shadowAtlas = TextureHandle::Invalid,
85 rg::ResourceId shadowResource = rg::kNoResource);
86
88 void release();
89
90 static constexpr u32 kMaxGridSize = 128;
91 static constexpr u32 kMinGridSize = 32;
92 static u32 gridSizeOf(u32 asked);
93 static u32 sunSamplesOf(u32 asked);
94
95private:
96 struct Programs;
97 bool ensure(u32 gridSize);
99 bool ensureHistory(u32 width, u32 height);
100 void writeParams(const VoxelGIParams& p);
102 u32 writeSun(const VoxelGIParams& p);
103
104 GfxDevice& device_;
105 RenderContext& context_;
115 bool failed_ = false;
116 u32 frame_ = 0;
118 u32 historyWidth_ = 0;
119 u32 historyHeight_ = 0;
121 bool historyValid_ = false;
122 f32 previousViewProjection_[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
124 glm::dvec3 previousOrigin_{0.0};
125 f32 previousVoxelSize_ = 0.0f;
126 u32 gridSize_ = 0;
128 i32 origin_[3] = {0, 0, 0};
129};
130
131} // namespace esengine
Backend-agnostic graphics enumerations.
Full-screen passes as a declared graph: what each one reads, what it writes, and at what size — the g...
Core type definitions and utilities for ESEngine.
Abstract graphics device interface.
Definition GfxDevice.hpp:75
static constexpr u32 kMinGridSize
Definition VoxelGI.hpp:91
rg::ResourceId declare(rg::RenderGraph &graph, rg::ResourceId input, rg::ResourceId scene, const VoxelGIParams &params, u32 width, u32 height, TextureHandle shadowAtlas=TextureHandle::Invalid, rg::ResourceId shadowResource=rg::kNoResource)
Declares the four passes onto graph, reading input and the scene's depth and G-buffer.
Definition VoxelGI.cpp:666
static constexpr u32 kMaxGridSize
Definition VoxelGI.hpp:90
VoxelGI & operator=(const VoxelGI &)=delete
VoxelGI(const VoxelGI &)=delete
static u32 gridSizeOf(u32 asked)
Definition VoxelGI.cpp:511
static u32 sunSamplesOf(u32 asked)
Definition VoxelGI.cpp:517
VoxelGI(GfxDevice &device, RenderContext &context)
Definition VoxelGI.cpp:487
constexpr ResourceId kNoResource
std::int32_t i32
Signed 32-bit integer.
Definition Types.hpp:54
ComputeHandle
A compute program (GfxDevice::createCompute); only a device that supportsCompute() issues one.
Definition GfxEnums.hpp:39
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
float f32
32-bit floating point
Definition Types.hpp:59
f32 voxelSize
World size of one voxel.
Definition VoxelGI.hpp:46
u32 divisor
The gather runs at 1 / this of the picture's size per axis.
Definition VoxelGI.hpp:56
f32 intensity
How much of the gathered light is added over the picture.
Definition VoxelGI.hpp:42
u32 rays
Rays per surface point.
Definition VoxelGI.hpp:44
f32 decay
What the grid keeps each frame of what it held: 0 forgets at once, 1 never.
Definition VoxelGI.hpp:52
f32 range
How far a ray looks, in voxels.
Definition VoxelGI.hpp:48
f32 blend
How much of each frame's gather goes into the picture the next frame builds on (the rest is what the ...
Definition VoxelGI.hpp:60
f32 bounceFeedback
How much of the light the last gather found on a surface it gives off again (the bounces after the fi...
Definition VoxelGI.hpp:65
f32 bias
How far off its own voxel a ray starts, in voxels, so a surface is not lit by itself.
Definition VoxelGI.hpp:54
f32 debug
1 shows the gathered light alone.
Definition VoxelGI.hpp:58
f32 maxBounce
The brightest a surface is taken to give out, so one lamp does not light the street from a single pix...
Definition VoxelGI.hpp:50