#### Archived

This topic is now archived and is closed to further replies.

# Raytracing problem with Octree

This topic is 5202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i coded an octree, and it works for rendering. But for my main concern, to speed up shadow calculations for my radiosity processor, it fails... the problem is not the ray / polygon intersection (it is unchanged), shadow calculations worked before using the octree. maybe it is useful to post my code for the octree raytracer: To explain: The code returns the leaf node with the smallest box that intersects the ray. The leaf is then returned and its primitives are processed by the caller.
ZNode* raytrace_node(ZNode *node, const vec3 &rO, const vec3 &delta)
{
if (!node->ray_intersect(rO, delta))
return 0;

if (node->_isLeaf)
{
return node;
}

for (int i = 0; i < 8; i++)
{
ZNode *thisNode = 0;

if (node->_octants[i])
{
thisNode = raytrace_node(node->_octants[i], rO, delta);

if (thisNode)
return thisNode;
}
}

return 0;
}

greets
Gammastrahler



##### Share on other sites
How do you deal with situations where the ray intersects more than one node (i.e. the common case)? It looks like the code will just return the first leaf node it finds that intersects the ray.
In my code I find the leaf node containing the start of the ray, and then walk through the octree to find all the nodes it intersects. Also, I used to do it by breaking the ray up into smaller sections, calculating the AABB for each section, and then find the nodes that intersect with those AABBs (which was still pretty quick).
Sorry if I haven''t understood the problem though .

T

1. 1
Rutin
25
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 11
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631754
• Total Posts
3002104
×