Sign in to follow this  
tokaplan

Vertex-based lighting vs. pixel-based lighting

Recommended Posts

Hi everyone, I'm just wondering how much slower it is to do per-pixel lighting than it is to do per-vertex lighting? I mean, there are generaly much more pixels than there are vertices, but since hardware has to interpolate anyway, how significant is the difference in the end? Thanks

Share this post


Link to post
Share on other sites
If you have a pre-GeForce 2 card, then the difference could be substanital. Otherwise the performance will almost certainly be unnoticible. As always, profile and see if it makes a difference in your case.

Share this post


Link to post
Share on other sites
The ratio in performance between the two approaches is roughly determined by the ratio of numbers of needed calculations in each approach.

In per-vertex Gouraud lighting, the actual light formula is evaluated only three times - once for each triangle - so the lighting is cheap to begin with.

If you're evaluating the same formula for each pixel, consider that there are usually a lot more than 3 pixels filling a single triangle. Therefore, while the lighting algorithm would be exactly of same complexity as in per-vertex approach, the quantity of calculations (and conversely the needed GPU time) will, in general, multiply great many times over with per-pixel lighting.

Of course, if fillrate isn't your bottleneck to begin with, you won't notice the performance difference.

Share this post


Link to post
Share on other sites
Lighting speed depends highly on the chip. A Radeon X1900, for example, has 48 pixel processors and only 8 vertex processors. Using complex vertex processing and simple pixel processing is a waste on this chip. Things are different for different chips. In general, modern chips are designed to do a lot of arithmetic per pixel. Simple per pixel lighting would not tax them greatly, even at the low end.

Share this post


Link to post
Share on other sites
Uhm. Are you writing this because of the conventional wisdom or because of tests?
It's a bit sad to say but my experiments with a very complex lighting shader (30 attenuated point lights) ended up being roughtly 5x faster on vertex processor, even with 2 tris per pixel!
Ok, it wasn't a real world example. No one can really afford that degree of tassellation on real assets.
Please, avoid the temptation to say "I have more pixel processors, so there's more power there"... yes it may be but there's also a lot more work to do... and we all know vertex processors are usually better at a few things (branching performance anyone? dynamic uniform array indexing on VS/PS 3.0 hw?). This kind of comparisons are simply meaningless.

Share this post


Link to post
Share on other sites
Just to add some points gained from experience: you usually don't just do lighting in the pixel shader, you do more. Some texture fetches at least, maybe some stages of parallax mapping, and so on. And you don't do everything of the lighting procedure in the pixelshader, some of it can easily be done per vertex without using quality. In our test cases, difference between vertex lighting and pixel lighting was about 10% in average. Considering the visual quality you gain by using it (plus Normal Maps, that is), it is definitily worth the performance.

Bye, Thomas

Share this post


Link to post
Share on other sites
In more conventional computer graphics it's essentially the difference between Gouraud Shading and Phong Shading (Note: Phong shading is not the same as Phong illumination [wink]). Throw those into your favourite search engine and you can pull up loads of info...

As for the hardware details - my understanding of the VS:PS ratio is that it comes from the relative work-loads. Effectively a fixed form of load-balancing, 48:8 implies 6 pixels for every vertex. Rather than the VS or PS units being more/less powerful on an individual level.

This becomes a moot point going forwards as we're heading torwards unified architectures with proper runtime load-balancing. Think G80 and R600 here.

My section of the upcoming Programming Vertex, Geometry and Pixel Shaders with Direct3D 10 covers quite a lot of this sort of thing. I make several cases of LOD lighting whereby you can switch between per-vertex or per-pixel according to performance/quality metrics. IMO there isn't really a single correct answer to this as it all depends what is more important and what the target hardware/usage is...

hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this