RenderKit / embree

Embree ray tracing kernels repository.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GeomID, PrimID in Pathtracer Tutorial

tbhunderbird opened this issue · comments

I am trying to figure out, where and how geometry IDs and primitive IDs are assigned in the Tutorial Code (specifically the pathtracer tutorial).
Could someone please help me to understand how a read .obj file with a single mesh ends up with hundreds of primitive IDs and thousands of geometry Ids?

All the best and thanks,
Tobias

The Embree API supports geometries (such as triangle meshes) and primitives inside these geometries (such as triangles inside a triangle mesh). You attach geometries to Embree scenes, and the slot it got attached corresponds to the geometry ID returned. The n'th triangle has primitive ID of n.
The pathtracer in default mode loads an obj mesh and splits it up into geometries/triangle meshes whenever a different material is used. What do you want to do? The precise way of splitting the input into geometries does not matter from the pathtracer side much, the pathtracer itself just indexes with these geomIDs into its scene representation to access materials for instance, or use the primID to access triangle vertices when required.

I have two associated problems/ideas in mind:
1.) I need to generate a pseudo-random number that is always the same, when the same triangle is hit. I guess I could use the combination of geom and prim ID if I understand you correctly.
2.) I need to know which of the added geometried is hit (obj1, obj2, ...). How would I do that?

  1. Yes, the geomID/primID pair identifies your triangle in default mode (no instancing)
  2. The geometry/triangle mesh is identified by the geomID

Regarding 2.) use case:
You mentioned that the pathtracer splits it up into geometries whenever a new material is encountered. Thus, the geomId is more or less random and I cannot infer the original object ID I added.
Is there a way to assign some sort of ID that I can infer or read once I found an intersection?

You could change the OBJ loader to create a mesh for each object. Have a look at the obj_loader.cpp and execute flushFaceGroup at the places you want.