Skip to main content

Core Shaders


This section provides detailed documentation about Brakeza3D's internal shaders. These shaders power the engine's rendering pipeline and can be found in the /GLSL folder.

warning

Modifying core shaders requires a solid understanding of GLSL and the rendering pipeline. Incorrect changes may cause visual artifacts or crashes.

Shader Architecture


Brakeza3D uses a combination of forward and deferred rendering techniques. Each shader consists of:

  • Vertex Shader (.vs): Transforms vertices and passes data to the fragment shader
  • Fragment Shader (.fs): Calculates the final pixel color

Mesh/Object Shaders


These shaders handle the rendering of 3D objects in the scene.

ShaderFilesDescription
RenderRender.vs / Render.fsMain forward rendering shader for Mesh3D objects. Handles lighting, textures, and material properties
GBufferGBuffer.vs / GBuffer.fsGeometry buffer pass for deferred rendering. Outputs position, normal, and albedo to multiple render targets
LightingPassLightingPass.vs / LightingPass.fsDeferred lighting calculations using G-buffer data
OutlinerOutliner.vs / Outliner.fsRenders a colored outline around selected objects in the editor
ColorColor.vs / Color.fsRenders a Mesh3D with a solid color (no textures)
WireframeWireframe.vs / Wireframe.fsRenders object edges as wireframe
PointsPoints.vs / Points.fsRenders vertices as points
ShadingShading.vs / Shading.fsRenders an object to a buffer for use as a mask

2D/Utility Shaders


ShaderFilesDescription
ImageImage.vs / Image.fsRenders 2D images on screen (Image2D objects)
LineLine.vs / Line.fsDraws 2D lines on screen
Line3DLine3D.vs / Line3D.fsDraws 3D lines in world space (used for debugging)
GridGrid.vs / Grid.fsRenders the editor grid
ParticleParticle.vs / Particle.fsRenders particles for ParticleEmitter objects

Shadow Shaders


ShaderFilesDescription
ShadowPassShadowPass.vs / ShadowPass.fsGenerates shadow maps from light perspective
ShadowPassDebugLightShadowPassDebugLight.vs / ShadowPassDebugLight.fsVisualizes shadow maps for debugging
DepthMapDepthMap.vs / DepthMap.fsRenders scene depth information

Post-Processing Shaders


ShaderFilesDescription
DeepOfFieldDeepOfField.vs / DeepOfField.fsDepth of field blur effect based on distance from focus
FOGFOG.vs / FOG.fsDistance-based fog effect
TintTint.vs / Tint.fsApplies a color tint with alpha blending to the entire screen

Animation Shaders


ShaderFilesDescription
BonesTransformsBonesTransforms.vsHandles skeletal animation bone transformations

Common Uniforms


Most shaders receive these standard uniforms from the engine:

Transformation Matrices

UniformTypeDescription
modelmat4Model matrix (object to world space)
viewmat4View matrix (world to camera space)
projectionmat4Projection matrix (camera to clip space)

Lighting Uniforms

UniformTypeDescription
viewPosvec3Camera position in world space
lightDirectionvec3Global directional light direction
ambientColorvec3Global ambient light color
diffuseColorvec3Global diffuse light color
specularColorvec3Global specular light color

Time Uniforms

UniformTypeDescription
u_TimefloatCurrent time (for animated effects)
delta_timefloatTime since last frame
execution_timefloatTotal execution time

Shared Code


The /GLSL/Shared folder contains common GLSL functions that can be included in multiple shaders:

  • Lighting calculations
  • Shadow sampling functions
  • Utility functions

Modifying Core Shaders


If you need to modify core shaders:

  1. Backup first: Copy the original shader before making changes
  2. Test incrementally: Make small changes and test frequently
  3. Check console: Shader compilation errors appear in the log
  4. Use debug mode: Enable visual debugging to verify changes

Example: Adding a Custom Effect to Render.fs

// In Render.fs, after calculating finalColor:

// Custom desaturation effect
float gray = dot(finalColor.rgb, vec3(0.299, 0.587, 0.114));
finalColor.rgb = mix(finalColor.rgb, vec3(gray), 0.5); // 50% desaturation

Performance Considerations


  • Minimize texture samples: Each texture() call has a cost
  • Avoid branching: Use mix() and step() instead of if statements
  • Use appropriate precision: mediump for colors, highp for positions
  • Batch similar operations: Calculate common values once and reuse