Applied Spatial Hash Function in Ray Tracing By : Jaruwan Mesit Optimized ray tracing In class, we have learned two methods • Bounding Volume Hierarchy • Grid New method • Spatial Hash function (My project) Bounding Volume Hierarchy – Sort all objects in the scene – Create the tree from sorted objects – Create the bounding boxes to bound the objects in the same leave – Find the intersection between ray and bounding volume Grid (1) • Create grid from the scene • Create bounding box in every object in scene • Create the list of the object in the grid by comparing minimum and maximum points of bounded objects and grid (complex) • If ray pass through the grid – Check if the ray also pass the objects Some case is better than Bounding Volume Hierarchy but some case not. ******** We can do something easier******** Grid (2) Spatial Hash Function (1) • Simple and no comparison • Using hash function and hash table Spatial Hash Function (2) • Create grid • Give the index to grid by using spatial hash function which hashes to minimum point of Grid Index = ( floor(Grid.min.x / length) * xprime+ floor(Grid.min.y / height) * yprime + floor(Grid.min.z / width) * zprime) % bucketsize; length = Grid length height = Grid height width = Grid width xprime, yprime, zprime = any prime number for x, y, and z • Now we have Grid with the index. Spatial Hash Function (3) Grid 1 Index 1 Grid 2 Index 2 Grid 3 Index 3 Grid 4 Index 4 Grid 5 Index 5 Spatial Hash Function (4) • Create the bounding box to bound every object in scene • Create hash table by using the same hash function Spatial Hash Function (5) = point[1..8] HashIndex = ( floor(point[1..8].min.x /length) * xprime+ floor(point[1..8].min.y /height) * yprime + floor(point[1...8].min.z /width) * zprime) % bucketsize; • Put the object name into the hash index Spatial Hash Function (6) Hash Index Now We have 1) Hash table 2) List of Grid and Index Grid 1 Index 1 1 Object 1 Object 2 Object4 2 Object 1 Object 4 3 Object 3 4 Object 4 Grid 2 Index 2 Grid 3 Index 3 Grid 4 Index 4 Grid 5 Index 5 Spatial Hash Function (7) Ray Pass Through Grid 1 Grid 1 Index 1 Grid 2 Index 2 Grid 3 Index 3 Grid 4 Index 4 Grid 5 Index 5 Hash Index 1 Object 1 Object 2 Object4 Find Intersection with object 1, 2, and 4 Spatial Hash Function (8) Experiments # of objects Without any technique Bounding Volume Hierarchy (5) Grid (3) Spatial Hash Function with (3, 1001 bz) 30 spheres 5544 ms. 3654 ms. 5264 ms. 6420 ms. 50 spheres 8649 ms. 8560 ms. 6908 ms. 7770 ms. 100 spheres 25093 ms. 21314 ms. 21014 ms. 18966 ms. Problem Grid and hashing function These two girds have to be compute for intersection. This is the problem why hashing function and grid spend time more than bounding volume hierarchy in some case. Distributed objects If the objects are distributed among grid, hashing function and grid are better than bounding volume hierarchy. Images End • Question?