Home Unity

Rendering normal map information to lightmaps

easterislandnick
polycounter lvl 17
Offline / Send Message
easterislandnick polycounter lvl 17
I was looking at the UDK app Epic Citadel and it seems like they are baking their normal map shadow information to their light-maps, as the lighting is static in the scene they don't have to render normal maps at run time but still get lovely bumped effects baked in.

Is this possible with Unity? Has any one managed to get this up and running? I was looking at the advanced Beast settings but could not see any setting for taking normal map information into account when rendering light-maps. If I can bake normal map shadow information into light-maps and at runtime only calculate specularity I think I could achieve a very hi-end looking game on ipad2/3.

Replies

  • cupsster
    Options
    Offline / Send Message
    cupsster polycounter lvl 11
    Directional Lightmaps is way to go
  • bugo
    Options
    Offline / Send Message
    bugo polycounter lvl 17
    Exactly, but they only have this feature on Unity Pro. I wish I could know if this works on iOS, anyone?
  • Eric Chadwick
    Options
    Offline / Send Message
    Dual Lightmapping is the Unity method for this.
    http://unity3d.com/support/documentation/Manual/LightmappingInDepth.html

    I have Unity Pro here, but haven't tried it on iOS.
  • easterislandnick
    Options
    Offline / Send Message
    easterislandnick polycounter lvl 17
    Not really what I'm after as I don't want to use normal maps on my level at run time only during the bake process as it's too costly for ios devices.

    My thinking is that a scene that has static lighting always has the same shadows generated by normal maps, so why not bake them into the light-maps and not generate them at run time?
  • Ged
    Options
    Offline / Send Message
    Ged interpolator
    Ive also been looking for a way to do this. I would like to bake in shadows and specular and normal map shadows in unity. Even if it means my object can never move and the specular doesnt change it would be a nice effect. I guess I will just have to bake it in my cinema4d and include it all in the diffuse.
  • bugo
    Options
    Offline / Send Message
    bugo polycounter lvl 17
    Speculars can't be baked, or it would be color/albedo anyway, you will have to have at least one non-static light on your scene using dual lightmapping to get specularity.
  • Eric Chadwick
    Options
    Offline / Send Message
    FWIW, from what our programmers tell me, directional lights are much more performance-friendly than either point or spot lights.
  • easterislandnick
    Options
    Offline / Send Message
    easterislandnick polycounter lvl 17
    Yeah, specular can't be baked but I could use a masked per vertex specular as they do on Shadow Gun which is pretty cheap, combine that with baked normal and it would look great on iOS. Any ideas if it's possible anyone???
  • Farfarer
    Options
    Offline / Send Message
    I think you'd have to bake it in an external program, into a baked diffuse (or to your own lightmap textures).
  • Eric Chadwick
    Options
    Offline / Send Message
    But baking normal maps into your lightmap will require the lightmap to be a fairly high resolution, right? And this means a significantly larger download (and memory cost).
  • bugo
    Options
    Offline / Send Message
    bugo polycounter lvl 17
    @easterislandnick: I agree with Eric, it's not the goal to bake nmap light info. You should probably be able to use nmaps on iOS if you're not using an expensive shader, if you use specular + nmap it gets expensive for iOS. You will have to choose inbetween the two. I wouldn't go for that path, why do you need both?

    Shadowgun uses a vertex specular + mask specular which creates a fake specular effect. I don't know if adding nmaps to it will decrease performance, probably.

    They used nmaps + probes ONLY on their characters, so I imagine you can't (for an iOS game). I'm taking iPad3 out of consideration.
  • easterislandnick
    Options
    Offline / Send Message
    easterislandnick polycounter lvl 17
    A single lightmap is only 1.3 mb, a couple isn't going to be too much of a memory hog. I'm creating fairly enclosed environments so 3 1024s should give me fairly good lightmap resolution. Yeah, specular and normal maps per pixel is expensive on iPhone but I can make it really cheap if I bake the shadow information into the lightmaps. The only reason not to bake the normal shadow information into lightmaps is because it will increase download and runtime memory but people are willing to download large beautiful games (look at infinity blade) and the iPhone has a relatively large amount of memory so allocating about 4mb to lighting all of my environment with lovely looking shadows seems pretty great to me.

    Every one is expecting the next few years of iOS games to look more like their console big brothers and sticking with diffuse and a bit of faked spec isn't going to cut it. I need to implement a decent set of shaders that can let me fake all types of believable materials.

    In my mind the only reason not to do it is because no one knows how to do it! (including me!)
  • Elyaradine
    Options
    Offline / Send Message
    Elyaradine polycounter lvl 11
    Er... as far as I know, if you split it into 3x1024, you triple your draw calls. Have fun with that on mobile. :P

    (Test it first maybe, but I seem to remember this being a problem for us.)
  • easterislandnick
    Options
    Offline / Send Message
    easterislandnick polycounter lvl 17
    Could be an issue with draw calls, I would have though that if you only have one lightmap per object you would be okay and static batching would be fine.
  • Elyaradine
    Options
    Offline / Send Message
    Elyaradine polycounter lvl 11
    Batching batches stuff that uses the same material. The "same" material is the same shader, with all of the same textures plugged in. If things use different lightmaps, they're effectively using different materials too, as far as I know.

    (And batching works great for stuff that uses only one lightmap, but it also creates a new "batched" instance of the meshes in memory, so you're effectively using up twice as much memory for your meshes. Which... may or may not be an issue, depending on your game.)

    Anyway. Baking your normals into your lightmap sounds cool. From my experience, I just don't think it's practical.
  • bugo
    Options
    Offline / Send Message
    bugo polycounter lvl 17
    @easterislandnick: Dude, depends on the size of your scene, if your scene is big and to get the same pixel ratio of your normal maps, it can get quite of a big map. I'm not sure what you are looking for over here. I don't know how UDK does it, but it's probably a way of rendering static meshes that have nmaps, but I highly doubt they are the same pixel ratio as the textures theirselves.

    Have you thought about baking this light information of your normal maps on the diffuse map? It's a matter of not rotating the textures. Might look cool!
  • easterislandnick
    Options
    Offline / Send Message
    easterislandnick polycounter lvl 17
    Yeah, they won't be at the same resolution as the diffuse. In UDK it's a one click solution, "If you enable "Use Normal Maps For Simple Light Maps" in the World Properties Lightmass Settings section, normals maps on a mesh will be merged into the simple lightmap. This will give improved lightmaps, but can cause slower lighting build times as it has to process the extra texture." They do it and it looks great on an iPhone 4. A lot of people here are acting like this is a crazy idea, but it's tried and tested on a multi million selling game!

    If no one knows if it's possible in Unity then that's fair enough.
  • Farfarer
    Options
    Offline / Send Message
    It's probably possible in Unity with scripting, if you roll your own lightmapping algorithm.

    It's not in there as a default option, however.
  • bugo
    Options
    Offline / Send Message
    bugo polycounter lvl 17
    @easterislandnick: I think you misunderstood what UDK does, it probably creates a fixed normal map light direction and converts that to pixel on realtime. It's not possible to bake that info into a map for the whole environment, memory wise it's not smart. It probably just fixes the normals to a light direction somehow. I will research a bit more about this and come back here, cause it's interesting.
  • easterislandnick
    Options
    Offline / Send Message
    easterislandnick polycounter lvl 17
    epiclightmap.jpg

    Uploaded with ImageShack.us

    It does seem to be baking to the lightmap, there are some directional lightmaps in the project, I'm not sure they are used at runtime? It's clever stuff any way! The citadel demo has a huge amount of lightmaps, not sure how they fit it all in to memory at runtime!
  • bugo
    Options
    Offline / Send Message
    bugo polycounter lvl 17
    oh, but that is not near close to the resolution of the diffuse, is it?
    You know what's funny, I see some stains going on too, wow, im curious where those come from... thanks for showing.
  • commander_keen
    Options
    Offline / Send Message
    commander_keen polycounter lvl 18
    You should be able to do something like this in Unity by using Directional Lightmaps and doing a post process on the resulting lightmap files using the light normal map, along with the normal map of the individual normal maps from each lightmapped renderer. Its pretty complicated but possible. You would also want to define a custom lighting model for Directional Lightmaps and use that in all your shaders to disable the normal Directional Lightmap shading.

    Directional Lightmapping is already pretty cheap, and if you still want specular then you still "need" to do normal map texture sample and transform into tangent space, so your really not optimizing much by just baking normal map shading into a lightmap.
  • bugo
    Options
    Offline / Send Message
    bugo polycounter lvl 17
    Now I got what happens with directional lightmaps, it simply creates the world/object normals interpolated by light for the faces which enables a static nmap to be rendered cheaper (correct me if im wrong). Is that the same that UDK does? I wonder...
  • easterislandnick
    Options
    Offline / Send Message
    easterislandnick polycounter lvl 17
    HI, Unity 4 now does this out of the box! Having a play with it now! With single lightmaps normal information is now baked into lightmaps. Works great!
  • cupsster
    Options
    Offline / Send Message
    cupsster polycounter lvl 11
    To reduce drawcalls, you can select groups of objects that are nearby and bake them to specific lightmap by hand using BakeSelected. In previous versions it would require you to first create large enough lightmap array, lock it and then selectively bake.. I think in latest versions this was addressed. This way you can save with lightmaps. Other method is to use script to bake out objects that use same material to one lightmap. This way you preventing Unity from additional drawcalls.
  • Ged
    Options
    Offline / Send Message
    Ged interpolator
    sounds awesome I hope my work will buy unity 4 for us but it looks stupidly expensive to upgrade everyone in my office
  • cupsster
    Options
    Offline / Send Message
    cupsster polycounter lvl 11
    if you have good unity programmer he should be able to code tools for you that use unity text format and then you can edit and setup scenes and automate build, baking whatever from any app like maya or max for example.. so you can actually go with one licence ;) or three if you want also iOS and Android or vice versa
Sign In or Register to comment.