Lightmapping in iOS + VFX Lighting

Boiling it down to simple terms: “I want a flashlight!”

I am just now experimenting with Unity’s lightmapping for an iOS project, and so far it’s working well. As this is targeting the iOS, I’m only using a single light map.

http://new.tinygrab.com/ce82f3b13df5dc799c899a98f8686cac.png

What I am discovering is that when the “Use Lightmaps” check is selected:
http://new.tinygrab.com/2f71e7bf473cf0258e7dbb74749b0b4f.png

… none of my other lighting works.

I don’t have much additional lighting, but I do have a few VFX interactive lights, the main one being the equivalent of a flashlight. I was expecting this to work alongside the lightmapped objects, but I can’t seem to find the proper set-up for this. The built-in lightmapping seems to just ignore any lights on objects that are lightmapped.

Am I missing a set up?

Can I take these generated lightmaps and use them with a different shader?

What’s the best suggestion…

Additional information:

I’m setting my VFX lights to RealTime Only (even tho’ I’ve tried all of these settings…)

Is this simply an issue of (potentially) using the Vertex Lit Render Path?

I’m a bit confused when it comes to the render paths for iOS. The manuals indicate that on the advanced devices, Forward Rendering is possible:
http://new.tinygrab.com/52eb9e4d398ea4ec5b7bdd481cac8611.png

… but in the per-platform settings, you can only set the render path for Web and Stand-alone. There is no render settings button in the iOS.
http://new.tinygrab.com/e26c50aa589b8c27fcb32823a87a5a4b.png

http://new.tinygrab.com/3f44e77023de33a564fa9e88bb5d02e7.png

http://new.tinygrab.com/ab6c15aaa2ce6f2d75eadfb95bc6beea.png

On the other hand, this setting seems to be global and shared. If the developer decides to use forward rendering on the iOS, do they need to set this in one of the other build target windows?

There is a lot of information on the iOS, lightmapping and render paths:
http://unity3d.com/support/documentation/Manual/Optimizing%20Graphics%20Performance.html#iPhoneOptimizingGraphicsPerformance

http://unity3d.com/support/documentation/Components/class-LightMapping.html

None of this mentioning our wonderful custom google search engine:
http://www.google.com/cse/home?cx=001712401338047450041%3Acsfhqk-trfa

for searching the docs and forum.

So far, I’ve got zippo on this particular issue.

I also can’t seem to crack what the Lightmapper is actually doing or where it’s saving the uvmapping. Is this exportable? Can I bake my levels in Unity and then utilize the maps and coordinates with a different shader that will be effected by dynamic lights?

Will I have to look into lightmapping externally? This seems a shame…

I’ll take any hints and/or suggestions.

On mobiles there is no renderpath setting cause there is none to set, its always forward given you are on OES 2.0 (mobiles don’t support dynamic shadows at all and alike, so there is little reason to use deferred. Also it would be worlds to taxing). With ARMV6 targeting its vertex lit only as there is no shader support then and thus also no forward rendering or pixel lights.

The UV mapping done on mesh import (depending on if you allow it or not in the mesh import settings) and then stored in the engine mesh representation generated from the mesh you import.
The lightmap shader code itself is added as part of surface shader compilation, so all surface shaders that don’t disable it basically support lightmaps, no extra work required and any surface shader you do yourself will go that path.

If you write an own non surface shader or glsl you could potentially add it, there are a few threads on the matter of how / how not to try doing this from what I recall, unsure on the state of that knowledge and possibility though, as I didn’t need it so far.

Thanks Dreamora.

Ratz.

So, the bottom line is: No?

I’ll be the first one to admit that shaders are not my strong point.

I understand now that the lightmap shader code is added by Unity during shader compilation (this makes sense, and I suspected something like this…), but…

I don’t understand one point, which could be from my lack of technical experience:

Does this mean that: “No surface shader with the Unity Lightmapping code will accept additional dynamic lights on the iOS”? That’s what I’m reading. Did I misunderstand? (Sometimes I need to be hit with the information wrapped around a brick to get it into my skull…)

Can you imagine anyway I can use single-pass lightmapping and a dynamic light as well? I don’t seem to be getting this in any case I can come up with in the editor.

Can some one comment on whether there is any value at all in experimenting with a pipeline that includes external lightmapping in a 3D package, importing this lightmapped model/texture pair into Unity and using a texture/shader combination that would accept dynamic lights on top?

I’m struggling a bit as game play and level design have been (so far) based on the concept that I could have dynamic lights in the scene. Lightmapping is so effective on very simple geometry that I’d loathe to give up the beauty pass for a technical reason.

(I thought I’d put this in the post, but…)

You can add shadows to single pass lightmapping:
http://new.tinygrab.com/c258b216d8465832faa3186ef855135c.png
http://unity3d.com/support/documentation/Components/class-LightMapping.html

So I assumed that you could add dynamic lights as well…

