Skip to content

CoronaTotalTime

Steven Johnson edited this page Jan 9, 2019 · 11 revisions

The bare minima on OpenGLES2 are quite easy to overflow, cf. the "Qualifiers" section in the cheat sheet. For instance, even before floating-point numbers become integer-only or start incrementing by 2, 4, etc. we would get very crude interpolation, with the results relying upon such values becoming quite choppy. With mediump and 210 = 1024 full integers, we can only interpolate by steps of .25 from 128 to 256, so roughly the time from 2-4 minutes! Followed by increments of 1/2 between 256 and 512, then down to 1 next, and so on.

This gloomy scenario only captures part of what's going on, of course. The time is actually maintained in Lua as a single-precision float, with a rather more generous 23-bit mantissa. Furthermore, a huge number of shaders could use a MUCH smaller value derived from the time, e.g. those built on simple patterns or trigonometric functions that have narrow periods such as some low multiple of pi. In these cases the shader could receive, say, TrueTotalTime % X, or even just sin(N * TrueTotalTime) directly, seeing only the transformed result.

In practice, I don't know if there would be a wide selection of function to choose from; I think it would mostly be what's listed above, maybe using a gcd or lcm of several periods. In theory a Lua function could be provided, but maybe not necessary. In any event, it seems viable as a parameter to graphics.defineEffect, perhaps along with a couple arguments.