Sign in to follow this  

Radiosity issues

This topic is 4029 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I am having some problems with my radiosity renderer. See image below for shooting energy from the top patch only in one direction. The code for computing form factors seems to be wrong. I want the light to be in a more circular shape. Why is it so quadratic? This is the code I am using:
// Precalculate form factors between patches
  size = _radiosityPatches->getSize();
  _radiosityFormFactors = new NScalar[size * size];
  for (int i = 0; i < size; i++)
  {
    patch0 = (NPatch *) _radiosityPatches->get(i);

    for (int j = 0; j < size; j++)
    {
      if (i == j)
      {
        continue;
      }
      patch1 = (NPatch *) _radiosityPatches->get(j);
      index = i * size + j;

      diff = patch1->_center.sub(patch0->_center);
      diffLen = diff.getLength();
      diffLen2 = diffLen * diffLen;
      dir = diff.normalize();
      dotPatch0 = patch0->_normal.dotProduct(dir);
      dotPatch1 = -(patch1->_normal.dotProduct(dir));

      if (dotPatch0 <= 0 || dotPatch1 <= 0)
      {
        continue;
      }

      formFactor = ((dotPatch0*dotPatch1) / (NMath3DUtility::_PI * diffLen2)) * patch0->_area;
      _radiosityFormFactors[index] = formFactor;
    }
  }

The other problem I have is how to get rid of the seam clearly visible between the two triangles making up the bottom quad. I have a border around the textures so tiling quads will not produce seams due to filtering. But there is no border around the edge between the triangles so the black color in the texture is filtered with the whiter pixels. How can I fix this?

Share this post


Link to post
Share on other sites
Quote:
Have I given too little information?

No, it`s just an extremely specific topic and not very many people have actually implemented radiosity from start to finish, so it`s no wonder that you haven`t received any replies so far.

Whenever you are posting screenshots regarding radiosity, disable texturing, so we can see the actual lightmap that has been calculated. From your current image it`s hard to tell what`s going on, since the base material texture is of very high contrast, thus completely killing any radiosity effect.
Disable also any filtering, so we can see actual patches (texels).

As for border between triangles, you must make sure that you calculated also few texels behind the edge so that it gets filtered correctly.
Do you offset UV coords at vertices by half-texel ? That`s what must be done to prevent filtering with background of the lightmap texture (usually black).

Is the room regular box, i.e. walls have the same height as is the width ? Can`t tell from black walls. If so, there are mistakes, because that`s definitely not how it should look like after first shooting.

Share this post


Link to post
Share on other sites
Thanks for the input.

I fixed the problem with the visible seam between the triangles making up a quad.

You are right, the screen shots should only show the actual patches.

The box is a cube, the walls have the same height as the width. The screen shot also only shows ONE side of the hemicube, the downward direction. Shooting in the other four directions works correctly.

Unfortunately I still have the error with rectangular shape of the light.
If I lower the shooting patch so it's located just above the floor, the light is much brighter in the center of the floor and gets darker moving away of the center just as a normally light would do.

Maybe I have to put in some attenuation calculation into the form factor calculation...

Share this post


Link to post
Share on other sites
Post the screenshot with the patches visible (i.e. no texture filtering and no material texture selected - just lightmap). It`s impossible to tell what`s going on since we don`t see the actual patches.

As for the attenuation, you are already doing this - through following part of the equation : "/ (NMath3DUtility::_PI * diffLen2)"
At quick glance it seems you have the equation right. Are all your patches of the same size ?

If you raise the position of the light up, does it affect patches on side walls, or do only 1-2 bottom rows of patches get lighted ?

Try creating much bigger box with many more patches, or make your patch size much smaller - this way you`ll be able to tell (by slowly raising the light position) if it behaves correctly from the start (as it seems to be the case), or it creates those quadratic shapes.
In this case, it could be an error/issue with the Exposure -i.e. the light gets clamped to white, so it seems quadratic, since there aren`t any more patches in the distance that would show the slow light attenuation.
Which means you could get the same effect by lowering your light intensity, or by adjusting the exposure coefficients.
Notice, that the smaller the patches are, the darker the scene is (assuming light patch has same area as all other patches) - this is taken care of in the Form-Factor equation by multiplying by the Patch Area.
Try all above options and let me know the outcome through screenshots.

Share this post


Link to post
Share on other sites
Now I am starting to get somewhere!

I found another stupid mistake. I did not setup the view correctly. The window was too small so only 4x4 patches were visible for receiving light everytime I shot from the hemicube sides.

Now I can go from here! Thanks for the inputs!

Share this post


Link to post
Share on other sites
It looks correct to me. I assume this is after first shooting pass, since the top wall is black. Could you try to post the same scene after, say, 100/1000 passes ? I`d recommend to create 2 functions - first shall be for previews (1 pass per each light), second shall stop shooting after a threshold percentage of energy has been shot throughout the scene (so that you won`t have to manually try several different amount of passes when you`d like to have a nicely lit scene).

Did you try shadows already ? What do you use for visibility testing ?
EDIT: Rated you up for getting that far with radiosity ;-) Congrats !

Share this post


Link to post
Share on other sites
I draw the world 5 times from the shooting patch for the 5 hemicube sides (resolution 128), call glReadPixels to find visible patches (each patch has a unique color identifing it) and calculate the correct radiosity. Visibility will come for free since occluded patches will not be drawn to the screen buffer.

The screen shot shows 100 passes.

Share this post


Link to post
Share on other sites

This topic is 4029 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this