Aego Русский

Materials and shaders

A material is a shared asset. Assign it to SpriteRenderer or Mesh2D, then add MaterialOverride for values that belong to one node. The effective value is the shader default, then an explicit material value, then an explicit node override. Play and preview own separate node state.

On this page

Create and edit

  1. Choose Shader, Material, or Material from Shader in the searchable Create palette. The editable sources are .aeshader and .aemat.
  2. Select the material in Assets and choose its shader, variant, blend, parameters and textures. Saving a shared material affects every consumer of that asset.
  3. Assign it to the intended SpriteRenderer or Mesh2D. Save the material source and the scene containing that assignment separately.
  4. Add Material Override when only this node should differ. Change a declared instance parameter, compare a second node using the same material, then use Reset to restore inheritance.

The material source and its Inspector share one undo history. Dragging one parameter produces one undo step. Reset restores inheritance even when an explicit value happened to equal the inherited value; it is not an assignment of zero.

Select a sprite, assign its Material field and add Material Override. Only numerical parameters marked @instance can be overridden. Textures, variants and blend belong to the material asset. Removed fields remain serialized as unknown values; unresolved references keep their AssetID.

Portable shader

Author GLSL 330 with Aego metadata. The importer prepares and validates GLSL 330 and GLSL ES 3.00 sources. It resolves engine/ includes and project includes below assets/shaders/include/. Public fields come from declarations, so an optimized-out parameter stays in the Inspector.

#pragma aego abi 1
#pragma domain sprite
#include "engine/sprite.glsl"
#pragma material
uniform float Opacity; // @instance @default(1) @range(0, 1)
#pragma end
void fragment() {
    aego_out = aego_sample() * Opacity;
}

aego_sample() already returns linear, premultiplied color. Additional opacity scales the entire returned vec4 once. Ordinary vec4 values are numerical; only parameters marked @color use Color semantics. Sample a separate noise texture with aego_local, independent of the sprite's atlas location. aego_sample_at clamps to this sprite's region and returns transparent outside it.

Sprite and Mesh2D are separate shader domains. A material must match its consumer's vertex layout. Frame time belongs to the current world, View data to the current camera, and material values to their committed revision. A custom vertex stage disables CPU culling for its Sprite or Mesh2D consumer. The CPU does not analyze GLSL to guess vertex displacement bounds.

Animate and reload

Tween and Animation address a declared instance parameter through a property path. The final segment is the parameter's name from the shader schema, for example:

MaterialOverride.Flash
MaterialOverride.Threshold

Bindings refresh when a committed layout generation changes. Numeric integer animation keys retain signed integer precision; float tweens use float interpolation.

Save a shader or an include to import a candidate. Compile, link, layout validation and dependent material migration must all succeed before the next generation is committed at a frame boundary. An error retains the previous program, schema and values. The Problems panel opens the original source or include line; a column is omitted when the compiler did not provide one.

A failed current shader blocks strict export even when the scene still renders its last-good version. Save dirty shader/material/include buffers before exporting. Exports contain prepared shader and material artifacts; players do not need the importer or glslang.

Demonstration

examples/materials contains the full project workflow: translucent A/B/A sprites sharing an atlas, adjacent instances with different overrides, a Mesh2D, two cameras, a Flash tween and a Dissolve animation. Its README gives the edit, undo, reload and native/web export steps. The Inspector preview uses a separate material and transparent offscreen target; a session without a GPU displays its reason instead of pretending a render succeeded.

Try it

Change the example parameters and compare the result. Reset restores the initial scene.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene3 nodes
Flash instance
Transform
position[0, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")materialAssetRef<material>asset("ae900000000000000000000000000c02")layerint0orderint1tintColor#38bdf8fforiginVec2[0.5, 0.5]sizeVec2[4, 3]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Material Override
values[]engine.MaterialParameter[]
Backdrop
Transform
position[1.5, 1]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint0tintColor#f43f5efforiginVec2[0.5, 0.5]sizeVec2[4, 3]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat48viewportRect[0, 0, 1, 1]maskint-1orderint0clearbooltrueclearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
Scriptmain.aes
package demo

import (
    "aego/tween"
    "aego/curve"
)

script MaterialPulse {
    var pulse tween.Tween

    func Ready() {
        node.Get<MaterialOverride>().SetFloat("Flash", 0)
        pulse = tween.ToFloat(node, "MaterialOverride.Flash", 1, 0.8, curve.InOutSine).PingPong(-1)
    }
}