Dandelion 1.1.2
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 <algorithm>
5#include <functional>
6#include <map>
7#include <vector>
8#include <list>
9#include <queue>
10
11#include <Eigen/Core>
12#include <Eigen/Geometry>
13#include <spdlog/spdlog.h>
14
15#include "../platform/gl.hpp"
16#include "../scene/light.h"
17#include "../scene/camera.h"
18#include "triangle.h"
19#include "rasterizer_renderer.h"
20
21/*!
22 * \file render/rasterizer.h
23 * \ingroup rendering
24 * \~chinese
25 * \brief 光栅化渲染器中光栅化阶段的实现。
26 */
27
28float sign(Eigen::Vector2f p1, Eigen::Vector2f p2, Eigen::Vector2f p3);
29
30/*!
31 * \ingroup rendering
32 * \~chinese
33 * \brief 光栅化器
34 */
36{
37public:
38 /*!
39 * \~chinese
40 * \brief 负责执行光栅化的工作线程
41 *
42 * 不断读取顶点着色输出队列中的顶点数据,每三个顶点将其光栅化为三角形片元
43 *
44 */
45 void worker_thread();
46
47private:
48
49 /*!
50 * \~chinese
51 * \brief 将指定三角形光栅化为片元。
52 *
53 * \param t 要进行光栅化的三角形
54 */
56
57 /*! \~chinese 判断像素坐标 (x,y) 是否在给定三个顶点的三角形内 */
58 static bool inside_triangle(int x, int y, const Eigen::Vector4f* vertices);
59 /*! \~chinese 计算像素坐标 (x,y) 在给定三个顶点的三角形内的重心坐标 */
60 static std::tuple<float, float, float>
61 compute_barycentric_2d(float x, float y, const Eigen::Vector4f* v);
62 /*!
63 * \~chinese
64 * \brief 对顶点的任意属性(如world space坐标,法线向量)利用屏幕空间进行插值
65 *
66 * 这里的插值使用了透视矫正插值
67 *
68 * \param alpha, beta, gamma 计算出的重心坐标
69 * \param vert1, vert2, vert3 三角形的三个顶点的任意待插值属性
70 * \param weight 三个顶点的 w 坐标 (`Vector3f{v[0].w(), v[1].w(), v[2].w()}`)
71 * \param Z 1 / (alpha / v[0].w() + beta / v[1].w() + gamma / v[2].w());
72 */
73 static Eigen::Vector3f interpolate(
74 float alpha, float beta, float gamma, const Eigen::Vector3f& vert1,
75 const Eigen::Vector3f& vert2, const Eigen::Vector3f& vert3, const Eigen::Vector3f& weight,
76 const float& Z
77 );
78};
79
80#endif // DANDELION_RENDER_RASTERIZER_H
包含相机的类,用来表示场景中的相机。
光栅化器
定义 rasterizer.h:36
void rasterize_triangle(Triangle &t)
将指定三角形光栅化为片元。
定义 rasterizer.cpp:122
static bool inside_triangle(int x, int y, const Eigen::Vector4f *vertices)
定义 rasterizer.cpp:69
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:106
void worker_thread()
负责执行光栅化的工作线程
定义 rasterizer.cpp:24
static std::tuple< float, float, float > compute_barycentric_2d(float x, float y, const Eigen::Vector4f *v)
定义 rasterizer.cpp:85
表示一个三角形,包括三个顶点的世界坐标,视口坐标以及每个顶点的法向向量
定义 triangle.h:18
包含光源的类,目前只有一个点光源。
光栅化渲染器中顶点处理、片元处理两个阶段的实现。