H3D API
2.4.1
|
The PhongShader node defines a shader for using the Phong illumination model. More...
#include <H3D/PhongShader.h>
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. | |
![]() | |
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. | |
![]() | |
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. | |
![]() | |
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. | |
![]() | |
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. | |
![]() | |
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. | |
![]() | |
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... | |
![]() | |
X3DAppearanceChildNode (Inst< DisplayList > _displayList=0, Inst< SFNode > _metadata=0) | |
Constructor. | |
![]() | |
X3DNode (Inst< SFNode > _metadata=0) | |
Constructor. | |
X3DMetadataObject * | getMetadataByName (const string &_name) |
Given a name, the first X3DMetadataObject in the metadata field that matches that name is returned. More... | |
![]() | |
Node () | |
Constructor. | |
virtual Node * | clone (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. | |
X3DPrototypeInstance * | getProtoInstanceParent () |
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 Field * | getField (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... | |
![]() | |
H3DDisplayListObject (Inst< DisplayList > _displayList=0) | |
Constructor. | |
![]() | |
X3DProgrammableShaderObject (H3DNodeDatabase *_database) | |
Constructor. | |
virtual void | clearFields () |
Remove all dynamic fields that have been previously added. | |
virtual | ~X3DProgrammableShaderObject () |
Destructor. | |
![]() | |
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< SFTexture2DNode > | ambientMap |
Defines the Ma part in the Phong illumination model specified above. More... | |
H3DUniquePtr< SFTexture2DNode > | diffuseMap |
Defines the Md part in the Phong illumination model specified above. More... | |
H3DUniquePtr< SFTexture2DNode > | emissionMap |
Defines the Me part in the Phong illumination model specified above. More... | |
H3DUniquePtr< SFTexture2DNode > | normalMap |
Defines the normal(N) in the Phong illumination model specified above. More... | |
H3DUniquePtr< SFMatrix4f > | normalMapMatrix |
Defines the transformation from RGB values of the normalMap(in range [0,1]) to the actual normals in range[-1,1]. More... | |
H3DUniquePtr< SFString > | normalMapCoordSpace |
The normalMapCoordSpace field defines which coordinate space the normals in the normalMap are specified in. More... | |
H3DUniquePtr< SFTexture2DNode > | specularMap |
Defines the Ms part in the Phong illumination model specified above. More... | |
H3DUniquePtr< SFTexture2DNode > | glossMap |
Defines the Mshininess part in the Phong illumination model specified above. More... | |
H3DUniquePtr< SFTexture2DNode > | diffuseColorRamp |
The diffuseColorRamp can be used to control the diffuse color gradient across a material. More... | |
H3DUniquePtr< SFString > | diffuseColorRampMode |
The diffuseColorRampMode defines what value should be used to lookup up into the diffuseColorRamp texture. More... | |
H3DUniquePtr< SFTexture2DNode > | specularColorRamp |
The specularColorRamp can be used to control the specular color gradient across a material. More... | |
H3DUniquePtr< SFString > | specularColorRampMode |
The specularColorRampMode defines what value should be used to lookup up into the specularColorRamp texture. More... | |
H3DUniquePtr< SFFloat > | fresnel |
The fresnel field specifies if the fresnel effect should be used in the lighting model and if so how much. More... | |
H3DUniquePtr< SFBool > | modulateMaps |
The modulateMaps field determines if the map values should be modulated with the corresponding Material value or not. More... | |
H3DUniquePtr< SFTexture2DNode > | backAmbientMap |
Defines the Ma part in the Phong illumination model specified above for back facing polygons. More... | |
H3DUniquePtr< SFTexture2DNode > | backDiffuseMap |
Defines the Md part in the Phong illumination model specified above for back facing polygons. More... | |
H3DUniquePtr< SFTexture2DNode > | backEmissionMap |
Defines the Me part in the Phong illumination model specified above for back facing polygons. More... | |
H3DUniquePtr< SFTexture2DNode > | backNormalMap |
Defines the normal(N) in the Phong illumination model specified above for back facing polygons. More... | |
H3DUniquePtr< SFMatrix4f > | backNormalMapMatrix |
Defines the transformation from RGB values of the normalMap(in range [0,1]) to the actual normals in range[-1,1]. More... | |
H3DUniquePtr< SFString > | backNormalMapCoordSpace |
The normalMapCoordSpace field defines which coordinate space the normals in the normalMap are specified in. More... | |
H3DUniquePtr< SFTexture2DNode > | backSpecularMap |
Defines the Ms part in the Phong illumination model specified above for back facing polygons. More... | |
H3DUniquePtr< SFTexture2DNode > | backGlossMap |
Defines the Mshininess part in the Phong illumination model specified above for back facing polygons. More... | |
H3DUniquePtr< SFTexture2DNode > | backDiffuseColorRamp |
The diffuseColorRamp can be used to control the diffuse color gradient across a material for back facing polygons. More... | |
H3DUniquePtr< SFString > | backDiffuseColorRampMode |
The backDiffuseColorRampMode defines what value should be used to lookup up into the backDiffuseColorRamp texture. More... | |
H3DUniquePtr< SFTexture2DNode > | backSpecularColorRamp |
The specularColorRamp can be used to control the specular color gradient across a material for back facing polygons. More... | |
H3DUniquePtr< SFString > | backSpecularColorRampMode |
The backSpecularColorRampMode defines what value should be used to lookup up into the backSpecularColorRamp texture. More... | |
H3DUniquePtr< SFFloat > | backFresnel |
The backFresnel field specifies the fresnel value for back facing polygons when separateBackColor is TRUE. More... | |
H3DUniquePtr< SFBool > | backModulateMaps |
The modulateMaps field determines if the map values should be modulated with the corresponding Material value or not. More... | |
H3DUniquePtr< SFBool > | 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. More... | |
H3DUniquePtr< SFString > | model |
The shading model to use. More... | |
![]() | |
H3DUniquePtr< MFString > | fragmentShaderString |
Contains the generated fragment shader code. More... | |
H3DUniquePtr< MFString > | vertexShaderString |
Contains the generated vertex shader code. More... | |
H3DUniquePtr< RebuildShader > | rebuildShader |
Field used to update the shader code when an event is received. More... | |
![]() | |
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< MFShaderPart > | parts |
The shader parts to use in the ComposedShader. More... | |
H3DUniquePtr< SFBool > | suppressUniformWarnings |
Suppress the warnings printed to the console about setting uniform fields that do not exist in the shader. More... | |
H3DUniquePtr< SFString > | geometryInputType |
The input geometry type of the geometry being rendered with a geometry shader. More... | |
H3DUniquePtr< SFString > | geometryOutputType |
The output geometry type of the geometry being rendered with a geometry shader. More... | |
H3DUniquePtr< SFInt32 > | geometryVerticesOut |
The number of vertices the geometry shader generates. More... | |
H3DUniquePtr< SFString > | transparencyDetectMode |
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< MFString > | transformFeedbackVaryings |
List of varying names to capture during transform feedback. More... | |
H3DUniquePtr< SFBool > | printShaderWarnings |
Always print shader warnings to console. More... | |
![]() | |
H3DUniquePtr< SFBool > | isSelected |
The isSelected output field is used to indicate that this shader instance is the one selected for use by the browser. More... | |
H3DUniquePtr< SFBool > | isValid |
The isValid field is used to indicate whether the current shader objects can be run as a shader program. More... | |
H3DUniquePtr< SFBool > | activate |
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< SFString > | language |
The language field is used to indicate to the browser which shading language is used for the source file(s). More... | |
![]() | |
H3DUniquePtr< SFNode > | metadata |
Meta data about the node. More... | |
![]() | |
H3DUniquePtr< DisplayList > | displayList |
The DisplayList instance handling the OpenGL caching of this object. | |
Static Public Attributes | |
static H3DNodeDatabase | database |
The H3DNodeDatabase for this node. | |
![]() | |
static H3DNodeDatabase | database |
The H3DNodeDatabase for this node. | |
![]() | |
static H3DNodeDatabase | database |
The H3DNodeDatabase for this node. | |
![]() | |
static H3DNodeDatabase | database |
The H3DNodeDatabase for this node. | |
![]() | |
static H3DNodeDatabase | database |
The H3DNodeDatabase for this node. | |
![]() | |
static H3DNodeDatabase | database |
The H3DNodeDatabase for this node. | |
![]() | |
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... | |
![]() | |
void | setGeometryShaderParameters (GLenum _program_handle) |
Sets geometry shader paramters based on fields. | |
![]() | |
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< SFMatrix4f > | current_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) | |
![]() | |
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< SetupDynamicRoutes > | setupDynamicRoutes |
C++ fields only. Contains instance of SetupDynamicRoutes. | |
list< H3DSingleTextureNode * > | shader_textures |
list of textures to be used by the composedshader | |
H3DUniquePtr< UpdateUniforms > | updateUniforms |
A field used to update any uniforms from their corresponding fields. | |
Additional Inherited Members | |
![]() | |
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 X3DShaderNode * | getActiveShader () |
Gets the currently active shader, i.e. More... | |
![]() | |
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 Node * | getClonedInstance (Node *original, bool deepCopy, DeepCopyMap &deepCopyMap) |
A helper function for nodes that implement clone() More... | |
![]() | |
static bool | tessellation_support_checked = false |
True if a warning has already been output about missing tessellation shader support. | |
![]() | |
static bool | use_bindless_textures_set = false |
True if use_bindless_textures has already be set once. | |
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:
|
protectedvirtual |
Adds uniform fields to the shader.
A ComposedShader uses its dynamic fields to define uniform variables. Hence we need to add dynamic fields for each field that we want to be accessable in the shader.
Reimplemented from H3D::H3DGeneratedShaderNode.
References addUniformFieldsForLight(), H3D::H3DGeneratedShaderNode::addUniformToFragmentShader(), ambientMap, backAmbientMap, backDiffuseColorRamp, backDiffuseMap, backEmissionMap, backFresnel, backGlossMap, backNormalMap, backNormalMapMatrix, backSpecularColorRamp, backSpecularMap, current_light_nodes, current_nr_lightsources, diffuseColorRamp, diffuseMap, emissionMap, fresnel, glossMap, H3D::Field::INPUT_OUTPUT, normalMap, normalMapMatrix, separateBackColor, specularColorRamp, specularMap, and H3D::H3DGeneratedShaderNode::uniqueShaderName().
|
protectedvirtual |
Adds uniform fields needed for a light to the shader.
shader | The shader to add the uniform to. |
light | The light for which to a uniforms. |
gl_index | The 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().
|
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().
|
protectedvirtual |
Returns a string with glsl code that adds the color contribution of a light node to the variable "final_color".
light | The light node for which to calculate the contributtion. If NULL, headlight is used. |
index | The OpenGL light index for the light. |
normal | The glsl variable name in the shader for the normal. |
vertex | The glsl variable name in the shader for the vertex. |
shininess | The glsl variable name in the shader for the shininess. |
ambient_color | The glsl variable name in the shader for the ambient_color. |
diffuse_color | The glsl variable name in the shader for the diffuse_color. |
specular_color | The glsl variable name in the shader for the specular_color. |
References uniqueLightFieldName(), and H3D::H3DGeneratedShaderNode::uniqueShaderName().
Referenced by getFragmentShaderString().
|
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.
light | The light to generate glsl code for. |
gl_index | The OpenGL light index for the light. |
References H3D::SpotLight::beamWidth, H3D::SpotLight::cutOffAngle, H3D::GraphicsHardwareInfo::getInfo(), H3D::GraphicsHardwareInfo::infoIsInitialized(), and uniqueLightFieldName().
Referenced by getFragmentShaderString().
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().
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().
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().
H3DUniquePtr< SFString > H3D::PhongShader::backDiffuseColorRampMode |
The backDiffuseColorRampMode defines what value should be used to lookup up into the backDiffuseColorRamp texture.
Valid values are:
Access type: inputOutput
Default value: "LIGHT"
Valid values: "LIGHT", "CAMERA"
Referenced by getFragmentShaderString(), and PhongShader().
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().
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().
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().
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().
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().
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().
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:
Access type: inputOutput
Default value: "OBJECT" Valid values: "OBJECT", "TANGENT"
Referenced by PhongShader(), and traverseSG().
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().
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().
H3DUniquePtr< SFString > H3D::PhongShader::backSpecularColorRampMode |
The backSpecularColorRampMode defines what value should be used to lookup up into the backSpecularColorRamp texture.
Valid values are:
Access type: inputOutput
Default value: "LIGHT"
Valid values: "LIGHT", "CAMERA"
Referenced by getFragmentShaderString(), and PhongShader().
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().
|
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().
|
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().
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().
H3DUniquePtr< SFString > H3D::PhongShader::diffuseColorRampMode |
The diffuseColorRampMode defines what value should be used to lookup up into the diffuseColorRamp texture.
Valid values are:
Access type: inputOutput
Default value: "LIGHT"
Valid values: "LIGHT", "CAMERA"
Referenced by getFragmentShaderString(), and PhongShader().
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().
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().
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().
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().
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().
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().
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().
H3DUniquePtr< SFString > H3D::PhongShader::normalMapCoordSpace |
The normalMapCoordSpace field defines which coordinate space the normals in the normalMap are specified in.
Valid values are:
Access type: inputOutput
Default value: "OBJECT" Valid values: "OBJECT", "TANGENT"
Referenced by getAttributes(), getBaseNormal(), getVaryingVariables(), PhongShader(), and traverseSG().
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().
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().
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().
H3DUniquePtr< SFString > H3D::PhongShader::specularColorRampMode |
The specularColorRampMode defines what value should be used to lookup up into the specularColorRamp texture.
Valid values are:
Access type: inputOutput
Default value: "LIGHT"
Valid values: "LIGHT", "CAMERA"
Referenced by getFragmentShaderString(), and PhongShader().
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().