.TH "SoShaderProgram" 3 "Thu May 29 2014" "Version 4.0.0a" "Coin" \" -*- nroff -*- .ad l .nh .SH NAME SoShaderProgram \- .PP The \fBSoShaderProgram\fP class is used to specify a set of vertex/geometry/fragment objects\&. .SH SYNOPSIS .br .PP .PP \fC#include \fP .PP Inherits \fBSoNode\fP\&. .SS "Public Member Functions" .in +1c .ti -1c .RI "virtual \fBSoType\fP \fBgetTypeId\fP (void) const " .br .RI "\fIReturns the type identification of an object derived from a class inheriting \fBSoBase\fP\&. This is used for run-time type checking and 'downward' casting\&. \fP" .ti -1c .RI "\fBSoShaderProgram\fP (void)" .br .ti -1c .RI "void \fBsetEnableCallback\fP (SoShaderProgramEnableCB *cb, void *closure)" .br .ti -1c .RI "virtual void \fBGLRender\fP (\fBSoGLRenderAction\fP *action)" .br .ti -1c .RI "virtual void \fBsearch\fP (\fBSoSearchAction\fP *action)" .br .in -1c .SS "Static Public Member Functions" .in +1c .ti -1c .RI "static \fBSoType\fP \fBgetClassTypeId\fP (void)" .br .ti -1c .RI "static void \fBinitClass\fP ()" .br .in -1c .SS "Public Attributes" .in +1c .ti -1c .RI "\fBSoMFNode\fP \fBshaderObject\fP" .br .in -1c .SS "Protected Member Functions" .in +1c .ti -1c .RI "virtual const \fBSoFieldData\fP * \fBgetFieldData\fP (void) const " .br .ti -1c .RI "virtual \fB~SoShaderProgram\fP ()" .br .in -1c .SS "Static Protected Member Functions" .in +1c .ti -1c .RI "static const \fBSoFieldData\fP ** \fBgetFieldDataPtr\fP (void)" .br .in -1c .SS "Additional Inherited Members" .SH "Detailed Description" .PP The \fBSoShaderProgram\fP class is used to specify a set of vertex/geometry/fragment objects\&. This node can store one of each of \fBSoVertexShader\fP, \fBSoGeometryShader\fP and \fBSoFragmentShader\fP in its shaderObject field\&. Coin will load all shader objects specified there, and attach all objects into a program before binding it as the current shader program\&. .PP A typical scene graph with shaders will look something like this: .PP .PP .nf Separator { ShaderProgram { shaderObject [ VertexShader { sourceProgram "myvertexshader\&.glsl" parameter [ ShaderParameter1f { name "myvertexparam" value 1\&.0 } ] } FragmentShader { sourceProgram "myfragmentshader\&.glsl" parameter [ ShaderParameter1f { name "myfragmentparam" value 2\&.0 } ] } ] } Cube { } } .fi .PP .PP This will render the Cube with the vertex and fragment shaders specified in myvertexshader\&.glsl and myfragmentshader\&.glsl\&. Coin also supports ARB shaders and Cg shaders (if the Cg library is installed)\&. However, we recommend using GLSL since we will focus mostly on support this shader language\&. .PP Coin defines some named parameters that can be added by the application programmer, and which will be automatically updated by Coin while traversing the scene graph\&. .PP .PD 0 .IP "\(bu" 2 coin_texunit[n]_model - Set to 0 when texturing is disabled, and to SoTextureImageElement::Model if there's a current texture on the state for unit \fIn\fP\&. .PP .PD 0 .IP "\(bu" 2 coin_light_model - Set to 1 for PHONG, 0 for BASE_COLOR lighting\&. .PP Example scene graph that renders per-fragment OpenGL Phong lighting for one light source\&. The shaders assume the first light source is a directional light\&. This is the case if you open the file in a standard examiner viewer\&. .PP The iv-file: .PP .nf Separator { ShaderProgram { shaderObject [ VertexShader { sourceProgram "perpixel_vertex\&.glsl" } FragmentShader { sourceProgram "perpixel_fragment\&.glsl" } ] } Complexity { value 1\&.0 } Material { diffuseColor 1 0 0 specularColor 1 1 1 shininess 0\&.9 } Sphere { } Translation { translation 3 0 0 } Material { diffuseColor 0 1 0 specularColor 1 1 1 shininess 0\&.9 } Cone { } Translation { translation 3 0 0 } Material { diffuseColor 0\&.8 0\&.4 0\&.1 specularColor 1 1 1 shininess 0\&.9 } Cylinder { } } .fi .PP .PP The vertex shader (perpixel_vertex\&.glsl): .PP .nf varying vec3 ecPosition3; varying vec3 fragmentNormal; void main(void) { vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; ecPosition3 = ecPosition\&.xyz / ecPosition\&.w; fragmentNormal = normalize(gl_NormalMatrix * gl_Normal); gl_Position = ftransform(); gl_FrontColor = gl_Color; } .fi .PP .PP The fragment shader (perpixel_vertex\&.glsl): .PP .nf varying vec3 ecPosition3; varying vec3 fragmentNormal; void DirectionalLight(in int i, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular) { float nDotVP; // normal \&. light direction float nDotHV; // normal \&. light half vector float pf; // power factor nDotVP = max(0\&.0, dot(normal, normalize(vec3(gl_LightSource[i]\&.position)))); nDotHV = max(0\&.0, dot(normal, vec3(gl_LightSource[i]\&.halfVector))); if (nDotVP == 0\&.0) pf = 0\&.0; else pf = pow(nDotHV, gl_FrontMaterial\&.shininess); ambient += gl_LightSource[i]\&.ambient; diffuse += gl_LightSource[i]\&.diffuse * nDotVP; specular += gl_LightSource[i]\&.specular * pf; } void main(void) { vec3 eye = -normalize(ecPosition3); vec4 ambient = vec4(0\&.0); vec4 diffuse = vec4(0\&.0); vec4 specular = vec4(0\&.0); vec3 color; DirectionalLight(0, normalize(fragmentNormal), ambient, diffuse, specular); color = gl_FrontLightModelProduct\&.sceneColor\&.rgb + ambient\&.rgb * gl_FrontMaterial\&.ambient\&.rgb + diffuse\&.rgb * gl_Color\&.rgb + specular\&.rgb * gl_FrontMaterial\&.specular\&.rgb; gl_FragColor = vec4(color, gl_Color\&.a); } .fi .PP .PP \fBFILE FORMAT/DEFAULTS:\fP .PP .nf ShaderProgram { shaderObject [] } .fi .PP .PP \fBSee also:\fP .RS 4 \fBSoShaderObject\fP .PP \fBSoShaderProgram\fP .RE .PP \fBSince:\fP .RS 4 Coin 2\&.5 .RE .PP .SH "Constructor & Destructor Documentation" .PP .SS "SoShaderProgram::SoShaderProgram (void)" Constructor\&. .SS "SoShaderProgram::~SoShaderProgram ()\fC [protected]\fP, \fC [virtual]\fP" Destructor\&. .SH "Member Function Documentation" .PP .SS "\fBSoType\fP SoShaderProgram::getTypeId (void) const\fC [virtual]\fP" .PP Returns the type identification of an object derived from a class inheriting \fBSoBase\fP\&. This is used for run-time type checking and 'downward' casting\&. Usage example: .PP .PP .nf void foo(SoNode * node) { if (node->getTypeId() == SoFile::getClassTypeId()) { SoFile * filenode = (SoFile *)node; // safe downward cast, knows the type } } .fi .PP .PP For application programmers wanting to extend the library with new nodes, engines, nodekits, draggers or others: this method needs to be overridden in \fIall\fP subclasses\&. This is typically done as part of setting up the full type system for extension classes, which is usually accomplished by using the pre-defined macros available through for instance \fBInventor/nodes/SoSubNode\&.h\fP (SO_NODE_INIT_CLASS and SO_NODE_CONSTRUCTOR for node classes), Inventor/engines/SoSubEngine\&.h (for engine classes) and so on\&. .PP For more information on writing Coin extensions, see the class documentation of the toplevel superclasses for the various class groups\&. .PP Implements \fBSoBase\fP\&. .SS "const \fBSoFieldData\fP * SoShaderProgram::getFieldData (void) const\fC [protected]\fP, \fC [virtual]\fP" Returns a pointer to the class-wide field data storage object for this instance\&. If no fields are present, returns \fCNULL\fP\&. .PP Reimplemented from \fBSoFieldContainer\fP\&. .SS "void SoShaderProgram::setEnableCallback (SoShaderProgramEnableCB *cb, void *closure)" Adds a callback which is called every time this program is enabled/disabled\&. .SS "void SoShaderProgram::GLRender (\fBSoGLRenderAction\fP *action)\fC [virtual]\fP" Action method for the \fBSoGLRenderAction\fP\&. .PP This is called during rendering traversals\&. Nodes influencing the rendering state in any way or who wants to throw geometry primitives at OpenGL overrides this method\&. .PP Reimplemented from \fBSoNode\fP\&. .SS "void SoShaderProgram::search (\fBSoSearchAction\fP *action)\fC [virtual]\fP" Action method for \fBSoSearchAction\fP\&. .PP Compares the search criteria from the \fIaction\fP to see if this node is a match\&. Searching is done by matching up \fIall\fP criteria set up in the \fBSoSearchAction\fP -- if \fIany\fP of the requested criteria is a miss, the search is not deemed successful for the node\&. .PP \fBSee also:\fP .RS 4 \fBSoSearchAction\fP .RE .PP .PP Reimplemented from \fBSoNode\fP\&. .SH "Member Data Documentation" .PP .SS "\fBSoMFNode\fP SoShaderProgram::shaderObject" The shader objects\&. .SH "Author" .PP Generated automatically by Doxygen for Coin from the source code\&.