Open3D (C++ API)
PhongShader.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <vector>
30 #include <Eigen/Core>
32 
33 namespace open3d {
34 namespace visualization {
35 
36 namespace glsl {
37 
38 class PhongShader : public ShaderWrapper {
39 public:
40  ~PhongShader() override { Release(); }
41 
42 protected:
43  PhongShader(const std::string &name) : ShaderWrapper(name) { Compile(); }
44 
45 protected:
46  bool Compile() final;
47  void Release() final;
48  bool BindGeometry(const geometry::Geometry &geometry,
49  const RenderOption &option,
50  const ViewControl &view) final;
51  bool RenderGeometry(const geometry::Geometry &geometry,
52  const RenderOption &option,
53  const ViewControl &view) final;
54  void UnbindGeometry() final;
55 
56 protected:
57  virtual bool PrepareRendering(const geometry::Geometry &geometry,
58  const RenderOption &option,
59  const ViewControl &view) = 0;
60  virtual bool PrepareBinding(const geometry::Geometry &geometry,
61  const RenderOption &option,
62  const ViewControl &view,
63  std::vector<Eigen::Vector3f> &points,
64  std::vector<Eigen::Vector3f> &normals,
65  std::vector<Eigen::Vector3f> &colors) = 0;
66 
67 protected:
68  void SetLighting(const ViewControl &view, const RenderOption &option);
69 
70 protected:
73  GLuint vertex_color_;
77  GLuint MVP_;
78  GLuint V_;
79  GLuint M_;
81  GLuint light_color_;
86 
87  // At most support 4 lights
94 };
95 
97 public:
98  PhongShaderForPointCloud() : PhongShader("PhongShaderForPointCloud") {}
99 
100 protected:
101  bool PrepareRendering(const geometry::Geometry &geometry,
102  const RenderOption &option,
103  const ViewControl &view) final;
104  bool PrepareBinding(const geometry::Geometry &geometry,
105  const RenderOption &option,
106  const ViewControl &view,
107  std::vector<Eigen::Vector3f> &points,
108  std::vector<Eigen::Vector3f> &normals,
109  std::vector<Eigen::Vector3f> &colors) final;
110 };
111 
113 public:
114  PhongShaderForTriangleMesh() : PhongShader("PhongShaderForTriangleMesh") {}
115 
116 protected:
117  bool PrepareRendering(const geometry::Geometry &geometry,
118  const RenderOption &option,
119  const ViewControl &view) final;
120  bool PrepareBinding(const geometry::Geometry &geometry,
121  const RenderOption &option,
122  const ViewControl &view,
123  std::vector<Eigen::Vector3f> &points,
124  std::vector<Eigen::Vector3f> &normals,
125  std::vector<Eigen::Vector3f> &colors) final;
126 };
127 
128 } // namespace glsl
129 
130 } // namespace visualization
131 } // namespace open3d
~PhongShader() override
Definition: PhongShader.h:40
GLuint vertex_position_
Definition: PhongShader.h:71
Definition: Geometry.h:32
GLuint vertex_color_
Definition: PhongShader.h:73
GLuint light_color_
Definition: PhongShader.h:81
GLHelper::GLVector4f light_specular_power_data_
Definition: PhongShader.h:91
void SetLighting(const ViewControl &view, const RenderOption &option)
Definition: PhongShader.cpp:150
bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: PhongShader.cpp:68
Definition: ViewControl.h:38
GLuint MVP_
Definition: PhongShader.h:77
GLuint light_diffuse_power_
Definition: PhongShader.h:82
Eigen::Matrix< GLfloat, 4, 1, Eigen::ColMajor > GLVector4f
Definition: GLHelper.h:39
GLuint light_position_world_
Definition: PhongShader.h:80
Definition: PhongShader.h:38
bool Compile() final
Definition: PhongShader.cpp:39
GLuint V_
Definition: PhongShader.h:78
GLuint light_specular_power_
Definition: PhongShader.h:83
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:40
GLuint vertex_normal_
Definition: PhongShader.h:75
GLuint light_specular_shininess_
Definition: PhongShader.h:84
GLuint M_
Definition: PhongShader.h:79
Definition: RenderOption.h:36
void UnbindGeometry() final
Definition: PhongShader.cpp:141
void Release() final
Definition: PhongShader.cpp:63
GLHelper::GLVector4f light_diffuse_power_data_
Definition: PhongShader.h:90
GLHelper::GLMatrix4f light_position_world_data_
Definition: PhongShader.h:88
GLuint vertex_color_buffer_
Definition: PhongShader.h:74
GLHelper::GLVector4f light_specular_shininess_data_
Definition: PhongShader.h:92
int points
Definition: FilePCD.cpp:69
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
Definition: PinholeCameraIntrinsic.cpp:33
GLuint light_ambient_
Definition: PhongShader.h:85
virtual bool PrepareRendering(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
GLHelper::GLMatrix4f light_color_data_
Definition: PhongShader.h:89
std::string name
Definition: FilePCD.cpp:54
Definition: ShaderWrapper.h:40
bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: PhongShader.cpp:106
GLHelper::GLVector4f light_ambient_data_
Definition: PhongShader.h:93
PhongShaderForPointCloud()
Definition: PhongShader.h:98
PhongShader(const std::string &name)
Definition: PhongShader.h:43
GLuint vertex_position_buffer_
Definition: PhongShader.h:72
PhongShaderForTriangleMesh()
Definition: PhongShader.h:114
GLuint vertex_normal_buffer_
Definition: PhongShader.h:76