src/renderer/shader.h/cpp) for managing OpenGL shader programs.
Shader Class
TheShader class provides a simple interface for shader compilation and uniform management:
Loading and Compilation
Shaders are loaded from disk and compiled at construction:- Error messages are printed to
stdoutwith shader name and error log IDis set to 0 andvalid()returnsfalse- Shader object is safe to destroy
src/renderer/shader.cpp:9-35 for error checking implementation.
Uniform Management
Uniform locations are cached for performance:use() must be called first).
Available Shaders
World Rendering - Colored Lighting
Location:assets/shaders/colored_lighting/
The main shader for rendering voxel geometry with colored lighting and shadows.
Vertex Shader (vert.glsl)
Inputs:
Fragment Shader (frag.glsl)
Uniforms:
assets/shaders/colored_lighting/frag.glsl:23-70 for the complete shadow calculation.
Shadow Rendering
Location:assets/shaders/shadow/
Depth-only shader for shadow map generation.
Vertex Shader (vert.glsl)
Fragment Shader (frag.glsl)
Post-Processing
Location:assets/shaders/post/
Simple fullscreen quad shader for post-processing effects (currently used for framebuffer copy).
UI Rendering
Location:assets/shaders/ui/
Basic shader for UI elements and debug overlays.
Shader Conventions
Naming
- Uniforms: Prefixed with
u_(e.g.,u_MVPMatrix) - Vertex attributes: Prefixed with
a_(e.g.,a_Data0) - Varyings: Prefixed with
v_(e.g.,v_Position)
Version
All shaders use#version 330 or #version 330 core (OpenGL 3.3).
Constants
Shared constants are defined at the top of shaders:Debugging Tips
Black Screen
If blocks render black:- Check
u_TextureArraySampleris set to 0 (texture unit 0) - Verify texture array is bound to
GL_TEXTURE0before rendering - Ensure shader is active when setting uniforms
src/world.cpp:634-636 for correct texture sampler setup.
Shader Compilation Errors
Errors are printed to stdout in format:- Missing uniform declarations
- Type mismatches in uniform/attribute bindings
- GLSL version incompatibilities
Related Pages
- Rendering Overview - Full pipeline description
- Texture Management - Texture array setup
- Shadow Mapping - CSM shader details
- Lighting System - Colored lighting model