iMSTK
Interactive Medical Simulation Toolkit
imstkRenderMaterial.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkColor.h"
10 #include "imstkEventObject.h"
11 #include "imstkTexture.h"
12 
13 #include <vector>
14 
15 namespace imstk
16 {
17 class ColorFunction;
18 class Texture;
19 
27 {
28 public:
30  enum class DisplayMode
31  {
32  Surface,
33  Wireframe,
34  Points,
35  WireframeSurface,
36  VolumeRendering,
37  Fluid,
38  Image,
39  SurfaceNormals
40  };
41 
43  enum class ShadingModel
44  {
45  None,
46  Phong,
47  Gouraud,
48  Flat,
49  PBR
50  };
51 
53  enum class BlendMode
54  {
55  Alpha,
56  Additive,
57  MaximumIntensity,
58  MinimumIntensity
59  };
60 
62  virtual ~RenderMaterial() = default;
63 
64  // *INDENT-OFF*
68  SIGNAL(RenderMaterial, modified);
69 
73  SIGNAL(RenderMaterial, texturesModified);
74  // *INDENT-ON*
75 
79  const std::string& getName() const { return m_name; }
80  void setName(std::string name) { m_name = name; }
82 
86  DisplayMode getDisplayMode() const { return m_displayMode; }
87  void setDisplayMode(const DisplayMode displayMode);
89 
93  double getLineWidth() const { return m_lineWidth; }
94  void setLineWidth(const double width);
96 
100  double getPointSize() const { return m_pointSize; }
101  void setPointSize(const double size);
103 
107  bool getBackFaceCulling() const { return m_backfaceCulling; }
108  void setBackFaceCulling(const bool culling);
109  void backfaceCullingOn();
110  void backfaceCullingOff();
112 
117  const Color& getDiffuseColor() const { return m_diffuseColor; }
118  void setDiffuseColor(const Color& color);
119  const Color& getColor() const { return this->getDiffuseColor(); }
120  void setColor(const Color& color);
122 
126  const Color& getSpecularColor() const { return m_specularColor; }
127  void setSpecularColor(const Color& color);
129 
133  double getSpecular() const { return m_specular; }
134  void setSpecular(const double specular) { m_specular = specular; }
136 
140  const Color& getAmbientColor() const { return m_ambientColor; }
141  void setAmbientColor(const Color& color);
143 
147  double getMetalness() const { return m_metalness; }
148  void setMetalness(const double metalness);
150 
154  double getAmbient() const { return m_ambient; };
155  void setAmbient(const double ambient) { m_ambient = ambient; }
157 
161  double getDiffuse() const { return m_diffuse; }
162  void setDiffuse(const double diffuse) { m_diffuse = diffuse; }
164 
168  double getSpecularPower() const { return m_specularPower; }
169  void setSpecularPower(const double p) { m_specularPower = p; }
171 
175  double getRoughness() const { return m_roughness; }
176  void setRoughness(const double roughness);
178 
182  double getEmissivity() const { return m_emissivity; }
183  void setEmissivity(const double emissivity);
185 
186  double getAnisotropy() const { return m_anisotropy; }
187  void setAnisotropy(const double anisotropy);
188 
189  double getAnisotropyRotation() const { return m_anisotropyRotation; }
190  void setAnisotropyRotation(const double anisotropyRotation);
191 
192  double getBaseIOR() const { return m_baseIOR; }
193  void setBaseIOR(const double baseIOR);
194 
195  const Color& getCoatColor() const { return m_coatColor; }
196  void setCoatColor(const Color& coatColor);
197 
198  double getCoatIOR() const { return m_coatIOR; }
199  void setCoatIOR(const double coatIOR);
200 
201  double getCoatNormalScale() const { return m_coatNormalScale; }
202  void setCoatNormalScale(const double coatNormalScale);
203 
204  double getCoatRoughness() const { return m_coatRoughness; }
205  void setCoatRoughness(const double coatRoughness);
206 
207  double getCoatStrength() const { return m_coatStrength; }
208  void setCoatStrength(const double coatStrength);
209 
210  const Color& getEdgeTint() const { return m_edgeTint; }
211  void setEdgeTint(const Color& edgeTint);
212 
216  void addTexture(std::shared_ptr<Texture> texture);
217  void removeTexture(std::shared_ptr<Texture> texture);
218  void removeTexture(Texture::Type type);
219  std::shared_ptr<Texture> getTexture(Texture::Type type);
221 
225  void setEdgeVisibility(const bool visibility) { m_edgeVisibility = visibility; };
226  bool getEdgeVisibility() const { return m_edgeVisibility; };
228 
234  virtual void setBlendMode(const BlendMode blendMode);
235  BlendMode getBlendMode() const { return m_blendMode; }
237 
238  DisplayMode getRenderMode() const { return m_displayMode; }
239  ShadingModel getShadingModel() const { return m_shadingModel; }
240  void setShadingModel(const ShadingModel& model);
241 
242  double getOcclusionStrength() const { return m_occlusionStrength; }
243  void setOcclusionStrength(const double o);
244 
245  double getNormalStrength() const { return m_normalStrength; }
246  void setNormalStrength(const double n);
247 
248  const Color& getEdgeColor() const { return m_edgeColor; }
249  void setEdgeColor(const Color& color);
250 
251  const Color& getVertexColor() const { return m_vertexColor; }
252  void setVertexColor(const Color& color);
253 
254  double getOpacity() const { return m_opacity; }
255  void setOpacity(const double opacity);
256 
257  bool getBackfaceCulling() const { return m_backfaceCulling; }
258  void setBackfaceCulling(const bool c);
259 
260  std::shared_ptr<ColorFunction> getColorLookupTable() const { return m_lookupTable; }
261  void setColorLookupTable(std::shared_ptr<ColorFunction> lut);
262 
263  bool getScalarVisibility() const { return m_scalarVisibility; }
264  void setScalarVisibility(const bool scalarVisibility);
265 
266  bool getRecomputeVertexNormals() const { return m_recomputeVertexNormals; }
267  void setRecomputeVertexNormals(const bool recomputeVertexNormals) { m_recomputeVertexNormals = recomputeVertexNormals; }
268 
269  bool getRenderPointsAsSpheres() const { return m_renderPointsAsSpheres; }
270  void setRenderPointsAsSpheres(const bool renderPointsAsSpheres) { m_renderPointsAsSpheres = renderPointsAsSpheres; }
271 
272  bool getIsDynamicMesh() const { return m_isDynamicMesh; }
273  void setIsDynamicMesh(const bool isDynamicMesh) { m_isDynamicMesh = isDynamicMesh; }
274 
275  void postModified() { this->postEvent(Event(RenderMaterial::modified())); }
276 
277 protected:
278  std::string m_name = "";
279 
280  // Textures
281  std::vector<std::shared_ptr<Texture>> m_textures;
282 
284  BlendMode m_blendMode = BlendMode::Alpha;
285 
287  double m_diffuse = 1.0;
288  Color m_diffuseColor = Color::LightGray;
289 
290  double m_specularPower = 100.0;
291  double m_specular = 0.0;
292  Color m_specularColor = Color::Red;
293 
294  double m_ambient = 0.1;
295  Color m_ambientColor = Color::White;
296 
297  double m_opacity = 1.0;
298 
300  double m_lineWidth = 1.0;
301  double m_pointSize = 2.0;
302  Color m_edgeColor = Color::Marigold;
303  Color m_vertexColor = Color::Teal;
304  bool m_edgeVisibility = true;
305  bool m_vertexVisibility = true;
306 
308  double m_emissivity = 0.0;
309  Color m_emmisiveColor = Color::White;
310 
311  double m_metalness = 1.0;
312  double m_roughness = 1.0;
313  double m_occlusionStrength = 1.0;
314  double m_normalStrength = 1.0;
315 
317  double m_anisotropy = 0.0;
318  double m_anisotropyRotation = 0.0;
319  double m_baseIOR = 1.5; // Base index of refraction
320  Color m_coatColor = Color::White;
321  double m_coatIOR = 2.0; // Coat index of refraction
322  double m_coatNormalScale = 1.0;
323  double m_coatRoughness = 0.0;
324  double m_coatStrength = 0.0;
325  Color m_edgeTint = Color::White;
326 
327  bool m_backfaceCulling = true;
328  bool m_isDynamicMesh = true;
329 
330  DisplayMode m_displayMode = DisplayMode::Surface;
331  ShadingModel m_shadingModel = ShadingModel::Phong;
332 
334 
335  std::shared_ptr<ColorFunction> m_lookupTable;
336  bool m_scalarVisibility = false;
337 
338  bool m_renderPointsAsSpheres = false;
339 };
340 } // namespace imstk
double getSpecularPower() const
Get/Set ambient light coefficient.
bool m_isDynamicMesh
Dynamic mesh is one whose buffers are re-evaluated on update.
void addTexture(std::shared_ptr< Texture > texture)
Add/Remove/Get texture.
double getEmissivity() const
Get/Set emissivity.
double m_diffuse
----------------—Common properties------------------—
Phong shading model (default)
Base class for events which contain a type, priority, and data priority defaults to 0 and uses a grea...
Type
Texture type - determines filtering.
Definition: imstkTexture.h:30
SIGNAL(RenderMaterial, modified)
Posted when material parameters are modified.
double getRoughness() const
Get/Set the roughness.
Renders a set of points using a screen-space fluid renderer.
ShadingModel
surface shading model. Defaults to Phong
double m_emissivity
-------------—PBR specific properties----------------—
void setEdgeVisibility(const bool visibility)
Get/Set edge visibility.
DisplayMode
Display mode for the scene objects.
Compound Geometry.
bool m_recomputeVertexNormals
Update vertex normals when vertex or index data is changed.
BlendMode
Volume rendering blend mode.
const Color & getDiffuseColor() const
Get/Set the color. This affects the diffuse color directly, but it affects the specular color in the ...
const std::string & getName() const
Get/Set the material name.
double m_roughness
Value for roughness with range: [0.0, 1.0].
const Color & getAmbientColor() const
Get/Set the ambient color.
double getDiffuse() const
Get/Set diffuse light coefficient.
double getPointSize() const
Get/Set point radius.
DisplayMode getDisplayMode() const
Get/Set display mode.
BlendMode m_blendMode
-----------—Volume rendering properties-------------—
double getSpecular() const
Get/Set the specular amount.
double getMetalness() const
Get/Set the metalness.
virtual void setBlendMode(const BlendMode blendMode)
Get/Set blend mode This function only works for volumes, particles and decals currently and the MAXIM...
Color in RGB space.
Definition: imstkColor.h:24
EventObject is the base class for all objects in iMSTK that can receive and emit events. It supports direct and queued observer functions. Direct observers receive events immediately on the same thread This can either be posted on an object or be a function pointer Queued observers receive events within their queue which they can process whenever they like. These can be connected with the connect/queuedConnect/disconnect functions Lambda recievers cannot be disconnected unless all receivers to a signal are removed.
static Color White
Various commonly used colors.
Definition: imstkColor.h:112
const Color & getSpecularColor() const
Get/Set the specular color.
double m_anisotropy
-------------—PBR Clearcoat properties----------------—
bool getBackFaceCulling() const
Backface culling on/off.
Serves no function, just a database for render properties, emits events for others to observe its cha...
double getAmbient() const
Get/Set ambient light coefficient.
void postEvent(const T &e)
Emits the event Direct observers will be immediately called, in sync Queued observers will receive th...
double m_metalness
Value for metalness with range: [0.0, 1.0].
double getLineWidth() const
Get/Set line width or the wireframe.
bool m_backfaceCulling
For performance, uncommon for this to be false.
std::vector< std::shared_ptr< Texture > > m_textures
Ordered by Texture::Type.
double m_lineWidth
----------—Wireframe specific properties-------------—