Palomino - Shaders

©2004,2009  Jim E. Brooks   http://www.palomino3d.org


Contents


Shaders

[2009/01]

Shader programs can be attached to any node (this exposes an OSG capability which may differ from other scene-graphs). ShaderFactory caches pre-compiled shader programs. Shaders are identified by a name ("default", "metallic", etc). By default, SceneGraph places nodes under a generic shader. Effects code can attach a shader to a different group node and pass it to SceneGraph::AttachBranchNode().


ShaderSettings

[2009/05]

This singleton provides a traditional OpenGL interface over shaders. The interface of ShaderSettings hides the specific uniform names.

ShaderSettings::SetLightPosition( lightNum, pos );
ShaderSettings::SetLightColors( lightNum, ambient, diffuse, specular );
ShaderSettings::SetFogDensity( lightNum, fogDensity );

Macros/Preprocessing

[2009/05]

A very simple macro preprocessor is implemented. Macro keywords are prefixed by @.

@include - load an include file

@include executes recursively to support nested include files.

@include funcs.glsl
void main()
{
}

Per-Model Shaders

[2009/05]

Lua scripts load 3D models. Optionally, Lua can pick a shader for a particular 3D model.

    nodeSort = NodeSort:new( { shader="metallic" } )
    sim.SceneGraph:AttachObjectSpecial( object, nodeSort )

Modifying Models for Shaders

[2009/05]

A few 3D models will need to be modified to render correctly with the shaders. Problems cases are transparent polygons such as canopy glass and exhaust flame.

Example of inserting a shader uniform:

StateSet {
...
  Uniform {
    DataVariance STATIC
    name "uni_glass"
    bool 1
  }
...
}

In some models, to insert a uniform, a new StateSet must be inserted into a Group:

Group {
  DataVariance STATIC
  name "ExternalFlame"
  nodeMask 0xffffffff
  cullingActive TRUE
  num_children 3
-- insert --
  StateSet {
    Uniform {
      DataVariance STATIC
      name "uni_alphaBias"
      float -0.5
    }
  }
-- insert --
...
}

When converting 3D models, osgconv should be run with export OSG_OPTIMIZER=OFF. This prevents conversion problems such as losing node names, distorted geometry, etc.


Hardware Light

[2009/05]

A few 3D models aren't compatible with any shader. Therefore, if ShaderName="hw", ShaderFactory will produce a group node with the hardware light instead of a shader. HwLight singleton defines the hardware light (simulates the sun).


Brightness

[2009/05]

Brightness is adjusted by:


Problems

[2009/05]

These 3D models weren't originally created for rendering by shaders. A major problem is transparent polygons. Some aircraft models specify cockpit glass in the alpha of the texture, others in the alpha of the RGBA color with textures disabled. Solution was to write different shaders for different models or inserting uniforms. A few models have proven virtual incompatible with shaders. These models are placed under a node with a hardware light instead of shaders.


Last modified: Thu May 14 18:12:06 CDT 2009