170 likes | 292 Views
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
E N D
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********
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 Object 1 Object 2 Object4 1 • Now We have • Hash table • List of Grid • and Index 2 Object 1 Object 4 3 Object 3 4 Object 4 Grid 1 Index 1 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 Object 1 Object 2 Object4 1 Find Intersection with object 1, 2, and 4
Experiments Spatial Hash Function (8)
ProblemGrid 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.
End • Question?