Optimizing OpenGL ES 2.0 performance on low-end mobiles

Started by
3 comments, last by lawnjelly 6 years, 11 months ago
I've just got my latest build of my OpenGL ES 2.0 jungle game working on my android devices (nexus 7 2012 tablet, cat b15 phone) and am currently deciding the best way to address performance. (more details here: https://www.gamedev.net/blog/2199/entry-2262867-sound-particles-water-etc/)
All the graphics seem to be working fine, but it seems that the biggest issue is fillrate / texture samples / shader complexity.
So far I've identified the biggest issues: :blink:
  1. dynamic water shader
  2. particles
  3. pcf shadows
[attachment=35790:dynamic.jpg]
I'm aiming for 60fps even on low end phones, if possible. It seems to me that I should have graphic options so the user can get the best graphics / performance for their device.
Some of the issues are a consequence of using a scrolling pre-rendered background, with colour and a custom depth texture (as depth textures are not supported on some devices). When rendering the background as the viewer moves around I currently use 2 passes, one for the colour and one to write the depth into an RGBA, then in realtime I render dynamic objects on top (e.g. the animals) and I read from the depth texture, decode it and compare to the fragment z value.
One obvious speedup is to remove the depth comparison with the background for shaders that do not require it. For the particles, they look much nicer when they are hidden by trees / vegetation, but still look acceptable without it.
The PCF shadows I always suspected were going to be a problem. I was using PCF shadows for the pre-rendered scrolling background (only need refreshing every few frames) and PCF shadow on the animals as they get shaded by trees etc. Taking this down to a single sample greatly sped the shader up, so it is obviously a bottleneck. The single sample shadows look very bad however, so I think the options should be:
  • turning them off for animals
  • perhaps simplifying them for background or using some kind of pre-calculation.
  • There is also the option of randomized jitter / rotating sample window to get a softer shadow with less performance hit.
The biggest question I am still facing is how to do the water. :huh: Is it actually *feasible* to run a complex water shader covering the whole screen on these devices (worst case for sea parts) or do they lack the horse power? I am actually considering (!!) pre-rendering a static water as part of the background. Then bodging in some kind of depth blue colour for parts of animals that are below the surface on each frame. It won't look amazing but should be super fast. I could even add some dynamic particles or something on the water surface to make it look at least a little dynamic.
This is what static water might look like: :blink:
[attachment=35791:simpleshader.jpg]
I am currently just rendering a giant quad for the water, then using depth testing against the custom depth texture to handle visibility. But this is a bottleneck, as well as the calculations of the water colour. I have already considered drawing polys for the rough area where water will be (around the shores etc) rather than the whole screen, however this will only help in best case scenarios, not in worst cases. Maybe there is a cheaper way of deciding where it can draw the water? I would use the standard z buffer but that option does not appear to be open, given that I am using a custom encoded depth texture, and the shaders cannot write to the standard z buffer without an opengl extension (which may or may not be present lol :rolleyes: ).
I could maybe wangle another background luminance layer or something for where to draw realtime water, but this seems a lot of effort for not much reward (it would only be saving on decoding the depth texture and doing a comparison).
Another question that does occur is, whether all of these bottlenecks are simple bottlenecks, or whether I am stalling the pipeline somewhere with a dependency, and could I double / triple buffer the resources to alleviate the problem.
Anyway sorry for this long rambling post, but I would welcome and thoughts / ideas - probably along the lines of whether these should actually be causing such problems, and any ideas around them, particularly the water. In fact any suggestions for super fast simple water shaders would be useful .. I suspect just adding 2 scrolled tiled textures might produce something useable enough, if the texture reads are faster than calculations within the shader.
Advertisement

you need to prerender water normals texture for a set of time, so it will loop or even use some fancy perlin noise texture for that.

i dont get pcf

you should draw into 3 diffrent framebuffers

yes depth needs to be written to texture so you have 2 passes for each framebuffer

one colorbuffer, one depthbuffer

you use same dimensions for all framebuffers, along with same view and projection matrix

you draw all shadowcasting characters first (in your example it could be trees then animals) to depthbuffer (but no depthbuffer itself but a shader depthbuffer - the one that draws depthtexture) (from light view)

then you draw terrain to depthbuffer and apply lightmap test of depththing we wrote to tex before (from light view :P)

you could even draw a translucent quad in a water place to apply a straight shadow on water surface....

such shadows will reduce framerate by 50% or more

you need to prerender water normals texture for a set of time, so it will loop or even use some fancy perlin noise texture for that.

Ah yes! Good thinking, :D The simplest solution to pre-render some frames. I actually did this as the first version, long ago but had forgotten!

i dont get pcf

PCF is just basic shadow mapping but taking multiple samples:
http://fabiensanglard.net/shadowmappingPCF/

you should draw into 3 diffrent framebuffers
yes depth needs to be written to texture so you have 2 passes for each framebuffer
one colorbuffer, one depthbuffer
you use same dimensions for all framebuffers, along with same view and projection matrix


It kind of works like this already, a little more complex though as it has a wrapping tiling background bigger than the screen, and handles ground textures separately.

you draw all shadowcasting characters first (in your example it could be trees then animals) to depthbuffer (but no depthbuffer itself but a shader depthbuffer - the one that draws depthtexture) (from light view)
then you draw terrain to depthbuffer and apply lightmap test of depththing we wrote to tex before (from light view :P)
you could even draw a translucent quad in a water place to apply a straight shadow on water surface....

such shadows will reduce framerate by 50% or more


This is how it does things already with the shadows, except I am not casting from the animals at this stage as I figured that would be too expensive, I'll probably just add simple blob shadows for the animals. Although the shadows are received by the animals, from trees etc. The shadow map only needs to be regenerated as you move across the map, it is not rendered every frame.

With the dynamic shadows received on the animals turned off, the shadows on the terrain are essentially free for most frames, but they do cost when scrolling to a new tile.

I have this afternoon implemented the static water as part of the background (although not yet done the bit to add blue colour to under water animals). It doesn't look really bad on my low end phone and is now rendering mostly 60fps. There are occasional dropped frames during scrolling to new tiles but I'll see if I can address that.

I will see if I can add random jitter to the terrain shadows to make it look better with fewer samples.

On low end devices, overdraw and shader instructions are the bigger problems.

i doubt turning off depth testing for particles will matter.

try single sample shadows instead of multiple samples.

reduce the particle count and crop the particle geometry size to be smaller.

don't use too big triangles! more than 10x10 pixels may start hurting, depending on the hardware.

simplify per fragment calculations.

enum Bool { True, False, FileNotFound };

On low end devices, overdraw and shader instructions are the bigger problems.

Yes definitely, I've been finding this. Has made me so glad I went with pre-rendering the scrolling background as rendering all those sprites every frame would have killed performance. Most of the work on a frame is done by just drawing one big screen size quad for the background. The 'big work' is done when rendering a new row or column of the background, which only happens every few frames, and is limited to a small viewport so it minimizes the fillrate requirements.

See here:

which shows it working on the ground texture.

i doubt turning off depth testing for particles will matter.

As well as hardware depth testing (so the particles interact with the animals), the particles and models also can do a depth check against the custom encoded RGBA depth texture for the background, so they go behind trees etc. This is an extra texture read and calculations in the fragment shader so did give a speedup when turned off.

try single sample shadows instead of multiple samples.

Yup I definitely found this to be the case.

This topic is closed to new replies.

Advertisement