Git Product home page Git Product logo

fwater's Introduction

FWater - Visual Demo

This code uses the famous "two-buffer trick" to create a water-like visual effect. The idea is you have two buffers, which each store a heightmap. The pseudo-code is

  • Every frame, for a given pixel P, compute the average of that pixel's neighbors in the other buffer. Half that average, and subtract P's previous value. That (times some dampening factor) is P's new value.
  • Swap the roles of the buffers.

The concept is simple, yet it creates a rippling kind of effect due to the wave-like values that the heights will have and the way they oscillate up and down. The waves will bounce off "walls", too, depending on the implementation; this one allows that.

While a sensible implementation on modern computers will perform okay, this kind of technique is best suited to an implementation that can do many computations in parallel (e.g., a compute shader). Allegedly, the ifort compiler is supposed to help out here. Anecdotally, the performance has been good enough on this sample. It could be interesting to stress test it more.

Example

Example image

When running the program, use the mouse to cause motion in the heightmap.

Build

The program is for Windows-based x86-64 computer environments.

Visual Studio 2019 with Intel Parallel Studio XE was used to build this.

This program is organized as a Visual Studio solution with two projects.

  • Window - A Win32 executible written in C++, that has a window and a Direct3D12-compatible swap chain.
  • Compute - A DLL written in Fortran (2008-compatible) that implements the algorithm described above.

The setup has Window responsible for all the UI and user-facing elements; window, mouse input, etc, while the "heavy lifting" happens in Compute.

There are entrypoints in Compute to update the grid state, handle mouse input, and draw the current grid colors to a Direct3D surface.

Related Links

The Water Effect Explained

Coding Requirements for Sharing Procedures in DLLs

fwater's People

Contributors

clandrew avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.