Open3D (C++ API)  0.18.0
Loading...
Searching...
No Matches
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
15namespace open3d {
16namespace visualization {
17
18namespace glsl {
19
20class PhongShader : public ShaderWrapper {
21public:
22 ~PhongShader() override { Release(); }
23
24protected:
25 PhongShader(const std::string &name) : ShaderWrapper(name) { Compile(); }
26
27protected:
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
38protected:
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
49protected:
50 void SetLighting(const ViewControl &view, const RenderOption &option);
51
52protected:
59 GLuint MVP_;
60 GLuint V_;
61 GLuint M_;
68
69 // At most support 4 lights
70 gl_util::GLMatrix4f light_position_world_data_;
71 gl_util::GLMatrix4f light_color_data_;
72 gl_util::GLVector4f light_diffuse_power_data_;
73 gl_util::GLVector4f light_specular_power_data_;
74 gl_util::GLVector4f light_specular_shininess_data_;
75 gl_util::GLVector4f light_ambient_data_;
76};
77
79public:
80 PhongShaderForPointCloud() : PhongShader("PhongShaderForPointCloud") {}
81
82protected:
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
95public:
96 PhongShaderForTriangleMesh() : PhongShader("PhongShaderForTriangleMesh") {}
97
98protected:
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
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
Definition PinholeCameraIntrinsic.cpp:16
Definition Device.h:107