createSpheres has an argument for creating how many elements

This commit is contained in:
mklefrancois 2020-06-10 12:07:55 +02:00
parent 68164eafbf
commit 90dc65f220
3 changed files with 17 additions and 14 deletions

View file

@ -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<float> xzd{0.f, 5.f};
std::normal_distribution<float> yd{3.f, 1.f};
std::normal_distribution<float> yd{6.f, 3.f};
std::uniform_real_distribution<float> 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);
m_spheres[i] = std::move(s);
}
// Axis aligned bounding box of each sphere
std::vector<Aabb> 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<MaterialObj> materials;
std::vector<int> matIdx;
std::vector<int> 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

View file

@ -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);
};

View file

@ -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();