optix获取交点的模型id

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yellow_paper/article/details/85258705

最近遇到了怎样获取交点对应模型的问题。

方法参考了nvida网站的帖子,因为我们对每个geomrtry都定义了其intersection program, 而求交点的过程就是在这个program中发生的,所有的顶点数组、三角形索引数组等都是传到这里面的,因此我们对交点的模型ID识别也需要在这里定义。

只需要创建geometry时多传进来1个ID的参数,代表模型的ID信息,就能够获取到了。然后用attribute把ID传出来到hit program中即可。

还有一种办法是把modelID传到Material中,这样需要每个object都有着不同的material。但是需要注意多个模型的情况下,不能使用geometry instance的方式去构造group,因为这样子所有的object都是同一个ID了。

- If you have exactly one Transform node per object, let your Material have a variable rtDeclareVariable(unsigned int, objectID, , );
- In your given node hierarchy you load the Geometry only once, but assign different Material parameters (=> objectID) per hierarchy path to each GeometryInstance (i.e. per Transform) to identify the Geometry as you wish.
- To report back to the ray generation program that you hit a specific object, add a member 
unsigned int objectID; to your custom PerRayData payload.
- Inside the closest-hit program write the objectID from the material into the objectID of the current ray payload. 
- Inside the ray generation program add a switch-case which writes the other PerRayData results you generated into the output buffer you select with the PerRayData objectID.

猜你喜欢

转载自blog.csdn.net/yellow_paper/article/details/85258705