Created
February 25, 2017 20:46
-
-
Save Chlumsky/72fc648663c3a4a36e48d6565ac715d7 to your computer and use it in GitHub Desktop.
Revisions
-
Chlumsky created this gist
Feb 25, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ #define PLOT_SAMPLES 3 template <FN, XMIN, XMAX, YMIN, YMAX, XGRID, YGRID> glsl vec4 plot(vec2 pos) { vec2 tPos = vec2( mix(float(XMIN), float(XMAX), pos.x), mix(float(YMIN), float(YMAX), pos.y) ); vec2 pxSize = vec2((XMAX)-(XMIN), (YMAX)-(YMIN))*shadron_PixelSize; float opacity = 0.0; for (int ys = 0; ys < PLOT_SAMPLES; ++ys) for (int xs = 0; xs < PLOT_SAMPLES; ++xs) { vec2 stPos = tPos+pxSize*vec2(float(2*xs-(PLOT_SAMPLES-1)), float(2*ys-(PLOT_SAMPLES-1)))*(1.0/float(2*PLOT_SAMPLES)); float y = FN(stPos.x); float high = y; float low = y; for (int i = 1; i <= 4; ++i) { float ny = FN(stPos.x+0.25*pxSize.x*float(i)); low = min(low, ny); high = max(high, ny); ny = FN(stPos.x-0.25*pxSize.x*float(i)); low = min(low, ny); high = max(high, ny); } opacity += float(stPos.y >= low-pxSize.y && stPos.y <= high+pxSize.y); } opacity *= 1.0/float(PLOT_SAMPLES*PLOT_SAMPLES); vec2 grid = 0.5-abs(0.5-mod(tPos/vec2(XGRID, YGRID), vec2(1.0))); if (abs(tPos.x) < pxSize.x || abs(tPos.y) < pxSize.y) opacity += 0.5; else if (grid.x*(XGRID) <= 0.5*pxSize.x || grid.y*(YGRID) <= 0.5*pxSize.y) opacity += 0.25; return vec4(0.0, 0.0, 0.0, opacity); }