H3D API  2.4.1
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
H3D::PhongShader Class Reference

The PhongShader node defines a shader for using the Phong illumination model. More...

#include <H3D/PhongShader.h>

Inheritance diagram for H3D::PhongShader:
Inheritance graph

Public Types

typedef DependentSFNode< X3DTexture2DNode, FieldRef< H3DDisplayListObject, H3DDisplayListObject::DisplayList, &H3DDisplayListObject::displayList >, true > SFTexture2DNode
 The SFTexture2DNode field is dependent on the displayList field of the containing X3DTexture2DNode node.
 
- Public Types inherited from H3D::ComposedShader
typedef DependentSFNode< ShaderConstants, FieldRef< H3DDisplayListObject, H3DDisplayListObject::DisplayList, &H3DDisplayListObject::displayList >, true > SFShaderConstantsBase
 The SFShaderConstants field is dependent on the displayList field of the containing ShaderConstants node.
 
typedef DependentMFNode< ShaderPart, FieldRef< ShaderPart, ShaderPart::SFShaderString, &ShaderPart::shaderString >, true > MFShaderPartBase
 The MFShaderPartBase is dependent on the url field of the containing ShaderPart node.
 
- Public Types inherited from H3D::Node
typedef std::map< Node *, Node * > DeepCopyMap
 A map type used during a deep copy clone() to map from original nodes to cloned nodes.
 

Public Member Functions

 PhongShader (Inst< DisplayList > _displayList=0, Inst< SFNode > _metadata=0, Inst< SFBool > _isSelected=0, Inst< SFBool > _isValid=0, Inst< SFBool > _activate=0, Inst< SFString > _language=0, Inst< MFShaderPart > _parts=0, Inst< SFBool > _suppressUniformWarnings=0, Inst< MFString > _fragmentShaderString=0, Inst< MFString > _vertexShaderString=0, Inst< SFTexture2DNode > _ambientMap=0, Inst< SFTexture2DNode > _diffuseMap=0, Inst< SFTexture2DNode > _emissionMap=0, Inst< SFTexture2DNode > _normalMap=0, Inst< SFString > _normalMapCoordSpace=0, Inst< SFMatrix4f > _normalMapMatrix=0, Inst< SFTexture2DNode > _specularMap=0, Inst< SFTexture2DNode > _glossMap=0, Inst< SFTexture2DNode > _specularColorRamp=0, Inst< SFString > _specularColorRampMode=0, Inst< SFTexture2DNode > _diffuseColorRamp=0, Inst< SFString > _diffuseColorRampMode=0, Inst< SFFloat > _fresnel=0, Inst< SFBool > _modulateMaps=0, Inst< SFTexture2DNode > _backAmbientMap=0, Inst< SFTexture2DNode > _backDiffuseMap=0, Inst< SFTexture2DNode > _backEmissionMap=0, Inst< SFTexture2DNode > _backNormalMap=0, Inst< SFString > _backNormalMapCoordSpace=0, Inst< SFMatrix4f > _backNormalMapMatrix=0, Inst< SFTexture2DNode > _backSpecularMap=0, Inst< SFTexture2DNode > _backGlossMap=0, Inst< SFTexture2DNode > _backSpecularColorRamp=0, Inst< SFString > _backSpecularColorRampMode=0, Inst< SFTexture2DNode > _backDiffuseColorRamp=0, Inst< SFString > _backDiffuseColorRampMode=0, Inst< SFFloat > _backFresnel=0, Inst< SFBool > _backModulateMaps=0, Inst< SFBool > _separateBackColor=0, Inst< SFString > _model=0)
 Constructor.
 
virtual void traverseSG (TraverseInfo &ti)
 The traverseSG method is specialized to add the shaderRequiresTangents user data to the TraverseInfo object in order to let supported geometries to render tangents if they can.
 
- Public Member Functions inherited from H3D::H3DGeneratedFragmentShaderNode
 H3DGeneratedFragmentShaderNode (Inst< DisplayList > _displayList=0, Inst< SFNode > _metadata=0, Inst< SFBool > _isSelected=0, Inst< SFBool > _isValid=0, Inst< SFBool > _activate=0, Inst< SFString > _language=0, Inst< MFShaderPart > _parts=0, Inst< SFBool > _suppressUniformWarnings=0, Inst< MFString > _fragmentShaderString=0, Inst< MFString > _vertexShaderString=0)
 Constructor.
 
- Public Member Functions inherited from H3D::H3DGeneratedShaderNode
 H3DGeneratedShaderNode (Inst< DisplayList > _displayList=0, Inst< SFNode > _metadata=0, Inst< SFBool > _isSelected=0, Inst< SFBool > _isValid=0, Inst< SFBool > _activate=0, Inst< SFString > _language=0, Inst< MFShaderPart > _parts=0, Inst< SFBool > _suppressUniformWarnings=0, Inst< MFString > _fragmentShaderString=0, Inst< MFString > _vertexShaderString=0)
 Constructor.
 
virtual void buildShader ()
 Rebuilds the generated shader, causing a full rebuild and relink of the shader.
 
virtual void preRender ()
 The preRender method is extended to make sure that the shader is up to date before rendering.
 
virtual string getFinalFragmentShaderOutputString ()
 Returns the string that is the last thing that is done in the fragment shader. More...
 
virtual string getVertexShaderString ()
 Returns the shader code for the vertex shader. More...
 
virtual string uniqueShaderName (const string &base_name)
 The uniqueShaderName function is used to generate a name unique for this instance of the shader generator node class. More...
 
virtual string getFragmentShaderHeader ()
 Return a string that is placed at the beginning of a fragment shader to specify minimum required version of the shader as well as enabled extensions.
 
virtual string getVertexShaderHeader ()
 Return a string that is placed at the beginning of a vertex shader to specify minimum required version of the shader as well as enabled extensions.
 
