GithubHelp home page GithubHelp logo

postrediori / oceansimulation Goto Github PK

View Code? Open in Web Editor NEW
22.0 4.0 3.0 1.87 MB

Ocean Simulation Based on a Model By Keith Lantz (https://www.keithlantz.net/)

License: MIT License

CMake 9.41% C++ 77.41% GLSL 12.63% C 0.55%
opengl glsl fast-fourier-transform ocean-simulation

oceansimulation's Introduction

Ocean Simulation

Introduction

Ocean simulation is based on the project by Keith Lantz. This project uses OpenGL 3.3 by default and it is possible to make configuration for OpenGL 2.0 for maximum compatibility.

The numerical model is based on the paper by J. Tessendorf and utilizes Phillips spectrum and algorithm of inverse FFT.

Ocean Simulation screenshot

Ocean Simulation with UI

Ocean Simulation with Colors UI

Prerequisites

Generating build files for your OS and build system requires CMake. Most of the dependencies are bundled with the repository as git submodules. This includes:

  • glad - OpenGL Function Loader.
  • glfw - Windowing and Input.
  • glm - OpenGL Mathematics.
  • plog - Logging library.
  • imgui - UI library.
  • stb - Saving images for making screenshots.

Building for Linux

Dependencies

The following instructions apply to:

  • Ubuntu 20.04, 18.04, 16.04
  • Debian 9 and higher
sudo apt-get install -y \
    build-essential \
    cmake \
    xorg-dev \
    libgl1-mesa-dev \
    libfreetype6-dev

The following instructions apply to:

  • Fedora 22 and higher
sudo dnf install -y \
    gcc gcc-c++ make \
    cmake \
    mesa-libGL-devel \
    mesa-libGLU-devel \
    libXrandr-devel \
    libXinerama-devel \
    libXcursor-devel \
    libXi-devel \
    freetype-devel
  • CentOS 7 and higher
sudo yum install -y \
    gcc gcc-c++ make \
    cmake \
    mesa-libGL-devel \
    mesa-libGLU-devel \
    libXrandr-devel \
    libXinerama-devel \
    libXcursor-devel \
    libXi-devel \
    freetype-devel

Cloning Repository

git clone --recursive https://github.com/Postrediori/OceanSimulation.git
cd OceanSimulation

Cloning the repository requires passing the --recursive flag to load Git submodules.

Building Project

The program is built with the commands below. CMake requires the directory with the main project's CMakeLists.txt file as an argument. Then the CMake creates the build files for the GNU make which build an executable.

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
make install

Additional build options

The following options are available when running CMake:

  • USE_OPENGL2_0 (default value: OFF) - Use rendering with legacy OpenGL 2.0 (and GLSL 1.10) for maximum compatibility.

Example usage:

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DUSE_OPENGL2_0=ON

Running Project

After the successful build the binary Ocean will end up in <source dir>/bundle.

cd <PathToProject>
./bundle/Ocean

Building for macOS

Dependencies

Youโ€™ll need to download and install the following to build the project:

  • Xcode and the Xcode command line tools
  • CMake (e.g. via homebrew brew install cmake)

Cloning Repository

git clone --recursive https://github.com/Postrediori/OceanSimulation
cd OceanSimulation

Using CMake

Generate makefiles for the build:

mkdir build && cd build
cmake .. -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_BUILD_TYPE=Release

Building

make
make install

An Ocean application bundle will now be present under <Source directory>/bundle.

Building for Windows

Pre-requisites

Install MSYS2 and update it to the latest version by pacman -Syu.

Dependencies

Open the "MSYS2 MinGW 64-bit" (mingw64.exe) shell. Download and install all dependencies

pacman -S mingw-w64-x86_64-{gcc,cmake} make git

Cloning Repository

git clone --recursive https://github.com/Postrediori/OceanSimulation
cd OceanSimulation

Building

mkdir build && cd build
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release ..
make
make install

An Ocean application bundle will now be present under <Source directory>/bundle.

Configuration

The parameters of the model can be adjusted in the data/ocean.cfg file:

# configuration file for Ocean Simulation

# wave parameters
waveAmplitude = 2e-5

# wind parameters
windDirX = 0.0
windDirZ = 12.8

oceanSize = 64
oceanLen = 320.0
oceanRepeat = 5

The following parameters are to be adjusted:

  • waveAmplitude - amplitude of the surface disturbance.
  • windDirX, windDirZ - components of the wind vector. The vertical (Y) component is ignored in the model.
  • oceanLen - discretization parameter.
  • oceanRepeat - this model does use only a small patch of memory to model the whole Ocean. This parameter adjusts the size of the model in terms of one minimal patch. The value represents the number of ocean patches along X and Z dimensions. E.g. value 5 mean the simulated area will be 5x5 the size of the initial patch.
  • oceanSize, oceanLen - these are the parameters of the initial patch that will be used for simulation of the ocean. The first parameter is the grid size and the second value stands for the length of the patch.

Controls

  • F1 - Toggle fullscreen mode.
  • F2 - Show/hide UI on the screen.
  • Arrow keys - Navigate the model.
  • PgUp/PgDown - Adjust vertical position of the viewer point.
  • 1 - Toggle wireframe mode.
  • 2 - Toggle solid surface ("normal") mode.
  • S - Switch to the next post-processing shader.

Links

TODO

  • Adjust ocean parameters in the UI.
  • Color adjustment.
  • Add build instructions for Windows.
  • Mouse navigation.
  • Add Vulkan renderer.

oceansimulation's People

Contributors

postrediori avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

oceansimulation's Issues

Project uses obsolete libraries

Project uses combination Freeglut+GLEW. Combination of GLFW+GLAD is up-to-date and can be included into the project as 3rd party modules.

Changing sky color

Hello,

I was wondering how i can change the colors on both the sky and fog? Its something i want to do for an art project

Support for OSX

I was just checking Nick Lantz's work and bumped in to you version. Nice one!
Running and compiling on OSX will try to load the vertex_src_1_30, fragment_src_1_30 shaders by default and fails since the created OpenGL context is 2.1. With GLFW+Glad it seems to be easier to choose context on OSX, however not sure if GLFW is ported as widely as FreeGlut, so probably no Mobile Intel 965 support there ๐Ÿ˜„

Freetype.cpp:182

#ifdef __APPLE__
    vertex_src = vertex_src_1_10;
    fragment_src = fragment_src_1_10;
#else
    if (GLEW_VERSION_3_0) {
        vertex_src = vertex_src_1_30;
        fragment_src = fragment_src_1_30;
    } else {
        vertex_src = vertex_src_1_10;
        fragment_src = fragment_src_1_10;
    }
#endif

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.