Skip to content

Instantly share code, notes, and snippets.

@Dewb
Last active April 12, 2022 16:22
Show Gist options
  • Save Dewb/183a4f6a14b586bd27b4848f263eb4cb to your computer and use it in GitHub Desktop.
Save Dewb/183a4f6a14b586bd27b4848f263eb4cb to your computer and use it in GitHub Desktop.
Example of using GLSL shaders on the EYESY openFrameworks beta OS

EYESY openFrameworks mode demonstrating the use of GLSL shaders.

Requirements/Usage:

  • Install the EYESY_OS beta image from December 2021
  • Connect to EYESY wifi editor, create a new folder, and place these three files in it
  • You might also want to sync to ofEyesy commit 3991169 or newer. (It might work fine with original OS image or latest, but this is what my local repo is at currently.)

Video demo: https://vimeo.com/698406641

Lissajous plasma technique is inspired by the classic LoL Shield plasma demo.

// Lissajous Plasma Ramps
uniform vec2 resolution;
uniform float time;
uniform float knob1;
uniform float knob2;
uniform float knob3;
uniform float knob4;
uniform float knob5;
#define TAU 6.283184
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main(void)
{
vec2 uv = (-1. + 2. * vec2(gl_FragCoord.x / resolution.x, gl_FragCoord.y / resolution.y)) *
((50. * knob1) + (8. * sin(time/33.))) + (16. * cos(time/73.));
vec2 p1 = vec2(
(sin(time/31.) + 4.) * (3.45 + 12. * knob2) - 40.,
(sin(time/3.66) + 3.) * 7.5 + (2. * knob3 - 1.) * 47.
);
vec2 p2 = vec2(
(sin(time/13.) + 3.) * (13.27 - 4. * knob2) - 41.,
(sin(time/7.81) + 1.) * 16. * (1. - knob3) + 14.
);
float d1 = distance(uv, p1);
float d2 = distance(uv, p2);
float hueRange = .1 + knob5 * .38;
float baseHue = (1. - knob4) * (1. - hueRange);
gl_FragColor = vec4(
hsv2rgb(vec3(
baseHue + hueRange * abs(sin(TAU * mod(time, 72.) / 72. + sqrt(d1 * d2))),
abs(.9 - .32 * abs(sin(sqrt(1. + (d1 + d2))))),
abs(sin(sqrt(abs(1. - d1) * abs(4. - d2))))
)),
1.
);
}
require("eyesy")
modeTitle = "S - Lissajous Plasma Ramps"
modeExplain = "Demonstrate loading a shader in Eyesy ofLua, by Anagram/Dewb"
print(modeTitle)
print(modeExplain)
function script_path()
local str = debug.getinfo(2, "S").source:sub(2)
return str:match("(.*/)")
end
print(script_path())
function setup()
w = of.getWidth()
h = of.getHeight()
time = 0
k1s = knob1
k2s = knob2
k3s = knob3
k4s = knob4
k5s = knob5
inLTexture = of.Texture()
inRTexture = of.Texture()
inLTexture:allocate(256, 1, 0x1903) -- of.GL_RED
inRTexture:allocate(256, 1, 0x1903) -- of.GL_RED
shader = of.Shader()
shader:load(script_path() .. "vertex.glsl", script_path() .. "fragment.glsl", "")
end
function update()
time = (time + of.getLastFrameTime()) % 3600.0
-- basic knob smoothing
k1s = (k1s + knob1) / 2
k2s = (k2s + knob2) / 2
k3s = (k3s + knob3) / 2
k4s = (k4s + knob4) / 2
k5s = (k5s + knob5) / 2
-- need to enhance SWIG for loadData to convert table to float array?
--inLTexture:loadData(inL, 256, 1, 0x1903) -- of.GL_RED
--inRTexture:loadData(inR, 256, 1, 0x1903) -- of.GL_RED
end
function draw()
shader:beginShader()
shader:setUniform2f("resolution", w, h)
shader:setUniform1f("time", time)
shader:setUniform1f("knob1", k1s)
shader:setUniform1f("knob2", k2s)
shader:setUniform1f("knob3", k3s)
shader:setUniform1f("knob4", k4s)
shader:setUniform1f("knob5", k5s)
of.drawRectangle(0, 0, w, h)
shader:endShader()
end
function exit()
print("script finished")
end
// default vertex shader
attribute vec4 position;
uniform mat4 modelViewProjectionMatrix;
void main()
{
gl_Position = modelViewProjectionMatrix * position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment