22#ifndef EBGEOMETRY_RENDER_HPP
23#define EBGEOMETRY_RENDER_HPP
45template <
class T,
size_t K>
48template <
class T,
size_t K,
size_t W>
53namespace EBGeometry::Render {
70inline constexpr bool primitivesAreFaces<FlatMeshSDF<T>> =
true;
77template <
class T,
size_t K>
78inline constexpr bool primitivesAreFaces<MeshSDF<T, K>> =
true;
86template <
class T,
size_t K,
size_t W>
87inline constexpr bool primitivesAreFaces<TriMeshSDF<T, K, W>> =
true;
290 const T a_fieldOfView = T(40));
331 uint32_t m_width = 960;
336 uint32_t m_height = 960;
341 uint32_t m_supersampling = 2;
346 uint32_t m_threads = 0;
351 bool m_shadows =
true;
356 bool m_occlusion =
true;
382 static constexpr uint32_t PrimitiveColors = 16;
402 bool m_recordPrimitives =
false;
407 static constexpr uint32_t NoPrimitive = 0xFFFFFFFFU;
412 static constexpr uint32_t AllPrimitives = 0xFFFFFFFEU;
418 uint32_t m_highlightPrimitive = NoPrimitive;
424 uint32_t m_highlightCount = 1U;
436 return a_primitive != NoPrimitive &&
437 ((a_primitive - m_highlightPrimitive < m_highlightCount && m_highlightPrimitive != NoPrimitive) ||
438 m_highlightPrimitive == AllPrimitives);
461 T m_cutOpacity = T(1);
469 T m_seenThroughOpacity = T(0.3);
477 T m_ghostOpacity = T(0);
489 bool m_lightFromCamera =
true;
500 T m_lightIntensity = T(1.05);
505 T m_ambient = T(0.35);
515 T m_fillIntensity = T(0.35);
525 T m_shoulder = T(0.8);
530 T m_specular = T(0.45);
536 T m_shininess = T(32);
572 T m_floorCellSize = T(0);
582 uint32_t m_floorMajorEvery = 4;
588 T m_floorFade = T(6);
594 T m_floorReflectance = T(0.5);
601 T m_lightSize = T(0.04);
606 bool m_section =
false;
622 T m_contourWidth = T(3.5);
635 T m_isoSpacing = T(0);
653 bool m_isoSecondary =
false;
659 T m_sheetOpacity = T(0.35);
668 T m_sectionFill = T(1);
674 bool m_sectionFillOutside =
true;
707 T m_xrayOpacity = T(0.25);
712 static constexpr uint32_t HiddenPrimitives = 8;
736 uint32_t m_volumePrimitive = NoPrimitive;
753 T m_volumeOpacity = T(0.7);
768 static inline
Array<uint32_t, HiddenPrimitives>
769 noneHidden() noexcept;
778 hides(uint32_t a_primitive) const noexcept;
786 hidesAny() const noexcept;
827 uint32_t m_width = 0;
832 uint32_t m_height = 0;
852 [[nodiscard]]
inline uint32_t
853 at(
const uint32_t a_column,
const uint32_t a_row)
const noexcept;
863[[nodiscard]]
inline bool
884 uint64_t m_insideHits = 0;
889 uint64_t m_unresolved = 0;
894 bool m_cameraInside =
false;
899 bool m_complete =
true;
917 double m_costLow = 0.0;
923 double m_costHigh = 0.0;
932 double m_raysPerSecond = 0.0;
943[[nodiscard]]
inline double
951[[nodiscard]]
inline uint32_t
972 uint8_t m_insideHits = 0;
977 uint8_t m_unresolved = 0;
982 uint8_t m_cameraInside = 0;
987 uint32_t m_primitive = 0xFFFFFFFFU;
990namespace RenderDetail {
1002 uint32_t m_rgba = 0;
1012 uint8_t m_insideHits = 0;
1017 uint8_t m_unresolved = 0;
1022 uint8_t m_cameraInside = 0;
1034 a_result.
m_rgba, a_result.m_hits, a_result.m_insideHits, a_result.m_unresolved, a_result.m_cameraInside};
1123template <
class T,
class S>
1186 settings() noexcept;
1192 [[nodiscard]] inline const
Settings<T>&
1193 settings() const noexcept;
1205 render(const S& a_shape, const
Camera<T>& a_camera,
Image& a_image) const;
1223 render(const S& a_shape,
1224 const
Camera<T>& a_camera,
1226 const std::atomic<
bool>& a_cancel,
1227 std::atomic<uint32_t>* a_rowsDone =
nullptr) const;
1242 renderOnDevice(const S& a_deviceShape, const
Camera<T>& a_camera,
Image& a_image) const;
1261 renderOnDevice(const S& a_deviceShape,
1262 const
Camera<T>& a_camera,
1264 const std::atomic<
bool>& a_cancel,
1265 std::atomic<uint32_t>* a_rowsDone =
nullptr) const;
1282 [[nodiscard]] inline
HitT<T>
1283 pick(const S& a_shape, const
Camera<T>& a_camera, T a_column, T a_row) const;
1298 [[nodiscard]] inline std::vector<
HitT<T>>
1299 pickAll(const S& a_shape, const
Camera<T>& a_camera, T a_column, T a_row) const;
1305 static constexpr uint32_t MaxCrossings = 64;
1318 check(const
Camera<T>& a_camera) const;
1325 [[nodiscard]] inline
bool
1326 inspecting() const noexcept;
1339 collect(const std::vector<RenderDetail::StoredPixel>& a_results,
1340 std::vector<uint32_t>& a_primitives,
1343 double a_seconds) const;
1356 renderOnHost(const Q& a_query,
1358 const std::atomic<
bool>& a_cancel,
1359 std::atomic<uint32_t>* a_rowsDone) const;
1373 renderFrameOnDevice(const S& a_deviceShape,
1374 const
Camera<T>& a_camera,
1376 const std::atomic<
bool>* a_cancel,
1377 std::atomic<uint32_t>* a_rowsDone) const;
1390 renderFrameWith(const Q& a_query,
1392 const std::atomic<
bool>* a_cancel,
1393 std::atomic<uint32_t>* a_rowsDone) const;
1398#include "EBGeometry_RenderImplem.hpp"
A fixed-size array that compiles for both host and device.
Declarations of bounding volume types used in bounding volume hierarchies.
The tape's front end: Expr, a host-side value that describes a composed object, and the free function...
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Ray queries on any shape: where a ray, or the segment between two points, first crosses its surface (...
RegionSettings: how the regions of an object are shown (visibility, coloring, a domain's surface grou...
uint32_t costColor(double a_place) noexcept
The color a cost view gives a place on its scale, dark (0) to bright (1), as it colors the pixels.
const char * lookName(Look a_look) noexcept
A look's name, as the .ebg view block writes it: "sky", "dark", "gradient", "shadow_only",...
double costPlace(const Stats &a_stats, double a_cost) noexcept
Where a cost sits on a cost view's color scale: 0 at a_stats.m_costLow, 1 at a_stats....
Backdrop
What is drawn behind the shape, where a camera ray hits nothing (Settings::m_backdrop).
Definition EBGeometry_Render.hpp:131
@ Sky
Settings::m_skyHorizon to Settings::m_skyZenith by the ray's elevation above the horizon.
@ Plain
Settings::m_background.
@ Gradient
Settings::m_gradientFrom at the top of the view to Settings::m_gradientTo at its bottom.
@ Vignette
Settings::m_gradientFrom at the center of the view to Settings::m_gradientTo at its corners.
bool writeImage(const Image &a_image, const std::string &a_filename)
Write an image to a file, as binary PPM (P6: 8 bits per channel, no alpha), which most image programs...
CostUnit
What the costs of a cost view count (Stats::m_costLow, Stats::m_costHigh).
Definition EBGeometry_Render.hpp:119
@ Nanoseconds
On the host: each pixel's own ray, timed with the steady clock.
ViewMode
What a render shows at each pixel.
Definition EBGeometry_Render.hpp:104
@ CostCrossing
What each pixel's firstCrossing() cost, as CostHit.
@ Shaded
Lit surfaces, colored by Settings::m_colorBy.
@ XRay
On black, every surface a ray crosses glows faintly (more seen edge-on), with modest highlights.
constexpr uint8_t NumLooks
How many looks there are (Look's values are 0 to NumLooks - 1).
Definition EBGeometry_Render.hpp:171
constexpr bool primitivesAreFaces
Whether a shape's primitives (HitT::m_primitive) are the faces of one object rather than objects: tru...
Definition EBGeometry_Render.hpp:63
Look
Named combinations of the backdrop and the floor (see setLook()).
Definition EBGeometry_Render.hpp:156
@ Studio
A seamless white backdrop with a very soft shadow, as in product renderings.
@ Dark
A plain dark background and the checkered floor.
@ DarkGrid
A dark gray gradient and a faint grid.
@ LightGrid
A light gradient and a pale floor with a grid.
@ Blueprint
Navy, with light grid lines.
FloorStyle
How the floor under the shape is drawn, when there is one (Settings::m_floor, Settings::m_floorStyle)...
Definition EBGeometry_Render.hpp:142
@ Checker
Squares of side Settings::m_floorCellSize in Settings::m_floorColor, every second a little darker.
@ ShadowOnly
The backdrop, darkened where the shape shadows it: no floor is seen, only the shape's shadow.
View
A direction to look at a box from, for Camera::fit(): along the axes of the plane perpendicular to th...
Definition EBGeometry_Render.hpp:188
@ Bottom
Pitch -90: straight up the up axis.
@ Default
The default yaw (35) and pitch (25), from above at an angle.
@ Top
Pitch 90: straight down the up axis.
ColorBy
How surfaces are colored.
Definition EBGeometry_Render.hpp:93
@ Normal
The surface normal's direction as a color (each component from -1 to 1 mapped to 0 to 1).
@ Uniform
One color (Settings::m_color) everywhere.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
Renders shapes into images.
Definition EBGeometry_Render.hpp:1173
Renderer(const Settings< T > &a_settings=Settings< T >()) noexcept
Renderer with given settings.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
static constexpr Vec3T< T > zeros() noexcept
Return a vector with x = y = z = 0.
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
@ None
As written: the tape evaluates every operand, however many there are.
Fixed-size array with host- and device-callable members.
Definition EBGeometry_Array.hpp:33
Where a ray first crosses a surface.
Definition EBGeometry_Ray.hpp:98
How a query marches, where a shape has no ray form.
Definition EBGeometry_Ray.hpp:203
How the regions of an object are shown (see RegionView): which regions are visible,...
Definition EBGeometry_RegionSettings.hpp:66
A camera orbiting a target point.
Definition EBGeometry_Render.hpp:208
T m_fieldOfView
Vertical field of view, in degrees.
Definition EBGeometry_Render.hpp:232
void frame(Vec3T< T > &a_forward, Vec3T< T > &a_right, Vec3T< T > &a_up) const noexcept
The camera's frame: unit vectors forward (towards the target), right and up on the screen.
T m_distance
Distance from the eye to the target.
Definition EBGeometry_Render.hpp:227
bool m_orthographic
Parallel rays instead of rays from the eye: no perspective, so sizes do not shrink with distance.
Definition EBGeometry_Render.hpp:246
Vec3T< T > m_target
The point the camera looks at.
Definition EBGeometry_Render.hpp:212
static Camera fit(const BoundingVolumes::AABBT< T > &a_box, const Vec3T< T > &a_up=Vec3T< T >(T(0), T(1), T(0)))
A camera that sees the whole of a box, from the default direction.
T m_nearClip
How far along each camera ray it starts (0: at the eye): anything nearer is not seen.
Definition EBGeometry_Render.hpp:251
Vec3T< T > m_up
The up axis (need not be of unit length).
Definition EBGeometry_Render.hpp:237
static Camera lookAt(const Vec3T< T > &a_eye, const Vec3T< T > &a_target, const Vec3T< T > &a_up=Vec3T< T >(T(0), T(1), T(0)), const T a_fieldOfView=T(40))
A camera at a given eye, looking at a given point.
Vec3T< T > eye() const noexcept
Where the eye is.
void horizontal(Vec3T< T > &a_first, Vec3T< T > &a_second) const noexcept
Two unit vectors that span the plane perpendicular to the up axis: yaw 90 looks from the first,...
static Camera fit(const BoundingVolumes::AABBT< T > &a_box, View a_view, const Vec3T< T > &a_up=Vec3T< T >(T(0), T(1), T(0)))
A camera that sees the whole of a box, from a given direction.
T m_pitch
Degrees above the plane perpendicular to the up axis, from -90 to 90.
Definition EBGeometry_Render.hpp:222
T m_yaw
Degrees about the up axis.
Definition EBGeometry_Render.hpp:217
An image: width x height pixels, row by row from the top, each 0xRRGGBBAA.
Definition EBGeometry_Render.hpp:823
std::vector< uint32_t > m_primitives
With Settings::m_recordPrimitives, for each pixel the primitive its first ray hit (HitT::m_primitive)...
Definition EBGeometry_Render.hpp:844
std::vector< uint32_t > m_pixels
The pixels, row by row from the top.
Definition EBGeometry_Render.hpp:837
uint32_t at(const uint32_t a_column, const uint32_t a_row) const noexcept
One pixel.
One pixel of a rendered image in the shaded view: the functor that Renderer runs once per pixel index...
Definition EBGeometry_Render.hpp:1125
RenderDetail::CameraView< T > m_view
The camera's eye and axes, worked out once rather than per pixel.
Definition EBGeometry_Render.hpp:1144
PixelQuery(const S &a_shape, const Camera< T > &a_camera, const Settings< T > &a_settings) noexcept
The pixel functor for a shape, a camera and settings.
Settings< T > m_settings
The settings.
Definition EBGeometry_Render.hpp:1139
S m_shape
The shape.
Definition EBGeometry_Render.hpp:1129
PixelResult operator()(const uint32_t &a_index) const noexcept
Shade pixel a_index (row a_index / width, column a_index % width).
Camera< T > m_camera
The camera.
Definition EBGeometry_Render.hpp:1134
What PixelQuery computes for one pixel.
Definition EBGeometry_Render.hpp:958
What every pixel needs from the camera, worked out once per frame: the eye, the view's axes and the f...
Definition EBGeometry_Render.hpp:1048
Vec3T< T > m_up
Unit up of the image.
Definition EBGeometry_Render.hpp:1067
T m_distance
Distance from the eye to the target.
Definition EBGeometry_Render.hpp:1092
Vec3T< T > m_second
Horizontal unit vectors (see Camera::horizontal()).
Definition EBGeometry_Render.hpp:1082
Vec3T< T > m_right
Unit right of the image.
Definition EBGeometry_Render.hpp:1062
Vec3T< T > m_eye
The eye.
Definition EBGeometry_Render.hpp:1052
bool m_orthographic
Whether the camera is orthographic.
Definition EBGeometry_Render.hpp:1108
Vec3T< T > m_forward
Unit direction the camera looks in.
Definition EBGeometry_Render.hpp:1057
T m_footprint
How wide a pixel is at distance t along a camera ray: m_footprint + m_footprintPerLength t (the first...
Definition EBGeometry_Render.hpp:1098
Vec3T< T > m_axis
Unit up axis of the scene.
Definition EBGeometry_Render.hpp:1072
T m_tanHalf
Tangent of half the vertical field of view.
Definition EBGeometry_Render.hpp:1087
Vec3T< T > m_first
Horizontal unit vectors (see Camera::horizontal()).
Definition EBGeometry_Render.hpp:1077
T m_footprintPerLength
See m_footprint.
Definition EBGeometry_Render.hpp:1103
A pixel as a render stores it: PixelResult without the object, which is stored apart and only when as...
Definition EBGeometry_Render.hpp:998
static StoredPixel of(const PixelResult &a_result) noexcept
The stored part of a pixel's result.
Definition EBGeometry_Render.hpp:1031
uint32_t m_rgba
The pixel, 0xRRGGBBAA.
Definition EBGeometry_Render.hpp:1002
What to render and how. A plain value; every field has a default.
Definition EBGeometry_Render.hpp:327
bool isHighlighted(const uint32_t a_primitive) const noexcept
Whether a primitive is highlighted.
Definition EBGeometry_Render.hpp:433
RayOptions< T > m_rays
How rays march (see firstHit()). A scale of 0 takes the shape's box diagonal, or the camera distance ...
Definition EBGeometry_Render.hpp:696
static Array< Vec3T< T >, PrimitiveColors > unsetColors() noexcept
Every entry of m_primitiveColors unset.
RegionSettings m_regions
How a view of regions (RegionView) is shown: the visible regions, what a surface is colored by,...
Definition EBGeometry_Render.hpp:748
What a render saw.
Definition EBGeometry_Render.hpp:870