tex3D & raytracing performance

Started by
5 comments, last by spek 11 years, 7 months ago
Simple question... or at least... let's start simple: Is a tex3D read (much) more expensive than a tex2D read?

With attempt #3529 on G.I. I tried to store light data (as voxels) in 3D-textures and raycast through them in several ways. It "works", but in order to keep it realtime, I need to reduce the raycasting loops as little as possible. Less voxels, short-range rays, less rays... All in all, the quality suffers and its still pretty damn slow. To give an idea what's going on:

// for ~25.000 voxels (rendered as points into a 64x64x64 3D texture)
// the fragment shader sends out 9 rays in several directions, to see where they collide with
// the environment (stored as SH values into another 64x64x64 3D texture)
for (int i=0; i < RAYCOUNT; i++)
{
float3 direction = RAY_DIR;
float3 rayPos = startPos;

// Check where the ray hits a surface
while !occluded && steps++ < 25
{
rayPos += direction * stepsize;
float4 occl = tex3D( shTexOccl, rayPos );
// decode Spherical Harmonics, and check if we collided
...
}
// Get GI data from ray end position
...
}

The raycasts are killing here. But at the same time, other effects that test rays over 2D textures don't seem to be very slow (RLR reflections for example can easily do hundreds of checks per pixel over a fullscreen image)...
- Is tex3D really that slow?
- Or is it just because the rays fly in all directions, making it very hard for the GPU to do things in parallel / texture caching?
- And/or is the loop coded in a dumb way?

Of course, there are multiple ways to store data. I could splat down everything into a 2D texture, or put it in a buffer for example. Not figured out how Crassin exactly stored his Voxel Octrees for techniques like "Voxel Cone Tracing", but it seems to be a mixture of 3D textures, data-buffers, and moreover, fast enough to achieve awesome things in realtime... Any hints on effective raytracing on a GPU?

Cheers,
Rick
Advertisement
Just exchange the tex3d access with a tex 2d access. Does it performe better ?

In worst case you have 225 independent reads + some calculations, which isn't really fast, considering that the worst case scenario of a single pixel can kill the performance of a whole pixel block. 3d texture access has theoretically some more work when filtering, but this depends on hardware implementation.
Hey!

You mean just change the tex3D call into tex2D? I can't try it right now, but wouldn't that case a lot of faults, and completely different behavior on the GPU, as the collision detection is wrong? The raycast(or "march") loop converts a world position into a volume texture space, then checks if that cell is blocking the ray or not. It could be done with a 2D texture too of course, but then I first would need to remap the coordinates. Which doesn't (easily) allow (tri)linear-interpolation btw.

But from what I understand a bit, a 3D texture read isn't necessarly a lot slower than a 2D read, asides from some a bit more complicated filtering?

Likely single pixels are indeed ruining the parallel multithreading party. I suppose the longest ray (= taken most steps) will dominate the performance of a black. And since the rays fly in all directions... Either way, does someone have experience with building fast raymarching in volume textures (or equivalents)?

Cheers
Well I suppose the idea is that Crassin was using a voxel octree and not just a voxel volume, which is a completely different approach (instead of marching through the volume, you raytrace against bounding boxes that enclose voxels) and is much more efficient. Brute-force volume raycasting simply does not work well on GPU's, it's already a slow method and the incoherent rays just make it that much worse. You could probably squeeze a few more frames per second out of it but it's probably not going to be realtime with the same quality as voxel octrees :/

Put differently, the raycasting algorithm you are using is too naive and has O(n) performance anyway (because as the number of voxels in your volume increases, you will need to increase the number of ray steps, otherwise you won't be able to resolve the smaller voxels, so your raymarching cost is directly proportional to the number of voxels you have, even if it doesn't seem to be) whereas voxel octrees have O(log(n)) performance. Still largely asymptotic, and to be fair the reason it's even realtime at all is not so much the octree but more a significant number of clever implementation tricks and hacks to make it run just that little bit faster.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Didn't read the exact implementation of voxel trees, but if I understand it right, they aren't storing the octree into a texture, but a ....cbuffer or something? So the marching loop checks that data, then the octree leaf-nodes point to a certain space in a (3D) texture where actual data such as colors (for several directions) are stored.

If that's the case, I wonder why they store light/colors in a texture. Just to benefit from (tri)linear filtering?


Talking about Voxel Cone Tracing. I still wonder how they deal with walls in narrow environments. As the cone gets wider, it samples from larger
nodes, which contain the averages of its sub-cells. But what to do if those larger cells overlap multiple rooms/corridors with walls between them? I guess that's still an issue, but since Unreal4 is using VCT, they might have found a smart trick?

Cheers

If that's the case, I wonder why they store light/colors in a texture. Just to benefit from (tri)linear filtering?


That's the main reason. Storing in a 3D texture also means that the memory accesses for bilinear filtering will be at least somewhat coherent, since GPU's will store 3D textures in a tiled layout.


Talking about Voxel Cone Tracing. I still wonder how they deal with walls in narrow environments. As the cone gets wider, it samples from larger
nodes, which contain the averages of its sub-cells. But what to do if those larger cells overlap multiple rooms/corridors with walls between them? I guess that's still an issue, but since Unreal4 is using VCT, they might have found a smart trick?


Thin geometry is always going to be a problem for techniques like this. The Unreal guys attempt to deal with it by storing lighting in an ambient cube basis (1 color for each of the 6 major axis directions). Using such a basis lets you prevent the contribution from the other side of thin geometry from "leaking" into your sample, and also lets you generate mips independently for each direction.
All right. The ambient-cube makes sense, although it still doesn't prevent light leaking from walls/objects that have the same axis:
| || |
| || |
Let's say we have 2 parallel corridors, and the octree-cells are so big that they overlap both corridors after some distance. The most right wall will contribute GI to the most left wall as well. Maybe that scenario doesn't appear so often, although in my narrow indoor game I'm not so sure about it... But maybe Unreal4 just accepts and swallows this problem.

As for the octree traversing, I read somewhere they store it in "linear memory". Do they mean something like a Vertex Buffer or (OpenGL) "Unified Buffer Object" with that? So much terminology!

This topic is closed to new replies.

Advertisement