I'm realizing that this blog isn't actually that useful to someone who would like to get some useful information about what I'm doing and how, because mostly I just make quick posts showing off content and then put them up before I can add some information about what is actually going on.
So this post is going to go over some of the content and talk about the development of it.
Lightmapper
The lightmapper I was working on primarily works by casting rays from the 3D position of each pixel in the texture toward the lightsource If the ray hits something before reaching the lightsource, the texture pixel is not lightened. If the ray makes it to the light, then the texture is lightened according to the lights settings and the dot product of the surface normal and the light direction. ("Surface normal" means the direction that points directly away from the surface that is casting a ray toward the light. Dot product is a type of vector multiplication and it is a way to get the angle in between two vectors. If the vectors point the same direction the dot product is one, if there is a 90° angle in between them then it is 0, and if they point in opposite directions it is -1). This is basically the same as how realtime lighting is calculated, except it has ray-based shadowing.
It also has an ambient / bounce light pass where it casts a few rays in different directions from the same texel (texture pixel) position and checks the distance that the rays traveled before they hit something, and the color of the texture pixel that they hit. A indirect light color is calculated depending on the number of rays that hit close to where they started and the color of the texel that they hit.

The two textures that I have are very rough at this stage, especially the indirect lighting which usually ends up noisy. So I blur each component a configureable amount before combining them. This gives it a nicer soft look and masks the fact that it is highly unrealistic.
The method that I use to convert from texture coordinates (pixel positions on the lightmap) to world coordinates (points in 3d space) is quite cool so I will explain it. What I do is transfer whatever position into barycentric coordinates within the relevant triangle, then convert back by plugging the barycentric coordinate into a weighted average of the vertices of the corresponding triangle in the other coordinate system.
To start out, what is a barycentric coordinate? It is a group of 3 numbers that represents a position within a triangle. The three numbers always add up to one, and each one corresponds to a vertex of a triangle. Here are some barycentric coordinates:

As you can see the red dot (drawn approximately in those images) remains in the same place relative to each vertex of the triangle no matter the triangle's shape. This is what I want for a lightmapper because sometimes the texture coordinate triangles are different shapes than the 3D triangles.
The next question is, how do I construct a barycentric coordinate? This is the trickiest part programatically, because it involves a lot of variables. The needed inputs are 4 positions, one for the point that is being transfered to a barycentric point (p) and 3 for the triangle vertices(a,b,c). The first thing to do is to calculate a bunch of distances. (ab, bc, ca, pa, pb, pc)
Then I use Heron's Formula to calculate the area of the 4 triangles that are involved. (The whole triangle abc, and the sections pbc, pca, and pab).
Once I have the areas, It is simple to get the barycentric coordinate. Each component of the coordinate is simply the area of the section triangle opposite that component's vertex divided by the total area of the triangle.

To transfer a barycentric coordinate back into a 2D or 3D point is easy. It is simply the sum of each vertex position multiplied by its corresponding barycentric coordinate component.
Anyway, all in all I am happy with the results my lightmapper gives. It is not ready for prime time or anything and never really will be, but it was fun to work on.




14 comments:
Hey, this is cool. Greetings fellow Midwesterner. :)
Thanks ! Hopefully I'll find time in the future to do more write ups like this about some other subjects.
I perused your blog -- and I ended up at this image which I couldn't help but laugh and grin at : http://www.dinowaurs.com/images/stego_manyguns.jpg
Dinowaurs looks cool :)
Coach Outlet Online is a good store!
Coach Factory Outlet
As a Coach Factory Outlet Online, you get paid several ways. The primary way is resale - here is where you sell a product thru your company's Coach Factory Outlet Online. The 2nd way is membership sale - you can sell a club membership and you'll get paid unearned income each time the customer renews their Coach Factory Outlet Online.
You will never buy fashion and cheap Coach Handbags. These benefits, Coach Factory Outlet are the best shopping place for most women. They are the first choice for women.
Your success is my inspiration.Indeed, it is wonderful !!
the article is interesting Coach Factory Outlet although there is a small mistake in the chart.
the article is very interesting..Good!!thank you!!
Coach Outlet Online Build a network monitoring long-term mechanism of action to rectify the vigorous national network finally come to an end.
Making sure your legs are covered is just the first step on Coach Outlet the exciting road to choosing the right morning dress trousers for you.
Phony custom made designer bags outsell the original elements in China and tiawan with a staggering percentage of more than 20:
Phony custom made designer bags outsell the original elements in China and tiawan with a staggering percentage of more than 20:
Coach Outlet Online maybe a good handbag store, that I see women carrying in every city that I visit.
Post a Comment