Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Radiosity c++ tutorial


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 rumpfi88   Members   -  Reputation: 185

Like
0Likes
Like

Posted 07 December 2011 - 05:24 AM

For my graphic engine (not real time) I want to use Radiosity. My program only uses C++, but to create a window and draw pixels it uses OpenGL. My first Versions only works with raytracing algorithm and local illumination.

Do you know any practical tutorials where they explain Radiosity in C++?

lg rumpfi88

Sponsor:

#2 Krypt0n   Crossbones+   -  Reputation: 2686

Like
0Likes
Like

Posted 07 December 2011 - 07:19 AM

while not c++, it has still some pseudo code and is quite good explained and easy to understand:

http://freespace.virgin.net/hugo.elias/radiosity/radiosity.htm






#3 bombshell93   Members   -  Reputation: 210

Like
0Likes
Like

Posted 08 December 2011 - 04:20 PM

well just look for general radiosity tutorials, language doesn't matter, the theory is whats important and once you understand theory behind radiosity you'll be able to write your own radiosity engine in any language you understand.
The general approach for real-time is light propagation volumes which is very roughly a 3D grid which spreads lighting from the first bounce. I suppose the same thing could be done for not real-time quality if you do this on a much larger magnification.
That or if you want pure accuracy you could do a series of ray traces essentially
Light throws out A rays
A rays act as lights to colliding surfaces which then throw out B rays
B rays act as dim lights to colliding surfaces which then throw out C rays
C rays act as dimmer lights to colliding surfaces which then...
etc. etc. depending on how long you don't mind them bouncing around for (longer can = more accurate but also < efficient)

The way krypt0n linked to is a compromise of both sort of.
It splits surfaces into (just quoting the documentation I read on it) micro-facets which will act like the rays I mentioned above. though instead of infinitely multiplying each surface already has them and instead of creating more, information is passed and blended with each of the other micro-facets.

#4 rumpfi88   Members   -  Reputation: 185

Like
0Likes
Like

Posted 09 December 2011 - 04:53 AM

Ok, thanks both of you

#5 JustChris   Members   -  Reputation: 150

Like
0Likes
Like

Posted 10 December 2011 - 03:17 PM

The procedures behind rendering the hemicubes and approximating the light inputs and outputs is easy to understand for me, but how are we supposed to break up each surface into patches? And how could this be applied to a deferred renderer? I have no experience with baking any sort of textures onto objects, and this problem seems like it would have to use baked textures.
Electronic Meteor - My experiences with XNA and game development

#6 MJP   Moderators   -  Reputation: 11850

Like
0Likes
Like

Posted 10 December 2011 - 05:55 PM

You can bake per vertex, which makes things pretty simple. For textures you have to generate some sort of unique parameterization (UV mapping) of all meshes in the scene. Your sample points are then located at the center of each texel in the texture that you map to the scene. The DX9 D3DX library has a class that can generate the parametrization for you, although it's a little hard to use since the documentation sucks.

Why do you ask about a deferred rendering? If you pre-bake lighting, it's almost totally unrelated to how you handle your runtime lighting.

#7 Vilem Otte   Crossbones+   -  Reputation: 1572

Like
0Likes
Like

Posted 10 December 2011 - 07:30 PM

Don't know if it is related, but I've implemented algorithm from Hugo Elias website some 7 years ago (unwrapping static meshes to light maps is evil!!!) through render-to-texture and even in that time an average ray tracer could beat it in speed, or was it that using GPU for the actual implementation is that slow?

Ah... that was a long time ago, I bet that most modern games doesn't use light maps (mostly) - I personally would think twice before implementing them (of course if it is not for learning purpose - then go for it), as you can do dynamic lighting on most PCs today (on some even dynamic GI, ... eh... good dynamic GI, not that SSAO trick that everyone overdo and then it looks very very bad :wink: ... not that it couldn't be nice, but well most people overdo SSAO a lot).


My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com


#8 rouncer   Members   -  Reputation: 291

Like
-1Likes
Like

Posted 11 December 2011 - 01:57 AM

I find the industrial standard method to develop radiosity is a complete jarring solution, id rather invent my own gi method any day, its actually not that complicated, multiple bouncing...

#9 MJP   Moderators   -  Reputation: 11850

Like
0Likes
Like

Posted 11 December 2011 - 03:30 PM

Ah... that was a long time ago, I bet that most modern games doesn't use light maps (mostly) - I personally would think twice before implementing them (of course if it is not for learning purpose - then go for it), as you can do dynamic lighting on most PCs today


Lightmaps with prebaked GI are very popular. Off the top of my head you have...

  • All Call of Duty games
  • The Uncharted series
  • The God of War series
  • Killzone 2/3
  • Halo series
  • Pretty much every Unreal Engine 3 game
  • Battlefield 3 (they use Enlighten which is a realtime GI solution, but I'm pretty sure that they keep the GI static at runtime)
Typically it is only games with dynamic time of day that don't do it (GTA, Elder Scrolls, Assassin's Creed), although there is a few cases of games just going with all dynamic deferred lighting. I would definitely, definitely, definitely not recommend going without any kind of GI solution for a modern game. It makes an enormous difference on your overall lighting quality, and can actually make it easier for artists to a light a scene (since GI is intuitive to them, and they can use less lights). Runtime GI solutions are cool, but still very much in their infancy. Licensing or developing one means you will add non-trivial runtime costs, and will likely end up with lower-quality GI than you would have if you just pre-baked it.

Either way this is pretty off-topic since the OP already said that his engine is not real-time, so I apologize for that.

#10 Krypt0n   Crossbones+   -  Reputation: 2686

Like
0Likes
Like

Posted 12 December 2011 - 08:27 AM

I've implemented a similar tech like the one I linked to when the Geforce1 (256) came out, as there is a big advantage using the GPU. It's because all the setup artist do, be it multi layer texture, decals, glossy texture, env maps etc. doesn't have to implemented again, it's just the usual rendering when you make the initial shooting.

that's even more of an advantage nowadays then it was back then, you can have tons of shaders and effects combined nowadays, some fog volumes, fully reflective walls, water/pools, and you dont want to maintain it (as artist won't use that every day, they'll use it every now and then when they do another light pass).

and it's damn simple to implement, by rendering the scene and downscaling it to a pixel.

as for UVs, I'd suggest to not implement a special algorithm, but with what artist setup in their editors. they have auto unwrapper, they can always hand-tweak UVs and optimize/fix visual artifacts. it can be very time consuming to debug and fix your own UV mapper, it might be sometimes not even a bug, but some extreme case of the expected behavior and you might investigate for few days to come to this conclusion and it won't fix this bug.



#11 JustChris   Members   -  Reputation: 150

Like
0Likes
Like

Posted 13 December 2011 - 01:25 PM

You can bake per vertex, which makes things pretty simple. For textures you have to generate some sort of unique parameterization (UV mapping) of all meshes in the scene. Your sample points are then located at the center of each texel in the texture that you map to the scene. The DX9 D3DX library has a class that can generate the parametrization for you, although it's a little hard to use since the documentation sucks.

Why do you ask about a deferred rendering? If you pre-bake lighting, it's almost totally unrelated to how you handle your runtime lighting.


Vertex coloring was the first thing I thought of myself. A problem with it is that it won't look as good in large, flat surfaces where there aren't a lot of vertices. Maybe tessellation needs to be done?

However I find the texturing approach to be more appealing, as I would have finer control with it using pixel shaders. UV unwrapping via D3DX won't be possible, though, because I'm using XNA and that library or its UV Atlas functions aren't available.

I was planning to start by copying the models' UV coordinates straight through for the baked lightmap textures. Sometimes the textures wrap and that doesn't make sense for the lightmaps to do that, all texels must be unique for the lightmaps. So if some coordinates use wrapping and go beyond the bounds of 0 to 1, all of the coordinates for the baked texture are normalized.

Then based on the transformed scale of the object in the scene, and its original bounding box size, a texture size is chosen to fit the size, so that all lightmap texels look pretty uniform in size. The lightmap textures will still be noticeably coarser than material textures, to balance detail with speed in producing them. Does it seem sensible so far?

There still is the problem with models that reuse UV coordinates for material textures so without any more involved UV unwrapping methods I am not going to get around it other than breaking up the parts that reuse coordinates into separate objects in the scene. Still I think I'm thinking too hard about it.
Electronic Meteor - My experiences with XNA and game development

#12 MJP   Moderators   -  Reputation: 11850

Like
0Likes
Like

Posted 13 December 2011 - 01:43 PM

Vertex coloring was the first thing I thought of myself. A problem with it is that it won't look as good in large, flat surfaces where there aren't a lot of vertices. Maybe tessellation needs to be done?


Absolutely, that's the major problem with baking per-vertex: your lighting resolution is directly tied to how much you tessellate your meshes. So yeah you can add more verts, but then you end up adding more positions/normals/texture coordinates/tangents/etc. where you may not really need them. This is why lightmaps are nice, because their resolution is decoupled from your underlying geometry.

However I find the texturing approach to be more appealing, as I would have finer control with it using pixel shaders. UV unwrapping via D3DX won't be possible, though, because I'm using XNA and that library or its UV Atlas functions aren't available.


Well unwrapping is definitely something you'd want to do during content authoring or during your content processing phase. So you could certainly write a content processor that handles the mesh processing, perhaps using SlimDX or another managed wrapper. But if you don't want an automated process then you can just author the UV's as part of creating your models, as long as you either make sure that they're unique or you handle splitting up your lightmaps into the required number of separate textures.

I was planning to start by copying the models' UV coordinates straight through for the baked lightmap textures. Sometimes the textures wrap and that doesn't make sense for the lightmaps to do that, all texels must be unique for the lightmaps. So if some coordinates use wrapping and go beyond the bounds of 0 to 1, all of the coordinates for the baked texture are normalized.

Then based on the transformed scale of the object in the scene, and its original bounding box size, a texture size is chosen to fit the size, so that all lightmap texels look pretty uniform in size. The lightmap textures will still be noticeably coarser than material textures, to balance detail with speed in producing them. Does it seem sensible so far?

There still is the problem with models that reuse UV coordinates for material textures so without any more involved UV unwrapping methods I am not going to get around it other than breaking up the parts that reuse coordinates into separate objects in the scene. Still I think I'm thinking too hard about it.


Yeah that sounds like a fine way to start out. After you get that working, you can experiment with adjusting texture resolution based on a better metric of triangle surface area rather than just a bounding box.

#13 JustChris   Members   -  Reputation: 150

Like
0Likes
Like

Posted 14 December 2011 - 12:40 AM

Don't know if it is related, but I've implemented algorithm from Hugo Elias website some 7 years ago (unwrapping static meshes to light maps is evil!!!) through render-to-texture and even in that time an average ray tracer could beat it in speed, or was it that using GPU for the actual implementation is that slow?

Ah... that was a long time ago, I bet that most modern games doesn't use light maps (mostly) - I personally would think twice before implementing them (of course if it is not for learning purpose - then go for it), as you can do dynamic lighting on most PCs today (on some even dynamic GI, ... eh... good dynamic GI, not that SSAO trick that everyone overdo and then it looks very very bad :wink: ... not that it couldn't be nice, but well most people overdo SSAO a lot).



I think you're right about the SSAO, it needs a lot of fine tuning to get it looking right, and there are some examples I've seen where the effect looks out of place with how everything else is rendered. Having learnt about the process behind GI, it just seems like the "right" way to get such an effect with the lighting, and you get a lot more with it too.
Electronic Meteor - My experiences with XNA and game development

#14 Krohm   Crossbones+   -  Reputation: 3262

Like
0Likes
Like

Posted 14 December 2011 - 01:00 AM

I'm with Krypt0n on this.
I think I've read somewhere in the UDK documentation that per-vertex baking is discouraged. But perhaps they were talking about ambient occlusion?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS