How to create light maps at runtime?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
piiichan
Posts: 59
Joined: Thu May 01, 2008 1:20 am
Location: New Caledonia (France - Pacific)
Contact:

How to create light maps at runtime?

Post by piiichan »

Let's say I have a mesh (with multiple mesh buffers) created dynamically at runtime.

I'd like it to be nicely illuminated, so a nice way would be to use a light map texture. I can't use IrrEdit to create the light map texture, because the mesh is created dynamically.

Is there a way to create light maps at runtime?
Thank you.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

lightmaps are pre-calculated, basically a snapshot in time of a given moment. light values are baked into a texture which later on get blended into colormaps.

that's what lightmaps are for.

what you really want is something done in real-time, and that's not how lightmaps work.

try looking into SSAO or realtime radiosity. that may be what you are looking for.

on the other hand, shenmue II has that kind of feature, though. the lightmaps react to the time of day.
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You could buy the sources of irrEdit and apply the algorithms to your dynamically created mesh. Or you implement such stuff on your own. Another option is to write the dynamically generated mesh to a file (using the mesh writer interface) and load them into irrEdit, do the lightmaps, and load those back in your app.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Yeah presumably, to save paying $300 or whatever for the irrEdit source, you can just google light map generation and find out an algorithm for creating them and just implement that yourself.

Or you could just use shadow mapping (a few shaders for that in the projects forum) which will give you real-time shadows at a good speed, does it HAVE to be light maps? If so, why?
Image Image Image
floppyfreak
Posts: 117
Joined: Sat Apr 19, 2008 10:14 am

Post by floppyfreak »

one more stupid question of a noob who understand just half concepts:
can't you use render to texture technique for this task? I wanted to make some research on this and now I just can throw it in the round :lol:
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Not really no... the light map is projected shadows, i can't think of a way RTT could be used to produce that...
Image Image Image
piiichan
Posts: 59
Joined: Thu May 01, 2008 1:20 am
Location: New Caledonia (France - Pacific)
Contact:

Post by piiichan »

Or you could just use shadow mapping (a few shaders for that in the projects forum) which will give you real-time shadows at a good speed, does it HAVE to be light maps? If so, why?
JP, are you talking about the thread called XEffects - (Indoor Soft-Shadows + Post-Processing)? I'll have a look at it... looks like what I'm after.
To answer your question, I only know about light maps for creating static shadows, but any other solution such as shaders would do.
Another option is to write the dynamically generated mesh to a file (using the mesh writer interface) and load them into irrEdit, do the lightmaps, and load those back in your app.
I understand, but I can't do that as the mesh is changing very often. I have a big tile-based world (up to 10,000 x 10,000 tiles), but of course I can't render such a big world, so I create a mesh that only shows a small portion of the world (eg 10x10 tiles). Each time another part of the world must be displayed, the mesh is recreated.
what you really want is something done in real-time, and that's not how lightmaps work.
Well, I don't need dynamic shadows, I need static shadows for the environment (walls and corridors).
try looking into SSAO or realtime radiosity.
I need more dramatic shadows than those ambient occlusion creates.

Thank you all for your kind replies :D
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

it looks like you're still searching for a solution.

hope you find them soon.

in my case, giles for static lightmaps and xeffects for shadowmapping are the ones i use.

i just finished reading one chapter in gpu gems 2 about ambient occlusion(ao), and it looks like ao will also work. codewise, there's no code, though the book described the procedure how shadows get calculated. it uses disks having position, normal and area to project shadows down to other disks.

See chapter 14 found in this page: http://developer.nvidia.com/object/gpu_gems_2_home.html

hmm, the code for chapter 14 is here: http://http.download.nvidia.com/develop ... Index.html
Image
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

dlangdev is giving you the path to follow. You NEED dynamic shadow, not because your meshes does not move but your scene change dynamicaly.

real time ambient occlusion and shadow mapping are used in next-gen games to create the environnement using generated meshes. You will rely a lot on shaders power and next gen equipment to that and is the way to go if you want a look to rival CRYSIS or FAR CRY II.

You should take note that those technique will require a beefy PC to run the application and you surely will have to use multithreading effectively to make that happen (so will require at least a dual core CPU to run your application with thoses features)

The only other (less CPU/GPU expensive) solution would be to pre-render some lightmaps for some meshes that are placed "dynamicaly" (Like Hellgate London). But your will need to create parts and create the lightmaps inside the application. It will not look as good, but with some good planning (and really thinking were you place you lighting) you could achieve a nice look.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

I'm trying to understand you piiichan, but it's kind of hard to understand. From what I have read, about your tiled world, and the need to re-create your mesh, it appears as though you only want to generate lightmaps for the terrain dynamically? If this is true, then why not just store the lightmap textures along with their associated tile, and then load those. That may be a little memory intensive on the HD considering you have 10,000x10,000 tiles though I guess.

So next, I will recommend this algorithm. It has been implemented with Ogre3D, but the concept is there for you to implement with Irrlicht: Realtime Terrain Lightmapping. It took 1.4 seconds to generate a 2048x2048 lightmap for a terrain on his system, so I would check that thread.
TheQuestion = 2B || !2B
piiichan
Posts: 59
Joined: Thu May 01, 2008 1:20 am
Location: New Caledonia (France - Pacific)
Contact:

Post by piiichan »

dlangdev, I've downloaded the PDF of GPU Gems chap 14 (by the way, I'm impressed it is freely available online :shock: ). What I exactly want is shown in the first row, fig.14-8, p.232. So thanks for the link :)
I've heard about xeffects, but what is giles?

christianclavet, thanks for your advice and techniques, I'll take them into account. I will also have a thought on the technique you last mention... I was surely mistaken when I wrote that ambient occlusion is not a good solution for what I want. Can it generate sharp, direct shadows from point light sources?

Halifax, I'm doing a diablo-like game. The world is generated randomly when the level is loading. That means I allocate up to 10,000 by 10,000 tiles, set each of them to a particular type, eg grass, gravel, wall, door, stone, tree etc... For each type of tile, I know how to generate the corresponding mesh and associate the corresponding texture. Now, with the main character standing in the middle of the screen, there are about 10 by 10 visible tiles. Some tile types should be sources of light, eg a wall with a torch attached to it, a lava tile, or a magic crystal tile. These tiles should consequently affect the texture on surrounding tiles that are also part of the same mesh.
What I'd like to do is compute the lightmap only for the displayed mesh, ie for the 10x10 tiles.
I'll have a look at the link you provide, thx!

From what all of you told me, I see the problem I am tackling is not trivial. I now have plenty of links and ideas you kindly provided, thx again.

My game is simple and I do it only for the fun of doing it. I'd like it to be cute and pretty (all of us I believe would like that) with nice colored lights and shadows, but the gameplay is the number 1 priority for me. If I feel things get too hard and require too much time, I'll just use simple light nodes.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

you can also read more shading effect from valve's, here's the link to the pdf...

they call it "radiosity normal mapping"

http://www2.ati.com/developer/gdc/D3DTu ... hading.pdf
Image
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

found another good article, you might want to check this out. probably one of the complete detailed discussion about the subject.

http://freespace.virgin.net/hugo.elias/ ... iosity.htm
Image
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I've heard about xeffects, but what is giles?
Ok, I'm quoting this. :D
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Yoran
Site Admin
Posts: 96
Joined: Fri Oct 07, 2005 8:55 am
Location: The Netherlands
Contact:

Post by Yoran »

BlindSide wrote:
I've heard about xeffects, but what is giles?
Ok, I'm quoting this. :D
Muhahaha :)
Post Reply