vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
environment.h
1#pragma once
2
3#include <cstdint>
4#include <string>
5
6#include <glm/glm.hpp>
7
8#include "core/reflect.h"
9#include "ecs/component/render/light.h"
10
11namespace Vkm::Engine {
12
17 std::string hdrPath;
18 float intensity = 1.0f;
19 bool showSkybox = true;
20
21 // A Rayleigh, Mie and ozone atmosphere baked into the IBL in place of hdrPath,
22 // lit by the sun authored further down; on by default so a scene is lit before it owns
23 // any assets.
24 bool procedural = true;
25 float rayleigh = 1.0f;
26 float mie = 5.0f;
27 float mieG = 0.76f;
30 float sunDiscIntensity = 5.0f;
33 float aerialPerspective = 1.0f;
34
35 // SkySystem aims the key light from these, so the drawn sun and the shadows agree.
36 float sunElevation = 50.0f;
37 float sunAzimuth = 30.0f;
38
39 // The sun: the key light's daylight end, which SkySystem blends with the moonlight,
40 // and what lights the sky (Atmosphere::solarIlluminance). The Light's own colour and
41 // intensity are unused under the procedural sky.
42 glm::vec3 lightColor = {1.0f, 0.96f, 0.90f};
43 float lightIntensity = 3.0f;
44
46 static constexpr float MAX_MIE_G = 0.99f;
47};
48
57 glm::vec3 radiance = {0.004f, 0.006f, 0.014f};
58 float moonTilt = 15.0f;
59 float moonAngularRadius = 0.03f;
60 float moonIntensity = 1.2f;
61 float starIntensity = 3.0f;
62 float starDensity = 140.0f;
63
64 // The key light aimed at the moon once the sun is down, so night has
65 // direction, shadows and speculars.
66 glm::vec3 moonlightColor = {0.55f, 0.65f, 1.0f};
67 float moonlightIntensity = 0.12f;
68
74 static constexpr float TWILIGHT_DEGREES = 8.0f;
75};
76
82 bool enabled = false;
83 float density = 0.03f;
84 float height = 5.0f;
85 float heightFalloff = 0.15f;
86 float anisotropy = 0.7f;
87 glm::vec3 albedo = {0.8f, 0.85f, 1.0f};
88 uint32_t resolutionX = 160;
89 uint32_t resolutionY = 90;
90 uint32_t resolutionZ = 64;
98
100 static constexpr float MAX_ANISOTROPY = 0.95f;
101
102 static constexpr uint32_t MIN_FROXELS = 16;
103 static constexpr uint32_t MAX_FROXELS = 512;
109 static constexpr uint32_t MAX_FROXEL_COUNT = 1u << 22;
110
118 glm::uvec3 froxelGrid() const;
119};
120
126struct SkyAngles {
127 float elevation = 0.0f;
128 float azimuth = 0.0f;
129};
130
138 SkySettings sky;
139 NightSkySettings night;
140 FogSettings fog;
141
148 return {sky.sunElevation, sky.sunAzimuth};
149 }
150
159 return {-sky.sunElevation + night.moonTilt, sky.sunAzimuth + 180.0f};
160 }
161
169 glm::vec3 sunDirection() const {
170 const SkyAngles a = sunAngles();
172 }
173
179 glm::vec3 moonDirection() const {
180 const SkyAngles a = moonAngles();
182 }
183
191 static glm::vec3 directionFromAngles(float elevationDeg, float azimuthDeg);
192};
193
194} // namespace Vkm::Engine
195
196VKM_REFLECT_BEGIN(::Vkm::Engine::SkySettings)
197 VKM_F(hdrPath)
198 VKM_F(intensity)
199 VKM_F(showSkybox)
200 VKM_F(procedural)
201 VKM_F(rayleigh)
202 VKM_F(mie)
203 VKM_F(mieG)
204 VKM_F(sunDiscIntensity)
205 VKM_F(aerialPerspective)
206 VKM_F(sunElevation)
207 VKM_F(sunAzimuth)
208 VKM_F(lightColor)
209 VKM_F(lightIntensity)
210VKM_REFLECT_END()
211
212VKM_REFLECT_BEGIN(::Vkm::Engine::NightSkySettings)
213 VKM_F(radiance)
214 VKM_F(moonTilt)
215 VKM_F(moonAngularRadius)
216 VKM_F(moonIntensity)
217 VKM_F(starIntensity)
218 VKM_F(starDensity)
219 VKM_F(moonlightColor)
220 VKM_F(moonlightIntensity)
221VKM_REFLECT_END()
222
223VKM_REFLECT_BEGIN(::Vkm::Engine::FogSettings)
224 VKM_F(enabled)
225 VKM_F(density)
226 VKM_F(height)
227 VKM_F(heightFalloff)
228 VKM_F(anisotropy)
229 VKM_F(albedo)
230 VKM_F(resolutionX)
231 VKM_F(resolutionY)
232 VKM_F(resolutionZ)
233 VKM_F(maxDistance)
234VKM_REFLECT_END()
235
236VKM_REFLECT_BEGIN(::Vkm::Engine::Environment)
237 VKM_F(sky)
238 VKM_F(night)
239 VKM_F(fog)
240VKM_REFLECT_END()
The scene's lighting environment: sky, night sky and fog.
Definition environment.h:137
SkyAngles moonAngles() const
Where the moon sits: opposite the sun, tilted off that axis.
Definition environment.h:158
SkyAngles sunAngles() const
Where the sun sits, straight off the authored fields.
Definition environment.h:147
static glm::vec3 directionFromAngles(float elevationDeg, float azimuthDeg)
Unit direction for an elevation/azimuth pair, both in degrees.
glm::vec3 moonDirection() const
Direction TO the moon.
Definition environment.h:179
glm::vec3 sunDirection() const
Direction TO the sun from the authored angles.
Definition environment.h:169
Froxel volumetric fog: a compute pass scatters the scene lights through a height-falloff medium and a...
Definition environment.h:81
static constexpr uint32_t MAX_FROXEL_COUNT
The most froxels the whole grid holds; a grid over it is scaled down evenly.
Definition environment.h:109
glm::vec3 albedo
Scattering tint.
Definition environment.h:87
uint32_t resolutionX
Screen tiles; higher = sharper shafts.
Definition environment.h:88
uint32_t resolutionY
Screen tiles.
Definition environment.h:89
float maxDistance
How far from the eye the slices reach, in metres.
Definition environment.h:97
float density
Base extinction at height.
Definition environment.h:83
glm::uvec3 froxelGrid() const
The grid the volume is allocated at: the authored one, bounded.
static constexpr uint32_t MAX_FROXELS
Per axis.
Definition environment.h:103
static constexpr uint32_t MIN_FROXELS
Per axis.
Definition environment.h:102
float heightFalloff
Density e-folding per world unit above height.
Definition environment.h:85
float height
World Y where the medium is densest.
Definition environment.h:84
uint32_t resolutionZ
Exponential slices.
Definition environment.h:90
float anisotropy
Henyey-Greenstein g, within MAX_ANISOTROPY.
Definition environment.h:86
static constexpr float MAX_ANISOTROPY
At +-1 the phase function divides zero by zero.
Definition environment.h:100
Component representing a light source in the scene.
Definition light.h:36
float shadowDistance
Directional only: world distance the cascades cover.
Definition light.h:69
What the sky is once the sun is down.
Definition environment.h:55
float starDensity
Higher packs more, smaller stars.
Definition environment.h:62
float moonIntensity
Disc radiance; its halo follows.
Definition environment.h:60
static constexpr float TWILIGHT_DEGREES
Degrees either side of the horizon across which day hands over to night.
Definition environment.h:74
glm::vec3 radiance
Skyglow the scene is lit by, so night is dark, not black.
Definition environment.h:57
float moonTilt
Degrees off directly opposite the sun.
Definition environment.h:58
float starIntensity
0 disables; the default clears the bloom threshold.
Definition environment.h:61
float moonAngularRadius
Radians.
Definition environment.h:59
Where a celestial body sits, in the authored angle form.
Definition environment.h:126
float elevation
Degrees above the horizon. Negative is below it.
Definition environment.h:127
float azimuth
Degrees around the horizon, from +Z toward +X.
Definition environment.h:128
Sky and image-based lighting: what the world is lit by and set against.
Definition environment.h:16
float lightIntensity
Illuminance with the sun overhead.
Definition environment.h:43
float sunAzimuth
Degrees around the horizon, from +Z toward +X.
Definition environment.h:37
float aerialPerspective
Definition environment.h:33
float rayleigh
Blue-sky scattering scale.
Definition environment.h:25
glm::vec3 lightColor
With the sun overhead.
Definition environment.h:42
static constexpr float MAX_MIE_G
At 1 the phase function divides zero by zero.
Definition environment.h:46
float sunDiscIntensity
Definition environment.h:30
float mie
Haze / sun glow scattering scale; 1 is pristine air.
Definition environment.h:26
std::string hdrPath
Equirect HDR baked into IBL + skybox; empty = none.
Definition environment.h:17
float sunElevation
Degrees above the horizon. Negative is night.
Definition environment.h:36
float intensity
Indirect-lighting + skybox brightness.
Definition environment.h:18
float mieG
Definition environment.h:27
bool showSkybox
The IBL still lights the scene when off.
Definition environment.h:19