Dandelion 2.0.0
A light-weight 3D builder for educational usage
载入中...
搜索中...
未找到
rasterizer.h
浏览该文件的文档.
1#ifndef DANDELION_RENDER_RASTERIZER_H
2#define DANDELION_RENDER_RASTERIZER_H
3
4#include <Eigen/Core>
5#include <Eigen/Geometry>
6#include <spdlog/spdlog.h>
7
8#include "triangle.h"
9
10/*!
11 * \file render/rasterizer.h
12 * \ingroup rendering
13 * \~chinese
14 * \brief 光栅化渲染器中光栅化阶段的实现。
15 */
16
17float sign(Eigen::Vector2f p1, Eigen::Vector2f p2, Eigen::Vector2f p3);
18
19/*!
20 * \ingroup rendering
21 * \~chinese
22 * \brief 光栅化器
23 */
25{
26public:
27
28 /*!
29 * \~chinese
30 * \brief 负责执行光栅化的工作线程
31 *
32 * 不断读取顶点着色输出队列中的顶点数据,每三个顶点将其光栅化为三角形片元
33 *
34 */
35 void worker_thread();
36
37private:
38
39 /*!
40 * \~chinese
41 * \brief 将指定三角形光栅化为片元。
42 *
43 * \param t 要进行光栅化的三角形
44 */
46
47 /*! \~chinese 判断像素坐标 (x,y) 是否在给定三个顶点的三角形内 */
48 static bool inside_triangle(int x, int y, const Eigen::Vector4f* vertices);
49 /*! \~chinese 计算像素坐标 (x,y) 在给定三个顶点的三角形内的重心坐标 */
50 static std::tuple<float, float, float>
51 compute_barycentric_2d(float x, float y, const Eigen::Vector4f* v);
52 /*!
53 * \~chinese
54 * \brief 对顶点的任意属性(如world space坐标,法线向量)利用屏幕空间进行插值
55 *
56 * 这里的插值使用了透视矫正插值
57 *
58 * \param alpha, beta, gamma 计算出的重心坐标
59 * \param vert1, vert2, vert3 三角形的三个顶点的任意待插值属性
60 * \param weight 三个顶点的 w 坐标 (`Vector3f{v[0].w(), v[1].w(), v[2].w()}`)
61 * \param Z 1 / (alpha / v[0].w() + beta / v[1].w() + gamma / v[2].w());
62 */
63 static Eigen::Vector3f interpolate(
64 float alpha, float beta, float gamma, const Eigen::Vector3f& vert1,
65 const Eigen::Vector3f& vert2, const Eigen::Vector3f& vert3, const Eigen::Vector3f& weight,
66 const float& Z
67 );
68};
69
70#endif // DANDELION_RENDER_RASTERIZER_H
光栅化器
定义 rasterizer.h:25
void rasterize_triangle(Triangle &t)
将指定三角形光栅化为片元。
定义 rasterizer.cpp:117
static bool inside_triangle(int x, int y, const Eigen::Vector4f *vertices)
定义 rasterizer.cpp:64
static Eigen::Vector3f interpolate(float alpha, float beta, float gamma, const Eigen::Vector3f &vert1, const Eigen::Vector3f &vert2, const Eigen::Vector3f &vert3, const Eigen::Vector3f &weight, const float &Z)
对顶点的任意属性(如world space坐标,法线向量)利用屏幕空间进行插值
定义 rasterizer.cpp:101
void worker_thread()
负责执行光栅化的工作线程
定义 rasterizer.cpp:19
static std::tuple< float, float, float > compute_barycentric_2d(float x, float y, const Eigen::Vector4f *v)
定义 rasterizer.cpp:80
表示一个三角形,包括三个顶点的世界坐标,视口坐标以及每个顶点的法向向量
定义 triangle.h:18