Timeline for Voxel raycasting algorithm not working correctly
Current License: CC BY-SA 4.0
13 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 31, 2021 at 7:57 | comment | added | Glärbo | @Tristan367: I'll add my C code as another answer (no need to upvote it, I don't care about reputation), and my explanation of what I believe is happening – I do believe I found the reason! | |
Mar 31, 2021 at 5:24 | comment | added | Tristan367 | It looks like a big part of it was as I explained in the last comment because fixing it makes it look a lot better now, though there are still issues, especially on the y-axis. And my bounds checking upon calculating the 3D index of the voxel is wrong I think. I included an updated picture of what it looks like now. Thanks for the help so far btw, you are awesome! | |
Mar 31, 2021 at 4:45 | comment | added | Glärbo |
@Tristan367: Hmmm, yes. The major difference between our implementations is that mine jumps to the next intersection via assignment, you add the delta to the current position. See how mine just updates the intersection positions, and then just picks the next closest position? The only vector addition in the loop is when updating the next intersection position, xnext = xnext + xdelta; , ynext = ynext + ydelta; , znext = znext + zdelta; ? Perhaps the bug lies therein.
|
|
Mar 31, 2021 at 3:51 | comment | added | Tristan367 |
Yes I know. I think there may be something wrong with the part labeled // finding smallest distance along the direction to the next voxel face towards the top of the while loop. Because if the ray's shortest path to the next voxel is the same axis as the coordinate in the last voxel, the distance measure is 0. I tried adding a small number like 0.001 to the math to offset it and it worked a little bit better, though there were new issues.
|
|
Mar 31, 2021 at 3:41 | comment | added | Glärbo | @Tristan367: I don't have anything that can run HLSL (I'm Linux-only), so it's very hard for me to check your code.. I'm now writing one in C to make the comparison easier. You do realize that each voxel cell has exactly 3 faces? One at integer x, one at integer y, and one at integer z? So, no matter what direction you intersect a voxel, you always intersect one or more of those three faces of the cell whose integer coordinates match the integer part of the intersection point? | |
Mar 31, 2021 at 3:34 | comment | added | Tristan367 | Haha ok so do you have any idea why mine is not working? I'm seeing y faces when I should be seeing x and z faces and vice versa and other weird things. | |
Mar 31, 2021 at 3:25 | comment | added | Glärbo | @Tristan367: Oh that! :) Yes, of course. I told you I try to keep the math explicit and clear, and leave all such opimizations for you! | |
Mar 31, 2021 at 2:35 | comment | added | Tristan367 |
I understand that I was just telling you that (1.0f / unitdir.x) * unitdir is the same as doing unitdir / unitdir.x right?
|
|
Mar 31, 2021 at 2:30 | comment | added | Glärbo |
@Tristan367: The w components will be the length of each step along the ray, so 11/2 = 5.5 , 11/6 = 1.833 , and 11/9 = 1.222 . Summing these separately (so xdelta with only xdelta , ydelta only with ydelta ) we get the transitions to consecutive x (xdelta ), y (ydelta ) , or z (zdelta ) faces, with the distance to that face in the w component. Then we just see which one is next!
|
|
Mar 31, 2021 at 2:25 | comment | added | Glärbo |
@Tristan367: Note that (1.0f / unitdir.x) is a scalar (a number), whereas unitdir is a vector (whose length is 1); (1.0f / unitdir.x) * unitdir yields a vector whose length is reciprocal of unitdir.x . This length corresponds to the movement along the ray from one intersection with an x face to the next. Consider unitdir = {2/11,6/11,9/11} (ignore the .w component for now). We get xdelta = 11/2*unitdir = { 2/2, 6/2, 9/2 } = {1, 3, 4.5} , ydelta = {2/6, 6/6, 9/6} = {0.333, 1, 1.5} , zdelta = {2/9, 6/9, 9/9} = {0.222, 0.667, 1} .
|
|
Mar 31, 2021 at 0:08 | comment | added | Tristan367 | I realized a few errors in my code and revised it but I still have the same issue could you check it again, please? I don't understand why you are dividing 1 by a number and then multiplying that by another number, you could just divide that other number with the first number, right? ie (1/5) * 10 = 10 / 5 | |
Mar 30, 2021 at 6:05 | review | First posts | |||
Mar 30, 2021 at 8:56 | |||||
Mar 30, 2021 at 6:03 | history | answered | Glärbo | CC BY-SA 4.0 |