- Public Member Functions inherited from H3D::ComposedShader
 ComposedShader (Inst< DisplayList > _displayList=0, Inst< SFNode > _metadata=0, Inst< SFBool > _isSelected=0, Inst< SFBool > _isValid=0, Inst< SFBool > _activate=0, Inst< SFString > _language=0, Inst< MFShaderPart > _parts=0, Inst< SFBool > _suppressUniformWarnings=0, Inst< SFString > _geometryInputType=0, Inst< SFString > _geometryOutputType=0, Inst< SFInt32 > _geometryVerticesOut=0, Inst< SFString > _transparencyDetectMode=0, Inst< MFString > _transformFeedbackVaryings=0, Inst< SFBool > _printShaderWarnings=0, Inst< SFShaderConstants > _shaderConstants=0)
 Constructor.
 
virtual ~ComposedShader ()
 Destructor.
 
virtual bool addField (const string &_name, const Field::AccessType &access, Field *field)
 The addField method is specialized to add a route from the field added to the displayList field.
 
virtual bool removeField (const string &_name)
 The removeField method is specialized to remove the route from the field to the displayList field.
 
virtual void render ()
 Sets up the shader program and sets uniform variable values.
 
virtual void postRender ()
 Disables the shader program.
 
virtual GLbitfield getAffectedGLAttribs ()
 Returns a bitmask of the OpenGL attrib bits that will be affected by this node. More...
 
virtual bool isTransparent (X3DMaterialNode *material)
 Returns a hint if the X3DShaderNode produces an alpha channel that is < 1, i.e. More...
 
GLhandleARB getProgramHandle ()
 Returns the OpenGL shader program handle used by the ComposedShader.
 
- Public Member Functions inherited from H3D::X3DShaderNode
 X3DShaderNode (Inst< DisplayList > _displayList=0, Inst< SFNode > _metadata=0, Inst< SFBool > _isSelected=0, Inst< SFBool > _isValid=0, Inst< SFBool > _activate=0, Inst< SFString > _language=0)
 Constructor.
 
virtual bool isSupported ()
 Returns true if the shader node type is supported by the browser. More...
 
void setSelected (bool selected)
 Set the isSelected field.
 
virtual string defaultXMLContainerField ()
 Returns the default xml containerField attribute value. More...
 
- Public Member Functions inherited from H3D::X3DAppearanceChildNode
 X3DAppearanceChildNode (Inst< DisplayList > _displayList=0, Inst< SFNode > _metadata=0)
 Constructor.
 
- Public Member Functions inherited from H3D::X3DNode
 X3DNode (Inst< SFNode > _metadata=0)
 Constructor.
 
X3DMetadataObjectgetMetadataByName (const string &_name)
 Given a name, the first X3DMetadataObject in the metadata field that matches that name is returned. More...
 
- Public Member Functions inherited from H3D::Node
 Node ()
 Constructor.
 
virtual Nodeclone (bool deepCopy=true, DeepCopyMap *deepCopyMap=NULL)
 Returns a new instance of this node type with the same state as this one. More...
 
virtual ~Node ()
 Destructor.
 
X3DPrototypeInstancegetProtoInstanceParent ()
 If this node is the root node in the proto body of a X3DPrototypeInstance then this will return that node. More...
 
void setProtoInstanceParent (X3DPrototypeInstance *p)
 Set the X3DPrototypeInstance this node is the the root node if applicaple.
 
virtual bool lineIntersect (const Vec3f &from, const Vec3f &to, LineIntersectResult &result)
 Detect intersection between a line segment and the Node. More...
 
virtual void closestPoint (const Vec3f &p, NodeIntersectResult &result)
 Find closest point on Node to p. More...
 
virtual bool movingSphereIntersect (H3DFloat radius, const Vec3f &from, const Vec3f &to, NodeIntersectResult &result)
 Detect collision between a moving sphere and the Node. More...
 
virtual FieldgetField (const string &_name) const
 return a pointer to the field specified by name within this instance
 
int addDestructCallback (void(*func)(Node *, void *), void *args)
 Add a callback function to be run on destruction of node. More...
 
int removeDestructCallback (void(*func)(Node *, void *), void *args)
 Add a callback function to be run on destruction of node. More...
 
- Public Member Functions inherited from H3D::H3DDisplayListObject
 H3DDisplayListObject (Inst< DisplayList > _displayList=0)
 Constructor.
 
- Public Member Functions inherited from H3D::X3DProgrammableShaderObject
 X3DProgrammableShaderObject (H3DNodeDatabase *_database)
 Constructor.
 
virtual void clearFields ()
 Remove all dynamic fields that have been previously added.
 
virtual ~X3DProgrammableShaderObject ()
 Destructor.
 
- Public Member Functions inherited from H3D::H3DDynamicFieldsObject
field_iterator firstField ()
 Get an iterator to the first of the dynamic fields.
 
field_iterator endField ()
 Get an iterator pointing to the end of the dynamic fields.
 
 H3DDynamicFieldsObject ()
 Constructor.
 

Public Attributes

H3DUniquePtr< SFTexture2DNodeambientMap
 Defines the Ma part in the Phong illumination model specified above. More...
 
H3DUniquePtr< SFTexture2DNodediffuseMap
 Defines the Md part in the Phong illumination model specified above. More...
 
H3DUniquePtr< SFTexture2DNodeemissionMap
 Defines the Me part in the Phong illumination model specified above. More...
 
H3DUniquePtr< SFTexture2DNodenormalMap
 Defines the normal(N) in the Phong illumination model specified above. More...
 
H3DUniquePtr< SFMatrix4fnormalMapMatrix
 Defines the transformation from RGB values of the normalMap(in range [0,1]) to the actual normals in range[-1,1]. More...
 
H3DUniquePtr< SFStringnormalMapCoordSpace
 The normalMapCoordSpace field defines which coordinate space the normals in the normalMap are specified in. More...
 
