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 <Eigen/Core>
30 #include <vector>
31 
33 
34 namespace open3d {
35 namespace visualization {
36 
37 namespace glsl {
38 
39 class PhongShader : public ShaderWrapper {
40 public:
41  ~PhongShader() override { Release(); }
42 
43 protected:
44  PhongShader(const std::string &name) : ShaderWrapper(name) { Compile(); }
45 
46 protected:
47  bool Compile() final;
48  void Release() final;
49  bool BindGeometry(const geometry::Geometry &geometry,
50  const RenderOption &option,
51  const ViewControl &view) final;
52  bool RenderGeometry(const geometry::Geometry &geometry,
53  const RenderOption &option,
54  const ViewControl &view) final;
55  void UnbindGeometry() final;
56 
57 protected:
58  virtual bool PrepareRendering(const geometry::Geometry &geometry,
59  const RenderOption &option,
60  const ViewControl &view) = 0;
61  virtual bool PrepareBinding(const geometry::Geometry &geometry,
62  const RenderOption &option,
63  const ViewControl &view,
64  std::vector<Eigen::Vector3f> &points,
65  std::vector<Eigen::Vector3f> &normals,
66  std::vector<Eigen::Vector3f> &colors) = 0;
67 
68 protected:
69  void SetLighting(const ViewControl &view, const RenderOption &option);
70 
71 protected:
74  GLuint vertex_color_;
78  GLuint MVP_;
79  GLuint V_;
80  GLuint M_;
82  GLuint light_color_;
87 
88  // At most support 4 lights
95 };
96 
98 public:
99  PhongShaderForPointCloud() : PhongShader("PhongShaderForPointCloud") {}
100 
101 protected:
102  bool PrepareRendering(const geometry::Geometry &geometry,
103  const RenderOption &option,
104  const ViewControl &view) final;
105  bool PrepareBinding(const geometry::Geometry &geometry,
106  const RenderOption &option,
107  const ViewControl &view,
108  std::vector<Eigen::Vector3f> &points,
109  std::vector<Eigen::Vector3f> &normals,
110  std::vector<Eigen::Vector3f> &colors) final;
111 };
112 
114 public:
115  PhongShaderForTriangleMesh() : PhongShader("PhongShaderForTriangleMesh") {}
116 
117 protected:
118  bool PrepareRendering(const geometry::Geometry &geometry,
119  const RenderOption &option,
120  const ViewControl &view) final;
121  bool PrepareBinding(const geometry::Geometry &geometry,
122  const RenderOption &option,
123  const ViewControl &view,
124  std::vector<Eigen::Vector3f> &points,
125  std::vector<Eigen::Vector3f> &normals,
126  std::vector<Eigen::Vector3f> &colors) final;
127 };
128 
129 } // namespace glsl
130 
131 } // namespace visualization
132 } // namespace open3d
open3d::visualization::glsl::PhongShader::light_color_data_
GLHelper::GLMatrix4f light_color_data_
Definition: PhongShader.h:90
open3d::visualization::glsl::PhongShader::vertex_position_buffer_
GLuint vertex_position_buffer_
Definition: PhongShader.h:73
open3d::visualization::glsl::PhongShader::vertex_position_
GLuint vertex_position_
Definition: PhongShader.h:72
Eigen
Definition: EigenHelperForNonRigidOptimization.h:33
open3d::visualization::glsl::PhongShader::light_specular_power_data_
GLHelper::GLVector4f light_specular_power_data_
Definition: PhongShader.h:92
open3d::visualization::glsl::PhongShader::light_diffuse_power_
GLuint light_diffuse_power_
Definition: PhongShader.h:83
open3d::visualization::glsl::PhongShader::RenderGeometry
bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: PhongShader.cpp:106
open3d::visualization::glsl::PhongShader::PrepareRendering
virtual bool PrepareRendering(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
open3d::visualization::glsl::PhongShader::light_specular_shininess_
GLuint light_specular_shininess_
Definition: PhongShader.h:85
open3d::visualization::GLHelper::GLMatrix4f
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:46
open3d::visualization::RenderOption
Definition: RenderOption.h:36
open3d::visualization::glsl::PhongShader::V_
GLuint V_
Definition: PhongShader.h:79
open3d::visualization::glsl::PhongShader::M_
GLuint M_
Definition: PhongShader.h:80
open3d::visualization::glsl::PhongShader::vertex_normal_buffer_
GLuint vertex_normal_buffer_
Definition: PhongShader.h:77
open3d::visualization::glsl::PhongShader::vertex_color_buffer_
GLuint vertex_color_buffer_
Definition: PhongShader.h:75
open3d::visualization::glsl::PhongShaderForTriangleMesh
Definition: PhongShader.h:113
open3d::visualization::glsl::PhongShader::light_ambient_
GLuint light_ambient_
Definition: PhongShader.h:86
open3d::visualization::glsl::PhongShader::~PhongShader
~PhongShader() override
Definition: PhongShader.h:41
open3d::visualization::glsl::PhongShader
Definition: PhongShader.h:39
open3d::geometry::Geometry
The base geometry class.
Definition: Geometry.h:35
open3d::visualization::glsl::PhongShader::vertex_color_
GLuint vertex_color_
Definition: PhongShader.h:74
open3d::visualization::glsl::PhongShader::MVP_
GLuint MVP_
Definition: PhongShader.h:78
open3d::visualization::glsl::PhongShader::light_color_
GLuint light_color_
Definition: PhongShader.h:82
open3d::visualization::glsl::PhongShader::light_ambient_data_
GLHelper::GLVector4f light_ambient_data_
Definition: PhongShader.h:94
open3d::visualization::glsl::PhongShader::vertex_normal_
GLuint vertex_normal_
Definition: PhongShader.h:76
open3d::visualization::glsl::PhongShader::light_diffuse_power_data_
GLHelper::GLVector4f light_diffuse_power_data_
Definition: PhongShader.h:91
open3d::visualization::glsl::PhongShader::light_specular_shininess_data_
GLHelper::GLVector4f light_specular_shininess_data_
Definition: PhongShader.h:93
open3d::visualization::glsl::PhongShader::light_position_world_
GLuint light_position_world_
Definition: PhongShader.h:81
points
int points
Definition: FilePCD.cpp:70
open3d::visualization::glsl::PhongShaderForTriangleMesh::PhongShaderForTriangleMesh
PhongShaderForTriangleMesh()
Definition: PhongShader.h:115
open3d::visualization::glsl::PhongShader::SetLighting
void SetLighting(const ViewControl &view, const RenderOption &option)
Definition: PhongShader.cpp:150
name
std::string name
Definition: FilePCD.cpp:55
ShaderWrapper.h
open3d::visualization::glsl::PhongShader::PhongShader
PhongShader(const std::string &name)
Definition: PhongShader.h:44
open3d::visualization::glsl::PhongShaderForPointCloud
Definition: PhongShader.h:97
open3d::visualization::glsl::PhongShader::light_specular_power_
GLuint light_specular_power_
Definition: PhongShader.h:84
open3d::visualization::glsl::PhongShader::PrepareBinding
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
open3d::visualization::glsl::ShaderWrapper
Definition: ShaderWrapper.h:40
open3d::visualization::ViewControl
Definition: ViewControl.h:38
open3d::visualization::glsl::PhongShaderForPointCloud::PhongShaderForPointCloud
PhongShaderForPointCloud()
Definition: PhongShader.h:99
open3d::visualization::glsl::PhongShader::light_position_world_data_
GLHelper::GLMatrix4f light_position_world_data_
Definition: PhongShader.h:89
open3d
Definition: PinholeCameraIntrinsic.cpp:34
open3d::visualization::glsl::PhongShader::UnbindGeometry
void UnbindGeometry() final
Definition: PhongShader.cpp:141
open3d::visualization::GLHelper::GLVector4f
Eigen::Matrix< GLfloat, 4, 1, Eigen::ColMajor > GLVector4f
Definition: GLHelper.h:45
open3d::visualization::glsl::PhongShader::Release
void Release() final
Definition: PhongShader.cpp:63
open3d::visualization::glsl::PhongShader::Compile
bool Compile() final
Definition: PhongShader.cpp:39
open3d::visualization::glsl::PhongShader::BindGeometry
bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: PhongShader.cpp:68