- Home /
Shader optim ?
Hi, I have this shader that allow me to affect a sprite with some darkness effect as some kind of whirlpool and to display some light and dark area on a texture.
But on iOS, this is a huge overhead for some device (iPhone4, iPad2) so I just want to know if there is a way to optimize this a little bit ?
Thanks in advance
Answer by MakeCodeNow · Oct 08, 2014 at 04:33 AM
The main thing you want to do is move the UV calculations (things that modify i.tex) from the pixel shader to the vertex shader. I think you'll want 4 sets of UV texture cords. One that is the existing i.tex, two that is used to access the waterSamples, and one for bgDark. By computing this data per-vertex you will save some ALU time but most importantly you will prevent the iOS GPU from doing dependent texture fetches, which are super slow.
On iOS, you pretty much never want to compute UV coordinates in the pixel shader. You always compute them in the vertex shader and then pass them to the pixel shader. Also, never pack 2 sets of UVs into a single float4. Always use float2 for UVs because the GPU won't properly prefetch UVs in the zw components.
erf. I don't even know how to switch some code part from frag to vertex without blow everything in my shader. Still in progress...
You'll get there. It's a good skill to develop.
PS - please mark answer as accepted.