CauldronGPU.Sectors (CauldronGPU v0.3.3)

Copy Markdown View Source

A Cauldron2D.Sectors.Map uploaded for drawing: one mesh holding every floor, ceiling and wall, a material per picture, and a sky cylinder.

world = CauldronGPU.Sectors.upload(gpu, map, pictures, palette, sky: sky, sky_flats: [f_sky1])
CauldronGPU.submit(gpu, CauldronGPU.Sectors.instances(world, first_id: 1))

pictures is the Cauldron2D.Sectors.Pictures set the map's picture ids index, made with native: false; palette is 768 bytes. A map without a BSP gets one from Cauldron2D.Sectors.Map.with_bsp/2.

Floors and ceilings come from CauldronGPU.Sectors.Flats, walls with Doom's pegging from CauldronGPU.Sectors.Walls. Each sector's light level is baked into the vertices' lightmap coordinates and read from one lightmap texture (CauldronGPU.Sectors.Light), so surfaces are lit with the environment's ambient light at 0. Pictures with a mask are cut out where it is 0. Ceilings whose picture is one of :sky_flats are left open, and upper walls between two such sectors left out; the :sky picture is drawn unlit on a cylinder far outside the map.

Vertices stay in map units with heights on +Z; transform/1 turns them into the renderer's frame (+Y up) at :scale metres a unit, and point/2 does the same for one point such as a player start.

Options:

  • :sky — picture id of the sky, default none (the environment's sky shows)
  • :sky_flats — picture ids that mark a sky ceiling, default []
  • :scale — metres per map unit, default 1 / 32
  • :light_scale — lightmap multiplier, default 2.0
  • :light_distance — viewing distance in map units the light levels are taken at, default 128
  • :filter — texture filtering, :nearest (default) or :linear
  • :sky_distance — the sky cylinder's radius in half widths of the map, default 64

Summary

Functions

The camera rotation facing a map angle of degrees (0 along +X, counter-clockwise from above).

A camera far distance, in the renderer's units, that keeps the level and its sky in view.

Instance changes placing the level and its sky, ids counting up from :first_id (default 1).

A map point {x, y, height} in the renderer's frame.

The transform that places map coordinates in the renderer's frame.

Uploads map's floors, ceilings, walls and pictures, and the sky.

Types

model()

@type model() :: %{
  mesh: CauldronGPU.Handle.t(),
  materials: [CauldronGPU.Handle.t()],
  shadows: boolean()
}

t()

@type t() :: %CauldronGPU.Sectors{
  far: float(),
  handles: [CauldronGPU.Handle.t()],
  models: [model()],
  scale: number()
}

Functions

facing(degrees, pitch \\ 0.0)

@spec facing(number(), number()) :: CauldronGPU.Quat.t()

The camera rotation facing a map angle of degrees (0 along +X, counter-clockwise from above).

far(sectors)

@spec far(t()) :: float()

A camera far distance, in the renderer's units, that keeps the level and its sky in view.

instances(world, opts \\ [])

@spec instances(t(), keyword()) :: [CauldronGPU.Stream.change()]

Instance changes placing the level and its sky, ids counting up from :first_id (default 1).

point(sectors, arg)

@spec point(t(), {number(), number(), number()}) :: {float(), float(), float()}

A map point {x, y, height} in the renderer's frame.

transform(scale)

@spec transform(t() | number()) :: CauldronGPU.Transform.t()

The transform that places map coordinates in the renderer's frame.

upload(gpu, map, pictures, palette, opts \\ [])

Uploads map's floors, ceilings, walls and pictures, and the sky.