summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjjesswan <jessica_wan@brown.edu>2024-05-07 01:32:02 -0400
committerjjesswan <jessica_wan@brown.edu>2024-05-07 01:32:02 -0400
commitcb868acadcae4e3f497ecdabeca507f3e73e01c7 (patch)
treef7caa27311d6a7291be66cf98376223f7f283179
parenteb8af873097ce73a22139db4924ebd41d766f011 (diff)
add more accurate foam height saturation, poppping bubble effect
-rw-r--r--.DS_Storebin10244 -> 10244 bytes
-rw-r--r--resources/images/foam3.pngbin2042062 -> 4000051 bytes
-rw-r--r--resources/images/halftone.pngbin30448 -> 219172 bytes
-rw-r--r--resources/shaders/foam.frag12
-rwxr-xr-xsrc/glwidget.cpp2
-rw-r--r--src/ocean/ocean_alt.cpp6
-rw-r--r--src/ocean/ocean_alt.h6
7 files changed, 14 insertions, 12 deletions
diff --git a/.DS_Store b/.DS_Store
index 6e38143..1eac47f 100644
--- a/.DS_Store
+++ b/.DS_Store
Binary files differ
diff --git a/resources/images/foam3.png b/resources/images/foam3.png
index ab48f97..1113912 100644
--- a/resources/images/foam3.png
+++ b/resources/images/foam3.png
Binary files differ
diff --git a/resources/images/halftone.png b/resources/images/halftone.png
index e059862..cc11eba 100644
--- a/resources/images/halftone.png
+++ b/resources/images/halftone.png
Binary files 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<Eigen::Vector3f> 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