@WANotes on random start points for backgrounds
===================================
By referencing a texture by its folder name rather than file name, iStripper would draw one texture at random from the folder. This meant you could build a scene that could look different at every launch depending on which random textures were selected.
@WA has used this in his 3D gallery so that backgrounds chosen are all random. One issue is that when picking multiple backgrounds for a gallery effect the random selection can be a repeat of one already chosen.
I wanted a sequence of shader backgrounds that could play at random with a different start point each time and a random sequence. To play each shader once until it got to the end and then start again but in another random order.
If there's a simple solution to this problem, I couldn't think of one so I thought up a complicated solution instead.
I got around this problem by creating many copies of one image with one pixel changed to encode a serial number.
The scene file would pick one of those images at random and each shader would reference that one random image. The shader then decodes the random serial number:
vec4 vT = gl_TexCoord[0];
float randNum1 = texture(texture1, vec2(0.,0.)).a;
Next some creaky maths then gets each shader to switch itself on and off at a precise time. The shaders are built up on top of each other like in an image gallery however each shader needs to appear to fade into the next so it also needs to know whether the next shader to be shown is above or below it in the hard coded stack in the scn file. If we are above then the current shader will fade out whilst the new one is already visible. If we are below then the shader showing will continue whilst the new shader above will fade in.
For the random(ish) sequence I had the shader code select one random interval from an array of possible intervals and add this interval each scene change. So for example if we started on shader no 3 and the interval was say 7, the 47 shaders would be shown in this order: 3, 10, 17, 24, 31, 38, 45, 52... but 52 is out of range so we cycle back to the beggining 52-47 = 5 and then 5+7 = 12 and so on 19, 26, 33 etc etc
The code for all of this was built into all of the individual shaders, so they all run to the exact same timing, The shaders are called from the scene file with each one having some hard coded extra uniforms so that each one knows its job e.g:
// Scene: 35
// Source: https://www.shadertoy.com/view/sdlXRj
// By: FabriceNeyret2 (...or Forked by)
// Title: flownoise-isolined Britney stric
sprite {
source: Girl, 0
source: Font, 3
size: 3840, 2160
//size: 1920, 1080
uniform: scene_duration, float, 18
uniform: bgnum, float, 35
uniform: maxbgnum, float, 47
shader: fragment, shaders/timed/ti-r-sdlXRj.fsh
//scale: 2.0, 2.0
}
In the above..... this shader "knows" there are 47 shaders in total
uniform: maxbgnum, float, 47
and that it is number 35
uniform: bgnum, float, 35
and that we are showing the sequence in intervals of 18 seconds
uniform: scene_duration, float, 18
It is given a random image file which all other shaders will also receive from which it extracts the random serial number:
source: Font, 3
and hey presto ! Each shader turns itself on and off at the desired time but every time you run the scene it will be different.
@WAModifying this to work with a gallery of images instead of shaders should be quite "do-able". It needs the image textures to be hard coded into the scene file by file not folder and then an equivalent number of shader callers in a stack that are coded to switch their gallery image on and off at the required timing.