Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


tex3D & raytracing performance


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 spek   Prime Members   -  Reputation: 997

Like
1Likes
Like

Posted 02 October 2012 - 04:34 PM

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[i];
     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

Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 7987

Like
0Likes
Like

Posted 04 October 2012 - 02:45 AM

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.

#3 spek   Prime Members   -  Reputation: 997

Like
0Likes
Like

Posted 05 October 2012 - 02:21 AM

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

#4 Bacterius   Crossbones+   -  Reputation: 9262

Like
1Likes
Like

Posted 05 October 2012 - 02:50 AM

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.

Edited by Bacterius, 05 October 2012 - 02:53 AM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#5 spek   Prime Members   -  Reputation: 997

Like
0Likes
Like

Posted 06 October 2012 - 10:33 AM

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

#6 MJP   Moderators   -  Reputation: 11736

Like
0Likes
Like

Posted 06 October 2012 - 11:11 AM

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.

#7 spek   Prime Members   -  Reputation: 997

Like
0Likes
Like

Posted 07 October 2012 - 12:29 PM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS