Shaders DEADLY to perfomance?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By The_Black_Chess_King

Currently making a 2d game for PC, and just made a shader that have everything in one, Vignette, Grain, Blur, Texture Blur and Ripple. Made using modifications of the screen_space_shaders godot example.

The reason for that, is this shader can mix all the effects in just 1 material.

My question is, does shaders are performance-wise bad in 2d games?

  • Like for example, I know that light amount and shadowFilters can impact performance heavily. But what about shaders, are they related?

Some people sayed that using textureLod()does impact perfomance a lot. Others say that you should never use more than 1 texture per shader. There’s any pitfall we should avoid when dealing with shaders?

It would be awesome to know what I can do to minimize any POTATOES I may run while implementing those awesome features for my game. o_o

thanks for any info on that,

:bust_in_silhouette: Reply From: Calinou

One of the main performance pitfalls with shaders is that you should avoid conditionals (e.g. if) as much as possible. This is because GPUs are bad at branching (compared to CPUs).

This isn’t specific to Godot; this applies to any shader language out there.

Interesting, because I have done 3 if’s in my shader code lol, will clean that up.

I tested in a old machine, 2 GB of memory and GLES 2, no GPU, don’t remember what CPU it was though, but it was using only intel OpenGl, and to my surprise the effects worked fine (my gues was that with no GPU you would not be able to use shaders), but the perfomance was horrible, dropped to about 3-8 FPS.

I guess it was only because of low memory, but I could create a SHADERS-OFF option in the game, and check it before instancing the post-processing master node into the scene. My game was using about 350 mb of memory, which is fine I guess.

Thanks for the tip,

Cheers,

The_Black_Chess_King | 2019-10-23 03:19