The renderer
The renderer is in EBGeometry_Render.hpp and the window
in EBGeometry_Viewer.hpp; EBGeometry.hpp includes
both. It draws any shape through the shape’s own ray queries (see Ray queries): the shaded
view and the cost of finding hits use firstHit(), the depth view and the cost of finding crossings
firstCrossing(). Rendering describes what it draws, and The viewer the window.
Rendering an image
The classes are in namespace Render:
Render::Settings<T> settings; // 960 x 960, 2 x 2 rays per pixel, ...
settings.m_colorBy = Render::ColorBy::Primitive;
const Render::Renderer<T> renderer(settings);
const auto camera = Render::Camera<T>::fit(shape.computeBoundingVolume());
Render::Image image; // 0xRRGGBBAA, row by row from the top
const Render::Stats stats = renderer.render(shape, camera, image);
Render::writeImage(image, "shape.ppm"); // a binary PPM
Camera orbits a target: yaw about the up axis (+y by default), pitch above the horizontal plane, a distance and a vertical field of view.
Camera::fit(box)aims it at a box from far enough to see all of it,Camera::fit(box, view)does so from a named direction (View::Front,Back,Left,Right,ToporBottom), andCamera::lookAt(eye, target)places it directly.m_orthographicmakes the rays parallel, andm_nearClipstarts every camera ray that far from the eye. A shape with an unbounded box (a plane, a complement) has nothing to fit: give it a camera, or fit one to a box of your own.Renderer holds the settings.
render(shape, camera, image)renders on the host’s threads;renderOnDevice(deviceShape, camera, image)renders on a device, from a device view of the shape (see Running queries on a GPU). Overloads of both take astd::atomic<bool>that another thread sets to stop the render, which stops before the next pixel, and a counter of the rows done; a stopped render says so inStats::m_complete, and the pixels it did not reach stay black.pick(shape, camera, column, row)returns the hit (HitT: the primitive, the point, the normal) of the ray through a point of the image, cut as the render cuts it, looking through hidden primitives;pickAll()lists every crossing under the point, front to back, hidden ones included (at mostRenderer::MaxCrossings).Stats reports the rays cast, those that hit the shape, those that hit it from inside the solid (drawn tinted red), those that were unresolved (drawn as misses), and whether the eye is inside the solid; in a cost view, also the cost scale and the frame’s rays per second (below). The renderer prints nothing.
Render::toCode(camera, settings)writes a camera and settings as C++ statements, the fields that differ from their defaults: a view found by hand in the window, ready to paste into a program.Render::setLook(settings, Render::Look::Studio)sets the backdrop and the floor to one of nine named looks (lookName()gives their names), the ones the viewer’s B key steps through; change any of their fields afterwards to adjust one.
The settings
Settings is a plain value; every field has a default.
Fields |
Set |
|---|---|
|
The image size in pixels (960 x 960); rays per pixel along each axis (2, so 2 x 2; from 1 to 15); host threads (0: one per hardware thread). |
|
What is drawn: |
|
How surfaces are colored: |
|
Shadows, and ambient occlusion (darker creases); both on. The light’s size softens the shadows’ edges: with supersampling, each of a pixel’s rays sees the light from a different point of it. |
|
The direction toward the light, by default in the camera’s frame so that it lights the side in view
wherever the camera goes ( |
|
A fill light, which lights the sides the light leaves dark: it comes from the camera’s other side, a little below the horizon, and follows the light; it casts no shadow, makes no highlights and costs no rays (0 turns it off). Where lit surfaces start to roll off towards white instead of clipping at it (1: a hard clip). |
|
A floor under the shape that catches its shadow, fading into the backdrop far away: a checkerboard
( |
|
What is behind the shape: a sky ( |
|
A section plane, removing the part of the shape on the side its normal points to; with |
|
How the section is drawn: the cut face (opaque unless |
|
Lines of equal distance on the section plane, inside and outside, this far apart (0: none). |
|
For a view of regions: the plane filled by each point’s material, in the material’s color (gray where
a region has none, or where a domain shown on the plane does not compute), and whether lines are drawn
there, in another color. With |
|
Primitives tinted, and outlined, in a highlight color (what a viewer has picked). |
|
Up to |
|
Peel the frame: every camera ray passes this many surfaces (entering or leaving, a cut face too) and shows
the next, as seen from outside, with what lies in front of it left out; where a ray meets fewer, the floor or
the backdrop shows. It must be below |
|
A part whose inside is filled with a translucent color ( |
|
The color a surface seen from inside the solid is tinted toward. |
|
For a view of regions (below): what is shown, hidden and seen through, and how opaque a surface seen through is. |
|
Record each pixel’s primitive in |
|
How rays march where a shape is not traced exactly ( |
Views of regions
An object of regions (see Regions, materials and domains) renders as any shape does, as its outer surface. To see its regions, the surfaces between them, and its domains’ surface groups, render a RegionView of its tape instead:
const RegionView<Tape<T>> regions(tape);
settings.m_regions.m_coloring = RegionColoring::Material; // or Region, SurfaceGroup, SurfaceLabel, ...
settings.m_regions.setVisible(1, false); // hide region 1 (the air)
renderer.render(regions, camera, image);
A RegionView is a shape: it shows the surfaces of the visible regions, the interfaces between them
included, and passes through the rest. What it shows is set by the
RegionSettings in Settings::m_regions: the
regions hidden (setVisible(), showOnly()), what surfaces are colored and named by (m_coloring: by
region, material, surface label, surface, part, interface or surface group), a key shown alone, the
surfaces, regions and surface groups seen through, a domain’s surface groups (m_surfaceGroups, from
Domain::surfaceGroups()), and what is highlighted. Regions are hidden and seen through by bits, so only
the first 64 can be; later ones are always shown.
The cost views
The cost views (ViewMode::CostHit and ViewMode::CostCrossing) trace one ray per pixel and color each
pixel by what its ray cost, on a log scale over the frame. Stats::m_costUnit says what a cost counts:
nanoseconds on the host, each pixel’s ray timed on the thread that traced it; clock cycles on a device, as
the device counts them. A device traces the 32 threads of a warp together, so each pixel includes waiting
for the slowest ray of its warp (the picture shows blocks of 32 pixels along a row), and the device runs
other warps meanwhile. The two units differ, and so do the scales: the colors compare the pixels of one
frame, never the host with the device. Stats::m_costLow and m_costHigh are the costs of the
darkest and the brightest colors; the cheapest and dearest hundredth of the pixels take those colors too, so
that a few interrupted rays do not stretch the scale.
To compare the host with a device, use Stats::m_raysPerSecond, set in the cost views only: the frame’s
rays over the time their tracing took. It times the tracing only, not the whole render() call (not
allocating the device’s buffers, copying the image back or coloring it), and a frame with much background
traces many cheap misses. To time your own queries, use the Performance/ probes (see
Performance testing). A program that draws its own colorbar takes a cost’s place on the frame’s
scale from Render::costPlace(stats, cost) (0 at m_costLow, 1 at m_costHigh) and its color from
Render::costColor(place). A view of regions shows the cost of its tape’s queries, the whole object’s
firstHit() and firstCrossing(), whatever regions are shown, except for a domain shown alone when the
window was given the domain’s own shape (below): then the cost of finding the first surface of one of the
domain’s regions on the domain’s own tape, passing through the regions kept around them, as a solver of the
domain finds a subdomain’s surface (Tape::firstSurface()).
Fig. 14 The cost of firstCrossing() per pixel on a mesh, on the host in nanoseconds (left) and on a GPU in
clock cycles (right), with each frame’s rays per second in its colorbar.
Opening the window
Render::view(shape, argc, argv) opens a window on a shape, from a camera fitted to its box. Overloads
take a camera and settings, a device view of the shape to render on a GPU, and a
RegionNames, the names of a view of regions’ regions,
materials, surfaces and domains (see Regions and domains), and with them each domain’s own shape, a
Render::DomainShape: a view of regions of
the domain’s own tape (see “A domain on its own” there) and its map to the whole object’s regions, for the cost
views of the domain shown alone. Render::view(shape, pool, argc, argv)
takes instead the pool the shape lives in: in a GPU build with a visible device, it freezes the pool, mirrors
it for as long as the window is open and renders on the device (G switches to the host and back), and
otherwise renders on the host.
The window needs SDL2 and is compiled only on request (see The viewer window (EBGEOMETRY_VIEWER)). Without it, and
whenever no window should open (the program was given --no-view, there is no display, or SDL cannot
start), view() prints one line saying why and returns, so a program that calls it still runs
unattended. The viewer describes the window, and MeshSDF ends by opening it on a
mesh.