-RM-16-MR-We should document our shader mechanism, so developers know how it should be used correctly
Please edit this: [[DevelopingShaders]] You may use this snippet:
A shader can be used by applying it to a node. The following code gives a short overview:
osg::ref_ptr< WGEShader > m_shader = new WGEShader( "WMNavigationSlices", m_localPath );
...
This loads @surface.vs@, @surface.fs@ and (if existing) surface.gs. It recursively resolves all includes and sets several #define statements. Using the apply method sets the shader to the specified node. The shader gets activated for the node during the next update traversal of the OpenSceneGraph.
Note: Do never use @m_geode->setUpdateCallback()@ to set a custom callback. This will overwrite the shader update callback and the shader will not be applied. Use @addUpdateCallback@ instead.
Note: The name specified in the constructor is the base name of the shader file. It gets searched in the shader search path, which normally is the shader subdirectory inside the walnut binary directory. h2. Compilation
If the shaders are edited in the source directory they will be copied to "bin/shaders" with every call to "make". This is optional and can be switched on and off using cmake. One just has to adapt the state of OW_COPY_SHADERS. To develop shaders in the source directory, disable OW_COPY_SHADERS and link your shader file manually to OpenWalnut's binary directory.
h2. Shader Programming while OpenWalnut is running
Fortunately, it is possible to reload shaders in OpenWalnut while running. Simply press @'.'@ while the graphics widgets has the input focus. This enforces a reload of ALL shaders in ALL nodes. Appropriate output gets printed to stdout for debugging.
h2. Inclusion
OpenWalnut implements a framework that allows you to include the contents of one shader file into another shader file. The functionality is similar to what is well known from C++. If you want to include the file @shader.fs@ into your current shader file you would write the following
#include "shader.fs"
This is easy. Our code parser is robust enough to ignore spaces and commented include statements.
h2. Coding Standard
Even though it is not checked, the [[CodingStandard|coding standard]] we are using for all C++ codes also applies to shaders. In addition, EVERY shader needs to start with our OpenWalnut Copyright Comment followed by a @#version@ directive.
h2. Commonly used Code fragments
Some often used codes, like lighting, can be found in src/graphicsEngine/shaders. You should also put all your useful code, which not directly belongs to your shader, to this place.
(from redmine: created on 2011-08-05, closed on 2011-08-22)