SoFixedFunctionShader¶
-
InventorModule
¶ author MeVis Medical Solutions AG
package MeVisLab/Standard
dll SoFixedFunctionShader
definition SoFixedFunctionShader.def
Purpose¶
The SoFixedFunctionShader
generates a SoVertexShader
and SoFragmentShader
which implement the OpenGL fixed function pipeline as defined by the Open Inventor state. It thus supports the lighting, texture, fog and clip plane settings as given by the appropriate Open Inventor nodes. It supports SoDirectionalLight
, SoSpotLight
and SoPointLight
lights.
In addition to the fixed function pipeline it offers per-pixel lighting via Per Pixel Lighting
.
The module supports a simple mechanism to extend the generated shaders with user code via the userShaderCode
field.
This allows to add code blocks to a number of places in the shader. Each code block starts with an ‘@’ character and
the name of the block. The code following this block declaration is inserted into the corresponding place in the shader.
Available blocks are:
- @vertexShaderHeader
- @vertexShaderMain
- @vertexShaderMainEnd
- @fragmentShaderHeader
- @fragmentShaderMain
- @fragmentShaderMainEnd
Example user shader code:
@vertexShaderHeader
// Add vertex shader declarations here
attribute vec4 myVertexAttribute;
varying vec4 myVarying;
@vertexShaderMain
// Make attribute available to fragment shader
myVarying = myVertexAttribute;
@fragmentShaderHeader
// Add fragment shader declarations here
uniform float myUniform;
varying vec4 myVarying;
@fragmentShaderMain
// Modify the current color with our varying
color *= myVarying;
@fragmentShaderMainEnd
// Replace the color's alpha with our uniform
color.a = myUniform;
In addition to the above blocks, the following generated functions can be replaced:
- @directionalLight
- @pointLight
- @spotLight
- @infiniteSpotLight
- @sphereMap
- @reflectionMap
- @fixed_lighting
- @fixed_normal
- @fixed_fog
- @fixed_texgen
The replacement is done as follows:
@pointLight
// replacement code for pointLight:
LightResult pointLight(in int i, in vec3 normal, in vec3 eye, in vec3 ecPosition3)
{
float nDotVP; // normal . light direction
float nDotHV; // normal . light half vector
float pf; // power factor
float attenuation; // computed attenuation factor
float d; // distance from surface to light source
vec3 VP; // direction from surface to light position
vec3 halfVector; // direction of maximum highlights
// Compute vector from surface to light position
VP = vec3 (gl_LightSource[i].position) - ecPosition3;
// Compute distance between surface and light position
d = length(VP);
// Normalize the vector from surface to light position
VP = normalize(VP);
// Compute attenuation
attenuation = 1.0 / (gl_LightSource[i].constantAttenuation +
gl_LightSource[i].linearAttenuation * d +
gl_LightSource[i].quadraticAttenuation * d * d);
halfVector = normalize(VP + eye);
nDotVP = max(0.0, dot(normal, VP));
nDotHV = max(0.0, dot(normal, halfVector));
if (nDotVP == 0.0)
{
pf = 0.0;
}
else
{
pf = pow(nDotHV, gl_FrontMaterial.shininess);
}
return LightResult(gl_LightSource[i].ambient * attenuation,
gl_LightSource[i].diffuse * nDotVP * attenuation,
gl_LightSource[i].specular * pf * attenuation);
}
Usage¶
The module needs to be placed in front of a SoShaderProgram
. In only handles the Open Inventor state that is added before itself, so e.g. a SoPointLight
added after a SoFixedFunctionShader will not be handled by the generated shader.
Details¶
License of shader generator:
Copyright (C) 2002-2005 3Dlabs Inc. Ltd. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of 3Dlabs Inc. Ltd. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Parameter Fields¶
Field Index¶
fragmentShaderCode : String |
Per Pixel Lighting : Bool |
Use Lighting : Bool |
Use Texturing : Bool |
userShaderCode : String |
vertexShaderCode : String |
Visible Fields¶
Per Pixel Lighting¶
-
name:
perPixelLighting
, type:
Bool
, default:
TRUE
¶ Enables per-pixel light calculations. Disabling the flag will do the light calculations in the vertex shader as the classical OpenGL fixed function pipeline does.