I see particles
This commit is contained in:
parent
c3796e7b55
commit
f8d5b98574
@ -1,6 +1,6 @@
|
|||||||
#version 430
|
#version 430
|
||||||
|
|
||||||
uniform sampler2D texture;
|
layout (binding = 0) uniform sampler2D texture;
|
||||||
|
|
||||||
smooth in vec2 tex_coords;
|
smooth in vec2 tex_coords;
|
||||||
flat in vec4 color_part;
|
flat in vec4 color_part;
|
||||||
@ -9,6 +9,5 @@ out vec4 FragColor;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 tex_color = texture2D(texture, tex_coords);
|
FragColor = vec4(1.0, 0.0, 0.0, 1.0);// texture2D(texture, tex_coords) * color_part;
|
||||||
FragColor = vec4(tex_color.xyz, 1.0) * color_part;
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
#version 430
|
#version 430
|
||||||
|
|
||||||
uniform struct Matrices
|
|
||||||
{
|
uniform mat4 projection;
|
||||||
mat4 projection;
|
uniform mat4 view;
|
||||||
mat4 view;
|
|
||||||
} matrices;
|
|
||||||
|
|
||||||
uniform vec3 quad1, quad2;
|
uniform vec3 quad1, quad2;
|
||||||
|
|
||||||
@ -21,12 +19,12 @@ smooth out vec2 tex_coords;
|
|||||||
flat out vec4 color_part;
|
flat out vec4 color_part;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
if(type_pass[0] != 0) {
|
//if(type_pass[0] != 0) {
|
||||||
// This is not a generator particle
|
// This is not a generator particle
|
||||||
|
|
||||||
vec3 old_pos = gl_in[0].gl_Position.xyz;
|
vec3 old_pos = gl_in[0].gl_Position.xyz;
|
||||||
float size = size_pass[0];
|
float size = size_pass[0];
|
||||||
mat4 view_projection_matrix = matrices.projection * matrices.view;
|
mat4 view_projection_matrix = projection * view;
|
||||||
|
|
||||||
color_part = vec4(color_pass[0], lifetime_pass[0]);
|
color_part = vec4(color_pass[0], lifetime_pass[0]);
|
||||||
|
|
||||||
@ -52,5 +50,5 @@ void main() {
|
|||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
EndPrimitive();
|
EndPrimitive();
|
||||||
}
|
//}
|
||||||
}
|
}
|
@ -14,8 +14,7 @@ out float lifetime_pass;
|
|||||||
out float size_pass;
|
out float size_pass;
|
||||||
out int type_pass;
|
out int type_pass;
|
||||||
|
|
||||||
void main()
|
void main() {
|
||||||
{
|
|
||||||
position_pass = position;
|
position_pass = position;
|
||||||
velocity_pass = velocity;
|
velocity_pass = velocity;
|
||||||
color_pass = color;
|
color_pass = color;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "Gedeng/ParticleSystem.h"
|
#include "Gedeng/ParticleSystem.h"
|
||||||
|
#include "Gedeng/Logger.h"
|
||||||
|
|
||||||
namespace Gedeng {
|
namespace Gedeng {
|
||||||
|
|
||||||
@ -115,11 +116,12 @@ void ParticleSystem::render() {
|
|||||||
|
|
||||||
glDisable(GL_RASTERIZER_DISCARD);
|
glDisable(GL_RASTERIZER_DISCARD);
|
||||||
render_shader.use();
|
render_shader.use();
|
||||||
render_shader.setMat4("matrices.projection", projection_matrix);
|
render_shader.setMat4("projection", projection_matrix);
|
||||||
render_shader.setMat4("matrices.view", view_matrix);
|
render_shader.setMat4("view", view_matrix);
|
||||||
render_shader.setVec3("quad1", quad1);
|
render_shader.setVec3("quad1", quad1);
|
||||||
render_shader.setVec3("quad2", quad2);
|
render_shader.setVec3("quad2", quad2);
|
||||||
render_shader.setInt("texture", 0);
|
|
||||||
|
texture->bind_to(0);
|
||||||
|
|
||||||
glBindVertexArray(vao[current_read_buffer]);
|
glBindVertexArray(vao[current_read_buffer]);
|
||||||
glDisableVertexAttribArray(1); // Disable velocity, because we don't need it for rendering
|
glDisableVertexAttribArray(1); // Disable velocity, because we don't need it for rendering
|
||||||
@ -156,5 +158,8 @@ void ParticleSystem::set_interval(float interval) {
|
|||||||
void ParticleSystem::set_number_of_particles(int number) {
|
void ParticleSystem::set_number_of_particles(int number) {
|
||||||
this->target_particle_count = number;
|
this->target_particle_count = number;
|
||||||
}
|
}
|
||||||
|
void ParticleSystem::set_texture(Texture *texture) {
|
||||||
|
this->texture = texture;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Gedeng
|
} // namespace Gedeng
|
@ -17,9 +17,9 @@ void RenderBackend::initialize_window(unsigned int width, unsigned int height, S
|
|||||||
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_CULL_FACE);
|
// glEnable(GL_CULL_FACE);
|
||||||
glEnable(GL_BLEND);
|
// glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderBackend::is_window_created() {
|
bool RenderBackend::is_window_created() {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
// Other includes
|
// Other includes
|
||||||
#include "Gedeng/Camera.h"
|
#include "Gedeng/Camera.h"
|
||||||
#include "Gedeng/Shader.h"
|
#include "Gedeng/Shader.h"
|
||||||
|
#include "Gedeng/Texture.h"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ class ParticleSystem {
|
|||||||
void set_size(float size);
|
void set_size(float size);
|
||||||
void set_interval(float interval);
|
void set_interval(float interval);
|
||||||
void set_number_of_particles(int number);
|
void set_number_of_particles(int number);
|
||||||
|
void set_texture(Texture *texture);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void release();
|
void release();
|
||||||
@ -46,7 +48,8 @@ class ParticleSystem {
|
|||||||
GLuint vao[2];
|
GLuint vao[2];
|
||||||
|
|
||||||
GLuint query;
|
GLuint query;
|
||||||
GLuint texture;
|
|
||||||
|
Texture *texture;
|
||||||
|
|
||||||
int current_read_buffer;
|
int current_read_buffer;
|
||||||
int current_particle_count;
|
int current_particle_count;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
// Adapted from LearnOpenGL
|
// Adapted from LearnOpenGL
|
||||||
|
|
||||||
// Must be the first include
|
// Must be the first include
|
||||||
|
#include "Gedeng/Logger.h"
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
// Other includes
|
// Other includes
|
||||||
@ -89,51 +90,59 @@ class Shader {
|
|||||||
// utility uniform functions
|
// utility uniform functions
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setBool(const std::string &name, bool value) const {
|
void setBool(const std::string &name, bool value) const {
|
||||||
glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value);
|
glUniform1i(getUniformLocation(name), (int)value);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setInt(const std::string &name, int value) const {
|
void setInt(const std::string &name, int value) const {
|
||||||
glUniform1i(glGetUniformLocation(ID, name.c_str()), value);
|
glUniform1i(getUniformLocation(name), value);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setFloat(const std::string &name, float value) const {
|
void setFloat(const std::string &name, float value) const {
|
||||||
glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
|
glUniform1f(getUniformLocation(name), value);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setVec2(const std::string &name, const glm::vec2 &value) const {
|
void setVec2(const std::string &name, const glm::vec2 &value) const {
|
||||||
glUniform2fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
|
glUniform2fv(getUniformLocation(name), 1, &value[0]);
|
||||||
}
|
}
|
||||||
void setVec2(const std::string &name, float x, float y) const {
|
void setVec2(const std::string &name, float x, float y) const {
|
||||||
glUniform2f(glGetUniformLocation(ID, name.c_str()), x, y);
|
glUniform2f(getUniformLocation(name), x, y);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setVec3(const std::string &name, const glm::vec3 &value) const {
|
void setVec3(const std::string &name, const glm::vec3 &value) const {
|
||||||
glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
|
glUniform3fv(getUniformLocation(name), 1, &value[0]);
|
||||||
}
|
}
|
||||||
void setVec3(const std::string &name, float x, float y, float z) const {
|
void setVec3(const std::string &name, float x, float y, float z) const {
|
||||||
glUniform3f(glGetUniformLocation(ID, name.c_str()), x, y, z);
|
glUniform3f(getUniformLocation(name), x, y, z);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setVec4(const std::string &name, const glm::vec4 &value) const {
|
void setVec4(const std::string &name, const glm::vec4 &value) const {
|
||||||
glUniform4fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
|
glUniform4fv(getUniformLocation(name), 1, &value[0]);
|
||||||
}
|
}
|
||||||
void setVec4(const std::string &name, float x, float y, float z, float w) {
|
void setVec4(const std::string &name, float x, float y, float z, float w) {
|
||||||
glUniform4f(glGetUniformLocation(ID, name.c_str()), x, y, z, w);
|
glUniform4f(getUniformLocation(name), x, y, z, w);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setMat2(const std::string &name, const glm::mat2 &mat) const {
|
void setMat2(const std::string &name, const glm::mat2 &mat) const {
|
||||||
glUniformMatrix2fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
|
glUniformMatrix2fv(getUniformLocation(name), 1, GL_FALSE, &mat[0][0]);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setMat3(const std::string &name, const glm::mat3 &mat) const {
|
void setMat3(const std::string &name, const glm::mat3 &mat) const {
|
||||||
glUniformMatrix3fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
|
glUniformMatrix3fv(getUniformLocation(name), 1, GL_FALSE, &mat[0][0]);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setMat4(const std::string &name, const glm::mat4 &mat) const {
|
void setMat4(const std::string &name, const glm::mat4 &mat) const {
|
||||||
glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
|
glUniformMatrix4fv(getUniformLocation(name), 1, GL_FALSE, &mat[0][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
GLint getUniformLocation(const std::string &name) const {
|
||||||
|
GLint location = glGetUniformLocation(ID, name.c_str());
|
||||||
|
if (location == -1) {
|
||||||
|
GG_CORE_ERROR("Invalid uniform location: " + name);
|
||||||
|
}
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
// utility function for checking shader compilation/linking errors.
|
// utility function for checking shader compilation/linking errors.
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void checkCompileErrors(GLuint shader, std::string type) {
|
void checkCompileErrors(GLuint shader, std::string type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user