scimesh 0.3.2
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
rasterizer.h
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <scimesh/types.h>
12#include <scimesh/image.h>
13#include <vector>
14
15namespace scimesh {
16
45struct Rasterizer {
48
50 int width = 0;
51
53 int height = 0;
54
56
59
64 std::vector<float> z_buffer;
65
69 std::vector<Vec3> normal_buffer;
70
72
75
81 bool blend_mode = false;
82
84
87
91 Color specular_color = Color(0.0f, 0.0f, 0.0f, 0.0f);
92
96 float shininess = 0.0f;
97
99
102
107 std::vector<Light> lights;
108
112 float ambient = 0.3f;
113
115
118
120 float contrast = 1.0f;
121
123
126
128 bool fog_enabled = false;
129
131 float fog_start = 0.0f;
132
134 float fog_end = 1.0f;
135
138
140
143
145 bool ssao_enabled = false;
146
148 float ssao_radius = 16.0f;
149
151 float ssao_intensity = 0.8f;
152
154
161 Rasterizer(int w, int h);
162
168 void clear(float clear_depth = 1.0f);
169
174 void set_blend_mode(bool enabled) { blend_mode = enabled; }
175
198 const Vec3 &screen_v0, const Color &color0, const Vec3 &normal0, const Vec2 &uv0,
199 const Vec3 &screen_v1, const Color &color1, const Vec3 &normal1, const Vec2 &uv1,
200 const Vec3 &screen_v2, const Color &color2, const Vec3 &normal2, const Vec2 &uv2,
201 bool backface_culling,
202 bool smooth_shading,
203 const Vec3 &light_direction,
204 bool wireframe,
205 const Color &wireframe_color,
206 Image &output);
207
220 void rasterize_point(float screen_x, float screen_y, float depth,
221 float radius, const Color &color,
222 const Vec3 &normal, const Vec3 &light_direction,
223 Image &output);
224
233 void apply_ssao(Image &output, float z_near, float z_far);
234
241
242private:
244 void shade_and_write(int x, int y, float depth,
245 const Color &color, const Vec3 &normal,
246 const Vec3 &light_direction, Image &output);
247};
248
249} // namespace scimesh
The Image — an RGBA pixel buffer with compositing and I/O operations.
glm::vec2 Vec2
2-component floating-point vector (xy).
Definition types.h:32
glm::vec3 Vec3
3-component floating-point vector (xyz).
Definition types.h:46
constexpr Color TRANSPARENT_BLACK
A fully transparent black color (0, 0, 0, 0).
Definition types.h:150
Vec3 normal2
Definition renderer.cpp:23
Vec3 screen_v2
Definition renderer.cpp:21
Vec3 normal1
Definition renderer.cpp:23
Vec3 normal0
Definition renderer.cpp:23
Vec3 screen_v1
Definition renderer.cpp:21
Vec2 uv1
Definition renderer.cpp:24
Color color0
Definition renderer.cpp:22
Vec2 uv0
Definition renderer.cpp:24
Color color1
Definition renderer.cpp:22
Vec3 screen_v0
Definition renderer.cpp:21
Vec2 uv2
Definition renderer.cpp:24
Color color2
Definition renderer.cpp:22
An RGBA color with floating-point components.
Definition types.h:88
A 2D RGBA image buffer.
Definition image.h:87
Low-level triangle rasterizer with depth buffering and lighting.
Definition rasterizer.h:45
float ssao_radius
SSAO sample radius in pixels (default: 16).
Definition rasterizer.h:148
void clear(float clear_depth=1.0f)
Clear the depth and normal buffers.
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.
float fog_end
Distance where fog is fully opaque.
Definition rasterizer.h:134
Color fog_color
The fog color (what distant objects blend into).
Definition rasterizer.h:137
bool fog_enabled
Enable depth fog (default: false).
Definition rasterizer.h:128
float fog_start
Distance where fog begins.
Definition rasterizer.h:131
void apply_ssao(Image &output, float z_near, float z_far)
Apply screen-space ambient occlusion to the output image.
int height
Output image height in pixels.
Definition rasterizer.h:53
Image * active_texture
Optional texture image for textured meshes.
Definition rasterizer.h:240
float ssao_intensity
SSAO darkening intensity (0.0–1.0, default: 0.8).
Definition rasterizer.h:151
float ambient
Ambient light level (0.0–1.0, default: 0.3).
Definition rasterizer.h:112
int width
Output image width in pixels.
Definition rasterizer.h:50
void set_blend_mode(bool enabled)
Enable or disable alpha blending.
Definition rasterizer.h:174
Color specular_color
Specular highlight color.
Definition rasterizer.h:91
std::vector< Light > lights
Light sources for Blinn-Phong shading.
Definition rasterizer.h:107
float shininess
Shininess exponent (Phong model).
Definition rasterizer.h:96
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.
bool ssao_enabled
Enable SSAO (default: false).
Definition rasterizer.h:145
std::vector< float > z_buffer
Z-buffer (depth buffer), one float per pixel.
Definition rasterizer.h:64
bool blend_mode
Enable alpha blending for transparent triangles (default: false).
Definition rasterizer.h:81
float contrast
Contrast adjustment (1.0 = no change).
Definition rasterizer.h:120
std::vector< Vec3 > normal_buffer
Normal buffer, one Vec3 per pixel.
Definition rasterizer.h:69
Fundamental types used throughout the scimesh rendering engine.