Gazebo Rendering

API Reference

6.6.4
gz/rendering/ogre/OgreMaterial.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef GZ_RENDERING_OGRE_OGREMATERIAL_HH_
18 #define GZ_RENDERING_OGRE_OGREMATERIAL_HH_
19 
20 #include <string>
21 
22 #include <gz/common/SuppressWarning.hh>
23 
27 
28 namespace ignition
29 {
30  namespace rendering
31  {
32  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
33  // TODO(anyone): use a better way to find shader configurations
35  "depth_vertex_shader.glsl";
37  "depth_fragment_shader.glsl";
38 
39  class IGNITION_RENDERING_OGRE_VISIBLE OgreMaterial :
40  public BaseMaterial<OgreObject>
41  {
42  protected: OgreMaterial();
43 
44  public: virtual ~OgreMaterial();
45 
46  // Documentation inherited
47  public: virtual void Destroy() override;
48 
49  public: virtual bool LightingEnabled() const override;
50 
51  public: virtual void SetLightingEnabled(const bool _enabled) override;
52 
53  // Documentation inherited
54  public: virtual bool DepthCheckEnabled() const override;
55 
56  // Documentation inherited
57  public: virtual void SetDepthCheckEnabled(bool _enabled) override;
58 
59  // Documentation inherited
60  public: virtual bool DepthWriteEnabled() const override;
61 
62  // Documentation inherited
63  public: virtual void SetDepthWriteEnabled(bool _enabled) override;
64 
65  public: virtual math::Color Ambient() const override;
66 
67  public: virtual void SetAmbient(const math::Color &_color) override;
68 
69  public: virtual math::Color Diffuse() const override;
70 
71  public: virtual void SetDiffuse(const math::Color &_color) override;
72 
73  public: virtual math::Color Specular() const override;
74 
75  public: virtual void SetSpecular(const math::Color &_color) override;
76 
77  public: virtual math::Color Emissive() const override;
78 
79  public: virtual void SetEmissive(const math::Color &_color) override;
80 
81  public: virtual double Shininess() const override;
82 
83  public: virtual void SetShininess(const double _shininess) override;
84 
85  public: virtual double Transparency() const override;
86 
87  public: virtual void SetTransparency(const double _transparency)
88  override;
89 
90  // Documentation inherited
91  public: virtual void SetAlphaFromTexture(bool _enabled,
92  double _alpha = 0.5, bool _twoSided = true) override;
93 
94  public: virtual double Reflectivity() const override;
95 
96  public: virtual void SetReflectivity(const double _reflectivity)
97  override;
98 
99  public: virtual bool CastShadows() const override;
100 
101  // Documentation inherited.
102  public: virtual void SetCastShadows(const bool _castShadows) override;
103 
104  public: virtual bool ReceiveShadows() const override;
105 
106  public: virtual void SetReceiveShadows(const bool _receiveShadows)
107  override;
108 
109  // Documentation inherited
110  public: virtual float RenderOrder() const override;
111 
112  // Documentation inherited
113  // Review the official documentation to get more details about this
114  // parameter, in particular Ogre::Pass::setDepthBias()
115  // https://www.ogre3d.org/docs/api/1.8/class_ogre_1_1_pass.html
116  public: virtual void SetRenderOrder(const float _renderOrder) override;
117 
118  public: virtual bool ReflectionEnabled() const override;
119 
120  public: virtual void SetReflectionEnabled(const bool _enabled) override;
121 
122  public: virtual bool HasTexture() const override;
123 
124  public: virtual std::string Texture() const override;
125 
126  // Documentation inherited.
127  public: virtual void SetTexture(const std::string &_texture) override;
128 
129  public: virtual void ClearTexture() override;
130 
131  public: virtual bool HasNormalMap() const override;
132 
133  public: virtual std::string NormalMap() const override;
134 
135  // Documentation inherited.
136  public: virtual void SetNormalMap(const std::string &_normalMap) override;
137 
138  public: virtual void ClearNormalMap() override;
139 
140  public: virtual enum ShaderType ShaderType() const override;
141 
142  // Documentation inherited.
143  public: virtual void SetShaderType(enum ShaderType _type) override;
144 
145  public: virtual Ogre::MaterialPtr Material() const;
146 
147  // Documentation inherited.
148  // \sa Material::Set3DMaterial()
149  public: virtual void SetDepthMaterial(const double far,
150  const double near) override;
151 
152  // Documentation inherited.
153  // \sa Material::SetVertexShader(const std::string &)
154  public: virtual void SetVertexShader(const std::string &_path) override;
155 
156  // Documentation inherited.
157  // \sa Material::VertexShader() const
158  public: virtual std::string VertexShader() const override;
159 
160  // Documentation inherited.
161  // \sa Material::VertexShaderParams()
162  public: virtual ShaderParamsPtr VertexShaderParams() override;
163 
164  // Documentation inherited.
165  // \sa Material::SetFragmentShader(const std::string &)
166  public: virtual void SetFragmentShader(const std::string &_path)
167  override;
168 
169  // Documentation inherited.
170  // \sa Material::FragmentShader() const
171  public: virtual std::string FragmentShader() const override;
172 
173  // Documentation inherited.
174  // \sa Material::FragmentShaderParams()
175  public: virtual ShaderParamsPtr FragmentShaderParams() override;
176 
177  // Documentation inherited.
178  // \sa BaseMaterial::PreRender()
179  public: virtual void PreRender() override;
180 
181  protected: virtual void LoadOneImage(const std::string &_name,
182  Ogre::Image &_image);
183 
186  protected: virtual void SetTextureImpl(const std::string &_texture);
187 
188  protected: virtual Ogre::TexturePtr Texture(const std::string &_name);
189 
190  protected: virtual Ogre::TexturePtr CreateTexture(
191  const std::string &_name);
192 
193  protected: virtual void UpdateTransparency();
194 
195  protected: virtual void UpdateColorOperation();
196 
198  protected: void UpdateShaderParams();
199 
203  protected: void UpdateShaderParams(ConstShaderParamsPtr _params,
204  Ogre::GpuProgramParametersSharedPtr _ogreParams);
205 
206  protected: virtual void Init() override;
207 
209  protected: Ogre::MaterialPtr ogreMaterial;
210 
211  protected: Ogre::Technique *ogreTechnique = nullptr;
212 
213  protected: Ogre::Pass *ogrePass = nullptr;
214 
215  protected: Ogre::TextureUnitState *ogreTexState = nullptr;
216 
217  protected: Ogre::String ogreGroup;
218 
219 #if OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR <= 7
220  protected: math::Color emissiveColor;
221 #endif
223 
225 
226  protected: enum ShaderType shaderType = ST_PIXEL;
227 
230 
233 
236 
240 
241  private: friend class OgreScene;
242  };
243  }
244  }
245 }
246 #endif
Definition: gz/rendering/base/BaseMaterial.hh:41
Definition: gz/rendering/ogre/OgreMaterial.hh:41
std::string vertexShaderPath
Path to vertex shader program.
Definition: gz/rendering/ogre/OgreMaterial.hh:229
std::string normalMapName
Definition: gz/rendering/ogre/OgreMaterial.hh:224
virtual ShaderParamsPtr VertexShaderParams() override
Get params for the vertex shader.
virtual bool CastShadows() const override
Determine if this material casts shadows.
virtual double Transparency() const override
Get the transparency value.
virtual void SetDepthMaterial(const double far, const double near) override
Configuration for Depth Material.
void UpdateShaderParams(ConstShaderParamsPtr _params, Ogre::GpuProgramParametersSharedPtr _ogreParams)
Transfer params from ign-rendering type to ogre type.
Ogre::MaterialPtr ogreMaterial
Definition: gz/rendering/ogre/OgreMaterial.hh:209
virtual void SetReflectivity(const double _reflectivity) override
Set the reflectivity value.
virtual void SetRenderOrder(const float _renderOrder) override
Set the render order. When polygons are coplanar, you can get problems with 'depth fighting' where th...
ShaderParamsPtr vertexShaderParams
Parameters to be bound to the vertex shader.
Definition: gz/rendering/ogre/OgreMaterial.hh:235
void UpdateShaderParams()
bind shader parameters that have changed
virtual std::string NormalMap() const override
Get the URI of the normal map file.
virtual void SetAmbient(const math::Color &_color) override
Set the ambient color.
ShaderParamsPtr fragmentShaderParams
Parameters to be bound to the fragment shader.
Definition: gz/rendering/ogre/OgreMaterial.hh:238
virtual void SetDepthWriteEnabled(bool _enabled) override
Specify if depth buffer writing is enabled.
virtual void ClearNormalMap() override
Removes any normal map mapped to this material.
virtual void SetCastShadows(const bool _castShadows) override
Specify if this material casts shadows.
virtual void SetShininess(const double _shininess) override
Set the shininess value.
virtual bool ReceiveShadows() const override
Determine if this material receives shadows.
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
virtual math::Color Specular() const override
Get the specular color.
virtual void SetDepthCheckEnabled(bool _enabled) override
Specify if depth buffer checking is enabled.
virtual void SetFragmentShader(const std::string &_path) override
Set the fragment shader.
virtual void SetVertexShader(const std::string &_path) override
Set the vertex shader.
virtual void SetSpecular(const math::Color &_color) override
Set the specular color.
virtual void SetEmissive(const math::Color &_color) override
Set the emissive color.
virtual bool ReflectionEnabled() const override
Determine if this material has a reflection.
std::string textureName
Definition: gz/rendering/ogre/OgreMaterial.hh:222
virtual bool DepthCheckEnabled() const override
Determine if depth buffer checking is enabled.
std::string fragmentShaderPath
Path to fragment shader program.
Definition: gz/rendering/ogre/OgreMaterial.hh:232
virtual math::Color Emissive() const override
Get the emissive color.
virtual void ClearTexture() override
Removes any texture mapped to this material.
virtual bool HasTexture() const override
Determine if this material has a texture.
virtual void SetTransparency(const double _transparency) override
Set the transparency value.
virtual void SetNormalMap(const std::string &_normalMap) override
Set the material normal map.
Ogre::String ogreGroup
Definition: gz/rendering/ogre/OgreMaterial.hh:217
virtual void Destroy() override
virtual bool LightingEnabled() const override
Determine if lighting affects this material.
virtual double Reflectivity() const override
Get the reflectivity value.
virtual double Shininess() const override
Get the shininess value.
virtual Ogre::TexturePtr Texture(const std::string &_name)
virtual math::Color Ambient() const override
Get the ambient color.
virtual void LoadOneImage(const std::string &_name, Ogre::Image &_image)
virtual Ogre::TexturePtr CreateTexture(const std::string &_name)
virtual void SetAlphaFromTexture(bool _enabled, double _alpha=0.5, bool _twoSided=true) override
Set the material to use the alpha channel from the textures.
virtual Ogre::MaterialPtr Material() const
virtual float RenderOrder() const override
Get the render order value of this material.
virtual std::string Texture() const override
Get the URI of the texture file.
virtual math::Color Diffuse() const override
Get the diffuse color.
virtual bool HasNormalMap() const override
Determine if this material has a normal map.
virtual void SetReceiveShadows(const bool _receiveShadows) override
Specify if this material receives shadows.
virtual void SetTexture(const std::string &_texture) override
Set the material texture.
virtual std::string VertexShader() const override
Get path to the vertex shader.
virtual void Init() override
virtual bool DepthWriteEnabled() const override
Determine if depth buffer writing is enabled.
virtual void SetLightingEnabled(const bool _enabled) override
Specify if lighting affects this material.
virtual void SetDiffuse(const math::Color &_color) override
Set the diffuse color.
virtual std::string FragmentShader() const override
Get path to the fragment shader.
virtual ShaderParamsPtr FragmentShaderParams() override
Get params for the fragment shader.
virtual void SetShaderType(enum ShaderType _type) override
Set the ShaderType value.
virtual void SetReflectionEnabled(const bool _enabled) override
Specify if this material has a reflection.
virtual void SetTextureImpl(const std::string &_texture)
Set the texture for this material.
Definition: gz/rendering/ogre/OgreScene.hh:41
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
const std::string depth_vertex_shader_file
Definition: gz/rendering/ogre/OgreMaterial.hh:34
ShaderType
Available types of shaders. Note that not all rendering-engines will be able to use each type....
Definition: gz/rendering/ShaderType.hh:35
@ ST_PIXEL
Per pixel lighting shader.
Definition: gz/rendering/ShaderType.hh:40
const std::string depth_fragment_shader_file
Definition: gz/rendering/ogre/OgreMaterial.hh:36