This brings me back to the render path as the possible problem? (Since you can’t use shadows on the iOS…)

And blob shadow projectors add to the lightmapped surface, but a VFX point light does not, and neither do spot lights.
http://new.tinygrab.com/53ab9cff230d896e0a5864b0c3553c2c.png http://new.tinygrab.com/73bef1f5382234215364ab896293b5a7.png

http://new.tinygrab.com/f5984a4a93b8af49a7b6a6b7e5bed5ed.png http://new.tinygrab.com/4abf1edf6c9208cf4c1b1ac1a9c6fd00.png
Lightmapped VFX Light doesn’t work… Not Lightmapped VFX Light works.

Why would a blob shadow add to a lightmapped shader, but not a light?

http://new.tinygrab.com/06faa83c80765b7a4bea634a61b000e7.png/IMG] http://new.tinygrab.com/1a093d71248c6277d7e211791e49a55f.png
Again: Lightmapped and Not. With the effect light not working with the lightmap, but working while vertex lit.

Incidentally I’m researching the very same thing. I want a flashlight in my iOS game too! :slight_smile:

Today I also experimented with a blob light projector, which seems to produce acceptable results in combination with Unity-lightmapping. However, the contrast is a bit poor since the multiply of the lightmap will usually drown the additive blob. There’s a lot of black and a little grey this way, but no white.

Simply duplicating the light projector does increase the effect, but it also affects performance of course.

Will keep an eye on this topic, and if I find anything, report back!

And there I thought I was caught in my test sandbox - alone with Penelope!

I’ll let you know what I find out.

After finally getting your real intend and problem from the last posting I did some tests:
I didn’t have any problems to make it show up and brighten up an otherwise dark area.
so here a short summary of what I have:

  1. Requirement for it was, as mentioned previously: ARMV7 targeting, Light marked as realtime (don’t think it has an impact but I own U3 iOS Pro). If you want to see it in editor, don’t forget to change graphics emulation to OpenGL ES 2.0 (2nd from top) the rest won’t show it cause they have no pixel lights

  2. Shaders were simple default diffuse. Ensure to not have vertex lit shaders cause vertex lit ignores pixel light by definition and design

  3. lightmap was a simple beast lightmap, 50 texels, single directional light generating it

Mmmm…

I see it.

It was the original shaders. They are set to vertex lit. I made the assumption that once they were lightmapped that it was the lightmap shader that took over… but as you pointed out above, if it’s tacked on at compile-time, then yes, it wouldn’t show.

I’ll hop back on and give that a tweak and check. (Testing is slow going with tweak, render, wait…)

Yup!

That does it:
http://new.tinygrab.com/c16d55f3c63c4dd3bf48765c3ef943c4.png

Toggle the player’s light:
http://new.tinygrab.com/ef8210bf707aeb6a2ea27147b0a0cb48.png

Which is good! (Means older phone owners are screwed in one fashion or another, but …)

And the light mapping is looking good. Test geom and a simple brick texture, map it, and it shows promise! Still working out the subtleties of the pipeline.

Dre, thanks for the research.

Thanks dreamora, I guess I was trying too hard. Went back to basics, and indeed it works perfectly out of the box! Really cool stuff, can’t believe it’s so good on iOS! =)

No prob, glad it solved it :slight_smile:

One warning though: keep in mind that each object thats touched by light is redrawn a second time for this purpose. So you will want to limit the light range correspondingly or only make it affect rather simple objects with no transparent / transparent cutout material.

As for older devices being screwed: actually not, cause there it will run on vertex lit which you discovered to work, within its limits naturally (vertex density).
The main prob with older devices can become the lightmap itself as on pre 3GS, you have 22-23MB at max cause the VRAM is limited to 24MB and the rest goes into backbuffer, frontbuffer and depth buffer.
With newer ones its not limited to a fixed amount, it could use the whole RAM.

I guess what I meant about older devices being screwed is that, as my game currently expects (really requires) this lighting effect, otherwise it’s really unplayable. On older devices, I’ll have to somehow detect what device is running and disable lightmapping. Even though the device will run in vertex mode, it seems that is runs in vertex mode with lightmapping on which leads us full circle back to the flashlight not working.

Here’s a test with lightmapping and GLES2:
http://new.tinygrab.com/8bc213e3ea82fe479e4c6bdd45cba8c2.png

And here it is using no lightmappingand MBXLite emulation:
http://new.tinygrab.com/28a1827d6b536a1eeb67d038baf1f13c.png

And that is with a presubdivided wall:
http://new.tinygrab.com/c2196f67f1fec075d0503843b030732c.png

With lightmapping only, I could consider making that one wall a single quad…

Things to think about. I could just say “works on later models only”, but I currently have the iPhone 3G (not S) as my minimum target.

To be honest, after finding out the huge differences in quality, I’m going for 3GS and higher for my game. What’s the iPod equivalent again? Cheers!