Crystal Space
Welcome, Guest. Please login or register.
November 19, 2017, 08:34:37 pm

Login with username, password and session length
Search:     Advanced search
9081 Posts in 2051 Topics by 80463 Members
Latest Member: Bieses6p
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Game Content Creation
| | |-+  Simulating Photon Mapping in CS
« previous next »
Pages: [1] Print
Author Topic: Simulating Photon Mapping in CS  (Read 5123 times)
Posts: 5

View Profile Email
« on: September 03, 2008, 04:03:28 am »

I wasn't satisfied with the basic light map generation in CS so I have been generating my own lightmaps and radiosity.  This is a simple tutorial on how to do this.

here is a link to a screenshot of a basic photon map experiment in CS.

Terrain in Crystalspace


This looks like nothing special at first glance, it was just whipped up in a few minutes to serve as an example. If you pay careful attention to the curvatures of the terrain you will notice that this screenshot was taken in the shadow of the hill.  A single spotlight was used to light the entire scene.  Normally without some kind of second light or ambient adjustments the shadow areas would be totally black.  In this case there are very soft shadows bringing out all of the little details in an aesthetic way.

I will explain simply how this was done in a way to get the effects to work in crystal space, but I do suggest you familiarize yourself with blender radiosity first if you have no experience with it.

The concept behind radiosity or photon mapping is that in reality, light bounces off of objects. The objects absorb some of the light and repel other parts of the light which then continue bouncing around until they are finally absorbed or escape.  Photon mapping attempts to get more realistic effects by simulating the way light really works.  This is all great in concept and if you follow the blender tutorials you can get it to work.  The problem is when you try to expand the concept to large scenes or terrain.  Often your lighting will be totally wrong, or just wont look like the example you just completed. What is the trick?

Here is how it was done:

In blender start a new project and create an object or terrain which you want to have global lighting applied too.  REMOVE ANY LIGHTS FROM THE SCENE. Our base lighting will be generated using blenders radiosity tool.

When I first started playing with radiocity and terrains, I attempted to use emit objects like you would use a normal light.  In a closed in space, this might work just dandy, but terrain is normally out in the open and exposed.  This means that much of the light only bounces once and escapes.  In order to make radiosity work with terrain you need to scale the terrain down low so it is about as big as the default cube.   Then ad a cube mesh around the terrain so it is fully enclosed.  Remove one of the front faces of the enclosing mesh so you can see inside the box.  Reverse the normals on the box so the normals point in toward your terrain model.  Now create a light source object. I created a simple circle mesh plane and gave it a light yellowish material. (EDIT: The reason we put the terrain in a box is so the light can bounce off the walls and we get reflections back in the shadow area. Normally such reflections can occur off the atmosphere)

the yellow light, the terrain, and the box walls will need to have their emit and ambient values tweaked in order to get the right effect.  Radiocity does most of its light calculations assuming the majority of the light is coming from whatever object has the highest emit value (this is something I think)

Since the yellow circle is the primary light source it will have a higher emit value than the box or the terrain. 

make these changes under "shaders" in the materials buttons

circle:  emit=.4 ambient=.1
box: emit=.01 ambient = .1
terrain emit=.02 ambient = .1

now switch to the radiosity buttons.

drag the hemires slider all the way to the right (1000)

Make sure the circle, box, and terrain are selected.

Click the Gour button or ensure it is active

Click the collect meshes button.  All of the objects will turn white (im using the Apricot GLSL button so this may or may not happen in the regular version)

The collect meshes is confusing. At first I freaked out because everything was too bright and white.  I spent numerous attempts getting horrible lighting results because the system is not intuitive.  Once you clicked the "collect meshes" button, this basically merged the objects into one mesh.  Despite what the tutorial recommends, I do NOT put a limit in the max iterations.  I will explain the reason.

After clicking collect meshes, you will see a new set of buttons pop up over to the right.  One of the buttons says "GO".  Click it.

When the radiosity process starts, you will see a little blue square patch flying around the screen.  The scene will likely look like crap and you may get frustrated with the results.  Don't fret! there is still more to do!

Let the radiosity continue for 30 seconds or so and try not to look at the screen.

now hit the escape button and your radiocity process will cease.  Most likely you scene is too bright. 

Adjust the "mult" value, most likely bringing it down until your scene starts looking like you would expect.  if you lose your contrast or have too much contrast play around with the gamma also until you get the desired effect.    You might have to go back and forth adjusting gamma and mult several times until you have the general lighting effect you want.

Now leave the settings as is and click the "collect meshes" button again.  Click go again and just let the radiocity process continue until you have the effects you want.  The longer you let it run, the better the effect. This is the reason I told you to not add a max iterations.

When you are satisfied with the results, and ready to use the new settings permanently, then click "Replace Meshes"

One the screen your objects may get a checkerboard or corrupted look to them. Don't worry, this is only because you have these new meshes doubled up with your old ones.  Get your old meshes out of the way.  You will find that the box, the light and the terrain are now all one mesh.  Just delete the light and the box faces so you have only your original mesh. 

Getting it to work in Crystal Space:

You will find that your new mesh has a newly created material generated by the radiosity system. It also will have vertex colors which were not there before.  The vertex colors are primarily what was changed to give the photon mapping effect.

We now want to create a UV map (if you are unfamiliar with UV mapping read up on it because I am not going into detail about it here)

After creating a UV map, add a single spotlight as a global light source and tweak it until you have the results you want. You want the spotlight to shine from roughly the same direction that the radiocity emitter was coming from.    (BTW feel free to scale your terrain back up to full size) Once you have the spot lighting positioned as desired, go to the render buttons and bake to a full render.  Again, if you don't know about render baking, then read the tutorials you can find on the web. Everything I learned about blender I got from tutorials or playing around with it. You can too.

When you do a full render bake, essentially all of the spot light effects and the vertex lighting  produced by the photon mapping will be baked onto a texture image. 

Now, save the baked texture to your hard disk.  Delete any materials assigned to your terrain and add a fresh default material.  Go to the texture buttons and load your image you just baked off of your drive.  Go to the material buttons under Map Input.  Click on the UV button. This should make your texture fit the way it was mapped when you unwrapped.

Feel free to add other textures at this point, such as specular maps, alpha, normal maps or whatever.  Once you are done, export to crystalspace.
You might want to adjust the ambient value some but my screenshot was done without any crystalspace lights at all.  You can add further static lights and or dynamic lights to the scene and you should get a satisfying effect.

This technique can be used on indoor scenes with windows, using a light which is outside the window to cast really nice looking shadows and add realistic gradations to the walls.

Feel free to make suggestions for improvements or email me with any mistakes I made in the tutorial.

« Last Edit: September 03, 2008, 08:33:37 am by » Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 5.19 seconds with 17 queries.