SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
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
7
namespace
Sleak
{
8
namespace
RenderEngine
{
9
10
class
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.
21
class
OpenGLIBL
{
22
public
:
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
50
private
:
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_
OSDef.hpp
Sleak::RenderEngine::OpenGLIBL::UNIT_BRDF_LUT
static constexpr uint32_t UNIT_BRDF_LUT
Definition
OpenGLIBL.hpp:31
Sleak::RenderEngine::OpenGLIBL::PREFILTER_SIZE
static constexpr uint32_t PREFILTER_SIZE
Definition
OpenGLIBL.hpp:24
Sleak::RenderEngine::OpenGLIBL::BRDF_LUT_SIZE
static constexpr uint32_t BRDF_LUT_SIZE
Definition
OpenGLIBL.hpp:26
Sleak::RenderEngine::OpenGLIBL::PrefilterCubemap
GLuint PrefilterCubemap() const
Definition
OpenGLIBL.hpp:47
Sleak::RenderEngine::OpenGLIBL::UNIT_PREFILTER
static constexpr uint32_t UNIT_PREFILTER
Definition
OpenGLIBL.hpp:30
Sleak::RenderEngine::OpenGLIBL::UNIT_IRRADIANCE
static constexpr uint32_t UNIT_IRRADIANCE
Definition
OpenGLIBL.hpp:29
Sleak::RenderEngine::OpenGLIBL::Cleanup
void Cleanup()
Definition
OpenGLIBL.cpp:60
Sleak::RenderEngine::OpenGLIBL::PREFILTER_MIPS
static constexpr uint32_t PREFILTER_MIPS
Definition
OpenGLIBL.hpp:25
Sleak::RenderEngine::OpenGLIBL::Initialize
bool Initialize(GLuint sourceCubemap)
Bakes the irradiance map, prefiltered specular map, and BRDF LUT from a source cubemap.
Definition
OpenGLIBL.cpp:95
Sleak::RenderEngine::OpenGLIBL::IsInitialized
bool IsInitialized() const
Definition
OpenGLIBL.hpp:40
Sleak::RenderEngine::OpenGLIBL::Bind
void Bind() const
Definition
OpenGLIBL.cpp:332
Sleak::RenderEngine::OpenGLIBL::OpenGLIBL
OpenGLIBL()=default
Sleak::RenderEngine::OpenGLIBL::BRDFLUT
GLuint BRDFLUT() const
Definition
OpenGLIBL.hpp:48
Sleak::RenderEngine::OpenGLIBL::IRRADIANCE_SIZE
static constexpr uint32_t IRRADIANCE_SIZE
Definition
OpenGLIBL.hpp:23
Sleak::RenderEngine::OpenGLIBL::IrradianceCubemap
GLuint IrradianceCubemap() const
Definition
OpenGLIBL.hpp:46
Sleak::RenderEngine::OpenGLShader
GLSL shader program compiled from either a combined source file or separate vertex/fragment files.
Definition
OpenGLShader.hpp:11
Sleak::RenderEngine
Backend-facing rendering layer shared by the four graphics backends.
Definition
Application.hpp:60
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
include
private
Graphics
OpenGL
OpenGLIBL.hpp
Generated on
for SleakEngine by
1.18.0