class SFML::Shader

A GLSL shader. Build one from a vertex and/or fragment source (either a file path or a literal source string), then set uniforms with bracket assignment and pass it to draw via the shader: kwarg:

shader = SFML::Shader.from_source(fragment: <<~GLSL) uniform sampler2D texture; uniform float time; void main() { vec2 uv = gl_TexCoord.xy; uv.x += sin(uv.y * 20.0 + time * 3.0) * 0.02; gl_FragColor = texture2D(texture, uv) * gl_Color; } GLSL

shader = clock.elapsed.as_seconds window.draw(sprite, shader: shader)

Uniform types are inferred from the Ruby value: Float / Integer / Numeric β†’ float (uniform float) true / false β†’ bool SFML::Vector2 β†’ vec2 SFML::Vector3 β†’ vec3 SFML::Color β†’ vec4 (normalised RGBA) SFML::Texture β†’ sampler2D :current_texture (Symbol) β†’ sampler2D bound to the drawable’s own texture [a, b] β†’ vec2 (floats) [a, b, c] β†’ vec3 [a, b, c, d] β†’ vec4

Array uniforms (uniform vec2 positions[8]; and friends): [[x, y], [x, y], …] β†’ vec2[] [[x, y, z], …] β†’ vec3[] [[x, y, z, w], …] β†’ vec4[] [Vector2[a, b], …] β†’ vec2[] (also accepts Vector2 / Vector3)

Float arrays (uniform float weights[N];) are ambiguous with vec3 at length 3, so use the explicit set_float_array setter.

Need an int / bvec / matrix uniform? Use set_int, set_ivec2, etc. β€” they exist for completeness.