H3DUniquePtr< SFTexture2DNodespecularMap
 Defines the Ms part in the Phong illumination model specified above. More...
 
H3DUniquePtr< SFTexture2DNodeglossMap
 Defines the Mshininess part in the Phong illumination model specified above. More...
 
H3DUniquePtr< SFTexture2DNodediffuseColorRamp
 The diffuseColorRamp can be used to control the diffuse color gradient across a material. More...
 
H3DUniquePtr< SFStringdiffuseColorRampMode
 The diffuseColorRampMode defines what value should be used to lookup up into the diffuseColorRamp texture. More...
 
H3DUniquePtr< SFTexture2DNodespecularColorRamp
 The specularColorRamp can be used to control the specular color gradient across a material. More...
 
H3DUniquePtr< SFStringspecularColorRampMode
 The specularColorRampMode defines what value should be used to lookup up into the specularColorRamp texture. More...
 
H3DUniquePtr< SFFloatfresnel
 The fresnel field specifies if the fresnel effect should be used in the lighting model and if so how much. More...
 
H3DUniquePtr< SFBoolmodulateMaps
 The modulateMaps field determines if the map values should be modulated with the corresponding Material value or not. More...
 
H3DUniquePtr< SFTexture2DNodebackAmbientMap
 Defines the Ma part in the Phong illumination model specified above for back facing polygons. More...
 
H3DUniquePtr< SFTexture2DNodebackDiffuseMap
 Defines the Md part in the Phong illumination model specified above for back facing polygons. More...
 
H3DUniquePtr< SFTexture2DNodebackEmissionMap
 Defines the Me part in the Phong illumination model specified above for back facing polygons. More...
 
H3DUniquePtr< SFTexture2DNodebackNormalMap
 Defines the normal(N) in the Phong illumination model specified above for back facing polygons. More...
 
H3DUniquePtr< SFMatrix4fbackNormalMapMatrix
 Defines the transformation from RGB values of the normalMap(in range [0,1]) to the actual normals in range[-1,1]. More...
 
H3DUniquePtr< SFStringbackNormalMapCoordSpace
 The normalMapCoordSpace field defines which coordinate space the normals in the normalMap are specified in. More...
 
H3DUniquePtr< SFTexture2DNodebackSpecularMap
 Defines the Ms part in the Phong illumination model specified above for back facing polygons. More...
 
H3DUniquePtr< SFTexture2DNodebackGlossMap
 Defines the Mshininess part in the Phong illumination model specified above for back facing polygons. More...
 
H3DUniquePtr< SFTexture2DNodebackDiffuseColorRamp
 The diffuseColorRamp can be used to control the diffuse color gradient across a material for back facing polygons. More...
 
H3DUniquePtr< SFStringbackDiffuseColorRampMode
 The backDiffuseColorRampMode defines what value should be used to lookup up into the backDiffuseColorRamp texture. More...
 
H3DUniquePtr< SFTexture2DNodebackSpecularColorRamp
 The specularColorRamp can be used to control the specular color gradient across a material for back facing polygons. More...
 
H3DUniquePtr< SFStringbackSpecularColorRampMode
 The backSpecularColorRampMode defines what value should be used to lookup up into the backSpecularColorRamp texture. More...
 
H3DUniquePtr< SFFloatbackFresnel
 The backFresnel field specifies the fresnel value for back facing polygons when separateBackColor is TRUE. More...
 
H3DUniquePtr< SFBoolbackModulateMaps
 The modulateMaps field determines if the map values should be modulated with the corresponding Material value or not. More...
 
H3DUniquePtr< SFBoolseparateBackColor
 If the separateBackColor field is set to TRUE, then the rendering shall render the front and back faces of the geometry with different values using the backDiffuseMap, backSpecularMap, etc. More...
 
H3DUniquePtr< SFStringmodel
 The shading model to use. More...
 
- Public Attributes inherited from H3D::H3DGeneratedShaderNode
H3DUniquePtr< MFStringfragmentShaderString
 Contains the generated fragment shader code. More...
 
H3DUniquePtr< MFStringvertexShaderString
 Contains the generated vertex shader code. More...
 
H3DUniquePtr< RebuildShaderrebuildShader
 Field used to update the shader code when an event is received. More...
 
- Public Attributes inherited from H3D::ComposedShader
H3DUniquePtr< SFShaderConstants > shaderConstants
 The shaderConstants field can contain a ShaderConstants node defining constants that can be used by all ShaderPart instances in the ComposedShader node. More...
 
H3DUniquePtr< MFShaderPartparts
 The shader parts to use in the ComposedShader. More...
 
H3DUniquePtr< SFBoolsuppressUniformWarnings
 Suppress the warnings printed to the console about setting uniform fields that do not exist in the shader. More...
 
H3DUniquePtr< SFStringgeometryInputType
 The input geometry type of the geometry being rendered with a geometry shader. More...
 
H3DUniquePtr< SFStringgeometryOutputType
 The output geometry type of the geometry being rendered with a geometry shader. More...
 
H3DUniquePtr< SFInt32geometryVerticesOut
 The number of vertices the geometry shader generates. More...
 
H3DUniquePtr< SFStringtransparencyDetectMode
 Determines how the render system will determine if the shader used generates any fragment that has an alpha channel that is < 1, i.e. More...
 
H3DUniquePtr< MFStringtransformFeedbackVaryings
 List of varying names to capture during transform feedback. More...
 
H3DUniquePtr< SFBoolprintShaderWarnings
 Always print shader warnings to console. More...
 
- Public Attributes inherited from H3D::X3DShaderNode
H3DUniquePtr< SFBoolisSelected
 The isSelected output field is used to indicate that this shader instance is the one selected for use by the browser. More...
 
H3DUniquePtr< SFBoolisValid
 The isValid field is used to indicate whether the current shader objects can be run as a shader program. More...
 
