GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
Sky3D.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_SKY_3D_HPP
5#define GREM_GRAPHICS_3D_SKY_3D_HPP
6
8
17
18namespace grem::graphics {
19
20class Device; // Forward declaration, to avoid including Device.hpp.
21class Renderer3D; // Forward declaration, to avoid a circular include of Renderer3D.hpp.
22class LightBaker3D; // Forward declaration, to avoid a circular include of LightBaker3D.hpp.
23
32
37
42
51
59
67
75 [[nodiscard]] constexpr bool operator==(const Sky3DOptions& other) const noexcept = default;
76};
77
81class Sky3D {
82public:
85
88
91
96
99
126
128 using ParameterBuffer = UniformBuffer<Parameters, "Sky3DParameters">;
129
132
135
138 .SKY_HDR = false,
139 };
140
143 .depthTestPredicate = DepthTestPredicate::LESS_OR_EQUAL,
144 .faceCullingMode = FaceCullingMode::NONE,
145 };
146
158 GREM_API(graphics_3d) explicit Sky3D(Device& device, const Sky3DOptions& options = {});
159
178 GREM_API(graphics_3d) Sky3D(Device& device, Texture radianceMap, Texture irradianceMap, Texture reflectionMap, const Sky3DOptions& options);
179
190 GREM_API(graphics_3d) void setSky(const Sky3DOptions& newOptions);
191
211 GREM_API(graphics_3d) void setSky(Texture newRadianceMap, Texture newIrradianceMap, Texture newReflectionMap, const Sky3DOptions& newOptions);
212
220 [[nodiscard]] const Texture& getRadianceMap() const noexcept {
221 return radianceMap;
222 }
223
231 [[nodiscard]] const Texture& getIrradianceMap() const noexcept {
232 return irradianceMap;
233 }
234
242 [[nodiscard]] const Texture& getReflectionMap() const noexcept {
243 return reflectionMap;
244 }
245
251 [[nodiscard]] Sky3DOptions getOptions() const noexcept {
252 return options;
253 }
254
255private:
256 friend Renderer3D;
257 friend LightBaker3D;
258
259 GREM_API(graphics_3d) void flush(Renderer3D& renderer3D) const;
260
261 Sky3DOptions options;
262 Texture radianceMap{};
263 Texture irradianceMap{};
264 Texture reflectionMap{};
265 mutable ParameterBuffer parameterBuffer;
266 mutable bool parameterBufferDirty = true;
267};
268
277 bool skipSkyRendering = false;
278};
279
283struct Sky3DView {
285 const Sky3D* sky;
286
289
292
299 Sky3DView(const Sky3D& sky, const Sky3DFilter& filter = {})
300 : sky(&sky)
301 , filter(filter) {}
302
310 Sky3DView(const Sky3D& sky, const Sky3D::ShaderPipeline& shaderPipelineOverride, const Sky3DFilter& filter = {})
311 : sky(&sky)
312 , shaderPipelineOverrideHandle(shaderPipelineOverride.lock())
313 , filter(filter) {}
314};
315
316} // namespace grem::graphics
317
318#endif
Floating-point linear RGBA color in the Rec.
Definition Color.hpp:60
static const Color WHITE
Definition Color.hpp:215
Definition SharedPointer.hpp:65
Definition fundamentals.hpp:109
graphics::Mesh< Vertex, Index > Mesh
Cubemap mesh primitive type.
Definition Cubemap3D.hpp:33
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
System for pre-baking global illumination.
Definition LightBaker3D.hpp:134
Persistent system that provides 3D rendering capabilities.
Definition Renderer3D.hpp:120
Linked GPU shader pipeline.
Definition shaders.hpp:1508
Skybox in 3D space.
Definition Sky3D.hpp:81
Sky3D(Device &device, const Sky3DOptions &options={})
Construct a sky.
void setSky(const Sky3DOptions &newOptions)
Set the sky to the default invisible texture with new options.
static constexpr FragmentShaderConstants DEFAULT_FRAGMENT_SHADER_CONSTANTS
Default skybox fragment shader constants.
Definition Sky3D.hpp:137
void setSky(Texture newRadianceMap, Texture newIrradianceMap, Texture newReflectionMap, const Sky3DOptions &newOptions)
Set the sky to a pre-baked sky.
static constexpr VertexShaderConstants DEFAULT_VERTEX_SHADER_CONSTANTS
Default skybox vertex shader constants.
Definition Sky3D.hpp:134
UniformBuffer< Parameters, "Sky3DParameters"> ParameterBuffer
Shader buffer for sky parameters.
Definition Sky3D.hpp:128
Sky3DOptions getOptions() const noexcept
Get the configuration options of the sky.
Definition Sky3D.hpp:251
Cubemap3D::VertexShaderConstants VertexShaderConstants
Struct of default vertex shader constants.
Definition Sky3D.hpp:87
Cubemap3D::Mesh Mesh
Type of a skybox mesh.
Definition Sky3D.hpp:84
Cubemap3D::VertexShaderOutputs VertexShaderOutputs
Struct of fields output by the default vertex shader.
Definition Sky3D.hpp:90
graphics::ShaderPipeline< Mesh > ShaderPipeline
Shader pipeline for drawing skyboxes.
Definition Sky3D.hpp:131
const Texture & getReflectionMap() const noexcept
Get the reflection map of the sky.
Definition Sky3D.hpp:242
Sky3D(Device &device, Texture radianceMap, Texture irradianceMap, Texture reflectionMap, const Sky3DOptions &options)
Construct a pre-baked sky.
const Texture & getRadianceMap() const noexcept
Get the radiance map of the sky.
Definition Sky3D.hpp:220
Cubemap3D::FragmentShaderOutputs FragmentShaderOutputs
Struct of fields output by the default fragment shader.
Definition Sky3D.hpp:98
const Texture & getIrradianceMap() const noexcept
Get the irradiance map of the sky.
Definition Sky3D.hpp:231
static constexpr ShaderPipelineOptions DEFAULT_SHADER_PIPELINE_OPTIONS
Default skybox graphics pipeline configuration.
Definition Sky3D.hpp:142
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
@ NONE
Ignore facing, don't cull primitives based on their winding order.
Definition shaders.hpp:319
@ LESS_OR_EQUAL
The depth test passes if and only if the new depth value is less than or equal to the old depth value...
Definition shaders.hpp:108
vec< 4, float > vec4
Definition math.hpp:440
GREM_ALWAYS_INLINE void lock(Lockable1 &lock1, Lockable2 &lock2, LockableN &... lockN)
Definition synchronization.hpp:1268
Struct of fields output by the default fragment shader.
Definition Cubemap3D.hpp:44
Struct of default vertex shader constants.
Definition Cubemap3D.hpp:36
Struct of fields output by the default vertex shader.
Definition Cubemap3D.hpp:39
Configuration of a graphics pipeline.
Definition shaders.hpp:428
Filter parameters that determine which parts of a sky are drawn.
Definition Sky3D.hpp:272
bool skipSkyRendering
If set, the sky will not be directly rendered, but will still contribute to the lighting of other ren...
Definition Sky3D.hpp:277
Configuration options for a Sky3D.
Definition Sky3D.hpp:27
Color color
Tint color of the skybox.
Definition Sky3D.hpp:31
uint32_t reflectionMapResolution
Desired width, in texels, of the generated reflection cubemap, or 0 to disable specular reflections f...
Definition Sky3D.hpp:66
uint32_t irradianceMapResolution
Desired width, in texels, of the generated irradiance cubemap, or 0 to disable diffuse irradiance fro...
Definition Sky3D.hpp:58
Color reflectionColor
Reflection tint color produced by the skybox.
Definition Sky3D.hpp:41
constexpr bool operator==(const Sky3DOptions &other) const noexcept=default
Compare these options to another set of options for equality.
uint32_t radianceMapResolution
Desired width, in texels, of the generated radiance cubemap, or 0 to choose an appropriate resolution...
Definition Sky3D.hpp:50
Color ambientColor
Ambient light tint color produced by the skybox.
Definition Sky3D.hpp:36
Sky3DView(const Sky3D &sky, const Sky3D::ShaderPipeline &shaderPipelineOverride, const Sky3DFilter &filter={})
Construct a sky view with a shader override.
Definition Sky3D.hpp:310
Sky3DView(const Sky3D &sky, const Sky3DFilter &filter={})
Construct a sky view.
Definition Sky3D.hpp:299
const Sky3D * sky
Non-owning read-only pointer to the sky.
Definition Sky3D.hpp:285
Sky3DFilter filter
Filter parameters that determine which parts of the sky to draw.
Definition Sky3D.hpp:291
SharedPointer< ShaderPipelineImplementation > shaderPipelineOverrideHandle
Shader pipeline override to use, or nullptr to not use a shader override.
Definition Sky3D.hpp:288
Struct of default fragment shader constants.
Definition Sky3D.hpp:93
bool32_t SKY_HDR
Definition Sky3D.hpp:94
Struct of shader parameters representing the sky's appearance.
Definition Sky3D.hpp:101
samplerCube skyRadianceMap
Sampler for the skybox radiance map.
Definition Sky3D.hpp:103
samplerCube skyReflectionMap
Sampler for the skybox reflection map.
Definition Sky3D.hpp:109
vec4 skyAmbientColor
Tint color of the ambient light produced by the skybox.
Definition Sky3D.hpp:115
samplerCube skyIrradianceMap
Sampler for the skybox irradiance map.
Definition Sky3D.hpp:106
vec4 skyReflectionColor
Tint color of the reflections produced by the skybox.
Definition Sky3D.hpp:118
float skyReflectionMapDetailLevelMax
Maximum mip level in the skybox reflection map.
Definition Sky3D.hpp:124
vec4 skyColor
Tint color of the skybox.
Definition Sky3D.hpp:112
float skyReflectionMapDetailLevelScale
Scale of the skybox reflection detail level.
Definition Sky3D.hpp:121
Reference to a samplerCube Texture that may be used as a parameter value type in a shader-read buffer...
Definition ParameterDescription.hpp:163