This makes a few significant changes that can affect users working on Ogre 2.1:
The main feature introduced is that there is now 2 Vaos per Renderable for v2 objects, and 2 vertexData/indexData pairs for v1 objects.
So now Ogre can render a mesh during the regular pass, and a completely different one during the shadow casting pass.
This allows us to use an optimized version of the mesh for shadow mapping. In case you don't know, a cube can be represented with 8 vertices, 24 vertices, or 36.
This is because whenever there is a discontinuity, like per face normals or tangents, or UV seams; the vertex needs to be duplicated.
Normally, we don't need UVs or normals during the shadow map pass (unless we need the UVs for sampling a texture for alpha testing; in which case we use mVao[0] instead of mVao[1]) so Ogre will use mVao[1] to send a position-only buffer that has no duplicated vertices to speed up rendering.
The downside is that we need a little more memory to store the extra optimized mesh.
The performance differences can vary wildly. Heavy vertex count with lots of duplicated vertices or bandwidth limited will show the best performance improvements from this (I suspect Mobile will see a huge benefit when we support it) while other applications will see no difference at all.
Results can also depend on the GPU.
Note that this optimization is optional and turned off by default.
When it's off, the pointers of mVao[0] will be referenced by mVao[1]. When it's on, the pointers of mVao[0] & mVao[1] will be unique instances. Same goes for v1 objects.
How to enable it?
You can set Mesh::msOptimizeForShadowMapping and v1::Mesh::msOptimizeForShadowMapping to true and Ogre will automatically generate the optimized version when loading the mesh. However for large meshes this can take quite some time (like 10 seconds for a 200.000-vertices mesh) so it's best to leave this flag disabled, and save the optimized version into disk.
When the optimized vertices were saved to the mesh file, Ogre will load the optimized one regardless of what msOptimizeForShadowMapping says.
The new tool "OgreMeshTool" which was ported from OgreMeshUpgrader and merged with OgreXMLConverter can do this.
The file v2 format changed
Meshes in the previous v2 format are still supported, but we will remove support before releasing the official stable 2.1 version. It is therefore strongly recommended to update your meshes if they were stored in the v2 format. The MeshTool can upgrade them for you.
Examples with the Mesh tool:
To upgrade existing v1 and v2 files and generate the shadow mapping optimized buffers:
Code: Select all
OgreMeshTool -O s sourcefile [destfile]
Code: Select all
OgreMeshTool sourcefile [destfile]
Code: Select all
OgreMeshTool -O S sourcefile [destfile]
The MeshTool is still WIP, so not all command line combinations will work, specially because most of its options only work on v1 meshes yet, and if you load a v2 mesh it may ignore them silently.
In the future we plan the MeshTool to be able to convert between v1, v2 and xml mesh file formats without issues. The MeshTool can read XML meshes (not skeletons yet), but cannot write XML yet.
The code has been tested, but expect a few bugs. We may have missed one or two pointer evaluations, i.e. if you see a crash on vertexData and i=1 it's probably because of this new feature.