H3DUniquePtr< SFBoolactivate
 The activate field forces the shader to activate the contained objects. More...
 
H3DUniquePtr< EventCollectingField< Field > > activateMonitor
 field used to monitor if activate field is modified
 
H3DUniquePtr< SFStringlanguage
 The language field is used to indicate to the browser which shading language is used for the source file(s). More...
 
- Public Attributes inherited from H3D::X3DNode
H3DUniquePtr< SFNodemetadata
 Meta data about the node. More...
 
- Public Attributes inherited from H3D::H3DDisplayListObject
H3DUniquePtr< DisplayListdisplayList
 The DisplayList instance handling the OpenGL caching of this object.
 

Static Public Attributes

static H3DNodeDatabase database
 The H3DNodeDatabase for this node.
 
- Static Public Attributes inherited from H3D::H3DGeneratedFragmentShaderNode
static H3DNodeDatabase database
 The H3DNodeDatabase for this node.
 
- Static Public Attributes inherited from H3D::H3DGeneratedShaderNode
static H3DNodeDatabase database
 The H3DNodeDatabase for this node.
 
- Static Public Attributes inherited from H3D::ComposedShader
static H3DNodeDatabase database
 The H3DNodeDatabase for this node.
 
- Static Public Attributes inherited from H3D::X3DShaderNode
static H3DNodeDatabase database
 The H3DNodeDatabase for this node.
 
- Static Public Attributes inherited from H3D::X3DNode
static H3DNodeDatabase database
 The H3DNodeDatabase for this node.
 
- Static Public Attributes inherited from H3D::X3DProgrammableShaderObject
static bool use_bindless_textures = false
 True if we should use bindless textures.
 

Protected Member Functions

string uniqueLightFieldName (const string &field_name, X3DLightNode *light)
 Returns a unique name to use in this shader for a field of a light node.
 
virtual string addUniformFields (ComposedShader *shader)
 Adds uniform fields to the shader. More...
 
virtual string addUniformFieldsForLight (ComposedShader *shader, X3DLightNode *light, int gl_index)
 Adds uniform fields needed for a light to the shader. More...
 
virtual string getFunctionShaderString ()
 Get a string with GLSL function definitions to be used by the generated shader.
 
virtual void getVaryingVariables (vector< VaryingVariable > &variables)
 Get the varying variables used by the shader generator.
 
virtual void getAttributes (vector< Attribute > &attributes)
 Get the attribues used by the shader generator.
 
virtual string getFragmentShaderString ()
 Returns the shader code for the fragment shader.
 
virtual string getBaseDiffuseColor (const string &diffuse_color, const string &back_diffuse_color)
 Returns a glsl string that sets the variable diffuse_color to the diffuse component to use in the shading model and back_diffuse_color to the diffuse component for back facing faces.
 
virtual string getBaseEmissionColor (const string &emission_color, const string &back_emission_color)
 Returns a glsl string that sets the variable emission_color to the emission component to use in the shading model and back_emission_color to the emission component for back facing faces.
 
virtual string getBaseAmbientColor (const string &ambient_color, const string &back_ambient_color)
 Returns a glsl string that sets the variable ambient_color to the ambient component to use in the shading model and back_ambient_color to the ambient component for back facing faces.
 
virtual string getBaseSpecularColor (const string &specular_color, const string &back_specular_color)
 Returns a glsl string that sets the variable specular_color to the specular component to use in the shading model and back_specular_color to the specular component for back facing faces.
 
virtual string getBaseShininess (const string &shininess, const string &back_shininess)
 Returns a glsl string that sets the variable shininess to the shininess component to use in the shading model and back_shininess to the shininess component for back facing faces.
 
virtual string getBaseNormal (const string &normal, const string &back_normal)
 Returns a glsl string that sets the variable normal to the normal to use in the shading model and back_normal to the normal for back facing faces.
 
virtual string getBaseColors (const string &emission_color, const string &shininess, const string &ambient_color, const string &diffuse_color, const string &specular_color, const string &normal, const string &back_emission_color, const string &back_shininess, const string &back_ambient_color, const string &back_diffuse_color, const string &back_specular_color, const string &back_normal)
 Returns a glsl string that sets all the given variables to its appropriate values. More...
 
virtual string getLightContribution (X3DLightNode *light, unsigned int index, string normal, string vertex, string shininess, string ambient_color, string diffuse_color, string specular_color)
 Returns a string with glsl code that adds the color contribution of a light node to the variable "final_color". More...
 
virtual string setupLight (X3DLightNode *light, unsigned int gl_index)
 Returns a string with glsl code that sets adds and initialized a variable of type gl_LightParameters and name light to the values of the light source. More...
 
- Protected Member Functions inherited from H3D::ComposedShader
void setGeometryShaderParameters (GLenum _program_handle)
 Sets geometry shader paramters based on fields.
 
- Protected Member Functions inherited from H3D::Node
void cloneFieldValue (Field &_from, Field &_to, bool deepCopy, DeepCopyMap &deepCopyMap)
 A helper function for the clone() method. More...
 

Protected Attributes

TraverseInfo::LightVector current_light_nodes
 The X3DLightNode instances that this shader is built for. More...
 
AutoPtrVector< SFMatrix4fcurrent_light_node_transforms
 The transform matrices for all lights with index > maximum number lightsources supported by OpenGL fixed functionallity. More...
 
unsigned int current_nr_lightsources
 The number of light sources the shader currently handles(including headlight)
 
- Protected Attributes inherited from H3D::ComposedShader
GLhandleARB program_handle
 The handle to the program object used for the shader in OpenGL.
 
vector< GLhandleARB > current_shaders
 A vector of the handles to all shader objects that are currently linked into the program object.
 
H3DUniquePtr< SetupDynamicRoutessetupDynamicRoutes
 C++ fields only. Contains instance of SetupDynamicRoutes.
 
list< H3DSingleTextureNode * > shader_textures
 list of textures to be used by the composedshader
 
