summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjjesswan <jessica_wan@brown.edu>2024-05-06 02:22:37 -0400
committerjjesswan <jessica_wan@brown.edu>2024-05-06 02:22:37 -0400
commit7a6ceadedc20f58b7be76654eb8357e3ca0b026d (patch)
treeef4b93cdb8f92c358c3d4715f6eebd5a2827427b
parent2ba27898535e01298ef8f0d0b9ffd4e69ce13458 (diff)
saving
-rw-r--r--resources/images/foam.pngbin0 -> 653157 bytes
-rw-r--r--resources/images/foam2.jpegbin0 -> 101489 bytes
-rw-r--r--resources/shaders/foam.frag30
-rw-r--r--resources/shaders/foam.vert6
-rwxr-xr-xsrc/glwidget.cpp12
-rwxr-xr-xsrc/glwidget.h2
-rw-r--r--src/ocean/ocean_alt.cpp2
-rw-r--r--src/ocean/ocean_alt.h7
8 files changed, 43 insertions, 16 deletions
diff --git a/resources/images/foam.png b/resources/images/foam.png
new file mode 100644
index 0000000..ff7404b
--- /dev/null
+++ b/resources/images/foam.png
Binary files differ
diff --git a/resources/images/foam2.jpeg b/resources/images/foam2.jpeg
new file mode 100644
index 0000000..e8f2e8c
--- /dev/null
+++ b/resources/images/foam2.jpeg
Binary files 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<Eigen::Vector3f> 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