The main reason your performance is suffering is because of the large number of dependent texture reads you are performing. Every time you use a texture coordinate that has been calculated in the fragment shader as a parameter to texture2D(), the thread processing that fragment will have to stall until the texture data is retrieved. POWERVR hardware is capable of hiding the latency of a few dependent texture reads as the hardware will schedule in other threads until the data is retrieved. When a large number of dependent texture reads are performed, the hardware will reach a point where all queued threads are waiting for texture data.
You should perform independent texture reads where possible instead of dependent reads. Independent texture reads are performed by the hardware when the texture coordinate is already known for the fragment before it is processed, which means the hardware can pre-fetch texture data (e.g. the texture coordinate is a varying or a constant value). For example, if you calculate vTextureCoord * Aspect in the vertex shader and pass it to the fragment shader as a varying, 5 of your texture2D() calls will be independents and faster.
Ideally, you’ll want to reduce the number of texture samples you have here as much as possible. If you can, you should pack textures so instead of only retrieving the data in the .r channel, you could be retrieving data in all .rgba channels.
If you can either post a picture of your rendered effect here, or send it to devtech@imgtec.com I can advice further. If I can understand the end effect you are going for, I think I’ll be able to suggest further optimisations
Some more details… Top and bottom variables are used to give a sense of depth to the scene according to what is below and above current pixel.
texColor * (1.0 - variable.channel) … or texColor * variable.channel is doing the masking according to the color and picks the correct texture. This avoids using ifs and color comparison.
Any more tips would be appreciated, I will try then out and let you know =P
After modifying the VS and FS to the ones below, when trying to add the depth color component (bt) the shader compilation fails, that’s it no other error messages. Tried several things but I wasn’t able go around the problem.
But for instance outputting bt as the final color, it looks correct. check the pics below.
Good thing is that the performance increased 10 fps.