Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adminotech - Implement Ogre Instancing #680

Merged
merged 18 commits into from
Jun 14, 2013

Conversation

jonnenauha
Copy link
Member

Implements Ogre instancing support for Tundra in EC_Mesh and OgreWorld.

Instancing1

Implemented now

  • New useInstancing attribute for EC_Mesh.
    • Handles toggling instancing on/off during runtime.
    • No other visible changes to external code, except OgreEntity() may return null if instancing is used. Created new OgreInstancedEntity() for these situations. I've checked all core c++ code that nothing blindly uses the OgreEntity() ptr.
    • EC_Placeable attaching and EC_Mesh node transform keep working just like before instancing.
  • OgreWorld implements CreateInstance() and DestroyInstances() functions that must be used by eg. EC_Mesh in pair to keep OgreWorld internal state in sync.
    • Implements automatically injecting VS and PS programs into the input materials if they are not already defined. This logic will not modify the existing material but clone it and put changes there, so non instanced meshes can use the material at the same time. It will also replace shaders if there already are existing shaders, in this case it will prints a helpful warning log line that tells the author what we should do to fix the situation.
    • Implements visual debugging on instance batch bounding boxes (utilizes an existing Ogre feature) via IsDebugInstancingEnabled() and SetDebugInstancingEnabled(enabled) and a qt property (just like PhysicsWorld does).
    • Enables script logic to define static instancing for a particular mesh ref via IsInstancingStatic(meshRef) and SetInstancingStatic(meshRef, static). This can make the rendering dramatically faster in cases where the instances are not moved. This must be decided by a inworld script, it is too bug prone to automate in OgreWorld. If you know a) you have huge amount of instances b) you are not going to move them via EC_Mesh transform or EC_Placeacble, either for scripts or via clients, you should go ahead and set static to true.
  • Example scene bin/scenes/Instancing/scene.txml
    • Test instanced and non-instanced runs with your own instance row/column count.
    • UI can toggle static/non-static intancing.
    • UI can toggle instancing debugging.

Needs work!?

  • Test all kinds of input materials and how they will behave. Also test multi submesh meshes.
  • Integrate instancing VS part to Tundra super shader?
  • EC_Highlight wont work on instanced entities as their submesh materials cannot be replaced that easily. We might need to make a instanced version of the highlight material and apply that. Afaik EC_Highlight calls SetMaterial that does currently nothing for instanced meshes, and it would probably be a bit slow to destroy the current material ones and recreate with "hightlight" material.

I've sent this pull request in good time so people have time to review it before merging talk becomes relevant. Any feedback on the code in general and API in OgreWorld would be appreciated!

Jonne Nauha added 13 commits May 30, 2013 20:14
… can start. Next I need to figure out the instancing shaders etc. All of this is still very much WIP.
… more logic to the instance state objects in OgreWorld, including optimization runs after 5 seconds after creations/deletions have been done.
…instead of the deprecated GetEntity(). Check that all these places have proper null checking in preparation for instancing.
…perty/slots. Add function that can set mesh refs instances as static, this can boost performance quite a bit but is hard to automatically detect (if static any movement wont be updated) so lets leave it to script logic to tell the rendering what instance meshes wont be touched. Improve destroying instances so that the manager gets cleared once it has 0 instances left.
…s to test performance with both instancing on and off and toggling static instancing.
…sh targets with ref and submesh. Fix that meshes that are set as static also create new instances (with all of its submesh/material combos) as static. Added a getter for static instancing for a particular mesh ref.
…ill usually override both or none so this makes the output cleaner to read. Fix documentation that CreateInstance can return null in error situations with given input.
…fied from the Ogre 3D example assets and note the original author Matias N. Goldberg.
Jonne Nauha added 4 commits June 3, 2013 17:37
… empty targets into the internal lists. Now if create and destroy are used in pair correctly, there is nothing left for dtor to cleanup. Fixed typo in script UI.
…ncing is used. Add todo tag to SetMaterial. Implementing this might be quite heavy with instancing as it involved completely destroying the current instances with this material and creating new with 'instancing supported highlight material'.
…state book keeping. This fixes meshes with multiple submeshes in them and makes the internals a faster when instances are destroyed by EC_Mesh.
@jonnenauha
Copy link
Member Author

Adminotech@b3f7250 Makes a bit of overhaul to my OgreWorld internals. Fixes things with multiple submeshes and should speed up DestroyInstance() a bit, less things to loop around.

Hopefully this will get cleanly merged to lasses work that is making all (most at least) our super shaders available for instancing, which is a super exiting feature for artists! My thing was kind of restricted demo phase in terms of shaders :)

…needed test code for multi submesh creation.
@cadaver
Copy link
Member

cadaver commented Jun 13, 2013

Multi-submesh support looks solid now. Draw distance & draw shadows settings are not being used in instanced entities though.

@jonnenauha
Copy link
Member Author

https://github.com/realXtend/naali/pull/680/files#L13R966 Hmm, I did implement and even test it by selecting a bunch of ents in the instancing test scene, setting their draw distance to 10 and they dissapeared. Came back when a high enough distance was used, or set to 0. It should sync that in both creation and any time the attribute changes.

@cadaver
Copy link
Member

cadaver commented Jun 13, 2013

Sorry, when retesting, draw distance worked correctly. Shadow casting is only changeable per instance batch, so it is now locked on.

@cadaver cadaver merged commit 4d3bdf6 into realXtend:tundra2 Jun 14, 2013
@jonnenauha
Copy link
Member Author

Thanks @cadaver for the quick work and great job on cloning the super shaders with instancing support! This is huge plus for maintainability of the super shader.

@jonnenauha jonnenauha deleted the admino_instancing branch August 6, 2013 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants