H3D API  2.4.1
PhongShader.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __PHONGSHADER_H__
30 #define __PHONGSHADER_H__
31 
33 #include <H3D/X3DTexture2DNode.h>
34 #include <H3D/SFMatrix4f.h>
35 
36 namespace H3D {
37 
161  class H3DAPI_API PhongShader :
163  public:
164 
171  true >
173 
175  PhongShader( Inst< DisplayList > _displayList = 0,
176  Inst< SFNode > _metadata = 0,
177  Inst< SFBool > _isSelected = 0,
178  Inst< SFBool > _isValid = 0,
179  Inst< SFBool > _activate = 0,
180  Inst< SFString > _language = 0,
181  Inst< MFShaderPart > _parts = 0,
182  Inst< SFBool > _suppressUniformWarnings = 0,
183  Inst< MFString > _fragmentShaderString = 0,
184  Inst< MFString > _vertexShaderString = 0,
185  Inst< SFTexture2DNode > _ambientMap = 0,
186  Inst< SFTexture2DNode > _diffuseMap = 0,
187  Inst< SFTexture2DNode > _emissionMap = 0,
188  Inst< SFTexture2DNode > _normalMap = 0,
189  Inst< SFString > _normalMapCoordSpace = 0,
190  Inst< SFMatrix4f > _normalMapMatrix = 0,
191  Inst< SFTexture2DNode > _specularMap = 0,
192  Inst< SFTexture2DNode > _glossMap = 0,
193  Inst< SFTexture2DNode > _specularColorRamp = 0,
194  Inst< SFString > _specularColorRampMode = 0,
195  Inst< SFTexture2DNode > _diffuseColorRamp = 0,
196  Inst< SFString > _diffuseColorRampMode = 0,
197  Inst< SFFloat > _fresnel = 0,
198  Inst< SFBool > _modulateMaps = 0,
199  Inst< SFTexture2DNode > _backAmbientMap = 0,
200  Inst< SFTexture2DNode > _backDiffuseMap = 0,
201  Inst< SFTexture2DNode > _backEmissionMap = 0,
202  Inst< SFTexture2DNode > _backNormalMap = 0,
203  Inst< SFString > _backNormalMapCoordSpace = 0,
204  Inst< SFMatrix4f > _backNormalMapMatrix = 0,
205  Inst< SFTexture2DNode > _backSpecularMap = 0,
206  Inst< SFTexture2DNode > _backGlossMap = 0,
207  Inst< SFTexture2DNode > _backSpecularColorRamp = 0,
208  Inst< SFString > _backSpecularColorRampMode = 0,
209  Inst< SFTexture2DNode > _backDiffuseColorRamp = 0,
210  Inst< SFString > _backDiffuseColorRampMode = 0,
211  Inst< SFFloat > _backFresnel = 0,
212  Inst< SFBool > _backModulateMaps = 0,
213  Inst< SFBool > _separateBackColor = 0,
214  Inst< SFString > _model = 0 );
215 
220  virtual void traverseSG( TraverseInfo &ti );
221 
230  //
235  H3DUniquePtr< SFTexture2DNode > ambientMap;
236 
245  //
250  H3DUniquePtr< SFTexture2DNode > diffuseMap;
251 
259  //
264  H3DUniquePtr< SFTexture2DNode > emissionMap;
265 
273  //
278  H3DUniquePtr< SFTexture2DNode > normalMap;
279 
282  //
290  H3DUniquePtr< SFMatrix4f > normalMapMatrix;
291 
307  H3DUniquePtr< SFString > normalMapCoordSpace;
308 
317  //
322  H3DUniquePtr< SFTexture2DNode > specularMap;
323 
332  //
337  H3DUniquePtr< SFTexture2DNode > glossMap;
338 
352  H3DUniquePtr< SFTexture2DNode > diffuseColorRamp;
353 
366  H3DUniquePtr< SFString > diffuseColorRampMode;
367 
380  H3DUniquePtr< SFTexture2DNode > specularColorRamp;
381 
382 
395  H3DUniquePtr< SFString > specularColorRampMode;
396 
414  H3DUniquePtr< SFFloat > fresnel;
415 
424  H3DUniquePtr< SFBool > modulateMaps;
425 
435  //
440  H3DUniquePtr< SFTexture2DNode > backAmbientMap;
441 
451  //
456  H3DUniquePtr< SFTexture2DNode > backDiffuseMap;
457 
466  //
471  H3DUniquePtr< SFTexture2DNode > backEmissionMap;
472 
481  //
486  H3DUniquePtr< SFTexture2DNode > backNormalMap;
487 
491  //
499  H3DUniquePtr< SFMatrix4f > backNormalMapMatrix;
500 
517  H3DUniquePtr< SFString > backNormalMapCoordSpace;
518 
528  //
533  H3DUniquePtr< SFTexture2DNode > backSpecularMap;
534 
544  //
549  H3DUniquePtr< SFTexture2DNode > backGlossMap;
550 
564  H3DUniquePtr< SFTexture2DNode > backDiffuseColorRamp;
565 
578  H3DUniquePtr< SFString > backDiffuseColorRampMode;
579 
593  H3DUniquePtr< SFTexture2DNode > backSpecularColorRamp;
594 
607  H3DUniquePtr< SFString > backSpecularColorRampMode;
608 
617  H3DUniquePtr< SFFloat > backFresnel;
618 
628  H3DUniquePtr< SFBool > backModulateMaps;
629 
640  H3DUniquePtr< SFBool > separateBackColor;
641 
653  H3DUniquePtr< SFString > model;
654 
657  protected:
658 
663 
669 
672 
674  string uniqueLightFieldName( const string &field_name,
675  X3DLightNode *light);
676 
681  virtual string addUniformFields( ComposedShader *shader );
682 
690  virtual string addUniformFieldsForLight( ComposedShader *shader,
691  X3DLightNode *light,
692  int gl_index);
693 
696  virtual string getFunctionShaderString();
697 
699  virtual void getVaryingVariables( vector< VaryingVariable > &variables );
700 
702  virtual void getAttributes( vector< Attribute > &attributes );
703 
705  virtual string getFragmentShaderString();
706 
710  virtual string getBaseDiffuseColor( const string &diffuse_color,
711  const string &back_diffuse_color );
712 
716  virtual string getBaseEmissionColor( const string &emission_color,
717  const string &back_emission_color );
718 
722  virtual string getBaseAmbientColor( const string &ambient_color,
723  const string &back_ambient_color );
724 
728  virtual string getBaseSpecularColor( const string &specular_color,
729  const string &back_specular_color );
730 
734  virtual string getBaseShininess( const string &shininess,
735  const string &back_shininess );
736 
740  virtual string getBaseNormal( const string &normal,
741  const string &back_normal );
742 
746  virtual string getBaseColors( const string &emission_color,
747  const string &shininess,
748  const string &ambient_color,
749  const string &diffuse_color,
750  const string &specular_color,
751  const string &normal,
752  const string &back_emission_color,
753  const string &back_shininess,
754  const string &back_ambient_color,
755  const string &back_diffuse_color,
756  const string &back_specular_color,
757  const string &back_normal );
758 
770  virtual string getLightContribution( X3DLightNode *light,
771  unsigned int index,
772  string normal,
773  string vertex,
774  string shininess,
775  string ambient_color,
776  string diffuse_color,
777  string specular_color );
778 
785  virtual string setupLight( X3DLightNode *light,
786  unsigned int gl_index );
787  };
788 }
789 
790 #endif
Header file for H3DGeneratedFragmentShaderNode.
Contains the SFMatrix4f field class.
Header file for X3DTexture2DNode, X3D scene-graph node.
The ComposedShader node defines a shader where the individual source files are not individually progr...
Definition: ComposedShader.h:77
DependentSFNode are modified TypedSFNode fields where the field dirty status is dependent on fields i...
Definition: DependentNodeFields.h:294
Class used for specifying a field member of a node in a DependentSFNode or DependentMFNode specificat...
Definition: DependentNodeFields.h:48
We use the Field's lazy evaluation mechanisms to manage the GL display lists for rendering,...
Definition: H3DDisplayListObject.h:60
This abstract interface class is the base class for all node types that wants to create an OpenGL dis...
Definition: H3DDisplayListObject.h:54
H3DUniquePtr< DisplayList > displayList
The DisplayList instance handling the OpenGL caching of this object.
Definition: H3DDisplayListObject.h:256
The H3DGeneratedFragmentShaderNode node is the base class for shader generator nodes that specify a f...
Definition: H3DGeneratedFragmentShaderNode.h:44
The PhongShader node defines a shader for using the Phong illumination model.
Definition: PhongShader.h:162
H3DUniquePtr< SFTexture2DNode > ambientMap
Defines the Ma part in the Phong illumination model specified above.
Definition: PhongShader.h:235
H3DUniquePtr< SFMatrix4f > normalMapMatrix
Defines the transformation from RGB values of the normalMap(in range [0,1]) to the actual normals in ...
Definition: PhongShader.h:290
unsigned int current_nr_lightsources
The number of light sources the shader currently handles(including headlight)
Definition: PhongShader.h:671
H3DUniquePtr< SFString > backSpecularColorRampMode
The backSpecularColorRampMode defines what value should be used to lookup up into the backSpecularCol...
Definition: PhongShader.h:607
AutoPtrVector< SFMatrix4f > current_light_node_transforms
The transform matrices for all lights with index > maximum number lightsources supported by OpenGL fi...
Definition: PhongShader.h:668
H3DUniquePtr< SFString > backNormalMapCoordSpace
The normalMapCoordSpace field defines which coordinate space the normals in the normalMap are specifi...
Definition: PhongShader.h:517
H3DUniquePtr< SFString > specularColorRampMode
The specularColorRampMode defines what value should be used to lookup up into the specularColorRamp t...
Definition: PhongShader.h:395
H3DUniquePtr< SFBool > backModulateMaps
The modulateMaps field determines if the map values should be modulated with the corresponding Materi...
Definition: PhongShader.h:628
H3DUniquePtr< SFTexture2DNode > backGlossMap
Defines the Mshininess part in the Phong illumination model specified above for back facing polygons.
Definition: PhongShader.h:549
H3DUniquePtr< SFFloat > backFresnel
The backFresnel field specifies the fresnel value for back facing polygons when separateBackColor is ...
Definition: PhongShader.h:617
H3DUniquePtr< SFTexture2DNode > backDiffuseMap
Defines the Md part in the Phong illumination model specified above for back facing polygons.
Definition: PhongShader.h:456
H3DUniquePtr< SFTexture2DNode > normalMap
Defines the normal(N) in the Phong illumination model specified above.
Definition: PhongShader.h:278
H3DUniquePtr< SFTexture2DNode > backSpecularColorRamp
The specularColorRamp can be used to control the specular color gradient across a material for back f...
Definition: PhongShader.h:593
H3DUniquePtr< SFString > backDiffuseColorRampMode
The backDiffuseColorRampMode defines what value should be used to lookup up into the backDiffuseColor...
Definition: PhongShader.h:578
H3DUniquePtr< SFTexture2DNode > backSpecularMap
Defines the Ms part in the Phong illumination model specified above for back facing polygons.
Definition: PhongShader.h:533
H3DUniquePtr< SFMatrix4f > backNormalMapMatrix
Defines the transformation from RGB values of the normalMap(in range [0,1]) to the actual normals in ...
Definition: PhongShader.h:499
H3DUniquePtr< SFFloat > fresnel
The fresnel field specifies if the fresnel effect should be used in the lighting model and if so how ...
Definition: PhongShader.h:414
H3DUniquePtr< SFTexture2DNode > backDiffuseColorRamp
The diffuseColorRamp can be used to control the diffuse color gradient across a material for back fac...
Definition: PhongShader.h:564
H3DUniquePtr< SFString > diffuseColorRampMode
The diffuseColorRampMode defines what value should be used to lookup up into the diffuseColorRamp tex...
Definition: PhongShader.h:366
H3DUniquePtr< SFTexture2DNode > backAmbientMap
Defines the Ma part in the Phong illumination model specified above for back facing polygons.
Definition: PhongShader.h:440
H3DUniquePtr< SFTexture2DNode > specularColorRamp
The specularColorRamp can be used to control the specular color gradient across a material.
Definition: PhongShader.h:380
H3DUniquePtr< SFString > normalMapCoordSpace
The normalMapCoordSpace field defines which coordinate space the normals in the normalMap are specifi...
Definition: PhongShader.h:307
H3DUniquePtr< SFTexture2DNode > backEmissionMap
Defines the Me part in the Phong illumination model specified above for back facing polygons.
Definition: PhongShader.h:471
DependentSFNode< X3DTexture2DNode, FieldRef< H3DDisplayListObject, H3DDisplayListObject::DisplayList, &H3DDisplayListObject::displayList >, true > SFTexture2DNode
The SFTexture2DNode field is dependent on the displayList field of the containing X3DTexture2DNode no...
Definition: PhongShader.h:172
H3DUniquePtr< SFString > model
The shading model to use.
Definition: PhongShader.h:653
H3DUniquePtr< SFTexture2DNode > glossMap
Defines the Mshininess part in the Phong illumination model specified above.
Definition: PhongShader.h:337
H3DUniquePtr< SFTexture2DNode > specularMap
Defines the Ms part in the Phong illumination model specified above.
Definition: PhongShader.h:322
TraverseInfo::LightVector current_light_nodes
The X3DLightNode instances that this shader is built for.
Definition: PhongShader.h:662
H3DUniquePtr< SFTexture2DNode > diffuseMap
Defines the Md part in the Phong illumination model specified above.
Definition: PhongShader.h:250
H3DUniquePtr< SFTexture2DNode > emissionMap
Defines the Me part in the Phong illumination model specified above.
Definition: PhongShader.h:264
H3DUniquePtr< SFBool > modulateMaps
The modulateMaps field determines if the map values should be modulated with the corresponding Materi...
Definition: PhongShader.h:424
H3DUniquePtr< SFTexture2DNode > backNormalMap
Defines the normal(N) in the Phong illumination model specified above for back facing polygons.
Definition: PhongShader.h:486
H3DUniquePtr< SFBool > separateBackColor
If the separateBackColor field is set to TRUE, then the rendering shall render the front and back fac...
Definition: PhongShader.h:640
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: PhongShader.h:656
H3DUniquePtr< SFTexture2DNode > diffuseColorRamp
The diffuseColorRamp can be used to control the diffuse color gradient across a material.
Definition: PhongShader.h:352
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
vector< LightInfo > LightVector
Used to get all the X3DLightNodes that are global.
Definition: TraverseInfo.h:441
The X3DLightNode abstract node type is the base type from which all node types that serve as light so...
Definition: X3DLightNode.h:70
This abstract node type is the base type for all node types which specify 2D sources for texture imag...
Definition: X3DTexture2DNode.h:46
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194