Aego Русский

Normal mapping with a moving light

The left sprite uses a normal map generated from a height image; the right sprite uses the same albedo and a flat normal. The moving Point light evaluates each surface separately. Change Height, Intensity or Range in the live Inspector to see the difference. Height is measured above the 2D plane, while shadows remain planar.

The complete source project is modules/render2d/res/docs/try/lighting/NormalMapping.assets. Open its project.aego in the editor to edit the images, material and moving-light script together. A copied .aescene alone does not include those external assets. The browser receives prepared resources from that project through the ordinary asset loader. It does not run image importers or search for normal-map filenames.

surface_height.png.meta selects semantic=height, generate_normal=true, height_channel=r, height_strength=12 and normal_y=up. Import produces a linear normal texture. The Lit material's explicit NormalMap reference points to that stable asset ID. The albedo uses color semantics and has no implicit normal association, so the flat comparison remains flat. Renaming either file with its .meta preserves the link.

For an authored normal image, use semantic=normal; choose normal_y=up or down to match the source's green-channel convention. Do not import normal, cookie or height data as sRGB color. An independently packed normal atlas keeps its own region, source dimensions and trim mapping. Rotated atlas entries remain unsupported. A missing normal frame keeps its reference and renders with a flat fallback until repaired.

If the surface looks flat, check that the material is Lit, the light's receiver mask includes the sprite, Height is positive, the normal reference resolves and NormalStrength is nonzero. Excessive ambient can hide the direct-light response. Scene View's Surface normals mode helps inspect the transformed normal without exposure or tone mapping. The project examples/platformer demonstrates the same pipeline in the actual game.

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
Scene5 nodes
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat62viewportRect[0, 0, 1, 1]maskint-1orderint0clearbooltrueclearColorColor#131b29ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
Normal mapped dome
Transform
position[-2.8, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("d5aa0000000000000000000000000001")materialAssetRef<material>asset("d5aa0000000000000000000000000003")layerint0orderint0tintColor#fffffffforiginVec2[0.5, 0.5]sizeVec2[4.6, 4.6]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumlinear
Flat normal comparison
Transform
position[2.8, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("d5aa0000000000000000000000000001")materialAssetRef<material>asset("ae900000000000000000000000000c06")layerint0orderint0tintColor#fffffffforiginVec2[0.5, 0.5]sizeVec2[4.6, 4.6]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumlinear
Moving light
Transform
position[0, 0]rotation0scale[1, 1]
Light 2D
typeenumpointcolorColor#fff0d5ffintensityfloat5rangefloat12heightfloat2.4fallofffloat1layersint1shadowCasterMaskint1shadowsboolfalsepriorityint1
Lighting environment
Transform
position[0, 0]rotation0scale[1, 1]
Scriptmain.aes
package demo

import "aego/math"

// A deterministic presentation-only motion makes the shadow response visible.
script MovingLight {
    @export var Speed float = 0.8
    @export var Distance float = 1.3
    var elapsed float
    var origin Vec2

    func Ready() {
        origin = node.Transform2D().Position
    }

    func Update(dt float) {
        elapsed += dt
        transform := node.Transform2D()
        transform.Position = origin + Vec2{math.Cos(elapsed * Speed) * Distance, math.Sin(elapsed * Speed) * 0.8}
        node.SetTransform2D(transform)
    }
}