diff --git a/ray_tracing_intersection/hello_vulkan.cpp b/ray_tracing_intersection/hello_vulkan.cpp index cc4ab8e..fcc46ca 100644 --- a/ray_tracing_intersection/hello_vulkan.cpp +++ b/ray_tracing_intersection/hello_vulkan.cpp @@ -720,25 +720,27 @@ nvvk::RaytracingBuilderKHR::Blas HelloVulkan::sphereToVkGeometryKHR() //-------------------------------------------------------------------------------------------------- // Creating all spheres // -void HelloVulkan::createSpheres() +void HelloVulkan::createSpheres(uint32_t nbSpheres) { std::random_device rd{}; std::mt19937 gen{rd()}; std::normal_distribution xzd{0.f, 5.f}; - std::normal_distribution yd{3.f, 1.f}; + std::normal_distribution yd{6.f, 3.f}; std::uniform_real_distribution radd{.05f, .2f}; // All spheres Sphere s; - for(uint32_t i = 0; i < 2000000; i++) + m_spheres.resize(nbSpheres); + for(uint32_t i = 0; i < nbSpheres; i++) { - s.center = nvmath::vec3f(xzd(gen), yd(gen), xzd(gen)); - s.radius = radd(gen); - m_spheres.emplace_back(s); + s.center = nvmath::vec3f(xzd(gen), yd(gen), xzd(gen)); + s.radius = radd(gen); + m_spheres[i] = std::move(s); } // Axis aligned bounding box of each sphere std::vector aabbs; + aabbs.reserve(nbSpheres); for(const auto& s : m_spheres) { Aabb aabb; @@ -751,7 +753,7 @@ void HelloVulkan::createSpheres() MaterialObj mat; mat.diffuse = vec3f(0, 1, 1); std::vector materials; - std::vector matIdx; + std::vector matIdx(nbSpheres); materials.emplace_back(mat); mat.diffuse = vec3f(1, 1, 0); materials.emplace_back(mat); @@ -759,7 +761,7 @@ void HelloVulkan::createSpheres() // Assign a material to each sphere for(size_t i = 0; i < m_spheres.size(); i++) { - matIdx.push_back(i % 2); + matIdx[i] = i % 2; } // Creating all buffers diff --git a/ray_tracing_intersection/hello_vulkan.h b/ray_tracing_intersection/hello_vulkan.h index fd35851..0521ea6 100644 --- a/ray_tracing_intersection/hello_vulkan.h +++ b/ray_tracing_intersection/hello_vulkan.h @@ -85,9 +85,9 @@ public: // Information pushed at each draw call struct ObjPushConstant { - nvmath::vec3f lightPosition{10.f, 15.f, 8.f}; + nvmath::vec3f lightPosition{10.f, 55.f, 8.f}; int instanceId{0}; // To retrieve the transformation matrix - float lightIntensity{100.f}; + float lightIntensity{1000.f}; int lightType{0}; // 0: point, 1: infinite }; ObjPushConstant m_pushConstant; @@ -182,5 +182,5 @@ public: nvvk::Buffer m_spheresAabbBuffer; // Buffer of all Aabb nvvk::Buffer m_spheresMatColorBuffer; // Multiple materials nvvk::Buffer m_spheresMatIndexBuffer; // Define which sphere uses which material - void createSpheres(); + void createSpheres(uint32_t nbSpheres); }; diff --git a/ray_tracing_intersection/main.cpp b/ray_tracing_intersection/main.cpp index 3dbaba0..115103a 100644 --- a/ray_tracing_intersection/main.cpp +++ b/ray_tracing_intersection/main.cpp @@ -69,11 +69,12 @@ void renderUI(HelloVulkan& helloVk) up = nvmath::vec3f(item == 0, item == 1, item == 2); CameraManip.setLookat(pos, eye, up); } - ImGui::SliderFloat3("Light Position", &helloVk.m_pushConstant.lightPosition.x, -20.f, 20.f); - ImGui::SliderFloat("Light Intensity", &helloVk.m_pushConstant.lightIntensity, 0.f, 100.f); + ImGui::SliderFloat3("Light Position", &helloVk.m_pushConstant.lightPosition.x, -200.f, 200.f); + ImGui::SliderFloat("Light Intensity", &helloVk.m_pushConstant.lightIntensity, 0.f, 1000.f); ImGui::RadioButton("Point", &helloVk.m_pushConstant.lightType, 0); ImGui::SameLine(); ImGui::RadioButton("Infinite", &helloVk.m_pushConstant.lightType, 1); + ImGui::Text("Nb Spheres and Cubes: %d", helloVk.m_spheres.size()); } ////////////////////////////////////////////////////////////////////////// @@ -177,7 +178,7 @@ int main(int argc, char** argv) // Creation of the example // helloVk.loadModel(nvh::findFile("media/scenes/Medieval_building.obj", defaultSearchPaths)); helloVk.loadModel(nvh::findFile("media/scenes/plane.obj", defaultSearchPaths)); - helloVk.createSpheres(); + helloVk.createSpheres(2000000); helloVk.createOffscreenRender(); helloVk.createDescriptorSetLayout();