Shader
Represents a GPU shader program for custom rendering effects.
Shaders are programs that run on the GPU to transform vertices and calculate pixel colors. Ceramic uses shaders for all rendering, from basic sprite drawing to complex visual effects.
Key features:
- Support for vertex and fragment shaders
- Uniform variables for passing data to shaders
- Multiple texture slot support
- Custom vertex attributes
- Automatic shader compilation and linking
Common uses:
- Visual effects (blur, glow, distortion)
- Color manipulation (hue shift, contrast)
- Custom rendering techniques
- Post-processing filters
- Special material effects
Ceramic provides several built-in shaders:
- 'shader:textured' - Standard textured rendering (default)
- 'shader:pixelArt' - High-quality pixel art scaling
- Various effect shaders depending on plugins
// Load and apply a custom shader
var shader = assets.shader('myEffect').clone();
shader.setFloat('intensity', 0.5);
shader.setVec2('resolution', screen.width, screen.height);
myVisual.shader = shader;
// Animate shader uniforms
app.onUpdate(this, delta -> {
shader.setFloat('time', Timer.now);
shader.setColor('tint', Color.fromHSB(
(Timer.now * 60) % 360, 1, 1
));
});
Instance Members
backendItem: backend.ShaderThe backend-specific shader implementation. Used internally by the rendering system.
asset: ShaderAssetThe shader asset this shader was loaded from. Null if created programmatically.
attributes: ReadOnlyArray<ShaderAttribute>All vertex attributes used by this shader (except texture slot attribute) Includes standard attributes (position, texCoord, color) plus any custom attributes.
baseAttributes: ReadOnlyArray<ShaderAttribute>Base standard vertex attributes (position, texCoord, color), without any custom attribute.
customAttributes: ReadOnlyArray<ShaderAttribute>Custom vertex attributes beyond the standard ones. Used for passing additional per-vertex data to shaders.
textureIdAttribute: ShaderAttributeVertex attribute used to store texture slot (if the shader is a multi-texture shader).
customFloatAttributesSize: IntTotal size of custom float attributes in the vertex buffer. Calculated from customAttributes array.
destroy(): Voidclone(): ShaderCreates a copy of this shader with independent uniform values.
Useful when you need multiple instances of the same shader with different parameters.
| Returns | Description |
|---|---|
| Shader | A new shader instance with the same program but separate uniforms |
Sets an integer uniform variable.
| Name | Type | Description |
|---|---|---|
name |
String | The uniform variable name in the shader |
value |
Int | The integer value to set |
Sets a float uniform variable.
| Name | Type | Description |
|---|---|---|
name |
String | The uniform variable name in the shader |
value |
Float | The float value to set |
Sets a vec2 uniform variable.
| Name | Type | Description |
|---|---|---|
name |
String | The uniform variable name in the shader |
x |
Float | The x component |
y |
Float | The y component |
Sets a vec3 uniform variable.
| Name | Type | Description |
|---|---|---|
name |
String | The uniform variable name in the shader |
x |
Float | The x component |
y |
Float | The y component |
z |
Float | The z component |
Sets a vec4 uniform variable.
| Name | Type | Description |
|---|---|---|
name |
String | The uniform variable name in the shader |
x |
Float | The x component |
y |
Float | The y component |
z |
Float | The z component |
w |
Float | The w component |
Sets a float array uniform variable. Useful for passing multiple values or matrices.
| Name | Type | Description |
|---|---|---|
name |
String | The uniform variable name in the shader |
array |
Array<Float> | The array of float values |
Sets a texture uniform variable.
Textures are bound to numbered slots (0, 1, 2, etc.). Slot 0 is typically used for the main texture.
| Name | Type | Default | Description |
|---|---|---|---|
name |
String | The uniform sampler2D variable name in the shader | |
slot |
Int | -1 |
The texture slot index (0-based) |
texture |
Texture | The texture to bind, or null to unbind |
Sets a mat2 uniform variable (column-major order).
| Name | Type | Description |
|---|---|---|
name |
String | The uniform mat2 variable name in the shader |
m00 |
Float | Column 0, row 0 |
m10 |
Float | Column 0, row 1 |
m01 |
Float | Column 1, row 0 |
m11 |
Float | Column 1, row 1 |
setMat3(name: String, m00: Float, m10: Float, m20: Float, m01: Float, m11: Float, m21: Float, m02: Float, m12: Float, m22: Float): VoidSets a mat3 uniform variable (column-major order).
| Name | Type | Description |
|---|---|---|
name |
String | The uniform mat3 variable name in the shader |
m00 |
Float | Column 0, row 0 |
m10 |
Float | Column 0, row 1 |
m20 |
Float | Column 0, row 2 |
m01 |
Float | Column 1, row 0 |
m11 |
Float | Column 1, row 1 |
m21 |
Float | Column 1, row 2 |
m02 |
Float | Column 2, row 0 |
m12 |
Float | Column 2, row 1 |
m22 |
Float | Column 2, row 2 |
setMat4(name: String, m00: Float, m10: Float, m20: Float, m30: Float, m01: Float, m11: Float, m21: Float, m31: Float, m02: Float, m12: Float, m22: Float, m32: Float, m03: Float, m13: Float, m23: Float, m33: Float): VoidSets a mat4 uniform variable (column-major order).
| Name | Type | Description |
|---|---|---|
name |
String | The uniform mat4 variable name in the shader |
m00 |
Float | Column 0, row 0 |
m10 |
Float | Column 0, row 1 |
m20 |
Float | Column 0, row 2 |
m30 |
Float | Column 0, row 3 |
m01 |
Float | Column 1, row 0 |
m11 |
Float | Column 1, row 1 |
m21 |
Float | Column 1, row 2 |
m31 |
Float | Column 1, row 3 |
m02 |
Float | Column 2, row 0 |
m12 |
Float | Column 2, row 1 |
m22 |
Float | Column 2, row 2 |
m32 |
Float | Column 2, row 3 |
m03 |
Float | Column 3, row 0 |
m13 |
Float | Column 3, row 1 |
m23 |
Float | Column 3, row 2 |
m33 |
Float | Column 3, row 3 |
new(customAttributes: ReadOnlyArray<ShaderAttribute>, baseAttributes: ReadOnlyArray<ShaderAttribute>, textureIdAttribute: ShaderAttribute): VoidCreates a new shader instance.
Standard vertex attributes are automatically included:
- vertexPosition (vec3): Vertex position in model space
- vertexTCoord (vec2): Texture coordinates
- vertexColor (vec4): Vertex color with alpha
| Name | Type | Description |
|---|---|---|
customAttributes |
ReadOnlyArray<ShaderAttribute> | Optional additional vertex attributes |
baseAttributes |
ReadOnlyArray<ShaderAttribute> | |
textureIdAttribute |
ShaderAttribute |
Private Members
Resolve the texture slot for the given name
| Name | Type | Description |
|---|---|---|
name |
String | The name of the texture uniform |
| Returns | Description |
|---|---|
| Int | The slot or -1 if not found. |
toString(): String| Returns |
|---|
| String |
Metadata
| Name | Parameters |
|---|---|
:hxGen |
- |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |