markusfisch / ShaderEditor

Android app to create GLSL shaders and use them as live wallpaper
https://play.google.com/store/apps/details?id=de.markusfisch.android.shadereditor
MIT License
911 stars 136 forks source link

Not stateless shaders #93

Open michalelektryk opened 4 years ago

michalelektryk commented 4 years ago

Currently our creations have to be stateless, except for lastFrame. could we also output to another framebuffer object or something to be able to store some parameters. For eg. I want to make planets on top of changing background. I can't always deduce position of the planets from last frame and also can't change planets positions to be stateless as I want to influence them with my fingertips

fekga commented 4 years ago

Until this feature gets added there is a workaround even if it's not an easy way. You can use some of the backbuffer's pixel to store positions or any data that fits the RGB values, you can even store through multiple pixels but it complicates things even more. You just have to take care of reading and updating these values.

michalelektryk commented 4 years ago

I see. It's kind of hard but should be doable, thanks

sambeard commented 4 years ago

One more important use for maintaining a complex state would be a non linear time increase. The time uniform is definitely the most important uniform when it comes to animation for me. At the moment my animation variable(s) is/ are a linear function of time and any other uniform I would like to use. This works fine in a lot of cases however when changing the 'speed' at which the animation moves the point in time also changes. This can give unexpected, chaotic behaviour which is often unpleasant to the eye. My proposition is to have a speed increment and accumulated 'time' variable, possibly part of a larger buffer. I do not completely understand the GPU pipeline but I believe updating these variables in the fragment shader is not ideal and probably not a good practice but also not impossible. Having a state object which serves as this buffer, with allocated space for these types of variables would be a versatile solution. I hope some other people recognise this struggle and thanks in advance for looking in to this problem

Mehran7kl commented 2 years ago

i noticed this problem, and i don't know how this happens because the time uniform get updated every frame , maybe the system delays updating. in this case a glFinish and glFlush might solve the problem. @markusfisch please test this. i think glFinish solves the problem, but many things are realy arguable here. https://www.khronos.org/opengl/wiki/Synchronization#Asynchronous_action https://community.khronos.org/t/glflush-glfinish/24451 https://stackoverflow.com/questions/70722072/timing-for-update-of-uniforms-in-opengl