To Defer or Not To Defer

Started by
4 comments, last by Promit 10 years, 11 months ago

I've had my eye on deferred lighting for a while. In my renderer, I've tried sending an arbitrary amount of lights through a shader and using expensive loops per-pixel, and an attempt at forward rendering that requires me to draw the screen a bunch of times which is also very expensive.

However, it sounds like deferred lighting still requires a forward renderer for transparent, reflective, or refractive objects. Is that correct? I could understand if this is the case for transparent objects, but not for reflective/refractive objects since you could just render the scene to a cube map with deferred lighting applied to it. Also, if I'm wrong and reflection and refraction is possible, then why not just make all transparent objects refractive with a refraction index of 1? Sure, cube maps can be expensive, but then again, everything is at least a little refractive. It could us to abuse refraction and reflection more since the maps are updated anyway.

Now, here's the biggest problem I face: all of these are pretty tough on mobile hardware. MRTs won't be an option on mobile hardware until Open GL ES 3.0-compliant devices are mainstream since Tegra 3's the only hardware I know of that support it as an extension... My shaders for mobile allow you to have up to 1 of each light enabled: global (directional), point, and spot light, but that's quite a bit too. Would supporting light maps be the best way to go for mobile devices?

Advertisement

However, it sounds like deferred lighting still requires a forward renderer for transparent, reflective, or refractive objects. Is that correct? I could understand if this is the case for transparent objects, but not for reflective/refractive objects since you could just render the scene to a cube map with deferred lighting applied to it. Also, if I'm wrong and reflection and refraction is possible, then why not just make all transparent objects refractive with a refraction index of 1? Sure, cube maps can be expensive, but then again, everything is at least a little refractive. It could us to abuse refraction and reflection more since the maps are updated anyway.

Now, here's the biggest problem I face: all of these are pretty tough on mobile hardware. MRTs won't be an option on mobile hardware until Open GL ES 3.0-compliant devices are mainstream since Tegra 3's the only hardware I know of that support it as an extension... My shaders for mobile allow you to have up to 1 of each light enabled: global (directional), point, and spot light, but that's quite a bit too. Would supporting light maps be the best way to go for mobile devices?

The reason transparent objects are usually done with forward rendering is because you have to render in a specific order. If you just rendered using your reflection cube map, then you wouldn't be able to have multiple layers of transparency. Also using a cube map for transparency would probably create artifacts because reflection cube maps are usually lower resolution.

I think that if you're targeting current mobile hardware then deferred lighting is not really that wise a choice. If you're playing a long game, or you're just playing with it then maybe that's OK, but fill rate is so restricted on many mobile chipsets and MRT support so limited that I'd advise against it. There's an article on light prepass rendering which is probably more viable than full deferred on mobile, but I think you're still going to get better results with forward rendering http://www.altdevblogaday.com/2012/03/01/light-pre-pass-renderer-on-iphone/. You mention light maps, if they're a viable approach for your project then use them as they perform very well on powervr chips.

Some thoughts:

Mobile devices generally have really small screens. Is deferred rendering really worth it?

As for rendering the scene to a cubemap with deferred rendering, well that just sounds ridiculously expensive, and again, mobile hardware

No MRTs means multiple full-scene passes. Thats however many buffers there are in the gbuffer, x7 (1 for screen, 6 for a cubemap).

We tend not to use refraction on most transparent objects because it's quicker to use normal boring alpha blending. (Did I misunderstand you here?)

I was playing Black Ops 2 earlier, and I noticed a weird transition on the reflections on my golden gun whenever I exited a room. That I suspect is caused by the engine using pre-baked cubemaps.

Lightmaps can look absolutely gorgeous if well done.

Yah, definitely not a mobile thing yet unless you're targeting quite far into the future. If you're using OpenGl ES 3.0 or above as your minimum spec, and have some large art requirements the equal of current gen consoles games or better, and are exclusively targeting Tegra 4 or above as your spec (and Tegra 4 isn't even fully 3.0 compliant) then I don't see what benefit you'd gain.

The reason transparent objects are usually done with forward rendering is because you have to render in a specific order. If you just rendered using your reflection cube map, then you wouldn't be able to have multiple layers of transparency. Also using a cube map for transparency would probably create artifacts because reflection cube maps are usually lower resolution.

The reason transparent objects are rendered using forward rendering is because MRT in DX9 class hardware cannot selectively use one channel from one render target as the alpha channel and not use the same channel from the other render targets in a similar way. In other words, if you have 4 render targets each with an R,G,B,A channel and enable alpha blending, then the alpha channels of all 4 render targets are considered not just the alpha channel of the 1st render target (if that's the render target/channel that represents your alpha component in your G-buffer). This generally yields an invalid visual result. Anyway, with > DX9 class hardware you should be able to selectively blend using individual channels from selected render targets.

Deferred style renderers are a terrible idea on mobile due not only to bandwidth limitations, but cache issues and other memory issues related to the fact that the dominant mobile chips are tile based deferred renderers running in very tight constraints. I'm also finding that at very high resolutions (4K and above), deferred starts to behave very poorly with respect to bandwidth. I'm planning to investigate tiled-forward as a better alternative on modern hardware, though it doesn't seem to have gotten much attention yet.

In general, I think it's safest to treat mobile devices roughly as if they were desktop GPUs from approximately 10 years ago, give or take.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

This topic is closed to new replies.

Advertisement