SoShaderPipelineLightModel

InventorModule
author MeVis Medical Solutions AG
package MeVisLab/Standard
dll SoShaderPipeline
definition SoShaderPipeline.def

Purpose

The SoShaderPipelineLightModel module allows for choosing and even replacing the lighting model that is used by the SoShaderPipeline.

All built-in lights (SoDirectionalLight, SoPointLight, SoShadowMapping, etc.) make use of the lighting model to apply shading to a surface.

The default lighting model of SoShaderPipeline is the BlinnPhong model.

Parameter Fields

Visible Fields

Enabled

name: enabled, type: Bool, default: TRUE

If checked, the lighting model is enabled.

Light Model

name: lightModel, type: Enum, default: BlinnPhong

Defines the used lighting model.

Values:

Title Name Description
Lambert Lambert Lambertian diffuse illumination without specular reflections.
Blinn Phong BlinnPhong Default BlinnPhong lighting, using the half-vector for specular reflections.
Phong Phong Phong lighting model, which calculates the reflection vector for specular highlights.
Custom Custom

A custom lighting model, the code is provided in Custom Light Model.

The lighting model needs to implement a function that is named so_Lighting and has the following signature:

vec3 so_Lighting(in State state, vec3 lightColor, vec3 lightDirection, vec3 viewDirection, float attenuation)

It needs to calculate the lighting added by the given light using the passed parameters.

As an example, the following code implements the Phong model:

vec3 so_Lighting(in State state, vec3 lightColor, vec3 lightDirection, vec3 viewDirection, float attenuation)
{
  vec3 R = normalize(-reflect(lightDirection,state.vertexEyeNormal));
  float nDotLight = so_LightingDot(state.vertexEyeNormal, lightDirection);
  float nDotHalf = so_LightingDot(viewDirection, R);
  vec3 result = lightColor * state.surfaceDiffuse * nDotLight;
  if (nDotLight != 0.0)
  {
    float powerFactor = pow(nDotHalf, state.surfaceShininess);
    result += lightColor.rgb * state.surfaceSpecular * powerFactor;
  }
  return result * attenuation;
}

Custom Light Model

name: customLightModel, type: String

Sets the custom lighting model code.

Create Custom Model

name: createCustomLightModel, type: Trigger

When pressed, the current lighting model is copied to the Custom Light Model and the custom model is enabled.