z3r0_d's homepage

Home
Thoughts
TI Calculators
Blender 3d
Programming
About Me

E-mail me

Radiosity for games, December 31 2002
For this escapade I attempted to try using radiosity as a technique for setting vertex colors in a more realistic (and easier) manner.    I learned a few other things in the process.  I have no intention of explaining the entire radiosity process (look for another tutorial, my hints are material settings, select meshes, press collect meshes, then go, then wait, then wait more, then wait more, [then become satisfied and impatient and press escape] then press Replace meshes, then free radio data)

My Plan

I was going to create a little 'building' with four exiting hallways, and a dome that emits light into the environment.  It ended up looking like this:

solidWithWire.png (32923 bytes) finalSolidWire.png (105111 bytes)
Starting Mesh, viewed in solid view mode from the inside

Outside in solid view mode

Outside in solid view mode with wire.  

Outside in solid view mode with wire after radiosity calculation where the subdivisions done by it are visible.  **

Then things got interesting.  I had numerous problems
  • Incorrectly facing normals (some faced outside)
  • Places that should have seams didn't (the ends of the hallway where they meet the curves)
  • Too high an emit value on the dome (everything was a bright, bright white after too few radiosity iterations)
  • Creation of too many (more) faces during radiosity calculations (I will cover my fix to this first)
I ended up with the following radiosity settings which increased the number of faces from 503 to 847 (rather than to 10,000+)

My Radiosity Settings

These will probably NOT be a good starting point for your environment.  Read on for more.  

Of note are the ElMax, ElMin, PaMax, PaMin settings.  I shall attempt to explain what they are... Parts may sound like they were taken from the official Blender 2.0 Guide in the back with the Radiosity Buttons.  Before I begin Patches and Elements Must be explained

Patch
A patch is a face able to send energy, but it is only sent from the center.  The amount sent depends on the emit value of the material, the amount of unabsorbed energy sent to it from other patches, and the size of the patch.  Smaller patches are better for realism, but not speed.  
Element
An element is a face that is capable of receiving energy.  It is a child of a patch.  Patches can have more than one child element.  Elements pass the energy they absorb that is to be reflected into their parent patch.  The amount of energy that is passed to their parent depends on the reflectivity of the element (inverse of how much of the light it absorbs), and the color of the light the element absorbs compared to the color of the element.  Smaller elements are better fore realism, but not speed.  

For the game engine faces (here synonymous with elements) should be subdivided as few times as possible (even if it looks better) so that it may run at a reasonable rate, but it doesn't look as good.  So where is the happy medium?  That is for you to decide, but I tried to decide it when I made the mesh (which was painful).  It can be seen above.  If you do not wish to model with the intended best sizes of your faces in mind from the beginning there is a better solution.  When radiosity calculation starts blender subdivides the faces so that the patches and elements fit into a range of sizes giving us control over how much things are subdivided if they are at all.  The options that give us this control are the ElMax, ElMin, PaMax, PaMin settings.   They are the Element and the Patch minimum and maximum sizes in units of 1/10,000 (one ten thousandth) "of the boundbox size of the entire environment," but I don't know if this is limited to the all meshes, or just the ones involved in radiosity calculation.  

How do I determine the settings for these sizes?

It is simple really.  Do you see the [Z] and [ShowLim] buttons, when any one of them are pressed (after collecting the meshes) the limits for the element min/max and patch min/max are drawn as squares in the center of the environment.  Like so:

Patch and Element limit wires

The inner (currently) squares (in aqua) are the element limits, and the outer two (in white) are the patch limits.  Press the Wire button to better compare their sizes to the surrounding world.  Also, changing how the ShowLim and Z buttons are pressed (one, the other or both) changes the orientation of the limits.  

Clearly you want the maximum element size not to be too small since it will result in many, many, many small faces where it isn't necessary.  If the element min is larger it may make things less realistic but will also make the end result have fewer faces.  

Other changes?

[SubSh P] and [SubSh E] I set to 0 in fear that they may create more faces.  See, I don't know everything.  I haven't played with them to know if they would, but things worked well enough already.  

Touching up after radiosity

After you are satisfied with the result of the radiosity calculation, and before you add a new mesh (or replace the existing) there are some things that you can do to improve results in the game engine.  

