Open3D (C++ API)  0.18.0+5c982c7
PhongShader.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <vector>
12 
14 
15 namespace open3d {
16 namespace visualization {
17 
18 namespace glsl {
19 
20 class PhongShader : public ShaderWrapper {
21 public:
22  ~PhongShader() override { Release(); }
23 
24 protected:
25  PhongShader(const std::string &name) : ShaderWrapper(name) { Compile(); }
26 
27 protected:
28  bool Compile() final;
29  void Release() final;
30  bool BindGeometry(const geometry::Geometry &geometry,
31  const RenderOption &option,
32  const ViewControl &view) final;
33  bool RenderGeometry(const geometry::Geometry &geometry,
34  const RenderOption &option,
35  const ViewControl &view) final;
36  void UnbindGeometry() final;
37 
38 protected:
39  virtual bool PrepareRendering(const geometry::Geometry &geometry,
40  const RenderOption &option,
41  const ViewControl &view) = 0;
42  virtual bool PrepareBinding(const geometry::Geometry &geometry,
43  const RenderOption &option,
44  const ViewControl &view,
45  std::vector<Eigen::Vector3f> &points,
46  std::vector<Eigen::Vector3f> &normals,
47  std::vector<Eigen::Vector3f> &colors) = 0;
48 
49 protected:
50  void SetLighting(const ViewControl &view, const RenderOption &option);
51 
52 protected:
55  GLuint vertex_color_;
59  GLuint MVP_;
60  GLuint V_;
61  GLuint M_;
63  GLuint light_color_;
68 
69  // At most support 4 lights
76 };
77 
79 public:
80  PhongShaderForPointCloud() : PhongShader("PhongShaderForPointCloud") {}
81 
82 protected:
83  bool PrepareRendering(const geometry::Geometry &geometry,
84  const RenderOption &option,
85  const ViewControl &view) final;
86  bool PrepareBinding(const geometry::Geometry &geometry,
87  const RenderOption &option,
88  const ViewControl &view,
89  std::vector<Eigen::Vector3f> &points,
90  std::vector<Eigen::Vector3f> &normals,
91  std::vector<Eigen::Vector3f> &colors) final;
92 };
93 
95 public:
96  PhongShaderForTriangleMesh() : PhongShader("PhongShaderForTriangleMesh") {}
97 
98 protected:
99  bool PrepareRendering(const geometry::Geometry &geometry,
100  const RenderOption &option,
101  const ViewControl &view) final;
102  bool PrepareBinding(const geometry::Geometry &geometry,
103  const RenderOption &option,
104  const ViewControl &view,
105  std::vector<Eigen::Vector3f> &points,
106  std::vector<Eigen::Vector3f> &normals,
107  std::vector<Eigen::Vector3f> &colors) final;
108 };
109 
110 } // namespace glsl
111 
112 } // namespace visualization
113 } // namespace open3d
The base geometry class.
Definition: Geometry.h:18
Defines rendering options for visualizer.
Definition: RenderOption.h:20
View controller for visualizer.
Definition: ViewControl.h:23
PhongShaderForPointCloud()
Definition: PhongShader.h:80
PhongShaderForTriangleMesh()
Definition: PhongShader.h:96
Definition: PhongShader.h:20
GLuint M_
Definition: PhongShader.h:61
bool Compile() final
Definition: PhongShader.cpp:20
gl_util::GLVector4f light_specular_shininess_data_
Definition: PhongShader.h:74
bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: PhongShader.cpp:49
GLuint light_specular_power_
Definition: PhongShader.h:65
gl_util::GLMatrix4f light_position_world_data_
Definition: PhongShader.h:70
GLuint V_
Definition: PhongShader.h:60
GLuint vertex_color_buffer_
Definition: PhongShader.h:56
GLuint light_diffuse_power_
Definition: PhongShader.h:64
GLuint light_ambient_
Definition: PhongShader.h:67
GLuint vertex_position_buffer_
Definition: PhongShader.h:54
void SetLighting(const ViewControl &view, const RenderOption &option)
Definition: PhongShader.cpp:130
GLuint vertex_normal_
Definition: PhongShader.h:57
GLuint light_position_world_
Definition: PhongShader.h:62
GLuint vertex_color_
Definition: PhongShader.h:55
GLuint vertex_position_
Definition: PhongShader.h:53
virtual bool PrepareRendering(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
void Release() final
Definition: PhongShader.cpp:44
PhongShader(const std::string &name)
Definition: PhongShader.h:25
virtual bool PrepareBinding(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view, std::vector< Eigen::Vector3f > &points, std::vector< Eigen::Vector3f > &normals, std::vector< Eigen::Vector3f > &colors)=0
gl_util::GLVector4f light_specular_power_data_
Definition: PhongShader.h:73
bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: PhongShader.cpp:86
GLuint MVP_
Definition: PhongShader.h:59
GLuint light_color_
Definition: PhongShader.h:63
void UnbindGeometry() final
Definition: PhongShader.cpp:121
GLuint light_specular_shininess_
Definition: PhongShader.h:66
gl_util::GLVector4f light_diffuse_power_data_
Definition: PhongShader.h:72
~PhongShader() override
Definition: PhongShader.h:22
gl_util::GLMatrix4f light_color_data_
Definition: PhongShader.h:71
GLuint vertex_normal_buffer_
Definition: PhongShader.h:58
gl_util::GLVector4f light_ambient_data_
Definition: PhongShader.h:75
Definition: ShaderWrapper.h:21
std::string name
Definition: FilePCD.cpp:39
int points
Definition: FilePCD.cpp:54
Definition: NonRigidOptimizer.cpp:22
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:34
Eigen::Matrix< GLfloat, 4, 1, Eigen::ColMajor > GLVector4f
Definition: GLHelper.h:33
Definition: PinholeCameraIntrinsic.cpp:16
Definition: Device.h:107