$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
pbr.h File Reference

Physically-Based Rendering (PBR) and Image-Based Lighting (IBL) utilities. More...

#include "gl_common.h"
Include dependency graph for pbr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PBRSpecUniforms
 Cached uniform locations for specular prefiltering shader. More...
 
struct  PBRIrrUniforms
 Cached uniform locations for radiance convolution shader. More...
 
struct  PBRLumUniforms
 Cached uniform locations for luminance reduction shader. More...
 

Functions

void pbr_get_spec_uniforms (GLuint shader, PBRSpecUniforms *out)
 Retrieves uniform locations for the specular prefilter shader. More...
 
void pbr_get_irr_uniforms (GLuint shader, PBRIrrUniforms *out)
 Retrieves uniform locations for the irradiance convolution shader. More...
 
void pbr_get_lum_uniforms (GLuint shader, PBRLumUniforms *out)
 Retrieves uniform locations for the luminance reduction shader. More...
 
GLuint build_prefiltered_specular_map (GLuint shader, GLuint env_hdr_tex, int width, int height, float threshold)
 Generates a pre-filtered specular environment map in a single pass. More...
 
GLuint pbr_prefilter_init (int width, int height)
 Initializes a texture for progressive specular pre-filtering. More...
 
void pbr_prefilter_mip (GLuint shader, const PBRSpecUniforms *uniforms, GLuint env_hdr_tex, GLuint dest_tex, int width, int height, int level, int total_levels, int slice_index, int total_slices, float threshold)
 Computes a single slice or mip-level for progressive pre-filtering. More...
 
GLuint build_irradiance_map (GLuint shader, GLuint env_hdr_tex, int size, float threshold)
 Generates an irradiance map (diffuse IBL) in a single pass. More...
 
GLuint pbr_irradiance_init (int size)
 Initializes a texture for progressive irradiance computation. More...
 
void pbr_irradiance_slice_compute (GLuint shader, const PBRIrrUniforms *uniforms, GLuint env_hdr_tex, GLuint dest_tex, int size, int slice_index, int total_slices, float threshold)
 Computes one face/slice of the irradiance map. More...
 
GLuint build_brdf_lut_map (int size)
 Generates the 2D BRDF Integration Look-Up Table. More...
 
void compute_mean_luminance_gpu_start (GLuint shader_pass1, GLuint shader_pass2, GLuint hdr_tex, int width, int height, GLuint ssbos[2], const PBRLumUniforms *uniforms)
 Starts the GPU computation for mean luminance (non-blocking). Uses a two-pass parallel reduction via compute shaders and SSBOs. More...
 
float compute_mean_luminance_gpu_result (GLuint ssbos[2], float clamp_multiplier)
 Reads the result of mean luminance computation from the SSBO. This function should be called only after the GPU has finished the computation started by compute_mean_luminance_gpu_start. More...
 

Detailed Description

Physically-Based Rendering (PBR) and Image-Based Lighting (IBL) utilities.

This module handles the generation of pre-filtered environment maps (specular, irradiance, BRDF LUT) and GPU-accelerated luminance computation.

Function Documentation

◆ build_brdf_lut_map()

GLuint build_brdf_lut_map ( int  size)

Generates the 2D BRDF Integration Look-Up Table.

Parameters
sizeLUT resolution (width and height).
Returns
GLuint handle of the 2D RG texture.
Here is the call graph for this function:

◆ build_irradiance_map()

GLuint build_irradiance_map ( GLuint  shader,
GLuint  env_hdr_tex,
int  size,
float  threshold 
)

Generates an irradiance map (diffuse IBL) in a single pass.

Parameters
shaderIrradiance convolution shader.
env_hdr_texSource HDR map.
sizeDestination resolution (width/height).
thresholdLuminance threshold.
Returns
GLuint handle of the irradiance cubemap.
Here is the call graph for this function:

◆ build_prefiltered_specular_map()

GLuint build_prefiltered_specular_map ( GLuint  shader,
GLuint  env_hdr_tex,
int  width,
int  height,
float  threshold 
)

Generates a pre-filtered specular environment map in a single pass.

Parameters
shaderPrefiltering compute shader.
env_hdr_texSource HDR environment map.
widthDestination width.
heightDestination height.
thresholdLuminance threshold for importance sampling.
Returns
GLuint handle of the generated cubemap.
Here is the call graph for this function:

