-
-
Notifications
You must be signed in to change notification settings - Fork 192
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 a convenient hook for Postprocessors to update #2416
Comments
I have personally been doing something like this: class MyActor extends ex.Actor {
effect = new SomePostProcessor()
onInitialize(engine) {
engine.graphicsContext.addPostProcessor(this.effect)
const shader = this.effect.getShader()
// set initial uniforms, otherwise shader errors
shader.use()
shader.setUniformFloat('u_time', 0)
}
onPreUpdate() {
const shader = this.effect.getShader()
shader.use()
shader.setUniformFloat('u_time', someValue)
}
} which I honestly haven't minded to this point, but this is about as complex as my usage has gotten. A lifecycle hook that allows me to set the uniforms once instead of both in initialize and an update loop would be nice. Possibly something that abstracts I guess another thought I have is, if |
@mattjennings I like what you've done here! That's a pretty convenient work around at the moment. I think it makes sense to have a shader specific lifecycle hook for the situation you describe. Perhaps something specific like It's probably worth including a few well known uniforms by default (definitely Things that look useful on first glance might be I'd want to also document a way to include additional textures into the composition as well. |
That all sounds good to me! A set of well-known uniforms from ShaderToy would be awesome. It seems to be the go-to for examples, and it would really help newcomers like myself with migrating to Excalibur. |
This issue hasn't had any recent activity lately and is being marked as stale automatically. |
Closes #2416 This PR adds some new default uniforms supplied to postprocessors automatically if they are present in the source * `uniform float u_time_ms` - total playback time in milliseconds * `uniform float u_elapsed_ms` - the elapsed time from the last frame in milliseconds * `uniform vec2 u_resolution` - the resolution of the canvas (in pixels) Custom uniforms can now be set in an optional `onUpdate()` function on postprocessors, the internal `shader.use()` is called for users. Example using the CRT post processor, see gist https://gist.github.com/eonarheim/5ebb7f9161c10894935479e0caa0f6c7 <img width="677" alt="image" src="https://github.com/excaliburjs/Excalibur/assets/612071/07521591-934b-4aec-b77b-a01c8488025b">
Context
Currently there is no lifecycle hook for postprocessors to update over time.
See discussion #2415
Proposal
Add some sort of hook that allows users to update uniforms after the shader has been bound.
Perhaps a
onPreRender()
orupdate
? Not sure what makes the most sense?The text was updated successfully, but these errors were encountered: