GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
LightProbeVolumes3D.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_GRAPHICS_3D_LIGHT_PROBE_VOLUMES_3D_HPP
5#define GREM_GRAPHICS_3D_LIGHT_PROBE_VOLUMES_3D_HPP
6
8
12#include <GREM/core/extents.hpp>
14#include <GREM/core/math.hpp>
17
18namespace grem::graphics {
19
20class Device; // Forward declaration, to avoid including Device.hpp.
21class RenderPass; // Forward declaration, to avoid including RenderPass.hpp.
22class Renderer3D; // Forward declaration, to avoid a circular include of Renderer3D.hpp.
23class LightBaker3D; // Forward declaration, to avoid a circular include of LightBaker3D.hpp.
24
71
83 [[nodiscard]] constexpr bool operator==(const LightProbeVolumes3DOptions& other) const noexcept = default;
84};
85
90public:
101
105 using AtlasBuffer = UniformBuffer<AtlasParameters, "LightProbeVolumes3DAtlases">;
106
135
139 using VolumeBuffer = StorageBuffer<VolumeFields, "LightProbeVolumes3DVolumes">;
140
145 .minificationFilter = TextureFilter::LINEAR,
146 .magnificationFilter = TextureFilter::LINEAR,
147 .mipmapMode = TextureMipmapMode::NONE,
148 .horizontalWrappingMode = TextureWrappingMode::CLAMP_TO_EDGE,
149 .verticalWrappingMode = TextureWrappingMode::CLAMP_TO_EDGE,
150 .maxAnisotropy = 1.0f,
151 };
152
157 .minificationFilter = TextureFilter::LINEAR,
158 .magnificationFilter = TextureFilter::LINEAR,
159 .mipmapMode = TextureMipmapMode::NONE,
160 .horizontalWrappingMode = TextureWrappingMode::CLAMP_TO_EDGE,
161 .verticalWrappingMode = TextureWrappingMode::CLAMP_TO_EDGE,
162 .maxAnisotropy = 1.0f,
163 };
164
177 GREM_API(graphics_3d) explicit LightProbeVolumes3D(Device& device, const LightProbeVolumes3DOptions& options = {});
178
202 GREM_API(graphics_3d)
203 LightProbeVolumes3D(Device& device, Texture irradianceAtlasTexture, Texture distanceAtlasTexture, ArrayList<LightProbeVolumeOptions3D> volumeOptions,
204 const LightProbeVolumes3DOptions& options);
205
209 GREM_API(graphics_3d) void clearLightProbeVolumes() noexcept;
210
220 GREM_API(graphics_3d) void addLightProbeVolume(const LightProbeVolumeOptions3D& options);
221
233 GREM_API(graphics_3d) void setLightProbeVolumes(const LightProbeVolumes3DOptions& newOptions);
234
254 GREM_API(graphics_3d)
255 void setLightProbeVolumes(Texture newIrradianceAtlasTexture, Texture newDistanceAtlasTexture, ArrayList<LightProbeVolumeOptions3D> newVolumeOptions,
256 const LightProbeVolumes3DOptions& newOptions);
257
265 [[nodiscard]] const Texture& getIrradianceAtlasTexture() const noexcept {
266 return irradianceAtlasTexture;
267 }
268
276 [[nodiscard]] const Texture& getDistanceAtlasTexture() const noexcept {
277 return distanceAtlasTexture;
278 }
279
287 return volumeOptions;
288 }
289
295 [[nodiscard]] LightProbeVolumes3DOptions getOptions() const noexcept {
296 return options;
297 }
298
299private:
300 friend Renderer3D;
301 friend LightBaker3D;
302
303 GREM_API(graphics_3d) void flushVolumesAndTextures(Device& device) const;
304 GREM_API(graphics_3d) void flush(Device& device, Renderer3D& renderer3D) const;
305
308 mutable Texture irradianceAtlasTexture{};
309 mutable Texture distanceAtlasTexture{};
310 mutable uint32_t irradianceAtlasResolution = 0;
311 mutable uint32_t irradianceAtlasDepth = 0;
312 mutable uint32_t distanceAtlasResolution = 0;
313 mutable uint32_t distanceAtlasDepth = 0;
314 mutable Buffer<VolumeFields> volumes{};
315 mutable Buffer<float> worldSpaceVolumes{};
316 mutable AtlasBuffer atlasBuffer;
317 mutable VolumeBuffer volumeBuffer;
318 mutable bool volumesDirty = false;
319 mutable bool texturesDirty = false;
320 mutable bool buffersDirty = true;
321};
322
323} // namespace grem::graphics
324
325#endif
Definition ArrayList.hpp:27
Definition Span.hpp:146
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
System for pre-baking global illumination.
Definition LightBaker3D.hpp:134
void setLightProbeVolumes(const LightProbeVolumes3DOptions &newOptions)
Set the light probe volume set to the default empty set with new options.
const Texture & getDistanceAtlasTexture() const noexcept
Get the atlas of distance values for the light probe volumes.
Definition LightProbeVolumes3D.hpp:276
const Texture & getIrradianceAtlasTexture() const noexcept
Get the atlas of irradiance values for the light probe volumes.
Definition LightProbeVolumes3D.hpp:265
void addLightProbeVolume(const LightProbeVolumeOptions3D &options)
Add a light probe volume to the set.
Span< const LightProbeVolumeOptions3D > getVolumeOptions() const noexcept
Get the configuration options for the light probe volumes in the set.
Definition LightProbeVolumes3D.hpp:286
LightProbeVolumes3D(Device &device, const LightProbeVolumes3DOptions &options={})
Construct an empty set of light probe volumes.
LightProbeVolumes3DOptions getOptions() const noexcept
Get the configuration options of the light probe volume set.
Definition LightProbeVolumes3D.hpp:295
UniformBuffer< AtlasParameters, "LightProbeVolumes3DAtlases"> AtlasBuffer
Shader buffer for light probe volume atlases.
Definition LightProbeVolumes3D.hpp:105
void clearLightProbeVolumes() noexcept
Remove all light probe volumes from the set.
static constexpr TextureSamplerOptions IRRADIANCE_ATLAS_SAMPLER_OPTIONS
Sampler options to use for the irradiance atlas of light probe volumes.
Definition LightProbeVolumes3D.hpp:144
StorageBuffer< VolumeFields, "LightProbeVolumes3DVolumes"> VolumeBuffer
Shader buffer for light probe volumes.
Definition LightProbeVolumes3D.hpp:139
static constexpr TextureSamplerOptions DISTANCE_ATLAS_SAMPLER_OPTIONS
Sampler options to use for the distance atlas of light probe volumes.
Definition LightProbeVolumes3D.hpp:156
Backend-specific implementation of RenderPass.
Definition RenderPass.hpp:38
Persistent system that provides 3D rendering capabilities.
Definition Renderer3D.hpp:120
GPU memory buffer containing an array of structs to be read by a shader program.
Definition buffers.hpp:493
Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configurati...
Definition Texture.hpp:700
GPU memory buffer containing a fixed-size struct of uniform parameters to be read by a shader program...
Definition buffers.hpp:426
Definition buffer_layouts.hpp:20
@ CLAMP_TO_EDGE
Clamp to the edge of the texture when sampling outside the 0-1 range.
Definition Texture.hpp:492
@ NONE
Always use the most detailed mip level (level 0).
Definition Texture.hpp:482
@ LINEAR
Interpolate between texels for a smoother appearance.
Definition Texture.hpp:475
qua< float > quat
Definition math.hpp:892
vec< 4, float > vec4
Definition math.hpp:440
vec< 3, uint32_t > u32vec3
Definition math.hpp:419
vec< 2, float > vec2
Definition math.hpp:438
vec< 3, float > vec3
Definition math.hpp:439
Configuration options for a light probe volume in a LightProbeVolumes3D set.
Definition LightProbeVolumes3D.hpp:28
uint32_t distanceMapResolution
Width, in texels, of each light probe's distance map in the distance atlas, including a 1 pixel borde...
Definition LightProbeVolumes3D.hpp:69
u32vec3 probeCounts
Number of light probes along each axis of the light probe volume.
Definition LightProbeVolumes3D.hpp:51
uint32_t irradianceMapResolution
Width, in texels, of each light probe's irradiance map in the irradiance atlas, including a 1 pixel b...
Definition LightProbeVolumes3D.hpp:60
vec3 probeSpacing
Local spacing between the light probes.
Definition LightProbeVolumes3D.hpp:44
vec3 center
Center position of the light probe volume in world space.
Definition LightProbeVolumes3D.hpp:32
quat orientation
Orientation of the light probe volume in world space.
Definition LightProbeVolumes3D.hpp:37
Configuration options for a LightProbeVolumes3D set.
Definition LightProbeVolumes3D.hpp:75
constexpr bool operator==(const LightProbeVolumes3DOptions &other) const noexcept=default
Compare these options to another set of options for equality.
Struct of shader parameters representing the light probe volume atlases.
Definition LightProbeVolumes3D.hpp:94
sampler2DArray lightProbeVolumesDistanceAtlasTexture
Sampler for the atlas of distance values for the light probe volumes.
Definition LightProbeVolumes3D.hpp:99
sampler2DArray lightProbeVolumesIrradianceAtlasTexture
Sampler for the atlas of irradiance values for the light probe volumes.
Definition LightProbeVolumes3D.hpp:96
Struct of shader fields representing a light probe volume.
Definition LightProbeVolumes3D.hpp:110
vec3 lightProbeVolumeProbeCounts
Number of probes along each coordinate axis in the light probe volume.
Definition LightProbeVolumes3D.hpp:121
vec4 lightProbeVolumeOrientation
Components of the quaternion representing the orientation of the light probe volume in world space.
Definition LightProbeVolumes3D.hpp:115
vec3 lightProbeVolumeProbeSpacing
Local spacing between the light probes.
Definition LightProbeVolumes3D.hpp:118
vec3 lightProbeVolumeCenter
Center position of the light probe volume in world space.
Definition LightProbeVolumes3D.hpp:112
vec3 lightProbeVolumeIrradianceAtlasOffset
Texture coordinate offset of the light probe volume in the atlas of irradiance values.
Definition LightProbeVolumes3D.hpp:124
vec2 lightProbeVolumeIrradianceAtlasPaddedProbeSizeAndTexelSize
Padded size of the probes in the irradiance map atlas (X), and the size of the texels (Y) in texture ...
Definition LightProbeVolumes3D.hpp:130
vec3 lightProbeVolumeDistanceAtlasOffset
Texture coordinate offset of the light probe volume in the atlas of distance values.
Definition LightProbeVolumes3D.hpp:127
vec2 lightProbeVolumeDistanceAtlasPaddedProbeSizeAndTexelSize
Padded size of the probes in the distance map atlas (X), and the size of the texels (Y) in texture co...
Definition LightProbeVolumes3D.hpp:133
Configuration options for the sampler of a Texture.
Definition Texture.hpp:617
Reference to a sampler2DArray Texture that may be used as a parameter value type in a shader-read buf...
Definition ParameterDescription.hpp:147