|
scimesh 0.3.2
Headless CPU-only 3D software renderer for scientific mesh visualization
|
Low-level triangle rasterizer with depth buffering and lighting. More...
#include <rasterizer.h>

Public Member Functions | |
| Rasterizer (int w, int h) | |
| Construct a rasterizer for the given output size. | |
| void | clear (float clear_depth=1.0f) |
| Clear the depth and normal buffers. | |
| void | set_blend_mode (bool enabled) |
| Enable or disable alpha blending. | |
| void | rasterize_triangle (const Vec3 &screen_v0, const Color &color0, const Vec3 &normal0, const Vec2 &uv0, const Vec3 &screen_v1, const Color &color1, const Vec3 &normal1, const Vec2 &uv1, const Vec3 &screen_v2, const Color &color2, const Vec3 &normal2, const Vec2 &uv2, bool backface_culling, bool smooth_shading, const Vec3 &light_direction, bool wireframe, const Color &wireframe_color, Image &output) |
| Rasterize a single triangle into the output image. | |
| void | rasterize_point (float screen_x, float screen_y, float depth, float radius, const Color &color, const Vec3 &normal, const Vec3 &light_direction, Image &output) |
| Rasterize a single point (filled circle) into the output image. | |
| void | apply_ssao (Image &output, float z_near, float z_far) |
| Apply screen-space ambient occlusion to the output image. | |
Public Attributes | |
| Image * | active_texture = nullptr |
| Optional texture image for textured meshes. | |
Output dimensions | |
| int | width = 0 |
| Output image width in pixels. | |
| int | height = 0 |
| Output image height in pixels. | |
Depth and normal buffers | |
| std::vector< float > | z_buffer |
| Z-buffer (depth buffer), one float per pixel. | |
| std::vector< Vec3 > | normal_buffer |
| Normal buffer, one Vec3 per pixel. | |
Blending | |
| bool | blend_mode = false |
| Enable alpha blending for transparent triangles (default: false). | |
Specular lighting | |
| Color | specular_color = Color(0.0f, 0.0f, 0.0f, 0.0f) |
| Specular highlight color. | |
| float | shininess = 0.0f |
| Shininess exponent (Phong model). | |
Lights | |
| std::vector< Light > | lights |
| Light sources for Blinn-Phong shading. | |
| float | ambient = 0.3f |
| Ambient light level (0.0–1.0, default: 0.3). | |
Post-processing | |
| float | contrast = 1.0f |
| Contrast adjustment (1.0 = no change). | |
Fog | |
| bool | fog_enabled = false |
| Enable depth fog (default: false). | |
| float | fog_start = 0.0f |
| Distance where fog begins. | |
| float | fog_end = 1.0f |
| Distance where fog is fully opaque. | |
| Color | fog_color = TRANSPARENT_BLACK |
| The fog color (what distant objects blend into). | |
SSAO (Screen-Space Ambient Occlusion) | |
| bool | ssao_enabled = false |
| Enable SSAO (default: false). | |
| float | ssao_radius = 16.0f |
| SSAO sample radius in pixels (default: 16). | |
| float | ssao_intensity = 0.8f |
| SSAO darkening intensity (0.0–1.0, default: 0.8). | |
Low-level triangle rasterizer with depth buffering and lighting.
The Rasterizer is the heart of the rendering pipeline. It takes triangles in screen space (after all transforms have been applied) and fills in the corresponding pixels, applying:
You typically don't create a Rasterizer directly; it is managed internally by Renderer. However, for advanced use:
Definition at line 45 of file rasterizer.h.
| scimesh::Rasterizer::Rasterizer | ( | int | w, |
| int | h | ||
| ) |
Construct a rasterizer for the given output size.
Allocates depth and normal buffers.
| w | Output width in pixels. |
| h | Output height in pixels. |
Definition at line 12 of file rasterizer.cpp.
| void scimesh::Rasterizer::apply_ssao | ( | Image & | output, |
| float | z_near, | ||
| float | z_far | ||
| ) |
Apply screen-space ambient occlusion to the output image.
Uses the depth and normal buffers to darken crevices and corners. Must be called after all triangles have been rasterized.
| [in,out] | output | The image to modify. |
| z_near | Near plane distance. | |
| z_far | Far plane distance. |
Definition at line 206 of file rasterizer.cpp.
| void scimesh::Rasterizer::clear | ( | float | clear_depth = 1.0f | ) |
Clear the depth and normal buffers.
Must be called at the start of each frame.
| clear_depth | Initial depth value (default: 1.0 = farthest). |
Definition at line 15 of file rasterizer.cpp.
| void scimesh::Rasterizer::rasterize_point | ( | float | screen_x, |
| float | screen_y, | ||
| float | depth, | ||
| float | radius, | ||
| const Color & | color, | ||
| const Vec3 & | normal, | ||
| const Vec3 & | light_direction, | ||
| Image & | output | ||
| ) |
Rasterize a single point (filled circle) into the output image.
The point is drawn as a circle of the given radius (in screen pixels). Depth testing is performed at the circle center.
| screen_x,screen_y | Screen-space center position. | |
| depth | Depth value for z-buffering. | |
| radius | Circle radius in screen pixels. | |
| color | Point color. | |
| normal | Surface normal (for lighting). | |
| light_direction | Light direction for shading. | |
| [in,out] | output | The output image. |
Definition at line 183 of file rasterizer.cpp.
| void scimesh::Rasterizer::rasterize_triangle | ( | const Vec3 & | screen_v0, |
| const Color & | color0, | ||
| const Vec3 & | normal0, | ||
| const Vec2 & | uv0, | ||
| const Vec3 & | screen_v1, | ||
| const Color & | color1, | ||
| const Vec3 & | normal1, | ||
| const Vec2 & | uv1, | ||
| const Vec3 & | screen_v2, | ||
| const Color & | color2, | ||
| const Vec3 & | normal2, | ||
| const Vec2 & | uv2, | ||
| bool | backface_culling, | ||
| bool | smooth_shading, | ||
| const Vec3 & | light_direction, | ||
| bool | wireframe, | ||
| const Color & | wireframe_color, | ||
| Image & | output | ||
| ) |
Rasterize a single triangle into the output image.
The triangle vertices are in screen space (pixel coordinates with depth). This function performs:
smooth_shading is false)| screen_v0,screen_v1,screen_v2 | Screen-space vertex positions. | |
| color0,color1,color2 | Per-vertex colors. | |
| normal0,normal1,normal2 | Per-vertex normals. | |
| uv0,uv1,uv2 | Per-vertex texture coordinates. | |
| backface_culling | Whether to cull backfaces. | |
| smooth_shading | Whether to interpolate normals. | |
| light_direction | Light direction for shading. | |
| wireframe | Whether to draw wireframe edges. | |
| wireframe_color | Color for wireframe edges. | |
| [in,out] | output | The output image to draw into. |
Definition at line 78 of file rasterizer.cpp.
|
inline |
Enable or disable alpha blending.
| enabled | If true, transparent fragments blend with the existing pixel color. |
Definition at line 174 of file rasterizer.h.
| Image* scimesh::Rasterizer::active_texture = nullptr |
Optional texture image for textured meshes.
Set this before rasterizing textured triangles. The triangle's UV coordinates are used to sample this image.
Definition at line 240 of file rasterizer.h.
| float scimesh::Rasterizer::ambient = 0.3f |
Ambient light level (0.0–1.0, default: 0.3).
Uniform fill light that prevents completely black shadows.
Definition at line 112 of file rasterizer.h.
| bool scimesh::Rasterizer::blend_mode = false |
Enable alpha blending for transparent triangles (default: false).
When enabled, transparent fragments blend with the existing pixel color instead of overwriting it. When disabled, only fully opaque fragments are drawn (alpha is ignored after the depth test).
Definition at line 81 of file rasterizer.h.
| float scimesh::Rasterizer::contrast = 1.0f |
Contrast adjustment (1.0 = no change).
Definition at line 120 of file rasterizer.h.
| Color scimesh::Rasterizer::fog_color = TRANSPARENT_BLACK |
The fog color (what distant objects blend into).
Definition at line 137 of file rasterizer.h.
| bool scimesh::Rasterizer::fog_enabled = false |
Enable depth fog (default: false).
Definition at line 128 of file rasterizer.h.
| float scimesh::Rasterizer::fog_end = 1.0f |
Distance where fog is fully opaque.
Definition at line 134 of file rasterizer.h.
| float scimesh::Rasterizer::fog_start = 0.0f |
Distance where fog begins.
Definition at line 131 of file rasterizer.h.
| int scimesh::Rasterizer::height = 0 |
Output image height in pixels.
Definition at line 53 of file rasterizer.h.
| std::vector<Light> scimesh::Rasterizer::lights |
Light sources for Blinn-Phong shading.
If empty, a default directional light from +Z is used.
Definition at line 107 of file rasterizer.h.
| std::vector<Vec3> scimesh::Rasterizer::normal_buffer |
Normal buffer, one Vec3 per pixel.
Stores the surface normal at each pixel for SSAO computations.
Definition at line 69 of file rasterizer.h.
| float scimesh::Rasterizer::shininess = 0.0f |
Shininess exponent (Phong model).
Higher values = sharper highlights. Typical range: 16–128.
Definition at line 96 of file rasterizer.h.
Specular highlight color.
Set to a non-transparent color to enable specular highlights.
Definition at line 91 of file rasterizer.h.
| bool scimesh::Rasterizer::ssao_enabled = false |
Enable SSAO (default: false).
Definition at line 145 of file rasterizer.h.
| float scimesh::Rasterizer::ssao_intensity = 0.8f |
SSAO darkening intensity (0.0–1.0, default: 0.8).
Definition at line 151 of file rasterizer.h.
| float scimesh::Rasterizer::ssao_radius = 16.0f |
SSAO sample radius in pixels (default: 16).
Definition at line 148 of file rasterizer.h.
| int scimesh::Rasterizer::width = 0 |
Output image width in pixels.
Definition at line 50 of file rasterizer.h.
| std::vector<float> scimesh::Rasterizer::z_buffer |
Z-buffer (depth buffer), one float per pixel.
Stores the depth of the closest surface at each pixel. A new triangle only overwrites a pixel if its depth is closer.
Definition at line 64 of file rasterizer.h.