Open3D (C++ API)  0.18.0+252c867
TexturePhongShader.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 
21 public:
22  ~TexturePhongShader() override { Release(); }
23 
24 protected:
25  TexturePhongShader(const std::string &name) : ShaderWrapper(name) {
26  Compile();
27  }
28 
29 protected:
30  bool Compile() final;
31  void Release() final;
32  bool BindGeometry(const geometry::Geometry &geometry,
33  const RenderOption &option,
34  const ViewControl &view) final;
35  bool RenderGeometry(const geometry::Geometry &geometry,
36  const RenderOption &option,
37  const ViewControl &view) final;
38  void UnbindGeometry() final;
39 
40 protected:
41  virtual bool PrepareRendering(const geometry::Geometry &geometry,
42  const RenderOption &option,
43  const ViewControl &view) = 0;
44  virtual bool PrepareBinding(const geometry::Geometry &geometry,
45  const RenderOption &option,
46  const ViewControl &view,
47  std::vector<Eigen::Vector3f> &points,
48  std::vector<Eigen::Vector3f> &normals,
49  std::vector<Eigen::Vector2f> &uvs) = 0;
50 
51 protected:
52  void SetLighting(const ViewControl &view, const RenderOption &option);
53 
54 protected:
56  GLuint vertex_uv_;
58  GLuint MVP_;
59  GLuint V_;
60  GLuint M_;
62  GLuint light_color_;
67 
69 
71  std::vector<int> array_offsets_;
72  std::vector<GLsizei> draw_array_sizes_;
73 
74  std::vector<GLuint> vertex_position_buffers_;
75  std::vector<GLuint> vertex_uv_buffers_;
76  std::vector<GLuint> vertex_normal_buffers_;
77  std::vector<GLuint> diffuse_texture_buffers_;
78 
79  // At most support 4 lights
86 };
87 
89 public:
91  : TexturePhongShader("TexturePhongShaderForTriangleMesh") {}
92 
93 protected:
94  bool PrepareRendering(const geometry::Geometry &geometry,
95  const RenderOption &option,
96  const ViewControl &view) final;
97  bool PrepareBinding(const geometry::Geometry &geometry,
98  const RenderOption &option,
99  const ViewControl &view,
100  std::vector<Eigen::Vector3f> &points,
101  std::vector<Eigen::Vector3f> &normals,
102  std::vector<Eigen::Vector2f> &uvs) final;
103 };
104 
105 } // namespace glsl
106 
107 } // namespace visualization
108 } // 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
Definition: ShaderWrapper.h:21
TexturePhongShaderForTriangleMesh()
Definition: TexturePhongShader.h:90
Definition: TexturePhongShader.h:20
GLuint vertex_normal_
Definition: TexturePhongShader.h:57
void Release() final
Definition: TexturePhongShader.cpp:48
TexturePhongShader(const std::string &name)
Definition: TexturePhongShader.h:25
GLuint M_
Definition: TexturePhongShader.h:60
std::vector< GLuint > vertex_normal_buffers_
Definition: TexturePhongShader.h:76
std::vector< GLuint > diffuse_texture_buffers_
Definition: TexturePhongShader.h:77
GLuint MVP_
Definition: TexturePhongShader.h:58
bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: TexturePhongShader.cpp:98
GLuint V_
Definition: TexturePhongShader.h:59
GLuint vertex_position_
Definition: TexturePhongShader.h:55
GLuint light_diffuse_power_
Definition: TexturePhongShader.h:63
bool Compile() final
Definition: TexturePhongShader.cpp:21
gl_util::GLMatrix4f light_color_data_
Definition: TexturePhongShader.h:81
virtual bool PrepareRendering(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
gl_util::GLVector4f light_diffuse_power_data_
Definition: TexturePhongShader.h:82
GLuint light_position_world_
Definition: TexturePhongShader.h:61
gl_util::GLVector4f light_specular_power_data_
Definition: TexturePhongShader.h:83
GLuint light_specular_power_
Definition: TexturePhongShader.h:64
std::vector< GLsizei > draw_array_sizes_
Definition: TexturePhongShader.h:72
GLuint light_color_
Definition: TexturePhongShader.h:62
std::vector< int > array_offsets_
Definition: TexturePhongShader.h:71
GLuint light_specular_shininess_
Definition: TexturePhongShader.h:65
GLuint vertex_uv_
Definition: TexturePhongShader.h:56
void SetLighting(const ViewControl &view, const RenderOption &option)
Definition: TexturePhongShader.cpp:172
GLuint light_ambient_
Definition: TexturePhongShader.h:66
std::vector< GLuint > vertex_position_buffers_
Definition: TexturePhongShader.h:74
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::Vector2f > &uvs)=0
bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: TexturePhongShader.cpp:53
GLuint diffuse_texture_
Definition: TexturePhongShader.h:68
~TexturePhongShader() override
Definition: TexturePhongShader.h:22
gl_util::GLVector4f light_specular_shininess_data_
Definition: TexturePhongShader.h:84
gl_util::GLMatrix4f light_position_world_data_
Definition: TexturePhongShader.h:80
gl_util::GLVector4f light_ambient_data_
Definition: TexturePhongShader.h:85
std::vector< GLuint > vertex_uv_buffers_
Definition: TexturePhongShader.h:75
int num_materials_
Definition: TexturePhongShader.h:70
void UnbindGeometry() final
Definition: TexturePhongShader.cpp:146
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