In order to debug this visually we first set up a shader which plots the curve produced by sin(): Output of GLSL sin() call. Reducing the number of octaves would reduce the number of calls to sin() but also immediately changes the visual nature of the effect, so sadly this was not really an option.Īt this stage we looked into alternatives for the call to sin() which would perform better on the affected GPUs. The X and Y axis each get their own displacement, which is based on a 2D noise algorithm which in turn combines 5 octaves of noise at different scales to produce a nicely uneven distortion effect. In short the shader is using a form of Fractional Brownian Motion (see ) to offset the read UV coordinates. The fact that we call it that many times was not immediately apparent in the original version, as there is only one method with a single call to sin().Īt this point it makes sense to look a bit deeper into what this shader is actually doing to achieve the intended effect: We are calling sin() in this shader 120 times for each fragment, and unfortunately this is extremely slow on some mobile GPUs. Although this doesn’t actually run faster it does help us identify the performance bottleneck quite easily: This is only a fraction of the ~700 lines of output from the optimizer. Sadly the “optimized” version of the shader was not only a lot bigger then the original but it also ran a whole order of magnitude slower than the original version.Īt this point we looked into what kind of output the optimizer produced and noticed that it’s not really optimizing the code in any way, it simply “unrolls” the entire thing and obfuscates the variable names: Snippet from ‘optimized’ shader. To improve the situation we first looked into some automated options, such as this GLSL optimizer originally used by the Unity engine: Whilst this produced the intended visual effect and the performance hit on most devices we tested this on was minimal, we also found during testing that on some mobile devices this shader had a really drastic impact on the games framerate (bringing it from our target 30 FPS down to ~5/6 FPS). With our new underwater era outpost we wanted to add a post-processing effect to simulate the water by adding a small amount of animated visual distortion on top of the rendered game scene.Īfter some back and forth between the art and dev departments we settled on the following implementation: Original shader. Forge of Empires, Improvements, Performance
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |