From 2ba27898535e01298ef8f0d0b9ffd4e69ce13458 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 6 May 2024 00:01:04 -0400 Subject: uv mapping onto water good --- src/ocean/halftone.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/ocean/halftone.h | 19 +++++++++++++++++++ src/ocean/ocean_alt.cpp | 35 +++++++++++++++++++++++++++++++++-- src/ocean/ocean_alt.h | 29 +++++++++++++++++++++++++---- 4 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 src/ocean/halftone.cpp create mode 100644 src/ocean/halftone.h (limited to 'src/ocean') diff --git a/src/ocean/halftone.cpp b/src/ocean/halftone.cpp new file mode 100644 index 0000000..6aa59cb --- /dev/null +++ b/src/ocean/halftone.cpp @@ -0,0 +1,47 @@ +#include "halftone.h" +#include +#include + +halftone::halftone() +{ + +} + +//void halftone::init(int n, int m, float density){ +// N = n; +// M = m; +// // std::vector> m_halftone; +// // 1. intiialize pattern array with density +// for (int i=0; i +class halftone +{ +public: + halftone(); + +private: + int N = 0; + int M = 0; + float m_sigma = 24.f; + std::vector> m_halftone; + +}; + +#endif // HALFTONE_H diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 025e89b..9ba0042 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -12,6 +12,7 @@ ocean_alt::ocean_alt() // initializes static constants (aka they are not time dependent) void ocean_alt::init_wave_index_constants(){ + float tex_step = 1.f/num_rows; for (int i=0; i ocean_alt::get_vertices() vertices.push_back(Eigen::Vector3f(horiz_pos[0] + disp[0], height, horiz_pos[1] + disp[1])); m_normals[i] = norm.normalized();//Eigen::Vector3f(-slope[0], 1.0, -slope[1]).normalized(); //std::cout << "normal: " << m_normals[i] << std::endl + + + } + + // populate foam constants + m_foam_constants.positions = vertices; + return vertices; } @@ -450,4 +481,4 @@ std::vector ocean_alt::fast_fft } return h; -} \ No newline at end of file +} diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index 4bb1d54..dc9bb33 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -20,6 +20,13 @@ struct WaveIndexConstant{ Eigen::Vector2d k_vector = Eigen::Vector2d(0.f, 0.f); // static horiz pos with no displacement }; +struct FoamConstants{ + std::vector positions; + std::vector k_vectors; + std::vector wavelengths; + std::vector texCoords; +}; + class ocean_alt { public: @@ -30,6 +37,10 @@ public: void fft_prime(double t); std::vector getNormals(); + FoamConstants getFoamConstants(){ + return m_foam_constants; + } + @@ -49,6 +60,10 @@ private: std::pair sample_complex_gaussian(); + // FOAM + std::vector m_saturation; + + @@ -63,11 +78,11 @@ 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 = 32; + const int num_cols = 32; const int N = num_rows*num_cols; // total number of grid points - const double lambda = 0; // how much displacement matters + const double lambda = 0.3; // how much displacement matters const double spacing = 35.0; // spacing between grid points const double A = 100; // numeric constant for the Phillips spectrum @@ -81,7 +96,13 @@ private: std::vector m_slopes; // current displacement vector for each K //std::vector m_slope_vectors; // current displacement vector for each K - std::vector m_normals; // current displacement vector for each K + std::vector m_normals; // normal calculations + + // FOR FOAM: + FoamConstants m_foam_constants; + + + -- cgit v1.2.3-70-g09d2 From 7a6ceadedc20f58b7be76654eb8357e3ca0b026d Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 6 May 2024 02:22:37 -0400 Subject: saving --- resources/images/foam.png | Bin 0 -> 653157 bytes resources/images/foam2.jpeg | Bin 0 -> 101489 bytes resources/shaders/foam.frag | 30 +++++++++++++++++++++++++----- resources/shaders/foam.vert | 6 +++--- src/glwidget.cpp | 12 ++++++++---- src/glwidget.h | 2 ++ src/ocean/ocean_alt.cpp | 2 ++ src/ocean/ocean_alt.h | 7 +++---- 8 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 resources/images/foam.png create mode 100644 resources/images/foam2.jpeg (limited to 'src/ocean') diff --git a/resources/images/foam.png b/resources/images/foam.png new file mode 100644 index 0000000..ff7404b Binary files /dev/null and b/resources/images/foam.png differ diff --git a/resources/images/foam2.jpeg b/resources/images/foam2.jpeg new file mode 100644 index 0000000..e8f2e8c Binary files /dev/null and b/resources/images/foam2.jpeg differ diff --git a/resources/shaders/foam.frag b/resources/shaders/foam.frag index 86403d8..91ce3b9 100644 --- a/resources/shaders/foam.frag +++ b/resources/shaders/foam.frag @@ -1,22 +1,27 @@ #version 330 core -in vec4 saturation_const; +in vec2 constants; in vec2 dir; in vec2 tex; in vec3 pos; uniform float time; +uniform float phaseC; // phase constant + uniform sampler2D halftone_texture; +uniform sampler2D foam_texture; + uniform vec2 widthBounds; uniform vec2 lengthBounds; out vec4 fragColor; float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){ + //k = normalize(k); float result = dot(k, xzPos) * 3.14f / adjWaveLength; result = result + phaseC*time*.5f; - result = -tan(result) + 1.57f; + result = -tan(result + 1.57f); result = exp(result) / 4.f; return result; @@ -26,8 +31,23 @@ float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){ void main() { - //float saturation = getSaturation(saturation_const[0], saturation_const[1],saturation_const[2],saturation_const[3]); - vec4 color = texture(halftone_texture, tex); + float height = pos.y; + float saturation = getSaturation(dir, vec2(pos.x,pos.z), 100.f, constants[0]); + vec4 m_uv = texture(halftone_texture, tex); + float m_threshold = m_uv.r * m_uv.g * m_uv.b; + + // final rgba color at x,z pos + vec4 h = vec4(0,0,1,1); + if (saturation > m_threshold) h = vec4(vec3(m_threshold), 1); + + // add fading effect to bubble popping + vec4 g = clamp(.5*saturation - m_threshold, 0, 1) * h; + + // apply foam texture + vec4 foam = texture(foam_texture, tex); + vec4 j = vec4(0,0,0,1); + if (saturation > m_threshold) j = vec4(vec3(g*foam), 1); + - fragColor = vec4(vec3(color), 1); + fragColor = vec4(vec3(saturation), 1); } diff --git a/resources/shaders/foam.vert b/resources/shaders/foam.vert index 6192ba7..261eeea 100644 --- a/resources/shaders/foam.vert +++ b/resources/shaders/foam.vert @@ -7,7 +7,7 @@ layout(location = 3) in vec2 texCoords; // texture coords layout(location = 3) in vec3 norm; // texture coords -out vec4 saturation_const; +out vec2 constants; out vec2 dir; out vec2 tex; out vec3 pos; @@ -38,13 +38,13 @@ vec2 calculateTexCoord(vec3 pos){ float offset = .5f; - return vec2(u_coord + offset, v_coord + offset); + return 6*vec2(u_coord + offset, v_coord + offset); } void main() { dir = direction; - saturation_const = vec4(wavelength, phaseC, position.x, position.z); + constants = vec2(wavelength, phaseC); gl_Position = proj * view * model * vec4(position, 1); pos = vec3(gl_Position); diff --git a/src/glwidget.cpp b/src/glwidget.cpp index f2a6d94..2805d3c 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -85,8 +85,8 @@ void GLWidget::initializeGL() m_colorShader = new Shader(":resources/shaders/color.vert", ":resources/shaders/color.frag"); m_foamShader = new Shader(":resources/shaders/foam.vert", ":resources/shaders/foam.frag"); - m_halftone_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/sky_clouds.png").textureID; - + m_halftone_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/halftone.png").textureID; + m_foam_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/foam.png").textureID; @@ -361,6 +361,10 @@ void GLWidget::paintGL() glBindTexture(GL_TEXTURE_2D, m_halftone_tex); glUniform1i(glGetUniformLocation(m_foamShader->id(), "halftone_texture"), 5); + glActiveTexture(GL_TEXTURE6); + glBindTexture(GL_TEXTURE_2D, m_foam_tex); + glUniform1i(glGetUniformLocation(m_foamShader->id(), "foam_texture"), 6); + @@ -395,8 +399,8 @@ TextureData GLWidget::loadTextureFromFile(const char *path) glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); diff --git a/src/glwidget.h b/src/glwidget.h index dc4ee78..42cfd83 100755 --- a/src/glwidget.h +++ b/src/glwidget.h @@ -91,6 +91,8 @@ private: // FOAM GLuint m_halftone_tex; + GLuint m_foam_tex; + // Timing QElapsedTimer m_deltaTimeProvider; // For measuring elapsed time diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 9ba0042..8f46f1b 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -317,6 +317,8 @@ std::vector ocean_alt::get_vertices() vertices.push_back(Eigen::Vector3f(horiz_pos[0] + disp[0], height, horiz_pos[1] + disp[1])); m_normals[i] = norm.normalized();//Eigen::Vector3f(-slope[0], 1.0, -slope[1]).normalized(); //std::cout << "normal: " << m_normals[i] << std::endl + m_foam_constants.wavelengths[i] = 2.f *M_PI * m_slopes[i].dot(m_slopes[i]) / Lx; + //std::cout << m_foam_constants.wavelengths[i] << std::endl; diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index dc9bb33..41c99ba 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -78,11 +78,10 @@ private: const double Lx = 512.0; const double Lz = 512.0; - const int num_rows = 32; - const int num_cols = 32; - + const int num_rows = 64; + const int num_cols = 64; const int N = num_rows*num_cols; // total number of grid points - const double lambda = 0.3; // how much displacement matters + const double lambda = 0.4; // how much displacement matters const double spacing = 35.0; // spacing between grid points const double A = 100; // numeric constant for the Phillips spectrum -- cgit v1.2.3-70-g09d2 From d87077e403f5070ad5419a6c4ec7fd9ff0890788 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 6 May 2024 04:30:32 -0400 Subject: saving with good res --- resources/images/foam3.png | Bin 0 -> 2042062 bytes resources/images/halftone.png | Bin 11714 -> 30448 bytes resources/shaders/foam.frag | 12 ++++++------ resources/shaders/foam.vert | 2 +- src/glwidget.cpp | 2 +- src/ocean/ocean_alt.cpp | 20 ++++++++++---------- src/ocean/ocean_alt.h | 12 ++++++------ 7 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 resources/images/foam3.png (limited to 'src/ocean') diff --git a/resources/images/foam3.png b/resources/images/foam3.png new file mode 100644 index 0000000..ab48f97 Binary files /dev/null and b/resources/images/foam3.png differ diff --git a/resources/images/halftone.png b/resources/images/halftone.png index c70e107..e059862 100644 Binary files a/resources/images/halftone.png and b/resources/images/halftone.png differ diff --git a/resources/shaders/foam.frag b/resources/shaders/foam.frag index 91ce3b9..9e86011 100644 --- a/resources/shaders/foam.frag +++ b/resources/shaders/foam.frag @@ -22,7 +22,7 @@ float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){ float result = dot(k, xzPos) * 3.14f / adjWaveLength; result = result + phaseC*time*.5f; result = -tan(result + 1.57f); - result = exp(result) / 4.f; + result = exp(result) / 100.f; return result; @@ -38,16 +38,16 @@ void main() { // final rgba color at x,z pos vec4 h = vec4(0,0,1,1); - if (saturation > m_threshold) h = vec4(vec3(m_threshold), 1); + if (saturation > m_threshold) h = vec4(1,1,1, 1); // add fading effect to bubble popping vec4 g = clamp(.5*saturation - m_threshold, 0, 1) * h; // apply foam texture - vec4 foam = texture(foam_texture, tex); - vec4 j = vec4(0,0,0,1); - if (saturation > m_threshold) j = vec4(vec3(g*foam), 1); + vec4 foam = texture(foam_texture, tex*.3); + vec4 j = vec4(vec3(g*foam), 1); + //if (saturation > m_threshold) j = vec4(vec3(g*foam), 1); - fragColor = vec4(vec3(saturation), 1); + fragColor = vec4(j); } diff --git a/resources/shaders/foam.vert b/resources/shaders/foam.vert index 261eeea..76f2af7 100644 --- a/resources/shaders/foam.vert +++ b/resources/shaders/foam.vert @@ -38,7 +38,7 @@ vec2 calculateTexCoord(vec3 pos){ float offset = .5f; - return 6*vec2(u_coord + offset, v_coord + offset); + return 2*vec2(u_coord + offset, v_coord + offset); } diff --git a/src/glwidget.cpp b/src/glwidget.cpp index 2805d3c..5a2d87d 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -86,7 +86,7 @@ void GLWidget::initializeGL() m_foamShader = new Shader(":resources/shaders/foam.vert", ":resources/shaders/foam.frag"); m_halftone_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/halftone.png").textureID; - m_foam_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/foam.png").textureID; + m_foam_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/foam3.png").textureID; diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 8f46f1b..e2d3000 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -23,17 +23,17 @@ void ocean_alt::init_wave_index_constants(){ Eigen::Vector2d k_conj = get_k_vector(-n_prime, m_prime); - Eigen::Vector3f v = Eigen::Vector3f(0,0,1); - Eigen::Vector3f norm = Eigen::Vector3f(0,1,0); - if (abs(norm[1]) < 1.f){ - v = (Eigen::Vector3f(0,1,0) - norm[1]*norm).normalized(); - } - Eigen::Vector3f u = norm.cross(v).normalized(); +// Eigen::Vector3f v = Eigen::Vector3f(0,0,1); +// Eigen::Vector3f norm = Eigen::Vector3f(0,1,0); +// if (abs(norm[1]) < 1.f){ +// v = (Eigen::Vector3f(0,1,0) - norm[1]*norm).normalized(); +// } +// Eigen::Vector3f u = norm.cross(v).normalized(); - float u_coord = u.dot(Eigen::Vector3f(n_prime, 0, m_prime)) / 64.f; - float v_coord = v.dot(Eigen::Vector3f(n_prime, 0, m_prime)) / 64.f; +// float u_coord = u.dot(Eigen::Vector3f(n_prime, 0, m_prime)) / 64.f; +// float v_coord = v.dot(Eigen::Vector3f(n_prime, 0, m_prime)) / 64.f; - std::cout << u_coord << ", " << v_coord << std::endl; +// //std::cout << u_coord << ", " << v_coord << std::endl; // texture coord: @@ -69,7 +69,7 @@ void ocean_alt::init_wave_index_constants(){ m_foam_constants.k_vectors.push_back(Eigen::Vector2f(k[0], k[1])); m_foam_constants.positions.push_back(Eigen::Vector3f(0,0,0)); m_foam_constants.wavelengths.push_back(0); - m_foam_constants.texCoords.push_back(texCoord); + // m_foam_constants.texCoords.push_back(texCoord); } diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index 41c99ba..31f53ca 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -75,14 +75,14 @@ private: - const double Lx = 512.0; - const double Lz = 512.0; + const double Lx = 1024.0; + const double Lz = 1024.0; - const int num_rows = 64; - const int num_cols = 64; + const int num_rows = 256; + const int num_cols = 256; const int N = num_rows*num_cols; // total number of grid points - const double lambda = 0.4; // how much displacement matters - const double spacing = 35.0; // spacing between grid points + const double lambda = 0.8; // how much displacement matters + const double spacing = 75.0; // spacing between grid points const double A = 100; // numeric constant for the Phillips spectrum const double V = 50; // wind speed -- cgit v1.2.3-70-g09d2 From 8d6fd1befd53948cfb4f44ba84bfdb54ac97cf81 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 6 May 2024 17:33:46 -0400 Subject: saving --- resources/shaders/foam.frag | 12 ++++++------ src/arap.h | 2 +- src/ocean/ocean_alt.h | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/ocean') diff --git a/resources/shaders/foam.frag b/resources/shaders/foam.frag index 9e86011..30fe241 100644 --- a/resources/shaders/foam.frag +++ b/resources/shaders/foam.frag @@ -21,8 +21,8 @@ float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){ //k = normalize(k); float result = dot(k, xzPos) * 3.14f / adjWaveLength; result = result + phaseC*time*.5f; - result = -tan(result + 1.57f); - result = exp(result) / 100.f; + result = -tan(result) + 1.57f; + result = exp(result) / 20.f; return result; @@ -32,7 +32,7 @@ float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){ void main() { float height = pos.y; - float saturation = getSaturation(dir, vec2(pos.x,pos.z), 100.f, constants[0]); + float saturation = getSaturation(dir, vec2(pos.x,pos.z), 100.f, 1.f); vec4 m_uv = texture(halftone_texture, tex); float m_threshold = m_uv.r * m_uv.g * m_uv.b; @@ -45,9 +45,9 @@ void main() { // apply foam texture vec4 foam = texture(foam_texture, tex*.3); - vec4 j = vec4(vec3(g*foam), 1); - //if (saturation > m_threshold) j = vec4(vec3(g*foam), 1); + vec4 j = vec4(22, 33, 54, 100)/255; + if (saturation > m_threshold) j = vec4(vec3(g*foam), 1); - fragColor = vec4(j); + // fragColor = vec4(vec3(saturation), 1); } diff --git a/src/arap.h b/src/arap.h index df31dc0..e5529d9 100644 --- a/src/arap.h +++ b/src/arap.h @@ -96,7 +96,7 @@ public: ocean_alt m_ocean; double m_time = 0.00; - double m_timestep = 0.03; + double m_timestep = 0.3; Eigen::Vector3f minCorner, maxCorner; }; diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index 31f53ca..0673bbf 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -81,11 +81,11 @@ private: const int num_rows = 256; const int num_cols = 256; const int N = num_rows*num_cols; // total number of grid points - const double lambda = 0.8; // how much displacement matters + const double lambda = 2.5; // how much displacement matters const double spacing = 75.0; // spacing between grid points - const double A = 100; // numeric constant for the Phillips spectrum - const double V = 50; // wind speed + const double A = 200; // numeric constant for the Phillips spectrum + const double V = 200; // 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 -- cgit v1.2.3-70-g09d2 From d8bf256cf18327f48061ed875c98109200288733 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 6 May 2024 19:11:27 -0400 Subject: trial with vbo --- CMakeLists.txt.user | 20 +++++++---------- resources/shaders/foam.frag | 6 +++--- resources/shaders/foam.vert | 8 +++---- src/graphics/shape.cpp | 52 ++++++++++++++++++++++++++++++++++++--------- src/graphics/shape.h | 10 +++++++++ src/ocean/ocean_alt.cpp | 18 ++++++++++++++-- src/ocean/ocean_alt.h | 7 ++++-- 7 files changed, 88 insertions(+), 33 deletions(-) (limited to 'src/ocean') diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 9cfaad8..ae77a03 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,10 +1,10 @@ - + EnvironmentId - {96b0a71f-92bf-4ce4-971d-9106997a27d2} + {543a715d-8664-4ae3-b37a-5c03b38d6a62} ProjectExplorer.Project.ActiveTarget @@ -80,9 +80,6 @@ true - - true - @@ -107,7 +104,7 @@ -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} %{CMAKE_OSX_ARCHITECTURES:DefaultFlag} 0 - /Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Debug + /Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Debug @@ -155,7 +152,7 @@ -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} %{CMAKE_OSX_ARCHITECTURES:DefaultFlag} - /Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Release + /Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Release @@ -203,7 +200,7 @@ -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} %{CMAKE_OSX_ARCHITECTURES:DefaultFlag} - /Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-RelWithDebInfo + /Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-RelWithDebInfo @@ -250,7 +247,7 @@ -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} %{CMAKE_OSX_ARCHITECTURES:DefaultFlag} 0 - /Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Profile + /Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Profile @@ -296,7 +293,7 @@ -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} %{CMAKE_OSX_ARCHITECTURES:DefaultFlag} - /Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-MinSizeRel + /Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-MinSizeRel @@ -360,8 +357,7 @@ true false true - /Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/ - /Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Release + /Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Release 1 diff --git a/resources/shaders/foam.frag b/resources/shaders/foam.frag index 30fe241..8f5df85 100644 --- a/resources/shaders/foam.frag +++ b/resources/shaders/foam.frag @@ -21,7 +21,7 @@ float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){ //k = normalize(k); float result = dot(k, xzPos) * 3.14f / adjWaveLength; result = result + phaseC*time*.5f; - result = -tan(result) + 1.57f; + result = -tan(result + 1.57f); result = exp(result) / 20.f; return result; @@ -32,7 +32,7 @@ float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){ void main() { float height = pos.y; - float saturation = getSaturation(dir, vec2(pos.x,pos.z), 100.f, 1.f); + float saturation = constants[0];//getSaturation(dir, vec2(pos.x, pos.z), 512.f, constants[0]); vec4 m_uv = texture(halftone_texture, tex); float m_threshold = m_uv.r * m_uv.g * m_uv.b; @@ -49,5 +49,5 @@ void main() { if (saturation > m_threshold) j = vec4(vec3(g*foam), 1); - // fragColor = vec4(vec3(saturation), 1); + fragColor = vec4(vec3(saturation), 1); } diff --git a/resources/shaders/foam.vert b/resources/shaders/foam.vert index 76f2af7..a33e343 100644 --- a/resources/shaders/foam.vert +++ b/resources/shaders/foam.vert @@ -2,9 +2,9 @@ layout(location = 0) in vec3 position; // Position of the vertex layout(location = 1) in float wavelength; // wavelenth adjusted for ocean depth -layout(location = 2) in vec2 direction; // wave slope -layout(location = 3) in vec2 texCoords; // texture coords -layout(location = 3) in vec3 norm; // texture coords +//layout(location = 2) in vec2 direction; // wave slope +//layout(location = 3) in vec2 texCoords; // texture coords +//layout(location = 3) in vec3 norm; // texture coords out vec2 constants; @@ -43,7 +43,7 @@ vec2 calculateTexCoord(vec3 pos){ } void main() { - dir = direction; + dir = vec2(0,0); constants = vec2(wavelength, phaseC); gl_Position = proj * view * model * vec4(position, 1); diff --git a/src/graphics/shape.cpp b/src/graphics/shape.cpp index 7fa5c18..5e4a69d 100644 --- a/src/graphics/shape.cpp +++ b/src/graphics/shape.cpp @@ -126,24 +126,31 @@ void Shape::setFoamInputs(const vector &vertices, const vector const vector &waveDirs, const vector &textures){ - vector verts; - vector norms; +// vector verts; +// vector norms; - vector tex; - vector colors; - updateMesh(m_faces, vertices, verts, norms, colors); +// vector tex; +// vector colors; + m_vertices.clear(); + copy(vertices.begin(), vertices.end(), back_inserter(m_vertices)); + + std::vector verts; + std::vector ks; + std::vector waves; + + updateMeshFoam(m_faces, vertices, waveDirs, wavelengths, verts, ks, waves); //updateFoam(m_faces, vertices, textureCoords, verts, tex, colors); glBindBuffer(GL_ARRAY_BUFFER, m_surfaceVbo); - glBufferData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1) + (waveDirs.size() * 2) + (tex.size() * 2) + (norms.size() * 3)), nullptr, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (waves.size() * 1)), nullptr, GL_DYNAMIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * verts.size() * 3, static_cast(verts.data())); - glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * verts.size() * 3, sizeof(float) * wavelengths.size() * 1, static_cast(wavelengths.data())); - glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1)), sizeof(float) * waveDirs.size() * 2, static_cast(waveDirs.data())); - glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1) + (waveDirs.size() * 2)), sizeof(float) * tex.size() * 2, static_cast(tex.data())); - glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1) + (waveDirs.size() * 2) + (tex.size() * 2)), sizeof(float) * (norms.size() * 3), static_cast(norms.data())); + glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * verts.size() * 3, sizeof(float) * waves.size() * 1, static_cast(waves.data())); + //glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (waves.size() * 1)), sizeof(float) * ks.size() * 2, static_cast(ks.data())); + //glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1) + (waveDirs.size() * 2)), sizeof(float) * tex.size() * 2, static_cast(tex.data())); + // glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1) + (waveDirs.size() * 2) + (tex.size() * 2)), sizeof(float) * (norms.size() * 3), static_cast(norms.data())); glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -354,6 +361,31 @@ void Shape::updateMesh(const std::vector &faces, } } +void Shape::updateMeshFoam(const std::vector &faces, + const std::vector &vertices, + const std::vector &k_vectors, + const std::vector &wavelengths, + + std::vector &verts, + std::vector &ks, + std::vector &waves) +{ + verts.reserve(faces.size() * 3); + ks.reserve(faces.size() * 3); + waves.reserve(faces.size() * 3); + + + for (const Eigen::Vector3i& face : faces) { + + for (auto& v: {face[0], face[1], face[2]}) { + ks.push_back(k_vectors[v]); + verts.push_back(vertices[v]); + waves.push_back(wavelengths[v]); + + } + } +} + void Shape::updateFoam(const std::vector &faces, const std::vector &vertices, const std::vector &texCoords, diff --git a/src/graphics/shape.h b/src/graphics/shape.h index ef1c532..71c7bc4 100644 --- a/src/graphics/shape.h +++ b/src/graphics/shape.h @@ -41,6 +41,16 @@ public: std::vector& tex, std::vector& colors); + void updateMeshFoam(const std::vector &faces, + const std::vector &vertices, + const std::vector &k_vectors, + const std::vector &wavelengths, + + std::vector &verts, + std::vector &ks, + std::vector &waves); + + void setModelMatrix(const Eigen::Affine3f &model); diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index e2d3000..feed479 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -219,7 +219,7 @@ Eigen::Vector2d ocean_alt::get_k_vector(int n_prime, int m_prime){ double M_ = (double)num_cols; double k_x = (2*M_PI*n_ - M_PI*N_)/Lx; - double k_z = (2*M_PI*m_ - M_PI*M_)/Lz; + double k_z = (2*M_PI*m_ - M_PI*M_)/Lz; return Eigen::Vector2d(k_x, k_z); } @@ -280,6 +280,17 @@ Eigen::Vector2d ocean_alt::complex_exp(double exponent){ std::vector ocean_alt::get_vertices() { std::vector vertices = std::vector(); + if (iterations < 4){ + for (int i = 0; i < N; i++){ + Eigen::Vector2d amplitude = m_current_h[i]; + float height = amplitude[0]; + + if (height < min) min = height; + if (height > max) max = height; + + } + iterations ++; + } 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]; @@ -317,7 +328,10 @@ std::vector ocean_alt::get_vertices() vertices.push_back(Eigen::Vector3f(horiz_pos[0] + disp[0], height, horiz_pos[1] + disp[1])); m_normals[i] = norm.normalized();//Eigen::Vector3f(-slope[0], 1.0, -slope[1]).normalized(); //std::cout << "normal: " << m_normals[i] << std::endl - m_foam_constants.wavelengths[i] = 2.f *M_PI * m_slopes[i].dot(m_slopes[i]) / Lx; + Eigen::Vector2i m_n = index_1d_to_2d(i); + + + m_foam_constants.wavelengths[i] = 1.f;//(height - 0) / (max -0);//M_PI * m_slopes[i].dot(m_slopes[i]) / ((float) m_n[0] / Lx); //std::cout << m_foam_constants.wavelengths[i] << std::endl; diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index 0673bbf..ad6e69e 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -75,8 +75,8 @@ private: - const double Lx = 1024.0; - const double Lz = 1024.0; + const double Lx = 512.0; + const double Lz = 512.0; const int num_rows = 256; const int num_cols = 256; @@ -101,6 +101,9 @@ private: FoamConstants m_foam_constants; + float max = 0; + float min = 0; + int iterations = 0; -- cgit v1.2.3-70-g09d2 From eb8af873097ce73a22139db4924ebd41d766f011 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 6 May 2024 20:29:14 -0400 Subject: foam done --- resources/images/foam4.png | Bin 0 -> 10850158 bytes resources/shaders/foam.frag | 10 ++++----- resources/shaders/foam.vert | 8 ++++--- src/glwidget.cpp | 8 +++---- src/graphics/shape.cpp | 51 ++++++++++++++++---------------------------- src/graphics/shape.h | 12 +++++------ src/ocean/ocean_alt.cpp | 11 +++++++--- 7 files changed, 46 insertions(+), 54 deletions(-) create mode 100644 resources/images/foam4.png (limited to 'src/ocean') diff --git a/resources/images/foam4.png b/resources/images/foam4.png new file mode 100644 index 0000000..0b91836 Binary files /dev/null and b/resources/images/foam4.png differ diff --git a/resources/shaders/foam.frag b/resources/shaders/foam.frag index 8f5df85..af0cf4c 100644 --- a/resources/shaders/foam.frag +++ b/resources/shaders/foam.frag @@ -32,7 +32,7 @@ float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){ void main() { float height = pos.y; - float saturation = constants[0];//getSaturation(dir, vec2(pos.x, pos.z), 512.f, constants[0]); + float saturation = constants[0];//getSaturation(dir, vec2(pos.x, pos.z), 200.f, constants[0]); vec4 m_uv = texture(halftone_texture, tex); float m_threshold = m_uv.r * m_uv.g * m_uv.b; @@ -44,10 +44,10 @@ void main() { vec4 g = clamp(.5*saturation - m_threshold, 0, 1) * h; // apply foam texture - vec4 foam = texture(foam_texture, tex*.3); - vec4 j = vec4(22, 33, 54, 100)/255; - if (saturation > m_threshold) j = vec4(vec3(g*foam), 1); + vec4 foam = texture(foam_texture, tex*3); + vec4 j = vec4(0,0,0,0); + if (saturation > m_threshold) j = vec4(g*foam); - fragColor = vec4(vec3(saturation), 1); + fragColor = vec4(vec3(j), saturation); } diff --git a/resources/shaders/foam.vert b/resources/shaders/foam.vert index a33e343..f27c589 100644 --- a/resources/shaders/foam.vert +++ b/resources/shaders/foam.vert @@ -1,7 +1,9 @@ #version 330 core layout(location = 0) in vec3 position; // Position of the vertex -layout(location = 1) in float wavelength; // wavelenth adjusted for ocean depth +layout(location = 1) in vec3 wavelength; // wavelenth adjusted for ocean depth +layout(location = 2) in vec3 wavedirs; // wavelenth adjusted for ocean depth + //layout(location = 2) in vec2 direction; // wave slope //layout(location = 3) in vec2 texCoords; // texture coords //layout(location = 3) in vec3 norm; // texture coords @@ -43,8 +45,8 @@ vec2 calculateTexCoord(vec3 pos){ } void main() { - dir = vec2(0,0); - constants = vec2(wavelength, phaseC); + dir = vec2(wavedirs[0],wavedirs[1]); + constants = vec2(wavelength[0], phaseC); gl_Position = proj * view * model * vec4(position, 1); pos = vec3(gl_Position); diff --git a/src/glwidget.cpp b/src/glwidget.cpp index 5a2d87d..230eb3c 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -86,7 +86,7 @@ void GLWidget::initializeGL() m_foamShader = new Shader(":resources/shaders/foam.vert", ":resources/shaders/foam.frag"); m_halftone_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/halftone.png").textureID; - m_foam_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/foam3.png").textureID; + m_foam_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/foam4.png").textureID; @@ -316,9 +316,9 @@ void GLWidget::paintGL() glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFBO); // return; // paintTexture(m_ground_texture, false); -// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -// glEnable( GL_BLEND ); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable( GL_BLEND ); m_defaultShader->bind(); m_defaultShader->setUniform("proj", m_camera.getProjection()); diff --git a/src/graphics/shape.cpp b/src/graphics/shape.cpp index 5e4a69d..e0afb83 100644 --- a/src/graphics/shape.cpp +++ b/src/graphics/shape.cpp @@ -125,33 +125,20 @@ void Shape::setVertices_and_Normals(const vector &vertices, const vect void Shape::setFoamInputs(const vector &vertices, const vector &wavelengths, const vector &waveDirs, const vector &textures){ - -// vector verts; -// vector norms; - -// vector tex; -// vector colors; m_vertices.clear(); copy(vertices.begin(), vertices.end(), back_inserter(m_vertices)); - std::vector verts; - std::vector ks; - std::vector waves; - - updateMeshFoam(m_faces, vertices, waveDirs, wavelengths, verts, ks, waves); - - //updateFoam(m_faces, vertices, textureCoords, verts, tex, colors); - + vector verts; + vector normals; + vector colors; + updateMeshFoam(m_faces, vertices, wavelengths, waveDirs, verts, normals, colors); glBindBuffer(GL_ARRAY_BUFFER, m_surfaceVbo); - glBufferData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (waves.size() * 1)), nullptr, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (normals.size() * 3) + (colors.size() * 3)), nullptr, GL_DYNAMIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * verts.size() * 3, static_cast(verts.data())); - glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * verts.size() * 3, sizeof(float) * waves.size() * 1, static_cast(waves.data())); - //glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (waves.size() * 1)), sizeof(float) * ks.size() * 2, static_cast(ks.data())); - //glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1) + (waveDirs.size() * 2)), sizeof(float) * tex.size() * 2, static_cast(tex.data())); - // glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1) + (waveDirs.size() * 2) + (tex.size() * 2)), sizeof(float) * (norms.size() * 3), static_cast(norms.data())); - + glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * verts.size() * 3, sizeof(float) * normals.size() * 3, static_cast(normals.data())); + glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (normals.size() * 3)), sizeof(float) * colors.size() * 3, static_cast(colors.data())); glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -349,7 +336,7 @@ void Shape::updateMesh(const std::vector &faces, Vector3f n = getNormal(face); for (auto& v: {face[0], face[1], face[2]}) { - normals.push_back(n); + normals.push_back(Eigen::Vector3f(1,1,1)); verts.push_back(vertices[v]); if (m_anchors.find(v) == m_anchors.end()) { @@ -362,26 +349,24 @@ void Shape::updateMesh(const std::vector &faces, } void Shape::updateMeshFoam(const std::vector &faces, - const std::vector &vertices, - const std::vector &k_vectors, - const std::vector &wavelengths, - - std::vector &verts, - std::vector &ks, - std::vector &waves) + const std::vector &vertices, + const std::vector &wavelengths, + const vector &waveDirs, + std::vector& verts, + std::vector& normals, + std::vector& colors) { verts.reserve(faces.size() * 3); - ks.reserve(faces.size() * 3); - waves.reserve(faces.size() * 3); + normals.reserve(faces.size() * 3); + colors.reserve(faces.size() * 3); for (const Eigen::Vector3i& face : faces) { for (auto& v: {face[0], face[1], face[2]}) { - ks.push_back(k_vectors[v]); + normals.push_back(Eigen::Vector3f(wavelengths[v],0,0)); verts.push_back(vertices[v]); - waves.push_back(wavelengths[v]); - + colors.push_back(Eigen::Vector3f(waveDirs[v][0], waveDirs[v][1], 0)); } } } diff --git a/src/graphics/shape.h b/src/graphics/shape.h index 71c7bc4..ab3c27a 100644 --- a/src/graphics/shape.h +++ b/src/graphics/shape.h @@ -42,13 +42,13 @@ public: std::vector& colors); void updateMeshFoam(const std::vector &faces, - const std::vector &vertices, - const std::vector &k_vectors, - const std::vector &wavelengths, + const std::vector &vertices, + const std::vector &wavelengths, + const std::vector &waveDirs, - std::vector &verts, - std::vector &ks, - std::vector &waves); + std::vector& verts, + std::vector& normals, + std::vector& colors); diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index feed479..5dcfd74 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -280,7 +280,7 @@ Eigen::Vector2d ocean_alt::complex_exp(double exponent){ std::vector ocean_alt::get_vertices() { std::vector vertices = std::vector(); - if (iterations < 4){ + if (iterations < 10){ for (int i = 0; i < N; i++){ Eigen::Vector2d amplitude = m_current_h[i]; float height = amplitude[0]; @@ -331,8 +331,13 @@ std::vector ocean_alt::get_vertices() Eigen::Vector2i m_n = index_1d_to_2d(i); - m_foam_constants.wavelengths[i] = 1.f;//(height - 0) / (max -0);//M_PI * m_slopes[i].dot(m_slopes[i]) / ((float) m_n[0] / Lx); - //std::cout << m_foam_constants.wavelengths[i] << std::endl; + // m_foam_constants.wavelengths[i] = 2.f* M_PI * m_slopes[i].dot(m_slopes[i]) / Lx; + m_foam_constants.wavelengths[i] = ((height -200 ) / (1000.f -200 )); + +// if (i < 5){ +// //std::cout << min << ", " << max << std::endl; +// std::cout << m_foam_constants.wavelengths[i] << std::endl; +// } -- cgit v1.2.3-70-g09d2 From cb868acadcae4e3f497ecdabeca507f3e73e01c7 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Tue, 7 May 2024 01:32:02 -0400 Subject: add more accurate foam height saturation, poppping bubble effect --- .DS_Store | Bin 10244 -> 10244 bytes resources/images/foam3.png | Bin 2042062 -> 4000051 bytes resources/images/halftone.png | Bin 30448 -> 219172 bytes resources/shaders/foam.frag | 12 ++++++------ src/glwidget.cpp | 2 +- src/ocean/ocean_alt.cpp | 6 ++++-- src/ocean/ocean_alt.h | 6 +++--- 7 files changed, 14 insertions(+), 12 deletions(-) (limited to 'src/ocean') diff --git a/.DS_Store b/.DS_Store index 6e38143..1eac47f 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/resources/images/foam3.png b/resources/images/foam3.png index ab48f97..1113912 100644 Binary files a/resources/images/foam3.png and b/resources/images/foam3.png differ diff --git a/resources/images/halftone.png b/resources/images/halftone.png index e059862..cc11eba 100644 Binary files a/resources/images/halftone.png and b/resources/images/halftone.png differ diff --git a/resources/shaders/foam.frag b/resources/shaders/foam.frag index af0cf4c..be95183 100644 --- a/resources/shaders/foam.frag +++ b/resources/shaders/foam.frag @@ -33,21 +33,21 @@ float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){ void main() { float height = pos.y; float saturation = constants[0];//getSaturation(dir, vec2(pos.x, pos.z), 200.f, constants[0]); - vec4 m_uv = texture(halftone_texture, tex); - float m_threshold = m_uv.r * m_uv.g * m_uv.b; + vec4 m_uv = texture(halftone_texture, tex*2); + float m_threshold = (m_uv.r + m_uv.g + m_uv.b) / 3; // final rgba color at x,z pos vec4 h = vec4(0,0,1,1); if (saturation > m_threshold) h = vec4(1,1,1, 1); // add fading effect to bubble popping - vec4 g = clamp(.5*saturation - m_threshold, 0, 1) * h; + vec4 g = clamp(saturation - m_threshold, 0, 1) * h; // apply foam texture - vec4 foam = texture(foam_texture, tex*3); + vec4 foam = texture(foam_texture, tex + time*.0003); vec4 j = vec4(0,0,0,0); - if (saturation > m_threshold) j = vec4(g*foam); + if (saturation > m_threshold) j = g*foam*1.8; - fragColor = vec4(vec3(j), saturation); + fragColor = j; //vec4(vec3(g), 1); } diff --git a/src/glwidget.cpp b/src/glwidget.cpp index 230eb3c..c3c525b 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -86,7 +86,7 @@ void GLWidget::initializeGL() m_foamShader = new Shader(":resources/shaders/foam.vert", ":resources/shaders/foam.frag"); m_halftone_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/halftone.png").textureID; - m_foam_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/foam4.png").textureID; + m_foam_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/foam3.png").textureID; diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 5dcfd74..20c663c 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -332,10 +332,12 @@ std::vector ocean_alt::get_vertices() // m_foam_constants.wavelengths[i] = 2.f* M_PI * m_slopes[i].dot(m_slopes[i]) / Lx; - m_foam_constants.wavelengths[i] = ((height -200 ) / (1000.f -200 )); + 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 << min << ", " << max << std::endl; +// std::cout << h_0 << ", " << h_max << std::endl; // std::cout << m_foam_constants.wavelengths[i] << std::endl; // } diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index ad6e69e..219ad60 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -75,14 +75,14 @@ private: - const double Lx = 512.0; - const double Lz = 512.0; + const double Lx = 1024.0; + const double Lz = 1024.0; const int num_rows = 256; const int num_cols = 256; const int N = num_rows*num_cols; // total number of grid points const double lambda = 2.5; // how much displacement matters - const double spacing = 75.0; // spacing between grid points + const double spacing = 25.0; // spacing between grid points const double A = 200; // numeric constant for the Phillips spectrum const double V = 200; // wind speed -- cgit v1.2.3-70-g09d2