21.5 Shader API
It is recommended in the fragment shader to use depth-peeling helper functions to test fragment coordinates and output fragment color. These functions are avaible whatever the type of transparency is. It is mandatory to use these functions if you want to benefit from advanced Open Inventor features such as order independant transparency.
You must add the appropriated header file at the beginning of the fragment shader file to use these functions such as:
When using multi-pass order independant transparency, a fragment can be unsignificant for a given pass and significant for the next one. In order to know if the current fragment is relevant for the current pass, the following function should be used such as:
with fragmentCoords the fragment coordinates in screen space (e.g. gl_FragCoord.xyz should be used most of the time). This method returns true if the fragment is significant, false otherwise.
To output the fragment color, the following function must be used:
with color, the color of the fragment.
When using instancing capabilities in Open Inventor (see SoMultipleInstance), functions are defined to query instance parameters. You must add the appropriated header file at the beginning of the vertex shader file to use these functions such as:
Instancing helper functions are:
returns the current instanceID.
returns the translation vector of the current geometry instance.
returns the scale vector of the current geometry instance.
returns the rotation (i.e. a quaternion) of the current geometry instance.
returns the model matrix to apply to the current geometry instance (i.e. the composition of rotation, translation and scale transformations).
returns the model matrix to apply to the current geometry vertex. This matrix contains instance and local transformations.
returns the normal matrix to apply to the current geometry normal. This matrix takes into account instance and local transformations.
returns the normal matrix to apply to the current geometry normal, with precomputed model view matrix as parameter.
Algebraic shapes (see SoAlgebraicShape and derivated classes) provide a shader API to define types and helper functions. You must add the appropriated header file at the beginning of the shader file such as:
Types used by helper functions are:
and,
Helper functions are defined to compute intersection points such as:
to solve quadric of type a*x*x + b*x + c = 0 with coefficients *a, b and c packed in the 3D vector abc. It returns true if there are roots, stored in the roots vector. Note that it can be used in fragment shader only.
to test if a ray (i.e. parameter ray) intersects a plane defined by vector p such as xyz represents the orientation and w the distance from origin (i.e. the point p.w*p.xyz lies on the plane). It returns* true* is there is an intersection at t (i.e. the intersection point is ray.rs + t*ray.rd).
to get the color (i.e. from material or vertex color) of the shape.
to get the opacity (i.e. alpha component) of the shape.
to ask if the shape is opaque (i.e. OivASGetOpacity() == 1.0).