Changing the Rendering order for a Level

About Icarus Forums Icarus Scene Engine General Changing the Rendering order for a Level

This topic contains 0 replies, has 1 voice, and was last updated by  admin 1 year, 5 months ago.

  • Author
  • #374


    By default, a Level will render items in Sorted order (except a Scene, which defaults Sorted = false). The much easier scenario is when Sorted = false, so we will cover that first:

    Sorted = false order

    Items are rendered in the order that you add them. Simple as that, no fuss.

    Simple, yes, but very far from optimal, as objects with the same Material, and objects with the same Mesh, should be rendered together for best performance. This lets ISE avoid having to change VAO & VBO and/or mapped textures, material definitions and current shader. This is where Sorted=true comes in.

    What is Sorted = true order?

    When an object is added to a Level, and Level.Sorted = true, it is then inserted based on two numbers inside the added Object, it’s SortGroup, and it’s SortIndex. This insertion is done via a BinarySort.

    SortGroup is an integer value, whereas SortIndex is a floating point number. This allows objects to be specified according to your own defined object “type” (mapped to a SortGroup), and then sorted by, e.g. Distance from Camera.

    SortGroup and SortIndex can be manually defined. Objects are only sorted when they are added to the list. If these sorting fields are then changed, the list is not updated, and must be re-sorted manually, by calling Level.Sort(), which performs a Binary Sort on the list. As this can be time-intensive, “choose wisely”.

    Neither of these values, SortGroup or SortIndex, need be unique. Like values are collated together.

    Most objects in ISE don’t set values for these sorting fields, with one notable exception, Entities.

    For Entities ONLY

    Note: “Entity” applies to both an EntityMesh and an EntityInstance.

    By default, an Entity generates a unique Sort Group number, from 1000 onwards. (This number is incremented for every new Mesh loaded, so it may not be consistent from run-to-run).

    For ISE 4.0, if the Entity has a transparent Material (Blended = true), then this is fixed at 16000.

    The goal here is to ensure that non-transparent material render first, and these non-transparent meshes are rendered together, e.g. all “blue ice cream” meshes are rendered together. Then, because all transparent meshes have the same Sort Group, only the Sort Index (typically Distance from Camera) is used to Sort them, so they render strictly in Distance order.

    This ensures that all identical meshes are rendered together (no changes to the VBOs or VAOs) for better performance, while all transparent meshes are rendered in distance order for visual accuracy.

    • This topic was modified 1 year, 5 months ago by  admin.
    • This topic was modified 1 year, 5 months ago by  admin.
    • This topic was modified 1 year, 5 months ago by  admin.
    • This topic was modified 1 year, 5 months ago by  admin.
    • This topic was modified 1 year, 5 months ago by  admin.
    • This topic was modified 1 year, 5 months ago by  admin.

You must be logged in to reply to this topic.

Comments are closed.