add in-progress particle system
This commit is contained in:
parent
91dc1a49dd
commit
26d1ded09a
@ -14,6 +14,7 @@
|
||||
<ClCompile Include="src\Box.cpp" />
|
||||
<ClCompile Include="src\Camera.cpp" />
|
||||
<ClCompile Include="src\main.cpp" />
|
||||
<ClCompile Include="src\Particle.cpp" />
|
||||
<ClCompile Include="src\Render_Utils.cpp" />
|
||||
<ClCompile Include="src\Shader_Loader.cpp" />
|
||||
<ClCompile Include="src\SOIL\image_DXT.c" />
|
||||
@ -25,6 +26,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\Camera.h" />
|
||||
<ClInclude Include="src\objload.h" />
|
||||
<ClInclude Include="src\Particle.h" />
|
||||
<ClInclude Include="src\projekt.hpp" />
|
||||
<ClInclude Include="src\Render_Utils.h" />
|
||||
<ClInclude Include="src\Shader_Loader.h" />
|
||||
|
@ -51,6 +51,9 @@
|
||||
<ClCompile Include="src\SOIL\image_helper.c">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Particle.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\objload.h">
|
||||
@ -89,6 +92,9 @@
|
||||
<ClInclude Include="src\projekt.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Particle.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\pbr.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);
|
||||
}
|
@ -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);
|
||||
}
|
62
cw_8/src/Particle.cpp
Normal file
62
cw_8/src/Particle.cpp
Normal file
@ -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());
|
||||
}
|
||||
}
|
19
cw_8/src/Particle.h
Normal file
19
cw_8/src/Particle.h
Normal file
@ -0,0 +1,19 @@
|
||||
#include <vector>
|
||||
#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<Particle> particles;
|
||||
GLuint VAO;
|
||||
void init();
|
||||
};
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
BIN
cw_8/textures/particles/fire.png
Normal file
BIN
cw_8/textures/particles/fire.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
Loading…
Reference in New Issue
Block a user