Fx module

What a script puts in front of the player: things seen rather than things the game holds.

Nothing here takes a place in a save or has a bearing on what anything decides.

Every call here lasts the frame it is made in. A light that stays is the same call made every frame, which is also how one follows something that moves; there is nothing to remove.

A frame shows only so much: see trx.fx.MAX_LIGHTS and trx.fx.MAX_FOG. Once a frame is full, what is asked for takes the place of the one furthest from the camera, so the nearest are the ones seen. Neither raises an error.

Constants

  • trx.fx.MAX_LIGHTS = 64 (integer)
    How many lights a script can put up in one frame.

  • trx.fx.MAX_FOG = 10 (integer)
    How many balls of fog can be seen at once. TR4 levels carry fog of their own, which takes its slots first, so fewer than this reach the screen where a level is already using them.

Functions

  • trx.fx.emit_light(opts)
    Lights the world around a point for this frame.

    TR1 and TR2 light in brightness alone, so there the light is as bright as its brightest channel and comes out white.

    Parameters:

    • opts (table). Where the light is and what it looks like.

      Keys:

      • pos (trx.math.Vec3). World position.
      • radius (trx.math.Distance, optional, default 3072). How far it reaches, at least an eighth of a sector. Rounded down to the eighth of a sector the engine measures a dynamic light in, and carried about a quarter further than asked for in TR4, which falls a light off more gently.
      • color (table, optional). Its color, each channel 0 to 255. Defaults to white.

    Example:

    trx.events.after_control(function()
      trx.fx.emit_light({
        pos = trx.lara.item.pos,
        radius = 2048,
        color = { r = 0, g = 255, b = 192 },
      })
    end)
    
  • trx.fx.emit_fog(opts)
    Fills a ball of air with fog for this frame, which the player sees through rather than on. Where a light brightens what it falls on, this hangs in the space itself.

    Parameters:

    • opts (table). Where the fog is and what it looks like.

      Keys:

      • pos (trx.math.Vec3). World position.
      • radius (trx.math.Distance, optional, default 2048). How far the fog reaches, at least one unit.
      • density (integer, optional, default 128). How thick it is, from 0 for nothing to 255.
      • color (table, optional). Its color, each channel 0 to 255. Defaults to white.

    Example:

    trx.events.after_control(function()
      trx.fx.emit_fog({
        pos = { x = 32768, y = -1024, z = 45056 },
        radius = 3072,
        density = 64,
        color = { r = 128, g = 160, b = 192 },
      })
    end)