SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
OpenGLIBL.hpp
Go to the documentation of this file.
1#ifndef OPENGLIBL_HPP_
2#define OPENGLIBL_HPP_
3
4#include <Core/OSDef.hpp>
5#include <glad/glad.h>
6
7namespace Sleak {
8namespace RenderEngine {
9
10class OpenGLShader;
11
12// Image-Based Lighting resources for the OpenGL deferred lighting pass.
13//
14// Precomputes three textures from a source environment cubemap:
15// * irradiance cubemap (diffuse ambient per-direction)
16// * prefiltered env cubemap (specular ambient per-roughness)
17// * BRDF LUT (split-sum term)
18//
19// Precompute runs ONCE (Initialize). Bind() attaches the 3 textures to
20// the texture units expected by lighting_pass_gl.frag.
21class OpenGLIBL {
22public:
23 static constexpr uint32_t IRRADIANCE_SIZE = 32;
24 static constexpr uint32_t PREFILTER_SIZE = 128;
25 static constexpr uint32_t PREFILTER_MIPS = 5;
26 static constexpr uint32_t BRDF_LUT_SIZE = 512;
27
28 // Texture unit slots matched by lighting_pass_gl.frag:
29 static constexpr uint32_t UNIT_IRRADIANCE = 14;
30 static constexpr uint32_t UNIT_PREFILTER = 15;
31 static constexpr uint32_t UNIT_BRDF_LUT = 16;
32
33 OpenGLIBL() = default;
34 ~OpenGLIBL();
35
36 /// Bakes the irradiance map, prefiltered specular map, and BRDF LUT from a source cubemap.
37 bool Initialize(GLuint sourceCubemap);
38 void Cleanup();
39
40 bool IsInitialized() const { return m_initialized; }
41
42 // Bind the 3 IBL textures at the conventional units for the deferred
43 // lighting pass. Caller is responsible for binding the IBL UBO.
44 void Bind() const;
45
46 GLuint IrradianceCubemap() const { return m_irradianceCubemap; }
47 GLuint PrefilterCubemap() const { return m_prefilterCubemap; }
48 GLuint BRDFLUT() const { return m_brdfLUT; }
49
50private:
51 /// Allocates a mipmapped cubemap render target of the given face size.
52 bool CreateCubemapTarget(GLuint& tex, uint32_t size, uint32_t mipLevels);
53 /// Convolves the source cubemap into a diffuse irradiance map.
54 bool BakeIrradiance(GLuint sourceCubemap);
55 /// Prefilters the source cubemap per roughness mip for specular IBL.
56 bool BakePrefilter(GLuint sourceCubemap);
57 /// Renders the split-sum BRDF integration LUT.
58 bool BakeBRDFLUT();
59
60 GLuint m_irradianceCubemap = 0;
61 GLuint m_prefilterCubemap = 0;
62 GLuint m_brdfLUT = 0;
63
64 GLuint m_fbo = 0;
65 GLuint m_rbo = 0;
66 GLuint m_cubeVAO = 0;
67 GLuint m_cubeVBO = 0;
68 GLuint m_quadVAO = 0;
69
70 GLuint m_faceUBO = 0; // mat4 ViewProjection (shared by irradiance / prefilter)
71 GLuint m_prefilterUBO = 0; // mat4 ViewProjection + float Roughness
72
73 OpenGLShader* m_irradianceShader = nullptr;
74 OpenGLShader* m_prefilterShader = nullptr;
75 OpenGLShader* m_brdfShader = nullptr;
76
77 bool m_initialized = false;
78};
79
80} // namespace RenderEngine
81} // namespace Sleak
82
83#endif // OPENGLIBL_HPP_
static constexpr uint32_t UNIT_BRDF_LUT
Definition OpenGLIBL.hpp:31
static constexpr uint32_t PREFILTER_SIZE
Definition OpenGLIBL.hpp:24
static constexpr uint32_t BRDF_LUT_SIZE
Definition OpenGLIBL.hpp:26
static constexpr uint32_t UNIT_PREFILTER
Definition OpenGLIBL.hpp:30
static constexpr uint32_t UNIT_IRRADIANCE
Definition OpenGLIBL.hpp:29
static constexpr uint32_t PREFILTER_MIPS
Definition OpenGLIBL.hpp:25
bool Initialize(GLuint sourceCubemap)
Bakes the irradiance map, prefiltered specular map, and BRDF LUT from a source cubemap.
Definition OpenGLIBL.cpp:95
static constexpr uint32_t IRRADIANCE_SIZE
Definition OpenGLIBL.hpp:23
GLSL shader program compiled from either a combined source file or separate vertex/fragment files.
Backend-facing rendering layer shared by the four graphics backends.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10