Jump to content

Rendering Only "In Screen" objects


Gerente
 Share

Recommended Posts

Hello,

I'm doing some stress test with PIXI, and it seems that PIXI draw all the element of the stage, it does not matter if they are in range off the screen or not.

I'm trying with 300 circles and even if I move the layer to coordinates very far from the "screen view" (x=10000,y=10000), it still processing them all and give me very low FPS

There is any way to process only "inrange" objects to save CPU/GPU usage?

It is a Normal Draw (drawCircle) slower or heavier than an Image?

Thanks

Link to comment
Share on other sites

Yes, you can do that. 300 different Graphics elements and 300 circles in same Graphics element are different things because in first case its 300 drawcalls.

The only thing that is optimized here is that GPU doesn't call fragment shader on pixels that are out-of-bounds. IF you want to save drawcalls and vertices, implement your own culling algorithm, pixi doesn't have that.

I advice you to read at least 4 last pages, there are many related threads about your issue.

Also, related thread:

 

Link to comment
Share on other sites

According to https://github.com/pixijs/pixi.js/blob/dev/src/core/display/Container.js#L394 , its enough to set visible on parent.

If you mean that you want to check every element in the tree whether it has to be rendered - there's a cause why pixi doesn't have that built-in function. getBounds() of many sprites/graphics is slow. You have to find your own way of culling, based on your app specifics.

Link to comment
Share on other sites

var loopChildsDisableRenderablesOffScreen = function(children) {
	for (let k in children) {
	  var child = children[k]
	  var pos = child.toGlobal(new PIXI.Point(0, 0))
	  child.visible =child.renderable= (pos.x > 0 && pos.y > 0 && pos.x < screen.width && pos.y < screen.height)
	  loopChildsDisableRenderablesOffScreen(child.children)
	}
}

loopChildsDisableRenderablesOffScreen(stage.children)
render()

The logic works but it does not seems to improve the FPS, any idea why?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...