diff options
author | jjesswan <jessica_wan@brown.edu> | 2024-05-06 19:11:27 -0400 |
---|---|---|
committer | jjesswan <jessica_wan@brown.edu> | 2024-05-06 19:11:27 -0400 |
commit | d8bf256cf18327f48061ed875c98109200288733 (patch) | |
tree | c33234e5fe9a0b69925cfee16b8ba5f627b54595 | |
parent | 8d6fd1befd53948cfb4f44ba84bfdb54ac97cf81 (diff) |
trial with vbo
-rw-r--r-- | CMakeLists.txt.user | 20 | ||||
-rw-r--r-- | resources/shaders/foam.frag | 6 | ||||
-rw-r--r-- | resources/shaders/foam.vert | 8 | ||||
-rw-r--r-- | src/graphics/shape.cpp | 52 | ||||
-rw-r--r-- | src/graphics/shape.h | 10 | ||||
-rw-r--r-- | src/ocean/ocean_alt.cpp | 18 | ||||
-rw-r--r-- | src/ocean/ocean_alt.h | 7 |
7 files changed, 88 insertions, 33 deletions
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 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> -<!-- Written by QtCreator 8.0.1, 2024-04-30T18:44:58. --> +<!-- Written by QtCreator 8.0.1, 2024-05-06T17:52:32. --> <qtcreator> <data> <variable>EnvironmentId</variable> - <value type="QByteArray">{96b0a71f-92bf-4ce4-971d-9106997a27d2}</value> + <value type="QByteArray">{543a715d-8664-4ae3-b37a-5c03b38d6a62}</value> </data> <data> <variable>ProjectExplorer.Project.ActiveTarget</variable> @@ -80,9 +80,6 @@ <valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/> <value type="bool" key="ClangTools.UseGlobalSettings">true</value> </valuemap> - <valuemap type="QVariantMap" key="CppEditor.QuickFix"> - <value type="bool" key="UseGlobalSettings">true</value> - </valuemap> </valuemap> </data> <data> @@ -107,7 +104,7 @@ -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} %{CMAKE_OSX_ARCHITECTURES:DefaultFlag}</value> <value type="int" key="EnableQmlDebugging">0</value> - <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Debug</value> + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Debug</value> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets"> @@ -155,7 +152,7 @@ -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} %{CMAKE_OSX_ARCHITECTURES:DefaultFlag}</value> - <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Release</value> + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Release</value> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets"> @@ -203,7 +200,7 @@ -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} %{CMAKE_OSX_ARCHITECTURES:DefaultFlag}</value> - <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-RelWithDebInfo</value> + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-RelWithDebInfo</value> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets"> @@ -250,7 +247,7 @@ -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} %{CMAKE_OSX_ARCHITECTURES:DefaultFlag}</value> <value type="int" key="EnableQmlDebugging">0</value> - <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Profile</value> + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Profile</value> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets"> @@ -296,7 +293,7 @@ -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} %{CMAKE_OSX_ARCHITECTURES:DefaultFlag}</value> - <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-MinSizeRel</value> + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-MinSizeRel</value> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets"> @@ -360,8 +357,7 @@ <value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value> <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value> <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> - <value type="QString" key="RunConfiguration.WorkingDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/</value> - <value type="QString" key="RunConfiguration.WorkingDirectory.default">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Release</value> + <value type="QString" key="RunConfiguration.WorkingDirectory.default">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Release</value> </valuemap> <value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value> </valuemap> 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<Vector3f> &vertices, const vector<float> const vector<Vector2f> &waveDirs, const vector<Vector2f> &textures){ - vector<Vector3f> verts; - vector<Vector3f> norms; +// vector<Vector3f> verts; +// vector<Vector3f> norms; - vector<Vector2f> tex; - vector<Vector3f> colors; - updateMesh(m_faces, vertices, verts, norms, colors); +// vector<Vector2f> tex; +// vector<Vector3f> colors; + m_vertices.clear(); + copy(vertices.begin(), vertices.end(), back_inserter(m_vertices)); + + std::vector<Eigen::Vector3f> verts; + std::vector<Eigen::Vector2f> ks; + std::vector<float> 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<const void *>(verts.data())); - glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * verts.size() * 3, sizeof(float) * wavelengths.size() * 1, static_cast<const void *>(wavelengths.data())); - glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1)), sizeof(float) * waveDirs.size() * 2, static_cast<const void *>(waveDirs.data())); - glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1) + (waveDirs.size() * 2)), sizeof(float) * tex.size() * 2, static_cast<const void *>(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<const void *>(norms.data())); + glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * verts.size() * 3, sizeof(float) * waves.size() * 1, static_cast<const void *>(waves.data())); + //glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (waves.size() * 1)), sizeof(float) * ks.size() * 2, static_cast<const void *>(ks.data())); + //glBufferSubData(GL_ARRAY_BUFFER, sizeof(float) * ((verts.size() * 3) + (wavelengths.size() * 1) + (waveDirs.size() * 2)), sizeof(float) * tex.size() * 2, static_cast<const void *>(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<const void *>(norms.data())); glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -354,6 +361,31 @@ void Shape::updateMesh(const std::vector<Eigen::Vector3i> &faces, } } +void Shape::updateMeshFoam(const std::vector<Eigen::Vector3i> &faces, + const std::vector<Eigen::Vector3f> &vertices, + const std::vector<Eigen::Vector2f> &k_vectors, + const std::vector<float> &wavelengths, + + std::vector<Eigen::Vector3f> &verts, + std::vector<Eigen::Vector2f> &ks, + std::vector<float> &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<Eigen::Vector3i> &faces, const std::vector<Eigen::Vector3f> &vertices, const std::vector<Eigen::Vector2f> &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<Eigen::Vector2f>& tex, std::vector<Eigen::Vector3f>& colors); + void updateMeshFoam(const std::vector<Eigen::Vector3i> &faces, + const std::vector<Eigen::Vector3f> &vertices, + const std::vector<Eigen::Vector2f> &k_vectors, + const std::vector<float> &wavelengths, + + std::vector<Eigen::Vector3f> &verts, + std::vector<Eigen::Vector2f> &ks, + std::vector<float> &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<Eigen::Vector3f> ocean_alt::get_vertices() { std::vector<Eigen::Vector3f> vertices = std::vector<Eigen::Vector3f>(); + 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<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; + 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; |