Sign in to follow this  
tpastor

Create a LightMap with raytracing

Recommended Posts

tpastor    121
hi,
I want to create a light map render using ray tracing for learning purpose.
I already builded the raytracer part, but i dont know how to generate the lightmap from that.
Today, i just throw the rays from my camera, calculate the intersection, shading, throw extra rays ....
But how do i use this to generate the lightmap ?
Do i need throw rays from each texel of my model's texture ? (how many rays should i throw ??!!) Is this the right way ?
And, to "throw rays from each texel of my model's texture", do i need to rasterize my triangles, get the generated position, them throw the rays ?

Thanks !! Edited by tpastor

Share this post


Link to post
Share on other sites
Vilem Otte    2938
First of all you *need* to create texture coordinates for your lightmap (unless you already have them). For more information on how to unwrap your environment to lightmap read for example here - [url="http://www.blackpawn.com/texts/lightmaps/"]http://www.blackpawn.com/texts/lightmaps/[/url]

Now for each pixel in the lightmap, there exists "microfacet" in your scene, and you compute light for that microfacet using your ray tracer.

Share this post


Link to post
Share on other sites
tpastor    121
In resume:
i have model that already have UV mapping.
I need to read the texels of my "empty" lightmap, find the model position associate with it and then use the raytracing in this position.
Do this for all my texels and thats it ??!!

Thanks !

Share this post


Link to post
Share on other sites
MrOMGWTF    444
[quote name='Vilem Otte' timestamp='1352858088' post='5000747']
First of all you *need* to create texture coordinates for your lightmap (unless you already have them). For more information on how to unwrap your environment to lightmap read for example here - [url="http://www.blackpawn.com/texts/lightmaps/"]http://www.blackpawn...exts/lightmaps/[/url]

Now for each pixel in the lightmap, there exists "microfacet" in your scene, and you compute light for that microfacet using your ray tracer.
[/quote]

Assumming that your whole world is made out of quads...
Is there any method for packing [b]triangle[/b] world in to lightmap? Maybe I should just find every 2 triangles that has similar normal, and then assume those two triangles are one quad?

Share this post


Link to post
Share on other sites
MJP    19753
[quote name='tpastor' timestamp='1352858660' post='5000751']
I need to read the texels of my "empty" lightmap, find the model position associate with it and then use the raytracing in this position.
Do this for all my texels and thats it ??!!
[/quote]

You actually need the position and normal, since you need to trace rays through the hemisphere surrounding the normal to calculate the total irradiance incident on the texel. Also in practice you'll find that it's actually not so simple to determine the position and normal for any given texel. To do it you need to figure out which triangle that the texel is mapped to, figure out the barycentric coordinates of the texel relative to the triangle, and then use those barycentric coordinates to intepolate the position and normal from the vertices. To make things even more complicated you'll often have multiple triangles overlapping a single texel, which means you have to be able to either consistently choose which triangle to use or you have to blend between the results from both triangles. One common way to do this is to rasterize the geometry in UV space. This lets you perform the interpolation as a normal part of the rasterization process, and you can also use standard rasterization techniques to choose which triangle to use or to even analytically compute the triangle coverage. You can even rasterize on the GPU if you want, although you'll probably want to use more than one sample per pixel since GPU's don't use conservative rasterizers.

Share this post


Link to post
Share on other sites
MJP    19753
[quote name='MrOMGWTF' timestamp='1352875485' post='5000811']
[quote name='Vilem Otte' timestamp='1352858088' post='5000747']
First of all you *need* to create texture coordinates for your lightmap (unless you already have them). For more information on how to unwrap your environment to lightmap read for example here - [url="http://www.blackpawn.com/texts/lightmaps/"]http://www.blackpawn...exts/lightmaps/[/url]

Now for each pixel in the lightmap, there exists "microfacet" in your scene, and you compute light for that microfacet using your ray tracer.
[/quote]

Assumming that your whole world is made out of quads...
Is there any method for packing [b]triangle[/b] world in to lightmap? Maybe I should just find every 2 triangles that has similar normal, and then assume those two triangles are one quad?
[/quote]

It's a fairly complex topic. You can read through [url="http://the-witness.net/news/2010/03/graphics-tech-texture-parameterization/"]this[/url] to get an idea of the headaches involved, as well as possible solutions. Edited by MJP

Share this post


Link to post
Share on other sites
tpastor    121
hi,
thanks for the answers (specially MJP), they helped me to make some real progress (i finally got something working !!!)
But now that i am implementing some stuffs ... some new doubts are raising... (iam too much "ad hoc", i want to know if what iam doing is the right way to do !)
Instead of making some more questions here, i would love if someone point me a good book or a project that does the simple thing i want to do (a light baker with raytracing -- not the illumination calculation part ...)

Thanks !

Share this post


Link to post
Share on other sites
MJP    19753
I don't know of any projects that you could download. You could definitely take a look through some of the material in [url="http://realtimerendering.com/Principles_of_Digital_Image_Synthesis_v1.0.1.pdf"]Principles of Digital Image Synthesis[/url], as there is definitely some relevant sections in there.

Share this post


Link to post
Share on other sites

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