H3DUniquePtr< UpdateUniformsupdateUniforms
 A field used to update any uniforms from their corresponding fields.
 

Additional Inherited Members

- Static Public Member Functions inherited from H3D::H3DGeneratedShaderNode
static string addUniformToFragmentShader (ComposedShader *shader, const string &name, const string &glsl_type, const Field::AccessType &access, Field *field, int array_size=-1, bool delete_unadded_field=true)
 Convenience function to add field in addUniformFields function to add uniform to fragment shader. More...
 
- Static Public Member Functions inherited from H3D::X3DShaderNode
static X3DShaderNodegetActiveShader ()
 Gets the currently active shader, i.e. More...
 
- Static Public Member Functions inherited from H3D::Node
static unsigned int nrNodesAlive ()
 Returns the nr of nodes currently alive, i.e. nodes created but not destructed.
 
static int nrNodesCreated ()
 Returns the number of nodes created in total since the start of the program.
 
- Static Protected Member Functions inherited from H3D::Node
static NodegetClonedInstance (Node *original, bool deepCopy, DeepCopyMap &deepCopyMap)
 A helper function for nodes that implement clone() More...
 
- Static Protected Attributes inherited from H3D::ComposedShader
static bool tessellation_support_checked = false
 True if a warning has already been output about missing tessellation shader support.
 
- Static Protected Attributes inherited from H3D::X3DProgrammableShaderObject
static bool use_bindless_textures_set = false
 True if use_bindless_textures has already be set once.
 

Detailed Description

The PhongShader node defines a shader for using the Phong illumination model.

Restrictions: The PhongShader can only be used on geometries that have had their texture coordinates specified with glTexCoord calls. That means that geometries which have there texture coordinates generated by a TextureCoordinateGenerator or default coordinates based on the bounding box(e.g. IndexedFaceSet without texCoord specified) will not work. In order to use tangent space normal maps you must provide vertex attributes for tangent and binormal(see below). This means that only geometries that allow specification of vertex attributes can be used as geometry then, e.g. all X3DComposedGeometryNode nodes. For IndexedTriangleSet nodes these will be automatically generated but for all other node they have to be set explicitly by the modeller.

For each light we have C = att(d)*(Ma * La + Md*Ld*(L dot N) + Fs*Ms*Ls*(R dot V )^Mshininess) where Ma, Md, Ms and Mshininess are the ambient, diffuse, specular and shininess values for a point and La, Ld and Ls are the same for the light.

L is the direction from the point to the light. N is the normal at the point. V is the direction from the point to the viewer. R is the reflected light direction. att(d) is the attenuation of the light based on the constant, linear, and quadratic attenuation parameters set for each light based on the distance d from the light. Fs is the fresnel term and is calculated by Fs = 1-fresnel + fresnel * (1-N dot V)^5

The final color is the sum of all lights color contributions and the emissive color of the material(Me).

Ma, Md, Me, Ms and Mshininess are by default the values specified by an X3DMaterialNode. Instead of just using these constant values each of these can be controlled by a texture instead allowing different values at different parts of the 3d object. Ma is controlled by ambientMap, Md by diffuseMap, Me by emissionMap Ms by specularMap and Mshininess by glossMap.

The specularColorRamp and diffuseColorRamp can be used to control the color gradient across a material. It contains a 1D texture that defines the color ramp and the value used for lookup is controlled by the specularColorRampMode and diffuseColorRampMode fields. The looked up color is then multiplied with the diffuse or specular color respectively to generate the final diffuse or specular color. This allows for different colors depending on the view angle to the surface.

The specularColorRampMode and diffuseColorRampMode defines what value should be used to lookup into the color ramp textures.

Valid values are:

If modulateMaps is FALSE the color from the map is used directly in all texture maps except for Mshininess which is a floating point value. In this case for a 1 or 2 component image, we use the intensity and for RGB and RGBA texture the R component is used.

If modulateMaps is TRUE the values are modulated with the material value, e.g. Md = Material diffuse * diffuseMap value.

The fresnel field specifies if the fresnel effect should be used in the lighting model and if so how much. The fresnel effect is the effect that surfaces reflect more light if looking at them from an angle than straight down along the normal. If set to 0 no fresnel effect is used and the surface is fully reflective. If set to 1 only the reflectivity of the fresnel effect is used, which means no reflectivity when looking down perpendicular to the surace. One can think of the term as controlling the minimum reflectivness of the surface. By default it is set to 0 and no fresnel effect is used. The fresnel value only affects the specular component of the Phong lighting calculations since this is the only part that deals with reflective properties.

The normal N can also be modified across the surface of a 3d object using a normalMap texture. The normalMap encodes the normal at each point of an object in the RGB value of an image. This allows for adding detailed features without increasing polygon count.

Since a texture holds values between [0,1] and normals have values between [-1, 1] we need to translate the RGB values of the texture to the correct normal values. The matrix in the normalMapMatrix performes this translation. The normal value is the matrix multiplied by the RGB value. By default the mapping is for each component x = R*2 - 1, transforming 0 to -1 and 1 to 1. Normals can be defined in different coordinate spaces. The normalMapCoordSpace defines which one is used:

It is possible to have different materials for front facing and back facing polygons. By default back and front use the same color but by setting the separateBackColor to TRUE a separate set of maps will be used. In this case all fields starting with back.. will be used instead for all back facing polygons. Back Material values can be set using a TwoSidedMaterial node.

Examples:

Internal routes:

Member Function Documentation

◆ addUniformFields()

string PhongShader::addUniformFields ( ComposedShader shader)
protectedvirtual

◆ addUniformFieldsForLight()

string PhongShader::addUniformFieldsForLight ( ComposedShader shader,
X3DLightNode light,
int  gl_index 
)
protectedvirtual

Adds uniform fields needed for a light to the shader.

