<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">The geometry BVH is also heavily optimised for one task, fast ray/geometry intersections, with a specific data layout, alignment and build strategy. A light BVH may benefit from different build strategies (Is a median split better than SAH there?)  and could require different data stored inside the nodes. If I remember correctly, you’ll need to also be able to traverse the tree from a leaf to its root to get a given light sample’s PDF. This would be difficult to do with the current geometry BVH.<br class=""><div><br class=""></div><div>-Stefan</div><div><br class=""><blockquote type="cite" class=""><div class="">On 26. May 2018, at 15:12, Brecht Van Lommel <<a href="mailto:brechtvanlommel@gmail.com" class="">brechtvanlommel@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Erik,<div class=""><br class=""></div><div class="">I don't think we should reuse the geometry BVH code for light sampling. There is a bit of overlap but I expect it will end up making the code harder to understand and modify overall if that BVH code is used for two different purposes.</div><div class=""><br class=""></div><div class="">Instead create your own simple (BVH) tree structure, in a new <font face="monospace, monospace" class="">render/light_tree.cpp</font> file and integrate it into <font face="monospace, monospace" class="">render/light.cpp</font><font face="arial, helvetica, sans-serif" class="">. There we already create a distribution from a list of lamps and emissive triangle. </font>It's going to be faster to iterate and experiment than reusing the quite complex geometry BVH code.</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Brecht.</div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sat, May 26, 2018 at 8:01 AM, Erik Englesson <span dir="ltr" class=""><<a href="mailto:erikenglesson@gmail.com" target="_blank" class="">erikenglesson@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><div class="">Hi all,</div><div class=""><br class=""></div><div class="">I hope you have had a good week! <br class=""></div><div class=""><br class=""></div><div class="">This week I had a look at the code related to the building of a bounding volume hierarchy(BVH) in intern/cycles/bvh/. In my project, I will create a BVH of light sources instead of geometry, which is why I had a look at this part of the code. See below for some notes.<br class=""></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">/cycles/bvh/bvh.h/cpp</b></div><b class="">/cycles/bvh/bvh2.h/cpp<br class="">/cycles/bvh/bvh4.h/cpp</b>:<br class="">Code for BVHs where each node has 2 or 4 children. (BVH2,BVH4 inherits from BVH) It seems to have two functions of interest:<br class=""><u class="">BVH::create</u>: Based on the BVHParams input parameter a BVH2 or BVH4 is created.<br class=""><u class="">BVH::build</u>: Builds the BVH by using a helper class called BVHBuilder <br class=""><br class=""><b class="">/cycles/bvh/bvh_params.h</b>:<br class="">Parameters sent to the BVH::create algorithm, e.g. to use BVH2/BVH4, splitting thresholds, min primitives in leaf nodes etc.<br class=""><br class=""><b class="">/cycles/bvh/bvh_node.h/cpp:</b><br class="">There is a node base class called BVHNode and then InnerNode and LeafNode inherit from BVHNode. It seems each leaf stores indices to the first and last triangle they contain in a linear array of triangles. InnerNodes always stores two pointers to children. Is bvh4 using some other code or what am I missing?<br class=""><br class=""><b class="">/cycles/bvh/bvh_build.cpp:</b><br class="">Creates the actual BVH in BVHBuilder::run(). The most interesting method here seems to be build_node(). It is a recursive function that first checks if it is deep enough to create a leaf, otherwise it splits the node into child nodes and calls build_node on each child.<br class=""><div class=""><br class=""></div><div class="">BVHBuild takes a vector of Objects to its constructor, but from what I can see in cycles/render/scene.h, the lights are not part of this array. I will have to get them into my BVH in another way.<br class=""></div><br class=""><b class="">/cycles/bvh/bvh_split.cpp:</b><br class="">Algorithms to split a node into two child nodes. There is an object split method and a spatial split method and a combination of both. This is where the surface area heuristic(SAH) calculations happen.<br class=""><br class=""></div><div class="">Note: BVHBuilder::run() decides which splitting method is used.<br class=""><br class=""></div><div class=""><u class=""><b class="">Plan for next week</b></u></div><div class="">I have my final exam on Monday and then I can finally start this project full-time!  <br class=""></div><div class=""><br class=""></div><div class="">Next week I will have a look a bit more at the code in /cycles/bvh/ and then start to build my own BVH of lamps. It should be possible to reuse a lot of the code in bvh_build/bvh_split and I will have to figure out what the best way to implement my parts will be. Create new classes that uses code from existing classes either through inheritance or refactor or modify existing classes, etc.<br class=""></div><div class=""><br class=""></div><div class="">I will have to get access to light sources in the bvh building process somehow and create my own splitting method that uses a Surface Area Orientation Heuristic(SAOH) instead of SAH. To be able to create the SAOH splitting method, I need more information in each node related to lights, so I will have to create/modify the node data structure too.</div><div class=""><br class=""></div><div class="">I have planned for all of the mentioned steps to take two weeks to implement.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Erik<br class=""></div><div class=""><u class=""><b class=""><br class=""></b></u></div></div>
<br class="">-- <br class="">
Soc-2018-dev mailing list<br class="">
<a href="mailto:Soc-2018-dev@blender.org" class="">Soc-2018-dev@blender.org</a><br class="">
<a href="https://lists.blender.org/mailman/listinfo/soc-2018-dev" rel="noreferrer" target="_blank" class="">https://lists.blender.org/<wbr class="">mailman/listinfo/soc-2018-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
-- <br class="">Soc-2018-dev mailing list<br class=""><a href="mailto:Soc-2018-dev@blender.org" class="">Soc-2018-dev@blender.org</a><br class="">https://lists.blender.org/mailman/listinfo/soc-2018-dev<br class=""></div></blockquote></div><br class=""></body></html>