-
Notifications
You must be signed in to change notification settings - Fork 13
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 characters
144 changes: 144 additions & 0 deletions
144
src/commonMain/resources/shader-libraries/built-in/movers/Movers Beats.glsl
This file contains 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 characters
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 | ||
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()); | ||
} |
72 changes: 72 additions & 0 deletions
72
src/commonMain/resources/shader-libraries/built-in/movers/Movers Brightness Filter.glsl
This file contains 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 characters
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(); | ||
} | ||
|
||
|
||
} |
71 changes: 71 additions & 0 deletions
71
src/commonMain/resources/shader-libraries/built-in/movers/Movers Color Filter.glsl
This file contains 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 characters
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.); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.