So I need to raycast a octree for closest leaf node as efficient as possible. I will be doing it on compute shader (hlsl), but I think it doesn't matter because first I need to understand the approach and math behind this process in general.

My struct looks like this:

struct OctreeNode
    uint  size; // size of cubic node
    uint posX; // center of node
    uint posY; // center of node
    uint posZ; // center of node
    uint childExists;
    uint isLeaf;
    uint isChild;

    uint parentIndex; //Parent node index in structured buffer
    uint minchildIndex; // Node child min index in structured buffer (+1 is next child, etc)   
    uint index; //Index in structured buffer

Octree is rather big, so I guess I can't afford to raycast everything and then compare distances. I have been looking into https://stackoverflow.com/questions/6281415/octree-raycasting-raytracing-best-ray-leaf-intersection-without-recursion , but I do not understand the answer (especially HLSL one with hitbox what is unknow thing).

Any hints, code, directions highly appreciated.

  • \$\begingroup\$ In that answer, hitbox seems to be just a function that tests whether the given ray hits or misses a given AABB within the given time/distance interval, returning true or false. Have you had difficulty coding such a function? \$\endgroup\$
    – DMGregory
    May 7, 2021 at 14:10
  • \$\begingroup\$ Yes! I don't know how to code such function. Other than that I don't understand the TestValue. It's kind of described, but I don't get it. Also don't understand how it can work with One hitbox test. I don't think that example works for my case. \$\endgroup\$ May 7, 2021 at 14:44
  • \$\begingroup\$ We have past Q&A about ray vs AABB tests. TestValue is just a limit for how many loops the routine will run. You can replace it with a constant high enough to handle the density of octrees you work with. \$\endgroup\$
    – DMGregory
    May 7, 2021 at 14:58
  • \$\begingroup\$ I still think it's no relevant to my structure. It doesn't ask isLeaf or query empty nodes. Or I just don't get it. Been over and over again. \$\endgroup\$ May 7, 2021 at 15:07
  • \$\begingroup\$ It sounds like you have more specific questions about this that should probably be explained in detail in your question post above, so we don't have to guess about what you need. \$\endgroup\$
    – DMGregory
    May 7, 2021 at 15:18


You must log in to answer this question.

Browse other questions tagged .