AcademySoftwareFoundation / openfx

OpenFX effects API
Other
393 stars 119 forks source link

Deterministic per-frame RNG #164

Open gregcotten opened 3 weeks ago

gregcotten commented 3 weeks ago

I'm just stubbing this issue for now, but some context:

One of our plugins uses kOfxPropTime to seed its RNG so we can do deterministically random things per-frame so when render is called on that frame, the frame looks the same, every time. kOfxPropTime isn't necessarily unique, and could be repeated for multiple clips depending on how the host uses it. It would be useful to have some sort of "per plugin instance" way of seeding the RNG, so that randomness is calculated as a combination of the plugin instance's unique ID and the current kOfxPropTime.

I have also considered storing some sort of secret property on the plugin instance that defaults to 0 but then is immediately replaced with a random number if its value is 0, but that behavior is kind of weird and probably most hosts implementations of copying parameters from one plugin instance to another would simply copy the random number I generated over to another instance, which is not desired.

Has anyone thought about how one might do this without adding anything to OpenFX?

john-paulsmith commented 3 days ago

Quite a few plug-ins have needed things like this over the years, but it's usually done with a visible seed parameter that's initialised to a random number. The reason you want a visible parameter is so that the user can set it manually to get an identical, predictable effect. If you want the user to be able to "roll the dice" to get random looks, you could include a re-seed button.

gregcotten commented 3 days ago

Quite a few plug-ins have needed things like this over the years, but it's usually done with a visible seed parameter that's initialised to a random number. The reason you want a visible parameter is so that the user can set it manually to get an identical, predictable effect. If you want the user to be able to "roll the dice" to get random looks, you could include a re-seed button.

For sure! We have a checkbox for "automatic" RNG mode that can be unchecked to reveal the underlying seed parameter. Unfortunately still the pitfall of hosts naively copying this parameter around when duplicating instances of the plugin when the user likely doesn't want this parameter copied still arise! There doesn't really seem to be much for the plugin to do here to mitigate things like that.

Also, in a "progressive disclosure" sense, I'd rather the user not have to manually manage the seed until they know they need to - our plugin should "do the right thing" until then. Just looking for a creative solution that allows for the plugin user to not have to worry about two plugin instances having identical RNG until they actually want that to happen.