This originally started out as an attempt to try out instanced rendering. It now includes an OpenCL wind simulation.
The program is written in C++/Qt. OpenGL and OpenCL are both used, but some of the OpenCL code is Apple-specific (guarded by #ifdef __APPLE__
). Fortunately, these instances are completely isolated to two files: include_opencl.h
and myclwrapper.cpp
.
- The
cl_interface/include_opencl.h
header does a platform-specific OpenCL include. For Apple, this is<OpenCL/opencl.h>
, and for other systems it might be different. By default, if__APPLE__
isn't defined, I include<cl.h>
. - Change
makeCLGLContext()
inMyCLWrapper
.
Press F to toggle the force. The quad in the upper-right corner displays the wind velocities. The grass reacts to the wind.
- 128x128 grass blades are drawn with a
glDrawArraysInstanced()
call. - OpenCL code approximates the Navier-Stokes equations for an incompressible fluid.
- The grass waves in response to the wind.
A small script creates the grass blade model. Per-instance data is stored in special per-instance buffers. I use glVertexAttribDivisor()
and glDrawArraysInstanced()
to achieve this.
To simulate wind, I use the Navier-Stokes approximation described here. My code for this is currently quite messy.