Euclid
Geometry Processing and Shape Analysis in C++
Euclid::Rasterizer Class Reference

A simple rasterizer. More...

#include <Rasterizer.h>

Public Types

enum  SampleCount { SAMPLE_COUNT_1 = 0x00000001, SAMPLE_COUNT_2 = 0x00000002, SAMPLE_COUNT_4 = 0x00000004, SAMPLE_COUNT_8 = 0x00000008 }
 

Public Member Functions

 Rasterizer (uint32_t width=256, uint32_t height=256, SampleCount samples=SAMPLE_COUNT_1)
 Create a rasterizer. More...
 
void attach_position_buffer (const float *positions, size_t size)
 Attach a position buffer to the rasterizer. More...
 
void attach_normal_buffer (const float *normals, size_t size)
 Attach a normal buffer to the rasterizer. More...
 
void attach_color_buffer (const float *colors, size_t size)
 Attach a color buffer to the rasterizer. More...
 
void attach_index_buffer (const unsigned *indices, size_t size)
 Attach an index buffer to the Rasterizer. More...
 
void release_buffers ()
 Release all associated buffers.
 
void set_material (const Material &material)
 Change the material of the model.
 
void set_light (const Light &light)
 Change the light settings.
 
void set_background (const Eigen::Array3f &color)
 Change the color of background.
 
void set_background (float r, float g, float b)
 Change the color of background.
 
void set_image (uint32_t width, uint32_t height, SampleCount samples)
 Set the size and sampling of the resulting image.
 
void render_shaded (const Eigen::Matrix4f &model, const RasCamera &camera, std::vector< uint8_t > &pixels, bool interleaved=true)
 Render the mesh into a shaded image. More...
 
void render_unlit (const Eigen::Matrix4f &model, const RasCamera &camera, std::vector< uint8_t > &pixels, bool interleaved=true)
 Render the mesh into a unlit image. More...
 
void render_depth (const Eigen::Matrix4f &model, const RasCamera &camera, std::vector< uint8_t > &pixels, bool interleaved=true, bool linear=true)
 Render the mesh into a depth image. More...
 
void render_depth (const Eigen::Matrix4f &model, const RasCamera &camera, std::vector< float > &values, bool linear=true)
 Render the mesh into a depth image. More...
 

Detailed Description

This rasterizer could render several types of images of a triangle mesh.

Constructor & Destructor Documentation

Euclid::Rasterizer::Rasterizer ( uint32_t  width = 256,
uint32_t  height = 256,
SampleCount  samples = SAMPLE_COUNT_1 
)
inline

Essential vulkan setup goes here. There's no need for a window since all rendering happens offscreen. If your gpu is not suitable for rendering, an exception will be thrown.

Member Function Documentation

void Euclid::Rasterizer::attach_color_buffer ( const float *  colors,
size_t  size 
)
inline

If color buffer is provided, the rasterizer will use this buffer in the render_shaded and render_unlit functions. Otherwise, it will use the colors provided in the material.

Parameters
colorsAn array storing [r,g,b,r,g,b...] colors for each point. The values range in [0 1]. Set colors to nullptr to release the current buffer and fall back to the material.
sizeThe size of the buffer.
void Euclid::Rasterizer::attach_index_buffer ( const unsigned *  indices,
size_t  size 
)
inline

If index buffer is provided, the rasterizer will use indexed drawing mode. Otherwise, it will use plain drawing mode.

Parameters
indicesAn array storing [v1,v2,v3,v1,v2,v3...] indices for each triangle. Set indices to nullptr to release the current buffer and fall back to plain drawing mode.
sizeThe size of the buffer.
void Euclid::Rasterizer::attach_normal_buffer ( const float *  normals,
size_t  size 
)
inline

Normal buffer is requested in render_shaded.

Parameters
normalsAn array storing [x,y,z,x,y,z...] coordinates for each point. Set normal to nullptr to release the current buffer.
sizeThe size of the buffer.
void Euclid::Rasterizer::attach_position_buffer ( const float *  positions,
size_t  size 
)
inline

User should at least provide this buffer for the rasterizer to render anything. The size of the position buffer determines how many vertices are drawn.

Parameters
positionsAn array storing [x,y,z,x,y,z...] coordinates for each point. Set position to nullptr to release the current buffer.
sizeThe size of the buffer.
void Euclid::Rasterizer::render_depth ( const Eigen::Matrix4f &  model,
const RasCamera camera,
std::vector< uint8_t > &  pixels,
bool  interleaved = true,
bool  linear = true 
)
inline

The minimum depth value is mapped to 255 in image, and the maximum depth value is mapped to 0.

Parameters
modelThe model matrix.
cameraCamera.
pixelsOutput pixels.
interleavedIf true, pixels are stored like [RGBRGBRGB...], otherwise pixels are stored like [RRR...GGG...BBB...].
linearIf true, return linearized depth value, otherwise return z value as it is.
void Euclid::Rasterizer::render_depth ( const Eigen::Matrix4f &  model,
const RasCamera camera,
std::vector< float > &  values,
bool  linear = true 
)
inline

The depth values are returned as they are, while the depth of the background is one.

Parameters
modelThe model matrix.
cameraCamera.
valuesThe depth values.
linearIf true, return linearized depth value, otherwise return z value as it is.
void Euclid::Rasterizer::render_shaded ( const Eigen::Matrix4f &  model,
const RasCamera camera,
std::vector< uint8_t > &  pixels,
bool  interleaved = true 
)
inline

This function renders the mesh with simple lambertian shading, using a point light located at the camera position.

Parameters
modelThe model matrix.
cameraCamera.
pixelsOutput pixels
interleavedIf true, pixels are stored like [RGBRGBRGB...], otherwise pixels are stored like [RRR...GGG...BBB...].
void Euclid::Rasterizer::render_unlit ( const Eigen::Matrix4f &  model,
const RasCamera camera,
std::vector< uint8_t > &  pixels,
bool  interleaved = true 
)
inline

Only show raw diffuse color or vertex color if provided.

Parameters
modelThe model matrix.
cameraCamera.
pixelsOutput pixels.
interleavedIf true, pixels are stored like [RGBRGBRGB...], otherwise pixels are stored like [RRR...GGG...BBB...].

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