Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Moving head Shaders and Filters #546

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,60 @@
"@type=paint"
],
"srcFile": "shaders/ZebraMadness.glsl"
},
{
"id": "movers-beats",
"title": "Movers Beats",
"description": "On each beat jumps an eye to a random position. Can be constrained to a horizon, sky or ground.",
"lastModifiedMs": 0,
"tags": [
"@type=mover"
],
"srcFile": "movers/Movers Beats.glsl"
},
{
"id": "movers-brightness",
"title": "Movers Brightness Filter",
"description": "Filter for Moving Heads to adjust the dimmer to the beat",
"lastModifiedMs": 0,
"tags": [
"@filter",
"@type=mover"
],
"srcFile": "movers/Movers Brightness Filter.glsl"
},
{
"id": "movers-color",
"title": "Movers Color Filter",
"description": "Change colors of Moving Head fixtures",
"lastModifiedMs": 0,
"tags": [
"@filter",
"@type=mover"
],
"srcFile": "movers/Movers Color Filter.glsl"
},
{
"id": "movers-floor-position",
"title": "Movers Floor Position",
"description": "Point to a position on the floor (based on a rectangle)",
"lastModifiedMs": 0,
"tags": [
"@filter",
"@type=mover"
],
"srcFile": "movers/Movers Floor Position.glsl"
},
{
"id": "movers-spin",
"title": "Movers Spin",
"description": "Spin the Moving Heads together, crossed or independent",
"lastModifiedMs": 0,
"tags": [
"@filter",
"@type=mover"
],
"srcFile": "movers/Movers Spin.glsl"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// On each beat jumps an eye to a random position. Can be constrained to a horizon, sky or ground.
// by Aravindo Wingeier

struct FixtureInfo {
vec3 position;
vec3 rotation;
mat4 transformation;
};

struct MovingHeadParams {
float pan;
float tilt;
float colorWheel;
float dimmer;
};

uniform FixtureInfo fixtureInfo;

struct BeatInfo {
float beat;
float bpm;
float intensity;
float confidence;
};
uniform BeatInfo beatInfo; // @@baaahs.BeatLink:BeatInfo

uniform float time; // @@Time
uniform bool sky; // @@Switch enabled=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this! I'm gonna see if I can pull in the Select widget from this branch, which gives radio button-like behavior.

uniform bool horizon; // @@Switch enabled=true
uniform bool ground; // @@Switch enabled=true

#define PI 3.14159265358979323846

bool isLeft(){
return fixtureInfo.position.z < 0.;
}

#define SIMULATE_BPM false
#define alternateEye true

float getBPM() {
if (SIMULATE_BPM) {
return 120.;
} else {
return beatInfo.bpm;
}
}

float getTimeOfLastBeat() {
float beatShift = alternateEye && isLeft() ? 1.0 : 0.;
float eyesInSequence = alternateEye ? 2. : 1.;

// SIM:
if(SIMULATE_BPM){
float bpm = getBPM();
float beatDuration = 60. / bpm;
float timeSince2Beats = mod(time + beatShift * beatDuration, beatDuration * eyesInSequence);
return time - timeSince2Beats;
} else {
// real:
float beatDuration = 60. / getBPM();
float timeSince2Beats = mod(beatInfo.beat + beatShift, eyesInSequence) * beatDuration;
return time - timeSince2Beats;
}
}

float getSeed(){
float counter = getTimeOfLastBeat() * getBPM() / 60.;
float eyesInSequence = alternateEye ? 2. : 1.;
return counter / eyesInSequence;
}


float pan(float value /* [-1...1]*/ ) {
if(horizon && !sky && !ground) {
return 2. * PI /2. + 0.5 * PI;
}

float rangeOfMotion = 0.5 * PI; // to each side
return 2. * PI /2. + value * rangeOfMotion;
}

float tilt(float value /* [-1...1]*/) {
// if nothing is ticked, use default
if(!ground && !sky && !horizon) {
return value * 1.2;
}

if(!ground) value = min(0.1, value);
if(!sky) value = max(0.9, value);
if(!horizon) {
// avoid values near 0.0;
if(value > 0.0 && value < 0.1) {
value = 0.1;
} else if (value < 0.0 && value > 0.9) {
value = 0.9;
}
}
return value * 1.2;
}

float panValue(){
// start each eye at a different position so it does not seem like they follow each other.
float offset = isLeft() ? 4. : 0.;
int t = int(mod(getSeed() + offset, 13.));

float panStops[13] = float[](
-0.4, -0.3, -0.4, -0.2,
0., 0.3, 0.2, 0.4,
0.25, 0.3, 0., -0.1,
-0.25
);
return panStops[t];
}

float tiltValue(){
if(horizon && !sky && !ground) {
int t = int(mod(getSeed(), 11.));
float tiltStops[11] = float[](
-1., -0.4, -0.6, -0.2,
0.2, 0.0, 0.5, 1.0,
0.2, -0.4, -0.7
);
return tiltStops[t];
}
int t = int(mod(getSeed(), 5.));
float tiltStops[5] = float[](
-1., -0.4, -0.6, -0.3,
-0.7
);

return tiltStops[t];
}

// @param inHead moving-head-params
// @param params moving-head-params
void main(in MovingHeadParams inHead, out MovingHeadParams params) {
params = inHead;

params.pan = pan(panValue());
params.tilt = tilt(tiltValue());

params.dimmer = round(time - getTimeOfLastBeat());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Filter for Moving Heads to adjust the dimmer to the beat.
// by Aravindo Wingeier

struct FixtureInfo {
vec3 position;
vec3 rotation;
mat4 transformation;
};

struct MovingHeadParams {
float pan;
float tilt;
float colorWheel;
float dimmer;
};

uniform FixtureInfo fixtureInfo;


uniform float time; // @@Time
#define PI 3.14159265358979323846
uniform BeatInfo beatInfo; // @@baaahs.BeatLink:BeatInfo
#define SIMULATE_BPM false
uniform bool lightBeat; // @@Switch enabled=true

float getBPM() {
if (SIMULATE_BPM) {
return 120.;
} else {
return beatInfo.bpm;
}
}


float getTimeOfLastBeat() {
// SIM:
if(SIMULATE_BPM){
float bpm = getBPM();
float beatDuration = 60. / bpm;
float timeSince2Beats = mod(time * beatDuration, beatDuration );
return time - timeSince2Beats;
} else {
// real:
float beatDuration = 60. / getBPM();
float timeSince2Beats = mod(beatInfo.beat, 1.) * beatDuration;
return time - timeSince2Beats;
}
}

/* Test function for ShaderToy */
float beatIntensity() {
if(SIMULATE_BPM){
float bpm = getBPM();
float t = mod(time * bpm / 60., 1.);
return smoothstep(1., 0., t / 0.25) + smoothstep(1., 0., (1. - t) / 0.1);
} else {
return beatInfo.intensity;
}
}


// @param inHead moving-head-params
// @param params moving-head-params
void main(in MovingHeadParams inHead, out MovingHeadParams params) {
params = inHead;

if(lightBeat){
params.dimmer = beatIntensity();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Change colors of Moving Head fixtures. We should add a color selector here.
// by Aravindo Wingeier

struct FixtureInfo {
vec3 position;
vec3 rotation;
mat4 transformation;
};

struct MovingHeadParams {
float pan;
float tilt;
float colorWheel;
float dimmer;
};

struct BeatInfo {
float beat;
float bpm;
float intensity;
float confidence;
};
uniform BeatInfo beatInfo; // @@baaahs.BeatLink:BeatInfo

uniform FixtureInfo fixtureInfo;

uniform float time; // @@Time
uniform bool rotateColor; // @@Switch enabled=true
uniform bool changeColorOnBeat; // @@Switch enabled=true


#define SIMULATE_BPM false

float getBPM() {
if (SIMULATE_BPM) {
return 120.;
} else {
return beatInfo.bpm;
}
}

float getTimeOfLastBeat() {
// SIM:
if(SIMULATE_BPM){
float bpm = getBPM();
float beatDuration = 60. / bpm;
float timeSince2Beats = mod(time * beatDuration, beatDuration );
return time - timeSince2Beats;
} else {
// real:
float beatDuration = 60. / getBPM();
float timeSince2Beats = mod(beatInfo.beat, 1.) * beatDuration;
return time - timeSince2Beats;
}
}

float getSeed(){
return getTimeOfLastBeat() * getBPM() / 60.;
}

// @param inHead moving-head-params
// @param params moving-head-params
void main(in MovingHeadParams inHead, out MovingHeadParams params) {
params = inHead;

if(changeColorOnBeat) {
params.colorWheel = mod(getSeed(), 10.)/10.;
} else if(rotateColor){
params.colorWheel = sin(time/5.);
}
}
Loading