Overview
Atlas Engine provides a flexible shader system that supports custom GLSL shaders compiled for multiple graphics backends. The engine automatically translates shaders for OpenGL, Vulkan, and Metal through the Opal abstraction layer.Shader Architecture
The shader system consists of several components:- VertexShader: Transforms vertex positions and passes data to fragment shaders
- FragmentShader: Computes per-pixel colors and lighting
- GeometryShader: Optional stage for generating primitives
- TessellationShader: Optional stages for adaptive mesh refinement
- ShaderProgram: Links shader stages into a complete rendering pipeline
Creating Custom Shaders
Vertex Shader Example
Fragment Shader Example
Complete Shader Program
Using Default Shaders
Atlas provides many built-in shaders for common rendering tasks:Available Default Vertex Shaders
Debug
Debug
Outputs solid magenta color for debugging visibility.
Color
Color
Renders solid colors with per-vertex color attributes.
Main
Main
Full PBR shader supporting lighting, textures, normals, and materials.
Texture
Texture
Basic textured object rendering.
Skybox
Skybox
Cubemap sampling for environment rendering.
Particle
Particle
Efficient particle system rendering.
Terrain
Terrain
Tessellated terrain with displacement mapping.
Volumetric
Volumetric
Volumetric light scattering effects.
Available Default Fragment Shaders
Main
Main
PBR shading with support for:
- Multiple light types (directional, point, spot, area)
- Shadow mapping
- Normal mapping and parallax occlusion
- Metallic/roughness workflow
- Image-based lighting (IBL)
- ACES tone mapping
Deferred
Deferred
G-buffer output for deferred rendering pipeline.
SSAO
SSAO
Screen-space ambient occlusion calculation.
GaussianBlur
GaussianBlur
Multi-pass blur for post-processing.
Downsample/Upsample
Downsample/Upsample
Bloom texture chain processing.
Shader Capabilities
Shaders can declare capabilities that inform the rendering pipeline:Available Capabilities
Lighting- Handles lighting calculationsTextures- Supports texture mappingShadows- Implements shadow mappingEnvironmentMapping- Cube map reflectionsIBL- Image-based lightingDeferred- Deferred rendering G-bufferMaterial- Material property supportInstances- Instanced renderingEnvironment- Fog and rim lighting
Advanced Features
Tessellation Shaders
Geometry Shaders
Cross-Platform Compilation
Atlas automatically compiles shaders for the active graphics backend:
The engine handles all backend-specific details through the Opal abstraction layer:
Shader Caching
The engine caches compiled shaders to avoid recompilation:Uniform Management
Set shader uniforms with type-safe methods:Real-World Example: Main Fragment Shader
The built-in Main fragment shader demonstrates advanced features:- PBR lighting with GGX distribution
- Multiple light types (directional, point, spot, area)
- Cascaded shadow mapping with PCF filtering
- Normal mapping and parallax occlusion mapping
- Metallic-roughness material workflow
- Image-based lighting with HDR environment maps
- Rim lighting effects
- ACES tone mapping
- OpenGL:
shaders/opengl/main.frag(shader.h:278) - Vulkan:
shaders/vulkan/main.frag(shader.h:278) - Metal:
shaders/metal/main.frag.metal(shader.h:278)
Best Practices
Use Default Shaders
Start with built-in shaders for common tasks before writing custom ones
Declare Capabilities
Set shader capabilities to enable pipeline optimizations
Cache Aggressively
Reuse ShaderProgram instances to avoid recompilation
Test All Backends
Verify custom shaders work on OpenGL, Vulkan, and Metal
Shader compilation happens through the Opal abstraction layer, which automatically handles backend-specific details like descriptor sets, uniform buffers, and resource bindings.