Shaders
GLSL shader loading, uniform/attribute location, set_value by type, composition.
Shader reference
GLSL shader loading, uniform + attribute location resolution, per-type set_value, render-texture composition.
Shader lifecycle
Shader.load(vs_path: String, fs_path: String) -> Shader
Category: Lifecycle · raylib: LoadShader
Load vertex + fragment stages from files. Pass "" for either to use raylib's built-in default stage (common for full-screen post-FX).
val fx_grayscale = Shader.load("", "tests/assets/shaders/grayscale.fs")
val fx_invert = Shader.load("", "tests/assets/shaders/invert.fs")
raylib cheatsheet ·
Iron source ·
Test usage
Shader.load_from_memory(vs_code: String, fs_code: String) -> Shader
Category: Lifecycle · raylib: LoadShaderFromMemory
Load shader from inline GLSL strings. Useful for embedded/codegen'd shaders.
val s = Shader.load_from_memory(vs_src, fs_src)
raylib cheatsheet ·
Iron source ·
Test usage
Shader.is_valid(shader) -> Bool / Shader.unload(shader)
Category: Lifecycle · raylib: IsShaderValid / UnloadShader
Validity guard + release GL program object.
if Shader.is_valid(fx_invert) { Shader.unload(fx_invert) }
raylib cheatsheet ·
Iron source ·
Test usage
Locations
Shader.get_location(shader, uniform_name: String) -> Int32
Category: Locations · raylib: GetShaderLocation
Resolve a uniform by name. Returns -1 if the uniform doesn't exist; raylib ignores set_value calls at -1.
val loc_intensity = Shader.get_location(fx_invert, "u_intensity")
raylib cheatsheet ·
Iron source ·
Test usage
Shader.get_location_attrib(shader, attrib_name: String) -> Int32
Category: Locations · raylib: GetShaderLocationAttrib
Resolve per-vertex attribute by name (for custom mesh layouts).
val attr = Shader.get_location_attrib(shader, "a_custom")
raylib cheatsheet ·
Iron source ·
Test usage
Shader.set_location(shader, index: ShaderLocationIndex, loc: Int32)
Category: Locations · raylib: Iron-side helper (no raylib call)
Manually set one of the 30 built-in shader locations in Shader.locs[]. Rare — raylib auto-populates standard locations when you Shader.load.
Shader.set_location(shader, ShaderLocationIndex.MATRIX_MODEL, loc)
raylib cheatsheet ·
Iron source ·
ShaderLocationIndex enum
Shader.set_value(shader, loc: Int32, value: [UInt8], data_type: ShaderUniformDataType)
Category: Uniforms · raylib: SetShaderValue
Write single uniform by byte buffer. Use data_type to tell raylib how to unpack (FLOAT / VEC2 / VEC3 / VEC4 / INT / IVEC2 / IVEC3 / IVEC4 / UINT / UIVEC2 / UIVEC3 / UIVEC4 / SAMPLER2D).
-- Float32(1.0) IEEE-754 LE = [0x00, 0x00, 0x80, 0x3F]
val intensity_bytes: [UInt8] = [UInt8(0), UInt8(0), UInt8(128), UInt8(63)]
Shader.set_value(fx_invert, loc_intensity, intensity_bytes, ShaderUniformDataType.FLOAT)
raylib cheatsheet ·
Iron source ·
Test usage
Shader.set_value_v(shader, loc, values: [UInt8], data_type, count: Int32)
Category: Uniforms · raylib: SetShaderValueV
Uniform array setter — write count elements of data_type starting at loc.
Shader.set_value_v(shader, loc, packed, ShaderUniformDataType.VEC4, Int32(4))
raylib cheatsheet ·
Iron source ·
Test usage
Shader.set_value_matrix(shader, loc: Int32, mat: Matrix)
Category: Uniforms · raylib: SetShaderValueMatrix
Matrix-typed uniform (mat4).
Shader.set_value_matrix(shader, loc_model, Matrix.identity())
raylib cheatsheet ·
Iron source ·
Test usage
Shader.set_value_texture(shader, loc: Int32, tex: Texture)
Category: Uniforms · raylib: SetShaderValueTexture
Bind a sampler2D uniform to a texture handle.
Shader.set_value_texture(shader, loc_bg, background_tex)
raylib cheatsheet ·
Iron source ·
Test usage
Shader mode
Draw.begin_shader_mode(shader: Shader) / end_shader_mode()
Category: Mode · raylib: BeginShaderMode / EndShaderMode (cross-ref to draw2d)
Route subsequent draws through shader's fragment stage. Pair with Draw.begin_texture_mode for RenderTexture composition.
Draw.begin_shader_mode(fx_invert)
Texture.draw_rec(rt.texture, src_rec, Vector2.zero(), WHITE)
Draw.end_shader_mode()
raylib cheatsheet ·
Iron source ·
Test usage
Composition example
Full post-FX pipeline — render 3D scene to an offscreen RenderTexture, then draw that texture full-screen through a fragment shader. See the guide's post-FX tutorial for the step-by-step walkthrough.
-- Pass 1: offscreen 3D render
Draw.begin_texture_mode(rt)
Draw.clear(RAYWHITE)
Draw.begin_mode_3d(cam)
Model.draw(model, origin, Float32(1.0), WHITE)
Draw.end_mode_3d()
Draw.end_texture_mode()
-- Pass 2: draw RenderTexture through post-FX shader
Draw.begin()
Draw.clear(BLACK)
Draw.begin_shader_mode(active_shader)
-- Y-flip via negative-height Rectangle
Texture.draw_rec(
rt.texture,
Rectangle.of(0.0, 0.0, 800.0, -600.0),
Vector2.zero(),
WHITE
)
Draw.end_shader_mode()
Draw.end()
GLSL fragment sources live at tests/assets/shaders/ — grayscale.fs, invert.fs, and friends.
See also