Gazebo Rendering

API Reference

6.6.4
gz/rendering/ogre2/Ogre2Material.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 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_OGRE2_OGRE2MATERIAL_HH_
18 #define GZ_RENDERING_OGRE2_OGRE2MATERIAL_HH_
19 
20 #include <memory>
21 #include <string>
22 
25 
26 #ifdef _MSC_VER
27  #pragma warning(push, 0)
28 #endif
29 #include <Hlms/Pbs/OgreHlmsPbsPrerequisites.h>
30 #include <OgreGpuProgramParams.h>
31 #include <OgreMaterial.h>
32 #ifdef _MSC_VER
33  #pragma warning(pop)
34 #endif
35 
36 namespace Ogre
37 {
38  class HlmsPbsDatablock;
39  class HlmsUnlitDatablock;
40 } // namespace Ogre
41 
42 namespace ignition
43 {
44  namespace rendering
45  {
46  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
47  //
48  // forward declaration
49  class Ogre2MaterialPrivate;
50 
52  class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2Material :
53  public BaseMaterial<Ogre2Object>
54  {
56  protected: Ogre2Material();
57 
59  public: virtual ~Ogre2Material();
60 
61  // Documentation inherited
62  public: virtual void Destroy() override;
63 
64  // Documentation inherited
65  public: virtual math::Color Diffuse() const override;
66 
67  // Documentation inherited
68  public: virtual void SetDiffuse(const math::Color &_color) override;
69 
70  // Documentation inherited
71  public: virtual math::Color Specular() const override;
72 
73  // Documentation inherited
74  public: virtual void SetSpecular(const math::Color &_color) override;
75 
76  // Documentation inherited
77  public: virtual math::Color Emissive() const override;
78 
79  // Documentation inherited
80  public: virtual void SetEmissive(const math::Color &_color) override;
81 
82  // Documentation inherited
83  public: virtual void SetTransparency(const double _transparency) override;
84 
85  // Documentation inherited
86  public: virtual void SetAlphaFromTexture(bool _enabled,
87  double _alpha = 0.5, bool _twoSided = true) override;
88 
89  // Documentation inherited
90  public: virtual float RenderOrder() const override;
91 
92  // Documentation inherited
93  // Review the official documentation to get more details about this
94  // parameter, in particular mDepthBiasConstant
95  public: virtual void SetRenderOrder(const float _renderOrder) override;
96 
97  // Documentation inherited
98  public: virtual bool ReceiveShadows() const override;
99 
100  // Documentation inherited
101  public: virtual void SetReceiveShadows(const bool _receiveShadows)
102  override;
103 
104  // Documentation inherited
105  public: virtual bool HasTexture() const override;
106 
107  // Documentation inherited
108  public: virtual std::string Texture() const override;
109 
110  // Documentation inherited
111  public: virtual void SetTexture(const std::string &_texture) override;
112 
113  // Documentation inherited
114  public: virtual void ClearTexture() override;
115 
116  // Documentation inherited
117  public: virtual bool HasNormalMap() const override;
118 
119  // Documentation inherited
120  public: virtual std::string NormalMap() const override;
121 
122  // Documentation inherited
123  public: virtual void SetNormalMap(const std::string &_normalMap) override;
124 
125  // Documentation inherited
126  public: virtual void ClearNormalMap() override;
127 
128  // Documentation inherited
129  public: virtual bool HasRoughnessMap() const override;
130 
131  // Documentation inherited
132  public: virtual std::string RoughnessMap() const override;
133 
134  // Documentation inherited
135  public: virtual void SetRoughnessMap(
136  const std::string &_roughnessMap) override;
137 
138  // Documentation inherited
139  public: virtual void ClearRoughnessMap() override;
140 
141  // Documentation inherited
142  public: virtual bool HasMetalnessMap() const override;
143 
144  // Documentation inherited
145  public: virtual std::string MetalnessMap() const override;
146 
147  // Documentation inherited
148  public: virtual void SetMetalnessMap(
149  const std::string &_metalnessMap) override;
150 
151  // Documentation inherited
152  public: virtual void ClearMetalnessMap() override;
153 
154  // Documentation inherited
155  public: virtual bool HasEnvironmentMap() const override;
156 
157  // Documentation inherited
158  public: virtual std::string EnvironmentMap() const override;
159 
160  // Documentation inherited
161  public: virtual void SetEnvironmentMap(
162  const std::string &_metalnessMap) override;
163 
164  // Documentation inherited
165  public: virtual void ClearEnvironmentMap() override;
166 
167  // Documentation inherited
168  public: virtual void SetRoughness(const float _roughness) override;
169 
170  // Documentation inherited
171  public: virtual bool HasEmissiveMap() const override;
172 
173  // Documentation inherited
174  public: virtual std::string EmissiveMap() const override;
175 
176  // Documentation inherited
177  public: virtual void SetEmissiveMap(
178  const std::string &_emissiveMap) override;
179 
180  // Documentation inherited
181  public: virtual void ClearEmissiveMap() override;
182 
183  // Documentation inherited
184  public: virtual bool HasLightMap() const override;
185 
186  // Documentation inherited
187  public: virtual std::string LightMap() const override;
188 
189  // Documentation inherited
190  public: virtual unsigned int LightMapTexCoordSet() const override;
191 
192  // Documentation inherited
193  public: virtual void SetLightMap(const std::string &_lightMap,
194  unsigned int _uvSet = 0u) override;
195 
196  // Documentation inherited
197  public: virtual void ClearLightMap() override;
198 
199  // Documentation inherited
200  public: virtual float Roughness() const override;
201 
202  // Documentation inherited
203  public: virtual void SetMetalness(const float _roughness) override;
204 
205  // Documentation inherited
206  public: virtual float Metalness() const override;
207 
210  public: virtual Ogre::MaterialPtr Material();
211 
214  public: virtual Ogre::HlmsPbsDatablock *Datablock() const;
215 
218  public: virtual Ogre::HlmsUnlitDatablock *UnlitDatablock();
219 
223  public: virtual void FillUnlitDatablock(
224  Ogre::HlmsUnlitDatablock *_datablock) const;
225 
226  // Documentation inherited.
227  // \sa BaseMaterial::PreRender()
228  public: virtual void PreRender() override;
229 
230  // Documentation inherited.
231  public: virtual enum MaterialType Type() const override;
232 
233  // Documentation inherited
234  public: virtual bool DepthCheckEnabled() const override;
235 
236  // Documentation inherited
237  public: virtual void SetDepthCheckEnabled(bool _enabled) override;
238 
239  // Documentation inherited
240  public: virtual bool DepthWriteEnabled() const override;
241 
242  // Documentation inherited
243  public: virtual void SetDepthWriteEnabled(bool _enabled) override;
244 
245  // Documentation inherited.
246  // \sa Material::SetVertexShader(const std::string &)
247  public: virtual void SetVertexShader(const std::string &_path) override;
248 
249  // Documentation inherited.
250  // \sa Material::VertexShader() const
251  public: virtual std::string VertexShader() const override;
252 
253  // Documentation inherited.
254  // \sa Material::VertexShaderParams()
255  public: virtual ShaderParamsPtr VertexShaderParams() override;
256 
257  // Documentation inherited.
258  // \sa Material::SetFragmentShader(const std::string &)
259  public: virtual void SetFragmentShader(const std::string &_path)
260  override;
261 
262  // Documentation inherited.
263  // \sa Material::FragmentShader() const
264  public: virtual std::string FragmentShader() const override;
265 
266  // Documentation inherited.
267  // \sa Material::FragmentShaderParams()
268  public: virtual ShaderParamsPtr FragmentShaderParams() override;
269 
274  protected: virtual void SetTextureMapImpl(const std::string &_texture,
275  Ogre::PbsTextureTypes _type);
276 
279  protected: virtual Ogre::TextureGpu *Texture(const std::string &_name);
280 
283  protected: virtual void UpdateTransparency();
284 
285  // Documentation inherited.
286  protected: virtual void Init() override;
287 
289  protected: void UpdateShaderParams();
290 
294  protected: void UpdateShaderParams(ConstShaderParamsPtr _params,
295  Ogre::GpuProgramParametersSharedPtr _ogreParams);
296 
298  protected: Ogre::MaterialPtr ogreMaterial;
299 
301  protected: Ogre::HlmsPbsDatablock *ogreDatablock = nullptr;
302 
304  protected: Ogre::HlmsUnlitDatablock *ogreUnlitDatablock = nullptr;
305 
307  protected: Ogre::HlmsPbs *ogreHlmsPbs = nullptr;
308 
311 
314 
317 
320 
323 
326 
329 
331  protected: unsigned int lightMapUvSet = 0u;
332 
335 
337  private: std::unique_ptr<Ogre2MaterialPrivate> dataPtr;
338 
340  private: friend class Ogre2Scene;
341  };
342  }
343  }
344 }
345 #endif
Definition: gz/rendering/base/BaseMaterial.hh:41
Ogre 2.x implementation of the material class.
Definition: gz/rendering/ogre2/Ogre2Material.hh:54
virtual void SetMetalness(const float _roughness) override
Set the metalness value. Only affects material of type MT_PBS.
virtual void SetMetalnessMap(const std::string &_metalnessMap) override
Set the material metalness map.
virtual std::string EmissiveMap() const override
Get the URI of the emissive map file.
virtual unsigned int LightMapTexCoordSet() const override
Get the texture coordinate set used by lightmap.
std::string normalMapName
Name of the normal map.
Definition: gz/rendering/ogre2/Ogre2Material.hh:313
virtual ShaderParamsPtr VertexShaderParams() override
Get params for the vertex shader.
virtual float Metalness() const override
Get the metalness value of this material.
virtual bool HasLightMap() const override
Determine if this material has a light map.
virtual float Roughness() const override
Get the roughness value of this material.
void UpdateShaderParams(ConstShaderParamsPtr _params, Ogre::GpuProgramParametersSharedPtr _ogreParams)
Transfer params from ign-rendering type to ogre type.
std::string emissiveMapName
Name of the emissive map.
Definition: gz/rendering/ogre2/Ogre2Material.hh:325
virtual Ogre::TextureGpu * Texture(const std::string &_name)
Get a pointer to the ogre texture by name.
Ogre::MaterialPtr ogreMaterial
Ogre material. Mainly used for render targets.
Definition: gz/rendering/ogre2/Ogre2Material.hh:298
virtual void SetRenderOrder(const float _renderOrder) override
Set the render order. When polygons are coplanar, you can get problems with 'depth fighting' where th...
std::string ogreDatablockId
Unique id assigned to ogre hlms datablock.
Definition: gz/rendering/ogre2/Ogre2Material.hh:334
void UpdateShaderParams()
bind shader parameters that have changed
virtual std::string NormalMap() const override
Get the URI of the normal map file.
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 SetLightMap(const std::string &_lightMap, unsigned int _uvSet=0u) override
Set the material light map.
virtual bool HasRoughnessMap() const override
Determine if this material has a roughness map.
virtual bool ReceiveShadows() const override
Determine if this material receives shadows.
virtual void UpdateTransparency()
Updates the material transparency in the engine, based on transparency and diffuse alpha values.
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
std::string roughnessMapName
Name of the roughness map.
Definition: gz/rendering/ogre2/Ogre2Material.hh:316
virtual math::Color Specular() const override
Get the specular color.
virtual void SetEnvironmentMap(const std::string &_metalnessMap) override
Set the material environment map.
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.
std::string lightMapName
Name of the light map.
Definition: gz/rendering/ogre2/Ogre2Material.hh:328
virtual void SetVertexShader(const std::string &_path) override
Set the vertex shader.
virtual bool HasEnvironmentMap() const override
Determine if this material has a environment map.
virtual void SetSpecular(const math::Color &_color) override
Set the specular color.
virtual std::string RoughnessMap() const override
Get the URI of the roughness map file.
virtual void ClearEmissiveMap() override
Removes any emissive map mapped to this material.
virtual void SetEmissive(const math::Color &_color) override
Set the emissive color.
std::string textureName
Name of the texture.
Definition: gz/rendering/ogre2/Ogre2Material.hh:310
virtual bool DepthCheckEnabled() const override
Determine if depth buffer checking is enabled.
virtual std::string LightMap() const override
Get the URI of the light map file.
std::string environmentMapName
Name of the environment map.
Definition: gz/rendering/ogre2/Ogre2Material.hh:322
virtual math::Color Emissive() const override
Get the emissive color.
virtual void ClearMetalnessMap() override
Removes any metalness map mapped to this material.
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 SetTextureMapImpl(const std::string &_texture, Ogre::PbsTextureTypes _type)
Set the texture map for this material.
virtual std::string EnvironmentMap() const override
Get the URI of the environment map file.
virtual void SetNormalMap(const std::string &_normalMap) override
Set the material normal map.
virtual void Destroy() override
virtual ~Ogre2Material()
Destructor.
virtual void SetRoughness(const float _roughness) override
Set the roughness value. Only affects material of type MT_PBS.
virtual Ogre::MaterialPtr Material()
Return ogre low level material.
std::string metalnessMapName
Name of the metalness map.
Definition: gz/rendering/ogre2/Ogre2Material.hh:319
virtual Ogre::HlmsPbsDatablock * Datablock() const
Return ogre Hlms material pbs datablock.
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 void FillUnlitDatablock(Ogre::HlmsUnlitDatablock *_datablock) const
Fill the input unlit datablock with current material properties from the pbs datablock.
virtual Ogre::HlmsUnlitDatablock * UnlitDatablock()
Return ogre Hlms material unlit datablock.
virtual float RenderOrder() const override
Get the render order value of this material.
virtual void ClearRoughnessMap() override
Removes any roughness map mapped to this material.
virtual std::string MetalnessMap() const override
Get the URI of the metalness map file.
virtual bool HasMetalnessMap() const override
Determine if this material has a metalness map.
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 SetRoughnessMap(const std::string &_roughnessMap) override
Set the material roughness map.
virtual void Init() override
virtual bool DepthWriteEnabled() const override
Determine if depth buffer writing is enabled.
virtual void ClearEnvironmentMap() override
Removes any environment map mapped to this material.
virtual void ClearLightMap() override
Removes any light map mapped to 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 SetEmissiveMap(const std::string &_emissiveMap) override
Set the material emissive map.
virtual bool HasEmissiveMap() const override
Determine if this material has an emissive map.
Ogre2.x implementation of the scene class.
Definition: gz/rendering/ogre2/Ogre2Scene.hh:59
Definition: gz/rendering/ogre/OgreCamera.hh:28
MaterialType
An enum for the type of material.
Definition: gz/rendering/Material.hh:37