一个基于 Vulkan 的简单渲染器,用于我关于实时透明度的毕业论文
A simple Vulkan-based renderer for my master thesis on real-time transparency under the advise of Patrick Cozzi.
The renderer will be a rasterizer the implements phenomenological transparency by Morgan McGuire to demonstrate how the GPU could map well to this algorithm for real-time transparency.
This README also documents my learning progress with Vulkan and GPU programming.
I rewrote the SBVH memory scheme based on Parallel Spatial Splits in Bounding Volume Hierarchies .
SBVH construction requires temporary memory to store fragments (from triangle split) and primitive references (full triangle) created during splitting. Previously, the memory was packed tightly inside an array and shuffled to partition the references into left and right sides of the split. However, this has created complication with additinal fragments due to triangle splits where child nodes can have larger memory than parent nodes. So before construction starts, I allocate an additional 20% memory of buffer space for the potential fragments. The availabe buffer space is assigned to the function stack in each recursive calls using the first and last pointers. During the partitioning phase, the fragments of the left and right child sets are aligned to the upper and lower boundary and grow toward the center. Free space is reserved in between. Then I recursively distribute the fragments again based on this scheme, applying to both spatial and object splits, until a leaf node is create. Once no free memory is available, the construction switches to using full object splits.
The advantage of this division scheme is that the application can determine ahead of time how much memory to allocate, and each local task has full access to all its available memory without affecting other tasks. For potential parallel SBVH construction, this is extremely beneficial for lock-free multithreading since tasks don't need memory sychronization.
To simplify implementation, I use a PrimInfo struct to also mean a fragment reference. This does not necessarily mean that a primitive is duplicated, it's just that two or more nodes can point to the same primitive.
struct PrimInfo {
PrimID primitiveID;
BBox bbox;
}The PrimInfo is then used to construct leaf nodes when splitting is no longer beneficial.
Some scenes can potentially generate a deep tree, so I limit the amount of spatial splits based on a split budget. It is a counter that decrements each time a spatial split happens. Once the budget is fully consumed, the construction switches to using full object splits.
In some performance tests, SBVH can save up to 20-30ms of traversal time, with the cost of increased memory. However, not all scenes benefit from SBVH, although SBVH never performs less than BVH. By tweaking the spatial split budget and limiting tree depth, I observed that performance is significantly affected. There seems to be an optimal threshold for the budget and the tree depth, so I will need to do some additional tests.
Other misc. tasks:
Since the infrastructure has diverged quite a bit from my codes for hybrid rendering, I'm working on re-porting that codes into this repo. With hybrid, I will only need to trace secondary rays for refractive & reflective materials. With shadow rays, I'm thinking of voxelizing the space, then store lighting information for each voxel to speed up shadow computation. However, it doesn't seem to be a big bottleneck at this point yet.
This is a fairly short update. I spent most of the time fixing several bugs from building the SBVH.
I have added a concept of "sub geometry", as in a geometry info struct that contains a bounding box for only part of the geometry, due to spatial split. They are stored together with the regular geometry info struct.
firstGeomOffset and numGeoms when querying geometries from a leaf node. The reason is because the same geometry can be included in two spatially split node, so we simply can't assume that each leaf node stores a unique geometry anymore.A couple of issues:
With GDC and interviews coming up, I might be limitted in time to get some work in next week, but will likely to resume progress the week after.
To determine the cost of traversing my SBVH, I appended to the Ray object a traversal cost. When ray tracing through the scene, each time the ray enters a node, its cost is increased by 0.25 for just entering the node, and by 1.0 for each ray-primitive intersection test inside the leaf node. The total cost is then used to color the scene with more red is equivalent to higher cost, and green means low cost.
I mocked up a simple test scene in Maya, with 456 primnitives.
For each BVH implementation, the following renders show the ray traversal heat map for each splitting method:
| Equal counts | SAH | SBVH |
|---|---|---|
One neat thing we can see now is that SAH and SBVH are superior to EqualCounts. This visualization, however, led me to believe that there is DEFINITELY a bug somewhere in my code. The spatial split (3rd column) should have shown a different heat map. There must be something wrong.
So to dig futher, I put together two additional scenes from Maya to test spatial splitting (whether it did occur at the splitting plane or not). To enforce spatial splitting, I simply ignore computing the cost for object split.
a) Triangles
This scene contains solely triangles, built into quads. Each triangle primitive should be subdivided if a spatial split occurs.
| Diffuse | Heat map |
|---|---|
b) Cuboid
This scene is a highly subdivided cuboid shape, with random faces extruded for visibility. With a high density of such a geometry when triangulated, I suspect that I should be able to see even clearer spatial splitting.
| Diffuse | Heat map |
|---|---|
By visual inspection, I could see that the spatial split DID NOT occur along the maximum extent for primitives that straddle multiple splitting planes. This confirmed to me that I should re-examined my code. In conclusion, there is a bug that new bounding boxes created by these spatial splits are currently not inserted at the right position, and that I did not take care of growing the bounding box list properly. For this week, I haven't had enough time to fix this error, so it is going to be in the next week's planning!
VulkanHybridRenderer boilerplate. Prepping for porting the hybrid renderer from my school project in GPU Programming.SBVH and AccelStructure interfaces to allow future extensions.This week, I implemented the full SBVH (spatial splitting) for accelerating ray tracing. The structure follows this algorithm:
…There is a step referenced in the paper about unsplitting references, but I haven't had yet a chance to implement it.
When testing SBVH versus just regular BVH with the following scene:
| Scene | |
| # Primitives | 4212 |
| # frames | 300 |
the result is roughly similar to full BVH:
| No spatial split | With spatial split | |
|---|---|---|
| ms / frame | 130.33 | 127.26 |
It could be that this isn't the right scene to benefit from spatial split, or something is incorrect in my implementation. I'm going to test around with a couple different scenes also.
I tested with a large mesh, and seemed to have a bug either with the visual debugging, or with storing primitives inside leaf node. In the scene below, half of all the leaf nodes disappeared!
Previously, the BVH only supported splitting using the EqualCounts method. This method partition evenly the number of geometries for each child node of a BVH interior node. While simple to implement and easy to understand, EqualCounts isn't the most efficient way to construct BVH tree. So this week I implemented the Surface Area Heuristics method, or SAH. Ray tracing speed is constrained by the cost of ray-triangle intersection, so the more we can skip irrelevant triangles, the better. SAH uses the surface area of primitive's bounding box to compute to probability the ray can intersect that bounding box, and decide whether to split a BVH node at that point, or generate a leaf node. We can think of the cost of splitting a node along a plane as:
`TotalCost = C_t + C_i * numTrisA * Area(childA) / Area(p
暂无开放 Issues,或尚未同步最近议题。