scimesh 0.3.2
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
scimesh::Renderer Class Reference

The main rendering engine. More...

#include <renderer.h>

Public Member Functions

Image render_mesh (const Mesh &mesh, const Camera &camera, const RenderOptions &options)
 Render a single mesh to an image.
 
Image render_scene (const Scene &scene, const Camera &camera, const RenderOptions &options)
 Render a scene (collection of meshes) to an image.
 
Image render_triangles_raw (const std::vector< Vec3 > &positions, const std::vector< Color > &colors, const Camera &camera, const RenderOptions &options)
 Render raw triangles (no Mesh wrapper) to an image.
 
Image render_points_raw (const std::vector< Vec3 > &positions, const std::vector< Color > &colors, float radius, const Camera &camera, const RenderOptions &options)
 Render a point cloud (spheres at each position) to an image.
 

Detailed Description

The main rendering engine.

Overview

The Renderer produces 2D images from 3D geometry using a software rasterization pipeline:

  1. Vertex processing: transform vertices through the model→view→projection pipeline.
  2. Clipping: discard or clip triangles outside the view frustum and clip planes.
  3. Rasterization: convert triangles to pixel fragments, computing color, depth, and lighting per pixel.
  4. Post-processing: apply anti-aliasing, SSAO, fog, and contrast.

Basic usage

#include <scimesh/core/renderer.h>
Mesh mesh = scimesh::generate_sphere({0,0,0}, 1.0f, 32,
Color(0.2f, 0.5f, 0.8f));
Camera cam = camera_fit_mesh(mesh, {0,0,1}, {0,1,0}, 45.0f);
RenderOptions opts;
opts.width = 800;
opts.height = 600;
Renderer renderer;
Image result = renderer.render_mesh(mesh, cam, opts);
result.write_png("sphere.png");
Mesh generate_sphere(const Vec3 &center, float radius, int segments, const Color &color)
Generate a UV-sphere (latitude/longitude tessellation).
Camera camera_fit_mesh(const Mesh &mesh, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin, ProjectionType projection)
Create a camera that automatically frames a single Mesh.
Definition camera.cpp:75
A virtual camera that defines the viewpoint for rendering.
Definition camera.h:77
An RGBA color with floating-point components.
Definition types.h:88
A 3D triangle mesh using an indexed face set representation.
Definition mesh.h:76

Rendering multiple meshes

For multiple meshes, use a Scene:

Scene scene;
scene.meshes.push_back(sphere1);
scene.meshes.push_back(cube1);
Image result = renderer.render_scene(scene, cam, opts);
A 2D RGBA image buffer.
Definition image.h:87
A collection of Mesh objects to be rendered together.
Definition scene.h:57
std::vector< Mesh > meshes
The meshes in this scene, drawn in order.
Definition scene.h:59

Raw rendering (no mesh needed)

For programmatic point clouds or triangle soups:

// Render 100 random points as a point cloud
std::vector<Vec3> positions = /* ... */;
std::vector<Color> colors = /* ... */;
Image result = renderer.render_points_raw(positions, colors,
0.02f, cam, opts);
See also
Mesh, Scene, Camera, RenderOptions, Image, Rasterizer

Definition at line 73 of file renderer.h.

Member Function Documentation

◆ render_mesh()

Image scimesh::Renderer::render_mesh ( const Mesh mesh,
const Camera camera,
const RenderOptions options 
)

Render a single mesh to an image.

Parameters
meshThe mesh to render.
cameraThe camera defining the viewpoint.
optionsRendering settings (size, lighting, etc.).
Returns
The rendered image.
See also
render_scene(), render_triangles_raw(), render_points_raw()

Definition at line 31 of file renderer.cpp.

◆ render_points_raw()

Image scimesh::Renderer::render_points_raw ( const std::vector< Vec3 > &  positions,
const std::vector< Color > &  colors,
float  radius,
const Camera camera,
const RenderOptions options 
)

Render a point cloud (spheres at each position) to an image.

Each point is drawn as a small filled circle of the given radius (in screen-space pixels). Points are depth-tested against each other and against previously drawn geometry.

Parameters
positionsPoint positions in world space.
colorsPer-point colors (same size as positions).
radiusScreen-space radius of each point in pixels.
cameraThe camera.
optionsRendering settings.
Returns
The rendered image.
Example
std::vector<Vec3> pts = {{0,0,0}, {1,0,0}, {0,1,0}};
std::vector<Color> cols = {Color(1,0,0), Color(0,1,0), Color(0,0,1)};
Image result = renderer.render_points_raw(pts, cols, 3.0f, cam, opts);
See also
render_triangles_raw(), render_mesh()

Definition at line 77 of file renderer.cpp.

◆ render_scene()

Image scimesh::Renderer::render_scene ( const Scene scene,
const Camera camera,
const RenderOptions options 
)

Render a scene (collection of meshes) to an image.

All meshes are drawn into the same image in the order they appear in the scene. Later meshes are drawn on top of earlier ones.

Parameters
sceneThe scene containing one or more meshes.
cameraThe camera.
optionsRendering settings.
Returns
The rendered image.
Example
Scene scene;
scene.meshes.push_back(background_plane);
scene.meshes.push_back(main_object);
Image result = renderer.render_scene(scene, cam, opts);
See also
render_mesh(), Scene

Definition at line 43 of file renderer.cpp.

◆ render_triangles_raw()

Image scimesh::Renderer::render_triangles_raw ( const std::vector< Vec3 > &  positions,
const std::vector< Color > &  colors,
const Camera camera,
const RenderOptions options 
)

Render raw triangles (no Mesh wrapper) to an image.

Each consecutive triplet of positions forms a triangle. positions.size() must be a multiple of 3, and colors must have the same number of elements.

Parameters
positionsFlat array of vertex positions (3 per triangle).
colorsPer-vertex colors (same size as positions).
cameraThe camera.
optionsRendering settings.
Returns
The rendered image.
See also
render_points_raw(), render_mesh()

Definition at line 54 of file renderer.cpp.


The documentation for this class was generated from the following files: