Radiosity c++ tutorial
#1 Members - Reputation: 185
Posted 07 December 2011 - 05:24 AM
Do you know any practical tutorials where they explain Radiosity in C++?
lg rumpfi88
#2 Members - Reputation: 1386
Posted 07 December 2011 - 07:19 AM
http://freespace.virgin.net/hugo.elias/radiosity/radiosity.htm
#3 Members - Reputation: 190
Posted 08 December 2011 - 04:20 PM
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.
#5 Members - Reputation: 149
Posted 10 December 2011 - 03:17 PM
#6 Moderators - Reputation: 5462
Posted 10 December 2011 - 05:55 PM
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 Crossbones+ - Reputation: 746
Posted 10 December 2011 - 07: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 (on some even dynamic GI, ... eh... good dynamic GI, not that SSAO trick that everyone overdo and then it looks very very bad
#9 Moderators - Reputation: 5462
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)
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 Members - Reputation: 1386
Posted 12 December 2011 - 08:27 AM
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 Members - Reputation: 149
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.
#12 Moderators - Reputation: 5462
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 Members - Reputation: 149
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... 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.






