help writing a Material that fires once from a Cue
  • looseopinions
    member
    Posts: 10
    Joined: Tue Oct 19, 2021 1:57 am

    help writing a Material that fires once from a Cue

    by looseopinions » Tue Jun 28, 2022 4:31 am

    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?
  • Pierre Guilluy
    garageCube team
    Posts: 451
    Joined: Mon Oct 12, 2015 1:50 pm

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

    by Pierre Guilluy » Thu Jun 30, 2022 3:50 pm

    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).
    Attachments
    Screenshot 2022-06-30 at 15.48.03.png
    Screenshot 2022-06-30 at 15.48.03.png (27.91 KiB) Viewed 1807 times
  • looseopinions
    member
    Posts: 10
    Joined: Tue Oct 19, 2021 1:57 am

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

    by looseopinions » Sat Jul 02, 2022 9:24 pm

    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);
    }
  • Pierre Guilluy
    garageCube team
    Posts: 451
    Joined: Mon Oct 12, 2015 1:50 pm

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

    by Pierre Guilluy » Mon Jul 04, 2022 9:24 am

    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...

Who is online

Users browsing this forum: No registered users and 14 guests