Maximum Vertex Lights in a Scene

I know that Light.pixelLightCount is a great way to find out the maximum number of pixel lights that either your graphics card can handle or your quality setting will allow (not sure which or both), but is there a way to find out the maximum number of vertex lights?

The way my scene is set up, the internal calculation of the closest vertex lights is messed up and I would like to set them myself. Thanks.

(This was originally accidently posted in the Unity Support forum.)

The reason I say my scene is set up so that “internal calculation of the closest vertex lights” (or any light for that matter) is that it contains a fairly large flat surface with lights all the same height above it throughout the scene (think like a large warehouse).

I’m planning on using a top-down view, so I’m not worried about distant lights being turned on. I’ve tried splitting the floor into smaller chunks, but the seems between them are very visible and I’ve had objects fall through the cracks.

Any ideas? Thanks.

You could place a giant single pixel spotlight above the scene with a cookie that matches the roof lights.

Light.pixelLightCount is what is set in the quality settings. It will force some auto lights to become vertex instead of pixel depending on brightness.

What exactly is the problem? what does it look like? I bet you really should instead be using some other lighting method.

Hmm… the cookie idea is interesting. I really want realism, so I want multiple shines and glares off of the player character (3rd-person view); this is why I want many lights in the scene. The problems I am having is it picks a bunch of lights to be pixel (4), a handful more to be vertex (8 additional), and the rest are off.

I wrote a script that once per second it loops through through all the lights in the scene with a certain tag, turns on the 4 (or how many ever Light.pixelLightCount gives me) closest ones to be pixel and the rest to vertex. The scene looks good and I don’t notice the lights going from vertex to pixel as I approach them, however, I do notice them going from off to pixel because it still chooses 8 lights to be vertex lit at start and some get left out.

Is looping through and turning them on and off by hand stupid? I think I read somewhere how Unity/OpenGL calculates which lights should be pixel or vertex and it seemed to me to be related to object size, not camera position or view. Thanks for your help.

This sounds like a lighting nightmare. Why don’t you bake the lightness from the roof lights into your ground texture in a way that makes sense and is aligned with the roof lights, then make them only shine on the player using layers and the culling mask. Make them all Force Pixel and maintain only the closest 4 on at once. Then for slow cards just make them Force Vertex instead.

Interesting idea. Still, I feel I’d have to give up some features and have to do a whole lot of work to get it back, such as levels being able to be set up in Unity or from a file. That’s an idea, though, to have the culling mask ignore the floor in calculations.

This all makes me wonder, how do other people do it? If you have one big mesh as your terrain, how do you have lights by the player on and not the ones on the other side of the map? Is this normally done by splitting the terrain into smaller meshes? Will smaller meshes help Unity give priority to turning on lights within the field-of-view/by the camera? How do you keep things from falling through the cracks? Help with post-haste is greatly appreciated (I have to present this game design project at a national conference in 6 days)!

If you don’t like how unity handles lights, handle them yourself. Personally I would avoid ever having that many lights in the first place. If you have to have them I still think you should reduce your light count as much as possible with baking type things. Other wise just handle them yourself and turn off ones outside off the view area.

I’m thinking for the sake of time, I may leave my Vertex light moving script, but have one big directional pixel or vertex light above the scene like you suggested. Thanks a bunch for your help.

Still, if anyone can tell me how to figure out the maximum number of vertex lights on in a scene, you know what to do.

What? You can make as many lights of any kind as you want. It will just get slower and slower…

It would really help if I knew what you are actually doing/what you actually want.

In fixed function OpenGL, you can have up to 8 vertex lights taken into account.

So the 8 brightest vertex lights affect your meshes in Unity. You can split up the mesh cleverly if you need to simulate more. You can of course have more lights inside of a Unity scene. Just up to 8 get taken into account per mesh.

-Jon

Some pictures. Editor quality: Fantastic, I can see all 4 pixel lights when they’re turned on, using a Radeon Mobility 9700 64MB in a PowerBook G3 1.5Ghz 17".

1st: Only vertex lights turned on. Notice lack of lighting on the left side.

2nd: All lights selected so you can see them. Yes, each light is double (top and bottom) making a lot of lights (18), but the issue remains: does Unity/OpenGL have a max vertex light limit or not?

3rd: The 3 lights in the scene selected that I just turned on to “force pixel”.

33379--1215--$gsm_a_all_vertex_167.png
33379--1216--$gsm_b_all_vertex_selected_533.png
33379--1217--$gsm_c_3_pixel_selected_968.png

Funny how you have to attach in opposite order and the file caption don’t appear by the image. I know, it’s not your engine (PHPBB?)

4th: Notice how the 3 forced pixel lights in the bottom-right allow the previously-dark vertex light on the left to light up the floor. If you save this and the 1st images, open them together in Preview, and toggle between them, you’ll really see the differences (such as the left light being dark on the floor, but not the wall by it).

33380--1218--$gsm_d_3_pixel_136.png

Yes, in Unity the first N lights on an object are pixel lights (set in quality settings), then usually 8 lights are vertex lights (that’s the limit imposed by the hardware). If there are more, they increase the ambient (again, per-object) a bit.

The usual solution is: don’t have that much lights. For the environment, bake that into lightmaps or vertex colors. For the characters, use fewer lights (using culling masks so that they only affect characters). And then characters are usually much smaller.

I know, but I like to push the limits. (;-)) If you don’t mind my asking, is there anything wrong with (efficiently) hand assigning the 8 vertex lights? Will it be fewer than 8 on older hardware? (I’m actually using a PowerBook G3 400/Pismo with an ATI Rage Mobility 128 8MB for a test machine and Unity actually works!) Thanks again for everyone’s help.

No, there’s nothing particularly wrong. But keep in mind that the brightest lights are selected per-object, not per-scene.

In theory there could be hardware that can do less than 8 vertex lights; I’ve never seen one though. I think some of old hardware (GeForce2 era, with old drivers) dropped into software vertex processing when more than 4 lights were used, but technically it still works, just slower. ATI Rage on the other hand does not have hardware vertex processing at all, so it always does lighting on the CPU.