Skip to content
v3: Surface plot of f(x,y) with colormap in vertex shader

Computes the plot of a function $z=f(x,y)$ of two parameters.
Draw the surface, grid wireframe, and cloud of points, each
separately toggleable from UI.

The compute kernel (be it on CPU or GPU) rescales $z$ values to
be in the [-1.0, 1.0] range.  This means that the surface plot
of the function should fit in a [-1, 1]^3 cube, assuming that
all values are within expected range, at least for $x$ and $y$
in [-1, 1] range.

The function to draw is hardcoded in plot2d_common.hpp as `func(x,y)`,
and cannot be changed at runtime.  The min-max rescaling is implemented
by `rescaledValue()`.  The colormap code is embedded in the fragment
shader, as `colormap()` function in the 'glsl/plot2d.vert' shader.

It uses MATLAB_jet colormap (blue to red), using `colormap()` function
from https://github.com/kbinani/colormap-shaders without special
handling for values above 1.0 or below -1.0 (which is expected range
of $z$ values, after rescaling by `rescaledValue()`).