Table of Contents
- Nicer shadows
- Improved Documentation
- Better Python integration
- OgreUnifiedShader as a Cg replacement
- blender2ogre for Blender 2.8x
While revising the depth-texture implementation, I noticed that we would take advantage of that feature for performance instead of quality. With depth-textures the GPU can perform bilinear interpolation of the depth-test, so a single sample (tap) roughly corresponds to a classical 4-tap PCF in the shader. So what we did was just doing a 1 sample instead of 4.
However for hardware capable of depth-textures, performance is typically not an issue, so we should rather improve quality.
The images below show crops from the ShaderSystem sample at 200%. On the left, you see the old setting, while the new setting is in the middle. On the right, you see the 4-tap shader fallback used when depth-textures are not available i.e. on D3D9 and GLES2.
Yeah, so the other news is that D3D11 finally got depth-texture (
PF_DEPTH) support as well.
But what if you need to support RenderSystems without
PF_DEPTH or you are on GLES2 where
PF_DEPTH support is not guaranteed. Well, Ogre will now gracefully fall back to the closeset non-depth format: e.g.
PF_L16 and the RTSS will then deal with the differences.
While at it, I also updated the default shadow material settings to be more robust as in shadow aliasing artefacts:
Thanks to an additional round of fixes to the emscripten GLES2 backend, you can also try out the shadow improvements in a WebGL2 capable browser.
I took another look at the documentation and added a CI test to detect docstring inconsistencies like undocumented or superficial parameters. This should help improving the documentation quality of external and my own pull-requests.While at it I also added doxygen groups to several large classes. These allow tying related methods together. See e.g. the Material class:
- before: https://ogrecave.github.io/ogre/api/1.11/class_ogre_1_1_material.html
- after: https://ogrecave.github.io/ogre/api/1.12/class_ogre_1_1_material.html
Speaking of Materials.. did you ever wonder how they work exactly? Well, now you can take a look at
Better Python integration
Next, it kind of bothered me that one has to write so verbose code, when using the Python bindings, so I tried to take advantage of Python protocols:
# Now, instead of specifying the type as before vp.setBackgroundColour(Ogre.ColourValue(.3, .3, .3)) # you can do vp.setBackgroundColour((.3, .3, .3)) # or vp.setBackgroundColour(numpy.zeros(3)) # or even vp.setBackgroundColour(range(3))
Also, bytes objects are now supported where raw pointers are expected in the API:
# so you can do arr = np.zeros((256, 256, 3), dtype=np.uint8) ogre_img.loadDynamicImage(arr, 256, 256, Ogre.PF_BYTE_RGB)
OgreUnifiedShader as a Cg replacement
In an effort to provide an modern alternative for Cg and to reduce the maintenance overhead of the Ogre internal shaders, I created the
OgreUnifiedShader.h that allows writing cross-platform shaders.
It is greatly inspired by the shiny library for Ogre and the shaderc tool of bgfx. However, in contrast to the latter this header is fully self-contained. All you need to do is
#include it – no need to run an additional tool. It also has the advantage that you can run your shader through the standard c preprocessor (cpp) to see what the transformed shader looks like.
Just as bgfx, I opted for GLSL as the least common denominator between the shader languages. That is with some preprocessor based abstractions on top:
- Declare Samplers with
SAMPLER2D/3D/CUBE/..macros instead of
- Use the HLSL style
mul(x, y)for matrix multiplication
mtxFromRowsto construct matrices
- Declare parameters with
IN/ OUTmacros instead of
- Use the
MAIN_PARAMETERS & MAIN_DECLARATIONmacros instead of
Here, I tried to maintain compatibility with bgfx where possible.
For an example of usage, see this PR, where I converted the Light Shafts Demo from Cg to HLSL & GLSL. As you can see there is still some room for improvements on the Ogre Material side.
Anyway, this allowed to drop 1800 lines (#1663) of shader code from the RTSS and we now have arrived at a single, GLSL based, shader library. When I joined Ogre there were 4 RTSS implementations (GLSL, GLSLES, HLSL, Cg) – with individual, subtle, bugs.
blender2ogre for Blender 2.8x
Thanks to a contribution by “Grodou” blender2ogre gained back the ability to export textures with Blender 2.8x, which is notable as we need to read from the node-based shaders for this. Together with some additional fixes by yours truly and the initial porting done by Paul Gerke, this brings exporting with Blender 2.8x roughly at the same level as with Blender 2.7x.
However, we can now take advantage of the texture semantics one gets from the Cycles materials. Thereofore, blender2ogre is able to correctly export emissive textures and, notably, normal maps.
The difference in appearance that you see above is due to the missing gamma handling. Also, to fully match what you see in Blender, we need add support for metalness and roughness maps.