diff --git a/cw_8/grk-cw8.vcxproj b/cw_8/grk-cw8.vcxproj
index ea3d83b..7dfffdb 100644
--- a/cw_8/grk-cw8.vcxproj
+++ b/cw_8/grk-cw8.vcxproj
@@ -14,6 +14,7 @@
+
@@ -25,6 +26,7 @@
+
diff --git a/cw_8/grk-cw8.vcxproj.filters b/cw_8/grk-cw8.vcxproj.filters
index a93d698..7ae4756 100644
--- a/cw_8/grk-cw8.vcxproj.filters
+++ b/cw_8/grk-cw8.vcxproj.filters
@@ -51,6 +51,9 @@
Source Files\SOIL
+
+ Source Files
+
@@ -89,6 +92,9 @@
Source Files
+
+ Source Files
+
diff --git a/cw_8/shaders/part.frag b/cw_8/shaders/part.frag
index e69de29..291ec4c 100644
--- a/cw_8/shaders/part.frag
+++ b/cw_8/shaders/part.frag
@@ -0,0 +1,12 @@
+#version 430 core
+in vec2 TexCoords;
+in vec4 ParticleColor;
+out vec4 FragColor;
+
+uniform sampler2D sprite;
+
+void main()
+{
+ FragColor = (texture(sprite, TexCoords) * ParticleColor);
+ FragColor = texture(sprite, TexCoords);
+}
\ No newline at end of file
diff --git a/cw_8/shaders/part.vert b/cw_8/shaders/part.vert
index e69de29..8671f1b 100644
--- a/cw_8/shaders/part.vert
+++ b/cw_8/shaders/part.vert
@@ -0,0 +1,22 @@
+#version 430 core
+layout (location = 0) in vec3 vertex;
+layout (location = 1) in vec2 texCoords;
+
+out vec2 TexCoords;
+out vec4 ParticleColor;
+
+uniform mat4 transformation;
+uniform vec3 position;
+uniform vec4 color;
+
+uniform vec3 cameraUp;
+uniform vec3 cameraSide;
+
+void main()
+{
+ float scale = 1.0f;
+ TexCoords = texCoords;
+ ParticleColor = color;
+ vec3 worldspacePos = cameraSide*vertex.x + cameraUp*vertex.y;
+ gl_Position = transformation * vec4((worldspacePos.xyz * scale) + position, 1.0);
+}
\ No newline at end of file
diff --git a/cw_8/src/Particle.cpp b/cw_8/src/Particle.cpp
new file mode 100644
index 0000000..ad06a9a
--- /dev/null
+++ b/cw_8/src/Particle.cpp
@@ -0,0 +1,62 @@
+#include "Particle.h"
+
+ParticleGenerator::ParticleGenerator() {
+ this->init();
+}
+
+void ParticleGenerator::Draw(glm::mat4 modelMatrix, GLuint programParticle, GLuint texture, glm::vec3 cameraDir) {
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ glUseProgram(programParticle);
+
+ for (Particle particle : this->particles) {
+
+ glUniform1i(glGetUniformLocation(programParticle, "sprite"), 0);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ glUniformMatrix4fv(glGetUniformLocation(programParticle, "transformation"), 1, GL_FALSE, (float*)&(modelMatrix));
+ glUniform3f(glGetUniformLocation(programParticle, "position"), particle.position.x, particle.position.y, particle.position.z);
+ glUniform4f(glGetUniformLocation(programParticle, "color"), particle.color.x, particle.color.y, particle.color.z, particle.color.w);
+
+ glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
+
+ glUniform3f(glGetUniformLocation(programParticle, "cameraSide"), cameraSide.x, cameraSide.y, cameraSide.z);
+ glUniform3f(glGetUniformLocation(programParticle, "cameraUp"), 0.f, 1.f, 0.f);
+
+ glBindVertexArray(this->VAO);
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+ glBindVertexArray(0);
+ }
+
+ glUseProgram(0);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glDisable(GL_BLEND);
+}
+
+void ParticleGenerator::init() {
+ unsigned int VBO;
+ float particle_quad[] = {
+ 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+
+ 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+ 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
+ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f
+ };
+ glGenVertexArrays(1, &this->VAO);
+ glGenBuffers(1, &VBO);
+ glBindVertexArray(this->VAO);
+ glBindBuffer(GL_ARRAY_BUFFER, VBO);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(particle_quad), particle_quad, GL_STATIC_DRAW);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3*sizeof(float)));
+ glBindVertexArray(0);
+
+ for (unsigned int i = 0; i < 1; i++) {
+ this->particles.push_back(Particle());
+ }
+}
diff --git a/cw_8/src/Particle.h b/cw_8/src/Particle.h
new file mode 100644
index 0000000..e2b7bd7
--- /dev/null
+++ b/cw_8/src/Particle.h
@@ -0,0 +1,19 @@
+#include
+#include "glm.hpp"
+#include "glew.h"
+
+struct Particle {
+ glm::vec3 position, velocity;
+ glm::vec4 color;
+ float life;
+};
+
+class ParticleGenerator {
+ public:
+ void Draw(glm::mat4 modelMatrix, GLuint programParticle, GLuint texture, glm::vec3 cameraDir);
+ ParticleGenerator();
+ private:
+ std::vector particles;
+ GLuint VAO;
+ void init();
+};
diff --git a/cw_8/src/Texture.cpp b/cw_8/src/Texture.cpp
index 2548b13..2e0f7c0 100644
--- a/cw_8/src/Texture.cpp
+++ b/cw_8/src/Texture.cpp
@@ -15,8 +15,8 @@ GLuint Core::LoadTexture( const char * filepath )
glBindTexture(GL_TEXTURE_2D, id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
int w, h;
unsigned char* image = SOIL_load_image(filepath, &w, &h, 0, SOIL_LOAD_RGBA);
diff --git a/cw_8/src/projekt.hpp b/cw_8/src/projekt.hpp
index 16066c1..a07e872 100644
--- a/cw_8/src/projekt.hpp
+++ b/cw_8/src/projekt.hpp
@@ -10,6 +10,7 @@
#include "Texture.h"
#include "SOIL/SOIL.h"
+#include "Particle.h"
GLuint program;
GLuint programSun;
@@ -78,6 +79,7 @@ namespace texture {
GLuint station_metallic;
GLuint cube;
+ GLuint particle_fire;
}
float aspectRatio = 1.f;
@@ -129,6 +131,8 @@ void processInput(GLFWwindow* window)
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint normal, GLuint ao, GLuint roughness, GLuint metallic) {
+ glUseProgram(program);
+
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
@@ -145,6 +149,8 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint a
Core::SetActiveTexture(metallic, "metallicMap", program, 4);
Core::DrawContext(context);
+
+ glUseProgram(0);
}
void drawObjectSun(Core::RenderContext& context, glm::mat4 modelMatrix) {
diff --git a/cw_8/textures/particles/fire.png b/cw_8/textures/particles/fire.png
new file mode 100644
index 0000000..1a3ab01
Binary files /dev/null and b/cw_8/textures/particles/fire.png differ