Parameters
shaderThe shader to add the uniform to.
lightThe light for which to a uniforms.
gl_indexThe OpenGL light index used for the light. If the index is larger than the number of supported light sources in the OpenGL implementation all fields of the light are added in order to support more lights than that.

References H3D::H3DGeneratedShaderNode::addUniformToFragmentShader(), H3D::X3DLightNode::ambientIntensity, H3D::PointLight::attenuation, H3D::SpotLight::attenuation, H3D::SpotLight::beamWidth, H3D::X3DLightNode::color, current_light_node_transforms, H3D::SpotLight::cutOffAngle, H3D::DirectionalLight::direction, H3D::SpotLight::direction, H3D::GraphicsHardwareInfo::getInfo(), H3D::GraphicsHardwareInfo::infoIsInitialized(), H3D::Field::INPUT_OUTPUT, H3D::X3DLightNode::intensity, H3D::PointLight::location, H3D::SpotLight::location, H3D::PointLight::radius, H3D::SpotLight::radius, and uniqueLightFieldName().

Referenced by addUniformFields().

◆ getBaseColors()

string PhongShader::getBaseColors ( const string &  emission_color,
const string &  shininess,
const string &  ambient_color,
const string &  diffuse_color,
const string &  specular_color,
const string &  normal,
const string &  back_emission_color,
const string &  back_shininess,
const string &  back_ambient_color,
const string &  back_diffuse_color,
const string &  back_specular_color,
const string &  back_normal 
)
protectedvirtual

Returns a glsl string that sets all the given variables to its appropriate values.

Default implementation is to call the getBaseSpecularColor, getBaseDiffuseColor etc.

References getBaseAmbientColor(), getBaseDiffuseColor(), getBaseEmissionColor(), getBaseNormal(), getBaseShininess(), and getBaseSpecularColor().

Referenced by getFragmentShaderString().

◆ getLightContribution()

string PhongShader::getLightContribution ( X3DLightNode light,
unsigned int  index,
string  normal,
string  vertex,
string  shininess,
string  ambient_color,
string  diffuse_color,
string  specular_color 
)
protectedvirtual

Returns a string with glsl code that adds the color contribution of a light node to the variable "final_color".

Parameters
lightThe light node for which to calculate the contributtion. If NULL, headlight is used.
indexThe OpenGL light index for the light.
normalThe glsl variable name in the shader for the normal.
vertexThe glsl variable name in the shader for the vertex.
shininessThe glsl variable name in the shader for the shininess.
ambient_colorThe glsl variable name in the shader for the ambient_color.
diffuse_colorThe glsl variable name in the shader for the diffuse_color.
specular_colorThe glsl variable name in the shader for the specular_color.

References uniqueLightFieldName(), and H3D::H3DGeneratedShaderNode::uniqueShaderName().

Referenced by getFragmentShaderString().

◆ setupLight()

string PhongShader::setupLight ( X3DLightNode light,
unsigned int  gl_index 
)
protectedvirtual

Returns a string with glsl code that sets adds and initialized a variable of type gl_LightParameters and name light to the values of the light source.

Parameters
lightThe light to generate glsl code for.
gl_indexThe OpenGL light index for the light.

References H3D::SpotLight::beamWidth, H3D::SpotLight::cutOffAngle, H3D::GraphicsHardwareInfo::getInfo(), H3D::GraphicsHardwareInfo::infoIsInitialized(), and uniqueLightFieldName().

Referenced by getFragmentShaderString().

Member Data Documentation

◆ ambientMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::ambientMap

Defines the Ma part in the Phong illumination model specified above.

If NULL Ma = Material_ambientIntensity * Material_diffuseColor If non-NULL and modulateMaps FALSE Ma = texture color If non-NULL and modulateMaps TRUE Ma = Material_ambientIntensity * texture color

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseAmbientColor(), PhongShader(), and traverseSG().

◆ backAmbientMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::backAmbientMap

Defines the Ma part in the Phong illumination model specified above for back facing polygons.

Only used if separateBackColor is TRUE.

If NULL Ma = Material_ambientIntensity * Material_diffuseColor If non-NULL and modulateMaps FALSE Ma = texture color If non-NULL and modulateMaps TRUE Ma = Material_ambientIntensity * texture color

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseAmbientColor(), and PhongShader().

◆ backDiffuseColorRamp

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::backDiffuseColorRamp

The diffuseColorRamp can be used to control the diffuse color gradient across a material for back facing polygons.

It contains a 1D texture that defines the color ramp and the value used for lookup is controlled by the diffuseColorRampMode field. The looked up color is then multiplied with the diffuse to generate the final diffuse color used in the lighting equations. This allows for different colors depending on the view angle to the surface.

Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getFragmentShaderString(), and PhongShader().

◆ backDiffuseColorRampMode

H3DUniquePtr< SFString > H3D::PhongShader::backDiffuseColorRampMode

The backDiffuseColorRampMode defines what value should be used to lookup up into the backDiffuseColorRamp texture.

Valid values are:

  • "LIGHT" - light direction dot normal
  • "CAMERA" - camera direction dot normal

Access type: inputOutput
Default value: "LIGHT"
Valid values: "LIGHT", "CAMERA"

Referenced by getFragmentShaderString(), and PhongShader().

◆ backDiffuseMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::backDiffuseMap

Defines the Md part in the Phong illumination model specified above for back facing polygons.

Only used if separateBackColor is TRUE.

If NULL Md = Material_diffuseColor If non-NULL and modulateMaps FALSE Md = texture color If non-NULL and modulateMaps TRUE Md = Material_diffuseColor * texture color

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseDiffuseColor(), and PhongShader().

◆ backEmissionMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::backEmissionMap

Defines the Me part in the Phong illumination model specified above for back facing polygons.

Only used if separateBackColor is TRUE.

If NULL Me = Material_emissiveColor If non-NULL Me = texture color

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseEmissionColor(), and PhongShader().

