From d2f792c6fee2a6e78dcf2fff77f43ef036c58877 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Fri, 10 May 2024 01:49:32 -0400 Subject: saving parts --- src/ocean/ocean_alt.cpp | 18 ++++++++++-------- src/ocean/ocean_alt.h | 12 ++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) (limited to 'src/ocean') diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index dcc3e42..58e76f8 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -330,6 +330,7 @@ void ocean_alt::update_ocean() // reset normals & vertices arrays for the single tile m_vertices = std::vector(N); m_normals = std::vector(N); + m_heights.clear(); for (int i = 0; i < N; i++){ Eigen::Vector2d horiz_pos = spacing*m_waveIndexConstants[i].base_horiz_pos; Eigen::Vector2d amplitude = m_current_h[i]; @@ -357,9 +358,10 @@ void ocean_alt::update_ocean() Eigen::Vector2d disp = lambda*Eigen::Vector2d(m_displacements_x[i][0], m_displacements_z[i][0]) + Eigen::Vector2d(vertex_displacement, vertex_displacement); // set corner at 0,0 for retiling + Eigen::Vector3f v = Eigen::Vector3f(horiz_pos[0] + disp[0], height, horiz_pos[1] + disp[1]); // for final vertex position, use the real number component of amplitude vector - m_vertices[i] = {horiz_pos[0] + disp[0], height, horiz_pos[1] + disp[1]}; + m_vertices[i] = v; m_normals[i] = norm.normalized();//Eigen::Vector3f(-slope[0], 1.0, -slope[1]).normalized(); //std::cout << "normal: " << m_normals[i] << std::endl Eigen::Vector2i m_n = index_1d_to_2d(i); @@ -367,14 +369,14 @@ void ocean_alt::update_ocean() // m_foam_constants.wavelengths[i] = 2.f* M_PI * m_slopes[i].dot(m_slopes[i]) / Lx; float h_0 = m_waveIndexConstants[i].h0_prime[0]; // min*.2f; - float h_max = max*.01f; // the smaller the constant, the more foam there is - m_foam_constants.wavelengths[i] = (height - h_0 ) / (h_max - h_0); - -// if (i < 5){ -// std::cout << h_0 << ", " << h_max << std::endl; -// std::cout << m_foam_constants.wavelengths[i] << std::endl; -// } + float h_max = max*.001f; // the smaller the constant, the more foam there is + float waveheight = (height - h_0 ) / (h_max - h_0); + m_foam_constants.wavelengths[i] = waveheight; + if (waveheight >= height_threshold){ + //std::cout << "push" << std::endl; + m_heights.push_back(v); + } } diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index 9c5e4e2..a5bcd12 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -43,6 +43,8 @@ public: } std::vector m_vertices; // current displacement vector for each K + std::vector m_heights; // stores height above threshold + @@ -71,8 +73,8 @@ private: const double Lx = 512.0; const double Lz = 512.0; - const int num_rows = 256; - const int num_cols = 256; + const int num_rows = 128; + const int num_cols = 128; const int num_tiles_x = 1; const int num_tiles_z = 1; @@ -83,8 +85,8 @@ private: const double lambda = .5; // how much displacement matters const double spacing = 1.0; // spacing between grid points - const double A = 10000; // numeric constant for the Phillips spectrum - const double V = 500; // wind speed + const double A = 100; // numeric constant for the Phillips spectrum + const double V = 50; // wind speed const double gravity = 9.81; const double L = V*V/gravity; const Eigen::Vector2d omega_wind = Eigen::Vector2d(1.0, 0.0); // wind direction, used in Phillips equation @@ -102,6 +104,8 @@ private: // FOR FOAM: FoamConstants m_foam_constants; + float height_threshold = 2.f; + float max = 0; -- cgit v1.2.3-70-g09d2 From c5ff8ed6e95b7de0876dc5e97a9cb606fd84be85 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Fri, 10 May 2024 03:02:42 -0400 Subject: progress parti --- src/ocean/ocean_alt.cpp | 7 +++++-- src/ocean/ocean_alt.h | 10 ++++++++-- src/particlesystem.cpp | 36 +++++++++++++++++++++++++----------- src/particlesystem.h | 13 +++++++------ 4 files changed, 45 insertions(+), 21 deletions(-) (limited to 'src/ocean') diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 1c9306b..9ead324 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -381,9 +381,12 @@ void ocean_alt::update_ocean() // std::cout << m_foam_constants.wavelengths[i] << std::endl; // } - if (waveheight >= height_threshold){ + if (m_foam_constants.wavelengths[i] >= height_threshold){ //std::cout << "push" << std::endl; - m_heights.push_back(v); + OceanSpray s; + s.height = v; + s.slope = norm; + m_heights.push_back(s); } diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index a5bcd12..bbfce9a 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -27,6 +27,12 @@ struct FoamConstants{ std::vector texCoords; }; +struct OceanSpray{ + Eigen::Vector3f height; + Eigen::Vector3f slope; + +}; + class ocean_alt { public: @@ -43,7 +49,7 @@ public: } std::vector m_vertices; // current displacement vector for each K - std::vector m_heights; // stores height above threshold + std::vector m_heights; // stores height above threshold @@ -86,7 +92,7 @@ private: const double spacing = 1.0; // spacing between grid points const double A = 100; // numeric constant for the Phillips spectrum - const double V = 50; // wind speed + const double V = 100; // wind speed const double gravity = 9.81; const double L = V*V/gravity; const Eigen::Vector2d omega_wind = Eigen::Vector2d(1.0, 0.0); // wind direction, used in Phillips equation diff --git a/src/particlesystem.cpp b/src/particlesystem.cpp index 104b449..b645929 100644 --- a/src/particlesystem.cpp +++ b/src/particlesystem.cpp @@ -32,23 +32,29 @@ float getRandomInRange(float max, float min){ } +float getRandomY(){ + return getRandomInRange(.001,.2); +} Eigen::Vector3f particlesystem::getRandomInitialVel(){ std::pair r = sample_complex_gaussian(); - return factor*Eigen::Vector3f(r.first, getRandomInRange(1.f, 10.f), r.second); + return factor*Eigen::Vector3f(r.first, getRandomY(), r.second); } -void particlesystem::init(std::vector verts){ +void particlesystem::init(std::vector verts){ // make sure to set m_verts setVerts(verts); m_particles.reserve(4000); - for (Eigen::Vector3f v : m_verts){ + for (auto v : m_verts){ Particle p; - p.pos = Eigen::Vector3f(v); - p.vel = getRandomInitialVel(); + p.pos = Eigen::Vector3f(v.height); + p.vel = v.slope*factor; + //p.vel = getRandomInitialVel(); + p.vel = getRandomInitialVel().asDiagonal() * v.slope; + p.vel[1] = 0.1; m_particles.push_back(p); @@ -85,15 +91,19 @@ void particlesystem::update(double deltaTime){ float dt = deltaTime; // update all particles values for (Particle &p : m_particles){ - p.life -= deltaTime * getRandomInRange(.01f, .5f); + p.life -= deltaTime * getRandomInRange(.1f, .5f); // if particle is still alive, update pos if (p.life >= 0.f){ - p.vel += gravity*dt; + float r = getRandomInRange(.5, 1.f); + p.vel += gravity*dt*r; p.pos += p.vel * dt * 10.f; - +// p.vel[1] -= (p.vel.dot(p.vel) / 2 + gravity[0]) * dt; +// p.pos += p.vel * dt * 10.f; } + if (p.pos[1] < 0.f) p.life = 0.f; + } } @@ -124,10 +134,14 @@ int particlesystem::getUnusedParticleIndex(){ return -1; } -void particlesystem::respawn_particle(Particle &p, Eigen::Vector3f new_pos){ +void particlesystem::respawn_particle(Particle &p, OceanSpray new_pos){ + + p.pos = Eigen::Vector3f(new_pos.height); + p.vel = new_pos.slope*factor; + //p.vel = getRandomInitialVel(); + p.vel = getRandomInitialVel().asDiagonal() * new_pos.slope; + p.vel[1] = .01; - p.pos = new_pos; - p.vel = getRandomInitialVel(); // TODO: change to more accurate vel // reset life p.life = 1.f; diff --git a/src/particlesystem.h b/src/particlesystem.h index 9744153..e2874dd 100644 --- a/src/particlesystem.h +++ b/src/particlesystem.h @@ -2,6 +2,7 @@ #ifndef PARTICLESYSTEM_H #define PARTICLESYSTEM_H +#include "ocean/ocean_alt.h" #include #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT #define EIGEN_DONT_VECTORIZE @@ -31,9 +32,9 @@ public: void draw(Shader *skybox_shader, Camera m_camera); void draw(Shader *shader, Camera m_camera, std::vector verts, Eigen::Matrix4f model); - void init(std::vector verts); + void init(std::vector verts); - void setVerts(std::vector verts){ + void setVerts(std::vector verts){ std::cout << "VERTS SIZE:" << verts.size() << std::endl; m_verts = verts; @@ -46,18 +47,18 @@ private: int m_new_amount = 100; // new particles per frame int lastUsedIndex = 0; Eigen::Vector3f gravity = Eigen::Vector3f(0,-9.81f,0); - float factor = 10.f; // velocity multiplier + float factor = 40.f; // velocity multiplier - void respawn_particle(Particle &p, Eigen::Vector3f new_pos); + void respawn_particle(Particle &p, OceanSpray new_pos); int getUnusedParticleIndex(); Eigen::Vector3f getRandomInitialVel(); - float d = 5.f; + float d = 2.f; std::vector m_vertices = { -d, d, d,d, @@ -76,7 +77,7 @@ private: std::vector m_particles; - std::vector m_verts; + std::vector m_verts; }; -- cgit v1.2.3-70-g09d2 From 7c0cd109b098b24279fb17b9a05ab846405d169b Mon Sep 17 00:00:00 2001 From: jjesswan Date: Fri, 10 May 2024 03:41:20 -0400 Subject: particlesss --- resources/shaders/particles.frag | 2 +- resources/shaders/particles.vert | 4 +++- src/ocean/ocean_alt.cpp | 2 ++ src/ocean/ocean_alt.h | 7 ++++--- src/particlesystem.cpp | 29 +++++++++++++++++++---------- src/particlesystem.h | 2 +- 6 files changed, 30 insertions(+), 16 deletions(-) (limited to 'src/ocean') diff --git a/resources/shaders/particles.frag b/resources/shaders/particles.frag index 73a4eb4..99373e7 100644 --- a/resources/shaders/particles.frag +++ b/resources/shaders/particles.frag @@ -11,5 +11,5 @@ uniform float alpha; void main() { // color = (texture(sprite, TexCoords) * ParticleColor); - fragColor = vec4(0,1,0,alpha); + fragColor = vec4(1,1,1,alpha); } diff --git a/resources/shaders/particles.vert b/resources/shaders/particles.vert index 0905514..7b49a46 100644 --- a/resources/shaders/particles.vert +++ b/resources/shaders/particles.vert @@ -7,6 +7,8 @@ out vec4 ParticleColor; uniform mat4 view, projection, model; uniform vec3 offset; uniform vec4 color; +uniform float alpha; + void main() { @@ -14,6 +16,6 @@ void main() //TexCoords = vertex.zw; ParticleColor = color; // gl_Position = projection *view* vec4((pos * scale) + vec2(offset), 0.0, 1.0); - gl_Position = (vec4(pos.x, pos.y, 0, 1) + projection*view*vec4(vec3(offset), 1))*scale; + gl_Position = (vec4(pos.x*alpha, pos.y*alpha, 0, 1) + projection*view*vec4(vec3(offset), 1))*scale; } diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 9ead324..751fca5 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -386,6 +386,8 @@ void ocean_alt::update_ocean() OceanSpray s; s.height = v; s.slope = norm; + s.slope_vector = Eigen::Vector2f(m_slopes_x[i][0], m_slopes_z[i][0]); + //std::cout << s.slope_vector << std::endl; m_heights.push_back(s); } diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index bbfce9a..7e293f9 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -30,6 +30,7 @@ struct FoamConstants{ struct OceanSpray{ Eigen::Vector3f height; Eigen::Vector3f slope; + Eigen::Vector2f slope_vector; }; @@ -79,8 +80,8 @@ private: const double Lx = 512.0; const double Lz = 512.0; - const int num_rows = 128; - const int num_cols = 128; + const int num_rows = 256; + const int num_cols = 256; const int num_tiles_x = 1; const int num_tiles_z = 1; @@ -91,7 +92,7 @@ private: const double lambda = .5; // how much displacement matters const double spacing = 1.0; // spacing between grid points - const double A = 100; // numeric constant for the Phillips spectrum + const double A = 10000; // numeric constant for the Phillips spectrum const double V = 100; // wind speed const double gravity = 9.81; const double L = V*V/gravity; diff --git a/src/particlesystem.cpp b/src/particlesystem.cpp index b645929..566667f 100644 --- a/src/particlesystem.cpp +++ b/src/particlesystem.cpp @@ -35,6 +35,8 @@ float getRandomInRange(float max, float min){ float getRandomY(){ return getRandomInRange(.001,.2); } + + Eigen::Vector3f particlesystem::getRandomInitialVel(){ @@ -42,6 +44,16 @@ Eigen::Vector3f particlesystem::getRandomInitialVel(){ return factor*Eigen::Vector3f(r.first, getRandomY(), r.second); } +Eigen::Vector3f getInitVel(OceanSpray s){ + float x = getRandomInRange(0,1); + float y = getRandomInRange(0.1, .9); + Eigen::Vector3f v = Eigen::Vector3f(s.slope_vector[0], y, s.slope_vector[1]) + Eigen::Vector3f(x,0,0); + return v*10.f; + //p.vel[1] = 0.1; + + +} + void particlesystem::init(std::vector verts){ // make sure to set m_verts setVerts(verts); @@ -51,10 +63,10 @@ void particlesystem::init(std::vector verts){ for (auto v : m_verts){ Particle p; p.pos = Eigen::Vector3f(v.height); - p.vel = v.slope*factor; + p.life = getRandomInRange(.1,1); + // p.vel = v.slope*factor; //p.vel = getRandomInitialVel(); - p.vel = getRandomInitialVel().asDiagonal() * v.slope; - p.vel[1] = 0.1; + p.vel = getInitVel(v); m_particles.push_back(p); @@ -95,7 +107,7 @@ void particlesystem::update(double deltaTime){ // if particle is still alive, update pos if (p.life >= 0.f){ - float r = getRandomInRange(.5, 1.f); + float r = getRandomInRange(.5, 1.6f); p.vel += gravity*dt*r; p.pos += p.vel * dt * 10.f; // p.vel[1] -= (p.vel.dot(p.vel) / 2 + gravity[0]) * dt; @@ -134,13 +146,10 @@ int particlesystem::getUnusedParticleIndex(){ return -1; } -void particlesystem::respawn_particle(Particle &p, OceanSpray new_pos){ +void particlesystem::respawn_particle(Particle &p, OceanSpray s){ - p.pos = Eigen::Vector3f(new_pos.height); - p.vel = new_pos.slope*factor; - //p.vel = getRandomInitialVel(); - p.vel = getRandomInitialVel().asDiagonal() * new_pos.slope; - p.vel[1] = .01; + p.pos = Eigen::Vector3f(s.height); + p.vel = getInitVel(s); // reset life diff --git a/src/particlesystem.h b/src/particlesystem.h index e2874dd..d3b0b8f 100644 --- a/src/particlesystem.h +++ b/src/particlesystem.h @@ -35,7 +35,7 @@ public: void init(std::vector verts); void setVerts(std::vector verts){ - std::cout << "VERTS SIZE:" << verts.size() << std::endl; + //std::cout << "VERTS SIZE:" << verts.size() << std::endl; m_verts = verts; } -- cgit v1.2.3-70-g09d2