Page 1 of 1

help writing a Material that fires once from a Cue

Posted: Tue Jun 28, 2022 4:31 am
by looseopinions
Hi, I'm putting together a project and I would like to use a Cue to trigger a single strobe flash. My thought was to use an ISF or a Material such as the Strobe material, and modify it to fire once rather than loop. I've written a little bit of shader code but this was not as easy as I had hoped. I thought I could create an input EVENT button which I could trigger with a Cue but I am having trouble working out the code to do this?

Or does anyone have alternative way to fire a single non-looping flash from a Cue?

Re: help writing a Material that fires once from a Cue

Posted: Thu Jun 30, 2022 3:50 pm
by Pierre Guilluy
Here's a super simple solution to your problem:

Create a new material with the following code:

/*{
"CREDIT": "One Flash",
"DESCRIPTION": "the material will flash white once",
"TAGS": "flash",
"VSN": "1.0",
"INPUTS": [
{"LABEL": "Duration", "NAME": "duration", "TYPE": "float", "MIN": 0.0, "MAX": 10.0, "DEFAULT": 1.0 },
],
"GENERATORS": [
{"NAME": "mat_time", "TYPE": "time_base" },
],
}*/

vec4 materialColorForPixel( vec2 texCoord )
{
if (mat_time < duration)
return vec4(1.);
else
return vec4(0.);
}

It will display white for "duration" seconds, then black.

Finally it's just a matter of cueing the "restart" parameter of your material so its time will restart anytime your trigger your cue (cf screenshot).

Re: help writing a Material that fires once from a Cue

Posted: Sat Jul 02, 2022 9:24 pm
by looseopinions
Great! Thanks for getting me unstuck. I added a decay to the flash, and an easing curve in either direction. Next up I'm going to work on a full featured Attack / Hold / Decay and I also plan to add bpm sync.

It would be great if I could figure out how to not make it fire on its own the first time. In other words is there a way to pause it on the last frame, and only trigger it from the beginning when I hit Restart?

Here is what I have so far:

/*{
"CREDIT": "One Flash",
"DESCRIPTION": "the material will flash white once",
"TAGS": "flash",
"VSN": "1.0",
"INPUTS": [
{"LABEL": "Duration", "NAME": "mat_duration", "TYPE": "float", "MIN": 0.0, "MAX": 10.0, "DEFAULT": 1.0 },
{"LABEL": "Curve", "NAME": "mat_curve", "TYPE": "float", "MIN": 0.25, "MAX": 2.0, "DEFAULT": 1.0 },
{"LABEL": "Reverse", "NAME": "mat_reverse", "TYPE": "bool", "DEFAULT": false, "FLAGS": "button" },
],
"GENERATORS": [
{"NAME": "mat_time", "TYPE": "time_base" },
],
}*/

vec4 materialColorForPixel( vec2 texCoord )
{
if (mat_time < mat_duration)
if(mat_reverse) return vec4((mat_time/mat_curve)/mat_duration);
else return vec4((mat_duration - (mat_time/mat_curve))/mat_duration);
}

Re: help writing a Material that fires once from a Cue

Posted: Mon Jul 04, 2022 9:24 am
by Pierre Guilluy
It would be great if I could figure out how to not make it fire on its own the first time. In other words is there a way to pause it on the last frame, and only trigger it from the beginning when I hit Restart?
I'm not sure to understand your request, but remember you can add parameters that can be controlled / faded using the cues, so I guess you can figure out a way to trigger an action when a parameter reaches a certain value for instance...