Risultati da 1 a 4 di 4

Discussione: Lightmaps in Doom 3 Engine: A Hybrid Approach To Real-Time Lighting

  1. #1

    Predefinito Lightmaps in Doom 3 Engine: A Hybrid Approach To Real-Time Lighting

    Posto anche qui questa notizia

    http://www.raybench.com/fuzzpopfx/tutori als/doom3/

    scusate se non traduco........

    Since the inception of Doom 3, many artists have been disappointed with the engine's limited lighting ability. Utilizing a small number of point lights to illuminate levels results in stark scenery with excessive contrast and absence of subtlety. Environments remain dark due to lack of bounced light. And the lack of area lighting creates rigid shadows and hard surface shading. From an artistic standpoint, Doom3's native solution is undesirable at best. From the perspective of a deathmatch gamer looking for pleasant environments with minimal distractions, it is a beast to reckon with. Seeing Quake 4 soon to release on Doom 3 engine, I decided to get a jumpstart on development by providing a new technique that will help deathmatch mappers create the beautiful environments they truly desire in Q4. With great pleasure I provide this solution: the introduction of lightmaps into a real-time lighted environment -- an extension to Doom3 lighting.

    Some Theory -- How do lightmaps work?
    Lightmaps are a type of "precomputed lighting". This means they are calculated -- through a process called "baking" -- before being used at runtime (the time when you actually play the game). Because they are not calculated during runtime, any changes to the environment will not require recalculation of the lighting. While the performance benefits are great, there exist potential problems. The clearest example is to imagine a dark room with an open door and light pouring in through the opening. If you computed the lighting with a single lightmap while the door were open, you would be stuck with this open-door lighting at runtime. When the door closed, the room would still look like it were open! So you say, "Wait a minute, pha3z! Doom 3's real time lighting already casts proper shadows that would make the light disappear if the door closed!" Precisely. That is why you either wouldn't use lightmaps in this case or you'd be very clever in how you used them. There is *at least* one workaround for the door example. You could bake two lightmaps -- one for the lighting when the door is open and one for hte lighting when its closed. Then you could blend between them with a script when you close/open the door at runtime. Doing that is beyond the scope of this tutorial, however. My aim is only to show how to get lightmaps into Doom 3. Its up to you to make them turn your boring old point-lighty doom3 map into a work-of-art.

    Lets get started implementing these wonderful lightmaps in our own doom3 map!

    CAUTION! -- As you follow these steps, note that you may have to deviate from the process to optimize the scene for your own map. Some mappers will only be wanting to bake lightmaps for small portions of their level, while others will want to have several lightmaps for different areas. Your environment may also have very specific realtime lighting needs as well. So use your head and think carefully about what you need for your scene. You have been warned!

    Before you begin - Verify Geometry Setup
    The first thing you need to do is build your level. How you do this is up to you. You can use GTKRadiant, Doom3Editor, or a full blown 3d app (maya, softimage, 3dsmax, blender, etc). Ultimately,any geometry that you want to bake lightmaps for will need to be brought to a 3d app. With GTKRadiant and Doom3Editor, there are options to export brushes to OBJ mesh files. You can then import those files to your 3d app to begin this process.

    For my test level, I chose to build everything in 3ds max. This was the fastest way for me. I setup all my base geometry in less than 15 minutes and then sent it to Tectonic for texturing. Here is what I have in the 3ds Max viewport:

    Step 1 - Creating a Mesh for the Lightmap
    The first thing we need to do is create a mesh that our lightmap will be applied to. In most 3d apps this should be very simple. In max the steps flow like this:
    1 - Select all geometry
    2 - Clone Selected
    3 - Now my newly cloned objects automatically become the selected objects. I hide everything that is not selected -- this way I only see the cloned geometry. Its easier to work with.
    4 - Attach all of the cloned objects together to make one mesh. Name it something straightforward like "LightmeshRoom1" or whatever makes sense for your scene.

    After those steps, my scene looks something like this. All of the cloned objects are now one mesh:

    Note: If you have multiple rooms or irregular rooms with specific details extending from them, it would be wise to combine the geometry in a way that creates more than one mesh -- where each mesh will allow for another lightmap. This will help you achieve more control in your lighting and also keep detail where you need it. Simply using one giant lightmap spread out over a massive level is gonna produce very low detail lighting -- this could be undesirable.

    Step 2 - Setting up UV Coordinates
    Setup UV Coordinates on the mesh(es) intended for lightmapping. If you aren't familiar with setting up complex UV Coordinates, you may need to consult documentation/tutorials before continuing with this tutorial.

    Here is a picture of the UV coordinates for my mesh. I unwrapped them by hand. I actually could have done a much better job but I didn't think of a better approach until after I was over half-way done. The main problem is that I didn't keep good scale in detailed shapes -- making them larger would help. Also, most of the very small pieces have too much empty space between them that was just be wasted when I baked the lightmap.

    Step 3 - Setting up Lighting
    Not much to say here. All depends on your own 3d app. Here's what I came up with.
    The Yellow light represents the sun and the Blue Lights represent skylight:

    -- mmm tastey lighting. For you other Photorealistic boys and girls out there, yeah I realize the sunlight is razor sharp! It won't matter for the baking process. Get off me!

    Step 4 - Baking the Lightmap(s)
    Consult your documents or tutorials on how this is done in your 3d app. In 3dsmax, its done through a tool called Render-To-Texture. Depending on your app, you may also have different choices of renderers for baking. I used Mental Ray in 3dsMax and setup a complete global illumination solution with Photon Mapping and Final Gather. There is a little bit of trickery here.

    In my particular scene, I have one light to represent the sun. Now, we do not want to bake the direct light coming from the sun. Instead we're going to use one doom3 point light for real time sunlight. However, we *do* want to bake bounced lighting from the sun (since doom3 point lights won't do the bounced lighting in realtime). This is where some of the real power of the lightmap approach kicks in. So how do we bake indirect lighting but NOT direct lighting from the sun? There are various ways depending on your lighting solution. Since I used photons, I used an old trick to get the job done. The steps go something like this:

    1 - Setup all lights to emit photons:
    2 - Choose a file to store the photon map at render time.
    3 - Start a normal render so all the photons get fired from the lights and stored in the photon map.
    4 - Make sure the render looks good -- tweak appropriately. Consult docs here too.
    5 - Now turn off the sunlight. If you render the scene again, you would see that there is no direct light from the sun. However, the bounced lighting is still there because its stored in the photon map!
    6 - Bake the lightmap to texture.

    Finally, assign the lightmap to the Diffuse/Color portion of a standard material. Assign the material to our cloned lightmap mesh. The material setup here is done exactly like you'd do material setup for export on any typical doom 3 mesh. If you want, you can render a preview or something to make sure its mapped right. Here is what my mesh looks like in the viewport when the lightmap is visible:

    Here's a preview render. Clearly the map has some problems. Its very speckled and some of the problems with bad placement/size of faces in the UV Map are showing up too. But it serves fine for this tutorial. Also, I have no clue what caused that weird triangle shadow on the crate. It could be fixed in photoshop though.

  2. #2

    Predefinito Re: Lightmaps in Doom 3 Engine: A Hybrid Approach To Real-Time Lighting


    Step 5 - Porting the Meshes to Doom 3
    Whatever you export to one file will be imported as one giant mesh by D3. If you have multiple areas in your map that could be seperated via BSP rooms and vizportals, then you will need to export these objects from your 3d app as seperate files. You will need to make sure to select the basic textured objects and also the lightmap mesh that goes with them and then export them together to one file. This way when you import the file to D3, the lightmap mesh and the basic textured surfaces are treated as one object. Its easier to handle in the editor like this.

    Here's a tutorial on getting models into doom 3:
    http://www.quake3bits.com/htm/tutorials/ doom_3_prepping_models.htm
    The important part is near the very end of the page where it talks about editing the .ASE file.
    You can also find some stuff on doom3world.org

    Step 6 - Setting up Materials
    The main materials on your objects should be treated just like any other materials. I'm going to assume you know how to create a material file and add materials to it and also how to get them to work with the .ASE file. There's only one special material to worry about for our purposes -- the lightmap material. Here's what I used:

    polygonOffset 1
    sort decal

    qer_editorimage textures/ptec/lightingmap

    // Multiply lightingmap by any color behind this surface on the screen.
    blend modulate
    map textures/ptec/lightingmap

    The important keywords:
    "sort decal" tells the renderer to render this surface after other surfaces so that it goes on top -- like a decal .
    "polygonOffset 1" is the magic that makes it possible to have the lightmap mesh cloned right on top of the normal mesh geometry. It tells the renderer to draw the surface as if it were offset by 1 unit, so it acts like its not sharing the same plane as the main material surface. This eliminates z-fighting.
    "blend modulate" is the same as a "blend filter" which performs color Multiplication -- an old hack for doing lightmaps.

    Step 7 - In the Editor
    Ok, so now you've got the lightmap material setup and you exported the ASE and made changes to it. Now you can import it to the editor and setup your BSP around it to seal the world properly.

    Cam view of my imported mesh:

    If you look at the mesh with Cam view, you should notice that the surfaces flicker due to z-fighting when you move around. You can actually see it in the image above where the crazy black moiring pattern is. Checking for z-fighting is the easiest way to see that the lightmap geometry and normal geometry imported correctly so both are on top of one another. If you don't see any z-fighting, it might mean that either the lightmapped mesh or your other mesh parts are missing -- meaning the parts probably didn't export from your 3d app properly.

    If you look at the mesh in Render view, everything will be lit based on the lights you have in the scene. Everything is black if you have no lights. The lightmaps are not going to have effect until you add some lights to "prelight" the surfaces.

    You will need to add lights that mildly respect the baked lighting you made. In my scene, I placed one fairly bright ambient light directly above the scene to represent light coming down from the sky. Then I placed four very weak lights around the whole scene on about the same elevation as the top of the crate -- one light on each side. Um... Ok well that's the dumb way of explaining. If you're familiar with D3 lights, you know that they have a lighting volume and a highlight/shadow center. I actually set the light volume up so that every light encompassed the scene comfortably. Then I moved the highlight/shadow centers to the positions previously described.

    I have five ambient lights in the scene now -- all of which are non-specular non-shadowing.

    Now if we look at the Rendered view, we see that your normal-bump maps correctly respect lighting in the scene! Remember the normal-bumps are being lit only by real-time lights so its very important to make sure your lights are positioned in ways that make sense. Also remember that your real time lights will also be lighting the player and items/objects in the map, so make sure they look right for those things.

    Here's the result with five ambient lights. Notice the bump-maps look like they are lit by light coming from outside.

    no sun


    And we go "OMGZ NOOO! There's a problem with the specular highlights! LOLZ WeRe DOOOOOMED!"
    Not quite. There's a simple reason why the highlight looks bad and it *is* fixable.

    Step 8 - Fixing Specular Problems
    The problem is that the highlight from the sun is being rendered so bright that its full white. Then the decal lightmap is going on top of this and trying to darken the surface. Since the surface is "blown out" to white already, the lightmap just scales it down to grey resulting in colorless crap. There are a few ways to fix this:
    a) Turn off specular in the light. Ok so this solution sucks, what next?
    b) Bust open photoshop and your 3d app. Hunt down the part of your lightmap where the sunlight is shining. You will find that the lightmap is some shade of grey here. Paint it brighter (closer to white) wherever the sun is shining and check the results in doom3. You may find that you have to go all the way to full white for it to look right.
    c) Open up the specular map for the material with the bad highlights and tone down the lighter areas so that there aren't any strong highlights. If you stop the highlights from blowing out to white, then the lightmap wont screw them up when it modulates the surface.
    d) And of course you can do a nice hybrid of B and C for optimal results.

    Well that pretty much sums it up. The procedure seems more complicated than it really is. Once you walk through it a time or two, you will see its nothing spectacular -- just a clever application of standard 3d techniques. And if you're a hardened veteran of quality CG, the effort required should seem pretty typical for what you're used to.

  3. #3
    Lo Zio L'avatar di mattoxo
    Data Registrazione

    Predefinito Re: Lightmaps in Doom 3 Engine: A Hybrid Approach To Real-Time Lighting

    ci ho messo 3 ore per leggerlo ma che genialata cavoli!

    certo così si snatura un pò la bontà dell'editor (il real time) ma chissene il risultato è comunque ottimo

    hexen grazie per queste news, appena muoio ti lscio in eredità il titolo di animatore

  4. #4
    Lo Zio L'avatar di Vision83
    Data Registrazione
    I'm Dead, Jim

    Predefinito Re: Lightmaps in Doom 3 Engine: A Hybrid Approach To Real-Time Lighting

    Post Up tutorial utile [Anti Apocafud]

Permessi di Scrittura

  • Tu non puoi inviare nuove discussioni
  • Tu non puoi inviare risposte
  • Tu non puoi inviare allegati
  • Tu non puoi modificare i tuoi messaggi
  • Il codice BB è Attivato
  • Le faccine sono Attivato
  • Il codice [IMG] è Attivato
  • Il codice HTML è Disattivato