Open3D (C++ API)  0.15.1
TexturePhongShader.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-2021 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
34namespace open3d {
35namespace visualization {
36
37namespace glsl {
38
40public:
41 ~TexturePhongShader() override { Release(); }
42
43protected:
44 TexturePhongShader(const std::string &name) : ShaderWrapper(name) {
45 Compile();
46 }
47
48protected:
49 bool Compile() final;
50 void Release() final;
51 bool BindGeometry(const geometry::Geometry &geometry,
52 const RenderOption &option,
53 const ViewControl &view) final;
54 bool RenderGeometry(const geometry::Geometry &geometry,
55 const RenderOption &option,
56 const ViewControl &view) final;
57 void UnbindGeometry() final;
58
59protected:
60 virtual bool PrepareRendering(const geometry::Geometry &geometry,
61 const RenderOption &option,
62 const ViewControl &view) = 0;
63 virtual bool PrepareBinding(const geometry::Geometry &geometry,
64 const RenderOption &option,
65 const ViewControl &view,
66 std::vector<Eigen::Vector3f> &points,
67 std::vector<Eigen::Vector3f> &normals,
68 std::vector<Eigen::Vector2f> &uvs) = 0;
69
70protected:
71 void SetLighting(const ViewControl &view, const RenderOption &option);
72
73protected:
75 GLuint vertex_uv_;
77 GLuint MVP_;
78 GLuint V_;
79 GLuint M_;
86
88
90 std::vector<int> array_offsets_;
91 std::vector<GLsizei> draw_array_sizes_;
92
94 std::vector<GLuint> vertex_uv_buffers_;
95 std::vector<GLuint> vertex_normal_buffers_;
97
98 // At most support 4 lights
105};
106
108public:
110 : TexturePhongShader("TexturePhongShaderForTriangleMesh") {}
111
112protected:
113 bool PrepareRendering(const geometry::Geometry &geometry,
114 const RenderOption &option,
115 const ViewControl &view) final;
116 bool PrepareBinding(const geometry::Geometry &geometry,
117 const RenderOption &option,
118 const ViewControl &view,
119 std::vector<Eigen::Vector3f> &points,
120 std::vector<Eigen::Vector3f> &normals,
121 std::vector<Eigen::Vector2f> &uvs) final;
122};
123
124} // namespace glsl
125
126} // namespace visualization
127} // namespace open3d
The base geometry class.
Definition: Geometry.h:37
Defines rendering options for visualizer.
Definition: RenderOption.h:39
View controller for visualizer.
Definition: ViewControl.h:41
Definition: ShaderWrapper.h:40
TexturePhongShaderForTriangleMesh()
Definition: TexturePhongShader.h:109
Definition: TexturePhongShader.h:39
GLuint vertex_normal_
Definition: TexturePhongShader.h:76
void Release() final
Definition: TexturePhongShader.cpp:67
TexturePhongShader(const std::string &name)
Definition: TexturePhongShader.h:44
GLuint M_
Definition: TexturePhongShader.h:79
std::vector< GLuint > vertex_normal_buffers_
Definition: TexturePhongShader.h:95
std::vector< GLuint > diffuse_texture_buffers_
Definition: TexturePhongShader.h:96
GLuint MVP_
Definition: TexturePhongShader.h:77
bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: TexturePhongShader.cpp:117
GLuint V_
Definition: TexturePhongShader.h:78
GLuint vertex_position_
Definition: TexturePhongShader.h:74
GLuint light_diffuse_power_
Definition: TexturePhongShader.h:82
bool Compile() final
Definition: TexturePhongShader.cpp:40
gl_util::GLMatrix4f light_color_data_
Definition: TexturePhongShader.h:100
virtual bool PrepareRendering(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
gl_util::GLVector4f light_diffuse_power_data_
Definition: TexturePhongShader.h:101
GLuint light_position_world_
Definition: TexturePhongShader.h:80
gl_util::GLVector4f light_specular_power_data_
Definition: TexturePhongShader.h:102
GLuint light_specular_power_
Definition: TexturePhongShader.h:83
std::vector< GLsizei > draw_array_sizes_
Definition: TexturePhongShader.h:91
GLuint light_color_
Definition: TexturePhongShader.h:81
std::vector< int > array_offsets_
Definition: TexturePhongShader.h:90
GLuint light_specular_shininess_
Definition: TexturePhongShader.h:84
GLuint vertex_uv_
Definition: TexturePhongShader.h:75
void SetLighting(const ViewControl &view, const RenderOption &option)
Definition: TexturePhongShader.cpp:191
GLuint light_ambient_
Definition: TexturePhongShader.h:85
std::vector< GLuint > vertex_position_buffers_
Definition: TexturePhongShader.h:93
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:72
GLuint diffuse_texture_
Definition: TexturePhongShader.h:87
~TexturePhongShader() override
Definition: TexturePhongShader.h:41
gl_util::GLVector4f light_specular_shininess_data_
Definition: TexturePhongShader.h:103
gl_util::GLMatrix4f light_position_world_data_
Definition: TexturePhongShader.h:99
gl_util::GLVector4f light_ambient_data_
Definition: TexturePhongShader.h:104
std::vector< GLuint > vertex_uv_buffers_
Definition: TexturePhongShader.h:94
int num_materials_
Definition: TexturePhongShader.h:89
void UnbindGeometry() final
Definition: TexturePhongShader.cpp:165
std::string name
Definition: FilePCD.cpp:58
int points
Definition: FilePCD.cpp:73
Definition: NonRigidOptimizer.cpp:41
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:53
Eigen::Matrix< GLfloat, 4, 1, Eigen::ColMajor > GLVector4f
Definition: GLHelper.h:52
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Device.h:138