◆ compute_mean_luminance_gpu_result()

float compute_mean_luminance_gpu_result ( GLuint  ssbos[2],
float  clamp_multiplier 
)

Reads the result of mean luminance computation from the SSBO. This function should be called only after the GPU has finished the computation started by compute_mean_luminance_gpu_start.

Parameters
ssbosThe SSBOs used in the computation.
clamp_multiplierMultiplier to apply to the result.
Returns
The computed mean luminance.

◆ compute_mean_luminance_gpu_start()

void compute_mean_luminance_gpu_start ( GLuint  shader_pass1,
GLuint  shader_pass2,
GLuint  hdr_tex,
int  width,
int  height,
GLuint  ssbos[2],
const PBRLumUniforms uniforms 
)

Starts the GPU computation for mean luminance (non-blocking). Uses a two-pass parallel reduction via compute shaders and SSBOs.

Parameters
shader_pass1First reduction pass shader.
shader_pass2Final reduction pass shader.
hdr_texSource HDR texture.
widthTexture width.
heightTexture height.
ssbosPair of SSBO handles for intermediate and final results.
uniformsCached uniform locations for pass 2.

◆ pbr_get_irr_uniforms()

void pbr_get_irr_uniforms ( GLuint  shader,
PBRIrrUniforms out 
)

Retrieves uniform locations for the irradiance convolution shader.

Parameters
shaderThe shader program.
outPointer to the struct to populate.

◆ pbr_get_lum_uniforms()

void pbr_get_lum_uniforms ( GLuint  shader,
PBRLumUniforms out 
)

Retrieves uniform locations for the luminance reduction shader.

Parameters
shaderThe shader program.
outPointer to the struct to populate.

◆ pbr_get_spec_uniforms()

void pbr_get_spec_uniforms ( GLuint  shader,
PBRSpecUniforms out 
)

Retrieves uniform locations for the specular prefilter shader.

Parameters
shaderThe shader program.
outPointer to the struct to populate.

◆ pbr_irradiance_init()

GLuint pbr_irradiance_init ( int  size)

Initializes a texture for progressive irradiance computation.

Parameters
sizeDestination resolution.
Returns
GLuint handle of the empty cubemap.
Here is the call graph for this function:

◆ pbr_irradiance_slice_compute()

void pbr_irradiance_slice_compute ( GLuint  shader,
const PBRIrrUniforms uniforms,
GLuint  env_hdr_tex,
GLuint  dest_tex,
int  size,
int  slice_index,
int  total_slices,
float  threshold 
)

Computes one face/slice of the irradiance map.

Parameters
shaderCompute shader.
uniformsCached uniform locations.
env_hdr_texSource HDR map.
dest_texDestination cubemap.
sizeResolution.
slice_indexCurrent face.
total_slicesTotal faces.
thresholdLuminance threshold.
Note
This function does NOT issue a memory barrier. The caller must call glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT) once after all slices have been dispatched.

◆ pbr_prefilter_init()

GLuint pbr_prefilter_init ( int  width,
int  height 
)

Initializes a texture for progressive specular pre-filtering.

Parameters
widthBase level width.
heightBase level height.
Returns
GLuint handle of the empty cubemap with allocated mips.
Here is the call graph for this function:

◆ pbr_prefilter_mip()

void pbr_prefilter_mip ( GLuint  shader,
const PBRSpecUniforms uniforms,
GLuint  env_hdr_tex,
GLuint  dest_tex,
int  width,
int  height,
int  level,
int  total_levels,
int  slice_index,
int  total_slices,
float  threshold 
)

Computes a single slice or mip-level for progressive pre-filtering.

Parameters
shaderCompute shader.
uniformsCached uniform locations.
env_hdr_texSource HDR map.
dest_texDestination cubemap.
widthCurrent level width.
heightCurrent level height.
levelCurrent mip level being processed.
total_levelsTotal number of mips in the cubemap.
slice_indexCurrent face/slice being processed.
total_slicesTotal slices (usually 6).
thresholdLuminance threshold.
Note
This function does NOT issue a memory barrier. The caller must call glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT) once after all slices have been dispatched.