GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
Fog3D.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_FOG_3D_HPP
5#define GREM_GRAPHICS_3D_FOG_3D_HPP
6
8
12#include <GREM/core/math.hpp>
16
17namespace grem::graphics {
18
19class Device; // Forward declaration, to avoid including Device.hpp.
20class Renderer3D; // Forward declaration, to avoid a circular include of Renderer3D.hpp.
21
31 float startDistance = 0.0f;
32
39 float endDistance = 1000.0f;
40
46
52 vec3 skyFadeDirection{0.0f, 1.0f, 0.0f};
53
61 float skyFadeMinAngle = 1.4835299f; // 85 degrees.
62
70 float skyFadeMaxAngle = 1.5707963f; // 90 degrees.
71
79 [[nodiscard]] constexpr bool operator==(const Fog3DOptions& other) const noexcept = default;
80};
81
85class Fog3D {
86public:
113
115 using ParameterBuffer = UniformBuffer<Parameters, "Fog3DParameters">;
116
123 GREM_API(graphics_3d) explicit Fog3D(Device& device, const Fog3DOptions& options = {});
124
135 GREM_API(graphics_3d) void setFog(const Fog3DOptions& newFogOptions);
136
142 [[nodiscard]] Fog3DOptions getOptions() const noexcept {
143 return options;
144 }
145
146private:
147 friend Renderer3D;
148
149 GREM_API(graphics_3d) void flush() const;
150
151 Fog3DOptions options;
152 mutable ParameterBuffer parameterBuffer;
153 mutable bool parameterBufferDirty = true;
154};
155
156} // namespace grem::graphics
157
158#endif
Floating-point linear RGBA color in the Rec.
Definition Color.hpp:60
static const Color INVISIBLE
Definition Color.hpp:70
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
void setFog(const Fog3DOptions &newFogOptions)
Set the fog parameters.
Fog3D(Device &device, const Fog3DOptions &options={})
Construct a fog.
UniformBuffer< Parameters, "Fog3DParameters"> ParameterBuffer
Shader buffer for fog parameters.
Definition Fog3D.hpp:115
Fog3DOptions getOptions() const noexcept
Get the configuration options of the fog.
Definition Fog3D.hpp:142
Persistent system that provides 3D rendering capabilities.
Definition Renderer3D.hpp:120
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
vec< 4, float > vec4
Definition math.hpp:440
vec< 3, float > vec3
Definition math.hpp:439
Configuration options for a Fog3D.
Definition Fog3D.hpp:25
vec3 skyFadeDirection
Direction in which the fog gradually fades out to reveal the skybox according to skyFadeMinAngle and ...
Definition Fog3D.hpp:52
float endDistance
Distance from the camera's position to where fog reaches its maximum density.
Definition Fog3D.hpp:39
float startDistance
Distance from the camera's position to where visible fog starts.
Definition Fog3D.hpp:31
constexpr bool operator==(const Fog3DOptions &other) const noexcept=default
Compare these options to another set of options for equality.
Color color
Color of the fog, where the alpha component represents the fraction of the maximum density reached by...
Definition Fog3D.hpp:45
float skyFadeMaxAngle
Angle from skyFadeDirection, in radians, at which fog reaches its maximum density in the skybox.
Definition Fog3D.hpp:70
float skyFadeMinAngle
Angle from skyFadeDirection, in radians, at which fog starts to appear in the skybox.
Definition Fog3D.hpp:61
Struct of shader parameters representing the fog's appearance.
Definition Fog3D.hpp:88
vec3 fogSkyFadeDirection
Direction in which the fog gradually fades out to reveal the skybox (typically towards the sky).
Definition Fog3D.hpp:111
vec4 fogColorAndMaxDensity
Color (XYZ) and fraction of maximum density (W) reached by fog at its end distance.
Definition Fog3D.hpp:105
vec4 fogStartAndEndDistancesAndSkyFadeMinAndMaxAngleCosines
Distance from the camera's position to where visible fog starts (X) and to where it reaches its maxim...
Definition Fog3D.hpp:99