summaryrefslogtreecommitdiff
path: root/src/ocean
diff options
context:
space:
mode:
authorjjesswan <jessica_wan@brown.edu>2024-05-06 00:01:04 -0400
committerjjesswan <jessica_wan@brown.edu>2024-05-06 00:01:04 -0400
commit2ba27898535e01298ef8f0d0b9ffd4e69ce13458 (patch)
tree18dac0a37704ba9c2271f185d62ea4a6d4873b61 /src/ocean
parent72bcf6a346dfcaeaac9520d8c524711192e77c3d (diff)
uv mapping onto water good
Diffstat (limited to 'src/ocean')
-rw-r--r--src/ocean/halftone.cpp47
-rw-r--r--src/ocean/halftone.h19
-rw-r--r--src/ocean/ocean_alt.cpp35
-rw-r--r--src/ocean/ocean_alt.h29
4 files changed, 124 insertions, 6 deletions
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 <cmath>
+#include <vector>
+
+halftone::halftone()
+{
+
+}
+
+//void halftone::init(int n, int m, float density){
+// N = n;
+// M = m;
+// // std::vector<std::vector<int>> m_halftone;
+// // 1. intiialize pattern array with density
+// for (int i=0; i<N; i++){
+// for (int j=0; j<M; j++){
+// // determine whether to place a 1 or 0 here based on density
+
+// // generate random number 0-1
+// float r = ((float) rand() / (float) RAND_MAX);
+// if (r < density){
+// m_halftone[i][j] = 1;
+// } else {
+// m_halftone[i][j] = 0;
+// }
+// }
+// }
+
+//}
+
+//void halftone::apply_gaussian(){
+// for (int i=0; i<N; i++){
+// for (int j=0; j<M; j++){
+// m_halftone[i][j] = radial_gaussian(i, j);
+// }
+// }
+
+//}
+
+//float halftone::radial_gaussian(int i, int j){
+// float r = sqrt((i-.5*N)*(i-.5*N) + (j-.5*M)*(j-.5*M));
+// float result = exp(-(r*r) / (2.f*m_sigma*m_sigma));
+
+// return result;
+
+//}
+
diff --git a/src/ocean/halftone.h b/src/ocean/halftone.h
new file mode 100644
index 0000000..e913eac
--- /dev/null
+++ b/src/ocean/halftone.h
@@ -0,0 +1,19 @@
+#ifndef HALFTONE_H
+#define HALFTONE_H
+
+
+#include <vector>
+class halftone
+{
+public:
+ halftone();
+
+private:
+ int N = 0;
+ int M = 0;
+ float m_sigma = 24.f;
+ std::vector<std::vector<int>> 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<N; i++){
Eigen::Vector2i m_n = index_1d_to_2d(i);
@@ -22,6 +23,23 @@ 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();
+
+ 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;
+
+
+ // texture coord:
+ Eigen::Vector2f texCoord = Eigen::Vector2f(1, 1);
+
+
// store h0'(n,m) and w'(n,m) for every index, to be used for later
Eigen::Vector2d h0_prime = h_0_prime(k);
@@ -36,7 +54,6 @@ void ocean_alt::init_wave_index_constants(){
wave_const.h0_prime = h0_prime;
wave_const.h0_prime_conj = h0_prime_conj;
wave_const.w_prime = w_prime;
- wave_const.w_prime = w_prime;
wave_const.base_horiz_pos = get_horiz_pos(i);
wave_const.k_vector = k;
@@ -48,6 +65,13 @@ void ocean_alt::init_wave_index_constants(){
m_slopes.push_back(Eigen::Vector2d(0.0, 0.0));
m_normals.push_back(Eigen::Vector3f(0.0, 1.0, 0.0));
+ // initialize foam constant vectors
+ 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);
+
+
}
}
@@ -293,7 +317,14 @@ 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
+
+
+
}
+
+ // populate foam constants
+ m_foam_constants.positions = vertices;
+
return vertices;
}
@@ -450,4 +481,4 @@ std::vector<Eigen::Vector2d> 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<Eigen::Vector3f> positions;
+ std::vector<Eigen::Vector2f> k_vectors;
+ std::vector<float> wavelengths;
+ std::vector<Eigen::Vector2f> texCoords;
+};
+
class ocean_alt
{
public:
@@ -30,6 +37,10 @@ public:
void fft_prime(double t);
std::vector<Eigen::Vector3f> getNormals();
+ FoamConstants getFoamConstants(){
+ return m_foam_constants;
+ }
+
@@ -49,6 +60,10 @@ private:
std::pair<double, double> sample_complex_gaussian();
+ // FOAM
+ std::vector<float> 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<Eigen::Vector2d> m_slopes; // current displacement vector for each K
//std::vector<Eigen::Vector3f> m_slope_vectors; // current displacement vector for each K
- std::vector<Eigen::Vector3f> m_normals; // current displacement vector for each K
+ std::vector<Eigen::Vector3f> m_normals; // normal calculations
+
+ // FOR FOAM:
+ FoamConstants m_foam_constants;
+
+
+