Table of contents
This page deals with the ShOgre library which allows the Sh GPU metaprogramming language to be used as a shader language in Ogre. Note that it is currently alpha code, and needs testing.
What is ShOgre?
ShOgre is a library that provides glue code between the Sh GPU metaprogramming language and the Ogre rendering engine. Ogre can use most of the available high level shading languages like -GLSL, HLSL, Cg, so you might be wondering "Why another one?".
Well, the greatest advantage of Sh above those other languages is a that shader objects are completely built from C++. No other language has to be learnt. This also allows for the easy and automatic generation of different shader permutations for the amount and type of lights, the availability of hardware skinning and vertex blending, normal mapping and other material parameters. If desired, the syntax tree of the shader can be built and edited directly. Shader blocks can be conveniently combined and re-used using shader algebra.
Another advantage of Sh above other shading languages is that calculations that can be done outside the shader are "lifted" to the CPU, so that these are not executed per fragment or per vertex but once per shader invocation.
Also, Sh is completely transparent to the render system used. The current backends are -GLSL and ARB assembly for -OpenGL. A HLSL backend is planned for Direct3D support.
The package can be downloaded here. It includes
- An executable for windows, which can be found in Demos/bin/Release
- Source code
- Project files for windows(Visual C++ 7.1) and Linux (gcc 3.4+).
Sh has its own GPU program parameter and texture management, making the plugin tightly coupled to the -OpenGL RenderSystem. This allows it to do various things like updating parameters in its own way. Modifying Sh to do these operations through the Ogre API would be a lot of work. This will be done eventually, but the point of this demo is to show that Sh and Ogre can be conveniently used together.
This coupling makes that the plugin must be linked directly to the Plugin_GLRenderSystem library, which is easy under Linux (in which a plugin is just a library) but somewhat more involved in Windows as the neccesary symbols must be exported from the DLL.
The first step, whether building for Linux or Windows, is to get the latest Dagon (1.1.x) branch from CVS. This is described on the Ogre developers page here.
On Linux, no changes to Dagon are needed, just configure and build Ogre the normal way.
The build process of the demo is a matter of setting the Ogre base path in the Makefile and typing 'make'.
Before running the demo one needs to set the LD_LIBRARY_PATH to include the plugin path,
in which OGRE_PREFIX is the prefix in which OGRE was installed, /usr/local by default.
Compiling the library on Windows is somewhat more tricky as it requires Plugin_GLRenderSystem to export the GLGpuProgram object, so it can hook into bind unbind and the parameter passing functions.
- First, apply this patch to the Dagon source code
- In the project settings of RenderSystem_GL, C/C++ > Preprocessor > Preprocessor Definitions add ";OGREGL_NONCLIENT_BUILD" (without the quotes, obviously)
- Do a full build of Ogre
- Now Ogre is ready for the Sh Plugin
- You can now build the plugin and the demo
Using Sh as a shading language in Ogre is somewhat different than using the other shading languages, but also has a lot in common...
... todo ...
Some shots of the ShOgre demo in action are shown below.
- Phong shader, dynamically built by a C++ object.
- Anti-aliasing checkerboard shader
- Athene mesh displayed with Glass shader