◆ backFresnel

H3DUniquePtr< SFFloat > H3D::PhongShader::backFresnel

The backFresnel field specifies the fresnel value for back facing polygons when separateBackColor is TRUE.

Se fresnel field for more info.

Access type: inputOutput
Default value: 0

Referenced by addUniformFields(), getFragmentShaderString(), and PhongShader().

◆ backGlossMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::backGlossMap

Defines the Mshininess part in the Phong illumination model specified above for back facing polygons.

Only used if separateBackColor is TRUE.

If NULL Mshininess = Material_shininess If non-NULL and modulateMaps FALSE Mshininess = texture color.r If non-NULL and modulateMaps TRUE Mshininess = Material_shininess * texture color.r

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseShininess(), and PhongShader().

◆ backModulateMaps

H3DUniquePtr< SFBool > H3D::PhongShader::backModulateMaps

The modulateMaps field determines if the map values should be modulated with the corresponding Material value or not.

See documentation for the map fields for each component for details(diffuseMap, emissiveMap, etc). Only used if separateBackColor is TRUE

Access type: inputOutput
Default value: false

Referenced by getBaseAmbientColor(), getBaseDiffuseColor(), getBaseEmissionColor(), getBaseShininess(), getBaseSpecularColor(), and PhongShader().

◆ backNormalMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::backNormalMap

Defines the normal(N) in the Phong illumination model specified above for back facing polygons.

Only used if separateBackColor is TRUE.

If NULL N = normal of the OpenGL primitive If non-NULL N = normalMapMatrix * texture color

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseNormal(), PhongShader(), and traverseSG().

◆ backNormalMapCoordSpace

H3DUniquePtr< SFString > H3D::PhongShader::backNormalMapCoordSpace

The normalMapCoordSpace field defines which coordinate space the normals in the normalMap are specified in.

Only used if separateBackColor is TRUE

Valid values are:

  • "OBJECT" - the normals are in the coordinate space of the object. This means that the normals will be correct as long as the object does not change the local position of its vertices.
  • "TANGENT" - the normals are specified in the coordinate space with the normal as z-axis and ... Not supported yet..

Access type: inputOutput
Default value: "OBJECT" Valid values: "OBJECT", "TANGENT"

Referenced by PhongShader(), and traverseSG().

◆ backNormalMapMatrix

H3DUniquePtr< SFMatrix4f > H3D::PhongShader::backNormalMapMatrix

Defines the transformation from RGB values of the normalMap(in range [0,1]) to the actual normals in range[-1,1].

Only used if separateBackColor is TRUE Access type: inputOutput
Default value: [ 2 0 0 -1
0 2 0 -1
0 0 2 -1
0 0 0 1 ]

Referenced by addUniformFields(), and PhongShader().

◆ backSpecularColorRamp

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::backSpecularColorRamp

The specularColorRamp can be used to control the specular color gradient across a material for back facing polygons.

It contains a 1D texture that defines the color ramp and the value used for lookup is controlled by the specularColorRampMode field. The looked up color is then multiplied with the specular to generate the final specular color used in the lighting equations. This allows for different colors depending on the view angle to the surface.

Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getFragmentShaderString(), and PhongShader().

◆ backSpecularColorRampMode

H3DUniquePtr< SFString > H3D::PhongShader::backSpecularColorRampMode

The backSpecularColorRampMode defines what value should be used to lookup up into the backSpecularColorRamp texture.

Valid values are:

  • "LIGHT" - light direction dot normal
  • "CAMERA" - camera direction dot normal

Access type: inputOutput
Default value: "LIGHT"
Valid values: "LIGHT", "CAMERA"

Referenced by getFragmentShaderString(), and PhongShader().

◆ backSpecularMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::backSpecularMap

Defines the Ms part in the Phong illumination model specified above for back facing polygons.

Only used if separateBackColor is TRUE.

If NULL Ms = Material_specularColor If non-NULL and modulateMaps FALSE Ms = texture color If non-NULL and modulateMaps TRUE Ms = Material_specularColor * texture color

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseSpecularColor(), and PhongShader().

◆ current_light_node_transforms

AutoPtrVector< SFMatrix4f > H3D::PhongShader::current_light_node_transforms
protected

The transform matrices for all lights with index > maximum number lightsources supported by OpenGL fixed functionallity.

Index 0 in this vector matches index max_gl_lights in current light nodes.

Referenced by addUniformFieldsForLight(), and traverseSG().

◆ current_light_nodes

TraverseInfo::LightVector H3D::PhongShader::current_light_nodes
protected

The X3DLightNode instances that this shader is built for.

The ligts are ordered in the same order as the gl light index they use.

Referenced by addUniformFields(), getFragmentShaderString(), and traverseSG().

◆ diffuseColorRamp

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::diffuseColorRamp

The diffuseColorRamp can be used to control the diffuse color gradient across a material.

It contains a 1D texture that defines the color ramp and the value used for lookup is controlled by the diffuseColorRampMode field. The looked up color is then multiplied with the diffuse to generate the final diffuse color used in the lighting equations. This allows for different colors depending on the view angle to the surface.

Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getFragmentShaderString(), and PhongShader().

◆ diffuseColorRampMode

H3DUniquePtr< SFString > H3D::PhongShader::diffuseColorRampMode

The diffuseColorRampMode defines what value should be used to lookup up into the diffuseColorRamp texture.

Valid values are:

  • "LIGHT" - light direction dot normal
  • "CAMERA" - camera direction dot normal

Access type: inputOutput
Default value: "LIGHT"
Valid values: "LIGHT", "CAMERA"

Referenced by getFragmentShaderString(), and PhongShader().

◆ diffuseMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::diffuseMap

Defines the Md part in the Phong illumination model specified above.

If NULL Md = Material_diffuseColor If non-NULL and modulateMaps FALSE Md = texture color If non-NULL and modulateMaps TRUE Md = Material_diffuseColor * texture color

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseDiffuseColor(), and PhongShader().

