render
What a frame is made of: the shape, sprite, mesh or emitter a node draws, the 2D and 3D cameras, the backdrop, debug lines and screenshots. window holds…
What a frame is made of: the shape, sprite, mesh or emitter a node draws, the 2D and 3D cameras, the backdrop, debug lines and screenshots. window holds the window itself.
45 functions, 41 constants. Scripts reach it as render::.
Acts on boolean3d, occluder2d, screen_notifier2d, tilemap: those functions are also methods on the component's handle, without the node argument.
Functions
Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.
| function | acts on | what it does |
|---|---|---|
begin_retained(string) |
— | Keep what is drawn from here to end_retained under key, drawn every frame until the key is drawn again or cleared: an overlay redrawn when what it shows moves, not each frame. |
bounds(Node) -> [Vec3]? |
— | The box the node's geometry covers in its own space, as a centre xyz and half-extents xyz, with a z of zero for a 2D node; nil for a node that draws nothing. A solver's body reports where it is now, not where it was built; a text, the lines it was last laid out in. |
built_mesh(Node) -> render::BuiltMesh? |
boolean3d |
The triangles the node's boolean settled on, ready to be written out as a mesh asset; nil when the node draws no built geometry. |
camera_2d() -> render::Viewport2d |
— | The 2D camera this frame: its center and its zoom in logical pixels per world unit; all zeros with no window. |
camera_matrix() -> [float] |
— | The camera's projection*view matrix this frame, 16 numbers column-major; all zeros with no window. |
camera_pose() -> render::CameraPose |
— | The camera the renderer actually used, which is where a backend put it and not what a camera3d asked: its eye and target, the vertical fov in radians and the HiDPI scale_factor. Zeros and a scale of one with no window. |
cell(Node, int, int) -> int |
tilemap |
The tile at a column and row, or -1 for an empty cell or one past the edge. |
cell_terrain(Node, int, int) -> int |
tilemap |
The terrain value painted at a column and row, or -1 where nothing was painted. |
check_material(string) -> [script::Diagnostic] |
— | Every diagnostic about the material at that path, as [{ file, line, column, severity, message }]; empty when it links. |
clear_retained(string) |
— | Stop drawing what key kept. A script hears the camera a frame was drawn with move, to draw a group sized in pixels again, with events::listen(this.node, "camera_moved"). |
debug_view() -> string |
— | Which channel the viewport is drawing instead of the scene's colour, or empty for the scene as it is. |
debug_views() -> [str] |
— | Every channel name set_debug_view accepts, as a list. |
draw_arc_2d(Vec2, float, float, float, float?, Color?, render::DrawOptions?) |
— | Stroke an arc between two angles in radians, counter-clockwise from the x axis, for this frame; width is in pixels, and opts takes z_index. |
draw_box_3d(Vec3, Vec3, Color?) |
— | Draw a wireframe box centred at a point, size across along each axis in world units, for this frame. |
draw_capsule_3d(Vec3, float, float, Color?) |
— | Draw a wireframe capsule centred at a point, height being the straight part along y, for this frame. |
draw_circle_2d(Vec2, float, Color?, render::DrawOptions?) |
— | Fill a circle in world units for this frame, over everything the scene drew; opts.z_index places it among the nodes of that index instead. |
draw_lines_3d([render::Line3d]) |
— | Draw 3D world-space lines for this frame, each with its own ends, colour, width, perspective and on_top: a frame's worth crosses to the engine once. |
draw_polygon_2d([Vec2], Color?, render::DrawOptions?) |
— | Fill a convex outline of world-space points for this frame; geometry2d cuts a concave one into triangles first. opts takes z_index. |
draw_polyline_2d([Vec2], float?, Color?, render::DrawOptions?) |
— | Stroke a chain of world-space points for this frame; width is in pixels, and opts takes z_index. |
draw_rect_2d(Vec2, Vec2, Color?, render::DrawOptions?) |
— | Fill a rectangle of size centred at position, in world units, for this frame; opts takes z_index. |
draw_sphere_3d(Vec3, float, Color?) |
— | Draw a wireframe sphere centred at a point, as three rings in world units, for this frame. |
draw_text_2d(Vec2, string, render::TextOptions?) |
— | Draw a line of text in 2D world space for this frame, shaped by the engine's fonts. opts takes the text2d keys (font_size, font_weight, font_style, color, text_align, markup, max_width, font, text_style, …), pixels_per_unit and z_index; font and text_style name an asset. |
draw_text_3d(Vec3, string, render::TextOptions?) |
— | The same in 3D world space, on a quad that faces the camera. pixels_per_unit sizes it, so text a metre away reads the same whatever the font size. |
draw_texture_2d(string, Vec2, Vec2, Color?, render::TextureOptions?) |
— | Draw a project image over a rectangle of size centred at position, in world units, for this frame; the colour tints it. opts takes z_index, and region_origin and region_size in the image's pixels for part of it. |
end_retained() |
— | Keep what was drawn since begin_retained under its key, in place of what the key held. |
hold_cameras(Node?) |
— | Let no camera under a node drive the view, whatever its current says, until it is called with nil: an editor looking at a game through its own camera. The cameras keep what the scene asked of them. |
is_on_screen(Node) -> bool |
screen_notifier2d |
Whether any of the notifier's box was on screen at the end of the last frame. |
material_params(string) -> [render::Param] |
— | The material's editable rows, one { name, type, value } per field its linked shader declares; empty when it will not link. |
mouse_ray() -> render::Ray |
— | The picking ray through the mouse position, in world units: where it starts and which way it goes. |
mouse_world_2d() -> Vec2 |
— | The mouse position in 2D world coordinates, for picking. |
outline(Node) -> [Vec2] |
occluder2d |
The outline this node blocks 2D light with, as its points in world space, with the first repeated at the end when the outline is closed. Empty on a node with no occluder2d. |
pick_ray_at(Vec3, Vec3) -> render::Hit? |
— | The nearest node with a 3D shape that a world-space ray meets, from its origin along its direction, as node and at, how far along the ray it was met; nil when the ray meets nothing. |
screenshot(string) |
— | Save the next rendered frame as a PNG at a project-relative path. screenshot_saved goes to every listener with the path once it is on disk, and screenshot_failed with { path, error } when it cannot be, a run with no renderer included. |
set_background(Color) |
— | Set the colour the viewport is cleared to behind everything drawn: the colour a #rrggbb writes, each channel from 0 to 1. Its alpha is not read. |
set_cell(Node, int, int, int) |
tilemap |
Put one tile at a column and row; a tile below zero clears the cell, and a cell outside the map grows it in that direction. The mesh rebuilds on the next frame. |
set_cell_terrain(Node, int, int, int) |
tilemap |
Paint a terrain value at a column and row and let the tileset's rules pick the tiles, for that cell and the ring around it; below zero clears it. |
set_debug_view(string) |
— | Draw one channel of the scene (normals, uv, depth or albedo) instead of its colour; an empty name puts the picture back. |
set_shader_preview(string, int) |
— | Draw the value a shader's line computes for every pixel that reaches it; line 0 puts the picture back. |
snap_aov(string, string) |
— | Render the 3D scene once more as render.AOV_DEPTH (nearest brightest), AOV_NORMALS (world space), AOV_CAMERA_NORMALS or AOV_SEGMENTATION (a colour per object) and save it as a PNG, announcing it as screenshot does. A read-back of the GPU, as screenshot is. |
stats() -> render::Stats |
— | What this frame draws: { draws, triangles, texture_bytes, textures, nodes }, where nodes is a row per node that drew, each { node, draws, triangles, texture_bytes, copies }. Presentation, never simulation: nothing in the digest reads it. |
text_size(string, render::TextOptions?) -> Vec2 |
— | The width and height text shapes to, in font pixels, with the project's own fonts and never a system face, so a run with no window open answers as a windowed one does. A width is presentation: writing one into state puts presentation in the digest. |
texture_pixels_per_unit(string) -> float |
— | How many of an image's pixels make a world unit when a sprite says 0: its own pixels_per_unit import setting, else 100. |
texture_size(string) -> Vec2 |
— | An image's width and height in pixels, read from the file's own header. |
trace_texture(string, render::TraceOptions?) -> [[Vec2]] |
— | The outline of an image's opaque pixels, as [x, y] points in a node's own space, ready to be a polygon's positions. opts takes threshold (alpha counted as opaque, 0 to 1, default 0.5), tolerance (how many pixels of detail to drop, default 2), pixels_per_unit (default 100) and holes (every loop, largest first: each other island counter-clockwise and each hole clockwise; default false keeps the largest alone). Counter-clockwise with y up, centred on the origin, the way a sprite at the same pixels_per_unit is drawn. |
triangles_of(Node, Node?) -> [Vec3] |
— | The triangles node draws, from its mesh, its shape or its 2D polygon, as three corners each in the space of space, or of the world where it is left out. |
Constants
| name | value |
|---|---|
ALIGN_CENTER |
"center" |
ALIGN_END |
"end" |
ALIGN_START |
"start" |
ALPHA_BLEND |
"blend" |
ALPHA_MASK |
"mask" |
ALPHA_OPAQUE |
"opaque" |
ALPHA_PREMULTIPLIED |
"premultiplied" |
AOV_CAMERA_NORMALS |
"camera_normals" |
AOV_DEPTH |
"depth" |
AOV_NORMALS |
"normals" |
AOV_SEGMENTATION |
"segmentation" |
FOG_EXPONENTIAL |
"exponential" |
FOG_EXPONENTIAL_SQUARED |
"exponential_squared" |
FOG_LINEAR |
"linear" |
FOG_NONE |
"none" |
FONT_ITALIC |
"italic" |
FONT_NORMAL |
"normal" |
LIGHT_DIRECTIONAL |
"directional" |
LIGHT_POINT |
"point" |
LIGHT_SPOT |
"spot" |
SHAPE_BOX |
"box" |
SHAPE_CAPSULE |
"capsule" |
SHAPE_CIRCLE |
"circle" |
SHAPE_CONE |
"cone" |
SHAPE_CYLINDER |
"cylinder" |
SHAPE_ELLIPSE |
"ellipse" |
SHAPE_NGON |
"ngon" |
SHAPE_PLANE |
"plane" |
SHAPE_PRISM |
"prism" |
SHAPE_PYRAMID |
"pyramid" |
SHAPE_RECTANGLE |
"rectangle" |
SHAPE_SPHERE |
"sphere" |
SHAPE_STAR |
"star" |
SHAPE_TORUS |
"torus" |
SHAPE_TUBE |
"tube" |
TONEMAP_ACES |
"aces" |
TONEMAP_AGX |
"agx" |
TONEMAP_NEUTRAL |
"neutral" |
TONEMAP_NONE |
"none" |
TONEMAP_REINHARD |
"reinhard" |
TONEMAP_TONY_MCMAPFACE |
"tony_mcmapface" |