Archived

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

Gammastrahler

Raytracing problem with Octree

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;
}

Thanks in advance!

greets
Gammastrahler

Share this post


Link to post
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

Share this post


Link to post
Share on other sites