Announcement

Collapse
No announcement yet.

Collision with many sprites in screen is eating a lot of frame time. How to improve?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Collision with many sprites in screen is eating a lot of frame time. How to improve?

    Hi,

    I have authored a tool for importing Spriter animations into UE4. Each part of the animation is a SpriteComponent. Everything I'm talking here is about 2D PaperSpriteComponents and "plane meshes"

    I know at the moment the sprites are not being batched.

    But the collision calculation performance is also really really bad !

    My setup:
    - several sprites with custom geometry (not should be very expensive, only some extra vertices to the quad, hand made).
    - set all the sprites to overlap only with Pawn -ignore the others- and the Pawn to overlap only with WorldDynamic -ignore the others-
    - then, when I have on the screen a Pawn entity (made of ~10 spritecomponents) and ~10 WorldDynamic entities (made of ~4 spritecomponents) my Samsung Galaxy 3 performance go down ... i got spikes of ~20 fps and the time of "Game thread" is increased by a lot.

    If I deactivate the collisions (setting ignore to all in every sprite) I get a noticeable performance boost (like very stable 62 limit fps with spikes to 50)

    If no other method is proposed, I will have to rely with very imperfect collision using only 1 poly per each entity -instead 1 poly for each part of the entity-.

    Questions:

    - How can I profile the collision performance in the device? and see where are the bottlenecks?
    - How can I improve the performance of several collision overlap testing in screen?
    - Can I tune the time between overlaps/collisions updates ? What triggers exactly this function -so I could look if im doing something wrong-?
    WIP Save the princess !
    https://twitter.com/stp_the_game

    #2
    Is this a workaround for the flipbook having no sprite based collisions? So are you having a sprite component for each frame of animation in the same actor and then switching though them to be visible frame by frame? OR are you using each sprite as a separate part of the same object (i think from your post that its the latter). It might be more performance friendly if you made your collision out of capsules and boxes. I know it's only simple custom geo but its still geo collision which is known to be more expensive.

    Also have you constrained the physics engine to be 2d? it might cut physX testing in 1 dimension and help things.

    I haven't played too much with the 2d collisions so feel free to ignore me though!
    Visual Effects Artist, Weta Digital, Wellington New Zealand
    BLOG www.danielelliott.co.uk
    @danielelliott3d https://twitter.com/danielelliott3d
    Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
    2015 Showreel: https://vimeo.com/116917817

    Comment


      #3
      My entities are composed by several sprites which are the parts of the animation. So I do not use flipbooks. I use the sprite collision polygon, adding some vertices -but not a lot-.

      I will tray switching to boxes for testing if the penalty is due to geometry complexity!

      Regarding to constraining physics, *I think* i have constrained physics in Y plane in project settings and I think I have checked "Can use 2DPhysics - Box2D" to true in project settings also. BUT I think each sprite has checked the "use 3d physics"

      Also, each sprite of my entities is tweened -driven by a UTimelineComponent-, so every frame every sprite can potentially -and likely will- update its transform
      WIP Save the princess !
      https://twitter.com/stp_the_game

      Comment


        #4
        There are two physics systems here. Box2d and PhysX. It's not immediately clear where the settings from one or the other are set. I would probably stick to just physX for now as it could be possible that box2d is also colliding and causing performance issues. So maybe uncheck the box2d option and also uncheck use 2d as then the physics will be 2d physX.
        Visual Effects Artist, Weta Digital, Wellington New Zealand
        BLOG www.danielelliott.co.uk
        @danielelliott3d https://twitter.com/danielelliott3d
        Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
        2015 Showreel: https://vimeo.com/116917817

        Comment


          #5
          Well I think the "use 2D" and "use box2D" are the same option.

          when you say the physics will be 2d physx what do you mean?
          WIP Save the princess !
          https://twitter.com/stp_the_game

          Comment


            #6
            I mean the standard physics in unreal engine which is the nvidia physX engine under the hood. There is an option from 4.4....

            "New: Simple 2D Physics Constraints

            The engine now supports easily constraining 3D physics objects into a 2D plane. This can help when making 2D games like side-scrollers."

            Looking here.....
            https://forums.unrealengine.com/show...or-4-3-Preview

            ...I see that yes you were right in having use 3d physics. I got confused with the physics 2d 'constrain to plane' .The forum docs say.....

            "Use 3D Physics: Collision geometry will be generated for use with PhysX. The 2D collision geometry defined in the sprite will be extruded to “Collision Thickness” units deep in the perpendicular axis to make 3D collision geometry."

            So I would have Use 3d physics ON and then in the physics section of the actor, have "Locked Axis" set to be the plane that your 3d world is aligned against. I would like to test this myself.
            Visual Effects Artist, Weta Digital, Wellington New Zealand
            BLOG www.danielelliott.co.uk
            @danielelliott3d https://twitter.com/danielelliott3d
            Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
            2015 Showreel: https://vimeo.com/116917817

            Comment


              #7
              yeah I think I have my settings like you said.

              My game runs in ZX axis so I have Y-axis locked. The only option I can change is "Use 2D physics" option which I will try
              WIP Save the princess !
              https://twitter.com/stp_the_game

              Comment


                #8
                The Use 2d Physics option will enable 2d physics which is not what I'm suggesting. I'm suggestion the

                "New: Simple 2D Physics Constraints

                The engine now supports easily constraining 3D physics objects into a 2D plane. This should help with 3D side scrollers."

                ..which was added in 4.4. have a look at the release notes....

                https://www.unrealengine.com/blog/un...ne-44-released

                It says....
                'The setting can be applied per object, or project wide by changing the project physics settings."

                So go to world setting under the physics section and the option should be there.
                Visual Effects Artist, Weta Digital, Wellington New Zealand
                BLOG www.danielelliott.co.uk
                @danielelliott3d https://twitter.com/danielelliott3d
                Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
                2015 Showreel: https://vimeo.com/116917817

                Comment


                  #9
                  I'm sorry I meant disabling it (the Use 2d Physics) ... currently I have it enabled. So It might help ... the other options I think I have them already set (constrining 3d physics to lock the Y-axis plane, applied in project settings)
                  WIP Save the princess !
                  https://twitter.com/stp_the_game

                  Comment


                    #10
                    I will quote from Epics VFX Opt guide:
                    If you are a seasoned effects artist, or if you have only been an effects artist for 2 weeks you have already heard about Overdraw.

                    In its simplest form, overdraw can be described as:

                    Overdraw = Pixel shader cost = Number of layers * avg number of pixels affected by a layer * avg number of instructions for a layer
                    Essentially, when you add a material to the surface of a sprite, that material has a cost in instruction count, which UE3 displays in the content browser and material editor. For translucent objects this instruction cost adds up as translucency stacks up, creating overdraw. The more layers of translucency, the higher the cost. You can easily see this cost in the shader complexity mode. Bright Red = 300 instructions, pink = 600 instructions, and white = 900 instructions. Press F5 to view shader complexity on PC.

                    Shader complexity outputs an approximation of what the cost of a system will be, however it is also dependent upon the scene since translucency is calculated against opaque objects which also have a cost.

                    Checking the usage of your effects is critical. An effect which may be called in any given scenario (weapon impact) will generally need to be lighter than an effect you can custom build to match a specific scenario, since it will be drawn in fluctuating cost scenarios.

                    Some steps that can be taken to get overdraw impact under control are:

                    Reduce emission rates
                    Reduce material instruction count
                    Reduce particle scale (fill less of the screen)
                    Create LODs for near/far particle emissions to reduce cost at different view distances
                    Check for emitters placed in a line stacking against each other (static placed effects)
                    To sum it up: Collision calculations + overdraw + other calculations in scene = no no.
                    You should never have too many sprites in your screen, Try creating a per distance culling so if they get too close or too far they are hidden.

                    Hope this helps you.

                    ~Chris I.
                    VFX Artist
                    Portfolio: Here

                    Comment


                      #11
                      Overdraws are not a problem ... the render geometry is pretty simple (sprites) and there is not alpha blending at all -all materials are unlit and masked opaque, only 1 texture sample-.

                      Problem is in "Game thread" and disappears when I turn off collisions so no rendering issues -my scenes are pretty simple-.

                      It would be interesting knowing how the "broad phase" of collisions is configured and knowing if it can be tuned someway
                      WIP Save the princess !
                      https://twitter.com/stp_the_game

                      Comment


                        #12
                        ah, Unfortunately i can't help on that part, Will wait for someone with more experience to reply on this.
                        VFX Artist
                        Portfolio: Here

                        Comment


                          #13
                          Box2d is still in experimental phase in Unreal so it does not work well.So from my understanding what they did was to lock the "regular" Unreal physics engine and costrain it to whatever axis you want.In our case is the Y axis.It still has its issues https://answers.unrealengine.com/que...xis-issue.html though.

                          As for performance it seems that whatever is off screen is not rendered so it has no cost https://answers.unrealengine.com/que...questions.html.

                          As for mobile performance unreal is not optimized for all devices.They have a list that have already tested and approved.And to be honest our telephones (i have an LG 4XHD) are 3 to 4 times less powerful that the ones that are out right now.I do not believe that is realistic for us to develop anything for this kind of devices using Unreal.I tested something that was 10-15 fps at my phone to a friends S5 and it was a rock solid 60fps.Huge difference.The new K-1 chip from Nvidia is rumored to have ps3 if not better performance!

                          I am using spriter as well for all my animations!If you could help me out to import my stuff in Unreal(I HATE EXPORTING PNG'S AND USING TEXTUREPACKER) i will be for ever grateful!

                          Comment


                            #14
                            Yesterday I tested without Using 2D physics and it seems it made no difference at all. I have to test changing all my fully custom geometry to a basic geometry and see what happens ...
                            WIP Save the princess !
                            https://twitter.com/stp_the_game

                            Comment


                              #15
                              just to bring an update to this ... definetly update overlaps crushes my resources. Even using basic geometry.

                              I think I will have to get back to more rough geometry with less polygons, maybe just 1 per entity.
                              WIP Save the princess !
                              https://twitter.com/stp_the_game

                              Comment

                              Working...
                              X