Make ground mesh, improve particles
This commit is contained in:
parent
82fae245a1
commit
5016ee49d1
@ -62,11 +62,12 @@ void main() {
|
|||||||
vec3 view_direction = normalize(fs_in.TangentViewPos - fs_in.TangentFragPos);
|
vec3 view_direction = normalize(fs_in.TangentViewPos - fs_in.TangentFragPos);
|
||||||
vec2 uv = fs_in.TexCoords;
|
vec2 uv = fs_in.TexCoords;
|
||||||
|
|
||||||
uv = get_parallax_offset_uv(fs_in.TexCoords, view_direction);
|
uv = get_parallax_offset_uv(uv, view_direction);
|
||||||
|
|
||||||
// Discard if the parallax offset moved us outside of the texture
|
// Discard if the parallax offset moved us outside of the texture
|
||||||
if (uv.x > 1.0 || uv.y > 1.0 || uv.x < 0.0 || uv.y < 0.0)
|
// TODO: Do this only if the mode is not REPEAT
|
||||||
discard;
|
//if (uv.x > 1.0 || uv.y > 1.0 || uv.x < 0.0 || uv.y < 0.0)
|
||||||
|
// discard;
|
||||||
|
|
||||||
// Get normal from normal map and scale it to -1..1
|
// Get normal from normal map and scale it to -1..1
|
||||||
vec3 normal = texture(normalMap, uv).rgb;
|
vec3 normal = texture(normalMap, uv).rgb;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "Gedeng/ParticleSystem.h"
|
#include "Gedeng/ParticleSystem.h"
|
||||||
#include "Gedeng/Logger.h"
|
#include "Gedeng/Logger.h"
|
||||||
|
|
||||||
|
#include <glm/gtc/random.hpp>
|
||||||
|
|
||||||
namespace Gedeng {
|
namespace Gedeng {
|
||||||
|
|
||||||
ParticleSystem::ParticleSystem() {
|
ParticleSystem::ParticleSystem() {
|
||||||
@ -69,9 +71,8 @@ void ParticleSystem::update(float delta) {
|
|||||||
update_shader.setInt("number_to_generate", target_particle_count);
|
update_shader.setInt("number_to_generate", target_particle_count);
|
||||||
elapsed_time -= next_generation_time;
|
elapsed_time -= next_generation_time;
|
||||||
|
|
||||||
glm::vec3 random_seed = glm::vec3(
|
glm::vec3 random_seed =
|
||||||
10.0, 10.0,
|
glm::vec3(glm::linearRand(-10.0f, 20.0f), glm::linearRand(-10.0f, 20.0f), glm::linearRand(-10.0f, 20.0f));
|
||||||
10.0); // FIXME: Random glm::vec3(grandf(-10.0f, 20.0f), grandf(-10.0f, 20.0f), grandf(-10.0f, 20.0f));
|
|
||||||
update_shader.setVec3("random_seed", random_seed);
|
update_shader.setVec3("random_seed", random_seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,21 +13,21 @@ namespace Gedeng {
|
|||||||
// A simple 2x2 quad mesh consisting of two triangles. Oriented upwards by default.
|
// A simple 2x2 quad mesh consisting of two triangles. Oriented upwards by default.
|
||||||
class QuadMesh : public Spatial {
|
class QuadMesh : public Spatial {
|
||||||
public:
|
public:
|
||||||
QuadMesh() {
|
QuadMesh(float scale = 1.0f) {
|
||||||
// Positions
|
// Positions
|
||||||
glm::vec3 pos1(-1.0f, 1.0f, 0.0f);
|
glm::vec3 pos1 = glm::vec3(-1.0f, 0.0f, 1.0f) * scale;
|
||||||
glm::vec3 pos2(-1.0f, -1.0f, 0.0f);
|
glm::vec3 pos2 = glm::vec3(-1.0f, 0.0f, -1.0f) * scale;
|
||||||
glm::vec3 pos3(1.0f, -1.0f, 0.0f);
|
glm::vec3 pos3 = glm::vec3(1.0f, 0.0f, -1.0f) * scale;
|
||||||
glm::vec3 pos4(1.0f, 1.0f, 0.0f);
|
glm::vec3 pos4 = glm::vec3(1.0f, 0.0f, 1.0f) * scale;
|
||||||
|
|
||||||
// Texture coordinates
|
// Texture coordinates
|
||||||
glm::vec2 uv1(0.0f, 1.0f);
|
glm::vec2 uv1 = glm::vec2(0.0f, 1.0f) * scale;
|
||||||
glm::vec2 uv2(0.0f, 0.0f);
|
glm::vec2 uv2 = glm::vec2(0.0f, 0.0f) * scale;
|
||||||
glm::vec2 uv3(1.0f, 0.0f);
|
glm::vec2 uv3 = glm::vec2(1.0f, 0.0f) * scale;
|
||||||
glm::vec2 uv4(1.0f, 1.0f);
|
glm::vec2 uv4 = glm::vec2(1.0f, 1.0f) * scale;
|
||||||
|
|
||||||
// Normal vector
|
// Normal vector
|
||||||
glm::vec3 nm(0.0f, 0.0f, 1.0f);
|
glm::vec3 nm(0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
// Calculate tangent/bitangent vectors of both triangles
|
// Calculate tangent/bitangent vectors of both triangles
|
||||||
glm::vec3 tangent1, bitangent1;
|
glm::vec3 tangent1, bitangent1;
|
||||||
@ -69,21 +69,20 @@ class QuadMesh : public Spatial {
|
|||||||
bitangent2.z = f * (-deltaUV2.x * edge1.z + deltaUV1.x * edge2.z);
|
bitangent2.z = f * (-deltaUV2.x * edge1.z + deltaUV1.x * edge2.z);
|
||||||
bitangent2 = glm::normalize(bitangent2);
|
bitangent2 = glm::normalize(bitangent2);
|
||||||
|
|
||||||
float quadVertices[] = {
|
float quadVertices[] = {// positions // normal // texcoords // tangent // bitangent
|
||||||
// positions // normal // texcoords // tangent // bitangent
|
pos1.x, pos1.y, pos1.z, nm.x, nm.y, nm.z, uv1.x,
|
||||||
pos1.x, pos1.y, pos1.z, nm.x, nm.y, nm.z, uv1.x,
|
uv1.y, tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,
|
||||||
uv1.y, tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,
|
pos2.x, pos2.y, pos2.z, nm.x, nm.y, nm.z, uv2.x,
|
||||||
pos2.x, pos2.y, pos2.z, nm.x, nm.y, nm.z, uv2.x,
|
uv2.y, tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,
|
||||||
uv2.y, tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,
|
pos3.x, pos3.y, pos3.z, nm.x, nm.y, nm.z, uv3.x,
|
||||||
pos3.x, pos3.y, pos3.z, nm.x, nm.y, nm.z, uv3.x,
|
uv3.y, tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,
|
||||||
uv3.y, tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,
|
|
||||||
|
|
||||||
pos1.x, pos1.y, pos1.z, nm.x, nm.y, nm.z, uv1.x,
|
pos1.x, pos1.y, pos1.z, nm.x, nm.y, nm.z, uv1.x,
|
||||||
uv1.y, tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z,
|
uv1.y, tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z,
|
||||||
pos3.x, pos3.y, pos3.z, nm.x, nm.y, nm.z, uv3.x,
|
pos3.x, pos3.y, pos3.z, nm.x, nm.y, nm.z, uv3.x,
|
||||||
uv3.y, tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z,
|
uv3.y, tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z,
|
||||||
pos4.x, pos4.y, pos4.z, nm.x, nm.y, nm.z, uv4.x,
|
pos4.x, pos4.y, pos4.z, nm.x, nm.y, nm.z, uv4.x,
|
||||||
uv4.y, tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z};
|
uv4.y, tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z};
|
||||||
|
|
||||||
// Configure plane VAO
|
// Configure plane VAO
|
||||||
glGenVertexArrays(1, &quadVAO);
|
glGenVertexArrays(1, &quadVAO);
|
||||||
@ -94,17 +93,13 @@ class QuadMesh : public Spatial {
|
|||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void *)0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void *)0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float),
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void *)(3 * sizeof(float)));
|
||||||
(void *)(3 * sizeof(float)));
|
|
||||||
glEnableVertexAttribArray(2);
|
glEnableVertexAttribArray(2);
|
||||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 14 * sizeof(float),
|
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void *)(6 * sizeof(float)));
|
||||||
(void *)(6 * sizeof(float)));
|
|
||||||
glEnableVertexAttribArray(3);
|
glEnableVertexAttribArray(3);
|
||||||
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float),
|
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void *)(8 * sizeof(float)));
|
||||||
(void *)(8 * sizeof(float)));
|
|
||||||
glEnableVertexAttribArray(4);
|
glEnableVertexAttribArray(4);
|
||||||
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float),
|
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(float), (void *)(11 * sizeof(float)));
|
||||||
(void *)(11 * sizeof(float)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(Shader &shader) {
|
void render(Shader &shader) {
|
||||||
@ -120,4 +115,4 @@ class QuadMesh : public Spatial {
|
|||||||
unsigned int quadVBO;
|
unsigned int quadVBO;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace Gedeng
|
@ -1,5 +1,6 @@
|
|||||||
#include "Gedeng/Logger.h"
|
#include "Gedeng/Logger.h"
|
||||||
#include "Gedeng/ParticleSystem.h"
|
#include "Gedeng/ParticleSystem.h"
|
||||||
|
#include "Gedeng/QuadMesh.h"
|
||||||
#include "Gedeng/TextLabel.h"
|
#include "Gedeng/TextLabel.h"
|
||||||
#include "Gedeng/Vector3.h"
|
#include "Gedeng/Vector3.h"
|
||||||
#define GEDENG_MAIN
|
#define GEDENG_MAIN
|
||||||
@ -15,18 +16,19 @@ class ParticleApp : public Gedeng::Application {
|
|||||||
camera(Gedeng::FPSCamera(90, 1920, 1080, 0.1, 1000.0)),
|
camera(Gedeng::FPSCamera(90, 1920, 1080, 0.1, 1000.0)),
|
||||||
albedo("Resources/Textures/PavingStones/PavingStones070_2K_Color.jpg", Gedeng::Texture::Settings()),
|
albedo("Resources/Textures/PavingStones/PavingStones070_2K_Color.jpg", Gedeng::Texture::Settings()),
|
||||||
bump("Resources/Textures/PavingStones/PavingStones070_2K_Displacement.jpg", Gedeng::Texture::Settings()),
|
bump("Resources/Textures/PavingStones/PavingStones070_2K_Displacement.jpg", Gedeng::Texture::Settings()),
|
||||||
normal("Resources/Textures/PavingStones/PavingStones070_2K_Normal.jpg", Gedeng::Texture::Settings()) {
|
normal("Resources/Textures/PavingStones/PavingStones070_2K_Normal.jpg", Gedeng::Texture::Settings()),
|
||||||
particles.set_position(glm::vec3(0.0f, 0.0f, -10.0f));
|
quad_mesh(Gedeng::QuadMesh(10.0)) {
|
||||||
particles.set_velocity(glm::vec3(-5, 0, -5), glm::vec3(5, 20, 5));
|
particles.set_position(glm::vec3(0.0f, 0.0f, -5.0f));
|
||||||
particles.set_gravity(glm::vec3(0, -5, 0));
|
particles.set_velocity(glm::vec3(-1, 0, -1), glm::vec3(1, 5, 1));
|
||||||
|
particles.set_gravity(glm::vec3(0, -1, 0));
|
||||||
particles.set_color(glm::vec3(0.0f, 0.5f, 1.0f));
|
particles.set_color(glm::vec3(0.0f, 0.5f, 1.0f));
|
||||||
particles.set_lifetime(1.5f, 3.0f);
|
particles.set_lifetime(5.0f, 10.0f);
|
||||||
particles.set_size(0.75f);
|
particles.set_size(0.1);
|
||||||
particles.set_interval(0.5f);
|
particles.set_interval(0.05f);
|
||||||
particles.set_number_of_particles(30);
|
particles.set_number_of_particles(50);
|
||||||
particles.set_texture(&albedo);
|
particles.set_texture(&albedo);
|
||||||
|
|
||||||
camera.translate(glm::vec3(0.0, 0.0, 1.0));
|
camera.translate(glm::vec3(0.0, 2.0, 1.0));
|
||||||
// camera.rotate(30, glm::vec3(1.0, 0.0, 0.0));
|
// camera.rotate(30, glm::vec3(1.0, 0.0, 0.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ class ParticleApp : public Gedeng::Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dynamic_update(double delta) override {
|
void dynamic_update(double delta) override {
|
||||||
glClearColor(0.85f, 0.9f, 0.94f, 1.0f);
|
glClearColor(0.1, 0.1f, 0.1, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
render_shader.use();
|
render_shader.use();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user