PolyFEM
Loading...
Searching...
No Matches
raster.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <Eigen/Dense>
5
6#include <functional>
7#include <vector>
8
9namespace polyfem
10{
11 namespace renderer
12 {
13 struct Material
14 {
15 Eigen::Vector3d diffuse_color;
16 Eigen::Vector3d specular_color;
18 };
20 {
21 public:
22 VertexAttributes(double x = 0, double y = 0, double z = 0, double w = 1)
23 {
24 position << x, y, z, w;
25 }
26
28 const VertexAttributes &a,
29 const VertexAttributes &b,
30 const VertexAttributes &c,
31 const double alpha,
32 const double beta,
33 const double gamma)
34 {
36 r.position = alpha * (a.position / a.position(3)) + beta * (b.position / b.position(3)) + gamma * (c.position / c.position(3));
37 r.color = alpha * a.color + beta * b.color + gamma * c.color;
38 return r;
39 }
40
41 Eigen::Vector4d position;
42 Eigen::Vector3d normal;
43 Eigen::Vector3d color;
45 };
46
48 {
49 public:
50 FragmentAttributes(double r = 0, double g = 0, double b = 0, double a = 1)
51 {
52 color << r, g, b, a;
53 }
54 double depth;
55 Eigen::Vector4d color;
56 };
57
59 {
60 public:
61 FrameBufferAttributes(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, uint8_t a = 255)
62 {
63 color << r, g, b, a;
64 depth = 2;
65 }
66 double depth;
67 Eigen::Matrix<uint8_t, 4, 1> color;
68 };
69
71 {
72 public:
73 Eigen::Matrix4d M_cam;
74
75 Eigen::Matrix4d M_orth;
76 Eigen::Matrix4d M;
77 };
78
86
87 std::vector<uint8_t> render(const Eigen::MatrixXd &vertices, const Eigen::MatrixXi &faces, const Eigen::MatrixXi &faces_id,
88 int width, int height,
89 const Eigen::Vector3d &camera_position, const double camera_fov, const double camera_near, const double camera_far, const bool is_perspective, const Eigen::Vector3d &lookat, const Eigen::Vector3d &up,
90 const Eigen::Vector3d &ambient_light, const std::vector<std::pair<Eigen::MatrixXd, Eigen::MatrixXd>> &lights,
91 std::vector<Material> &materials);
92 } // namespace renderer
93} // namespace polyfem
std::vector< Eigen::VectorXi > faces
int y
int z
int x
FragmentAttributes(double r=0, double g=0, double b=0, double a=1)
Definition raster.hpp:50
Eigen::Matrix< uint8_t, 4, 1 > color
Definition raster.hpp:67
FrameBufferAttributes(uint8_t r=0, uint8_t g=0, uint8_t b=0, uint8_t a=255)
Definition raster.hpp:61
std::function< FragmentAttributes(const VertexAttributes &, const UniformAttributes &)> FragmentShader
Definition raster.hpp:83
std::function< VertexAttributes(const VertexAttributes &, const UniformAttributes &)> VertexShader
Definition raster.hpp:82
std::function< FrameBufferAttributes(const FragmentAttributes &, const FrameBufferAttributes &)> BlendingShader
Definition raster.hpp:84
static VertexAttributes interpolate(const VertexAttributes &a, const VertexAttributes &b, const VertexAttributes &c, const double alpha, const double beta, const double gamma)
Definition raster.hpp:27
VertexAttributes(double x=0, double y=0, double z=0, double w=1)
Definition raster.hpp:22
std::vector< uint8_t > render(const Eigen::MatrixXd &vertices, const Eigen::MatrixXi &faces, const Eigen::MatrixXi &faces_id, int width, int height, const Eigen::Vector3d &camera_position, const double camera_fov, const double camera_near, const double camera_far, const bool is_perspective, const Eigen::Vector3d &lookat, const Eigen::Vector3d &up, const Eigen::Vector3d &ambient_light, const std::vector< std::pair< Eigen::MatrixXd, Eigen::MatrixXd > > &lights, std::vector< Material > &materials)
Definition raster.cpp:155
Eigen::Vector3d specular_color
Definition raster.hpp:16
Eigen::Vector3d diffuse_color
Definition raster.hpp:15