Element Filter (if necessary...) This will smooth your elements.  I haven't found it necessary if my radiosity settings were reasonable, and my faces were smooth.  

Remove doubles in radiosity buttons.  This will remove double elements with their color being different less than Lim (next to it) which is an integer for the color channel ranging from 0 to 255.  0 has no effect where numbers nearing 255 will nearly merge everything.  It also appears that remove doubles is called when radiosity calculation is completed.  

Remove doubles in edit buttons (after texturing...) to decrease the number of vertices significantly.  Excess vertices slow things down as well.  This should probably be done after texturing since pressing [L] after removing the double vertices will select the entire object.  

The Result:

By A Lamp converted to vertex colors

inside lit by a single lamp (sphere) converted to vertex colors by pressing Make [vertex colors] in the edit buttons.  The lines on the dome are there because it was rendered flat sided.  Note how the end of the hallway, the walls of the hallway, and the ceiling are improperly lit.  The far wall of the halls should be darker (it is in shadow), and the others should be lighter because of the reflected light.  The floor will pass for acceptable.  The environment is not blue like the light coming from the dome would be because the lamp was the default gray (my fault).  
texturedLighted.jpg (45133 bytes)

Textured version of previous.  

 

By Radiosity

Inside, after radiosity, and making the dome a darker blue (in face mode).  Note that the end of the hallway is dark, and the light fades out in the hallway, and the ceiling is lit by the light reflected by the floor.  Everything is blue because that was the color the ceiling emit, and the room did not have a color (it was the default gray).  

 

Textured version of previous.  

Some Comments

Vertex colors for faces that can be lit by the game engine seem to specify the BRIGHTEST color the vertex can be.  This means that is the dark corners the brightest light shinning most directly would still yield darkness.  Given that realistic lighting has now been accomplished putting a light in the corner is not necessary, but it may happen.  Also, when the faces are set to be rendered light sensitive, they go dark unless lit by a light (if there is one).  

Radiosity doesn't seem to preserve the solid or smooth rendering of faces.  The way I built my mesh I could just hit set smooth on the object to have it return to it's original shading.  

Accounting for curves meeting hard edges when radiosity is to be used.  

The technique is pretty simple, but I will not give you any graphics for it (as I am lazy).  What you do is make all of the faces render smooth, and modify your mesh so that there are edges where there should be.  This also works on subdivision surfaces sometimes (for a cube extruding will be better than splitting).  

A simple example:

  1. Add a cube
  2. Make it render smoothly
  3. in edit mode from one side select the top
  4. press [y] to split the top off
  5. press [h] to hide the top
  6. repeat steps 3-5 for the bottom and two opposite sides
  7. press [alt] + [h] to reveal the hidden faces

The reason the top and bottom are moved hidden is so that there is not a duplicated edge created when when the sides are split (the selected edge for the top will be split as well)

Simple really.  I separated my object into the walls of the hallway, the ends of the hallway, the ceiling, the floor, the dome, and the curved parts around the main area.  Note that I made the floor is in one piece (but many faces). If it were not the radiosity calculation would make the seams in the floor visible.  It would not look good.  

Radiosity is odd in that faces rendered solid when subdivided end up not sharing edges (maybe after they are subdivided).  It is much easier to select an object of many if many of the object's faces are sharing edges so that the faces may be selected with [L], for this they must be rendered smooth.  

** If you look closely at this you will see things that should never be done when creating an object in blender.  Where some faces meet the adjacent face has been subdivided with no transition leaving the possibility to see through the created hole.  Since the added vertex lies EXACTLY on the line of the adjacent face (the one not subdivided) it will not likely show, but in performing further modifications to the mesh problems may arise.  Don't further modify the mesh.  Two problem areas are shown in light blue below. 
bad edges after radiosity

The Wire and Solid mode combined images were created by making the original mesh render in wire (top left of edit buttons), duplicating with [Alt] + [d], and making the newly created (and automatically selected) object render in shaded.  Deselect all, and enjoy.  If you wish to edit the mesh edit the one rendered in wire for better results.  

I feel I was rather incoherent. 

Page created and maintained by z3r0_d.  Please read the disclaimer