I'm working with Brad Larson's GPUImage, which I've found to be really amazing. For flexibility and ease of writing, I've created a custom filter that has 3 uniform inputs. I based it on the GPUImageBrightnessFilter.h and .m. One uniform is simply a "parameter" float, one is a "center" CGPoint to feed in touch coordinates if I need them, and one will hopefully be a time float which is the amount of time that has elapsed since the shader was started. I'm using initWithFragmentShaderFromFile
to use my own shader files.
My "parameter" and "center" uniforms work. It's the time uniform that doesn't work because I don't understand how to create a uniform that is constantly changing (as time does).
The goal of my time uniform seems to be similar to SpriteKit's u_time
. It returns the number of seconds since the current shader has been running which you can feed into your custom shader to animate it. One very simple example use might be to cycle the hue of an image as time passes. I'm hoping to build upon that with more complexity as my knowledge of GLSL grows.
I'm not sure what code to post, as my misunderstanding could be in many places and it may be that I'm trying to do something that's not possible. This post about setting a start time and subtracting it from CACurrentMediaTime()
seems like a good place to start:
Getting the time elapsed (Objective-c)
The problem is I'm not sure how to continually update a uniform to pass to my shader. Do I do it in my custom filter's setter for time? Don't custom setter's only get executed once? Do I do it in my init override? Doesn't that only get executed once? Do I write a loop in my controller that continually calls the setter? That seems like an expensive and messy solution.
I'm not asking for code, just suggestions to steer me in the right direction or un-steer me from whatever wrong direction I've gone in my thinking.