Skip to content
Snippets Groups Projects
Commit f3261631 authored by Katharina Krämer's avatar Katharina Krämer
Browse files

[#69] added multiple drawcalls for particles

parent 751d1759
No related branches found
No related tags found
1 merge request!56Resolve "Partikelsystem"
Pipeline #25686 failed
...@@ -10,7 +10,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) ...@@ -10,7 +10,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# adding source files to the project # adding source files to the project
add_executable(particle_simulation src/main.cpp add_executable(particle_simulation src/main.cpp
src/ParticleSystem.hpp src/ParticleSystem.cpp) src/ParticleSystem.hpp src/ParticleSystem.cpp
src/Particle.hpp)
# this should fix the execution path to load local files from the project (for MSVC) # this should fix the execution path to load local files from the project (for MSVC)
if(MSVC) if(MSVC)
......
...@@ -14,7 +14,7 @@ layout(set=0,binding=1) uniform uPosition{ ...@@ -14,7 +14,7 @@ layout(set=0,binding=1) uniform uPosition{
void main() void main()
{ {
vec2 mouse = vec2(Position.position.x, Position.position.y); vec2 mouse = vec2(Position.position.x, Position.position.y);
outColor = vec4(0,1,0,0);
outColor = float(distance(gl_FragCoord.xy, mouse) < 100) * vec4(0,0,1,0) + //outColor = float(distance(gl_FragCoord.xy, mouse) < 100) * vec4(0,0,1,0) +
float(distance(gl_FragCoord.xy, mouse) >= 100) * Color.color; // float(distance(gl_FragCoord.xy, mouse) >= 100) * Color.color;
} }
\ No newline at end of file
#pragma once
class Particle {
public:
Particle(glm::vec3 position, glm::vec3 velocity)
noexcept
: m_position(position),
m_velocity(velocity) {}
const glm::vec3& getPosition()const{
return m_position;
};
private:
// all properties of the Particle
glm::vec3 m_position;
float padding = 0.f;
glm::vec3 m_velocity;
float padding_2 = 0.f;
};
\ No newline at end of file
...@@ -2,20 +2,7 @@ ...@@ -2,20 +2,7 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <vector> #include <vector>
#include "Particle.hpp"
struct Particle{
Particle(glm::vec3 position, glm::vec3 velocity)
noexcept
: m_position(position),
m_velocity(velocity)
{}
// all properties of the Particle
glm::vec3 m_position;
float padding = 0.f;
glm::vec3 m_velocity;
float padding_2 = 0.f;
};
class ParticleSystem { class ParticleSystem {
...@@ -26,5 +13,4 @@ public: ...@@ -26,5 +13,4 @@ public:
private: private:
std::vector<Particle> m_particles; std::vector<Particle> m_particles;
};
}; \ No newline at end of file
...@@ -68,9 +68,9 @@ int main(int argc, const char** argv) { ...@@ -68,9 +68,9 @@ int main(int argc, const char** argv) {
3 3
); );
const std::vector<glm::vec3> vertices = {glm::vec3(-0.5, 0.5, -1), const std::vector<glm::vec3> vertices = {glm::vec3(-0.1, 0.1, 0),
glm::vec3( 0.5, 0.5, -1), glm::vec3( 0.1, 0.1, 0),
glm::vec3(0, -0.5, -1)}; glm::vec3(0, -0.1, 0)};
vertexBuffer.fill(vertices); vertexBuffer.fill(vertices);
...@@ -82,12 +82,6 @@ int main(int argc, const char** argv) { ...@@ -82,12 +82,6 @@ int main(int argc, const char** argv) {
5126, 5126,
3}; 3};
ParticleSystem particleSystem;
particleSystem.addParticles({
Particle(glm::vec3(0.f), glm::vec3(0.f)),
Particle(glm::vec3(0.f), glm::vec3(0.f)),
Particle(glm::vec3(0.f), glm::vec3(0.f))});
const vkcv::PipelineConfig particlePipelineDefinition( const vkcv::PipelineConfig particlePipelineDefinition(
particleShaderProgram, particleShaderProgram,
UINT32_MAX, UINT32_MAX,
...@@ -112,6 +106,7 @@ int main(int argc, const char** argv) { ...@@ -112,6 +106,7 @@ int main(int argc, const char** argv) {
vkcv::VertexBufferBinding(0, vertexBuffer.getVulkanHandle()) vkcv::VertexBufferBinding(0, vertexBuffer.getVulkanHandle())
}; };
vkcv::DescriptorWrites setWrites; vkcv::DescriptorWrites setWrites;
setWrites.uniformBufferWrites = {vkcv::UniformBufferDescriptorWrite(0,color.getHandle()), setWrites.uniformBufferWrites = {vkcv::UniformBufferDescriptorWrite(0,color.getHandle()),
vkcv::UniformBufferDescriptorWrite(1,position.getHandle())}; vkcv::UniformBufferDescriptorWrite(1,position.getHandle())};
...@@ -125,46 +120,39 @@ int main(int argc, const char** argv) { ...@@ -125,46 +120,39 @@ int main(int argc, const char** argv) {
const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle(); const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();
const vkcv::Mesh renderMesh({vertexBufferBindings}, particleIndexBuffer.getVulkanHandle(), 3); const vkcv::Mesh renderMesh({vertexBufferBindings}, particleIndexBuffer.getVulkanHandle(), particleIndexBuffer.getCount());
vkcv::DescriptorSetUsage descriptorUsage(0, core.getDescriptorSet(descriptorSet).vulkanHandle); vkcv::DescriptorSetUsage descriptorUsage(0, core.getDescriptorSet(descriptorSet).vulkanHandle);
vkcv::DrawcallInfo drawcalls(renderMesh, {vkcv::DescriptorSetUsage(0, core.getDescriptorSet(descriptorSet).vulkanHandle)}); //vkcv::DrawcallInfo drawcalls(renderMesh, {vkcv::DescriptorSetUsage(0, core.getDescriptorSet(descriptorSet).vulkanHandle)});
auto start = std::chrono::system_clock::now(); glm::vec3 instancePosition;
glm::vec4 colorData = glm::vec4(1.0f,1.0f,0.0f,1.0f);
glm::vec2 pos = glm::vec2(1.f); glm::vec2 pos = glm::vec2(1.f);
window.e_mouseMove.add([&]( double offsetX, double offsetY) { window.e_mouseMove.add([&]( double offsetX, double offsetY) {
pos = glm::vec2(static_cast<float>(offsetX), static_cast<float>(offsetY)); pos = glm::vec2(static_cast<float>(offsetX), static_cast<float>(offsetY));
instancePosition.x = static_cast<float>(offsetX);
instancePosition.y = static_cast<float>(offsetY);
instancePosition.z = -1.f;
}); });
ParticleSystem particleSystem;
particleSystem.addParticles({
Particle(instancePosition, glm::vec3(0.f)),
Particle(glm::vec3( 0.2f, 0.1f, 0.f), glm::vec3(0.f)),
Particle(glm::vec3(0.15f, 0.f, 0.1f), glm::vec3(0.f))});
std::vector<glm::mat4> modelMatrices;
std::vector<vkcv::DrawcallInfo> drawcalls;
for(auto particle : particleSystem.getParticles()) {
modelMatrices.push_back(glm::translate(glm::mat4(1.f), particle.getPosition()));
drawcalls.push_back(vkcv::DrawcallInfo(renderMesh, {descriptorUsage}));
}
struct Particle{ auto start = std::chrono::system_clock::now();
glm::vec2 Position;
glm::vec2 Velocity;
float Rotation = 0.0f;
float SizeBegin, SizeEnd;
float LifeTime = 1.0f;
float LifeRemaining = 0.0f;
bool Active = true;
};
std::vector<Particle> m_ParticlePool;
uint32_t poolIndex = 999;
m_ParticlePool.resize(1000); glm::vec4 colorData = glm::vec4(1.0f,1.0f,0.0f,1.0f);
//float angle = 0.0005;
glm::mat4 modelmatrix = glm::mat4(1.0);
for(auto& particle : m_ParticlePool){
if(!particle.Active){
continue;
}
}
while (window.isWindowOpen()) while (window.isWindowOpen())
{ {
...@@ -183,25 +171,16 @@ int main(int argc, const char** argv) { ...@@ -183,25 +171,16 @@ int main(int argc, const char** argv) {
start = end; start = end;
//modelmatrix = glm::rotate(modelmatrix, angle, glm::vec3(0,0,1)); //modelmatrix = glm::rotate(modelmatrix, angle, glm::vec3(0,0,1));
for(auto& particle : m_ParticlePool){
if (!particle.Active){
continue;
}
if (particle.LifeRemaining <= 0.0f){
particle.Active = false;
continue;
}
particle.LifeRemaining -= deltatime;
particle.Position += particle.Velocity * deltatime;
particle.Rotation += 0.01f * deltatime;
}
cameraManager.getCamera().updateView(deltatime); cameraManager.getCamera().updateView(deltatime);
const glm::mat4 mvp = modelmatrix * cameraManager.getCamera().getProjection() * cameraManager.getCamera().getView(); //const glm::mat4 mvp = modelmatrix * cameraManager.getCamera().getProjection() * cameraManager.getCamera().getView();
std::vector<glm::mat4> mvp;
mvp.clear();
for(const auto& m : modelMatrices){
mvp.push_back(m * cameraManager.getCamera().getProjection() * cameraManager.getCamera().getView());
}
vkcv::PushConstantData pushConstantData((void*)&mvp, sizeof(glm::mat4)); vkcv::PushConstantData pushConstantData((void*)mvp.data(), sizeof(glm::mat4));
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics); auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
core.recordDrawcallsToCmdStream( core.recordDrawcallsToCmdStream(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment