GL Studio C++ Runtime API
effect_diff_norm_spec_refl.h
Go to the documentation of this file.
1 /*! \file
2  \brief Render effect that supports diffuse, normal, specular, and reflection maps
3 
4  \par Copyright Information
5 
6  Copyright (c) 2017 by The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America. Use, distribution,
38 duplication, or disclosure by the U. S. Government is subject to
39 "Restricted Rights" as set forth in DFARS 252.227-7014(c)(1)(ii).
40 
41 */
42 
43 #ifndef _EFFECT_DIFF_NORM_SPEC_REF_H_INCLUDED
44 #define _EFFECT_DIFF_NORM_SPEC_REF_H_INCLUDED
45 
46 #include "gls_render_effect.h"
47 
48 #ifdef _MSC_VER
49  // Disable warning in gls_matrix_affine.h (DR 2156)
50 # pragma warning( push )
51 # pragma warning( disable : 4244 )
52 #endif
53 #include "gls_matrix_affine.h"
54 #ifdef _MSC_VER
55 # pragma warning( pop )
56 #endif
57 
58 #ifdef GLES
59 # include "gls_state_manager.h"
60 #endif
61 
62 //////////////////// Provides support for creating DLLs ////////////////////////
63 #if( defined( GLSGEN_EXPORT_GLSADVANCEDMESH ) || defined( GLSGEN_IMPORT_GLSADVANCEDMESH ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
64  && defined( _MSC_VER )
65 # if defined( GLSGEN_EXPORT_GLSADVANCEDMESH ) || defined( GLS_EXPORT_GENERATED )
66 # define GLSGEN_GlsAdvancedMesh_EXPORT __declspec( dllexport )
67 # else
68 # define GLSGEN_GlsAdvancedMesh_EXPORT __declspec( dllimport )
69 # endif
70 #else
71 # define GLSGEN_GlsAdvancedMesh_EXPORT
72 #endif
73 ///////////////////////////////////////////////////////////////////////////////
74 
75 namespace disti
76 {
77 #ifndef GLES
78 class MaxLike_Shader;
79 #endif
80 
81 /** Render effect that supports diffuse, normal, specular, and reflection maps. */
83 {
84 public:
85  static const std::string EFFECT_TYPE_NAME;
86 
88  {
89  bool _isIdentity;
90 
91  float _uOffset;
92  float _vOffset;
93  float _uTiling;
94  float _vTiling;
95  float _angle;
96 
97  GlsMatrixAffineF _matrix;
98 
99  public:
101 
102  bool operator==( const TextureUVWMatrix& rhs ) const;
103 
104  // Transform parameters
105  void UOffset( float val ) { _uOffset = val; }
106  float UOffset() const { return _uOffset; }
107  void VOffset( float val ) { _vOffset = val; }
108  float VOffset() const { return _vOffset; }
109  void UTiling( float val ) { _uTiling = val; }
110  float UTiling() const { return _uTiling; }
111  void VTiling( float val ) { _vTiling = val; }
112  float VTiling() const { return _vTiling; }
113  void Angle( float val ) { _angle = val; }
114  float Angle() const { return _angle; }
115 
116  // Should be called after changing the parameters
117  void RecalcTransformMatrix();
118 
119  // returns true if the matrix is identity
120  inline bool IsIdentity() { return _isIdentity; }
121 
122  // matrix must be an array of [16]
123  inline float* GetTransformMatrix() { return _matrix.Data(); }
124  };
125 
126 protected:
127  unsigned int _ref_count; ///< Reference count
128 
129 #ifdef GLES20
130  GlsEffect* _shader; /**< The current active effect in the system. If NULL, then no effect is active.
131  * Effects are retrieved from the GlsEffectFactory class. */
132  bool _userHasCustomShader; /** whether or not the user already had a custom shader set up */
133 #elif !defined( GLES )
134  MaxLike_Shader* _shader; ///< shader program to use (if any)
135 #endif
136 
137  unsigned int _materialIndex; ///< The material index to use
138  int _diffuseTextureIndex; ///< INVALID_INDEX, or the texture index to use
139  int _normalTextureIndex; ///< INVALID_INDEX, or the texture index to use
140  int _specularTextureIndex; ///< INVALID_INDEX, or the texture index to use
141  int _reflectionTextureIndex; ///< INVALID_INDEX, or the texture index to use
142 
143  float _diffuseAmount; ///< [0.0,1.0] "Weight" of the diffuse map
144  float _normalAmount; ///< [0.0,1.0] "Weight" of the normal map
145  float _specularAmount; ///< [0.0,1.0] "Weight" of the specular map
146  float _reflectionAmount; ///< [0.0,1.0] "Weight" of the reflection map
147 
148  bool _useVertexColors; ///< true: use vertex color for diffuse rather than material diffuse
149 
150  /// true: expect 'DirectX' format normal maps (positive Green points down)
151  /// false: expect 'OpenGL' format normal maps (positive Green points up)
152  /// Note: the sense is backwards from the Max 'Normal Bump' 'Flip Green' option because
153  /// Max defaults to 'DirectX' format and GL Studio defaults to 'OpenGL' format
155 
156  DistiAttribDict* _attribDict;
157 
158  TextureUVWMatrix _diffuseUVWMatrix;
159  TextureUVWMatrix _normalUVWMatrix;
160  TextureUVWMatrix _specularUVWMatrix;
161 
162  void SetupAttribDict();
163 
164 public:
165 #ifdef GLES20
166  static const GLenum NORMAL_MAP_TEXTURE_UNIT = GL_TEXTURE1; ///< the texture unit that the normal map should be bound to, \see glActiveTexture
167  static const GLenum SPECULAR_MAP_TEXTURE_UNIT = GL_TEXTURE2; ///< the texture unit that the specular map should be bound to, \see glActiveTexture
168  static const GLenum REFLECTION_MAP_TEXTURE_UNIT = GL_TEXTURE3; ///< the texture unit that the reflection map should be bound to, \see glActiveTexture
169 
170  /** Get the index for the sampler uniform for the given texture unit
171  * \param textureUnit the texture unit (e.g. GL_TEXTURE1)
172  * \return the index for the sampler uniform
173  */
174  static inline unsigned int TextureUnitIndex( GLenum textureUnit ) { return textureUnit - GL_TEXTURE0; }
175 #endif // GLES20
176  static const int INVALID_INDEX = -1;
177 
178  GLSGEN_GlsAdvancedMesh_EXPORT Effect_DiffNormSpecRefl();
179  GLSGEN_GlsAdvancedMesh_EXPORT ~Effect_DiffNormSpecRefl();
180 
181  /** Assignment operator */
182  GLSGEN_GlsAdvancedMesh_EXPORT Effect_DiffNormSpecRefl( const Effect_DiffNormSpecRefl& );
183  GLSGEN_GlsAdvancedMesh_EXPORT const Effect_DiffNormSpecRefl& operator=( const Effect_DiffNormSpecRefl& );
184 
185  GLSGEN_GlsAdvancedMesh_EXPORT bool operator==( const Effect_DiffNormSpecRefl& ) const;
186  inline bool operator!=( const Effect_DiffNormSpecRefl& o ) const { return !( *this == o ); }
187 
188  inline void SetMaterialIndex( unsigned int materialIndex ) { _materialIndex = materialIndex; }
189  inline unsigned int GetMaterialIndex() const { return _materialIndex; }
190 
191  inline void SetUseVertexColor( bool value )
192  {
193  _useVertexColors = value;
194 #ifndef GLES
195  SelectShader();
196 #endif
197  }
198  inline bool GetUseVertexColor() const { return _useVertexColors; }
199 
200  inline void SetDiffuseTextureIndex( int textureIndex )
201  {
202  _diffuseTextureIndex = textureIndex;
203 #ifndef GLES
204  SelectShader();
205 #endif
206  }
207  inline int GetDiffuseTextureIndex() const { return _diffuseTextureIndex; }
208 
209  inline void SetNormalTextureIndex( int textureIndex )
210  {
211  _normalTextureIndex = textureIndex;
212 #ifndef GLES
213  SelectShader();
214 #endif
215  }
216  inline int GetNormalTextureIndex() const { return _normalTextureIndex; }
217 
218  inline void SetSpecularTextureIndex( int textureIndex )
219  {
220  _specularTextureIndex = textureIndex;
221 #ifndef GLES
222  SelectShader();
223 #endif
224  }
225  inline int GetSpecularTextureIndex() const { return _specularTextureIndex; }
226 
227  inline void SetReflectionTextureIndex( int textureIndex )
228  {
229  _reflectionTextureIndex = textureIndex;
230 #ifndef GLES
231  SelectShader();
232 #endif
233  }
234  inline int GetReflectionTextureIndex() const { return _reflectionTextureIndex; }
235 
236  inline void SetDiffuseAmount( float value )
237  {
238  _diffuseAmount = value;
239 #ifndef GLES
240  SelectShader();
241 #endif
242  }
243  inline float GetDiffuseAmount() const { return _diffuseAmount; }
244 
245  inline void SetNormalAmount( float value )
246  {
247  _normalAmount = value;
248 #ifndef GLES
249  SelectShader();
250 #endif
251  }
252  inline float GetNormalAmount() const { return _normalAmount; }
253 
254  inline void SetSpecularAmount( float value )
255  {
256  _specularAmount = value;
257 #ifndef GLES
258  SelectShader();
259 #endif
260  }
261  inline float GetSpecularAmount() const { return _specularAmount; }
262 
263  inline void SetReflectionAmount( float value )
264  {
265  _reflectionAmount = value;
266 #ifndef GLES
267  SelectShader();
268 #endif
269  }
270  inline float GetReflectionAmount() const { return _reflectionAmount; }
271 
272  inline void SetNormalMapFlipGreen( bool value )
273  {
274  _normalMapFlipGreen = value;
275 #ifndef GLES
276  SelectShader();
277 #endif
278  }
279  inline bool GetNormalMapFlipGreen() const { return _normalMapFlipGreen; }
280 
281  /* Set Diffuse Map UV transform parameters
282  * Note that scaling and rotation are performed from the center of the texture.
283  * \param uOffset u axis translation
284  * \param vOffset v axis translation
285  * \param uTiling u axis scaling
286  * \param vTiling v axis scaling
287  * \param angle x axis rotation in degrees
288  */
289  GLSGEN_GlsAdvancedMesh_EXPORT void SetDiffuseUVWSettings( float uOffset, float vOffset, float uTiling, float vTiling, float angle );
290  GLSGEN_GlsAdvancedMesh_EXPORT void GetDiffuseUVWSettings( float& uOffset, float& vOffset, float& uTiling, float& vTiling, float& angle );
291 
292  /* Set Normal Map UV transform parameters
293  * Note that scaling and rotation are performed from the center of the texture.
294  * \param uOffset u axis translation
295  * \param vOffset v axis translation
296  * \param uTiling u axis scaling
297  * \param vTiling v axis scaling
298  * \param angle W-axis rotation in degrees
299  */
300  GLSGEN_GlsAdvancedMesh_EXPORT void SetNormalUVWSettings( float uOffset, float vOffset, float uTiling, float vTiling, float angle );
301  GLSGEN_GlsAdvancedMesh_EXPORT void GetNormalUVWSettings( float& uOffset, float& vOffset, float& uTiling, float& vTiling, float& angle );
302 
303  /* Set Specular Map UV transform parameters
304  * Note that scaling and rotation are performed from the center of the texture.
305  * \param uOffset u axis translation
306  * \param vOffset v axis translation
307  * \param uTiling u axis scaling
308  * \param vTiling v axis scaling
309  * \param angle W-axis rotation in degrees
310  */
311  GLSGEN_GlsAdvancedMesh_EXPORT void SetSpecularUVWSettings( float uOffset, float vOffset, float uTiling, float vTiling, float angle );
312  GLSGEN_GlsAdvancedMesh_EXPORT void GetSpecularUVWSettings( float& uOffset, float& vOffset, float& uTiling, float& vTiling, float& angle );
313 
314  // Selects the shader to use based on the current effect parameters
315  // Not normally called by users
316  GLSGEN_GlsAdvancedMesh_EXPORT void SelectShader();
317 
318  // Recalculate the texture transform matrices
319  // Not normally called by users
320  GLSGEN_GlsAdvancedMesh_EXPORT void TextureUVWSettingsChanged();
321 
322  // Returns true if the effect has non-default texture transform settings
323  // Not normally called by users
324  GLSGEN_GlsAdvancedMesh_EXPORT bool UsesTextureTransforms();
325 
326  // Returns reference to the effect attribute dictionary
327  inline DistiAttribDict& Attributes()
328  {
329  if( !_attribDict )
330  {
331  SetupAttribDict();
332  }
333  return *_attribDict;
334  }
335 
336  // Return this effect's type as a readable string
337  inline const std::string& EffectTypeName()
338  {
339  return EFFECT_TYPE_NAME;
340  }
341 
342  /////////////////////////////////////////////
343  // VertexAttribIndexLookup Interface
344  /////////////////////////////////////////////
345 
346  virtual GLint GetVertexAttribIndexForSemantic( int semanticEnum );
347 
348  ///////////////////////////////////////////////////////////////////////////
349  // GlsRenderEffect overrides
350  ///////////////////////////////////////////////////////////////////////////
351  virtual void AddRef();
352  virtual void Release();
353  virtual unsigned int GlsRenderEffect_ClassID() const;
354  virtual void SetupEffect(
355  DynamicArray<Material, false>& materialPalette,
356  TexturePalette* texturePalette,
357  const TextureSettings& textureSettings,
358  float* viewToWorld3x3 // 3x3 matrix (float[9])
359 #if !( ( GLS_VERSION_MAJOR == 4 && ( GLS_VERSION_MINOR == 1 || GLS_VERSION_MINOR == 0 ) ) || GLS_VERSION_MAJOR <= 3 )
360  ,
361  unsigned int maxLightNum,
362  unsigned int activeLightMask
363 #endif
364  );
365 
366  virtual void CleanupEffect();
367  virtual int Compare( const GlsRenderEffect* ) const;
368  virtual GlsRenderEffect* Clone() const;
369  virtual void GetReferencedTextures( ReferencedTextureArray& referencedTextures );
370  virtual void GetReferencedMaterials( ReferencedMaterialArray& referencedMaterials );
371 };
372 
373 } // namespace disti
374 
375 #endif
Definition: effect_diff_norm_spec_refl.h:87
Definition: gls_es20_effect.h:58
Definition: effect_diff_norm_spec_refl.h:82
unsigned int _ref_count
Reference count.
Definition: effect_diff_norm_spec_refl.h:127
float _normalAmount
[0.0,1.0] "Weight" of the normal map
Definition: effect_diff_norm_spec_refl.h:144
The GlsMatrixAffine class.
bool _useVertexColors
true: use vertex color for diffuse rather than material diffuse
Definition: effect_diff_norm_spec_refl.h:148
virtual GlsRenderEffect * Clone() const
virtual void SetupEffect(DynamicArray< Material, false > &materialPalette, TexturePalette *texturePalette, const TextureSettings &textureSettings, float *viewToWorld3x3)
The disti::GlsStateManager factory class. Creates an instance of a state manager that manages the GL ...
virtual void GetReferencedTextures(ReferencedTextureArray &referencedTextures)
virtual void CleanupEffect()
Remove the effect trom the OpenGL state.
virtual int Compare(const GlsRenderEffect *) const
float _specularAmount
[0.0,1.0] "Weight" of the specular map
Definition: effect_diff_norm_spec_refl.h:145
float _reflectionAmount
[0.0,1.0] "Weight" of the reflection map
Definition: effect_diff_norm_spec_refl.h:146
MaxLike_Shader * _shader
shader program to use (if any)
Definition: effect_diff_norm_spec_refl.h:134
int _diffuseTextureIndex
INVALID_INDEX, or the texture index to use.
Definition: effect_diff_norm_spec_refl.h:138
Type * Data()
Definition: gls_matrix.h:131
unsigned int _materialIndex
The material index to use.
Definition: effect_diff_norm_spec_refl.h:137
virtual GLint GetVertexAttribIndexForSemantic(int semanticEnum)
int _specularTextureIndex
INVALID_INDEX, or the texture index to use.
Definition: effect_diff_norm_spec_refl.h:140
Definition: disti_metadata.h:673
bool _normalMapFlipGreen
Definition: effect_diff_norm_spec_refl.h:154
int _reflectionTextureIndex
INVALID_INDEX, or the texture index to use.
Definition: effect_diff_norm_spec_refl.h:141
float _diffuseAmount
[0.0,1.0] "Weight" of the diffuse map
Definition: effect_diff_norm_spec_refl.h:143
int _normalTextureIndex
INVALID_INDEX, or the texture index to use.
Definition: effect_diff_norm_spec_refl.h:139
Definition: gls_render_effect.h:115
Definition: bmpimage.h:46
virtual void GetReferencedMaterials(ReferencedMaterialArray &referencedMaterials)
The disti::GlsRenderEffect class.