#Running shaders only for on-screen entities?

25 messages · Page 1 of 1 (latest)

dreamy sparrow
#

I tried to add my first shader to my game. Its a top down 2D game, and I added a shader that moves my foliage to simulate wind. Its a fairly simple vertex shader, but my world generates a lot of chunks/foliage, and so when i converted my spritebundles to my mesh2d material bundles with the shader when spawning foliage entities, my game is unplayably slow. I imagine its because its running the shader on some 5-10k+ trees that have generated around my world.

What is the appropriate work around for things like this, im very new to shaders. Is there a way to only run shaders for whats on the screen?

radiant mica
#

Have you considered chunking your world?

dreamy sparrow
#

resolved this in #rendering.

#

Yes, i alreayd chunk it, but i render 2 chunk radius around the player/camera

#

thats enough to cause lag bc the amount of trees

short hollow
#

I think that the perf difference you're seeing is more likely from the lack of "batching" in the mesh2d pipeline, which the sprite pipeline has.

Although if you have a lot of offscreen stuff, frustum culling can help as well. But I don't think we have that built-in (yet) in either the sprite or mesh2d pipelines at the moment.

Take that with a grain of salt, been a while since I looked at any of that stuff. I can't seem to find any github issues tracking either the lack of batching or frustum culling.

dreamy sparrow
#

im goign to set trees visibility to false if theyre off camera

radiant mica
#

Wow that’s a lot of trees in that small of an area I’m very curious to see it lol.

dreamy sparrow
#

haha, i can show you what it looks like for one snapshot of the camera view, but if i turn the trees on for the rest of the chunks i get 0fps, so i cant really show you

radiant mica
#

Fair lol

dreamy sparrow
short hollow
#

yeah, that should help

dreamy sparrow
#

heres a snapshot. each chunk is 64x64 tiles, each tile is 32x32px. I made it only spawn trees in my (0,0) chunk to test. now ill try adding the visibility stuff

#

it runs fine for just 1 chunk of trees, under 1k ithink

#

each chunk gets like 600-800 trees based on my generation algo

radiant mica
#

Out of curiosity why are the chunks so large?

dreamy sparrow
#

you cant see the shader in action obviosuly, but the trees sway slightly left to right

#

its a suggestion from the bevy_ecs_tilemap maintainer, i had smaller 16x61 chunks bf, but that was way too much loading/unloading

#

i was told its better to make fewer render calls and have larger chunks. I think under the hood each chunk is batched into 1 render call or something

radiant mica
#

Ah I’ll have to keep that in mind I’ll be also working on a top down game soon

dreamy sparrow
#

sweet! yeah i got a lot of help from that crate and its help channel

#

working in bevy 2D for a top down game has been interesting lol, goodluck

radiant mica
#

Yeah I’m planning on using bevy_ecs_tile map for my project

#

Thanks you too! It looks awesome so far

dreamy sparrow
#

thanks, cheers 🙂