├── src ├── GeepGLFW │ ├── All.h │ ├── Tests │ │ ├── CMakeLists.txt │ │ ├── glfw_helloWorld.cpp │ │ └── glfw_helloWorld2.cpp │ ├── CMakeLists.txt │ ├── Foundation.h │ ├── UtilGL.h │ └── UtilGL.cpp ├── Util │ ├── All.h │ ├── Exception.cpp │ ├── Tests │ │ ├── test_Exceptions.cpp │ │ ├── CMakeLists.txt │ │ ├── test_Functions.cpp │ │ └── test_Cpp11.cpp │ ├── CMakeLists.txt │ ├── Timer.h │ ├── Foundation.h │ └── Exception.h ├── SimpleSimViewer │ ├── All.h │ ├── CMakeLists.txt │ ├── Foundation.h │ ├── StdShaders.h │ ├── Tests │ │ ├── CMakeLists.txt │ │ ├── test_SimplePointsSim.cpp │ │ └── test_SimpleMeshSim.cpp │ ├── PointsDrawHelper.h │ ├── ViewerGLFW.h │ ├── LinesDrawHelper.h │ ├── Sim.cpp │ ├── GLCamera.h │ ├── MeshDrawHelper.h │ ├── Sim.h │ ├── PointsDrawHelper.cpp │ └── LinesDrawHelper.cpp ├── CMakeLists.txt └── EncinoWaves │ ├── Foundation.cpp │ ├── Exception.cpp │ ├── Tests │ ├── OceanTestShaders.h │ ├── OceanTestTextureSky.h │ ├── OceanTestEnvSphere.h │ ├── OceanTestSky.h │ ├── OceanTestFoundation.h │ ├── test_Propagation.cpp │ ├── test_MipMap.cpp │ ├── CMakeLists.txt │ ├── OceanTestMesh.h │ ├── test_Fftw.cpp │ ├── OceanTestSky.cpp │ └── OceanTestTextureSky.cpp │ ├── FftwWrapper.cpp │ ├── All.h │ ├── CMakeLists.txt │ ├── Filter.h │ ├── Normals.h │ ├── Random.h │ ├── Parameters.h │ ├── Spectra.h │ ├── Exception.h │ ├── Dispersion.h │ └── Stats.h └── README.md /src/GeepGLFW/All.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_GeepGLFW_All_h_ 18 | #define _EncinoWaves_GeepGLFW_All_h_ 19 | 20 | #include "Foundation.h" 21 | #include "Program.h" 22 | #include "UtilGL.h" 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/Util/All.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_Util_All_h_ 18 | #define _EncinoWaves_Util_All_h_ 19 | 20 | #include "Foundation.h" 21 | 22 | #include "Exception.h" 23 | #include "Functions.h" 24 | #include "Timer.h" 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/All.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_SimpleSimViewer_All_h_ 18 | #define _EncinoWaves_SimpleSimViewer_All_h_ 19 | 20 | #include "Foundation.h" 21 | #include "GLCamera.h" 22 | #include "MeshDrawHelper.h" 23 | #include "PointsDrawHelper.h" 24 | #include "LinesDrawHelper.h" 25 | #include "Sim.h" 26 | #include "StdShaders.h" 27 | #include "ViewerGLFW.h" 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/Util/Exception.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #include "Exception.h" 18 | 19 | namespace EncinoWaves { 20 | namespace Util { 21 | 22 | //-***************************************************************************** 23 | void __EWAV_DEBUG_ASSERT_FAIL(const char* msg) throw() { 24 | std::cerr << msg << std::endl; 25 | abort(); 26 | } 27 | 28 | } // namespace Util 29 | } // namespace EncinoWaves 30 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##-***************************************************************************** 2 | ## Copyright 2015 Christopher Jon Horvath 3 | ## 4 | ## Licensed under the Apache License, Version 2.0 (the "License"); 5 | ## you may not use this file except in compliance with the License. 6 | ## You may obtain a copy of the License at 7 | ## 8 | ## http://www.apache.org/licenses/LICENSE-2.0 9 | ## 10 | ## Unless required by applicable law or agreed to in writing, software 11 | ## distributed under the License is distributed on an "AS IS" BASIS, 12 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ## See the License for the specific language governing permissions and 14 | ## limitations under the License. 15 | ##-***************************************************************************** 16 | 17 | # Create a container project for all the src 18 | PROJECT( EWAV_SRC ) 19 | 20 | # Include the source dirs to make the src root dir an include 21 | INCLUDE_DIRECTORIES( ${EWAV_SRC_SOURCE_DIR} ) 22 | 23 | # Recurse into all the subdirectories 24 | ADD_SUBDIRECTORY( Util ) 25 | ADD_SUBDIRECTORY( GeepGLFW ) 26 | ADD_SUBDIRECTORY( SimpleSimViewer ) 27 | ADD_SUBDIRECTORY( EncinoWaves ) 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/GeepGLFW/Tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##-***************************************************************************** 2 | ## Copyright 2015 Christopher Jon Horvath 3 | ## 4 | ## Licensed under the Apache License, Version 2.0 (the "License"); 5 | ## you may not use this file except in compliance with the License. 6 | ## You may obtain a copy of the License at 7 | ## 8 | ## http://www.apache.org/licenses/LICENSE-2.0 9 | ## 10 | ## Unless required by applicable law or agreed to in writing, software 11 | ## distributed under the License is distributed on an "AS IS" BASIS, 12 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ## See the License for the specific language governing permissions and 14 | ## limitations under the License. 15 | ##-***************************************************************************** 16 | 17 | SET( GLFW_TEST_LIBS 18 | EncinoWavesGeepGLFW 19 | EncinoWavesUtil 20 | ${EWAV_GL_LIBS} 21 | ${EWAV_BOOST_LIBS} 22 | ${EWAV_THREAD_LIBS} 23 | ${EWAV_Z_LIBS} m ) 24 | 25 | ADD_EXECUTABLE( glfw_helloWorld glfw_helloWorld.cpp ) 26 | TARGET_LINK_LIBRARIES( glfw_helloWorld ${GLFW_TEST_LIBS} ) 27 | 28 | ADD_EXECUTABLE( glfw_helloWorld2 glfw_helloWorld2.cpp ) 29 | TARGET_LINK_LIBRARIES( glfw_helloWorld2 ${GLFW_TEST_LIBS} ) 30 | -------------------------------------------------------------------------------- /src/Util/Tests/test_Exceptions.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | int main(int argc, char *argv[]) { 24 | try { 25 | EWAV_THROW("I am an exception. Was I caught?"); 26 | } catch (std::exception &exc) { 27 | std::cout << "Exception caught; " << exc.what() << std::endl; 28 | return 0; 29 | } 30 | 31 | std::cerr << "Didn't catch exception. Fail." << std::endl; 32 | return -1; 33 | } 34 | -------------------------------------------------------------------------------- /src/Util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##-***************************************************************************** 2 | ## Copyright 2015 Christopher Jon Horvath 3 | ## 4 | ## Licensed under the Apache License, Version 2.0 (the "License"); 5 | ## you may not use this file except in compliance with the License. 6 | ## You may obtain a copy of the License at 7 | ## 8 | ## http://www.apache.org/licenses/LICENSE-2.0 9 | ## 10 | ## Unless required by applicable law or agreed to in writing, software 11 | ## distributed under the License is distributed on an "AS IS" BASIS, 12 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ## See the License for the specific language governing permissions and 14 | ## limitations under the License. 15 | ##-***************************************************************************** 16 | 17 | # C++ files for this project 18 | SET( H_FILES 19 | Exception.h 20 | Foundation.h 21 | Functions.h 22 | Timer.h 23 | All.h ) 24 | 25 | SET( CXX_FILES 26 | Exception.cpp ) 27 | 28 | SET( SOURCE_FILES ${CXX_FILES} ${H_FILES} ) 29 | 30 | ADD_LIBRARY( EncinoWavesUtil ${SOURCE_FILES} ) 31 | 32 | INSTALL( TARGETS EncinoWavesUtil 33 | LIBRARY DESTINATION lib 34 | ARCHIVE DESTINATION lib/static ) 35 | 36 | INSTALL( FILES ${H_FILES} 37 | DESTINATION include/EncinoWaves/Util 38 | PERMISSIONS OWNER_READ GROUP_READ WORLD_READ ) 39 | 40 | ADD_SUBDIRECTORY( Tests ) 41 | -------------------------------------------------------------------------------- /src/GeepGLFW/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##-***************************************************************************** 2 | ## Copyright 2015 Christopher Jon Horvath 3 | ## 4 | ## Licensed under the Apache License, Version 2.0 (the "License"); 5 | ## you may not use this file except in compliance with the License. 6 | ## You may obtain a copy of the License at 7 | ## 8 | ## http://www.apache.org/licenses/LICENSE-2.0 9 | ## 10 | ## Unless required by applicable law or agreed to in writing, software 11 | ## distributed under the License is distributed on an "AS IS" BASIS, 12 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ## See the License for the specific language governing permissions and 14 | ## limitations under the License. 15 | ##-***************************************************************************** 16 | 17 | # Name our source files 18 | SET( H_FILES 19 | All.h 20 | Foundation.h 21 | Program.h 22 | UtilGL.h ) 23 | 24 | SET( CXX_FILES 25 | Program.cpp 26 | UtilGL.cpp ) 27 | 28 | SET( SOURCE_FILES ${CXX_FILES} ${H_FILES} ) 29 | 30 | # Create the library 31 | ADD_LIBRARY( EncinoWavesGeepGLFW ${SOURCE_FILES} ) 32 | 33 | # Recurse into test subdirectory 34 | ADD_SUBDIRECTORY( Tests ) 35 | 36 | # INSTALLATION 37 | INSTALL( TARGETS EncinoWavesGeepGLFW 38 | LIBRARY DESTINATION lib 39 | ARCHIVE DESTINATION lib/static ) 40 | 41 | INSTALL( FILES ${H_FILES} 42 | DESTINATION include/EncinoWaves/GeepGLFW 43 | PERMISSIONS OWNER_READ GROUP_READ WORLD_READ ) 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## EncinoWaves 2 | 3 | The basic architecture of these Waves is based on the TweakWaves application 4 | written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 5 | on the SIGGRAPH papers and courses by [Jerry Tessendorf][tessendorf], and by 6 | the paper ["A Simple Fluid Solver based on the FTT" by Jos Stam][simplesolver]. 7 | 8 | [tessendorf]: http://jerrytessendorf.blogspot.com/ 9 | [simplesolver]: http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/jgt01.pdf 10 | 11 | The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 12 | directional spreading functions are formulated based on the descriptions 13 | given in "Ocean Waves: The Stochastic Approach", 14 | by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 15 | 16 | This library is written as a working implementation of the paper: 17 | 18 | > Christopher J. Horvath. 2015. 19 | > [Empirical directional wave spectra for computer graphics.](http://dl.acm.org/authorize?N90195) 20 | > In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 21 | > Los Angeles, Aug. 8, 2015, pp. 29-39. 22 | 23 | 24 | ### License 25 | 26 | Copyright © 2015 Christopher Jon Horvath 27 | 28 | Licensed under the Apache License, Version 2.0 (the "License"); 29 | you may not use this file except in compliance with the License. 30 | You may obtain a copy of the License at 31 | 32 | http://www.apache.org/licenses/LICENSE-2.0 33 | 34 | Unless required by applicable law or agreed to in writing, software 35 | distributed under the License is distributed on an "AS IS" BASIS, 36 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 37 | See the License for the specific language governing permissions and 38 | limitations under the License. 39 | 40 | -------------------------------------------------------------------------------- /src/Util/Tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##-***************************************************************************** 2 | ## Copyright 2015 Christopher Jon Horvath 3 | ## 4 | ## Licensed under the Apache License, Version 2.0 (the "License"); 5 | ## you may not use this file except in compliance with the License. 6 | ## You may obtain a copy of the License at 7 | ## 8 | ## http://www.apache.org/licenses/LICENSE-2.0 9 | ## 10 | ## Unless required by applicable law or agreed to in writing, software 11 | ## distributed under the License is distributed on an "AS IS" BASIS, 12 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ## See the License for the specific language governing permissions and 14 | ## limitations under the License. 15 | ##-***************************************************************************** 16 | 17 | SET( THIS_LIBS 18 | EncinoWavesUtil 19 | ${EWAV_ALEMBIC_LIBS} 20 | ${EWAV_HDF5_LIBS} 21 | ${EWAV_ILMBASE_LIBS} 22 | ${EWAV_BOOST_LIBS} 23 | ${EWAV_TBB_LIBS} 24 | ${EWAV_GL_LIBS} 25 | ${EWAV_THREAD_LIBS} 26 | ${EWAV_Z_LIBS} m ) 27 | 28 | SET( CPP11_LIBS m ) 29 | 30 | #-****************************************************************************** 31 | # CPP11 Test 32 | ADD_EXECUTABLE( test_util_Cpp11 test_Cpp11.cpp ) 33 | TARGET_LINK_LIBRARIES( test_util_Cpp11 ${THIS_LIBS} ) 34 | ADD_TEST( TEST_util_Cpp11 test_util_Cpp11 ) 35 | 36 | #-****************************************************************************** 37 | # Exception Test 38 | ADD_EXECUTABLE( test_util_Exceptions test_Exceptions.cpp ) 39 | TARGET_LINK_LIBRARIES( test_util_Exceptions ${THIS_LIBS} ) 40 | ADD_TEST( TEST_util_Exceptions test_util_Exceptions ) 41 | 42 | #-****************************************************************************** 43 | # Functions Test 44 | ADD_EXECUTABLE( test_util_Functions test_Functions.cpp ) 45 | TARGET_LINK_LIBRARIES( test_util_Functions ${THIS_LIBS} ) 46 | ADD_TEST( TEST_util_Functions test_util_Functions ) 47 | 48 | -------------------------------------------------------------------------------- /src/GeepGLFW/Foundation.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_GeepGLFW_Foundation_h_ 18 | #define _EncinoWaves_GeepGLFW_Foundation_h_ 19 | 20 | #define GLFW_INCLUDE_GLU 1 21 | 22 | //-***************************************************************************** 23 | // MAC INCLUDES 24 | //-***************************************************************************** 25 | #ifndef PLATFORM_DARWIN 26 | 27 | #include 28 | 29 | #else 30 | 31 | //#include 32 | 33 | #endif // ifdef PLATFORM_DARWIN 34 | 35 | #define GLFW_INCLUDE_GLCOREARB 36 | #undef GLFW_INCLUDE_GLU 37 | #include 38 | 39 | #ifdef PLATFORM_DARWIN 40 | #include 41 | #endif 42 | 43 | #include 44 | 45 | #include 46 | #include 47 | #include 48 | 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | namespace EncinoWaves { 55 | namespace GeepGLFW { 56 | 57 | //-***************************************************************************** 58 | // NOTHING 59 | //-***************************************************************************** 60 | 61 | } // namespace GeepGLFW 62 | } // namespace EncinoWaves 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/GeepGLFW/Tests/glfw_helloWorld.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // This is the GLFW hello world code, verbatim. 19 | // Only difference is that I'm using the GeepGLFW::UtilGL init call. 20 | //-***************************************************************************** 21 | 22 | #include 23 | 24 | int main(void) { 25 | GLFWwindow* window; 26 | 27 | /* Initialize the library */ 28 | if (!glfwInit()) return -1; 29 | 30 | /* Create a windowed mode window and its OpenGL context */ 31 | window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); 32 | if (!window) { 33 | glfwTerminate(); 34 | return -1; 35 | } 36 | 37 | /* Make the window's context current */ 38 | glfwMakeContextCurrent(window); 39 | 40 | /* Init GLEW */ 41 | EncinoWaves::GeepGLFW::UtilGL::Init(true); 42 | 43 | /* Loop until the user closes the window */ 44 | while (!glfwWindowShouldClose(window)) { 45 | /* Render here */ 46 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 47 | glClear(GL_COLOR_BUFFER_BIT); 48 | 49 | /* Swap front and back buffers */ 50 | glfwSwapBuffers(window); 51 | 52 | /* Poll for and process events */ 53 | glfwPollEvents(); 54 | } 55 | 56 | glfwTerminate(); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /src/EncinoWaves/Foundation.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #include "Foundation.h" 36 | 37 | namespace EncinoWaves { 38 | 39 | //-***************************************************************************** 40 | tbb::mutex g_printMutex; 41 | 42 | } // namespace EncinoWaves 43 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##-***************************************************************************** 2 | ## Copyright 2015 Christopher Jon Horvath 3 | ## 4 | ## Licensed under the Apache License, Version 2.0 (the "License"); 5 | ## you may not use this file except in compliance with the License. 6 | ## You may obtain a copy of the License at 7 | ## 8 | ## http://www.apache.org/licenses/LICENSE-2.0 9 | ## 10 | ## Unless required by applicable law or agreed to in writing, software 11 | ## distributed under the License is distributed on an "AS IS" BASIS, 12 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ## See the License for the specific language governing permissions and 14 | ## limitations under the License. 15 | ##-***************************************************************************** 16 | 17 | SET( H_FILES 18 | All.h 19 | Foundation.h 20 | GLCamera.h 21 | MeshDrawHelper.h 22 | PointsDrawHelper.h 23 | LinesDrawHelper.h 24 | Sim.h 25 | StdShaders.h 26 | ViewerGLFW.h ) 27 | 28 | SET( CXX_FILES 29 | GLCamera.cpp 30 | MeshDrawHelper.cpp 31 | PointsDrawHelper.cpp 32 | LinesDrawHelper.cpp 33 | Sim.cpp 34 | StdShaders.cpp 35 | ViewerGLFW.cpp ) 36 | 37 | SET( SOURCE_FILES ${CXX_FILES} ${H_FILES} ) 38 | 39 | # Create the library 40 | ADD_LIBRARY( EncinoWavesSimpleSimViewer ${SOURCE_FILES} ) 41 | 42 | # Recurse into test subdirectory 43 | ADD_SUBDIRECTORY( Tests ) 44 | 45 | #-****************************************************************************** 46 | #-****************************************************************************** 47 | # INSTALLATION 48 | #-****************************************************************************** 49 | #-****************************************************************************** 50 | 51 | INSTALL( TARGETS EncinoWavesSimpleSimViewer 52 | LIBRARY DESTINATION lib 53 | ARCHIVE DESTINATION lib/static ) 54 | 55 | INSTALL( FILES ${H_FILES} 56 | DESTINATION include/EncinoWaves/SimpleSimViewer 57 | PERMISSIONS OWNER_READ GROUP_READ WORLD_READ ) 58 | 59 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/Foundation.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_SimpleSimViewer_Foundation_h_ 18 | #define _EncinoWaves_SimpleSimViewer_Foundation_h_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | namespace EncinoWaves { 49 | namespace SimpleSimViewer { 50 | 51 | //-***************************************************************************** 52 | #ifdef PLATFORM_DARWIN 53 | 54 | #define OSX_GLFW_VIEWPORT_BUG 1 55 | 56 | #else 57 | 58 | #define OSX_GLFW_VIEWPORT_BUG 0 59 | 60 | #endif 61 | 62 | using namespace EncinoWaves::Util; 63 | using namespace EncinoWaves::GeepGLFW; 64 | 65 | typedef Imath::Vec3 V3ui; 66 | 67 | } // namespace SimpleSimViewer 68 | } // namespace EncinoWaves 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/StdShaders.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_SimpleSimViewer_StdShaders_h_ 18 | #define _EncinoWaves_SimpleSimViewer_StdShaders_h_ 19 | 20 | #include "Foundation.h" 21 | #include "GLCamera.h" 22 | 23 | namespace EncinoWaves { 24 | namespace SimpleSimViewer { 25 | 26 | //-***************************************************************************** 27 | std::string StdShaderHeader(); 28 | std::string StdMatrices(); 29 | std::string StdTransformFunctions(); 30 | std::string StdSpecDiffuseGammaFunctions(); 31 | std::string SimpleVertexShader(); 32 | std::string SimplePointsGeometryShader(); 33 | std::string SimpleTrianglesGeometryShader(); 34 | std::string SimpleTrianglesWireframeGeometryShader(); 35 | std::string KeyFillFragmentShader(); 36 | std::string ConstantRedFragmentShader(); 37 | std::string ConstantWhiteFragmentShader(); 38 | void SetStdMatrices(Program& o_program, const GLCamera& i_cam, 39 | const M44d& i_objectToWorld); 40 | void SetKeyFillLights(Program& o_program, const V3f& i_toKey, 41 | const V3f& i_keyColor, const V3f& i_toFill, 42 | const V3f& i_fillColor); 43 | void SetStdMaterial(Program& o_program, const V3f& i_diffColor, 44 | const V3f& i_specColor, float i_specExponent); 45 | 46 | } // namespace SimpleSimViewer 47 | } // namespace EncinoWaves 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/Util/Tests/test_Functions.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | namespace EncinoWaves { 23 | namespace Util { 24 | 25 | //-***************************************************************************** 26 | template 27 | void testWrapT(T x, T lb, T ub, T expected, T tol) { 28 | T k = wrap(x, lb, ub); 29 | std::cout << "wrap<" << typeid(T).name() << ">( " << x << ", " << lb << ", " 30 | << ub << " ) = " << k << ", expecting: " << expected << std::endl; 31 | EWAV_ASSERT(std::abs(k - expected) <= tol, "test wrap"); 32 | } 33 | 34 | //-***************************************************************************** 35 | void testWrap() { 36 | testWrapT(15, 7, 12, 9, 0); 37 | testWrapT(6, -4, 3, -2, 0); 38 | testWrapT(-19, 9, 13, 11, 0); 39 | 40 | // Try floats. 41 | testWrapT(-741.325, 1.4151, 19.7333, 9.72113, 0.0001); 42 | 43 | float e = 32.4; 44 | int block = -844; 45 | float lb = 1.8; 46 | float ub = 66.7113; 47 | 48 | float x = lb + ((ub - lb) * float(block)) + (e - lb); 49 | testWrapT(x, lb, ub, e, 0.01); 50 | } 51 | 52 | } // namespace Util 53 | } // namespace EncinoWaves 54 | 55 | //-***************************************************************************** 56 | int main(int argc, char* argv[]) { 57 | EncinoWaves::Util::testWrap(); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /src/EncinoWaves/Exception.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #include "Exception.h" 36 | 37 | namespace EncinoWaves { 38 | 39 | //-***************************************************************************** 40 | void __EWAV_DEBUG_ASSERT_FAIL(const char* msg) throw() { 41 | std::cerr << msg << std::endl; 42 | abort(); 43 | } 44 | 45 | } // namespace EncinoWaves 46 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/OceanTestShaders.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #include "OceanTestFoundation.h" 36 | 37 | namespace OceanTest { 38 | 39 | //-***************************************************************************** 40 | std::string VertexShader(); 41 | std::string GeometryShader(); 42 | std::string FragmentShader(const std::string &i_prefixIn, bool texture_sky); 43 | 44 | std::string EnvVertexShader(); 45 | std::string EnvFragmentShader(); 46 | 47 | } // namespace OceanTest 48 | -------------------------------------------------------------------------------- /src/GeepGLFW/UtilGL.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_GeepGLFW_UtilGL_h_ 18 | #define _EncinoWaves_GeepGLFW_UtilGL_h_ 19 | 20 | #include "Foundation.h" 21 | 22 | namespace EncinoWaves { 23 | namespace GeepGLFW { 24 | 25 | //-***************************************************************************** 26 | //! Notational grouping namespace for OpenGL-related functions 27 | // 28 | //! The functions declared in the UtilGL namespace are global and not part 29 | //! of any particular class. 30 | namespace UtilGL { 31 | 32 | //-***************************************************************************** 33 | //! OpenGL does not need extension initialization on Mac OSX, but does 34 | //! require initialization via glewInit on non-mac systems. This function 35 | //! abstracts that. 36 | void Init(bool i_experimental = true); 37 | 38 | //-***************************************************************************** 39 | //! This function will throw an exception with an attached label if the OpenGL 40 | //! Error flag is set. It will get the error string from OpenGL and attach that 41 | //! to the exception text. 42 | void CheckErrors(const std::string &i_label); 43 | 44 | //-***************************************************************************** 45 | //! Checks framebuffer status. 46 | //! Copied directly out of the spec, modified to throw an exception 47 | //! for any failed checks. 48 | void CheckFramebuffer(); 49 | 50 | } // namespace UtilGL 51 | } // namespace GeepGLFW 52 | } // namespace EncinoWaves 53 | 54 | #endif // ifndef _EncinoWaves_GeepGLFW_UtilGL_h_ 55 | -------------------------------------------------------------------------------- /src/EncinoWaves/FftwWrapper.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #include "FftwWrapper.h" 36 | 37 | namespace EncinoWaves { 38 | 39 | //-***************************************************************************** 40 | // Global instantiation of these static members. 41 | 42 | std::unique_ptr< __BaseFftwInitThreadsT::Init > 43 | __BaseFftwInitThreadsT::sm_init; 44 | 45 | std::unique_ptr< __BaseFftwInitThreadsT::Init > 46 | __BaseFftwInitThreadsT::sm_init; 47 | 48 | } // namespace EncinoWaves 49 | 50 | -------------------------------------------------------------------------------- /src/EncinoWaves/All.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_All_h_ 36 | #define _EncinoWaves_All_h_ 37 | 38 | #include "Basics.h" 39 | #include "DirectionalSpreading.h" 40 | #include "Dispersion.h" 41 | #include "FftwWrapper.h" 42 | #include "Filter.h" 43 | #include "Foundation.h" 44 | #include "InitialState.h" 45 | #include "MipMap.h" 46 | #include "Normals.h" 47 | #include "Parameters.h" 48 | #include "Propagation.h" 49 | #include "Random.h" 50 | #include "Spectra.h" 51 | #include "SpectralSpatialField.h" 52 | #include "Stats.h" 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/Util/Timer.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_Util_Timer_h_ 18 | #define _EncinoWaves_Util_Timer_h_ 19 | 20 | #include "Foundation.h" 21 | 22 | namespace EncinoWaves { 23 | namespace Util { 24 | 25 | //-***************************************************************************** 26 | //! \brief Basic real-time stopwatch. Returns elapsed time in seconds. 27 | class Timer { 28 | public: 29 | //! Begins the timer and resets the elapsed time to zero 30 | void start() { 31 | struct timezone tz; 32 | gettimeofday(&m_tp0, &tz); 33 | m_stopped = -1; 34 | } 35 | 36 | //! Creates a timer which is started by default 37 | Timer() 38 | : m_stopped(-1) { 39 | start(); 40 | } 41 | 42 | //! Stops the timer and records elapsed time 43 | double stop() { 44 | struct timezone tz; 45 | struct timeval tp; 46 | gettimeofday(&tp, &tz); 47 | 48 | double seconds = tp.tv_sec - m_tp0.tv_sec; 49 | seconds += double(tp.tv_usec) * 1e-6; 50 | seconds -= double(m_tp0.tv_usec) * 1e-6; 51 | return (m_stopped = double(seconds)); 52 | } 53 | 54 | //! Returns the amount of time elapsed. 55 | double elapsed() const { 56 | if (m_stopped >= 0.0) { 57 | return m_stopped; 58 | } 59 | 60 | struct timezone tz; 61 | struct timeval tp; 62 | gettimeofday(&tp, &tz); 63 | 64 | double seconds = tp.tv_sec - m_tp0.tv_sec; 65 | seconds += double(tp.tv_usec) * 1e-6; 66 | seconds -= double(m_tp0.tv_usec) * 1e-6; 67 | return double(seconds); 68 | } 69 | 70 | private: 71 | double m_stopped; 72 | struct timeval m_tp0; 73 | }; 74 | 75 | } // namespace Util 76 | } // namespace EncinoWaves 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/OceanTestTextureSky.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_OceanTest_TextureSky_hpp_ 36 | #define _EncinoWaves_OceanTest_TextureSky_hpp_ 37 | 38 | #include "OceanTestFoundation.h" 39 | 40 | namespace OceanTest { 41 | 42 | class TextureSky { 43 | public: 44 | TextureSky(const std::string& filename); 45 | ~TextureSky(); 46 | 47 | void bind(GLuint program_id) const; 48 | 49 | private: 50 | GLuint m_tex_id; 51 | V3f m_to_sun; 52 | V3f m_sun_color; 53 | V3f m_to_moon; 54 | V3f m_moon_color; 55 | }; 56 | 57 | } // namespace OceanTest 58 | 59 | #endif // _EncinoWaves_OceanTest_TextureSky_hpp_ -------------------------------------------------------------------------------- /src/SimpleSimViewer/Tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##-***************************************************************************** 2 | ## Copyright (c) 2001-2013, Christopher Jon Horvath. All rights reserved. 3 | ## 4 | ## Redistribution and use in source and binary forms, with or without 5 | ## modification, are permitted provided that the following conditions are met: 6 | ## 7 | ## 1. Redistributions of source code must retain the above copyright notice, 8 | ## this list of conditions and the following disclaimer. 9 | ## 10 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 11 | ## this list of conditions and the following disclaimer in the documentation 12 | ## and/or other materials provided with the distribution. 13 | ## 14 | ## 3. Neither the name of Christopher Jon Horvath nor the names of his 15 | ## contributors may be used to endorse or promote products derived from this 16 | ## software without specific prior written permission. 17 | ## 18 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | ## POSSIBILITY OF SUCH DAMAGE. 29 | ##-***************************************************************************** 30 | 31 | SET( TEST_LIBS 32 | EncinoWavesSimpleSimViewer 33 | EncinoWavesGeepGLFW 34 | EncinoWavesUtil 35 | ${EWAV_ALEMBIC_LIBS} 36 | ${EWAV_HDF5_LIBS} 37 | ${EWAV_ILMBASE_LIBS} 38 | ${EWAV_BOOST_LIBS} 39 | ${EWAV_GL_LIBS} 40 | ${EWAV_THREAD_LIBS} 41 | ${EWAV_Z_LIBS} m ) 42 | 43 | #-****************************************************************************** 44 | # Simple Mesh Sim 45 | ADD_EXECUTABLE( test_SSV_SimpleMeshSim test_SimpleMeshSim.cpp ) 46 | TARGET_LINK_LIBRARIES( test_SSV_SimpleMeshSim ${TEST_LIBS} ) 47 | 48 | #-****************************************************************************** 49 | # Simple Points Sim 50 | ADD_EXECUTABLE( test_SSV_SimplePointsSim test_SimplePointsSim.cpp ) 51 | TARGET_LINK_LIBRARIES( test_SSV_SimplePointsSim ${TEST_LIBS} ) 52 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/OceanTestEnvSphere.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_OceanTestEnvSphere_h_ 36 | #define _EncinoWaves_OceanTestEnvSphere_h_ 37 | 38 | #include "OceanTestFoundation.h" 39 | #include "OceanTestTextureSky.h" 40 | 41 | namespace OceanTest { 42 | 43 | class EnvSphere { 44 | public: 45 | EnvSphere(); 46 | ~EnvSphere(); 47 | 48 | void draw(const EncinoWaves::SimpleSimViewer::GLCamera& i_camera, 49 | const TextureSky& sky); 50 | 51 | protected: 52 | void createProgram(); 53 | void setCameraUniforms( 54 | const EncinoWaves::SimpleSimViewer::GLCamera& i_camera); 55 | 56 | // The VAO and VBOs 57 | GLuint m_vertexArrayObject; 58 | GLuint m_vertexBuffers[2]; 59 | size_t m_num_indices; 60 | 61 | // The Program. 62 | std::unique_ptr m_program; 63 | }; 64 | 65 | } // namespace OceanTest 66 | 67 | #endif -------------------------------------------------------------------------------- /src/Util/Foundation.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_Util_Foundation_h_ 18 | #define _EncinoWaves_Util_Foundation_h_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | #include 42 | #include 43 | 44 | namespace EncinoWaves { 45 | namespace Util { 46 | 47 | // Bring in Alembic types! 48 | namespace AbcG = Alembic::AbcGeom; 49 | 50 | using AbcG::chrono_t; 51 | using AbcG::uint8_t; 52 | using AbcG::int8_t; 53 | using AbcG::uint16_t; 54 | using AbcG::int16_t; 55 | using AbcG::uint32_t; 56 | using AbcG::int32_t; 57 | using AbcG::uint64_t; 58 | using AbcG::int64_t; 59 | using AbcG::float16_t; 60 | using AbcG::float32_t; 61 | using AbcG::float64_t; 62 | using AbcG::bool_t; 63 | using AbcG::byte_t; 64 | using AbcG::index_t; 65 | 66 | using AbcG::V2s; 67 | using AbcG::V2i; 68 | using AbcG::V2f; 69 | using AbcG::V2d; 70 | 71 | using AbcG::V3s; 72 | using AbcG::V3i; 73 | using AbcG::V3f; 74 | using AbcG::V3d; 75 | 76 | using Imath::V4s; 77 | using Imath::V4i; 78 | using Imath::V4f; 79 | using Imath::V4d; 80 | 81 | using AbcG::Box2s; 82 | using AbcG::Box2i; 83 | using AbcG::Box2f; 84 | using AbcG::Box2d; 85 | 86 | using AbcG::Box3s; 87 | using AbcG::Box3i; 88 | using AbcG::Box3f; 89 | using AbcG::Box3d; 90 | 91 | using AbcG::M33f; 92 | using AbcG::M33d; 93 | using AbcG::M44f; 94 | using AbcG::M44d; 95 | 96 | using AbcG::Quatf; 97 | using AbcG::Quatd; 98 | 99 | using AbcG::C3h; 100 | using AbcG::C3f; 101 | using AbcG::C3c; 102 | 103 | using AbcG::C4h; 104 | using AbcG::C4f; 105 | using AbcG::C4c; 106 | 107 | using AbcG::N3f; 108 | using AbcG::N3d; 109 | 110 | } // namespace Util 111 | } // namespace EncinoWaves 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/OceanTestSky.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_OceanTestSky_h_ 36 | #define _EncinoWaves_OceanTestSky_h_ 37 | 38 | #include "OceanTestFoundation.h" 39 | 40 | namespace OceanTest { 41 | 42 | //-***************************************************************************** 43 | class Sky { 44 | public: 45 | struct Parameters { 46 | std::string filename; 47 | double time; 48 | double day; 49 | double latitude; 50 | double longitude; 51 | double GMT_offset; 52 | double turbidity; 53 | 54 | Parameters() 55 | : filename("") 56 | , time(23.0) // 24 hour clock 57 | , day(235.0) // day out of 365 58 | , latitude(37.783) // san francisco 59 | , longitude(122.4167) // san francisco 60 | , GMT_offset(17.0) // san francisco is GMT-7 61 | , turbidity(0.9) {} 62 | }; 63 | 64 | Sky(const Parameters& i_params) 65 | : m_params(i_params) {} 66 | 67 | void setUniforms(GeepGLFW::Program& i_program) const; 68 | 69 | protected: 70 | Parameters m_params; 71 | }; 72 | 73 | } // namespace OceanTest 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/OceanTestFoundation.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_OceanTest_Foundation_h_ 36 | #define _EncinoWaves_OceanTest_Foundation_h_ 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | 44 | #include 45 | #include 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | 66 | namespace OceanTest { 67 | 68 | //-***************************************************************************** 69 | namespace ewav = EncinoWaves; 70 | using namespace EncinoWaves; 71 | using namespace EncinoWaves::Util; 72 | using namespace EncinoWaves::GeepGLFW; 73 | 74 | } // namespace OceanTest 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/PointsDrawHelper.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_SimpleSimViewer_PointsDrawHelper_h_ 18 | #define _EncinoWaves_SimpleSimViewer_PointsDrawHelper_h_ 19 | 20 | #include "Foundation.h" 21 | #include "GLCamera.h" 22 | 23 | namespace EncinoWaves { 24 | namespace SimpleSimViewer { 25 | 26 | //-***************************************************************************** 27 | class PointsDrawHelper { 28 | public: 29 | PointsDrawHelper(bool i_dynamic, std::size_t i_numPoints, 30 | const V3f* i_vtxPosData, const V3f* i_vtxNormData, 31 | const V3f* i_vtxColData, const V2f* i_vtxUvData); 32 | 33 | virtual ~PointsDrawHelper(); 34 | 35 | // Update the point data 36 | void update(std::size_t i_numPoints, const V3f* i_vtxPosData, 37 | const V3f* i_vtxNormData, const V3f* i_vtxColData, 38 | const V2f* i_vtxUvData); 39 | 40 | // Draw. 41 | void draw(const GLCamera& i_cam) const; 42 | 43 | GLint posVboIdx() const { return m_posVboIdx; } 44 | GLint normVboIdx() const { return m_normVboIdx; } 45 | GLint colVboIdx() const { return m_colVboIdx; } 46 | GLint uvVboIdx() const { return m_uvVboIdx; } 47 | 48 | GLuint vertexArrayObject() const { return m_vertexArrayObject; } 49 | 50 | protected: 51 | template 52 | void updateFloatVertexBuffer(const T* i_vtxData, int i_vboIdx) { 53 | if (i_vboIdx < 0 || i_vtxData == NULL || m_numPoints == 0) { 54 | return; 55 | } 56 | 57 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[i_vboIdx]); 58 | UtilGL::CheckErrors("glBindBuffer"); 59 | glBufferData(GL_ARRAY_BUFFER, sizeof(T) * m_numPoints, 60 | (const GLvoid*)i_vtxData, GL_DYNAMIC_DRAW); 61 | UtilGL::CheckErrors("glBufferData"); 62 | } 63 | 64 | std::size_t m_numPoints; 65 | const V3f* m_vtxPosData; 66 | const V3f* m_vtxNormData; 67 | const V3f* m_vtxColData; 68 | const V2f* m_vtxUvData; 69 | 70 | // The VAO and VBOs 71 | GLuint m_vertexArrayObject; 72 | // At most we have pos, norm, col, uv 73 | GLuint m_vertexBuffers[4]; 74 | int m_numVBOs; 75 | GLint m_posVboIdx; 76 | GLint m_normVboIdx; 77 | GLint m_colVboIdx; 78 | GLint m_uvVboIdx; 79 | }; 80 | 81 | } // namespace SimpleSimViewer 82 | } // namespace EncinoWaves 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/ViewerGLFW.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_SimpleSimViewer_ViewerGLFW_h_ 18 | #define _EncinoWaves_SimpleSimViewer_ViewerGLFW_h_ 19 | 20 | #include "Foundation.h" 21 | #include "Sim.h" 22 | #include "GLCamera.h" 23 | 24 | namespace EncinoWaves { 25 | namespace SimpleSimViewer { 26 | 27 | //-***************************************************************************** 28 | class Viewer; 29 | 30 | //-***************************************************************************** 31 | class GLFWGlobal { 32 | public: 33 | GLFWGlobal(); 34 | ~GLFWGlobal(); 35 | 36 | void registerWindowAndViewer(GLFWwindow* i_window, Viewer* i_viewer); 37 | 38 | void unregisterWindowAndAllViewers(GLFWwindow* i_window); 39 | 40 | Viewer* viewerFromWindow(GLFWwindow* i_window, bool i_throwIfNotFound = true); 41 | 42 | protected: 43 | typedef std::map WindowViewerMap; 44 | WindowViewerMap m_wvMap; 45 | }; 46 | 47 | //-***************************************************************************** 48 | class Viewer { 49 | public: 50 | static const int BMASK_LEFT = 0x1 << 0; // binary 001 51 | static const int BMASK_MIDDLE = 0x1 << 1; // binary 010 52 | static const int BMASK_RIGHT = 0x1 << 2; // binary 100 53 | 54 | explicit Viewer(std::shared_ptr i_sim, bool i_anim = false); 55 | ~Viewer(); 56 | 57 | void init(); 58 | void tick(bool i_force); 59 | void display(); 60 | void reshape(int i_width, int i_height); 61 | void keyboard(int i_key, int i_scancode, int i_action, int i_mods); 62 | void character(unsigned int i_char); 63 | void mouse(int i_button, int i_action, int i_mods); 64 | void mouseDrag(double x, double y); 65 | GLFWwindow* window() { return m_window; } 66 | 67 | protected: 68 | std::shared_ptr m_sim; 69 | 70 | GLFWwindow* m_window; 71 | 72 | int m_buttonMask; 73 | double m_mouseX; 74 | double m_mouseY; 75 | double m_lastX; 76 | double m_lastY; 77 | int m_keyMods; 78 | 79 | bool m_animating; 80 | 81 | // GLCamera m_camera; 82 | Timer m_playbackTimer; 83 | }; 84 | 85 | //-***************************************************************************** 86 | void SimpleViewSim(std::shared_ptr i_sim, bool i_playing = false); 87 | 88 | } // namespace SimpleSimViewer 89 | } // namespace EncinoWaves 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/LinesDrawHelper.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_SimpleSimViewer_LinesDrawHelper_h_ 18 | #define _EncinoWaves_SimpleSimViewer_LinesDrawHelper_h_ 19 | 20 | #include "Foundation.h" 21 | #include "GLCamera.h" 22 | 23 | namespace EncinoWaves { 24 | namespace SimpleSimViewer { 25 | 26 | //-***************************************************************************** 27 | class LinesDrawHelper { 28 | public: 29 | LinesDrawHelper(bool i_dynamic, std::size_t i_numPoints, 30 | const V3f* i_vtxPosData, const V3f* i_vtxNormData, 31 | const V3f* i_vtxColData, const V2f* i_vtxUvData); 32 | 33 | virtual ~LinesDrawHelper(); 34 | 35 | // Update the point data 36 | void update(std::size_t i_numPoints, const V3f* i_vtxPosData, 37 | const V3f* i_vtxNormData, const V3f* i_vtxColData, 38 | const V2f* i_vtxUvData); 39 | 40 | // Draw. 41 | void draw(const GLCamera& i_cam) const; 42 | 43 | // Draw. 44 | void draw() const; 45 | 46 | GLint posVboIdx() const { return m_posVboIdx; } 47 | GLint normVboIdx() const { return m_normVboIdx; } 48 | GLint colVboIdx() const { return m_colVboIdx; } 49 | GLint uvVboIdx() const { return m_uvVboIdx; } 50 | 51 | GLuint vertexArrayObject() const { return m_vertexArrayObject; } 52 | 53 | protected: 54 | template 55 | void updateFloatVertexBuffer(const T* i_vtxData, int i_vboIdx) { 56 | if (i_vboIdx < 0 || i_vtxData == NULL || m_numPoints == 0) { 57 | return; 58 | } 59 | 60 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[i_vboIdx]); 61 | UtilGL::CheckErrors("glBindBuffer"); 62 | glBufferData(GL_ARRAY_BUFFER, sizeof(T) * m_numPoints, 63 | (const GLvoid*)i_vtxData, GL_DYNAMIC_DRAW); 64 | UtilGL::CheckErrors("glBufferData"); 65 | } 66 | 67 | std::size_t m_numPoints; 68 | const V3f* m_vtxPosData; 69 | const V3f* m_vtxNormData; 70 | const V3f* m_vtxColData; 71 | const V2f* m_vtxUvData; 72 | 73 | // The VAO and VBOs 74 | GLuint m_vertexArrayObject; 75 | // At most we have pos, norm, col, uv 76 | GLuint m_vertexBuffers[4]; 77 | int m_numVBOs; 78 | GLint m_posVboIdx; 79 | GLint m_normVboIdx; 80 | GLint m_colVboIdx; 81 | GLint m_uvVboIdx; 82 | }; 83 | 84 | } // namespace SimpleSimViewer 85 | } // namespace EncinoWaves 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/GeepGLFW/Tests/glfw_helloWorld2.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // This comes straight out of the GLFW docs, with a bit of reformatting 19 | // by me. I'm also calling the UtilGL Init inside the GeepGLFW library. 20 | //-***************************************************************************** 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | static void error_callback(int error, const char* description) { 27 | fputs(description, stderr); 28 | } 29 | 30 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, 31 | int mods) { 32 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { 33 | glfwSetWindowShouldClose(window, GL_TRUE); 34 | } 35 | } 36 | 37 | int main(void) { 38 | GLFWwindow* window; 39 | glfwSetErrorCallback(error_callback); 40 | 41 | if (!glfwInit()) { 42 | exit(EXIT_FAILURE); 43 | } 44 | 45 | window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); 46 | if (!window) { 47 | glfwTerminate(); 48 | exit(EXIT_FAILURE); 49 | } 50 | 51 | glfwMakeContextCurrent(window); 52 | 53 | // CJH: This is the only part I added. 54 | EncinoWaves::GeepGLFW::UtilGL::Init(true); 55 | 56 | glfwSetKeyCallback(window, key_callback); 57 | while (!glfwWindowShouldClose(window)) { 58 | float ratio; 59 | int width, height; 60 | glfwGetFramebufferSize(window, &width, &height); 61 | ratio = width / (float)height; 62 | glViewport(0, 0, width, height); 63 | glClear(GL_COLOR_BUFFER_BIT); 64 | #if 0 65 | glMatrixMode( GL_PROJECTION ); 66 | glLoadIdentity(); 67 | glOrtho( -ratio, ratio, -1.f, 1.f, 1.f, -1.f ); 68 | glMatrixMode( GL_MODELVIEW ); 69 | glLoadIdentity(); 70 | glRotatef( ( float ) glfwGetTime() * 50.f, 0.f, 0.f, 1.f ); 71 | glBegin( GL_TRIANGLES ); 72 | glColor3f( 1.f, 0.f, 0.f ); 73 | glVertex3f( -0.6f, -0.4f, 0.f ); 74 | glColor3f( 0.f, 1.f, 0.f ); 75 | glVertex3f( 0.6f, -0.4f, 0.f ); 76 | glColor3f( 0.f, 0.f, 1.f ); 77 | glVertex3f( 0.f, 0.6f, 0.f ); 78 | glEnd(); 79 | #endif 80 | glfwSwapBuffers(window); 81 | glfwPollEvents(); 82 | } 83 | 84 | glfwDestroyWindow(window); 85 | glfwTerminate(); 86 | exit(EXIT_SUCCESS); 87 | } 88 | -------------------------------------------------------------------------------- /src/EncinoWaves/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##-***************************************************************************** 2 | ## Copyright 2015 Christopher Jon Horvath 3 | ## 4 | ## Licensed under the Apache License, Version 2.0 (the "License"); 5 | ## you may not use this file except in compliance with the License. 6 | ## You may obtain a copy of the License at 7 | ## 8 | ## http://www.apache.org/licenses/LICENSE-2.0 9 | ## 10 | ## Unless required by applicable law or agreed to in writing, software 11 | ## distributed under the License is distributed on an "AS IS" BASIS, 12 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ## See the License for the specific language governing permissions and 14 | ## limitations under the License. 15 | ##-***************************************************************************** 16 | 17 | ##-***************************************************************************** 18 | ## The basic architecture of these Waves is based on the TweakWaves application 19 | ## written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | ## on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | ## "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | ## 23 | ## The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | ## directional spreading functions are formulated based on the descriptions 25 | ## given in "Ocean Waves: The Stochastic Approach", 26 | ## by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | ## 28 | ## This library is written as a working implementation of the paper: 29 | ## Christopher J. Horvath. 2015. 30 | ## Empirical directional wave spectra for computer graphics. 31 | ## In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | ## Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | ##-***************************************************************************** 34 | 35 | SET( H_FILES 36 | All.h 37 | Basics.h 38 | DirectionalSpreading.h 39 | Dispersion.h 40 | FftwWrapper.h 41 | Filter.h 42 | Foundation.h 43 | InitialState.h 44 | MipMap.h 45 | Normals.h 46 | Parameters.h 47 | Propagation.h 48 | Random.h 49 | Spectra.h 50 | SpectralSpatialField.h 51 | Stats.h 52 | ) 53 | 54 | SET( CXX_FILES 55 | Foundation.cpp 56 | FftwWrapper.cpp 57 | ) 58 | 59 | SET( SOURCE_FILES ${CXX_FILES} ${H_FILES} ) 60 | 61 | # Create the library 62 | ADD_LIBRARY( EncinoWavesEncinoWaves ${SOURCE_FILES} ) 63 | 64 | # Recurse into test subdirectory 65 | ADD_SUBDIRECTORY( Tests ) 66 | 67 | #-****************************************************************************** 68 | #-****************************************************************************** 69 | # INSTALLATION 70 | #-****************************************************************************** 71 | #-****************************************************************************** 72 | 73 | INSTALL( TARGETS EncinoWavesEncinoWaves 74 | LIBRARY DESTINATION lib 75 | ARCHIVE DESTINATION lib/static ) 76 | 77 | INSTALL( FILES ${H_FILES} 78 | DESTINATION include/EncinoWaves/EncinoWaves 79 | PERMISSIONS OWNER_READ GROUP_READ WORLD_READ ) 80 | 81 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/test_Propagation.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | namespace ewav = EncinoWaves; 42 | 43 | //-***************************************************************************** 44 | int main(int argc, char* argv[]) { 45 | ewav::Parametersf params; 46 | params.resolutionPowerOfTwo = 11; 47 | 48 | ewav::InitialStatef istate(params); 49 | int w = istate.HSpectralPos.width(); 50 | int h = istate.HSpectralPos.height(); 51 | int N = h; 52 | std::cout << "Computed initial state." << std::endl 53 | << "Size: " << w << " by " << h << std::endl 54 | << "HspecPos: " << istate.HSpectralPos[N / 4][N / 4] << std::endl 55 | << "HspecNeg: " << istate.HSpectralNeg[N / 4][N / 4] << std::endl 56 | << "Omega: " << istate.Omega[N / 4][N / 4] << std::endl; 57 | 58 | ewav::PropagatedStatef pstate(params); 59 | std::cout << "Created propagated state." << std::endl; 60 | 61 | ewav::Propagationf prop(params); 62 | std::cout << "Created propagation." << std::endl; 63 | 64 | for (int frame = 1; frame < 24; ++frame) { 65 | float ftime = float(frame) / 24.0f; 66 | prop.propagate(params, istate, pstate, ftime); 67 | std::cout << "Propagated to frame: " << frame << std::endl 68 | << "H: " << pstate.Height[N / 4][N / 4] << std::endl 69 | << "Dx: " << pstate.Dx[N / 4][N / 4] << std::endl 70 | << "Dy: " << pstate.Dy[N / 4][N / 4] << std::endl 71 | << "MinE: " << pstate.MinE[N / 4][N / 4] << std::endl; 72 | } 73 | 74 | return 0; 75 | } -------------------------------------------------------------------------------- /src/SimpleSimViewer/Sim.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #include "Sim.h" 18 | 19 | namespace EncinoWaves { 20 | namespace SimpleSimViewer { 21 | 22 | //-***************************************************************************** 23 | BaseSim::~BaseSim() {} 24 | 25 | //-***************************************************************************** 26 | void BaseSim::outerDraw() { 27 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 28 | UtilGL::CheckErrors("outerDraw glClearColor"); 29 | 30 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 31 | UtilGL::CheckErrors("outerDraw glClear"); 32 | 33 | draw(); 34 | } 35 | 36 | //-***************************************************************************** 37 | Sim3D::~Sim3D() {} 38 | 39 | //-***************************************************************************** 40 | void Sim3D::init(int w, int h) { 41 | m_camera.setSize(w, h); 42 | m_camera.lookAt(V3d(24, 18, 24), V3d(0.0)); 43 | m_camera.frame(getBounds()); 44 | } 45 | 46 | //-***************************************************************************** 47 | void Sim3D::reshape(int w, int h) { m_camera.setSize(w, h); } 48 | 49 | //-***************************************************************************** 50 | void Sim3D::frame() { m_camera.frame(getBounds()); } 51 | 52 | //-***************************************************************************** 53 | void Sim3D::dolly(float dx, float dy) { m_camera.dolly(V2d(dx, dy)); } 54 | 55 | //-***************************************************************************** 56 | void Sim3D::track(float dx, float dy) { m_camera.track(V2d(dx, dy)); } 57 | 58 | //-***************************************************************************** 59 | void Sim3D::rotate(float dx, float dy) { m_camera.rotate(V2d(dx, dy)); } 60 | 61 | //-***************************************************************************** 62 | void Sim3D::outputCamera() { 63 | std::cout << "# Camera\n" << m_camera.RIB() << std::endl; 64 | } 65 | 66 | //-***************************************************************************** 67 | void Sim3D::outerDraw() { 68 | #if OSX_GLFW_VIEWPORT_BUG 69 | glViewport(0, 0, 2 * (GLsizei)m_camera.width(), 70 | 2 * (GLsizei)m_camera.height()); 71 | #else 72 | glViewport(0, 0, (GLsizei)m_camera.width(), (GLsizei)m_camera.height()); 73 | #endif 74 | 75 | double n, f; 76 | m_camera.autoSetClippingPlanes(getBounds()); 77 | if (overrideClipping(n, f)) { 78 | m_camera.setClippingPlanes(n, f); 79 | } 80 | 81 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 82 | UtilGL::CheckErrors("outerDraw glClearColor"); 83 | 84 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 85 | UtilGL::CheckErrors("outerDraw glClear"); 86 | 87 | draw(); 88 | } 89 | 90 | } // namespace SimpleSimViewer 91 | } // namespace EncinoWaves 92 | -------------------------------------------------------------------------------- /src/GeepGLFW/UtilGL.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #include "UtilGL.h" 18 | 19 | namespace EncinoWaves { 20 | namespace GeepGLFW { 21 | namespace UtilGL { 22 | 23 | //-***************************************************************************** 24 | void Init(bool i_experimental) { 25 | CheckErrors("GeepGLFW::init before anything"); 26 | 27 | // On Mac, GLEW stuff is not necessary. 28 | #ifndef PLATFORM_DARWIN 29 | glewExperimental = i_experimental ? GL_TRUE : GL_FALSE; 30 | glewInit(); 31 | #endif 32 | // Reset errors. 33 | glGetError(); 34 | 35 | printf("OPEN GL VERSION: %s\n", glGetString(GL_VERSION)); 36 | 37 | CheckErrors("GeepGLFW::init glGetString"); 38 | } 39 | 40 | //-***************************************************************************** 41 | void CheckErrors(const std::string &i_label) { 42 | GLenum errCode; 43 | 44 | #ifndef DEBUG 45 | EWAV_ASSERT((errCode = glGetError()) == GL_NO_ERROR, 46 | "OpenGL Error: " 47 | << "Code = " << (int)errCode << " ( Label: " << i_label 48 | << " )"); 49 | 50 | #else 51 | 52 | if ((errCode = glGetError()) != GL_NO_ERROR) { 53 | std::cerr << "OpenGL Error: " 54 | << "Code = " << (int)errCode << " ( Label: " << i_label << " )" 55 | << std::endl; 56 | abort(); 57 | } 58 | 59 | #endif 60 | } 61 | 62 | //-***************************************************************************** 63 | void CheckFramebuffer() { 64 | GLenum status; 65 | status = (GLenum)glCheckFramebufferStatus(GL_FRAMEBUFFER); 66 | switch (status) { 67 | case GL_FRAMEBUFFER_COMPLETE: 68 | return; 69 | case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: 70 | EWAV_THROW("Framebuffer incomplete, incomplete attachment"); 71 | break; 72 | case GL_FRAMEBUFFER_UNSUPPORTED: 73 | EWAV_THROW("Unsupported framebuffer format"); 74 | break; 75 | case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: 76 | EWAV_THROW("Framebuffer incomplete, missing attachment"); 77 | break; 78 | // case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: 79 | // EWAV_THROW( 80 | // "Framebuffer incomplete, attached images " 81 | // "must have same dimensions" ); 82 | // break; 83 | // case GL_FRAMEBUFFER_INCOMPLETE_FORMATS: 84 | // EWAV_THROW( 85 | // "Framebuffer incomplete, attached images " 86 | // "must have same format" ); 87 | // break; 88 | case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: 89 | EWAV_THROW("Framebuffer incomplete, missing draw buffer"); 90 | break; 91 | case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: 92 | EWAV_THROW("Framebuffer incomplete, missing read buffer"); 93 | break; 94 | } 95 | EWAV_THROW("Unknown GL Framebuffer error"); 96 | } 97 | 98 | } // namespace UtilGL 99 | } // namespace GeepGLFW 100 | } // namespace EncinoWaves 101 | -------------------------------------------------------------------------------- /src/Util/Tests/test_Cpp11.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | typedef uint64_t seed_type; 27 | typedef std::linear_congruential_engine Rand48_Engine; 30 | 31 | //-***************************************************************************** 32 | // Let's see whether we can use fancy cmath stuff. 33 | void testFancyCmathStuff() { 34 | // Gamma. 35 | std::cout << "Gamma of 0.5 = " << std::tgamma(0.5) << std::endl; 36 | 37 | // Lround. 38 | std::cout << "Long round of 191381.1356: " << std::lround(191381.1356) 39 | << std::endl; 40 | 41 | // Erf & Erfc 42 | std::cout << "Erf of 18.881: " << std::erf(18.881) << std::endl 43 | << "Erfc of 18.881: " << std::erfc(18.881) << std::endl; 44 | 45 | // Random stuff 46 | Rand48_Engine rnd; 47 | rnd.seed(12345); 48 | std::uniform_real_distribution dist(0.0, 1.0); 49 | std::cout << "First draw from Rand48: " << dist(rnd) << std::endl; 50 | } 51 | 52 | //-***************************************************************************** 53 | template 54 | void applyToAll(ITER i_begin, ITER i_end, F i_func) { 55 | int N = i_end - i_begin; 56 | int* ptr = &(*i_begin); 57 | for (int i = 0; i < N; ++i) { 58 | i_func(*(ptr + i), i); 59 | } 60 | } 61 | 62 | //-***************************************************************************** 63 | struct Base { 64 | Base() 65 | : a(0.0f) {} 66 | float a; 67 | 68 | float A() const { return a; } 69 | }; 70 | 71 | //-***************************************************************************** 72 | template 73 | struct Derived : public Base { 74 | Derived() 75 | : Base() 76 | , b(T(0)) {} 77 | 78 | T b; 79 | // using Base::A; 80 | T B() const { return b; } 81 | T C() const { return b + A(); } 82 | }; 83 | 84 | //-***************************************************************************** 85 | template 86 | struct Derived2 : public Derived { 87 | Derived2() 88 | : Derived() 89 | , c(T(0)) {} 90 | 91 | T c; 92 | 93 | using Derived::C; 94 | 95 | T C2() const { return c + C(); } 96 | }; 97 | 98 | //-***************************************************************************** 99 | int main(int argc, char* argv[]) { 100 | std::vector v(17); 101 | 102 | applyToAll(v.begin(), v.end(), [](int& i, int j) { i = j; }); 103 | std::for_each(v.begin(), v.end(), [](int i) { std::cout << i << std::endl; }); 104 | 105 | testFancyCmathStuff(); 106 | 107 | Derived2 D; 108 | std::cout << "A = " << D.A() << std::endl << "C = " << D.C() << std::endl; 109 | 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/GLCamera.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_SimpleSimViewer_GLCamera_h_ 18 | #define _EncinoWaves_SimpleSimViewer_GLCamera_h_ 19 | 20 | #include "Foundation.h" 21 | 22 | namespace EncinoWaves { 23 | namespace SimpleSimViewer { 24 | 25 | //-***************************************************************************** 26 | class GLCamera { 27 | public: 28 | GLCamera(); 29 | ~GLCamera(){}; 30 | 31 | // Executes OpenGL commands to show the current camera 32 | void apply() const; 33 | 34 | //-************************************************************************* 35 | // LOCAL TRANSFORM: Get, Set 36 | M44d modelViewMatrix() const; 37 | M44d projectionMatrix() const; 38 | 39 | const V3d &rotation() const { return m_rotation; } 40 | void setRotation(const V3d &r) { m_rotation = r; } 41 | 42 | const V3d &scale() const { return m_scale; } 43 | void setScale(const V3d &s) { m_scale = s; } 44 | 45 | const V3d &translation() const { return m_translation; } 46 | void setTranslation(const V3d &t) { m_translation = t; } 47 | 48 | double centerOfInterest() const { return m_centerOfInterest; } 49 | void setCenterOfInterest(double coi) { 50 | m_centerOfInterest = std::max(coi, 0.1); 51 | } 52 | 53 | double fovy() const { return m_fovy; } 54 | void setFovy(double fvy) { m_fovy = fvy; } 55 | 56 | int width() const { return m_size.x; } 57 | int height() const { return m_size.y; } 58 | 59 | const V2d &clippingPlanes() const { return m_clip; } 60 | void autoSetClippingPlanes(const Box3d &bounds); 61 | void setClippingPlanes(double near, double far) { 62 | m_clip.x = near; 63 | m_clip.y = far; 64 | } 65 | 66 | //-************************************************************************* 67 | // UI Actions 68 | void track(const V2d &point); 69 | void dolly(const V2d &point, double dollySpeed = 5.0); 70 | void rotate(const V2d &point, double rotateSpeed = 400.0); 71 | 72 | void frame(const Box3d &bounds); 73 | 74 | void lookAt(const V3d &eye, const V3d &at); 75 | 76 | void setSize(int w, int h) { 77 | m_size.x = w; 78 | m_size.y = h; 79 | } 80 | void setSize(const V2i &sze) { m_size = sze; } 81 | 82 | //-************************************************************************* 83 | // RIB STUFF 84 | std::string RIB() const; 85 | 86 | //-************************************************************************* 87 | // RAY STUFF - convert a screen space point, in raster space, to a 88 | // ray from the eye. 89 | Imath::Line3d getRayThroughRasterPoint(const V2d &pt_raster) const; 90 | 91 | protected: 92 | //-************************************************************************* 93 | // DATA 94 | V3d m_rotation; 95 | V3d m_scale; 96 | V3d m_translation; 97 | 98 | double m_centerOfInterest; 99 | double m_fovy; 100 | V2d m_clip; 101 | V2i m_size; 102 | double m_aspect; 103 | }; 104 | 105 | } // namespace SimpleSimViewer 106 | } // namespace EncinoWaves 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/test_MipMap.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | namespace ewav = EncinoWaves; 42 | 43 | //-***************************************************************************** 44 | int main(int argc, char* argv[]) { 45 | ewav::Parametersf params; 46 | params.resolutionPowerOfTwo = 11; 47 | if (argc > 1) { 48 | params.resolutionPowerOfTwo = atoi(argv[1]); 49 | } 50 | 51 | ewav::InitialStatef istate(params); 52 | int w = istate.HSpectralPos.width(); 53 | int h = istate.HSpectralPos.height(); 54 | int N = h; 55 | std::cout << "Computed initial state." << std::endl 56 | << "Size: " << w << " by " << h << std::endl 57 | << "HspecPos: " << istate.HSpectralPos[N / 4][N / 4] << std::endl 58 | << "HspecNeg: " << istate.HSpectralNeg[N / 4][N / 4] << std::endl 59 | << "Omega: " << istate.Omega[N / 4][N / 4] << std::endl; 60 | 61 | ewav::PropagatedStatef pstate(params); 62 | std::cout << "Created propagated state." << std::endl; 63 | 64 | ewav::Propagationf prop(params); 65 | std::cout << "Created propagation." << std::endl; 66 | 67 | float ftime = 96.0f / 24.0f; 68 | prop.propagate(params, istate, pstate, ftime); 69 | std::cout << "Propagated to frame: " << 96 << std::endl 70 | << "H: " << pstate.Height[N / 4][N / 4] << std::endl 71 | << "Dx: " << pstate.Dx[N / 4][N / 4] << std::endl 72 | << "Dy: " << pstate.Dy[N / 4][N / 4] << std::endl 73 | << "MinE: " << pstate.MinE[N / 4][N / 4] << std::endl; 74 | 75 | ewav::Statsf s1(pstate.Height, pstate.MinE); 76 | 77 | ewav::PropagatedStatef pstateDown(params.resolutionPowerOfTwo - 1); 78 | std::cout << "Created half-sized state." << std::endl; 79 | 80 | ewav::DownsampleState(pstate, pstateDown); 81 | std::cout << "Downsampled half-sized state from state." << std::endl; 82 | 83 | ewav::Statsf s2(pstateDown.Height, pstateDown.MinE); 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/MeshDrawHelper.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_SimpleSimViewer_MeshDrawHelper_h_ 18 | #define _EncinoWaves_SimpleSimViewer_MeshDrawHelper_h_ 19 | 20 | #include "Foundation.h" 21 | #include "GLCamera.h" 22 | 23 | namespace EncinoWaves { 24 | namespace SimpleSimViewer { 25 | 26 | //-***************************************************************************** 27 | class MeshDrawHelper { 28 | public: 29 | enum DeformType { 30 | // No changes at all 31 | kStaticDeform, 32 | 33 | // Vertex data (positions, colors, normals, etc) change, but 34 | // not indices 35 | kConsistentDeform, 36 | 37 | // Everything changes 38 | kInconsistentDeform 39 | }; 40 | 41 | MeshDrawHelper(DeformType i_deformType, std::size_t i_numTriangles, 42 | std::size_t i_numVertices, const V3ui* i_triIndices, 43 | const V3f* i_vtxPosData, const V3f* i_vtxNormData, 44 | const V3f* i_vtxColData, const V2f* i_vtxUvData); 45 | 46 | virtual ~MeshDrawHelper(); 47 | 48 | // Update only the vertex data, leave topology alone 49 | void update(const V3f* i_vtxPosData, const V3f* i_vtxNormData, 50 | const V3f* i_vtxColData, const V2f* i_vtxUvData); 51 | 52 | // Update EVERYTHING. 53 | void update(std::size_t i_numTriangles, std::size_t i_numVertices, 54 | const V3ui* i_triIndices, const V3f* i_vtxPosData, 55 | const V3f* i_vtxNormData, const V3f* i_vtxColData, 56 | const V2f* i_vtxUvData); 57 | 58 | // Draw. 59 | void draw(const GLCamera& i_cam) const; 60 | 61 | // Draw without camera. 62 | void draw() const; 63 | 64 | GLint posVboIdx() const { return m_posVboIdx; } 65 | GLint normVboIdx() const { return m_normVboIdx; } 66 | GLint colVboIdx() const { return m_colVboIdx; } 67 | GLint uvVboIdx() const { return m_uvVboIdx; } 68 | GLint indicesVboIdx() const { return m_indicesVboIdx; } 69 | 70 | GLuint vertexArrayObject() const { return m_vertexArrayObject; } 71 | 72 | protected: 73 | template 74 | void updateFloatVertexBuffer(const T* i_vtxData, int i_vboIdx) { 75 | if (i_vboIdx < 0 || i_vtxData == NULL || m_numVertices == 0) { 76 | return; 77 | } 78 | 79 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[i_vboIdx]); 80 | UtilGL::CheckErrors("glBindBuffer"); 81 | glBufferData(GL_ARRAY_BUFFER, sizeof(T) * m_numVertices, 82 | (const GLvoid*)i_vtxData, GL_DYNAMIC_DRAW); 83 | UtilGL::CheckErrors("glBufferData"); 84 | } 85 | 86 | DeformType m_deformType; 87 | std::size_t m_numTriangles; 88 | std::size_t m_numVertices; 89 | const V3ui* m_triIndices; 90 | const V3f* m_vtxPosData; 91 | const V3f* m_vtxNormData; 92 | const V3f* m_vtxColData; 93 | const V2f* m_vtxUvData; 94 | 95 | // The VAO and VBOs 96 | GLuint m_vertexArrayObject; 97 | // At most we have indices, pos, norm, col, uv 98 | GLuint m_vertexBuffers[5]; 99 | int m_numVBOs; 100 | GLint m_posVboIdx; 101 | GLint m_normVboIdx; 102 | GLint m_colVboIdx; 103 | GLint m_uvVboIdx; 104 | GLint m_indicesVboIdx; 105 | }; 106 | 107 | } // namespace SimpleSimViewer 108 | } // namespace EncinoWaves 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /src/EncinoWaves/Filter.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_Filter_h_ 36 | #define _EncinoWaves_Filter_h_ 37 | 38 | #include "Foundation.h" 39 | #include "Parameters.h" 40 | #include "Basics.h" 41 | 42 | namespace EncinoWaves { 43 | 44 | //-***************************************************************************** 45 | // nullptr filter does nothing, always returns 1.0 46 | //-***************************************************************************** 47 | template 48 | class NullFilter { 49 | public: 50 | NullFilter() {} 51 | explicit NullFilter(const Parameters& i_params) {} 52 | 53 | T operator()(T i_kMag) const { return T(1.0); } 54 | }; 55 | 56 | //-***************************************************************************** 57 | // We do filtering by wavelength, rather than frequency (which is standard) 58 | // because it's easier for artists to visualize. 59 | // This filter just creates a smooth band that protects the wavelengths 60 | // between smallWavelength and bigWavelength. 61 | //-***************************************************************************** 62 | template 63 | class SmoothInvertibleBandPassFilter { 64 | protected: 65 | T m_edge0; 66 | T m_edge1; 67 | T m_edge2; 68 | T m_edge3; 69 | T m_min; 70 | bool m_invert; 71 | 72 | public: 73 | SmoothInvertibleBandPassFilter() 74 | : m_edge0(0.0) 75 | , m_edge1(0.0) 76 | , m_edge2(10000.0) 77 | , m_edge3(10000.0) 78 | , m_min(1.0) 79 | , m_invert(false) {} 80 | 81 | SmoothInvertibleBandPassFilter(const Parameters& i_params) 82 | : m_edge0(i_params.filter.smallWavelength - i_params.filter.softWidth) 83 | , m_edge1(i_params.filter.smallWavelength) 84 | , m_edge2(i_params.filter.bigWavelength) 85 | , m_edge3(i_params.filter.bigWavelength + i_params.filter.softWidth) 86 | , m_min(i_params.filter.min) 87 | , m_invert(i_params.filter.invert) {} 88 | 89 | SmoothInvertibleBandPassFilter(T edge0, T edge1, T edge2, T edge3, T min, 90 | bool invert) 91 | : m_edge0(edge0) 92 | , m_edge1(edge1) 93 | , m_edge2(edge2) 94 | , m_edge3(edge3) 95 | , m_min(min) 96 | , m_invert(invert) {} 97 | 98 | T operator()(T i_kMag) const { 99 | const T wavelength = WavelengthFromWavenumber(i_kMag); 100 | const T t = smoothstep(m_edge0, m_edge1, wavelength) - 101 | smoothstep(m_edge2, m_edge3, wavelength); 102 | const T f = Imath::clamp(m_min + (T(1.0) - m_min) * t, T(0.0), T(1.0)); 103 | return (m_invert ? T(1.0) - f : f); 104 | } 105 | }; 106 | 107 | } // namespace EncinoWaves 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##-***************************************************************************** 2 | ## Copyright 2015 Christopher Jon Horvath 3 | ## 4 | ## Licensed under the Apache License, Version 2.0 (the "License"); 5 | ## you may not use this file except in compliance with the License. 6 | ## You may obtain a copy of the License at 7 | ## 8 | ## http://www.apache.org/licenses/LICENSE-2.0 9 | ## 10 | ## Unless required by applicable law or agreed to in writing, software 11 | ## distributed under the License is distributed on an "AS IS" BASIS, 12 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ## See the License for the specific language governing permissions and 14 | ## limitations under the License. 15 | ##-***************************************************************************** 16 | 17 | ##-***************************************************************************** 18 | ## The basic architecture of these Waves is based on the TweakWaves application 19 | ## written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | ## on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | ## "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | ## 23 | ## The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | ## directional spreading functions are formulated based on the descriptions 25 | ## given in "Ocean Waves: The Stochastic Approach", 26 | ## by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | ## 28 | ## This library is written as a working implementation of the paper: 29 | ## Christopher J. Horvath. 2015. 30 | ## Empirical directional wave spectra for computer graphics. 31 | ## In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | ## Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | ##-***************************************************************************** 34 | 35 | SET( THIS_LIBS 36 | EncinoWavesEncinoWaves 37 | ${EWAV_FFTW_LIBS} 38 | ${EWAV_OPENEXR_LIBS} 39 | ${EWAV_ILMBASE_LIBS} 40 | ${EWAV_BOOST_LIBS} 41 | ${EWAV_TBB_LIBS} 42 | ${EWAV_GL_LIBS} 43 | ${EWAV_THREAD_LIBS} 44 | ${EWAV_Z_LIBS} m ) 45 | 46 | SET( OCEAN_TEST_LIBS 47 | EncinoWavesEncinoWaves 48 | EncinoWavesSimpleSimViewer 49 | EncinoWavesGeepGLFW 50 | EncinoWavesUtil 51 | ${EWAV_ALEMBIC_LIBS} 52 | ${EWAV_HDF5_LIBS} 53 | ${EWAV_FFTW_LIBS} 54 | ${EWAV_OPENEXR_LIBS} 55 | ${EWAV_ILMBASE_LIBS} 56 | ${EWAV_BOOST_LIBS} 57 | ${EWAV_TBB_LIBS} 58 | ${EWAV_GL_LIBS} 59 | ${EWAV_THREAD_LIBS} 60 | ${EWAV_Z_LIBS} m ) 61 | 62 | #-****************************************************************************** 63 | # FFTW Test 64 | ADD_EXECUTABLE( test_ewav_Fftw test_Fftw.cpp ) 65 | TARGET_LINK_LIBRARIES( test_ewav_Fftw ${THIS_LIBS} ) 66 | ADD_TEST( TEST_ewav_Fftw test_ewav_Fftw ) 67 | 68 | 69 | #-****************************************************************************** 70 | # InitialState Test 71 | ADD_EXECUTABLE( test_ewav_InitialState test_InitialState.cpp ) 72 | TARGET_LINK_LIBRARIES( test_ewav_InitialState ${THIS_LIBS} ) 73 | ADD_TEST( TEST_ewav_InitialState test_ewav_InitialState ) 74 | 75 | #-****************************************************************************** 76 | # Propagation Test 77 | ADD_EXECUTABLE( test_ewav_Propagation test_Propagation.cpp ) 78 | TARGET_LINK_LIBRARIES( test_ewav_Propagation ${THIS_LIBS} ) 79 | ADD_TEST( TEST_ewav_Propagation test_ewav_Propagation ) 80 | 81 | #-****************************************************************************** 82 | # MipMap Test 83 | ADD_EXECUTABLE( test_ewav_MipMap test_MipMap.cpp ) 84 | TARGET_LINK_LIBRARIES( test_ewav_MipMap ${THIS_LIBS} ) 85 | ADD_TEST( TEST_ewav_MipMap test_ewav_MipMap ) 86 | 87 | ##-***************************************************************************** 88 | # Ocean Test 89 | SET( OCEAN_TEST_H 90 | OceanTestFoundation.h 91 | OceanTestEnvSphere.h 92 | OceanTestShaders.h 93 | OceanTestViewScene.h 94 | OceanTestSky.h 95 | OceanTestTextureSky.h 96 | OceanTestMesh.h 97 | ) 98 | SET( OCEAN_TEST_CPP 99 | OceanTestShaders.cpp 100 | OceanTestEnvSphere.cpp 101 | OceanTestViewScene.cpp 102 | OceanTestMain.cpp 103 | OceanTestSky.cpp 104 | OceanTestTextureSky.cpp 105 | OceanTestMesh.cpp 106 | ) 107 | ADD_EXECUTABLE( ewav_OceanTest ${OCEAN_TEST_H} ${OCEAN_TEST_CPP} ) 108 | TARGET_LINK_LIBRARIES( ewav_OceanTest ${OCEAN_TEST_LIBS} ) 109 | SET_TARGET_PROPERTIES( ewav_OceanTest 110 | PROPERTIES 111 | OUTPUT_NAME "EncinoWaves" ) 112 | 113 | INSTALL( TARGETS ewav_OceanTest 114 | DESTINATION bin ) 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/OceanTestMesh.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_OceanTestMesh_h_ 36 | #define _EncinoWaves_OceanTestMesh_h_ 37 | 38 | #include "OceanTestFoundation.h" 39 | #include "OceanTestSky.h" 40 | #include "OceanTestTextureSky.h" 41 | #include "OceanTestEnvSphere.h" 42 | 43 | namespace OceanTest { 44 | 45 | //-***************************************************************************** 46 | class Mesh { 47 | public: 48 | struct DrawParameters { 49 | int repeat = 2; 50 | float wind_rotation = 45.0f; 51 | DrawParameters() = default; 52 | }; 53 | 54 | Mesh(const ewav::Parametersf& i_wparams, const Sky::Parameters& i_sparams, 55 | const DrawParameters& i_dparams); 56 | ~Mesh(); 57 | 58 | void step(); 59 | 60 | void draw(const EncinoWaves::SimpleSimViewer::GLCamera& i_camera); 61 | 62 | Box3d getBounds() const { 63 | return Box3d(V3d(-0.125 * m_params.domain, -0.125 * m_params.domain, 64 | -0.125 * m_params.domain), 65 | V3d(0.125 * m_params.domain)); 66 | } 67 | 68 | const ewav::Parametersf& wavesParams() const { return m_params; } 69 | void setWavesParams(const ewav::Parametersf& i_params); 70 | void setDrawParams(const DrawParameters& dparams) { m_drawParams = dparams; } 71 | 72 | protected: 73 | void createProgram(); 74 | void setCameraUniforms( 75 | const EncinoWaves::SimpleSimViewer::GLCamera& i_camera); 76 | void setWavesUniforms(); 77 | void domainChange(); 78 | void propagateAtFrame(); 79 | 80 | // Waves parameters - sky params will be stored in sky 81 | ewav::Parametersf m_params; 82 | DrawParameters m_drawParams; 83 | 84 | // Waves system itself. 85 | std::unique_ptr m_wavesInitialState; 86 | std::unique_ptr m_wavesPropagatedState; 87 | std::unique_ptr m_wavesPropagation; 88 | std::unique_ptr m_wavesStats; 89 | int N; 90 | 91 | // Non-changing arrays of the wave system. 92 | std::vector m_vertsXY; 93 | std::vector m_indices; 94 | std::vector m_normals; 95 | 96 | // The time 97 | int m_frame; 98 | 99 | // xy, h, dx, dy, minE, normals, quadIndices. 100 | enum VertexBuffer { 101 | XY_BUFFER, 102 | H_BUFFER, 103 | DX_BUFFER, 104 | DY_BUFFER, 105 | MINE_BUFFER, 106 | NORMALS_BUFFER, 107 | INDICES_BUFFER, 108 | 109 | NUM_VERTEX_BUFFERS 110 | }; 111 | 112 | // The VAO and VBOs 113 | GLuint m_vertexArrayObject; 114 | GLuint m_vertexBuffers[NUM_VERTEX_BUFFERS]; 115 | 116 | // The Program. 117 | std::unique_ptr m_program; 118 | 119 | // The Sky 120 | std::unique_ptr m_sky; 121 | std::unique_ptr m_texture_sky; 122 | 123 | // Env Sphere 124 | std::unique_ptr m_env_sphere; 125 | }; 126 | 127 | } // namespace OceanTest 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/Sim.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_SimpleSimViewer_Sim_h_ 18 | #define _EncinoWaves_SimpleSimViewer_Sim_h_ 19 | 20 | #include "Foundation.h" 21 | #include "GLCamera.h" 22 | 23 | namespace EncinoWaves { 24 | namespace SimpleSimViewer { 25 | 26 | //-***************************************************************************** 27 | class BaseSim { 28 | public: 29 | //! Virtual base class for simulation. 30 | //! ... 31 | BaseSim(void) {} 32 | 33 | //! Virtual destructor 34 | //! ... 35 | virtual ~BaseSim(); 36 | 37 | //! Return a name 38 | //! ... 39 | virtual std::string getName() const { return "BaseSim"; } 40 | 41 | //! Preferred window size. 42 | //! ... 43 | virtual V2i preferredWindowSize() const { return V2i(800, 600); } 44 | 45 | //! Init draw 46 | //! ... 47 | virtual void init(int w, int h) {} 48 | 49 | //! Reshape 50 | //! ... 51 | virtual void reshape(int w, int h) {} 52 | 53 | //! Just step forward. 54 | //! ... 55 | virtual void step() {} 56 | 57 | //! frame 58 | //! ... 59 | virtual void frame() {} 60 | 61 | //! Dolly 62 | //! ... 63 | virtual void dolly(float dx, float dy) {} 64 | 65 | //! Track 66 | //! ... 67 | virtual void track(float dx, float dy) {} 68 | 69 | //! Rotate 70 | //! ... 71 | virtual void rotate(float dx, float dy) {} 72 | 73 | //! Output camera 74 | //! ... 75 | virtual void outputCamera() {} 76 | 77 | //! This draws, assuming a camera matrix has already been set. 78 | //! ... 79 | virtual void draw() {} 80 | 81 | //! This outer draw function sets up the drawing environment. 82 | //! ... 83 | virtual void outerDraw(); 84 | 85 | //! This calls the character function 86 | virtual void character(unsigned int i_char, int x, int y) {} 87 | 88 | //! This calls the keyboard function. 89 | virtual void keyboard(int i_key, int i_scancode, int i_action, int i_mods, 90 | int i_x, int i_y) {} 91 | 92 | virtual void mouse(int i_button, int i_action, int i_mods, double x, double y, 93 | double lastX, double lastY) {} 94 | 95 | virtual void mouseDrag(double x, double y, double lastX, double lastY) {} 96 | }; 97 | 98 | //-***************************************************************************** 99 | class Sim3D : public BaseSim { 100 | public: 101 | //! Virtual base class for simulation. 102 | //! ... 103 | Sim3D(void) 104 | : BaseSim() {} 105 | 106 | //! Virtual destructor 107 | //! ... 108 | virtual ~Sim3D(); 109 | 110 | //! Return a name 111 | //! ... 112 | virtual std::string getName() const override { return "Sim3D"; } 113 | 114 | //! Init draw 115 | //! ... 116 | virtual void init(int w, int h) override; 117 | 118 | //! Reshape 119 | //! ... 120 | virtual void reshape(int w, int h) override; 121 | 122 | //! frame 123 | //! ... 124 | virtual void frame() override; 125 | 126 | //! Dolly 127 | //! ... 128 | virtual void dolly(float dx, float dy) override; 129 | 130 | //! Track 131 | //! ... 132 | virtual void track(float dx, float dy) override; 133 | 134 | //! Rotate 135 | //! ... 136 | virtual void rotate(float dx, float dy) override; 137 | 138 | //! Output camera 139 | //! ... 140 | virtual void outputCamera() override; 141 | 142 | //! Return the bounds at the current time. 143 | //! ... 144 | virtual Box3d getBounds() const { return Box3d(V3d(-0.1), V3d(0.1)); } 145 | 146 | //! Override clipping 147 | //! ... 148 | virtual bool overrideClipping(double& o_near, double& o_far) const { 149 | return false; 150 | } 151 | 152 | //! This outer draw function sets up the drawing environment. 153 | //! ... 154 | virtual void outerDraw() override; 155 | 156 | //! Return the camera 157 | const GLCamera& camera() const { return m_camera; } 158 | 159 | protected: 160 | GLCamera m_camera; 161 | }; 162 | 163 | } // namespace SimpleSimViewer 164 | } // namespace EncinoWaves 165 | 166 | #endif 167 | -------------------------------------------------------------------------------- /src/EncinoWaves/Normals.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_Normals_h_ 36 | #define _EncinoWaves_Normals_h_ 37 | 38 | #include "Foundation.h" 39 | #include "SpectralSpatialField.h" 40 | #include "Propagation.h" 41 | 42 | namespace EncinoWaves { 43 | 44 | template 45 | struct ComputeNormalsWithPinching { 46 | using V3T = Imath::Vec3; 47 | 48 | const T* H = nullptr; 49 | const T* DX = nullptr; 50 | const T* DY = nullptr; 51 | V3T* Normals = nullptr; 52 | 53 | int N = 0; 54 | T Spacing; 55 | T AmpGain; 56 | T Pinch; 57 | 58 | std::size_t index(std::size_t x, std::size_t y) const { 59 | return (y * std::size_t(N + 1)) + x; 60 | } 61 | 62 | V3T pointAtIndex(T i_xMult, T i_yMult, std::size_t i_index) const { 63 | return V3T((i_xMult * Spacing) - (Pinch * DX[i_index]), 64 | (i_yMult * Spacing) - (Pinch * DY[i_index]), 65 | AmpGain * H[i_index]); 66 | } 67 | 68 | void operator()(const tbb::blocked_range2d& range) const { 69 | for (auto y = range.rows().begin(); y != range.rows().end(); ++y) { 70 | auto downY = wrap(y - 1, N); 71 | auto cenY = wrap(y, N); 72 | auto upY = wrap(y + 1, N); 73 | 74 | for (auto x = range.cols().begin(); x != range.cols().end(); ++x) { 75 | auto leftX = wrap(x - 1, N); 76 | auto cenX = wrap(x, N); 77 | auto rightX = wrap(x + 1, N); 78 | 79 | auto leftIndex = index(leftX, cenY); 80 | auto rightIndex = index(rightX, cenY); 81 | auto downIndex = index(cenX, downY); 82 | auto upIndex = index(cenX, upY); 83 | 84 | auto downPoint = pointAtIndex(T(0.0), T(-1.0), downIndex); 85 | auto leftPoint = pointAtIndex(T(-1.0), T(0.0), leftIndex); 86 | auto rightPoint = pointAtIndex(T(1.0), T(0.0), rightIndex); 87 | auto upPoint = pointAtIndex(T(0.0), T(1.0), upIndex); 88 | 89 | auto dPdU = rightPoint - leftPoint; 90 | auto dPdV = upPoint - downPoint; 91 | 92 | Normals[index(x, y)] = dPdU.cross(dPdV).normalized(); 93 | } 94 | } 95 | } 96 | }; 97 | 98 | //-***************************************************************************** 99 | template 100 | void ComputeNormals(const Parameters& i_params, 101 | const PropagatedState& i_waves, 102 | Imath::Vec3* o_normals) { 103 | const int N = i_waves.Height.unpaddedWidth(); 104 | const T spacing = i_params.domain / T(N); 105 | 106 | ComputeNormalsWithPinching F; 107 | F.H = i_waves.Height.cdata(); 108 | F.DX = i_waves.Dx.cdata(); 109 | F.DY = i_waves.Dy.cdata(); 110 | F.Normals = o_normals; 111 | 112 | F.N = N; 113 | F.Spacing = spacing; 114 | F.AmpGain = i_params.amplitudeGain; 115 | F.Pinch = i_params.pinch; 116 | 117 | tbb::parallel_for(tbb::blocked_range2d{0, N + 1, 1, 0, N + 1, 512}, F); 118 | } 119 | 120 | } // namespace EncinoWaves 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/test_Fftw.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | namespace ewav = EncinoWaves; 46 | 47 | typedef ewav::CSpectralField2Df::value_type Cf; 48 | 49 | //-***************************************************************************** 50 | struct RandFillFunctor { 51 | Cf* Spectral; 52 | std::size_t StrideJ; 53 | int N; 54 | float Domain; 55 | ewav::seed_type Seed; 56 | 57 | void operator()(tbb::blocked_range2d i_range) const { 58 | ewav::Rand48_Engine r48; 59 | std::normal_distribution gdist{0.0f, 1.0f}; 60 | 61 | const float maxKmag = float(N / 2) * M_TAU / Domain; 62 | 63 | const float dk = float(1) * M_TAU / Domain; 64 | 65 | for (int j = i_range.rows().begin(); j != i_range.rows().end(); ++j) { 66 | // kj is the wave number in the j direction. 67 | int realJ = j <= (N / 2) ? j : j - N; 68 | float kj = float(realJ) * M_TAU / Domain; 69 | 70 | for (int i = i_range.cols().begin(); i != i_range.cols().end(); ++i) { 71 | // ki is the wave number in the i direction 72 | float ki = float(i) * M_TAU / Domain; 73 | 74 | // Magnitude of the wave vector. 75 | float kMag = std::hypot(ki, kj); 76 | 77 | // Index into the array. 78 | std::size_t index = (std::size_t(j) * StrideJ) + i; 79 | 80 | // If the wavenumber is zero, or we're in the outer ring, 81 | // set it to zero. 82 | if ((i == 0 && realJ == 0) || (kMag > maxKmag)) { 83 | Spectral[index] = Cf(0.0, 0.0); 84 | } else { 85 | r48.seed(ewav::SeedFromWavenumber(Imath::V2f(ki, kj), Seed)); 86 | Spectral[index] = dk * dk * Cf(gdist(r48), gdist(r48)); 87 | } 88 | } 89 | } 90 | } 91 | }; 92 | 93 | //-***************************************************************************** 94 | int main(int argc, char* argv[]) { 95 | int powerOfTwo = 12; 96 | ewav::RSpatialField2Df spatial(powerOfTwo); 97 | int N = spatial.width(); 98 | std::cout << "Made " << N << " x " << N << " spatial field." << std::endl; 99 | 100 | ewav::CSpectralField2Df spectral(powerOfTwo); 101 | std::cout << "Made " << N << " x " << N << " spectral field." << std::endl; 102 | 103 | ewav::SpectralToSpatial2Df convert(spectral, spatial); 104 | std::cout << "Made " << N << " x " << N << " converter." << std::endl; 105 | 106 | // Fill spectral 107 | { 108 | RandFillFunctor F; 109 | F.Spectral = spectral.data(); 110 | F.StrideJ = spectral.stride(); 111 | F.N = N; 112 | F.Domain = 1000.0f; 113 | F.Seed = 54321; 114 | 115 | // Rows, then columns. 116 | tbb::blocked_range2d range{0, spectral.height(), 1, 117 | 0, spectral.width(), 512}; 118 | tbb::parallel_for(range, F); 119 | } 120 | std::cout << "Filled spectral array with gaussian random numbers" 121 | << std::endl; 122 | 123 | // Convert. 124 | convert.execute(spectral, spatial); 125 | std::cout << "Converted to spatial." << std::endl 126 | << "Spatial midpoint: " << spatial[N / 2][N / 2] << std::endl; 127 | 128 | return 0; 129 | } -------------------------------------------------------------------------------- /src/Util/Exception.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #ifndef _EncinoWaves_Util_Exception_h_ 18 | #define _EncinoWaves_Util_Exception_h_ 19 | 20 | #include "Foundation.h" 21 | 22 | namespace EncinoWaves { 23 | namespace Util { 24 | 25 | //-***************************************************************************** 26 | //! Base class for all exceptions in the Emld libraries. Derived 27 | //! from both std::exception and std::string, publicly 28 | //! It is mostly commonly thrown using the macros 29 | class Exception : public std::string, public std::exception { 30 | public: 31 | //! default constructor creates exception with 32 | //! empty message string 33 | Exception() throw() 34 | : std::string("") 35 | , std::exception() {} 36 | 37 | //! Creates exception with an explicit message string. 38 | //! ... 39 | explicit Exception(const std::string &str) throw() 40 | : std::string(str) 41 | , std::exception() {} 42 | 43 | //! Copies exception. 44 | //! ... 45 | Exception(const Exception &exc) throw() 46 | : std::string(exc.c_str()) 47 | , std::exception() {} 48 | 49 | //! Destructor is empty, but virtual to support polymorphic 50 | //! destruction of data in any derived classes. 51 | virtual ~Exception() throw() {} 52 | 53 | //! Inherited from std::exception, this returns a non-modifiable 54 | //! character string describing the nature of the exception 55 | virtual const char *what() const throw() { return c_str(); } 56 | }; 57 | 58 | //-***************************************************************************** 59 | // This is for aborting in a debug mode to make a more traceable stack. 60 | 61 | #ifdef PLATFORM_DARWIN 62 | 63 | #if defined __cplusplus 64 | #define __EWAV_DEBUG_ASSERT_VOID_CAST static_cast 65 | #else 66 | #define __EWAV_DEBUG_ASSERT_VOID_CAST (void) 67 | #endif 68 | 69 | #else 70 | 71 | #if defined __cplusplus && __GNUC_PREREQ(2, 95) 72 | #define __EWAV_DEBUG_ASSERT_VOID_CAST static_cast 73 | #else 74 | #define __EWAV_DEBUG_ASSERT_VOID_CAST (void) 75 | #endif 76 | 77 | #endif 78 | 79 | extern void __EWAV_DEBUG_ASSERT_FAIL(const char *msg) throw(); 80 | 81 | //-***************************************************************************** 82 | // This macro will cause an abort. 83 | #define EWAV_FAIL(TEXT) \ 84 | do { \ 85 | std::stringstream sstr; \ 86 | sstr << TEXT; \ 87 | sstr << "\nFile: " << __FILE__ << std::endl \ 88 | << "Line: " << __LINE__ << std::endl; \ 89 | EncinoWaves::Util::__EWAV_DEBUG_ASSERT_FAIL(sstr.str().c_str()); \ 90 | } while (0) 91 | 92 | //-***************************************************************************** 93 | //! convenient macro which may be used with std::iostream syntax 94 | //! EWAV_THROW( "this integer: " << myInt << " is bad" ) 95 | //#ifdef DEBUG 96 | #if 0 97 | 98 | #define EWAV_THROW(TEXT) \ 99 | do { \ 100 | std::cerr << TEXT << std::endl; \ 101 | abort(); \ 102 | } while (0) 103 | 104 | #else 105 | 106 | #define EWAV_THROW(TEXT) \ 107 | do { \ 108 | std::stringstream sstr; \ 109 | sstr << TEXT; \ 110 | sstr << "\nFile: " << __FILE__ << std::endl \ 111 | << "Line: " << __LINE__ << std::endl; \ 112 | EncinoWaves::Util::Exception exc(sstr.str()); \ 113 | throw(exc); \ 114 | } while (0) 115 | 116 | #endif 117 | 118 | //-***************************************************************************** 119 | #ifdef DEBUG 120 | 121 | #define EWAV_ASSERT(COND, TEXT) \ 122 | do { \ 123 | if (!(COND)) { \ 124 | EWAV_FAIL(TEXT); \ 125 | } \ 126 | } while (0) 127 | 128 | #define EWAV_DEBUG_ASSERT(COND, TEXT) \ 129 | do { \ 130 | if (!(COND)) { \ 131 | EWAV_FAIL(TEXT); \ 132 | } \ 133 | } while (0) 134 | 135 | #else 136 | 137 | #define EWAV_ASSERT(COND, TEXT) \ 138 | do { \ 139 | if (!(COND)) { \ 140 | EWAV_THROW(TEXT); \ 141 | } \ 142 | } while (0) 143 | 144 | #define EWAV_DEBUG_ASSERT(COND, TEXT) (__EWAV_DEBUG_ASSERT_VOID_CAST(0)) 145 | 146 | #endif 147 | 148 | } // namespace Util 149 | } // namespace EncinoWaves 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /src/EncinoWaves/Random.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_Random_h_ 36 | #define _EncinoWaves_Random_h_ 37 | 38 | #include "Foundation.h" 39 | #include "Basics.h" 40 | #include "Parameters.h" 41 | 42 | namespace EncinoWaves { 43 | 44 | //-***************************************************************************** 45 | // C++ 11 FOR SURE 46 | //-***************************************************************************** 47 | 48 | typedef std::uint_fast32_t seed_type; 49 | typedef std::minstd_rand Rand48_Engine; 50 | 51 | //-***************************************************************************** 52 | template 53 | uint32_t SeedFromWavenumber(const Imath::Vec2 &i_wavenumber, 54 | uint32_t i_seed) { 55 | static constexpr uint32_t p1 = 73856093; 56 | static constexpr uint32_t p2 = 19349663; 57 | static constexpr uint32_t p3 = 83492791; 58 | 59 | // Truncate the ks to some precision, and then make them 60 | // into seeds. 61 | 62 | return (static_cast(i_wavenumber[0] * 10000) * p1) ^ 63 | (static_cast(i_wavenumber[1] * 10000) * p2) ^ (i_seed * p3); 64 | } 65 | 66 | //-***************************************************************************** 67 | template 68 | class BaseRandom { 69 | protected: 70 | seed_type m_seed; 71 | Rand48_Engine m_engine; 72 | std::uniform_real_distribution m_phaseDist; 73 | 74 | public: 75 | BaseRandom() 76 | : m_seed(0) 77 | , m_engine(seed_type(0)) 78 | , m_phaseDist(T(0.0), TAU) { 79 | this->seed(m_seed); 80 | } 81 | 82 | BaseRandom(const Parameters &i_params) 83 | : m_seed(i_params.random.seed) 84 | , m_engine(m_seed) 85 | , m_phaseDist(T(0.0), TAU) { 86 | this->seed(m_seed); 87 | } 88 | 89 | void seed(seed_type i_seed) { m_engine.seed(i_seed + m_seed); } 90 | 91 | void seed(const Imath::Vec2 &i_wavenumber) { 92 | m_engine.seed(SeedFromWavenumber(i_wavenumber, m_seed)); 93 | } 94 | 95 | T nextPhase() { return m_phaseDist(m_engine); } 96 | }; 97 | 98 | //-***************************************************************************** 99 | // The normal distribution which produces an average value of 0.5 when 100 | // integrated 101 | // from 0 to infinity has a standard deviation of 1.48448 102 | template 103 | class NormalRandom : public BaseRandom { 104 | protected: 105 | std::normal_distribution m_ampDist; 106 | 107 | public: 108 | NormalRandom() 109 | : BaseRandom() 110 | , m_ampDist(T(0.0), T(1.0)) {} 111 | 112 | NormalRandom(const Parameters &i_params) 113 | : BaseRandom(i_params) 114 | , m_ampDist(T(0.0), T(1.0)) {} 115 | 116 | T nextAmp() { return m_ampDist(this->m_engine); } 117 | }; 118 | 119 | //------------------------------------------------------------------------------ 120 | template 121 | class SquaredNormalRandom : public NormalRandom { 122 | public: 123 | SquaredNormalRandom() 124 | : NormalRandom() {} 125 | 126 | SquaredNormalRandom(const Parameters &i_params) 127 | : NormalRandom(i_params) {} 128 | 129 | T nextAmp() { return sqr(NormalRandom::nextAmp()); } 130 | }; 131 | 132 | //-***************************************************************************** 133 | template 134 | class LogNormalRandom : public BaseRandom { 135 | protected: 136 | std::lognormal_distribution m_ampDist; 137 | 138 | public: 139 | LogNormalRandom() 140 | : BaseRandom() 141 | , m_ampDist(T(1.0), T(1.0)) {} 142 | 143 | LogNormalRandom(const Parameters &i_params) 144 | : BaseRandom(i_params) 145 | , m_ampDist(T(1.0), T(1.0)) {} 146 | 147 | T nextAmp() { return m_ampDist(this->m_engine); } 148 | }; 149 | 150 | } // namespace EncinoWaves 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /src/EncinoWaves/Parameters.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_Parameters_h_ 36 | #define _EncinoWaves_Parameters_h_ 37 | 38 | #include "Foundation.h" 39 | #include "Basics.h" 40 | 41 | namespace EncinoWaves { 42 | 43 | enum DispersionType { 44 | kDeepDispersion, 45 | kFiniteDepthDispersion, 46 | kCapillaryDispersion 47 | }; 48 | 49 | enum SpectrumType { 50 | kPiersonMoskowitzSpectrum, 51 | kJONSWAPSpectrum, 52 | kTMASpectrum, 53 | 54 | kNumSpectrumTypes 55 | }; 56 | 57 | enum DirectionalSpreadingType { 58 | kPosCosThetaSqrDirectionalSpreading, 59 | kMitsuyasuDirectionalSpreading, 60 | kHasselmannDirectionalSpreading, 61 | kDonelanBannerDirectionalSpreading, 62 | }; 63 | 64 | enum FilterType { 65 | kNullFilter, 66 | kSmoothInvertibleBandPassFilter, 67 | }; 68 | 69 | enum RandomType { 70 | kNormalRandom, 71 | kLogNormalRandom, 72 | }; 73 | 74 | template 75 | struct Parameters { 76 | // Resolution of the waves. 77 | int resolutionPowerOfTwo; 78 | 79 | // Domain of the waves. - this is the size of the world space 80 | // that they occupy. 81 | T domain; // in meters 82 | 83 | // Some physical parameters. 84 | T gravity; // in meters per second squared. 85 | T surfaceTension; // in Newtons per meter 86 | T density; // in kilograms per meter cubed 87 | T depth; // in meters. 88 | 89 | // Wind stuff. It is assumed that wind travels along the positive 90 | // X axis, since we assume these fields can be externally transformed. 91 | // Wind speed is in meters per second. 92 | T windSpeed; // in meters per second 93 | T fetch; // in KILOMETERS 94 | 95 | T pinch; // lateral displacement 96 | T amplitudeGain; // vertical displacement 97 | 98 | T troughDamping; 99 | T troughDampingSmallWavelength; 100 | T troughDampingBigWavelength; 101 | T troughDampingSoftWidth; 102 | 103 | // Dispersion Stuff - Deep, FiniteDepth, Capillary 104 | struct Dispersion { 105 | DispersionType type; 106 | Dispersion() 107 | : type(kCapillaryDispersion) {} 108 | } dispersion; 109 | 110 | // Spectrum Stuff - Phillips, Pierson-Moskowitz, JONSWAP, TMA 111 | struct Spectrum { 112 | SpectrumType type; 113 | Spectrum() 114 | : type(kTMASpectrum) {} 115 | } spectrum; 116 | 117 | // Directional Spreading Stuff 118 | struct DirectionalSpreading { 119 | DirectionalSpreadingType type; 120 | T swell; 121 | DirectionalSpreading() 122 | : type(kHasselmannDirectionalSpreading) 123 | , swell(0.0) {} 124 | } directionalSpreading; 125 | 126 | // Filter 127 | struct Filter { 128 | FilterType type; 129 | T softWidth; 130 | T smallWavelength; 131 | T bigWavelength; 132 | T min; 133 | bool invert; 134 | Filter() 135 | : type(kNullFilter) 136 | , softWidth(0.0) 137 | , smallWavelength(0.0) 138 | , bigWavelength(1000000.0) 139 | , min(0.0) 140 | , invert(false) {} 141 | } filter; 142 | 143 | // Random Stuff 144 | struct Random { 145 | RandomType type; 146 | int seed; 147 | Random() 148 | : type(kNormalRandom) 149 | , seed(54321) {} 150 | } random; 151 | 152 | // Constructor 153 | Parameters() 154 | : resolutionPowerOfTwo(9) 155 | , domain(100.0) 156 | , gravity(9.81) 157 | , surfaceTension(0.074) 158 | , density(1000.0) 159 | , depth(100.0) 160 | , windSpeed(17.0) 161 | , fetch(300.0) 162 | , pinch(0.75) 163 | , amplitudeGain(1.0) 164 | , troughDamping(0.0) 165 | , troughDampingSmallWavelength(1.0) 166 | , troughDampingBigWavelength(4.0) 167 | , troughDampingSoftWidth(2.0) {} 168 | 169 | int resolution() const { return 1 << resolutionPowerOfTwo; } 170 | }; 171 | 172 | //-***************************************************************************** 173 | typedef Parameters Parametersf; 174 | typedef Parameters Parametersd; 175 | 176 | } // namespace EncinoWaves 177 | 178 | #endif 179 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/OceanTestSky.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #include "OceanTestSky.h" 36 | 37 | namespace OceanTest { 38 | 39 | using namespace GeepGLFW; 40 | 41 | //-***************************************************************************** 42 | //-***************************************************************************** 43 | // This rendering code is an implementation of the paper, 44 | // "A Practical Analytic Model for Daylight" 45 | // Preetham, Shirley, Smits, 1999 46 | //-***************************************************************************** 47 | //-***************************************************************************** 48 | 49 | //-***************************************************************************** 50 | static void DistributionCoefficients(double T, V3d &A, V3d &B, V3d &C, V3d &D, 51 | V3d &E) { 52 | A = V3d(-0.0193 * T - 0.2592, -0.0167 * T - 0.2608, 0.1787 * T - 1.4630); 53 | 54 | B = V3d(-0.0665 * T - 0.0008, -0.0950 * T + 0.0092, -0.3554 * T + 0.4275); 55 | 56 | C = V3d(-0.0004 * T + 0.2125, -0.0079 * T + 0.2102, -0.0227 * T + 5.3251); 57 | 58 | D = V3d(-0.0641 * T - 0.8989, -0.0441 * T - 1.6537, 0.1206 * T - 2.5771); 59 | 60 | E = V3d(-0.0033 * T + 0.0452, -0.0109 * T + 0.0529, -0.0670 * T + 0.3703); 61 | } 62 | 63 | //-***************************************************************************** 64 | static V3d Zenith_xyY(double T, double thetaS) { 65 | V3d xyY; 66 | 67 | double chi = ((4.0 / 9.0) - (T / 120.0)) * (M_PI - 2.0 * thetaS); 68 | 69 | xyY[2] = ((4.0453 * T) - 4.9710) * tan(chi) - (0.2155 * T) + 2.4192; 70 | 71 | double T2 = T * T; 72 | V3d T2T1(T2, T, 1.0); 73 | double S1 = thetaS; 74 | double S2 = S1 * S1; 75 | double S3 = S1 * S1 * S1; 76 | 77 | V3d zenx((0.00166 * S3) + (-0.00375 * S2) + (0.00209 * S1) + (0.0), 78 | 79 | (-0.02903 * S3) + (0.06377 * S2) + (-0.03202 * S1) + (0.00394), 80 | 81 | (0.11693 * S3) + (-0.21196 * S2) + (0.06052 * S1) + (0.25886)); 82 | 83 | xyY[0] = T2T1.dot(zenx); 84 | 85 | V3d zeny((0.00275 * S3) + (-0.00610 * S2) + (0.00317 * S1) + (0.0), 86 | 87 | (-0.04214 * S3) + (0.08970 * S2) + (-0.04153 * S1) + (0.00516), 88 | 89 | (0.15346 * S3) + (-0.26756 * S2) + (0.06670 * S1) + (0.26688)); 90 | 91 | xyY[1] = T2T1.dot(zeny); 92 | 93 | return xyY; 94 | } 95 | 96 | //-***************************************************************************** 97 | // Computing sun phi & theta from 98 | static void CalcSunPosition(double pTime, double pDay, double pLat, 99 | double pLong, double GMT_offset, 100 | 101 | double &o_phi, double &o_theta) { 102 | double latRad = radians(pLat); 103 | double longRad = radians(pLong); 104 | 105 | double solarTime = pTime + +0.170 * sin(4.0 * M_PI * (pDay - 80.0) / 373.0) - 106 | 0.129 * sin(2.0 * M_PI * (pDay - 8.0) / 355.0) + 107 | 12.0 * (((GMT_offset / 12.0) * M_PI) - longRad) / M_PI; 108 | 109 | double solarDeclination = 0.4093 * sin(2.0 * M_PI * (pDay - 81.0) / 368.0); 110 | 111 | double sinL = std::sin(latRad); 112 | double cosL = std::cos(latRad); 113 | 114 | double sinD = std::sin(solarDeclination); 115 | double cosD = std::cos(solarDeclination); 116 | 117 | double solarTimeRad = M_PI * solarTime / 12.0; 118 | double sinSTR = std::sin(solarTimeRad); 119 | double cosSTR = std::cos(solarTimeRad); 120 | 121 | o_theta = M_PI_2 - std::asin((sinL * sinD) - (cosL * cosD * cosSTR)); 122 | o_phi = std::atan2(-(cosD * sinSTR), (cosL * sinD) - (sinL * cosD * cosSTR)); 123 | } 124 | 125 | //-***************************************************************************** 126 | void Sky::setUniforms(Program &i_program) const { 127 | double d_phi; 128 | double d_theta; 129 | CalcSunPosition(m_params.time, m_params.day, m_params.latitude, 130 | m_params.longitude, m_params.GMT_offset, d_phi, d_theta); 131 | // std::cout << "Sun phi & theta: " << d_phi << ", " << d_theta << std::endl; 132 | 133 | double TURB = 1.7 + std::max(m_params.turbidity, 0.0); 134 | 135 | V3d zenith = Zenith_xyY(TURB, d_theta); 136 | 137 | V3d d_A, d_B, d_C, d_D, d_E; 138 | DistributionCoefficients(TURB, d_A, d_B, d_C, d_D, d_E); 139 | 140 | i_program(Uniform("g_ThetaSun", (float)d_theta)); 141 | i_program(Uniform("g_PhiSun", (float)d_phi)); 142 | i_program(Uniform("g_Zenith", zenith)); 143 | i_program(Uniform("g_A", d_A)); 144 | i_program(Uniform("g_B", d_B)); 145 | i_program(Uniform("g_C", d_C)); 146 | i_program(Uniform("g_D", d_D)); 147 | i_program(Uniform("g_E", d_E)); 148 | } 149 | 150 | } // namespace OceanTest 151 | -------------------------------------------------------------------------------- /src/EncinoWaves/Spectra.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_Spectra_h_ 36 | #define _EncinoWaves_Spectra_h_ 37 | 38 | #include "Foundation.h" 39 | #include "Parameters.h" 40 | #include "Basics.h" 41 | #include "Random.h" 42 | 43 | namespace EncinoWaves { 44 | 45 | //-***************************************************************************** 46 | // The spectra all have an equation of this form in them. 47 | // A, B, and g are constants. w is omega, and wm is the peak omega, 48 | // which is calculated differently for different spectra. 49 | template 50 | T AlphaBetaSpectrum(T A, T B, T g, T w, T wm) { 51 | return (A * sqr(g) / std::pow(w, T(5.0))) * 52 | std::exp(-B * std::pow(wm / w, T(4.0))); 53 | } 54 | 55 | //-***************************************************************************** 56 | // The Pierson Moskowitz spectrum is just an AlphaBetaSpectrum, 57 | // with A = 8.10e-3, B = 0.74 / 0.87^4 = 1.291, g = gravity, 58 | // and peakOmega is 0.87 * gravity / windSpeed. 59 | template 60 | class PiersonMoskowitzSpectrum { 61 | protected: 62 | T m_gravity = 9.81; 63 | T m_windSpeed = 20; 64 | T m_peakOmega = 0.87 * 9.81 / 20; 65 | 66 | public: 67 | PiersonMoskowitzSpectrum() = default; 68 | 69 | explicit PiersonMoskowitzSpectrum(const Parameters& i_params) 70 | : m_gravity(i_params.gravity) 71 | , m_windSpeed(i_params.windSpeed) 72 | , m_peakOmega(0.87 * m_gravity / m_windSpeed) {} 73 | 74 | T operator()(T i_omega) const { 75 | return AlphaBetaSpectrum(T(8.1e-3), T(1.291), m_gravity, i_omega, 76 | m_peakOmega); 77 | } 78 | }; 79 | 80 | //-***************************************************************************** 81 | // The JONSWAP spectrum introduces the fetch parameter. It is an 82 | // AlphaBeta spectrum times a peak sharpening function. The peak sharpening 83 | // coefficient, gamma, is chosen as a random draw. 84 | // alpha = 0.076 * pow( xbar, -0.22 ) 85 | // sigma = 0.07 for w < wm, 0.09 for w > wm 86 | // wm = TAU * 3.5 * ( g / U ) * pow( xbar, -0.33 ) 87 | // xbar = g F / U^2 88 | // F = fetch 89 | // U = wind speed 90 | // g = gravity 91 | // y = gaussian( mean=3.30, variance=0.62 ), clamped from 1 to 6 92 | // peakSharpening = pow( y, exp( -(w-wm)^2/2(sigma wm)^2 ) 93 | // beta = 1.25 94 | template 95 | class JONSWAPSpectrum { 96 | protected: 97 | T m_gravity; 98 | T m_windSpeed; 99 | T m_fetch; 100 | T m_gamma; 101 | 102 | T m_peakOmega; 103 | T m_dimensionlessFetch; 104 | T m_alpha; 105 | 106 | void init(T g, T U, T fkm, T y) { 107 | m_gravity = g; 108 | m_windSpeed = U; 109 | m_fetch = fkm * 1000.0; 110 | m_gamma = y; 111 | 112 | m_dimensionlessFetch = std::abs(m_gravity * m_fetch / sqr(m_windSpeed)); 113 | m_alpha = 0.076 * std::pow(m_dimensionlessFetch, T(-0.22)); 114 | m_peakOmega = M_TAU * 3.5 * std::abs(m_gravity / m_windSpeed) * 115 | std::pow(m_dimensionlessFetch, T(-0.33)); 116 | } 117 | 118 | public: 119 | JONSWAPSpectrum() { init(9.81, 10.0, 100.0, 3.30); } 120 | 121 | explicit JONSWAPSpectrum(const Parameters& i_params) { 122 | Rand48_Engine r48; 123 | std::normal_distribution norm{T(3.30), std::sqrt(T(0.67))}; 124 | r48.seed(i_params.random.seed + 191819); 125 | T gamma = Imath::clamp(norm(r48), T(1.0), T(6.0)); 126 | // gamma = T( 3.30 ); 127 | 128 | init(i_params.gravity, i_params.windSpeed, i_params.fetch, gamma); 129 | } 130 | 131 | T peakSharpening(T i_omega) const { 132 | const T sigma = (i_omega <= m_peakOmega) ? T(0.07) : T(0.09); 133 | return std::pow( 134 | m_gamma, 135 | std::exp(-sqr((i_omega - m_peakOmega) / (sigma * m_peakOmega)) / T(2.0))); 136 | } 137 | 138 | T operator()(T i_omega) const { 139 | return peakSharpening(i_omega) * AlphaBetaSpectrum(m_alpha, T(1.25), 140 | m_gravity, i_omega, 141 | m_peakOmega); 142 | } 143 | }; 144 | 145 | //-***************************************************************************** 146 | template 147 | class TMASpectrum { 148 | protected: 149 | JONSWAPSpectrum m_jonswap; 150 | T m_depth; 151 | T m_kdGain; 152 | 153 | void init(T h, T g) { 154 | m_depth = h; 155 | m_kdGain = std::sqrt(m_depth / g); 156 | } 157 | 158 | public: 159 | TMASpectrum() 160 | : m_jonswap() { 161 | init(100.0, 9.81); 162 | } 163 | 164 | explicit TMASpectrum(const Parameters& i_params) 165 | : m_jonswap(i_params) { 166 | init(i_params.depth, i_params.gravity); 167 | } 168 | 169 | T kitaigorodskiiDepth(T i_omega) const { 170 | const T wh = i_omega * m_kdGain; 171 | return T(0.5) + (T(0.5) * std::tanh(T(1.8) * (wh - T(1.125)))); 172 | } 173 | 174 | T operator()(T i_omega) const { 175 | return kitaigorodskiiDepth(i_omega) * m_jonswap(i_omega); 176 | } 177 | }; 178 | 179 | } // namespace EncinoWaves 180 | 181 | #endif 182 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/Tests/test_SimplePointsSim.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright (c) 2001-2013, Christopher Jon Horvath. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of Christopher Jon Horvath nor the names of his 15 | // contributors may be used to endorse or promote products derived from this 16 | // software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | // POSSIBILITY OF SUCH DAMAGE. 29 | //-***************************************************************************** 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | using namespace EncinoWaves::SimpleSimViewer; 36 | using namespace EncinoWaves::Util; 37 | 38 | //-***************************************************************************** 39 | class SimplePointsSim : public Sim3D { 40 | protected: 41 | void setTime(double i_time) { 42 | m_time = i_time; 43 | m_angleOfRotation = m_time * m_rotationRate; 44 | m_objectToWorld.setAxisAngle(m_axisOfRotation, m_angleOfRotation); 45 | m_worldSpaceBounds = Imath::transform(m_objectSpaceBounds, m_objectToWorld); 46 | } 47 | 48 | virtual void init(int w, int h) override { 49 | Sim3D::init(w, h); 50 | 51 | m_pointsDrawHelper.reset(new PointsDrawHelper(false, m_vtxPosData.size(), 52 | m_vtxPosData.data(), 53 | m_vtxNormData.data(), 54 | // NULL, 55 | NULL, NULL)); 56 | 57 | Program::Bindings vtxBindings; 58 | vtxBindings.push_back( 59 | Program::Binding(m_pointsDrawHelper->posVboIdx(), "g_Pobj")); 60 | vtxBindings.push_back( 61 | Program::Binding(m_pointsDrawHelper->normVboIdx(), "g_Nobj")); 62 | 63 | Program::Bindings frgBindings; 64 | frgBindings.push_back(Program::Binding(0, "g_fragmentColor")); 65 | 66 | m_program.reset(new Program( 67 | "SimplePointsDraw", SimpleVertexShader(), SimplePointsGeometryShader(), 68 | KeyFillFragmentShader(), 69 | // ConstantRedFragmentShader(), 70 | vtxBindings, frgBindings, m_pointsDrawHelper->vertexArrayObject())); 71 | 72 | // Sun, moon. 73 | float sunAltitude = radians(45.0f); 74 | float sunAzimuth = radians(35.0f); 75 | V3f toSun(cosf(sunAltitude) * cosf(sunAzimuth), 76 | cosf(sunAltitude) * sinf(sunAzimuth), sinf(sunAltitude)); 77 | V3f sunColor(1.0f, 1.0f, 1.0f); 78 | 79 | float moonAltitude = radians(65.0f); 80 | float moonAzimuth = sunAzimuth - radians(180.0f); 81 | V3f toMoon(cosf(moonAltitude) * cosf(moonAzimuth), 82 | cosf(moonAltitude) * sinf(moonAzimuth), sinf(moonAltitude)); 83 | V3f moonColor(0.1f, 0.1f, 0.3f); 84 | 85 | SetKeyFillLights(*m_program, toSun, sunColor, toMoon, moonColor); 86 | 87 | // Materials. 88 | SetStdMaterial(*m_program, V3f(0.18f), V3f(0.1f), 25.0f); 89 | } 90 | 91 | public: 92 | SimplePointsSim() 93 | : Sim3D() 94 | , m_axisOfRotation(0.0, 0.0, 1.0) 95 | , m_angleOfRotation(0.0) 96 | , m_rotationRate(0.75) 97 | , m_time(0.0) { 98 | V3d c000(-0.5, -0.5, -0.5); 99 | V3d c100(0.5, -0.5, -0.5); 100 | V3d c010(-0.5, 0.5, -0.5); 101 | V3d c110(0.5, 0.5, -0.5); 102 | V3d c001(-0.5, -0.5, 0.5); 103 | V3d c101(0.5, -0.5, 0.5); 104 | V3d c011(-0.5, 0.5, 0.5); 105 | V3d c111(0.5, 0.5, 0.5); 106 | 107 | m_vtxPosData.push_back(c000); 108 | m_vtxNormData.push_back(c000.normalized()); 109 | 110 | m_vtxPosData.push_back(c100); 111 | m_vtxNormData.push_back(c100.normalized()); 112 | 113 | m_vtxPosData.push_back(c010); 114 | m_vtxNormData.push_back(c010.normalized()); 115 | 116 | m_vtxPosData.push_back(c110); 117 | m_vtxNormData.push_back(c110.normalized()); 118 | 119 | m_vtxPosData.push_back(c001); 120 | m_vtxNormData.push_back(c001.normalized()); 121 | 122 | m_vtxPosData.push_back(c101); 123 | m_vtxNormData.push_back(c101.normalized()); 124 | 125 | m_vtxPosData.push_back(c011); 126 | m_vtxNormData.push_back(c011.normalized()); 127 | 128 | m_vtxPosData.push_back(c111); 129 | m_vtxNormData.push_back(c111.normalized()); 130 | 131 | m_objectSpaceBounds.min = c000; 132 | m_objectSpaceBounds.max = c111; 133 | 134 | setTime(m_time); 135 | } 136 | 137 | virtual std::string getName() const override { return "SimplePointsSim"; } 138 | 139 | virtual void step() override { setTime(m_time + (1.0 / 24.0)); } 140 | 141 | virtual Box3d getBounds() const override { return m_worldSpaceBounds; } 142 | 143 | //! This draws, assuming a camera matrix has already been set. 144 | //! ... 145 | virtual void draw() override { 146 | glEnable(GL_PROGRAM_POINT_SIZE); 147 | 148 | SetStdMatrices(*m_program, m_camera, m_objectToWorld); 149 | m_program->use(); 150 | 151 | (*m_program)(Uniform("g_pointSize", (float)25.0, 152 | (Uniform::Requirement)Uniform::kRequireOptional)); 153 | m_program->setUniforms(); 154 | 155 | m_pointsDrawHelper->draw(m_camera); 156 | m_program->unuse(); 157 | } 158 | 159 | protected: 160 | std::vector m_vtxPosData; 161 | std::vector m_vtxNormData; 162 | M44d m_objectToWorld; 163 | V3d m_axisOfRotation; 164 | double m_angleOfRotation; 165 | double m_rotationRate; 166 | double m_time; 167 | Box3d m_objectSpaceBounds; 168 | Box3d m_worldSpaceBounds; 169 | 170 | std::unique_ptr m_pointsDrawHelper; 171 | std::unique_ptr m_program; 172 | }; 173 | 174 | //-***************************************************************************** 175 | int main(int argc, char* argv[]) { 176 | std::shared_ptr sptr(new SimplePointsSim); 177 | SimpleViewSim(sptr, true); 178 | return 0; 179 | } 180 | -------------------------------------------------------------------------------- /src/EncinoWaves/Exception.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_Exception_h_ 36 | #define _EncinoWaves_Exception_h_ 37 | 38 | #include "Foundation.h" 39 | 40 | namespace EncinoWaves { 41 | 42 | //-***************************************************************************** 43 | //! Base class for all exceptions in the Emerald libraries. Derived 44 | //! from both std::exception and std::string, publicly 45 | //! It is mostly commonly thrown using the macros 46 | class Exception : public std::string, public std::exception { 47 | public: 48 | //! default constructor creates exception with 49 | //! empty message string 50 | Exception() throw() 51 | : std::string("") 52 | , std::exception() {} 53 | 54 | //! Creates exception with an explicit message string. 55 | //! ... 56 | explicit Exception(const std::string &str) throw() 57 | : std::string(str) 58 | , std::exception() {} 59 | 60 | //! Copies exception. 61 | //! ... 62 | Exception(const Exception &exc) throw() 63 | : std::string(exc.c_str()) 64 | , std::exception() {} 65 | 66 | //! Destructor is empty, but virtual to support polymorphic 67 | //! destruction of data in any derived classes. 68 | virtual ~Exception() throw() {} 69 | 70 | //! Inherited from std::exception, this returns a non-modifiable 71 | //! character string describing the nature of the exception 72 | virtual const char *what() const throw() { return c_str(); } 73 | }; 74 | 75 | //-***************************************************************************** 76 | // This is for aborting in a debug mode to make a more traceable stack. 77 | 78 | #ifdef PLATFORM_DARWIN 79 | 80 | #if defined __cplusplus 81 | #define __EWAV_DEBUG_ASSERT_VOID_CAST static_cast 82 | #else 83 | #define __EWAV_DEBUG_ASSERT_VOID_CAST (void) 84 | #endif 85 | 86 | #else 87 | 88 | #if defined __cplusplus && __GNUC_PREREQ(2, 95) 89 | #define __EWAV_DEBUG_ASSERT_VOID_CAST static_cast 90 | #else 91 | #define __EWAV_DEBUG_ASSERT_VOID_CAST (void) 92 | #endif 93 | 94 | #endif 95 | 96 | extern void __EWAV_DEBUG_ASSERT_FAIL(const char *msg) throw(); 97 | 98 | //-***************************************************************************** 99 | // This macro will cause an abort. 100 | #define EWAV_FAIL(TEXT) \ 101 | do { \ 102 | std::stringstream sstr; \ 103 | sstr << TEXT; \ 104 | sstr << "\nFile: " << __FILE__ << std::endl \ 105 | << "Line: " << __LINE__ << std::endl; \ 106 | EncinoWaves::__EWAV_DEBUG_ASSERT_FAIL(sstr.str().c_str()); \ 107 | } while (0) 108 | 109 | //-***************************************************************************** 110 | //! convenient macro which may be used with std::iostream syntax 111 | //! EWAV_THROW( "this integer: " << myInt << " is bad" ) 112 | //#ifdef DEBUG 113 | #if 0 114 | 115 | #define EWAV_THROW(TEXT) \ 116 | do { \ 117 | std::cerr << TEXT << std::endl; \ 118 | abort(); \ 119 | } while (0) 120 | 121 | #else 122 | 123 | #define EWAV_THROW(TEXT) \ 124 | do { \ 125 | std::stringstream sstr; \ 126 | sstr << TEXT; \ 127 | sstr << "\nFile: " << __FILE__ << std::endl \ 128 | << "Line: " << __LINE__ << std::endl; \ 129 | EncinoWaves::Exception exc(sstr.str()); \ 130 | throw(exc); \ 131 | } while (0) 132 | 133 | #endif 134 | 135 | //-***************************************************************************** 136 | #define EWAV_ASSERT(COND, TEXT) \ 137 | do { \ 138 | if (!(COND)) { \ 139 | std::stringstream sstr; \ 140 | sstr << TEXT; \ 141 | sstr << "\nFile: " << __FILE__ << std::endl \ 142 | << "Line: " << __LINE__ << std::endl; \ 143 | EncinoWaves::Exception exc(sstr.str()); \ 144 | throw(exc); \ 145 | } \ 146 | } while (0) 147 | 148 | //-***************************************************************************** 149 | #ifdef DEBUG 150 | 151 | #define EWAV_ASSERT(COND, TEXT) \ 152 | do { \ 153 | if (!(COND)) { \ 154 | EWAV_FAIL(TEXT); \ 155 | } \ 156 | } while (0) 157 | 158 | #define EWAV_DEBUG_ASSERT(COND, TEXT) \ 159 | do { \ 160 | if (!(COND)) { \ 161 | EWAV_FAIL(TEXT); \ 162 | } \ 163 | } while (0) 164 | 165 | #else 166 | 167 | #define EWAV_ASSERT(COND, TEXT) \ 168 | do { \ 169 | if (!(COND)) { \ 170 | EWAV_THROW(TEXT); \ 171 | } \ 172 | } while (0) 173 | 174 | #define EWAV_DEBUG_ASSERT(COND, TEXT) (__EWAV_DEBUG_ASSERT_VOID_CAST(0)) 175 | 176 | #endif 177 | 178 | } // namespace EncinoWaves 179 | 180 | #endif 181 | -------------------------------------------------------------------------------- /src/EncinoWaves/Dispersion.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_Dispersion_h_ 36 | #define _EncinoWaves_Dispersion_h_ 37 | 38 | #include "Foundation.h" 39 | #include "Basics.h" 40 | #include "Parameters.h" 41 | 42 | namespace EncinoWaves { 43 | 44 | //-***************************************************************************** 45 | //-***************************************************************************** 46 | // DISPERSION 47 | // https://en.wikipedia.org/wiki/Dispersion_(water_waves) 48 | // The dispersion relationship relates the angular frequency of waves 49 | // to their wavelengths, based on gravity, and ocean depth, and other physical 50 | // parameters. These are all statistical approximations, and there are 51 | // a ton of them. (Look at the bottom of the wikipedia page) 52 | // 53 | // For some simpler discussion, I referenced: 54 | // http://www.atm.ox.ac.uk/user/read/fluids/fluidsnotes5.pdf 55 | // 56 | // A simple deep water dispersion relationship, in which ocean depth is vastly 57 | // larger than considered wavelengths, is: 58 | // omega^2 = g * k // g = gravity 59 | // dOmega_dk = g / 2 sqrt( g * k ) = g / ( 2 omega ) 60 | // 61 | // A finite-depth water dispersion relationship is: 62 | // omega^2 = g * k * tanh( k * h ) // g = gravity, h = depth 63 | // dOmega_dk = g ( tanh( h k ) + h k sech^2( h k ) ) / 2 sqrt( g k tanh( h k ) ) 64 | // dOmega_dk = g ( tanh( h k ) + h k sech^2( h k ) ) / ( 2 omega ) 65 | // 66 | // A capillary-wave dispersion relationship is: 67 | // omega^2 = ( g*k + (sigma/rho)k^3 ) tanh( k * h ) 68 | // // g = gravity, h = depth, sigma = surface tension, rho = fluid density 69 | // // default sigma = 0.074 N/m, rho = 1000 kg/m^3 70 | // dOmega_dk = ( g + 3 k^2 s )tanh( h k ) + h k ( g + k^2 s )sech^2( h k ) 71 | // / ( 2 omega ) 72 | // 73 | // There are others, but they get kinda crazy. We can always come back to 74 | // these. 75 | // 76 | // Note that they're always written in terms of omega^2, which means there 77 | // are two solutions: omega & -omega. We'll return the positive one. 78 | // 79 | // Note that the capillary formulation given here will turn into 80 | // the finite depth dispersion, for big waves, and the finite depth dispersion 81 | // will turn into the deep dispersion, for deep water. So you can just 82 | // use the capillary dispersion all the time. 83 | //-***************************************************************************** 84 | //-***************************************************************************** 85 | 86 | //-***************************************************************************** 87 | template 88 | class DeepDispersion { 89 | protected: 90 | T m_gravity; 91 | 92 | public: 93 | DeepDispersion() 94 | : m_gravity(9.81) {} 95 | 96 | explicit DeepDispersion(const Parameters& i_params) 97 | : m_gravity(i_params.gravity) {} 98 | 99 | T operator()(T i_k) const { return std::sqrt(std::abs(m_gravity * i_k)); } 100 | 101 | void operator()(T i_k, T& o_omega, T& o_dOmegaDk) const { 102 | o_omega = std::sqrt(std::abs(m_gravity * i_k)); 103 | o_dOmegaDk = m_gravity / (T(2.0) * o_omega); 104 | } 105 | }; 106 | 107 | //-***************************************************************************** 108 | template 109 | class FiniteDepthDispersion : public DeepDispersion { 110 | protected: 111 | T m_depth; 112 | 113 | public: 114 | FiniteDepthDispersion() 115 | : DeepDispersion() 116 | , m_depth(1000.0) {} 117 | 118 | explicit FiniteDepthDispersion(const Parameters& i_params) 119 | : DeepDispersion(i_params) 120 | , m_depth(i_params.depth) {} 121 | 122 | T operator()(T i_k) const { 123 | return std::sqrt( 124 | std::abs(this->m_gravity * i_k * std::tanh(i_k * m_depth))); 125 | } 126 | 127 | void operator()(T i_k, T& o_omega, T& o_dOmegaDk) const { 128 | const T hk = i_k * m_depth; 129 | o_omega = std::sqrt(std::abs(this->m_gravity * i_k * std::tanh(hk))); 130 | 131 | o_dOmegaDk = (this->m_gravity * (std::tanh(hk) + hk / sqr(std::cosh(hk)))) / 132 | (T(2.0) * o_omega); 133 | } 134 | }; 135 | 136 | //-***************************************************************************** 137 | template 138 | class CapillaryDispersion : public FiniteDepthDispersion { 139 | protected: 140 | T m_sigmaOverRho; 141 | 142 | public: 143 | CapillaryDispersion() 144 | : FiniteDepthDispersion() 145 | , m_sigmaOverRho(0.074 / 1000.0) {} 146 | 147 | explicit CapillaryDispersion(const Parameters& i_params) 148 | : FiniteDepthDispersion(i_params) 149 | , m_sigmaOverRho(i_params.surfaceTension / i_params.density) {} 150 | 151 | T operator()(T i_k) const { 152 | return std::sqrt( 153 | std::abs(((this->m_gravity * i_k) + (m_sigmaOverRho * cube(i_k))) * 154 | std::tanh(this->m_depth * i_k))); 155 | } 156 | 157 | void operator()(T i_k, T& o_omega, T& o_dOmegaDk) const { 158 | const T hk = this->m_depth * i_k; 159 | const T k2s = sqr(i_k) * m_sigmaOverRho; 160 | const T gpk2s = this->m_gravity + k2s; 161 | 162 | o_omega = std::sqrt(std::abs(i_k * gpk2s * std::tanh(hk))); 163 | 164 | const T numer = 165 | ((gpk2s + k2s + k2s) * std::tanh(hk)) + (hk * gpk2s / sqr(std::cosh(hk))); 166 | 167 | o_dOmegaDk = std::abs(numer) / (T(2.0) * o_omega); 168 | } 169 | }; 170 | 171 | } // namespace EncinoWaves 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /src/EncinoWaves/Tests/OceanTestTextureSky.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #include "OceanTestTextureSky.h" 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | namespace OceanTest { 44 | 45 | using namespace Imf; 46 | using namespace Imath; 47 | 48 | static void readRgba1(const std::string& filename, Array2D& pixels, 49 | int& width, int& height) { 50 | RgbaInputFile file{filename.c_str()}; 51 | Box2i dw = file.dataWindow(); 52 | width = dw.max.x - dw.min.x + 1; 53 | height = dw.max.y - dw.min.y + 1; 54 | pixels.resizeErase(height, width); 55 | file.setFrameBuffer(&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width); 56 | file.readPixels(dw.min.y, dw.max.y); 57 | } 58 | 59 | TextureSky::TextureSky(const std::string& filename) { 60 | int width = 0; 61 | int height = 0; 62 | Array2D pixels; 63 | readRgba1(filename, pixels, width, height); 64 | std::cout << "Loaded texture sky: " << filename << std::endl; 65 | 66 | float gain = 2.0f; 67 | float exponent = 1.0f; 68 | auto brighten = [gain, exponent](Rgba& rgba) { 69 | rgba.r = std::pow(float(rgba.r), exponent) * gain; 70 | rgba.g = std::pow(float(rgba.g), exponent) * gain; 71 | rgba.b = std::pow(float(rgba.b), exponent) * gain; 72 | }; 73 | 74 | for (int y = 0, y2 = height - 1; y < y2; ++y, --y2) { 75 | for (int x = 0; x < width; ++x) { 76 | std::swap(pixels[y][x], pixels[y2][x]); 77 | brighten(pixels[y][x]); 78 | brighten(pixels[y2][x]); 79 | } 80 | } 81 | 82 | auto luminance = [](const Rgba& rgba) -> float { 83 | return (0.2126f * rgba.r) + (0.7152f * rgba.g) + (0.0722f * rgba.b); 84 | }; 85 | 86 | // find brightest pixel in image 87 | int brightest_x = -1; 88 | int brightest_y = -1; 89 | float brightest_luminance = std::numeric_limits::lowest(); 90 | auto brightest = std::tie(brightest_x, brightest_y, brightest_luminance); 91 | for (int y = 0; y < height; ++y) { 92 | for (int x = 0; x < width; ++x) { 93 | float lum = luminance(pixels[y][x]); 94 | if (lum > std::get<2>(brightest)) { 95 | std::get<0>(brightest) = x; 96 | std::get<1>(brightest) = y; 97 | std::get<2>(brightest) = lum; 98 | } 99 | } 100 | } 101 | std::cout << "Brightest x, y: " << brightest_x << ", " << brightest_y 102 | << std::endl; 103 | float brightest_theta = 104 | lerp(-M_PI, M_PI, (0.5f + static_cast(brightest_x)) / 105 | static_cast(width)); 106 | float brightest_phi = 107 | lerp(-M_PI_2, M_PI_2, (0.5f + static_cast(brightest_y)) / 108 | static_cast(height)); 109 | float cos_theta = std::cos(brightest_theta); 110 | float sin_theta = std::sin(brightest_theta); 111 | float cos_phi = std::cos(brightest_phi); 112 | float sin_phi = std::sin(brightest_phi); 113 | m_to_sun = V3f{cos_phi * cos_theta, cos_phi * sin_theta, sin_phi}; 114 | auto sun_rgba = pixels[brightest_y][brightest_x]; 115 | m_sun_color = 116 | V3f{static_cast(sun_rgba.r), static_cast(sun_rgba.g), 117 | static_cast(sun_rgba.b)}; 118 | m_to_moon = V3f{-m_to_sun.x, -m_to_sun.y, m_to_sun.z}; 119 | auto moon_rgba = pixels[brightest_y][wrap(brightest_x + (width / 2), width)]; 120 | m_moon_color = 121 | V3f{static_cast(moon_rgba.r), static_cast(moon_rgba.g), 122 | static_cast(moon_rgba.b)}; 123 | 124 | // create texture 125 | m_tex_id = 0; 126 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 127 | glGenTextures(1, &m_tex_id); 128 | 129 | // load into texture 130 | glActiveTexture(GL_TEXTURE0); 131 | glBindTexture(GL_TEXTURE_2D, m_tex_id); 132 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 133 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 134 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 135 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 136 | 137 | glTexImage2D(GL_TEXTURE_2D, // target 138 | 0, // level 139 | GL_RGBA16F_ARB, // internalformat 140 | width, // width 141 | height, // height 142 | 0, // border 143 | GL_RGBA, // format 144 | GL_HALF_FLOAT_ARB, reinterpret_cast(pixels[0])); 145 | std::cout << "Created GL Texture from Sky Pixels" << std::endl; 146 | } 147 | 148 | TextureSky::~TextureSky() { 149 | if (m_tex_id > 0) { 150 | glDeleteTextures(1, &m_tex_id); 151 | } 152 | } 153 | 154 | void TextureSky::bind(GLuint program_id) const { 155 | glActiveTexture(GL_TEXTURE0); 156 | glBindTexture(GL_TEXTURE_2D, m_tex_id); 157 | glUniform1i(glGetUniformLocation(program_id, "g_sky_texture"), 0); 158 | glUniform3f(glGetUniformLocation(program_id, "g_to_sun"), m_to_sun.x, 159 | m_to_sun.y, m_to_sun.z); 160 | glUniform3f(glGetUniformLocation(program_id, "g_sun_color"), m_sun_color.x, 161 | m_sun_color.y, m_sun_color.z); 162 | glUniform3f(glGetUniformLocation(program_id, "g_to_moon"), m_to_moon.x, 163 | m_to_moon.y, m_to_moon.z); 164 | glUniform3f(glGetUniformLocation(program_id, "g_moon_color"), m_moon_color.x, 165 | m_moon_color.y, m_moon_color.z); 166 | } 167 | 168 | } // namespace OceanTest -------------------------------------------------------------------------------- /src/SimpleSimViewer/Tests/test_SimpleMeshSim.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright (c) 2001-2013, Christopher Jon Horvath. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of Christopher Jon Horvath nor the names of his 15 | // contributors may be used to endorse or promote products derived from this 16 | // software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | // POSSIBILITY OF SUCH DAMAGE. 29 | //-***************************************************************************** 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | using namespace EncinoWaves::SimpleSimViewer; 36 | using namespace EncinoWaves::Util; 37 | 38 | //-***************************************************************************** 39 | class SimpleMeshSim : public Sim3D { 40 | protected: 41 | void setTime(double i_time) { 42 | m_time = i_time; 43 | m_angleOfRotation = m_time * m_rotationRate; 44 | m_objectToWorld.setAxisAngle(m_axisOfRotation, m_angleOfRotation); 45 | m_worldSpaceBounds = Imath::transform(m_objectSpaceBounds, m_objectToWorld); 46 | } 47 | 48 | void pushBackQuad(const V3f& i_c00, const V3f& i_c10, const V3f& i_c01, 49 | const V3f& i_c11, const V3f& i_n) { 50 | // Pushing back two triangles. 51 | V3ui triA; 52 | 53 | triA[0] = m_vtxPosData.size(); 54 | m_vtxPosData.push_back(i_c00); 55 | m_vtxNormData.push_back(i_n); 56 | 57 | triA[1] = m_vtxPosData.size(); 58 | m_vtxPosData.push_back(i_c10); 59 | m_vtxNormData.push_back(i_n); 60 | 61 | triA[2] = m_vtxPosData.size(); 62 | m_vtxPosData.push_back(i_c01); 63 | m_vtxNormData.push_back(i_n); 64 | 65 | m_triIndices.push_back(triA); 66 | 67 | V3ui triB; 68 | 69 | triB[0] = m_vtxPosData.size(); 70 | m_vtxPosData.push_back(i_c01); 71 | m_vtxNormData.push_back(i_n); 72 | 73 | triB[1] = m_vtxPosData.size(); 74 | m_vtxPosData.push_back(i_c10); 75 | m_vtxNormData.push_back(i_n); 76 | 77 | triB[2] = m_vtxPosData.size(); 78 | m_vtxPosData.push_back(i_c11); 79 | m_vtxNormData.push_back(i_n); 80 | 81 | m_triIndices.push_back(triB); 82 | } 83 | 84 | virtual void init(int w, int h) override { 85 | Sim3D::init(w, h); 86 | 87 | m_meshDrawHelper.reset(new MeshDrawHelper( 88 | MeshDrawHelper::kStaticDeform, m_triIndices.size(), m_vtxPosData.size(), 89 | m_triIndices.data(), m_vtxPosData.data(), m_vtxNormData.data(), 90 | // NULL, 91 | NULL, NULL)); 92 | 93 | Program::Bindings vtxBindings; 94 | vtxBindings.push_back( 95 | Program::Binding(m_meshDrawHelper->posVboIdx(), "g_Pobj")); 96 | vtxBindings.push_back( 97 | Program::Binding(m_meshDrawHelper->normVboIdx(), "g_Nobj")); 98 | 99 | Program::Bindings frgBindings; 100 | frgBindings.push_back(Program::Binding(0, "g_fragmentColor")); 101 | 102 | m_program.reset(new Program( 103 | "SimpleMeshDraw", SimpleVertexShader(), SimpleTrianglesGeometryShader(), 104 | KeyFillFragmentShader(), 105 | // ConstantRedFragmentShader(), 106 | vtxBindings, frgBindings, m_meshDrawHelper->vertexArrayObject())); 107 | 108 | // Sun, moon. 109 | float sunAltitude = radians(45.0f); 110 | float sunAzimuth = radians(35.0f); 111 | V3f toSun(cosf(sunAltitude) * cosf(sunAzimuth), 112 | cosf(sunAltitude) * sinf(sunAzimuth), sinf(sunAltitude)); 113 | V3f sunColor(1.0f, 1.0f, 1.0f); 114 | 115 | float moonAltitude = radians(65.0f); 116 | float moonAzimuth = sunAzimuth - radians(180.0f); 117 | V3f toMoon(cosf(moonAltitude) * cosf(moonAzimuth), 118 | cosf(moonAltitude) * sinf(moonAzimuth), sinf(moonAltitude)); 119 | V3f moonColor(0.1f, 0.1f, 0.3f); 120 | 121 | SetKeyFillLights(*m_program, toSun, sunColor, toMoon, moonColor); 122 | 123 | // Materials. 124 | SetStdMaterial(*m_program, V3f(0.18f), V3f(0.1f), 25.0f); 125 | } 126 | 127 | public: 128 | SimpleMeshSim() 129 | : Sim3D() 130 | , m_axisOfRotation(0.0, 0.0, 1.0) 131 | , m_angleOfRotation(0.0) 132 | , m_rotationRate(0.75) 133 | , m_time(0.0) { 134 | V3d c000(-0.5, -0.5, -0.5); 135 | V3d c100(0.5, -0.5, -0.5); 136 | V3d c010(-0.5, 0.5, -0.5); 137 | V3d c110(0.5, 0.5, -0.5); 138 | V3d c001(-0.5, -0.5, 0.5); 139 | V3d c101(0.5, -0.5, 0.5); 140 | V3d c011(-0.5, 0.5, 0.5); 141 | V3d c111(0.5, 0.5, 0.5); 142 | 143 | V3d nNegX(-1.0, 0.0, 0.0); 144 | V3d nPosX(1.0, 0.0, 0.0); 145 | V3d nNegY(0.0, -1.0, 0.0); 146 | V3d nPosY(0.0, 1.0, 0.0); 147 | V3d nNegZ(0.0, 0.0, -1.0); 148 | V3d nPosZ(0.0, 0.0, 1.0); 149 | 150 | pushBackQuad(c010, c000, c011, c001, nNegX); 151 | pushBackQuad(c100, c110, c101, c111, nPosX); 152 | pushBackQuad(c000, c100, c001, c101, nNegY); 153 | pushBackQuad(c110, c010, c111, c011, nPosY); 154 | pushBackQuad(c100, c000, c110, c010, nNegZ); 155 | pushBackQuad(c001, c101, c011, c111, nPosZ); 156 | 157 | m_objectSpaceBounds.min = c000; 158 | m_objectSpaceBounds.max = c111; 159 | 160 | setTime(m_time); 161 | } 162 | 163 | virtual std::string getName() const override { return "SimpleMeshSim"; } 164 | 165 | virtual void step() override { setTime(m_time + (1.0 / 24.0)); } 166 | 167 | virtual Box3d getBounds() const override { return m_worldSpaceBounds; } 168 | 169 | //! This draws, assuming a camera matrix has already been set. 170 | //! ... 171 | virtual void draw() override { 172 | SetStdMatrices(*m_program, m_camera, m_objectToWorld); 173 | m_program->use(); 174 | m_meshDrawHelper->draw(m_camera); 175 | m_program->unuse(); 176 | } 177 | 178 | protected: 179 | std::vector m_vtxPosData; 180 | std::vector m_vtxNormData; 181 | std::vector m_triIndices; 182 | M44d m_objectToWorld; 183 | V3d m_axisOfRotation; 184 | double m_angleOfRotation; 185 | double m_rotationRate; 186 | double m_time; 187 | Box3d m_objectSpaceBounds; 188 | Box3d m_worldSpaceBounds; 189 | 190 | std::unique_ptr m_meshDrawHelper; 191 | std::unique_ptr m_program; 192 | }; 193 | 194 | //-***************************************************************************** 195 | int main(int argc, char* argv[]) { 196 | std::shared_ptr sptr(new SimpleMeshSim); 197 | SimpleViewSim(sptr, true); 198 | return 0; 199 | } 200 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/PointsDrawHelper.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #include "PointsDrawHelper.h" 18 | 19 | namespace EncinoWaves { 20 | namespace SimpleSimViewer { 21 | 22 | //-***************************************************************************** 23 | PointsDrawHelper::PointsDrawHelper(bool i_dynamic, std::size_t i_numPoints, 24 | const V3f* i_vtxPosData, 25 | const V3f* i_vtxNormData, 26 | const V3f* i_vtxColData, 27 | const V2f* i_vtxUvData) 28 | : m_numPoints(i_numPoints) 29 | , m_vtxPosData(i_vtxPosData) 30 | , m_vtxNormData(i_vtxNormData) 31 | , m_vtxColData(i_vtxColData) 32 | , m_vtxUvData(i_vtxUvData) 33 | , m_vertexArrayObject(0) 34 | , m_posVboIdx(-1) 35 | , m_normVboIdx(-1) 36 | , m_colVboIdx(-1) 37 | , m_uvVboIdx(-1) { 38 | //-************************************************************************* 39 | // OPENGL INIT 40 | //-************************************************************************* 41 | UtilGL::CheckErrors("point draw helper init before anything"); 42 | 43 | // Create and bind VAO 44 | glGenVertexArrays(1, &m_vertexArrayObject); 45 | UtilGL::CheckErrors("glGenVertexArrays"); 46 | EWAV_ASSERT(m_vertexArrayObject > 0, "Failed to create VAO"); 47 | 48 | glBindVertexArray(m_vertexArrayObject); 49 | UtilGL::CheckErrors("glBindVertexArray"); 50 | 51 | // Figure out how many VBOs to make. 52 | EWAV_ASSERT(m_vtxPosData != NULL, "Must have vertex data."); 53 | m_numVBOs = 1; 54 | if (m_vtxNormData) { 55 | ++m_numVBOs; 56 | } 57 | if (m_vtxColData) { 58 | ++m_numVBOs; 59 | } 60 | if (m_vtxUvData) { 61 | ++m_numVBOs; 62 | } 63 | 64 | // Create vertex buffers. 65 | glGenBuffers(m_numVBOs, m_vertexBuffers); 66 | UtilGL::CheckErrors("glGenBuffers"); 67 | EWAV_ASSERT(m_vertexBuffers[0] > 0, "Failed to create VBOs"); 68 | 69 | GLenum vtxDataDyn = GL_STATIC_DRAW; 70 | if (i_dynamic) { 71 | vtxDataDyn = GL_DYNAMIC_DRAW; 72 | } 73 | 74 | // POS buffer 75 | int vboIdx = 0; 76 | m_posVboIdx = vboIdx; 77 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[vboIdx]); 78 | UtilGL::CheckErrors("glBindBuffer POS"); 79 | glBufferData(GL_ARRAY_BUFFER, sizeof(V3f) * m_numPoints, 80 | (const GLvoid*)m_vtxPosData, vtxDataDyn); 81 | UtilGL::CheckErrors("glBufferData POS"); 82 | glVertexAttribPointer(vboIdx, 3, GL_FLOAT, GL_FALSE, 0, 0); 83 | UtilGL::CheckErrors("glVertexAttribPointer POS"); 84 | glEnableVertexAttribArray(vboIdx); 85 | UtilGL::CheckErrors("glEnableVertexAttribArray POS"); 86 | 87 | // If NORM. 88 | m_normVboIdx = -1; 89 | if (m_vtxNormData) { 90 | ++vboIdx; 91 | m_normVboIdx = vboIdx; 92 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[vboIdx]); 93 | UtilGL::CheckErrors("glBindBuffer NORM"); 94 | glBufferData(GL_ARRAY_BUFFER, sizeof(V3f) * m_numPoints, 95 | (const GLvoid*)m_vtxNormData, vtxDataDyn); 96 | UtilGL::CheckErrors("glBufferData NORM"); 97 | glVertexAttribPointer(vboIdx, 3, GL_FLOAT, GL_FALSE, 0, 0); 98 | UtilGL::CheckErrors("glVertexAttribPointer NORM"); 99 | glEnableVertexAttribArray(vboIdx); 100 | UtilGL::CheckErrors("glEnableVertexAttribArray NORM"); 101 | } 102 | 103 | // If COLOR. 104 | m_colVboIdx = -1; 105 | if (m_vtxColData) { 106 | ++vboIdx; 107 | m_colVboIdx = vboIdx; 108 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[vboIdx]); 109 | UtilGL::CheckErrors("glBindBuffer COLOR"); 110 | glBufferData(GL_ARRAY_BUFFER, sizeof(V3f) * m_numPoints, 111 | (const GLvoid*)m_vtxColData, vtxDataDyn); 112 | UtilGL::CheckErrors("glBufferData COLOR"); 113 | glVertexAttribPointer(vboIdx, 3, GL_FLOAT, GL_FALSE, 0, 0); 114 | UtilGL::CheckErrors("glVertexAttribPointer COLOR"); 115 | glEnableVertexAttribArray(vboIdx); 116 | UtilGL::CheckErrors("glEnableVertexAttribArray COLOR"); 117 | } 118 | 119 | // If UVs. 120 | m_uvVboIdx = -1; 121 | if (m_vtxUvData) { 122 | ++vboIdx; 123 | m_uvVboIdx = vboIdx; 124 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[vboIdx]); 125 | UtilGL::CheckErrors("glBindBuffer UV"); 126 | glBufferData(GL_ARRAY_BUFFER, sizeof(V2f) * m_numPoints, 127 | (const GLvoid*)m_vtxUvData, vtxDataDyn); 128 | UtilGL::CheckErrors("glBufferData UV"); 129 | glVertexAttribPointer(vboIdx, 2, GL_FLOAT, GL_FALSE, 0, 0); 130 | UtilGL::CheckErrors("glVertexAttribPointer UV"); 131 | glEnableVertexAttribArray(vboIdx); 132 | UtilGL::CheckErrors("glEnableVertexAttribArray UV"); 133 | } 134 | 135 | EWAV_ASSERT(vboIdx == m_numVBOs - 1, "Mismatched vbo idx."); 136 | 137 | // Unbind VAO. 138 | glBindVertexArray(0); 139 | UtilGL::CheckErrors("Unbind VAO"); 140 | } 141 | 142 | //-***************************************************************************** 143 | PointsDrawHelper::~PointsDrawHelper() { 144 | if (m_vertexArrayObject > 0) { 145 | glDeleteVertexArrays(1, &m_vertexArrayObject); 146 | m_vertexArrayObject = 0; 147 | } 148 | 149 | if (m_numVBOs > 0 && m_vertexBuffers[0] > 0) { 150 | glDeleteBuffers(m_numVBOs, m_vertexBuffers); 151 | for (int i = 0; i < m_numVBOs; ++i) { 152 | m_vertexBuffers[i] = 0; 153 | } 154 | } 155 | } 156 | 157 | //-***************************************************************************** 158 | void PointsDrawHelper::update(std::size_t i_numPoints, const V3f* i_vtxPosData, 159 | const V3f* i_vtxNormData, const V3f* i_vtxColData, 160 | const V2f* i_vtxUvData) { 161 | m_numPoints = i_numPoints; 162 | 163 | // Activate VAO 164 | glBindVertexArray(m_vertexArrayObject); 165 | UtilGL::CheckErrors("glBindVertexArray"); 166 | 167 | if (i_vtxPosData) { 168 | m_vtxPosData = i_vtxPosData; 169 | updateFloatVertexBuffer(m_vtxPosData, m_posVboIdx); 170 | } 171 | if (i_vtxNormData) { 172 | m_vtxNormData = i_vtxNormData; 173 | updateFloatVertexBuffer(m_vtxNormData, m_normVboIdx); 174 | } 175 | if (i_vtxColData) { 176 | m_vtxColData = i_vtxColData; 177 | updateFloatVertexBuffer(m_vtxColData, m_colVboIdx); 178 | } 179 | if (i_vtxUvData) { 180 | m_vtxUvData = i_vtxUvData; 181 | updateFloatVertexBuffer(m_vtxUvData, m_uvVboIdx); 182 | } 183 | 184 | // Unbind 185 | glBindVertexArray(0); 186 | } 187 | 188 | //-***************************************************************************** 189 | void PointsDrawHelper::draw(const GLCamera& i_cam) const { 190 | // Bind the vertex array 191 | glBindVertexArray(m_vertexArrayObject); 192 | UtilGL::CheckErrors("glBindVertexArray draw"); 193 | 194 | // Draw the arrays 195 | glDrawArrays(GL_POINTS, 0, m_numPoints); 196 | UtilGL::CheckErrors("glDrawArrays"); 197 | 198 | // Unbind the vertex array 199 | glBindVertexArray(0); 200 | UtilGL::CheckErrors("glBindVertexArray 0 draw"); 201 | } 202 | 203 | } // namespace SimpleSimViewer 204 | } // namespace EncinoWaves 205 | -------------------------------------------------------------------------------- /src/EncinoWaves/Stats.h: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | //-***************************************************************************** 18 | // The basic architecture of these Waves is based on the TweakWaves application 19 | // written by Chris Horvath for Tweak Films in 2001. This, in turn, was based 20 | // on the SIGGRAPH papers and courses by Jerry Tessendorf, and by the paper 21 | // "A Simple Fluid Solver based on the FTT" by Jos Stam. 22 | // 23 | // The TMA, JONSWAP, and Pierson Moskowitz Wave Spectra, as well as the 24 | // directional spreading functions are formulated based on the descriptions 25 | // given in "Ocean Waves: The Stochastic Approach", 26 | // by Michel K. Ochi, published by Cambridge Ocean Technology Series, 1998,2005. 27 | // 28 | // This library is written as a working implementation of the paper: 29 | // Christopher J. Horvath. 2015. 30 | // Empirical directional wave spectra for computer graphics. 31 | // In Proceedings of the 2015 Symposium on Digital Production (DigiPro '15), 32 | // Los Angeles, Aug. 8, 2015, pp. 29-39. 33 | //-***************************************************************************** 34 | 35 | #ifndef _EncinoWaves_Stats_h_ 36 | #define _EncinoWaves_Stats_h_ 37 | 38 | #include "Foundation.h" 39 | 40 | namespace EncinoWaves { 41 | 42 | //-***************************************************************************** 43 | template 44 | struct MinMaxSum { 45 | T min; 46 | T max; 47 | T sum; 48 | MinMaxSum() 49 | : min(std::numeric_limits::max()) 50 | , max(-std::numeric_limits::max()) 51 | , sum(T(0)) {} 52 | 53 | MinMaxSum(const MinMaxSum& i_s, tbb::split) 54 | : min(std::numeric_limits::max()) 55 | , max(-std::numeric_limits::max()) 56 | , sum(T(0)) {} 57 | 58 | void operator()(const tbb::blocked_range& i_range) { 59 | T tmin = min; 60 | T tmax = max; 61 | T tsum = sum; 62 | for (const T* a = i_range.begin(); a != i_range.end(); ++a) { 63 | T ai = *a; 64 | if (ai < tmin) { 65 | tmin = ai; 66 | } 67 | if (ai > tmax) { 68 | tmax = ai; 69 | } 70 | tsum += ai; 71 | } 72 | min = tmin; 73 | max = tmax; 74 | sum = tsum; 75 | } 76 | void join(const MinMaxSum& i_rhs) { 77 | min = std::min(min, i_rhs.min); 78 | max = std::max(max, i_rhs.max); 79 | sum += i_rhs.sum; 80 | } 81 | }; 82 | 83 | //-***************************************************************************** 84 | template 85 | void ParallelMinMaxSum(const T* i_values, std::size_t i_size, T& o_min, 86 | T& o_max, T& o_sum) { 87 | MinMaxSum mms; 88 | tbb::parallel_reduce( 89 | tbb::blocked_range(i_values, i_values + i_size), mms); 90 | o_min = mms.min; 91 | o_max = mms.max; 92 | o_sum = mms.sum; 93 | } 94 | 95 | //-***************************************************************************** 96 | template 97 | struct Sum { 98 | T value; 99 | Sum() 100 | : value(T(0)) {} 101 | Sum(const Sum& i_s, tbb::split) 102 | : value(T(0)) {} 103 | void operator()(const tbb::blocked_range& i_range) { 104 | T temp = value; 105 | for (const T* a = i_range.begin(); a != i_range.end(); ++a) { 106 | temp += *a; 107 | } 108 | value = temp; 109 | } 110 | void join(const Sum& i_rhs) { value += i_rhs.value; } 111 | }; 112 | 113 | //-***************************************************************************** 114 | template 115 | T ParallelSum(const T* i_values, std::size_t i_size) { 116 | Sum sum; 117 | tbb::parallel_reduce( 118 | tbb::blocked_range(i_values, i_values + i_size), sum); 119 | return sum.value; 120 | } 121 | 122 | //-***************************************************************************** 123 | template 124 | T ParallelMean(const T* i_values, std::size_t i_size) { 125 | typedef typename singular_value_type::type denom_type; 126 | 127 | return ParallelSum(i_values, i_size) / denom_type(i_size); 128 | } 129 | 130 | //-***************************************************************************** 131 | template 132 | struct VarianceSum { 133 | T value; 134 | T mean; 135 | explicit VarianceSum(const T& i_mean) 136 | : value(T(0)) 137 | , mean(i_mean) {} 138 | VarianceSum(const VarianceSum& i_v, tbb::split) 139 | : value(T(0)) 140 | , mean(i_v.mean) {} 141 | void operator()(const tbb::blocked_range& i_range) { 142 | T temp = value; 143 | for (const T* a = i_range.begin(); a != i_range.end(); ++a) { 144 | temp += sqr(*a - mean); 145 | } 146 | value = temp; 147 | } 148 | void join(const VarianceSum& i_rhs) { value += i_rhs.value; } 149 | }; 150 | 151 | //-***************************************************************************** 152 | template 153 | T ParallelStdDev(T i_mean, const T* i_values, std::size_t i_size) { 154 | typedef typename singular_value_type::type denom_type; 155 | 156 | VarianceSum vsum(i_mean); 157 | tbb::parallel_reduce( 158 | tbb::blocked_range(i_values, i_values + i_size), vsum); 159 | T variance = std::abs(vsum.value / denom_type(i_size)); 160 | 161 | return std::sqrt(variance); 162 | } 163 | 164 | //-***************************************************************************** 165 | template 166 | struct Stats { 167 | T MinHeight; 168 | T MaxHeight; 169 | T MeanHeight; 170 | 171 | T MeanMinE; 172 | T StdDevMinE; 173 | 174 | #if 0 175 | explicit Stats( const PropagatedState& i_waves ) 176 | { 177 | ParallelMinMaxSum( i_waves.Height.cdata(), i_waves.Height.size(), 178 | MinHeight, MaxHeight, MeanHeight ); 179 | MeanHeight /= T( i_waves.Height.size() ); 180 | 181 | MeanMinE = ParallelMean( i_waves.MinE.cdata(), i_waves.MinE.size() ); 182 | StdDevMinE = 183 | ParallelStdDev( MeanMinE, 184 | i_waves.MinE.cdata(), i_waves.MinE.size() ); 185 | 186 | std::cout << 187 | ( boost::format( "Height (min, max, mean): (%f, %f, %f)" ) 188 | % MinHeight % MaxHeight % MeanHeight ) << std::endl << 189 | ( boost::format( "MinE (mean, stddev): (%f, %f)" ) 190 | % MeanMinE % StdDevMinE ) << std::endl; 191 | } 192 | #endif 193 | 194 | Stats(const RealSpatialField2D& Height, 195 | const RealSpatialField2D& MinE) { 196 | ParallelMinMaxSum(Height.cdata(), Height.size(), MinHeight, MaxHeight, 197 | MeanHeight); 198 | MeanHeight /= T(Height.size()); 199 | 200 | MeanMinE = ParallelMean(MinE.cdata(), MinE.size()); 201 | StdDevMinE = ParallelStdDev(MeanMinE, MinE.cdata(), MinE.size()); 202 | 203 | // std::cout << 204 | // ( boost::format( "Height (min, max, mean): (%f, %f, %f)" ) 205 | // % MinHeight % MaxHeight % MeanHeight ) << std::endl << 206 | // ( boost::format( "MinE (mean, stddev): (%f, %f)" ) 207 | // % MeanMinE % StdDevMinE ) << std::endl; 208 | } 209 | }; 210 | 211 | //-***************************************************************************** 212 | typedef Stats Statsf; 213 | typedef Stats Statsd; 214 | 215 | } // namespace EncinoWaves 216 | 217 | #endif 218 | -------------------------------------------------------------------------------- /src/SimpleSimViewer/LinesDrawHelper.cpp: -------------------------------------------------------------------------------- 1 | //-***************************************************************************** 2 | // Copyright 2015 Christopher Jon Horvath 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //-***************************************************************************** 16 | 17 | #include "LinesDrawHelper.h" 18 | 19 | namespace EncinoWaves { 20 | namespace SimpleSimViewer { 21 | 22 | //-***************************************************************************** 23 | LinesDrawHelper::LinesDrawHelper(bool i_dynamic, std::size_t i_numPoints, 24 | const V3f* i_vtxPosData, 25 | const V3f* i_vtxNormData, 26 | const V3f* i_vtxColData, 27 | const V2f* i_vtxUvData) 28 | : m_numPoints(i_numPoints) 29 | , m_vtxPosData(i_vtxPosData) 30 | , m_vtxNormData(i_vtxNormData) 31 | , m_vtxColData(i_vtxColData) 32 | , m_vtxUvData(i_vtxUvData) 33 | , m_vertexArrayObject(0) 34 | , m_posVboIdx(-1) 35 | , m_normVboIdx(-1) 36 | , m_colVboIdx(-1) 37 | , m_uvVboIdx(-1) { 38 | //-************************************************************************* 39 | // OPENGL INIT 40 | //-************************************************************************* 41 | UtilGL::CheckErrors("line draw helper init before anything"); 42 | 43 | // Create and bind VAO 44 | glGenVertexArrays(1, &m_vertexArrayObject); 45 | UtilGL::CheckErrors("glGenVertexArrays"); 46 | EWAV_ASSERT(m_vertexArrayObject > 0, "Failed to create VAO"); 47 | 48 | glBindVertexArray(m_vertexArrayObject); 49 | UtilGL::CheckErrors("glBindVertexArray"); 50 | 51 | // Figure out how many VBOs to make. 52 | EWAV_ASSERT(m_vtxPosData != NULL, "Must have vertex data."); 53 | m_numVBOs = 1; 54 | if (m_vtxNormData) { 55 | ++m_numVBOs; 56 | } 57 | if (m_vtxColData) { 58 | ++m_numVBOs; 59 | } 60 | if (m_vtxUvData) { 61 | ++m_numVBOs; 62 | } 63 | 64 | // Create vertex buffers. 65 | glGenBuffers(m_numVBOs, m_vertexBuffers); 66 | UtilGL::CheckErrors("glGenBuffers"); 67 | EWAV_ASSERT(m_vertexBuffers[0] > 0, "Failed to create VBOs"); 68 | 69 | GLenum vtxDataDyn = GL_STATIC_DRAW; 70 | if (i_dynamic) { 71 | vtxDataDyn = GL_DYNAMIC_DRAW; 72 | } 73 | 74 | // POS buffer 75 | int vboIdx = 0; 76 | m_posVboIdx = vboIdx; 77 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[vboIdx]); 78 | UtilGL::CheckErrors("glBindBuffer POS"); 79 | glBufferData(GL_ARRAY_BUFFER, sizeof(V3f) * m_numPoints, 80 | (const GLvoid*)m_vtxPosData, vtxDataDyn); 81 | UtilGL::CheckErrors("glBufferData POS"); 82 | glVertexAttribPointer(vboIdx, 3, GL_FLOAT, GL_FALSE, 0, 0); 83 | UtilGL::CheckErrors("glVertexAttribPointer POS"); 84 | glEnableVertexAttribArray(vboIdx); 85 | UtilGL::CheckErrors("glEnableVertexAttribArray POS"); 86 | 87 | // If NORM. 88 | m_normVboIdx = -1; 89 | if (m_vtxNormData) { 90 | ++vboIdx; 91 | m_normVboIdx = vboIdx; 92 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[vboIdx]); 93 | UtilGL::CheckErrors("glBindBuffer NORM"); 94 | glBufferData(GL_ARRAY_BUFFER, sizeof(V3f) * m_numPoints, 95 | (const GLvoid*)m_vtxNormData, vtxDataDyn); 96 | UtilGL::CheckErrors("glBufferData NORM"); 97 | glVertexAttribPointer(vboIdx, 3, GL_FLOAT, GL_FALSE, 0, 0); 98 | UtilGL::CheckErrors("glVertexAttribPointer NORM"); 99 | glEnableVertexAttribArray(vboIdx); 100 | UtilGL::CheckErrors("glEnableVertexAttribArray NORM"); 101 | } 102 | 103 | // If COLOR. 104 | m_colVboIdx = -1; 105 | if (m_vtxColData) { 106 | ++vboIdx; 107 | m_colVboIdx = vboIdx; 108 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[vboIdx]); 109 | UtilGL::CheckErrors("glBindBuffer COLOR"); 110 | glBufferData(GL_ARRAY_BUFFER, sizeof(V3f) * m_numPoints, 111 | (const GLvoid*)m_vtxColData, vtxDataDyn); 112 | UtilGL::CheckErrors("glBufferData COLOR"); 113 | glVertexAttribPointer(vboIdx, 3, GL_FLOAT, GL_FALSE, 0, 0); 114 | UtilGL::CheckErrors("glVertexAttribPointer COLOR"); 115 | glEnableVertexAttribArray(vboIdx); 116 | UtilGL::CheckErrors("glEnableVertexAttribArray COLOR"); 117 | } 118 | 119 | // If UVs. 120 | m_uvVboIdx = -1; 121 | if (m_vtxUvData) { 122 | ++vboIdx; 123 | m_uvVboIdx = vboIdx; 124 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[vboIdx]); 125 | UtilGL::CheckErrors("glBindBuffer UV"); 126 | glBufferData(GL_ARRAY_BUFFER, sizeof(V2f) * m_numPoints, 127 | (const GLvoid*)m_vtxUvData, vtxDataDyn); 128 | UtilGL::CheckErrors("glBufferData UV"); 129 | glVertexAttribPointer(vboIdx, 2, GL_FLOAT, GL_FALSE, 0, 0); 130 | UtilGL::CheckErrors("glVertexAttribPointer UV"); 131 | glEnableVertexAttribArray(vboIdx); 132 | UtilGL::CheckErrors("glEnableVertexAttribArray UV"); 133 | } 134 | 135 | EWAV_ASSERT(vboIdx == m_numVBOs - 1, "Mismatched vbo idx."); 136 | 137 | // Unbind VAO. 138 | glBindVertexArray(0); 139 | UtilGL::CheckErrors("Unbind VAO"); 140 | } 141 | 142 | //-***************************************************************************** 143 | LinesDrawHelper::~LinesDrawHelper() { 144 | if (m_vertexArrayObject > 0) { 145 | glDeleteVertexArrays(1, &m_vertexArrayObject); 146 | m_vertexArrayObject = 0; 147 | } 148 | 149 | if (m_numVBOs > 0 && m_vertexBuffers[0] > 0) { 150 | glDeleteBuffers(m_numVBOs, m_vertexBuffers); 151 | for (int i = 0; i < m_numVBOs; ++i) { 152 | m_vertexBuffers[i] = 0; 153 | } 154 | } 155 | } 156 | 157 | //-***************************************************************************** 158 | void LinesDrawHelper::update(std::size_t i_numPoints, const V3f* i_vtxPosData, 159 | const V3f* i_vtxNormData, const V3f* i_vtxColData, 160 | const V2f* i_vtxUvData) { 161 | m_numPoints = i_numPoints; 162 | 163 | // Activate VAO 164 | glBindVertexArray(m_vertexArrayObject); 165 | UtilGL::CheckErrors("glBindVertexArray"); 166 | 167 | if (i_vtxPosData) { 168 | m_vtxPosData = i_vtxPosData; 169 | updateFloatVertexBuffer(m_vtxPosData, m_posVboIdx); 170 | } 171 | if (i_vtxNormData) { 172 | m_vtxNormData = i_vtxNormData; 173 | updateFloatVertexBuffer(m_vtxNormData, m_normVboIdx); 174 | } 175 | if (i_vtxColData) { 176 | m_vtxColData = i_vtxColData; 177 | updateFloatVertexBuffer(m_vtxColData, m_colVboIdx); 178 | } 179 | if (i_vtxUvData) { 180 | m_vtxUvData = i_vtxUvData; 181 | updateFloatVertexBuffer(m_vtxUvData, m_uvVboIdx); 182 | } 183 | 184 | // Unbind 185 | glBindVertexArray(0); 186 | } 187 | 188 | //-***************************************************************************** 189 | void LinesDrawHelper::draw(const GLCamera& i_cam) const { 190 | // Bind the vertex array 191 | glBindVertexArray(m_vertexArrayObject); 192 | UtilGL::CheckErrors("glBindVertexArray draw"); 193 | 194 | // Draw the arrays 195 | glDrawArrays(GL_LINES, 0, m_numPoints); 196 | UtilGL::CheckErrors("glDrawArrays"); 197 | 198 | // Unbind the vertex array 199 | glBindVertexArray(0); 200 | UtilGL::CheckErrors("glBindVertexArray 0 draw"); 201 | } 202 | 203 | //-***************************************************************************** 204 | void LinesDrawHelper::draw() const { 205 | // Bind the vertex array 206 | glBindVertexArray(m_vertexArrayObject); 207 | UtilGL::CheckErrors("glBindVertexArray draw"); 208 | 209 | // Draw the arrays 210 | glDrawArrays(GL_LINES, 0, m_numPoints); 211 | UtilGL::CheckErrors("glDrawArrays"); 212 | 213 | // Unbind the vertex array 214 | glBindVertexArray(0); 215 | UtilGL::CheckErrors("glBindVertexArray 0 draw"); 216 | } 217 | 218 | } // namespace SimpleSimViewer 219 | } // namespace EncinoWaves 220 | --------------------------------------------------------------------------------