问题标签 [bounding-volume]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
opengl - Why does the bounding box appear around the object in a strange way?
I am creating an OpenGL based ray tracer for polygon models. The basic structure is about to render the results to a quad from the fragment shader. To accelerate the application, BVH-trees are used. Because there is no recursion in GLSL, I decided to find an other way to traverse the bounding boxes. The bvh nodes (including the boxes) and the primitive coordinates are sent to the fragment shader into a shader storage buffer.
I am using the basic idea described in: Threaded BVH-tree traversal in shaders
The above solution uses links "which are used to skip nodes which don't need to be evaluated". There is a hit link: which node to jump to in case of a hit and there is a miss link: which node to jump to in case of a miss.
Actually, I am not using links to navigate between the boxes, as I have a complete binary tree, which makes easier to navigate between the different depths. But the basic concept is similar to link above. I store the nodes in breadth-first order.
Unfortunately, when the program is running there is a weird result. I can see the object partly ray-traced and the bounding box as well. The bounding box has grey color, but this color should be the color of the background.
The below picture shows the current state. You should see a cone in a grey background, but instead of this you can see a grey bounding box around its object.
... and how it should look like (it is a non bvh-tree version)
Here is my fragment shader:
Any help is well appreciated.
Update 1:
I used Rabbid76's advice and modified the rayIntersectWithBox
method's return statement from return t1 >= t0;
to return tmin.x < tmax.x && tmin.y < tmax.y && tmin.z < tmax.z;
As you can see in the snapshot, there is no visible bounding box, but the object still has some troubles.
Update 2:
I updated the traverseBvhNode
of fragment shader's code. I am sure the algorithm traverses all the nodes now, as I checked if i==nodes.length()
and it gives true.
Unfortunately, the result in the window is still the same as in my last update.
Here are the modifcations of traverseBvhNode
method:
For simplicity I put the content of
firstIntersection
method totraverseBvhNode
method.Moreover, I move the
return besthit
line to the end of traverseBvhNode method, because I have to traverse all nodes before returning with the best intersection.I also modified the for cycle to a while cycle, as with
while
I can modify the value ofi
in the block, whereas for does not permit this kind of action.Because there are some
continue
instructions as well in thetraverseBvhNode
method, I put thei++
instruction at the beginning of the method.
Here is the updated code:
python - 将张量数据裁剪到包围体
我有 2 个关于 tensorflow 2.0 的问题,重点是 tensorflow 如何在其操作图中处理组合条件测试。
任务:将大量数据点切成块,并将索引存储到属于该卷的样本(而不是样本本身)。
我最初的方法:循环所有元素并收集“边界体积”内的数据点的索引。这非常慢,无论我如何重新排序坐标上的比较。
然后我想出了产生布尔张量并在逻辑上“和”它们以获得indices
我需要的元素的想法。快了很多,如下一个示例所示:
此代码产生正确的结果,但我想知道它是否是最佳的。
第一个问题是关于调度的:
如果包含操作的张量流图知道一些(块)已经测试过的元素,它是否会剔除(块)条件测试
False
。由于logical_and
组合了逻辑条件,因此对这些元素的后续条件测试将永远不会产生True
.
实际上,在上面的示例中c1
,并且正在就可能已经从集合中排除的c2
元素提出问题。c0
尤其是当您有大量元素要测试时,这可能会浪费时间,即使在并行硬件平台上也是如此
那么,如果我们根据之前的测试结果级联测试呢?虽然这看起来像是一个已解决的问题,但这个解决方案是不正确的,因为最终indices
张量将引用一个子集_X
,而不是总集X
:
我当然可以通过简单地扩展来“解决”这个问题X
,这样每个元素也可以在原始列表中包含自身的索引,然后像以前一样继续。
所以我的第二个问题是关于功能的:
tf 是否有一种方法可以让 GPU/张量基础设施提供簿记,而无需在这个看似简单的问题上花费内存/时间?