ray_tracing__advance/raytrace.cpp
auto Raytracer::objectToVkGeometryKHR(const ObjModel& model)
{
  // Building part
  VkDeviceAddress vertexAddress = nvvk::getBufferDeviceAddress(m_device, model.vertexBuffer.buffer);
  VkDeviceAddress indexAddress  = nvvk::getBufferDeviceAddress(m_device, model.indexBuffer.buffer);

  VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR};
  triangles.vertexFormat             = VK_FORMAT_R32G32B32_SFLOAT;
  triangles.vertexData.deviceAddress = vertexAddress;
  triangles.vertexStride             = sizeof(VertexObj);
  triangles.indexType                = VK_INDEX_TYPE_UINT32;
  triangles.indexData.deviceAddress  = indexAddress;
  triangles.transformData            = {};
  triangles.maxVertex                = model.nbVertices;

  // Setting up the build info of the acceleration
  VkAccelerationStructureGeometryKHR asGeom{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR};
  asGeom.geometryType       = VK_GEOMETRY_TYPE_TRIANGLES_KHR;
  asGeom.flags              = VK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR;  // For AnyHit
  asGeom.geometry.triangles = triangles;


  VkAccelerationStructureBuildRangeInfoKHR offset;
  offset.firstVertex     = 0;
  offset.primitiveCount  = model.nbIndices / 3;  // Nb triangles
  offset.primitiveOffset = 0;
  offset.transformOffset = 0;

  nvvk::RaytracingBuilderKHR::BlasInput input;
  input.asGeometry.emplace_back(asGeom);
  input.asBuildOffsetInfo.emplace_back(offset);
  return input;
}
//--------------------------------------------------------------------------------------------------
// Converting a OBJ primitive to the ray tracing geometry used for the BLAS
//
Converting a OBJ primitive to the ray tracing geometry used for the BLAS
Converting a OBJ primitive to the ray tracing geometry used for the BLAS
auto Raytracer::objectToVkGeometryKHR(const ObjModel& model)
{
  VkDeviceAddress vertexAddress = nvvk::getBufferDeviceAddress(m_device, model.vertexBuffer.buffer);
  VkDeviceAddress indexAddress  = nvvk::getBufferDeviceAddress(m_device, model.indexBuffer.buffer);
  VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR};
  triangles.vertexFormat             = VK_FORMAT_R32G32B32_SFLOAT;
  triangles.vertexData.deviceAddress = vertexAddress;
  triangles.vertexStride             = sizeof(VertexObj);
  triangles.indexType                = VK_INDEX_TYPE_UINT32;
  triangles.indexData.deviceAddress  = indexAddress;
  triangles.transformData            = {};
  triangles.maxVertex                = model.nbVertices;
  VkAccelerationStructureGeometryKHR asGeom{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR};
  asGeom.geometryType       = VK_GEOMETRY_TYPE_TRIANGLES_KHR;
  asGeom.flags              = VK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR;  
  asGeom.geometry.triangles = triangles;
  VkAccelerationStructureBuildRangeInfoKHR offset;
  offset.firstVertex     = 0;
  offset.primitiveCount  = model.nbIndices / 3;  
  offset.primitiveOffset = 0;
  offset.transformOffset = 0;
  nvvk::RaytracingBuilderKHR::BlasInput input;
  input.asGeometry.emplace_back(asGeom);
  input.asBuildOffsetInfo.emplace_back(offset);
  return input;
}
auto Raytracer :: objectToVkGeometryKHR ( const ObjModel & model ) { VkDeviceAddress vertexAddress = nvvk :: getBufferDeviceAddress ( m_device , model . vertexBuffer . buffer ) ; VkDeviceAddress indexAddress = nvvk :: getBufferDeviceAddress ( m_device , model . indexBuffer . buffer ) ; VkAccelerationStructureGeometryTrianglesDataKHR triangles { VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR } ; triangles . vertexFormat = VK_FORMAT_R32G32B32_SFLOAT ; triangles . vertexData . deviceAddress = vertexAddress ; triangles . vertexStride = sizeof ( VertexObj ) ; triangles . indexType = VK_INDEX_TYPE_UINT32 ; triangles . indexData . deviceAddress = indexAddress ; triangles . transformData = { } ; triangles . maxVertex = model . nbVertices ; VkAccelerationStructureGeometryKHR asGeom { VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR } ; asGeom . geometryType = VK_GEOMETRY_TYPE_TRIANGLES_KHR ; asGeom . flags = VK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR ; asGeom . geometry . triangles = triangles ; VkAccelerationStructureBuildRangeInfoKHR offset ; offset . firstVertex = 0 ; offset . primitiveCount = model . nbIndices / 3 ; offset . primitiveOffset = 0 ; offset . transformOffset = 0 ; nvvk :: RaytracingBuilderKHR :: BlasInput input ; input . asGeometry . emplace_back ( asGeom ) ; input . asBuildOffsetInfo . emplace_back ( offset ) ; return input ; }
Converting a OBJ primitive to the ray tracing geometry used for the BLAS
Converting a OBJ primitive to the ray tracing geometry used for the BLAS
// Building part // Setting up the build info of the acceleration // For AnyHit // Nb triangles