Multiple Lights on game map with forward rendering

Started by
12 comments, last by JohnnyCode 9 years, 3 months ago

Really though, are you sure you can't just send all lights at once?

Just to expand on this question, if the original poster is believing he or she has not enough uniforms etc., this is likely because he or she are using an overly complex lighting model designed after the fixed-function pipeline.
The fixed-function pipeline has a lot of parameters that are generally not useful just because it was fixed-function. Back then that was the only way to make all artists (somewhat) happy, and also a time when accurate lighting wasn’t a thing.

For a point light, you only need a color, position, and range. This means 2 vectors: [Cr, Cg, Cb, Range], [Px, Py, Pz, 1]. You don’t need specular color (it should always be the same as the regular color), ambient color (a nonsensical value), and 3 attenuation values.

Similar madness can be avoided by not following the example of the fixed-function pipeline for directional lights and spotlights, allowing you to easily double or triple the number of lights you can have with the same number of uniforms.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Advertisement


NB: all the game I've seen showed like ~32 number of lights. But I'm not sure if it's "hardcoded" to their engine. (I can't imagine looping thru 32 light properties in the shader just to compute 1 pixel's color)
Well, I did that as an experiment years ago on a GeForce 6600 GT, 128bit GDDR3. It did work (with quite fine parallax occlusion mapping) albeit not smooth enough to be used in production.

I would expect modern mobile to match that performance level at least on some silicon but since a lot of devices have hi-dpi screens I cannot really promise anything.

If you are sure you always have a high light count, consider deferred.

TL;DR: it is possible and sometimes viable to iterate them. Whatever it is in your case it's another matter.


If only I could store light properties in a texture and read em back in the fragment shader, that'd be great.

Wouldn't this be the same as a lightmap (or more like deferred shading)?

Absolutely not. Deferred is (sort of) splatting your lights on the (not quite) "finished" scene.

What he plans to do here is to use texture as an array (as a side note, this is what I did years ago).

It is doable... but be careful with instruction counts. Your shader might get killed after a while. This will be probably both hardware and driver-dependent. Proceed with caution!

Previously "Krohm"


What he plans to do here is to use texture as an array (as a side note, this is what I did years ago).

Oh, I think I understand now. Passing the lights into a texture only to get around the uniforms limitation.

I didn't think of that first. I thought he was talking about storing those Unity 3 harmonics coefficients in that texture. I worngly imagined those being used as a sort of g-buffer. I don't suppose Unity's shaders are open source though, anyway.

You really do not have to be dependant on the pixel function registers limit. Simply do not interpolate light vectors, but feed the lights as uniforms to the pixel function, and interpolate only data necessary for the computation that stays constant for all the lights (normal, object space position). Redesign shaders if neccesary, then the limit of lights will be lifted much higher. Yet! you should never shade more than about 32 lights, apply culling and combining upon player observation of course.

This topic is closed to new replies.

Advertisement