![]() |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
|
|
#1 |
|
DevMaster Editor
Join Date: Jan 2005
Posts: 54
|
Raytracing: Theory & Implementation:
Part 1, IntroductionAuthor: Jacco Bikker Note: These articles have been previously published at flipCode. They have been re-published at DevMaster.net based on author's request. |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Sep 2005
Location: .nl
Posts: 504
|
Very nice, I'm glad to hear that Jacco is still alive and that he knows devmaster.net
![]() |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
|
just wanted to say thanks for making this available on devmaster.net
___________________________________________
davepermen.net -Loving a Person is having the wish to see this Person happy, no matter what that means to yourself. -No matter what it means to myself.... |
|
|
|
|
|
#4 |
|
New Member
Join Date: Sep 2004
Posts: 27
|
No the honour is mine, flipcode is hardly visible at the moment and this is a great new spot.
Happy New Year to everyone, by the way. Hope you had some time to code. I sure did. ![]() |
|
|
|
|
|
#5 |
|
Member
Join Date: Dec 2004
Location: Ontario, Canada
Posts: 41
|
I'm really happy to see articles posted on here, regardless of whether or not they're new.
I hope this can help rekindle the small community feeling the flipCode once had but with its own personality. I am surprised to see so many old flipCode members here that I wrote off as being gone forever. Good to see you guys around again. ![]() |
|
|
|
|
|
#6 | |
|
Valued Member
Join Date: Mar 2005
Posts: 135
|
Quote:
Happy new year to you, comrade. |
|
|
|
|
|
|
#7 |
|
New Member
Join Date: Sep 2004
Posts: 27
|
Ah, tbp! Long time no see! Did you notice that the Intel paper was finally published?
For the unaware: I worked together with an intel dude to write a paper on the SSE/packet tracing details of the latest version of the ray tracer. This cooperation went, well, 'suboptimal' but at least the paper is online: http://www.intel.com/cd/ids/develope...ing/245711.htm Enjoy. It's basically 'part 8' of the tutorial. It doesn't include full source code though. |
|
|
|
|
|
#8 | |
|
New Member
Join Date: Jan 2006
Posts: 1
|
Quote:
I also hope you will continue the serie one day or that at least you'll let us see your progress through IOTDs/Demos ? Thanks again for an amazing ressource. Regards, jonjon. Last edited by jonjon : 01-07-2006 at 06:00 AM. |
|
|
|
|
|
|
#9 |
|
New Member
Join Date: Jan 2006
Posts: 29
|
Indeed, I would dearly love to see what happened with the integration of the photon mapping
![]() |
|
|
|
|
|
#10 | ||
|
Valued Member
Join Date: Mar 2005
Posts: 135
|
Quote:
Found out recently about it. Quote:
Heh, please tell me more about that suboptimality ![]() Anyway i already knew about all those features. I haven't touched my code for like a year, but as i'm sure you have some fancy stuff under your sleeve i'll have to retaliate. I hate you. PS: ISP switch = slow reply. |
||
|
|
|
|
|
#11 |
|
New Member
Join Date: Sep 2004
Posts: 27
|
Nah I haven't touched mine either. I've been working on a PocketPC game:
http://www.bik5.com/nc2 But after that I wanna do this: ftp://download.intel.com/technology/...load/mlrta.pdf |
|
|
|
|
|
#12 | ||
|
Valued Member
Join Date: Mar 2005
Posts: 135
|
Quote:
Seen it, and even if PocketPC aren't my thing it seems very nice. Quote:
After a sub-10s scan it sounds like something we've discussed a bit back then, i will give it a proper read when my gray cells are back online. When you say you "wanna do this", that means you have a prototype or something? PS: you've conveniently forgotten to clue me about alluded suboptimalities |
||
|
|
|
|
|
#13 |
|
New Member
Join Date: Sep 2004
Posts: 27
|
This is not the place to bash people.
![]() No I don't have a prototype, and yes, it sounds like what we have discussed. Their approach is however quite a bit simpler to implement than the corner ray approach. |
|
|
|
|
|
#14 | |
|
New Member
Join Date: Jan 2006
Posts: 29
|
Quote:
Wow, that is an increadible speed up... Implement it, then write about it ![]() ![]() ![]() ![]() |
|
|
|
|
|
|
#15 |
|
New Member
Join Date: Jan 2006
Location: Luxembourg
Posts: 15
|
Hi,
Just to share a little bit of my tests. After reading your article, I went back to my raytracer left in an hided corner of ppModeler. It was slow, and buggy, so I didn't work on it for ages... (other thing to do before). I have implemented the KD-tree algorithm, and it is quite good. But, for an animated scene, the KD-tree construction is too slow. The aim of my raytracer is to render animated scene, not static scene. So, the render time should take into account the KD-tree construction. Here are the results of my tests:
The results shows that simple BSP is better than full KD-tree (taking into account the KD-tree construction). hope this help, Thanks a lot for these articles, craouette |
|
|
|
|
|
#16 |
|
Valued Member
Join Date: Mar 2005
Posts: 135
|
Hello craouette,
let me start with 2 general remarks. You need to amend your kd-tree (and compiler) to allow for faster updates while animating, see Wald's thesis for some ideas. Also, Havran has shown that SAH is a better heuristic, in the general case, by a large margin. Granted, it's quite hard to write an efficient compiler. From what i see in your report (if i correctly interpret those numbers), it seems that it's your traversal that is really slow, nullifying all partitionning improvments. You're shooting about ~700k+~2M+~200k ~= 3M ray in ~20s or 150kray/s, and while intersection tests vary between 115M(!) and 300M(!!) rendering times don't change much. As Wald reports, with a proper kd-tree, you should get a couple of intersection tests per ray: that's one of the reason why kd-tree are so great. Of course, if you have to mitigate your kd-tree quality for building times it should be a bit worse, but certainly not in the 100 intersections/ray range. At that point, you'd better try with a bvh ![]() PS: Jacco, that Intel paper was really interesting... but implementing that efficiently with so little details... ouch. Still, really hmm fascinating. Last edited by tbp : 01-16-2006 at 05:10 AM. |
|
|
|
|
|
#17 |
|
New Member
Join Date: Sep 2004
Posts: 27
|
I once got a nice tip to speed up BSP compilation: Evaluate only one in every 10 faces. It's similar to what you propose, but with an important difference: In nodes that have less than 256 tris, you will test every triangle, while 'my' approach will still test 1/10th.
About kd-tree compilation: There is a lot that you can do to improve the process. The compiler that came with the article was slow, as I didn't optimize it at all; I only optimized the ray tracer. After writing the last article, I improved the ray tracer greatly (beats Wald) and also the kd-tree compiler (more than a 10-fold speed increase). However, it can be done much faster. TBP and a collegue managed to compile trees with the same heuristics in half the time and less. Once you have an optimal kd-tree compiler, you can start experimenting the compilation/rendering balance. There are many ways to make compilation cheaper: I never skip triangles, so that would be a nice start, you could go on all the way down to a straight octree compiler, which should compile 1M polies in a snap (far faster than 22secs). If you have 4 or 5 basic algorithms with some adjustable settings, you could even decide which one to use based on the scene at hand. If you really have a lot of spare time, you could go for an algo that recalculates only part of the tree. Or, even better, you could insert bounding boxes for animating objects, optimize the tree root (the most expensive part of the compilation) for these, and only update the dynamic portions of the tree this way. Lots of options. ![]() |
|
|
|
|
|
#18 |
|
New Member
Join Date: Jan 2006
Location: Australia
Posts: 3
|
So I was interested in your explanation of barycentric coordinates, and wrote a test harness to check out your code.
Code:
I am sad to report that the distance values your triangle intersection test returned were out by 10, scalar not linear. This probably still worked, because every test was out by the same amount. So I went back to the sources you cited and implemented the barycentric intersection test as discribed. Below is a listing of what I came up with... Code:
Code:
Cheers, -h |
|
|
|
|
|
#19 |
|
New Member
Join Date: Sep 2004
Posts: 27
|
Did you check in the source code if it matters at all if a correct distance is returned? Considering the research you put into it, you're probably right that it does return wrong distances, but I believe the test is only used to accept or reject rays. In that case only the sign of the distance is useful, probably. I'll check it in the code later today.
|
|
|
|
|
|
#20 | |||
|
New Member
Join Date: Jan 2006
Location: Luxembourg
Posts: 15
|
Quote:
One more question: in your sources, you compute the node surface before splitting. I think it is unnecessary, because you minimise a function, so all contant (added or multiplied) just shift the absolute values, but do not change the one that minimized... Do I miss something ? Quote:
Quote:
I change the kdTree construction, but not the rendering. The kdtree use the following split strategy: if bb of triangles included in bb of node -> split empty space if num of triangles > 100 -> split middle largest axis else use SAH Looking at the kdtree generated before, I found the the SAH can be locked into one node: split 18 triangles node => 14 triangles node and 18 triangles node => ... But I think that is linked to the approximation (test of splitting plane on 5 values for each axis). Here are the results: # triangles: 32240 => 37.3 intersections tested per search => 1.16 node per search. craouette |
|||
|
|
|
|
|
#21 | ||
|
New Member
Join Date: Jan 2006
Location: Australia
Posts: 3
|
Quote:
Actually that is your code in the last box (from raytrace7.zip scene.cpp). I though it would be a good idea to include it for comparison, but forgot to mention it. Quote:
I respectfully disagree. Depth matters when your scene has different primitives like cones, disks and spheres, each with different intersection tests. If things are close together, the ray will register a hit on the wrong thing. Also if you want to have depth queues in your shaders, obviously depth matters. Still I may have buggered up your code somehow while I was testing it, so who knows. Your demo worked fine. Anyway the bits of your code that still have me scratching my head are as follows... Code:
So here you have nu, nv and nd. If our axis (k) is z then this could be written as Code:
So these coordinates being projected onto the z axis. But then the next bit in the intersection test I just don't get. Code:
Anyway I would be most greatful for your insight. BTW: I really enjoyed your articles on ray tracing and all the other stuff over the years on flipcode. Thanks. -h |
||
|
|
|
|
|
#22 |
|
New Member
Join Date: Jan 2006
Location: Australia
Posts: 3
|
Thinking about this a bit more, I think the real answer I am after here is whether anyone has found a way to get rid of the divide in the barycentric triangle intersection test.
Is there a way to calculate the distance from the ray origin to the triangle plane using a pre calculated reciprical that would replace the following... Code:
With a bunch of multiplies? -h |
|
|
|
|
|
#23 |
|
Valued Member
Join Date: Mar 2005
Posts: 135
|
Kd-trees partition space and their traversal is cheap.
If you don't exploit those 2 properties, you're better using another hierarchy. Like i said it seems you're missing those 2 points. First you bundle lots of primitives in leaves. Second, even in your last report, you're shooting ~2M rays in ~15s or 150k ray/s. That's off by an order of magnitude (for mono ray in a straight fp implementation), see http://homepages.paradise.net.nz/nickamy/benchmark.html for various aproaches/numbers. Take note that a (box) bvh for such isolated model is more or less on par with a kd-tree and is much more animation friendly. On top of that, kd-tree compilation still only takes 7% of your total rendering time. It seems to me that you're barking at the wrong tree ![]() There's many solutions to your problem. I'd suggest using a SAH bvh as it's way easier to write in a efficient fashion and amend for animation while still giving interesting speedups, but i have to admit i'm biased ![]() The animated kd-tree road is way bumpier. But first things first, please fix your traversal ASAP. |
|
|
|
|
|
#24 |
|
New Member
Join Date: Jan 2006
Location: Luxembourg
Posts: 15
|
yeah, you're right... I'm working on it, but without much succes I must say.
any direction ? i suppose reducing the size of the main structures mainly... craouette |
|
|
|
|
|
#25 |
|
New Member
Join Date: Sep 2004
Posts: 27
|
Craouette: Check out Wald's thesis. It has some suggestions for fast kd-tree traversal and triangle intersections, even without SIMD.
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|