◆ emissionMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::emissionMap

Defines the Me part in the Phong illumination model specified above.

If NULL Me = Material_emissiveColor If non-NULL Me = texture color

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseEmissionColor(), and PhongShader().

◆ fresnel

H3DUniquePtr< SFFloat > H3D::PhongShader::fresnel

The fresnel field specifies if the fresnel effect should be used in the lighting model and if so how much.

The fresnel effect is the effect that surfaces reflect more light if looking at them from an angle than straight down along the normal. If set to 0 no fresnel effect is used and the surface is fully reflective. If set to 1 only the reflectivity of the fresnel effect is used, which means no reflectivity when looking down perpendicular to the surace. One can think of the term as controlling the minimum reflectivness of the surface. By default it is set to 0 and no fresnel effect is used. The fresnel value only affects the specular component of the Phong lighting calculations since this is the only part that deals with reflective properties.

Access type: inputOutput
Default value: 0

Referenced by addUniformFields(), getFragmentShaderString(), and PhongShader().

◆ glossMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::glossMap

Defines the Mshininess part in the Phong illumination model specified above.

If NULL Mshininess = Material_shininess If non-NULL and modulateMaps FALSE Mshininess = texture color.r If non-NULL and modulateMaps TRUE Mshininess = Material_shininess * texture color.r

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseShininess(), and PhongShader().

◆ model

H3DUniquePtr< SFString > H3D::PhongShader::model

The shading model to use.

Available values: "BLINN-PHONG" - modified Phong model using half-vector instead of reflection vector. "BLINN-PHONG-EYEATINF" - same as "BLINN-PHONG" with the difference that the eye is assumed to be at infinity. "PHONG" - normal phong shading using reflection vector.

Access type: inputOutput
Default value: "BLINN-PHONG"
Valid values: "PHONG"

Referenced by getFunctionShaderString(), and PhongShader().

◆ modulateMaps

H3DUniquePtr< SFBool > H3D::PhongShader::modulateMaps

The modulateMaps field determines if the map values should be modulated with the corresponding Material value or not.

See documentation for the map fields for each component for details(diffuseMap, emissiveMap, etc)

Access type: inputOutput
Default value: false

Referenced by getBaseAmbientColor(), getBaseDiffuseColor(), getBaseEmissionColor(), getBaseShininess(), getBaseSpecularColor(), and PhongShader().

◆ normalMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::normalMap

Defines the normal(N) in the Phong illumination model specified above.

If NULL N = normal of the OpenGL primitive If non-NULL N = normalMapMatrix * texture color

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getAttributes(), getBaseNormal(), getVaryingVariables(), PhongShader(), and traverseSG().

◆ normalMapCoordSpace

H3DUniquePtr< SFString > H3D::PhongShader::normalMapCoordSpace

The normalMapCoordSpace field defines which coordinate space the normals in the normalMap are specified in.

Valid values are:

  • "OBJECT" - the normals are in the coordinate space of the object. This means that the normals will be correct as long as the object does not change the local position of its vertices.
  • "TANGENT" - the normals are specified in the coordinate space with the normal as z-axis and ... Not supported yet..

Access type: inputOutput
Default value: "OBJECT" Valid values: "OBJECT", "TANGENT"

Referenced by getAttributes(), getBaseNormal(), getVaryingVariables(), PhongShader(), and traverseSG().

◆ normalMapMatrix

H3DUniquePtr< SFMatrix4f > H3D::PhongShader::normalMapMatrix

Defines the transformation from RGB values of the normalMap(in range [0,1]) to the actual normals in range[-1,1].

Access type: inputOutput
Default value: [ 2 0 0 -1
0 2 0 -1
0 0 2 -1
0 0 0 1 ]

Referenced by addUniformFields(), and PhongShader().

◆ separateBackColor

H3DUniquePtr< SFBool > H3D::PhongShader::separateBackColor

If the separateBackColor field is set to TRUE, then the rendering shall render the front and back faces of the geometry with different values using the backDiffuseMap, backSpecularMap, etc.

fields for its values. If the value is FALSE, then the front colours are used for both the front and back side of the polygon.

Access type: inputOutput
Default value: false

Referenced by addUniformFields(), getBaseAmbientColor(), getBaseDiffuseColor(), getBaseEmissionColor(), getBaseNormal(), getBaseShininess(), getBaseSpecularColor(), getFragmentShaderString(), and PhongShader().

◆ specularColorRamp

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::specularColorRamp

The specularColorRamp can be used to control the specular color gradient across a material.

It contains a 1D texture that defines the color ramp and the value used for lookup is controlled by the diffuseColorRampMode field. The looked up color is then multiplied with the specular to generate the final specular color used in the lighting equations. This allows for different colors depending on the view angle to the surface.

Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getFragmentShaderString(), and PhongShader().

◆ specularColorRampMode

H3DUniquePtr< SFString > H3D::PhongShader::specularColorRampMode

The specularColorRampMode defines what value should be used to lookup up into the specularColorRamp texture.

Valid values are:

  • "LIGHT" - light direction dot normal
  • "CAMERA" - camera direction dot normal

Access type: inputOutput
Default value: "LIGHT"
Valid values: "LIGHT", "CAMERA"

Referenced by getFragmentShaderString(), and PhongShader().

◆ specularMap

H3DUniquePtr< SFTexture2DNode > H3D::PhongShader::specularMap

Defines the Ms part in the Phong illumination model specified above.

If NULL Ms = Material_specularColor If non-NULL and modulateMaps FALSE Ms = texture color If non-NULL and modulateMaps TRUE Ms = Material_specularColor * texture color

The multiplications above are componentwise multiplication. Access type: inputOutput
Default value: NULL

Referenced by addUniformFields(), getBaseSpecularColor(), and PhongShader().


The documentation for this class was generated from the following files: