Ocean
rendering/Material.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_RENDERING_MATERIAL_H
9 #define META_OCEAN_RENDERING_MATERIAL_H
10 
13 
14 #include "ocean/math/RGBAColor.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Rendering
20 {
21 
22 // Forward declaration
23 class Material;
24 
25 /**
26  * Definition of a smart object reference holding a material.
27  * @see SmartObjectRef, Material.
28  * @ingroup rendering
29  */
31 
32 /**
33  * This class is the base class for all materials.
34  * Each material is composed by different color components and appearance values:<br>
35  * \b Ambient color models light that is inherent in the global scene due to global illumination, (0.2, 0.2, 0.2) as default.<br>
36  * \b Diffuse color models light reflected on rough surfaces, (0.8, 0.8, 0.8) as default.<br>
37  * \b Emissive color enabled objects to seam self-luminous, (0.0, 0.0, 0.0) as default.<br>
38  * \b Specular color models light reflected on shiny surfaces, (0.0, 0.0, 0.0) as default.<br>
39  * \b Specular exponent models the sharpness of the reflection with range [0.0, infinity), 0.0 as default.<br>
40  * \b Transparency models transparent surfaces with range [0.0, 1.0], 0.0 (fully opaque) as default.<br>
41  *
42  * Use the material object to define the appearance of geometry nodes.<br>
43  * Each geometry node is associated with at most one material object.<br>
44  * The material object has to be inserted to an attribute set which itself is connected to the geometry node.<br>
45  * @see AttributeSet, Geometry, Attribute
46  * @ingroup rendering
47  */
48 class OCEAN_RENDERING_EXPORT Material : virtual public Attribute
49 {
50  public:
51 
52  /**
53  * Returns the ambient color of this material.
54  * @return Ambient color
55  * @exception NotSupportedException Is thrown if this function is not supported
56  * @see setAmbientColor().
57  */
58  virtual RGBAColor ambientColor() const;
59 
60  /**
61  * Returns the diffuse color of this material.
62  * @return Diffuse color
63  * @exception NotSupportedException Is thrown if this function is not supported
64  * @see setDiffuseColor().
65  */
66  virtual RGBAColor diffuseColor() const;
67 
68  /**
69  * Returns the emissive color of this material.
70  * @return Emissive color
71  * @exception NotSupportedException Is thrown if this function is not supported
72  * @see setEmissiveColor().
73  */
74  virtual RGBAColor emissiveColor() const;
75 
76  /**
77  * Returns the specular color of this material.
78  * @return Specular color
79  * @exception NotSupportedException Is thrown if this function is not supported
80  * @see setSpecularColor().
81  */
82  virtual RGBAColor specularColor() const;
83 
84  /**
85  * Returns the specular exponent of this material with range [0.0, infinity).
86  * The higher the specular exponent value the sharper the reflection area.
87  * @return Specular exponent
88  * @exception NotSupportedException Is thrown if this function is not supported
89  * @see setSpecularExponent().
90  */
91  virtual float specularExponent() const;
92 
93  /**
94  * Returns the transparency factor of this material with range [0.0, 1.0].
95  * 0.0 means fully opaque, 1.0 means fully transparent.
96  * @return Transparency factor
97  * @exception NotSupportedException Is thrown if this function is not supported
98  * @see setTransparency().
99  */
100  virtual float transparency() const;
101 
102  /**
103  * Returns the reflectivity factor of this material with range [0.0, 1.0].
104  * 0.0 means no reflection, 1.0 means total reflection.<br>
105  * Beware: This parameter it used for global illumination and therefore not supported by most engines.
106  * @return Reflection factor
107  * @exception NotSupportedExcecption Is thrown if this function is not supported
108  * @see setReflectivity().
109  */
110  virtual float reflectivity() const;
111 
112  /**
113  * Returns the index of refraction of this material with range [0.0, 1.0].
114  * The default value is 1 (as for standard for vacuum; water has 1.33, fused quartz glass has 1.46).
115  * Beware: This parameter it used for global illumination and therefore not supported by most engines.
116  * @return Index of refraction
117  * @exception NotSupportedExcecption Is thrown if this function is not supported
118  * @see setRefractionIndex().
119  */
120  virtual float refractionIndex() const;
121 
122  /**
123  * Gets all color values of the material at once.
124  * @param ambient Resulting ambient color of this material
125  * @param diffuse Resulting diffuse color of this material
126  * @param emissive Resulting emissive color of this material
127  * @param specular Resulting specular color of this material
128  * @param specularExponent Resulting specular exponent of this material with range [0.0, infinity)
129  * @param transparency Resulting transparency factor of this material with range [0.0, 1.0]
130  * @exception NotSupportedException Is thrown if this function is not supported
131  * @see set().
132  */
133  virtual void get(RGBAColor& ambient, RGBAColor& diffuse, RGBAColor& emissive, RGBAColor& specular, float& specularExponent, float& transparency);
134 
135  /**
136  * Sets the ambient color of the material.
137  * @param color Ambient color
138  * @return True, if the specified color is valid and could be set
139  * @exception NotSupportedException Is thrown if this function is not supported
140  * @see ambientColor().
141  */
142  virtual bool setAmbientColor(const RGBAColor& color);
143 
144  /**
145  * Sets the diffuse color of the material.
146  * @param color Diffuse color
147  * @return True, if the specified color is valid and could be set
148  * @exception NotSupportedException Is thrown if this function is not supported
149  * @see diffuseColor().
150  */
151  virtual bool setDiffuseColor(const RGBAColor& color);
152 
153  /**
154  * Sets the emissive color of the material.
155  * @param color Emissive color
156  * @return True, if the specified color is valid and could be set
157  * @exception NotSupportedException Is thrown if this function is not supported
158  * @see emissiveColor().
159  */
160  virtual bool setEmissiveColor(const RGBAColor& color);
161 
162  /**
163  * Sets the specular color of the material.
164  * @param color Specular color
165  * @return True, if the specified color is valid and could be set
166  * @exception NotSupportedException Is thrown if this function is not supported
167  * @see specularColor().
168  */
169  virtual bool setSpecularColor(const RGBAColor& color);
170 
171  /**
172  * Sets the specular exponent of this material with range [0.0, infinity).
173  * The higher the specular exponent value the sharper the reflection area.
174  * @param specularExponent Specular exponent
175  * @return True, if the specified exponent is valid and could be set
176  * @exception NotSupportedException Is thrown if this function is not supported
177  * @see specularExponent().
178  */
179  virtual bool setSpecularExponent(const float specularExponent);
180 
181  /**
182  * Sets the transparency of the material.
183  * 0.0 means fully opaque, 1.0 means fully transparent.
184  * @param transparency Transparency factor of the material with range [0.0, 1.0]
185  * @return True, if the specified value is valid and could be set
186  * @exception NotSupportedException Is thrown if this function is not supported
187  * @see transparency().
188  */
189  virtual bool setTransparency(const float transparency);
190 
191  /**
192  * Sets the reflectivity of this material.
193  * 0 means no reflection, 1 means total reflection.<br>
194  * Beware: This parameter it used for global illumination and therefore not supported by most engines.
195  * @param reflectivity Reflectivity factor of this material with range [0.0, 1.0]
196  * @return True, if the specified value is valid and could be set
197  * @exception NotSupportedException Is thrown if this function is not supported
198  * @see reflectivity().
199  */
200  virtual bool setReflectivity(const float reflectivity);
201 
202  /**
203  * Sets the index of refraction of this material.
204  * The default value is 1 (as for standard for vacuum; water has 1.33, fused quartz glass has 1.46).
205  * Beware: This parameter it used for global illumination and therefore not supported by most engines.
206  * @param index Refraction index to be set with range [0.0, infinity)
207  * @return True, if the specified value is valid and could be set
208  * @exception NotSupportedException Is thrown if this function is not supported
209  * @see refractionIndex().
210  */
211  virtual bool setRefractionIndex(const float index);
212 
213  /**
214  * Sets all color values of the material at once.
215  * @param ambient Ambient color to set
216  * @param diffuse Diffuse color to set
217  * @param emissive Emissive color to set
218  * @param specular Specular color to set
219  * @param specularExponent Specular exponent to set with range [0.0, infinity)
220  * @param transparency Transparency factor to set with range [0.0, 1.0]
221  * @return True, if at least one specified value was valid and could be set
222  * @exception NotSupportedException Is thrown if this function is not supported
223  * @see get().
224  */
225  virtual bool set(const RGBAColor& ambient, const RGBAColor& diffuse, const RGBAColor& emissive, const RGBAColor& specular, const float specularExponent, const float transparency);
226 
227  /**
228  * Returns the type of this object.
229  * @see Object::type().
230  */
231  ObjectType type() const override;
232 
233  protected:
234 
235  /**
236  * Creates a new material object.
237  */
239 
240  /**
241  * Destructs a meterial object.
242  */
243  ~Material() override;
244 };
245 
246 }
247 
248 }
249 
250 #endif // META_OCEAN_RENDERING_MATERIAL_H
This class implements a color defined by red, green, blue and alpha parameters.
Definition: RGBAColor.h:41
This class is the base class for all rendering attribute objects.
Definition: Attribute.h:39
This class is the base class for all materials.
Definition: rendering/Material.h:49
virtual RGBAColor ambientColor() const
Returns the ambient color of this material.
virtual bool setTransparency(const float transparency)
Sets the transparency of the material.
~Material() override
Destructs a meterial object.
virtual float refractionIndex() const
Returns the index of refraction of this material with range [0.0, 1.0].
virtual bool set(const RGBAColor &ambient, const RGBAColor &diffuse, const RGBAColor &emissive, const RGBAColor &specular, const float specularExponent, const float transparency)
Sets all color values of the material at once.
virtual bool setRefractionIndex(const float index)
Sets the index of refraction of this material.
virtual bool setEmissiveColor(const RGBAColor &color)
Sets the emissive color of the material.
virtual bool setSpecularColor(const RGBAColor &color)
Sets the specular color of the material.
ObjectType type() const override
Returns the type of this object.
virtual float specularExponent() const
Returns the specular exponent of this material with range [0.0, infinity).
virtual RGBAColor specularColor() const
Returns the specular color of this material.
Material()
Creates a new material object.
virtual float reflectivity() const
Returns the reflectivity factor of this material with range [0.0, 1.0].
virtual void get(RGBAColor &ambient, RGBAColor &diffuse, RGBAColor &emissive, RGBAColor &specular, float &specularExponent, float &transparency)
Gets all color values of the material at once.
virtual bool setSpecularExponent(const float specularExponent)
Sets the specular exponent of this material with range [0.0, infinity).
virtual bool setAmbientColor(const RGBAColor &color)
Sets the ambient color of the material.
virtual RGBAColor diffuseColor() const
Returns the diffuse color of this material.
virtual float transparency() const
Returns the transparency factor of this material with range [0.0, 1.0].
virtual RGBAColor emissiveColor() const
Returns the emissive color of this material.
virtual bool setDiffuseColor(const RGBAColor &color)
Sets the diffuse color of the material.
virtual bool setReflectivity(const float reflectivity)
Sets the reflectivity of this material.
ObjectType
Definition of different object type.
Definition: Object.h:63
SmartObjectRef< Material > MaterialRef
Definition of a smart object reference holding a material.
Definition: rendering/Material.h:23
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15