Skip to content
Snippets Groups Projects
Commit 04eaac5b authored by Sebastian Gaida's avatar Sebastian Gaida
Browse files

[#69] add ParticleSystem basics

parent 8fc72e27
No related branches found
No related tags found
1 merge request!56Resolve "Partikelsystem"
Pipeline #25676 failed
......@@ -9,7 +9,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# 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)
# this should fix the execution path to load local files from the project (for MSVC)
if(MSVC)
......
#version 450 core
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 position;
layout(location = 0) in vec3 particle;
layout( push_constant ) uniform constants{
mat4 mvp;
......@@ -9,5 +9,5 @@ layout( push_constant ) uniform constants{
void main()
{
gl_Position = mvp * vec4(position, 1.0);
gl_Position = mvp * vec4(particle, 1.0);
}
\ No newline at end of file
No preview for this file type
#include "ParticleSystem.hpp"
const std::vector<Particle>& ParticleSystem::getParticles() const {
return m_particles;
}
void ParticleSystem::addParticle( const Particle particle ){
m_particles.push_back(particle);
}
void ParticleSystem::addParticles( const std::vector<Particle> particles ){
m_particles.insert(m_particles.end(), particles.begin(), particles.end());
}
\ No newline at end of file
#pragma once
#include <glm/glm.hpp>
#include <vector>
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 {
public:
const std::vector<Particle> &getParticles() const;
void addParticle( const Particle particle );
void addParticles( const std::vector<Particle> particles );
private:
std::vector<Particle> m_particles;
};
......@@ -3,6 +3,7 @@
#include <GLFW/glfw3.h>
#include <vkcv/camera/CameraManager.hpp>
#include <chrono>
#include "ParticleSystem.hpp"
int main(int argc, const char** argv) {
const char* applicationName = "Particlesystem";
......@@ -62,25 +63,27 @@ int main(int argc, const char** argv) {
vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(descriptorBindings);
vkcv::Buffer<glm::vec3> vertexbuffer = core.createBuffer<glm::vec3>(
vkcv::Buffer<Particle> vertexBuffer = core.createBuffer<Particle>(
vkcv::BufferType::VERTEX,
3
);
const std::vector<glm::vec3> vertices = {glm::vec3(-0.5, 0.5, -1),
glm::vec3( 0.5, 0.5, -1),
glm::vec3(0, -0.5, -1)};
vertexbuffer.fill(vertices);
ParticleSystem particleSystem;
particleSystem.addParticles({
Particle(glm::vec3(-0.5, 0.5, -1), glm::vec3(0.f)),
Particle(glm::vec3(0.5, 0.5, -1), glm::vec3(0.f)),
Particle(glm::vec3(0, -0.5, -1), glm::vec3(0.f))});
vertexBuffer.fill(particleSystem.getParticles());
vkcv::VertexAttribute attrib = vkcv::VertexAttribute{
vkcv::PrimitiveType::POSITION,
0,
sizeof(glm::vec3) * vertices.size(),
0,
offsetof(Particle, m_position),
sizeof(Particle::m_position) * particleSystem.getParticles().size(),
sizeof(Particle) - sizeof(Particle::m_position), // why is this the difference and not the total size? maybe calced after the last element not from the first like OpenGL
5126,
3};
sizeof(Particle::m_position) / sizeof(float)// number of elements, like vec3 = 3
};
const vkcv::PipelineConfig particlePipelineDefinition(
particleShaderProgram,
......@@ -103,7 +106,7 @@ int main(int argc, const char** argv) {
);
const std::vector<vkcv::VertexBufferBinding> vertexBufferBindings = {
vkcv::VertexBufferBinding(0, vertexbuffer.getVulkanHandle())
vkcv::VertexBufferBinding(0, vertexBuffer.getVulkanHandle())
};
vkcv::DescriptorWrites setWrites;
......
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