H3D API
2.4.1
|
The H3DGeneratedShaderNode node is the base class for nodes that generates GLSL shaders for use in place of a ComposedShader in the Appearance field. More...
#include <H3D/H3DGeneratedShaderNode.h>
Classes | |
struct | Attribute |
Struct used to define an attribute in the shader. More... | |
struct | RebuildShader |
Specialized field that rebuilds the shader when it updates. More... | |
struct | VaryingVariable |
Struct used to define a varying variable in the shader. More... | |
Public Member Functions | |
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 | addUniformFields (ComposedShader *shader) |
Adds uniform fields 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 > &) |
Get the varying variables used by the shader generator. More... | |
virtual void | getAttributes (vector< Attribute > &) |
Get the attribues used by the shader generator. More... | |
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 | getFragmentShaderString () |
Returns the shader code for the fragment 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 | traverseSG (TraverseInfo &ti) |
Traverse the node. More... | |
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. | |
Static Public Member Functions | |
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. | |
Public Attributes | |
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 bool | use_bindless_textures = false |
True if we should use bindless textures. | |
Additional Inherited Members | |
![]() | |
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. | |
![]() | |
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... | |
![]() | |
static Node * | getClonedInstance (Node *original, bool deepCopy, DeepCopyMap &deepCopyMap) |
A helper function for nodes that implement clone() More... | |
![]() | |
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. | |
![]() | |
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 H3DGeneratedShaderNode node is the base class for nodes that generates GLSL shaders for use in place of a ComposedShader in the Appearance field.
The generated strings for vertex and fragment shader can be found in the fragmentShaderString and vertexShaderString fields.
Node developer info: H3DGeneratedShaderNode sub-classes generate a fragment and a vertex shader string based on its field values. All sub-classes have to implement the appropriate virtual functions in order to add what it wants to the shader. The shader strings are build in the buildShader function. This basically builds a vertex and fragment shader based on virtual function calls that are implemented in sub-classes. The virtual functions that build the shader are:
addUniformFields(), getAttributes(), getVaryingVariables().
These function add the uniform variables, attributes and varying variables needed by the shader generator. Each sub-class should implement these to add the needed variables.
getVertexShaderString(), getFragmentShaderString(), getFinalFragmentShaderOutputString(), and getFunctionShaderString() build up the main body of code of the shaders.
The structure of the generated vertex shader is:
The structure of the generated fragment shader is:
See the documentation for each function for more info.
Note: When setting names for uniform and varying variables it is important that they are unique for each node that generates them so that there is no name clashing if several nodes are combined into on shader. In order to facilitate this one can use the function uniqueShaderName( base_name ) that provides such a name. This name should then be used throughout the generated code. Local variables in generated shader code are ok since the calls are encapsulated with {} in its own space.
|
virtual |
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.
The function does two things for each uniform variable.
shader | The ComposedShader node to add the fields to. |
Reimplemented in H3D::PhongShader, H3D::EnvironmentMapShader, H3D::ConvolutionFilterShader, H3D::ShaderCombiner, H3D::MultiRenderTargetShader, and H3D::ComposedGeneratedShader.
Referenced by H3D::ComposedGeneratedShader::addUniformFields(), H3D::MultiRenderTargetShader::addUniformFields(), H3D::ShaderCombiner::addUniformFields(), and buildShader().
|
static |
Convenience function to add field in addUniformFields function to add uniform to fragment shader.
shader | The ComposedShader to add the field to. |
name | The name of the field. |
glsl_type | The glsl type of the field(int, mat3, sampler2D etc). |
access | The access type of the field. |
field | The field to add to the shader. |
array_size | If != -1 it assumes that the uniform is an array with this size, if not it just a normal variable. |
delete_unadded_field | If true and the function failed to add the field to the fragment shader ( if for example a field of the same name is already added ) then the field is deleted. |
Referenced by H3D::ShaderCombiner::addUniformFields(), H3D::ConvolutionFilterShader::addUniformFields(), H3D::EnvironmentMapShader::addUniformFields(), H3D::PhongShader::addUniformFields(), and H3D::PhongShader::addUniformFieldsForLight().
|
inlinevirtual |
Get the attribues used by the shader generator.
Should be implemented by subclasses to add all the varying variables that are needed by the shader generator.
Reimplemented in H3D::ShaderCombiner, H3D::PhongShader, H3D::MultiRenderTargetShader, and H3D::ComposedGeneratedShader.
Referenced by buildShader(), H3D::ComposedGeneratedShader::getAttributes(), H3D::MultiRenderTargetShader::getAttributes(), and H3D::ShaderCombiner::getAttributes().
|
virtual |
Returns the string that is the last thing that is done in the fragment shader.
Usually this transfers the value of generated_color to gl_FragColor but can be changed by sub-classes to go to e.g. gl_FragData by overriding this function.
Reimplemented in H3D::MultiRenderTargetShader.
Referenced by buildShader().
|
inlinevirtual |
Returns the shader code for the fragment shader.
The job of this string is to set the variable generated_color to the fragment color generated by the node. This function should be implemented by subclasses that want to change the output of the fragment shader.
Reimplemented in H3D::ShaderCombiner, H3D::PhongShader, H3D::NormalShader, H3D::MultiRenderTargetShader, H3D::EnvironmentMapShader, H3D::ConvolutionFilterShader, and H3D::ComposedGeneratedShader.
Referenced by buildShader(), H3D::ComposedGeneratedShader::getFragmentShaderString(), H3D::MultiRenderTargetShader::getFragmentShaderString(), and H3D::ShaderCombiner::getFragmentShaderString().
|
inlinevirtual |
Get the varying variables used by the shader generator.
Should be implemented by subclasses to add all the varying variables that are needed by the shader generator.
Reimplemented in H3D::ShaderCombiner, H3D::PhongShader, H3D::NormalShader, H3D::MultiRenderTargetShader, H3D::EnvironmentMapShader, and H3D::ComposedGeneratedShader.
Referenced by buildShader(), H3D::ComposedGeneratedShader::getVaryingVariables(), H3D::MultiRenderTargetShader::getVaryingVariables(), and H3D::ShaderCombiner::getVaryingVariables().
|
virtual |
Returns the shader code for the vertex shader.
The job of this string is to possibly change to values of the default calculation of e.g. gl_Position before calculating the value of the varying variables. Can be used to e.g. do deformations etc.
Reimplemented in H3D::ShaderCombiner, H3D::NormalShader, H3D::MultiRenderTargetShader, and H3D::ComposedGeneratedShader.
Referenced by buildShader(), H3D::ComposedGeneratedShader::getVertexShaderString(), H3D::MultiRenderTargetShader::getVertexShaderString(), H3D::NormalShader::getVertexShaderString(), and H3D::ShaderCombiner::getVertexShaderString().
|
virtual |
The uniqueShaderName function is used to generate a name unique for this instance of the shader generator node class.
This should to generate names for all uniform and varying variables used in the node in order to avoid name clashes between other nodes or multiple instances of the same node type.
base_name | The original name of a variable. |
References H3DUtil::RefCountedClass::getTypeName().
Referenced by H3D::ShaderCombiner::addUniformFields(), H3D::ConvolutionFilterShader::addUniformFields(), H3D::EnvironmentMapShader::addUniformFields(), H3D::PhongShader::addUniformFields(), H3D::PhongShader::getBaseAmbientColor(), H3D::PhongShader::getBaseDiffuseColor(), H3D::PhongShader::getBaseEmissionColor(), H3D::PhongShader::getBaseNormal(), H3D::PhongShader::getBaseShininess(), H3D::PhongShader::getBaseSpecularColor(), H3D::ConvolutionFilterShader::getFragmentShaderString(), H3D::EnvironmentMapShader::getFragmentShaderString(), H3D::NormalShader::getFragmentShaderString(), H3D::PhongShader::getFragmentShaderString(), H3D::ShaderCombiner::getFragmentShaderString(), H3D::PhongShader::getFunctionShaderString(), H3D::PhongShader::getLightContribution(), H3D::EnvironmentMapShader::getVaryingVariables(), H3D::NormalShader::getVaryingVariables(), H3D::PhongShader::getVaryingVariables(), and H3D::PhongShader::uniqueLightFieldName().
H3DUniquePtr< MFString > H3D::H3DGeneratedShaderNode::fragmentShaderString |
Contains the generated fragment shader code.
Access type: outputOnly
Referenced by buildShader(), H3DGeneratedShaderNode(), and preRender().
H3DUniquePtr< RebuildShader > H3D::H3DGeneratedShaderNode::rebuildShader |
Field used to update the shader code when an event is received.
Every field that should cause the shaders to be rebuild needs to be routed to this field.
Referenced by H3D::ComposedGeneratedShader::ComposedGeneratedShader(), H3D::ConvolutionFilterShader::ConvolutionFilterShader(), H3D::EnvironmentMapShader::EnvironmentMapShader(), H3DGeneratedShaderNode(), H3D::MultiRenderTargetShader::MultiRenderTargetShader(), H3D::PhongShader::PhongShader(), preRender(), and H3D::ShaderCombiner::ShaderCombiner().
H3DUniquePtr< MFString > H3D::H3DGeneratedShaderNode::vertexShaderString |
Contains the generated vertex shader code.
Access type: outputOnly
Referenced by buildShader(), and H3DGeneratedShaderNode().