Wednesday, April 4, 2012

2d shadows with multiple light sources


On iPhone4 with retina, render 3 objects with 5 point light sources. To test the limitation of GPU, I achievement this by 4 passes:

  1. render every objects on a texture (shadow map).
  2. render background on the frame buffer.
  3. render point light one by one, multiple pixel color with alpha on shadow map (shifted coordinate).
  4. render all object again.
This scene can be rendered in 30+ fps. I think it can be better with more optimization, but the defer method seems not good on this platform.


當二維的場景需要影子時,大概都會直接貼圖搞定吧,這次碰到可能需要多光源的情況,就想試試 defer rendering   加 shadow map  的效果,雖然伙伴們說應該不會碰到這種情況,但是我手癢,所以就花了一天亂試,效果還不錯,但是效能上需要改善,主要的瓶頸大概是:

  • alpha blending 讓 tile based defer rendering 沒辦法加速。
  • fill rate,在我的 iPhone4上,5 個batch填 130x100x100x4 pixels, 差不多是60fps的極限(大約可以填滿八個retina 全螢幕)。
  • batch,defer shading 的大量光源需要大量的 batch。我用 40個batch畫 100x100x4 pixels,就開始不到 60fps了。

No comments:

Post a Comment