Author Topic: Animated Backgrounds?  (Read 52571 times)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #90 on: December 14, 2019, 04:50:41 pm »
Thanks!

Here are a few more

generators.fs
Code: [Select]
// "GENERATORS REDUX" by Kali

// Same fractal as "Ancient Temple" + rotations, improved shading
// (better coloring, AO and  shadows), some lighting effects, and a path for the camera 
// following a liquid metal ball.

uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

uniform sampler2D BWNoiseBig_png;

#define ENABLE_HARD_SHADOWS // turn off to enable faster AO soft shadows
//#define ENABLE_VIBRATION
#define ENABLE_POSTPROCESS // Works better on window view rather than full screen


#define RAY_STEPS 70
#define SHADOW_STEPS 50
#define LIGHT_COLOR vec3(.85,.9,1.)
#define AMBIENT_COLOR vec3(.8,.83,1.)
#define FLOOR_COLOR vec3(1.,.7,.9)
#define ENERGY_COLOR vec3(1.,.7,.4)
#define BRIGHTNESS .9
#define GAMMA 1.3
#define SATURATION .85


#define detail .00005
#define t iTime*.25



vec3 lightdir=normalize(vec3(0.5,-0.3,-1.));
vec3 ambdir=normalize(vec3(0.,0.,1.));
const vec3 origin=vec3(0.,3.11,0.);
vec3 energy=vec3(0.01);
#ifdef ENABLE_VIBRATION
float vibration=sin(iTime*60.)*.0013;
#else
float vibration=0.;
#endif
float det=0.0;
vec3 pth1;


mat2 rot(float a) {
return mat2(cos(a),sin(a),-sin(a),cos(a));
}


vec3 path(float ti) {
return vec3(sin(ti),.3-sin(ti*.632)*.3,cos(ti*.5))*.5;
}

float Sphere(vec3 p, vec3 rd, float r){//A RAY TRACED SPHERE
float b = dot( -p, rd );
float inner = b * b - dot( p, p ) + r * r;
if( inner < 0.0 ) return -1.0;
return b - sqrt( inner );
}

vec2 de(vec3 pos) {
float hid=0.;
vec3 tpos=pos;
tpos.xz=abs(.5-mod(tpos.xz,1.));
vec4 p=vec4(tpos,1.);
float y=max(0.,.35-abs(pos.y-3.35))/.35;
for (int i=0; i<7; i++) {//LOWERED THE ITERS
p.xyz = abs(p.xyz)-vec3(-0.02,1.98,-0.02);
p=p*(2.0+vibration*y)/clamp(dot(p.xyz,p.xyz),.4,1.)-vec4(0.5,1.,0.4,0.);
p.xz*=mat2(-0.416,-0.91,0.91,-0.416);
}
float fl=pos.y-3.013;
float fr=(length(max(abs(p.xyz)-vec3(0.1,5.0,0.1),vec3(0.0)))-0.05)/p.w;//RETURN A RRECT
//float fr=length(p.xyz)/p.w;
float d=min(fl,fr);
d=min(d,-pos.y+3.95);
if (abs(d-fl)<.001) hid=1.;
return vec2(d,hid);
}


vec3 normal(vec3 p) {
vec3 e = vec3(0.0,det,0.0);

return normalize(vec3(
de(p+e.yxx).x-de(p-e.yxx).x,
de(p+e.xyx).x-de(p-e.xyx).x,
de(p+e.xxy).x-de(p-e.xxy).x
)
);
}

float shadow(vec3 pos, vec3 sdir) {//THIS ONLY RUNS WHEN WITH HARD SHADOWS
float sh=1.0;
float totdist =2.0*det;
float dist=10.;
float t1=Sphere((pos-.005*sdir)-pth1,-sdir,0.015);
if (t1>0. && t1<.5) {
vec3 sphglowNorm=normalize(pos-t1*sdir-pth1);
sh=1.-pow(max(.0,dot(sphglowNorm,sdir))*1.2,3.);
}
for (int steps=0; steps<SHADOW_STEPS; steps++) {
if (totdist<.6 && dist>detail) {
vec3 p = pos - totdist * sdir;
dist = de(p).x;
sh = min( sh, max(50.*dist/totdist,0.0) );
totdist += max(.01,dist);
}
}

    return clamp(sh,0.1,1.0);
}


float calcAO( const vec3 pos, const vec3 nor ) {
float aodet=detail*40.;
float totao = 0.0;
    float sca = 14.0;
    for( int aoi=0; aoi<5; aoi++ ) {
        float hr = aodet*float(aoi*aoi);
        vec3 aopos =  nor * hr + pos;
        float dd = de( aopos ).x;
        totao += -(dd-hr)*sca;
        sca *= 0.7;
    }
    return clamp( 1.0 - 5.0*totao, 0., 1.0 );
}

float _texture(vec3 p) {
p=abs(.5-fract(p*10.));
vec3 c=vec3(3.);
float es, l=es=0.;
for (int i = 0; i < 10; i++) {
p = abs(p + c) - abs(p - c) - p;
p/= clamp(dot(p, p), .0, 1.);
p = p* -1.5 + c;
if ( mod(float(i), 2.) < 1. ) {
float pl = l;
l = length(p);
es+= exp(-1. / abs(l - pl));
}
}
return es;
}

vec3 light(in vec3 p, in vec3 dir, in vec3 n, in float hid) {//PASSING IN THE NORMAL
#ifdef ENABLE_HARD_SHADOWS
float sh=shadow(p, lightdir);
#else
float sh=calcAO(p,-2.5*lightdir);//USING AO TO MAKE VERY SOFT SHADOWS
#endif
float ao=calcAO(p,n);
float diff=max(0.,dot(lightdir,-n))*sh;
float y=3.35-p.y;
vec3 amb=max(.5,dot(dir,-n))*.5*AMBIENT_COLOR;
if (hid<.5) {
amb+=max(0.2,dot(vec3(0.,1.,0.),-n))*FLOOR_COLOR*pow(max(0.,.2-abs(3.-p.y))/.2,1.5)*2.;
amb+=energy*pow(max(0.,.4-abs(y))/.4,2.)*max(0.2,dot(vec3(0.,-sign(y),0.),-n))*2.;
}
vec3 r = reflect(lightdir,n);
float spec=pow(max(0.,dot(dir,-r))*sh,10.);
vec3 col;
float energysource=pow(max(0.,.04-abs(y))/.04,4.)*2.;
if (hid>1.5) {col=vec3(1.); spec=spec*spec;}
else{
float k=_texture(p)*.23+.2;
k=min(k,1.5-energysource);
col=mix(vec3(k,k*k,k*k*k),vec3(k),.3);
if (abs(hid-1.)<.001) col*=FLOOR_COLOR*1.3;
}
col=col*(amb+diff*LIGHT_COLOR)+spec*LIGHT_COLOR;
if (hid<.5) {
col=max(col,energy*2.*energysource);
}
col*=min(1.,ao+length(energy)*.5*max(0.,.1-abs(y))/.1);
return col;
}

vec3 raymarch(in vec3 from, in vec3 dir)

{
float ey=mod(t*.5,1.);
float glow,eglow,ref,sphdist,totdist=glow=eglow=ref=sphdist=0.;
vec2 d=vec2(1.,0.);
vec3 p, col=vec3(0.);
vec3 origdir=dir,origfrom=from,sphNorm;

//FAKING THE SQUISHY BALL BY MOVING A RAY TRACED BALL
vec3 wob=cos(dir*500.0*length(from-pth1)+(from-pth1)*250.+iTime*10.)*0.0005;
float t1=Sphere(from-pth1+wob,dir,0.015);
float tg=Sphere(from-pth1+wob,dir,0.02);
if(t1>0.){
ref=1.0;from+=t1*dir;sphdist=t1;
sphNorm=normalize(from-pth1+wob);
dir=reflect(dir,sphNorm);
}
else if (tg>0.) {
vec3 sphglowNorm=normalize(from+tg*dir-pth1+wob);
glow+=pow(max(0.,dot(sphglowNorm,-dir)),5.);
};

for (int i=0; i<RAY_STEPS; i++) {
if (d.x>det && totdist<3.0) {
p=from+totdist*dir;
d=de(p);
det=detail*(1.+totdist*60.)*(1.+ref*5.);
totdist+=d.x;
energy=ENERGY_COLOR*(1.5+sin(iTime*20.+p.z*10.))*.25;
if(d.x<0.015)glow+=max(0.,.015-d.x)*exp(-totdist);
if (d.y<.5 && d.x<0.03){//ONLY DOING THE GLOW WHEN IT IS CLOSE ENOUGH
float glw=min(abs(3.35-p.y-ey),abs(3.35-p.y+ey));//2 glows at once
eglow+=max(0.,.03-d.x)/.03*
(pow(max(0.,.05-glw)/.05,5.)
+pow(max(0.,.15-abs(3.35-p.y))/.15,8.))*1.5;
}
}
}
float l=pow(max(0.,dot(normalize(-dir.xz),normalize(lightdir.xz))),2.);
l*=max(0.2,dot(-dir,lightdir));
vec3 backg=.5*(1.2-l)+LIGHT_COLOR*l*.7;
backg*=AMBIENT_COLOR;
if (d.x<=det) {
vec3 norm=normal(p-abs(d.x-det)*dir);//DO THE NORMAL CALC OUTSIDE OF LIGHTING (since we already have the sphere normal)
col=light(p-abs(d.x-det)*dir, dir, norm, d.y)*exp(-.2*totdist*totdist);
col = mix(col, backg, 1.0-exp(-1.*pow(totdist,1.5)));
} else {
col=backg;
}
vec3 lglow=LIGHT_COLOR*pow(l,30.)*.5;
col+=glow*(backg+lglow)*1.3;
col+=pow(eglow,2.)*energy*.015;
col+=lglow*min(1.,totdist*totdist*.3);
if (ref>0.5) {
vec3 sphlight=light(origfrom+sphdist*origdir,origdir,sphNorm,2.);
col=mix(col*.3+sphlight*.7,backg,1.0-exp(-1.*pow(sphdist,1.5)));
}
return col;
}

vec3 move(inout mat2 rotview1,inout mat2 rotview2) {
vec3 go=path(t);
vec3 adv=path(t+.7);
vec3 advec=normalize(adv-go);
float an=atan(advec.x,advec.z);
rotview1=mat2(cos(an),sin(an),-sin(an),cos(an));
  an=advec.y*1.7;
rotview2=mat2(cos(an),sin(an),-sin(an),cos(an));
return go;
}


void main()
{
pth1 = path(t+.3)+origin+vec3(0.,.01,0.);
vec2 uv = gl_FragCoord.xy / iResolution.xy*2.-1.;
vec2 uv2=uv;
#ifdef ENABLE_POSTPROCESS
uv*=1.+pow(length(uv2*uv2*uv2*uv2),4.)*.07;
#endif
uv.y*=iResolution.y/iResolution.x;
vec2 mouse=(iMouse.xy/iResolution.xy-.5)*3.;
if (iMouse.z<1.) mouse=vec2(0.);
mat2 rotview1, rotview2;
vec3 from=origin+move(rotview1,rotview2);
vec3 dir=normalize(vec3(uv*.8,1.));
dir.yz*=rot(mouse.y);
dir.xz*=rot(mouse.x);
dir.yz*=rotview2;
dir.xz*=rotview1;
vec3 color=raymarch(from,dir);
color=clamp(color,vec3(.0),vec3(1.));
color=pow(color,vec3(GAMMA))*BRIGHTNESS;
color=mix(vec3(length(color)),color,SATURATION);
#ifdef ENABLE_POSTPROCESS
vec3 rain=pow(texture(BWNoiseBig_png,uv2+iTime*7.25468).rgb,vec3(1.5));
color=mix(rain,color,clamp(iTime*.5-.5,0.,1.));
color*=1.-pow(length(uv2*uv2*uv2*uv2)*1.1,6.);
uv2.y *= iResolution.y / 360.0;
color.r*=(.5+abs(.5-mod(uv2.y     ,.021)/.021)*.5)*1.5;
color.g*=(.5+abs(.5-mod(uv2.y+.007,.021)/.021)*.5)*1.5;
color.b*=(.5+abs(.5-mod(uv2.y+.014,.021)/.021)*.5)*1.5;
color*=.9+rain*.35;
#endif
gl_FragColor = vec4(color,1.);
}

Simplicity_Galaxy.fs
Code: [Select]
// Created by Reinder Nijhoff 2014
// Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
// @reindernijhoff
//
// https://www.shadertoy.com/view/Xtf3zn
//
// car model is made by Eiffie
// shader 'Shiny Toy': https://www.shadertoy.com/view/ldsGWB

uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

#define BUMPMAP
#define MARCHSTEPS 128
#define MARCHSTEPSREFLECTION 48
#define LIGHTINTENSITY 5.

//----------------------------------------------------------------------

const vec3 backgroundColor = vec3(0.2,0.4,0.6) * 0.09;
#define time (iTime + 90.)

//----------------------------------------------------------------------
// noises

float hash( float n ) {
    return fract(sin(n)*687.3123);
}

float noise( in vec2 x ) {
    vec2 p = floor(x);
    vec2 f = fract(x);
    f = f*f*(3.0-2.0*f);
    float n = p.x + p.y*157.0;
    return mix(mix( hash(n+  0.0), hash(n+  1.0),f.x),
               mix( hash(n+157.0), hash(n+158.0),f.x),f.y);
}

const mat2 m2 = mat2( 0.80, -0.60, 0.60, 0.80 );

float fbm( vec2 p ) {
    float f = 0.0;
    f += 0.5000*noise( p ); p = m2*p*2.02;
    f += 0.2500*noise( p ); p = m2*p*2.03;
    f += 0.1250*noise( p ); p = m2*p*2.01;
//    f += 0.0625*noise( p );
   
    return f/0.9375;
}

//----------------------------------------------------------------------
// distance primitives

float udRoundBox( vec3 p, vec3 b, float r ) {
  return length(max(abs(p)-b,0.0))-r;
}

float sdBox( in vec3 p, in vec3 b ) {
    vec3 d = abs(p) - b;
    return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
}

float sdSphere( in vec3 p, in float s ) {
    return length(p)-s;
}

float sdCylinder( in vec3 p, in vec2 h ) {
    vec2 d = abs(vec2(length(p.xz),p.y)) - h;
    return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}

//----------------------------------------------------------------------
// distance operators

float opU( float d2, float d1 ) { return min( d1,d2); }
float opS( float d2, float d1 ) { return max(-d1,d2); }
float smin( float a, float b, float k ) { return -log(exp(-k*a)+exp(-k*b))/k; } //from iq

//----------------------------------------------------------------------
// Map functions

// car model is made by Eiffie
// shader 'Shiny Toy': https://www.shadertoy.com/view/ldsGWB

float mapCar(in vec3 p0){
vec3 p=p0+vec3(0.0,1.24,0.0);
float r=length(p.yz);
float d= length(max(vec3(abs(p.x)-0.35,r-1.92,-p.y+1.4),0.0))-0.05;
d=max(d,p.z-1.0);
p=p0+vec3(0.0,-0.22,0.39);
p.xz=abs(p.xz)-vec2(0.5300,0.9600);p.x=abs(p.x);
r=length(p.yz);
d=smin(d,length(max(vec3(p.x-0.08,r-0.25,-p.y-0.08),0.0))-0.04,8.0);
d=max(d,-max(p.x-0.165,r-0.24));
float d2=length(vec2(max(p.x-0.13,0.0),r-0.2))-0.02;
d=min(d,d2);

return d;
}

float dL; // minimal distance to light

float map( const in vec3 p ) {
vec3 pd = p;
    float d;
   
    pd.x = abs( pd.x );
    pd.z *= -sign( p.x );
   
    float ch = hash( floor( (pd.z+18.*time)/40. ) );
    float lh = hash( floor( pd.z/13. ) );
   
    vec3 pdm = vec3( pd.x, pd.y, mod( pd.z, 10.) - 5. );
    dL = sdSphere( vec3(pdm.x-8.1,pdm.y-4.5,pdm.z), 0.1 );
   
    dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-9.5-lh,  mod( pd.z, 91.) - 45.5 ), vec3(0.2,4.5, 0.2) ) );
    dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-11.5+lh, mod( pd.z, 31.) - 15.5 ), vec3(0.22,5.5, 0.2) ) );
    dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-8.5-lh,  mod( pd.z, 41.) - 20.5 ), vec3(0.24,3.5, 0.2) ) );
   
    if( lh > 0.5 ) {
    dL = opU( dL, sdBox( vec3(pdm.x-12.5,pdm.y-2.75-lh,  mod( pd.z, 13.) - 6.5 ), vec3(0.1,0.25, 3.2) ) );
    }
   
    vec3 pm = vec3( mod( pd.x + floor( pd.z * 4. )*0.25, 0.5 ) - 0.25, pd.y, mod( pd.z, 0.25 ) - 0.125 );
d = udRoundBox( pm, vec3( 0.245,0.1, 0.12 ), 0.005 );
   
    d = opS( d, -(p.x+8.) );
    d = opU( d, pd.y );

    vec3 pdc = vec3( pd.x, pd.y, mod( pd.z+18.*time, 40.) - 20. );
   
    // car
    if( ch > 0.75 ) {
        pdc.x += (ch-0.75)*4.;
    dL = opU( dL, sdSphere( vec3( abs(pdc.x-5.)-1.05, pdc.y-0.55, pdc.z ),    0.025 ) );
    dL = opU( dL, sdSphere( vec3( abs(pdc.x-5.)-1.2,  pdc.y-0.65,  pdc.z+6.05 ), 0.025 ) );

        d = opU( d,  mapCar( (pdc-vec3(5.,-0.025,-2.3))*0.45 ) );
  }
   
    d = opU( d, 13.-pd.x );
    d = opU( d, sdCylinder( vec3(pdm.x-8.5, pdm.y, pdm.z), vec2(0.075,4.5)) );
    d = opU( d, dL );
   
return d;
}

//----------------------------------------------------------------------

vec3 calcNormalSimple( in vec3 pos ) {   
    const vec2 e = vec2(1.0,-1.0)*0.005;

    vec3 n = normalize( e.xyy*map( pos + e.xyy ) +
    e.yyx*map( pos + e.yyx )   +
    e.yxy*map( pos + e.yxy )   +
    e.xxx*map( pos + e.xxx )   ); 
    return n;
}

vec3 calcNormal( in vec3 pos ) {
    vec3 n = calcNormalSimple( pos );
    if( pos.y > 0.12 ) return n;

#ifdef BUMPMAP
    vec2 oc = floor( vec2(pos.x+floor( pos.z * 4. )*0.25, pos.z) * vec2( 2., 4. ) );

    if( abs(pos.x)<8. ) {
oc = pos.xz;
    }
   
     vec3 p = pos * 250.;
    vec3 xn = 0.05*vec3(noise(p.xz)-0.5,0.,noise(p.zx)-0.5);
     xn += 0.1*vec3(fbm(oc.xy)-0.5,0.,fbm(oc.yx)-0.5);
   
    n = normalize( xn + n );
#endif
   
    return n;
}

vec3 int1, int2, nor1;
vec4 lint1, lint2;

float intersect( in vec3 ro, in vec3 rd ) {
const float precis = 0.001;
    float h = precis*2.0;
    float t = 0.;
    int1 = int2 = vec3( -500. );
    lint1 = lint2 = vec4( -500. );
    float mld = 100.;
   
for( int i=0; i < MARCHSTEPS; i++ ) {
        h = map( ro+rd*t );
if(dL < mld){
mld=dL;
            lint1.xyz = ro+rd*t;
lint1.w = abs(dL);
}
        if( h < precis ) {
            int1.xyz = ro+rd*t;
            break;
        }
        t += max(h, precis*2.);
    }
   
    if( int1.z < -400. || t > 300.) {
        // check intersection with plane y = -0.1;
        float d = -(ro.y + 0.1)/rd.y;
if( d > 0. ) {
int1.xyz = ro+rd*d;
    } else {
        return -1.;
    }
    }
   
    ro = ro + rd*t;
    nor1 = calcNormal(ro);
    ro += 0.01*nor1;
    rd = reflect( rd, nor1 );
    t = 0.0;
    h = precis*2.0;
    mld = 100.;
   
    for( int i=0; i < MARCHSTEPSREFLECTION; i++ ) {
        h = map( ro+rd*t );
if(dL < mld){
mld=dL;           
            lint2.xyz = ro+rd*t;
lint2.w = abs(dL);
}
        if( h < precis ) {
    int2.xyz = ro+rd*t;
            return 1.;
        }   
        t += max(h, precis*2.);
    }

    return 0.;
}

//----------------------------------------------------------------------
// shade

vec3 shade( in vec3 ro, in vec3 pos, in vec3 nor ) {
    vec3  col = vec3(0.5);
   
    if( abs(pos.x) > 15. || abs(pos.x) < 8. ) col = vec3( 0.02 );
    if( pos.y < 0.01 ) {
        if( abs( int1.x ) < 0.1 ) col = vec3( 0.9 );
        if( abs( abs( int1.x )-7.4 ) < 0.1 ) col = vec3( 0.9 );
    }   
   
    float sh = clamp( dot( nor, normalize( vec3( -0.3, 0.3, -0.5 ) ) ), 0., 1.);
  col *= (sh * backgroundColor); 
 
    if( abs( pos.x ) > 12.9 && pos.y > 9.) { // windows
        float ha = hash(  133.1234*floor( pos.y / 3. ) + floor( (pos.z) / 3. ) );
        if( ha > 0.95) {
            col = ( (ha-0.95)*10.) * vec3( 1., 0.7, 0.4 );
        }
    }
   
col = mix(  backgroundColor, col, exp( min(max(0.1*pos.y,0.25)-0.065*distance(pos, ro),0.) ) );
 
    return col;
}

vec3 getLightColor( in vec3 pos ) {
    vec3 lcol = vec3( 1., .7, .5 );
   
vec3 pd = pos;
    pd.x = abs( pd.x );
    pd.z *= -sign( pos.x );
   
    float ch = hash( floor( (pd.z+18.*time)/40. ) );
    vec3 pdc = vec3( pd.x, pd.y, mod( pd.z+18.*time, 40.) - 20. );

    if( ch > 0.75 ) { // car
        pdc.x += (ch-0.75)*4.;
        if(  sdSphere( vec3( abs(pdc.x-5.)-1.05, pdc.y-0.55, pdc.z ), 0.25) < 2. ) {
            lcol = vec3( 1., 0.05, 0.01 );
        }
    }
    if( pd.y > 2. && abs(pd.x) > 10. && pd.y < 5. ) {
        float fl = floor( pd.z/13. );
        lcol = 0.4*lcol+0.5*vec3( hash( .1562+fl ), hash( .423134+fl ), 0. );
    }
    if(  abs(pd.x) > 10. && pd.y > 5. ) {
        float fl = floor( pd.z/2. );
        lcol = 0.5*lcol+0.5*vec3( hash( .1562+fl ),  hash( .923134+fl ), hash( .423134+fl ) );
    }
   
    return lcol;
}

float randomStart(vec2 co){return 0.8+0.2*hash(dot(co,vec2(123.42,117.853))*412.453);}

//----------------------------------------------------------------------
// main

void main() {   
    vec2 q = gl_FragCoord.xy / iResolution.xy;
vec2 p = -1.0 + 2.0*q;
p.x *= iResolution.x / iResolution.y;
       
    if (q.y < .12 || q.y >= .88) {
gl_FragColor=vec4(0.,0.,0.,1.);
return;
    } else {
   
        // camera
        float z = time;
        float x = -10.9+1.*sin(time*0.2);
        vec3 ro = vec3(x,  1.3+.3*cos(time*0.26), z-1.);
        vec3 ta = vec3(-8.,1.3+.4*cos(time*0.26), z+4.+cos(time*0.04));

        vec3 ww = normalize( ta - ro );
        vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) );
        vec3 vv = normalize( cross(uu,ww));
        vec3 rd = normalize( -p.x*uu + p.y*vv + 2.2*ww );

        vec3 col = backgroundColor;

        // raymarch
        float ints = intersect(ro+randomStart(p)*rd ,rd );
        if(  ints > -0.5 ) {

            // calculate reflectance
            float r = 0.09;             
            if( int1.y > 0.129 ) r = 0.025 * hash(  133.1234*floor( int1.y / 3. ) + floor( int1.z / 3. ) );
            if( abs(int1.x) < 8. ) {
                if( int1.y < 0.01 ) { // road
                    r = 0.007*fbm(int1.xz);
                } else { // car
                    r = 0.02;
                }
            }
            if( abs( int1.x ) < 0.1 ) r *= 4.;
            if( abs( abs( int1.x )-7.4 ) < 0.1 ) r *= 4.;

            r *= 2.;

            col = shade( ro, int1.xyz, nor1 );

            if( ints > 0.5 ) {
                col += r * shade( int1.xyz, int2.xyz, calcNormalSimple(int2.xyz) );
            } 
            if( lint2.w > 0. ) {           
                col += (r*LIGHTINTENSITY*exp(-lint2.w*7.0)) * getLightColor(lint2.xyz);
            }
        }

        // Rain (by Dave Hoskins)
        vec2 st = 256. * ( p* vec2(.5, .01)+vec2(time*.13-q.y*.6, time*.13) );
        float f = noise( st ) * noise( st*0.773) * 1.55;
        f = 0.25+ clamp(pow(abs(f), 13.0) * 13.0, 0.0, q.y*.14);

        if( lint1.w > 0. ) {
            col += (f*LIGHTINTENSITY*exp(-lint1.w*7.0)) * getLightColor(lint1.xyz);
        } 

        col += 0.25*f*(0.2+backgroundColor);

        // post processing
        col = pow( clamp(col,0.0,1.0), vec3(0.4545) );
        col *= 1.2*vec3(1.,0.99,0.95);   
        col = clamp(1.06*col-0.03, 0., 1.); 
        q.y = (q.y-.12)*(1./0.76);
        col *= 0.5 + 0.5*pow( 16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y), 0.1 );

        gl_FragColor = vec4( col, 1.0 );
    }
}

Tokyo.fs
Code: [Select]
// Created by Reinder Nijhoff 2014
// Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
// @reindernijhoff
//
// https://www.shadertoy.com/view/Xtf3zn
//
// car model is made by Eiffie
// shader 'Shiny Toy': https://www.shadertoy.com/view/ldsGWB

uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

#define BUMPMAP
#define MARCHSTEPS 128
#define MARCHSTEPSREFLECTION 48
#define LIGHTINTENSITY 5.

//----------------------------------------------------------------------

const vec3 backgroundColor = vec3(0.2,0.4,0.6) * 0.09;
#define time (iTime + 90.)

//----------------------------------------------------------------------
// noises

float hash( float n ) {
    return fract(sin(n)*687.3123);
}

float noise( in vec2 x ) {
    vec2 p = floor(x);
    vec2 f = fract(x);
    f = f*f*(3.0-2.0*f);
    float n = p.x + p.y*157.0;
    return mix(mix( hash(n+  0.0), hash(n+  1.0),f.x),
               mix( hash(n+157.0), hash(n+158.0),f.x),f.y);
}

const mat2 m2 = mat2( 0.80, -0.60, 0.60, 0.80 );

float fbm( vec2 p ) {
    float f = 0.0;
    f += 0.5000*noise( p ); p = m2*p*2.02;
    f += 0.2500*noise( p ); p = m2*p*2.03;
    f += 0.1250*noise( p ); p = m2*p*2.01;
//    f += 0.0625*noise( p );
   
    return f/0.9375;
}

//----------------------------------------------------------------------
// distance primitives

float udRoundBox( vec3 p, vec3 b, float r ) {
  return length(max(abs(p)-b,0.0))-r;
}

float sdBox( in vec3 p, in vec3 b ) {
    vec3 d = abs(p) - b;
    return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
}

float sdSphere( in vec3 p, in float s ) {
    return length(p)-s;
}

float sdCylinder( in vec3 p, in vec2 h ) {
    vec2 d = abs(vec2(length(p.xz),p.y)) - h;
    return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}

//----------------------------------------------------------------------
// distance operators

float opU( float d2, float d1 ) { return min( d1,d2); }
float opS( float d2, float d1 ) { return max(-d1,d2); }
float smin( float a, float b, float k ) { return -log(exp(-k*a)+exp(-k*b))/k; } //from iq

//----------------------------------------------------------------------
// Map functions

// car model is made by Eiffie
// shader 'Shiny Toy': https://www.shadertoy.com/view/ldsGWB

float mapCar(in vec3 p0){
vec3 p=p0+vec3(0.0,1.24,0.0);
float r=length(p.yz);
float d= length(max(vec3(abs(p.x)-0.35,r-1.92,-p.y+1.4),0.0))-0.05;
d=max(d,p.z-1.0);
p=p0+vec3(0.0,-0.22,0.39);
p.xz=abs(p.xz)-vec2(0.5300,0.9600);p.x=abs(p.x);
r=length(p.yz);
d=smin(d,length(max(vec3(p.x-0.08,r-0.25,-p.y-0.08),0.0))-0.04,8.0);
d=max(d,-max(p.x-0.165,r-0.24));
float d2=length(vec2(max(p.x-0.13,0.0),r-0.2))-0.02;
d=min(d,d2);

return d;
}

float dL; // minimal distance to light

float map( const in vec3 p ) {
vec3 pd = p;
    float d;
   
    pd.x = abs( pd.x );
    pd.z *= -sign( p.x );
   
    float ch = hash( floor( (pd.z+18.*time)/40. ) );
    float lh = hash( floor( pd.z/13. ) );
   
    vec3 pdm = vec3( pd.x, pd.y, mod( pd.z, 10.) - 5. );
    dL = sdSphere( vec3(pdm.x-8.1,pdm.y-4.5,pdm.z), 0.1 );
   
    dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-9.5-lh,  mod( pd.z, 91.) - 45.5 ), vec3(0.2,4.5, 0.2) ) );
    dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-11.5+lh, mod( pd.z, 31.) - 15.5 ), vec3(0.22,5.5, 0.2) ) );
    dL = opU( dL, sdBox( vec3(pdm.x-12., pdm.y-8.5-lh,  mod( pd.z, 41.) - 20.5 ), vec3(0.24,3.5, 0.2) ) );
   
    if( lh > 0.5 ) {
    dL = opU( dL, sdBox( vec3(pdm.x-12.5,pdm.y-2.75-lh,  mod( pd.z, 13.) - 6.5 ), vec3(0.1,0.25, 3.2) ) );
    }
   
    vec3 pm = vec3( mod( pd.x + floor( pd.z * 4. )*0.25, 0.5 ) - 0.25, pd.y, mod( pd.z, 0.25 ) - 0.125 );
d = udRoundBox( pm, vec3( 0.245,0.1, 0.12 ), 0.005 );
   
    d = opS( d, -(p.x+8.) );
    d = opU( d, pd.y );

    vec3 pdc = vec3( pd.x, pd.y, mod( pd.z+18.*time, 40.) - 20. );
   
    // car
    if( ch > 0.75 ) {
        pdc.x += (ch-0.75)*4.;
    dL = opU( dL, sdSphere( vec3( abs(pdc.x-5.)-1.05, pdc.y-0.55, pdc.z ),    0.025 ) );
    dL = opU( dL, sdSphere( vec3( abs(pdc.x-5.)-1.2,  pdc.y-0.65,  pdc.z+6.05 ), 0.025 ) );

        d = opU( d,  mapCar( (pdc-vec3(5.,-0.025,-2.3))*0.45 ) );
  }
   
    d = opU( d, 13.-pd.x );
    d = opU( d, sdCylinder( vec3(pdm.x-8.5, pdm.y, pdm.z), vec2(0.075,4.5)) );
    d = opU( d, dL );
   
return d;
}

//----------------------------------------------------------------------

vec3 calcNormalSimple( in vec3 pos ) {   
    const vec2 e = vec2(1.0,-1.0)*0.005;

    vec3 n = normalize( e.xyy*map( pos + e.xyy ) +
    e.yyx*map( pos + e.yyx )   +
    e.yxy*map( pos + e.yxy )   +
    e.xxx*map( pos + e.xxx )   ); 
    return n;
}

vec3 calcNormal( in vec3 pos ) {
    vec3 n = calcNormalSimple( pos );
    if( pos.y > 0.12 ) return n;

#ifdef BUMPMAP
    vec2 oc = floor( vec2(pos.x+floor( pos.z * 4. )*0.25, pos.z) * vec2( 2., 4. ) );

    if( abs(pos.x)<8. ) {
oc = pos.xz;
    }
   
     vec3 p = pos * 250.;
    vec3 xn = 0.05*vec3(noise(p.xz)-0.5,0.,noise(p.zx)-0.5);
     xn += 0.1*vec3(fbm(oc.xy)-0.5,0.,fbm(oc.yx)-0.5);
   
    n = normalize( xn + n );
#endif
   
    return n;
}

vec3 int1, int2, nor1;
vec4 lint1, lint2;

float intersect( in vec3 ro, in vec3 rd ) {
const float precis = 0.001;
    float h = precis*2.0;
    float t = 0.;
    int1 = int2 = vec3( -500. );
    lint1 = lint2 = vec4( -500. );
    float mld = 100.;
   
for( int i=0; i < MARCHSTEPS; i++ ) {
        h = map( ro+rd*t );
if(dL < mld){
mld=dL;
            lint1.xyz = ro+rd*t;
lint1.w = abs(dL);
}
        if( h < precis ) {
            int1.xyz = ro+rd*t;
            break;
        }
        t += max(h, precis*2.);
    }
   
    if( int1.z < -400. || t > 300.) {
        // check intersection with plane y = -0.1;
        float d = -(ro.y + 0.1)/rd.y;
if( d > 0. ) {
int1.xyz = ro+rd*d;
    } else {
        return -1.;
    }
    }
   
    ro = ro + rd*t;
    nor1 = calcNormal(ro);
    ro += 0.01*nor1;
    rd = reflect( rd, nor1 );
    t = 0.0;
    h = precis*2.0;
    mld = 100.;
   
    for( int i=0; i < MARCHSTEPSREFLECTION; i++ ) {
        h = map( ro+rd*t );
if(dL < mld){
mld=dL;           
            lint2.xyz = ro+rd*t;
lint2.w = abs(dL);
}
        if( h < precis ) {
    int2.xyz = ro+rd*t;
            return 1.;
        }   
        t += max(h, precis*2.);
    }

    return 0.;
}

//----------------------------------------------------------------------
// shade

vec3 shade( in vec3 ro, in vec3 pos, in vec3 nor ) {
    vec3  col = vec3(0.5);
   
    if( abs(pos.x) > 15. || abs(pos.x) < 8. ) col = vec3( 0.02 );
    if( pos.y < 0.01 ) {
        if( abs( int1.x ) < 0.1 ) col = vec3( 0.9 );
        if( abs( abs( int1.x )-7.4 ) < 0.1 ) col = vec3( 0.9 );
    }   
   
    float sh = clamp( dot( nor, normalize( vec3( -0.3, 0.3, -0.5 ) ) ), 0., 1.);
  col *= (sh * backgroundColor); 
 
    if( abs( pos.x ) > 12.9 && pos.y > 9.) { // windows
        float ha = hash(  133.1234*floor( pos.y / 3. ) + floor( (pos.z) / 3. ) );
        if( ha > 0.95) {
            col = ( (ha-0.95)*10.) * vec3( 1., 0.7, 0.4 );
        }
    }
   
col = mix(  backgroundColor, col, exp( min(max(0.1*pos.y,0.25)-0.065*distance(pos, ro),0.) ) );
 
    return col;
}

vec3 getLightColor( in vec3 pos ) {
    vec3 lcol = vec3( 1., .7, .5 );
   
vec3 pd = pos;
    pd.x = abs( pd.x );
    pd.z *= -sign( pos.x );
   
    float ch = hash( floor( (pd.z+18.*time)/40. ) );
    vec3 pdc = vec3( pd.x, pd.y, mod( pd.z+18.*time, 40.) - 20. );

    if( ch > 0.75 ) { // car
        pdc.x += (ch-0.75)*4.;
        if(  sdSphere( vec3( abs(pdc.x-5.)-1.05, pdc.y-0.55, pdc.z ), 0.25) < 2. ) {
            lcol = vec3( 1., 0.05, 0.01 );
        }
    }
    if( pd.y > 2. && abs(pd.x) > 10. && pd.y < 5. ) {
        float fl = floor( pd.z/13. );
        lcol = 0.4*lcol+0.5*vec3( hash( .1562+fl ), hash( .423134+fl ), 0. );
    }
    if(  abs(pd.x) > 10. && pd.y > 5. ) {
        float fl = floor( pd.z/2. );
        lcol = 0.5*lcol+0.5*vec3( hash( .1562+fl ),  hash( .923134+fl ), hash( .423134+fl ) );
    }
   
    return lcol;
}

float randomStart(vec2 co){return 0.8+0.2*hash(dot(co,vec2(123.42,117.853))*412.453);}

//----------------------------------------------------------------------
// main

void main() {   
    vec2 q = gl_FragCoord.xy / iResolution.xy;
vec2 p = -1.0 + 2.0*q;
p.x *= iResolution.x / iResolution.y;
       
    if (q.y < .12 || q.y >= .88) {
gl_FragColor=vec4(0.,0.,0.,1.);
return;
    } else {
   
        // camera
        float z = time;
        float x = -10.9+1.*sin(time*0.2);
        vec3 ro = vec3(x,  1.3+.3*cos(time*0.26), z-1.);
        vec3 ta = vec3(-8.,1.3+.4*cos(time*0.26), z+4.+cos(time*0.04));

        vec3 ww = normalize( ta - ro );
        vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) );
        vec3 vv = normalize( cross(uu,ww));
        vec3 rd = normalize( -p.x*uu + p.y*vv + 2.2*ww );

        vec3 col = backgroundColor;

        // raymarch
        float ints = intersect(ro+randomStart(p)*rd ,rd );
        if(  ints > -0.5 ) {

            // calculate reflectance
            float r = 0.09;             
            if( int1.y > 0.129 ) r = 0.025 * hash(  133.1234*floor( int1.y / 3. ) + floor( int1.z / 3. ) );
            if( abs(int1.x) < 8. ) {
                if( int1.y < 0.01 ) { // road
                    r = 0.007*fbm(int1.xz);
                } else { // car
                    r = 0.02;
                }
            }
            if( abs( int1.x ) < 0.1 ) r *= 4.;
            if( abs( abs( int1.x )-7.4 ) < 0.1 ) r *= 4.;

            r *= 2.;

            col = shade( ro, int1.xyz, nor1 );

            if( ints > 0.5 ) {
                col += r * shade( int1.xyz, int2.xyz, calcNormalSimple(int2.xyz) );
            } 
            if( lint2.w > 0. ) {           
                col += (r*LIGHTINTENSITY*exp(-lint2.w*7.0)) * getLightColor(lint2.xyz);
            }
        }

        // Rain (by Dave Hoskins)
        vec2 st = 256. * ( p* vec2(.5, .01)+vec2(time*.13-q.y*.6, time*.13) );
        float f = noise( st ) * noise( st*0.773) * 1.55;
        f = 0.25+ clamp(pow(abs(f), 13.0) * 13.0, 0.0, q.y*.14);

        if( lint1.w > 0. ) {
            col += (f*LIGHTINTENSITY*exp(-lint1.w*7.0)) * getLightColor(lint1.xyz);
        } 

        col += 0.25*f*(0.2+backgroundColor);

        // post processing
        col = pow( clamp(col,0.0,1.0), vec3(0.4545) );
        col *= 1.2*vec3(1.,0.99,0.95);   
        col = clamp(1.06*col-0.03, 0., 1.); 
        q.y = (q.y-.12)*(1./0.76);
        col *= 0.5 + 0.5*pow( 16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y), 0.1 );

        gl_FragColor = vec4( col, 1.0 );
    }
}
« Last Edit: December 14, 2019, 05:05:32 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #91 on: December 14, 2019, 05:20:07 pm »
Thank you, Patrice!

The shaders are beautiful. It's a pity though that you sent me another Tokyo instead of SimplicityGalaxy. ;)

P.S. Have you noticed that cars in that Tokyo are driving on the wrong side of the road? ;) (traffic in Japan is left-sided British-style)
« Last Edit: December 14, 2019, 05:26:13 pm by Michael Lobko-Lobanovsky »
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #92 on: December 14, 2019, 07:25:07 pm »
Here is
Simplicity_Galaxy.fs

Code: [Select]
//CBS
//Parallax scrolling fractal galaxy.
//Inspired by JoshP's Simplicity shader: https://www.shadertoy.com/view/lslGWr

uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

uniform sampler2D BWNoise_png;

// http://www.fractalforums.com/new-theories-and-research/very-simple-formula-for-fractal-patterns/
float field(in vec3 p,float s) {
float strength = 7. + .03 * log(1.e-6 + fract(sin(iTime) * 4373.11));
float accum = s/4.;
float prev = 0.;
float tw = 0.;
for (int i = 0; i < 26; ++i) {
float mag = dot(p, p);
p = abs(p) / mag + vec3(-.5, -.4, -1.5);
float w = exp(-float(i) / 7.);
accum += w * exp(-strength * pow(abs(mag - prev), 2.2));
tw += w;
prev = mag;
}
return max(0., 5. * accum / tw - .7);
}

// Less iterations for second layer
float field2(in vec3 p, float s) {
float strength = 7. + .03 * log(1.e-6 + fract(sin(iTime) * 4373.11));
float accum = s/4.;
float prev = 0.;
float tw = 0.;
for (int i = 0; i < 18; ++i) {
float mag = dot(p, p);
p = abs(p) / mag + vec3(-.5, -.4, -1.5);
float w = exp(-float(i) / 7.);
accum += w * exp(-strength * pow(abs(mag - prev), 2.2));
tw += w;
prev = mag;
}
return max(0., 5. * accum / tw - .7);
}

vec3 nrand3( vec2 co )
{
vec3 a = fract( cos( co.x*8.3e-3 + co.y )*vec3(1.3e5, 4.7e5, 2.9e5) );
vec3 b = fract( sin( co.x*0.3e-3 + co.y )*vec3(8.1e5, 1.0e5, 0.1e5) );
vec3 c = mix(a, b, 0.5);
return c;
}


void main() {
    vec2 uv = 2. * gl_FragCoord.xy / iResolution.xy - 1.;
vec2 uvs = uv * iResolution.xy / max(iResolution.x, iResolution.y);
vec3 p = vec3(uvs / 4., 0) + vec3(1., -1.3, 0.);
p += .2 * vec3(sin(iTime / 16.), sin(iTime / 12.),  sin(iTime / 128.));

float freqs[4];
//Sound
freqs[0] = texture( BWNoise_png, vec2( 0.01, 0.25 ) ).x;
freqs[1] = texture( BWNoise_png, vec2( 0.07, 0.25 ) ).x;
freqs[2] = texture( BWNoise_png, vec2( 0.15, 0.25 ) ).x;
freqs[3] = texture( BWNoise_png, vec2( 0.30, 0.25 ) ).x;

float t = field(p,freqs[2]);
float v = (1. - exp((abs(uv.x) - 1.) * 6.)) * (1. - exp((abs(uv.y) - 1.) * 6.));

    //Second Layer
vec3 p2 = vec3(uvs / (4.+sin(iTime*0.11)*0.2+0.2+sin(iTime*0.15)*0.3+0.4), 1.5) + vec3(2., -1.3, -1.);
p2 += 0.25 * vec3(sin(iTime / 16.), sin(iTime / 12.),  sin(iTime / 128.));
float t2 = field2(p2,freqs[3]);
vec4 c2 = mix(.4, 1., v) * vec4(1.3 * t2 * t2 * t2 ,1.8  * t2 * t2 , t2* freqs[0], t2);


//Let's add some stars
//Thanks to http://glsl.heroku.com/e#6904.0
vec2 seed = p.xy * 2.0;
seed = floor(seed * iResolution.x);
vec3 rnd = nrand3( seed );
vec4 starcolor = vec4(pow(rnd.y,40.0));

//Second Layer
vec2 seed2 = p2.xy * 2.0;
seed2 = floor(seed2 * iResolution.x);
vec3 rnd2 = nrand3( seed2 );
starcolor += vec4(pow(rnd2.y,40.0));

gl_FragColor = mix(freqs[3]-.3, 1., v) * vec4(1.5*freqs[2] * t * t* t , 1.2*freqs[1] * t * t, freqs[3]*t, 1.0)+c2+starcolor;
}

Galaxy_Trips.fs
Code: [Select]
//////////////////////////////////////////////////
// Xavier Benech
// Galaxy Trip
// Inspired by "Star Tunnel" shader from P_Malin
// https://www.shadertoy.com/view/MdlXWr
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
//

uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

// Increase pass count for a denser effect
#define PASS_COUNT 4

float fBrightness = 2.5;

// Number of angular segments
float fSteps = 121.0;

float fParticleSize = 0.015;
float fParticleLength = 0.5 / 60.0;

// Min and Max star position radius. Min must be present to prevent stars too near camera
float fMinDist = 0.8;
float fMaxDist = 5.0;

float fRepeatMin = 1.0;
float fRepeatMax = 2.0;

// fog density
float fDepthFade = 0.8;

float Random(float x)
{
return fract(sin(x * 123.456) * 23.4567 + sin(x * 345.678) * 45.6789 + sin(x * 456.789) * 56.789);
}

vec3 GetParticleColour( const in vec3 vParticlePos, const in float fParticleSize, const in vec3 vRayDir )
{
vec2 vNormDir = normalize(vRayDir.xy);
float d1 = dot(vParticlePos.xy, vNormDir.xy) / length(vRayDir.xy);
vec3 vClosest2d = vRayDir * d1;

vec3 vClampedPos = vParticlePos;

vClampedPos.z = clamp(vClosest2d.z, vParticlePos.z - fParticleLength, vParticlePos.z + fParticleLength);

float d = dot(vClampedPos, vRayDir);

vec3 vClosestPos = vRayDir * d;

vec3 vDeltaPos = vClampedPos - vClosestPos;

float fClosestDist = length(vDeltaPos) / fParticleSize;
float fShade = clamp(1.0 - fClosestDist, 0.0, 1.0);

if (d<3.0)
{
fClosestDist = max(abs(vDeltaPos.x),abs(vDeltaPos.y)) / fParticleSize;
float f = clamp(1.0 - 0.8*fClosestDist, 0.0, 1.0);
fShade += f*f*f*f;
fShade *= fShade;
}

fShade = fShade * exp2(-d * fDepthFade) * fBrightness;
return vec3(fShade);
}

vec3 GetParticlePos( const in vec3 vRayDir, const in float fZPos, const in float fSeed )
{
float fAngle = atan(vRayDir.x, vRayDir.y);
float fAngleFraction = fract(fAngle / (3.14 * 2.0));

float fSegment = floor(fAngleFraction * fSteps + fSeed) + 0.5 - fSeed;
float fParticleAngle = fSegment / fSteps * (3.14 * 2.0);

float fSegmentPos = fSegment / fSteps;
float fRadius = fMinDist + Random(fSegmentPos + fSeed) * (fMaxDist - fMinDist);

float tunnelZ = vRayDir.z / length(vRayDir.xy / fRadius);

tunnelZ += fZPos;

float fRepeat = fRepeatMin + Random(fSegmentPos + 0.1 + fSeed) * (fRepeatMax - fRepeatMin);

float fParticleZ = (ceil(tunnelZ / fRepeat) - 0.5) * fRepeat - fZPos;

return vec3( sin(fParticleAngle) * fRadius, cos(fParticleAngle) * fRadius, fParticleZ );
}

vec3 Starfield( const in vec3 vRayDir, const in float fZPos, const in float fSeed )
{
vec3 vParticlePos = GetParticlePos(vRayDir, fZPos, fSeed);

return GetParticleColour(vParticlePos, fParticleSize, vRayDir);
}

vec3 RotateX( const in vec3 vPos, const in float fAngle )
{
    float s = sin(fAngle); float c = cos(fAngle);
    return vec3( vPos.x, c * vPos.y + s * vPos.z, -s * vPos.y + c * vPos.z);
}

vec3 RotateY( const in vec3 vPos, const in float fAngle )
{
    float s = sin(fAngle); float c = cos(fAngle);
    return vec3( c * vPos.x + s * vPos.z, vPos.y, -s * vPos.x + c * vPos.z);
}

vec3 RotateZ( const in vec3 vPos, const in float fAngle )
{
    float s = sin(fAngle); float c = cos(fAngle);
    return vec3( c * vPos.x + s * vPos.y, -s * vPos.x + c * vPos.y, vPos.z);
}

// Simplex Noise by IQ
vec2 hash( vec2 p )
{
p = vec2( dot(p,vec2(127.1,311.7)),
  dot(p,vec2(269.5,183.3)) );

return -1.0 + 2.0*fract(sin(p)*43758.5453123);
}

float noise( in vec2 p )
{
    const float K1 = 0.366025404; // (sqrt(3)-1)/2;
    const float K2 = 0.211324865; // (3-sqrt(3))/6;

vec2 i = floor( p + (p.x+p.y)*K1 );

    vec2 a = p - i + (i.x+i.y)*K2;
    vec2 o = (a.x>a.y) ? vec2(1.0,0.0) : vec2(0.0,1.0); //vec2 of = 0.5 + 0.5*vec2(sign(a.x-a.y), sign(a.y-a.x));
    vec2 b = a - o + K2;
vec2 c = a - 1.0 + 2.0*K2;

    vec3 h = max( 0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 );

vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0)));

    return dot( n, vec3(70.0) );

}

const mat2 m = mat2( 0.80,  0.60, -0.60,  0.80 );

float fbm4( in vec2 p )
{
    float f = 0.0;
    f += 0.5000*noise( p ); p = m*p*2.02;
    f += 0.2500*noise( p ); p = m*p*2.03;
    f += 0.1250*noise( p ); p = m*p*2.01;
    f += 0.0625*noise( p );
    return f;
}

float marble(in vec2 p)
{
return cos(p.x+fbm4(p));
}

float dowarp ( in vec2 q, out vec2 a, out vec2 b )
{
float ang=0.;
ang = 1.2345 * sin (33.33); //0.015*iTime);
mat2 m1 = mat2(cos(ang), -sin(ang), sin(ang), cos(ang));
ang = 0.2345 * sin (66.66); //0.021*iTime);
mat2 m2 = mat2(cos(ang), -sin(ang), sin(ang), cos(ang));

a = vec2( marble(m1*q), marble(m2*q+vec2(1.12,0.654)) );

ang = 0.543 * cos (13.33); //0.011*iTime);
m1 = mat2(cos(ang), -sin(ang), sin(ang), cos(ang));
ang = 1.128 * cos (53.33); //0.018*iTime);
m2 = mat2(cos(ang), -sin(ang), sin(ang), cos(ang));

b = vec2( marble( m2*(q + a)), marble( m1*(q + a) ) );

return marble( q + b +vec2(0.32,1.654));
}

// -----------------------------------------------

void main()
{
  vec2 uv = gl_FragCoord.xy / iResolution.xy;
vec2 q = 2.*uv-1.;
q.y *= iResolution.y/iResolution.x;

// camera
vec3 rd = normalize(vec3( q.x, q.y, 1. ));
vec3 euler = vec3(
sin(iTime * 0.2) * 0.625,
cos(iTime * 0.1) * 0.625,
iTime * 0.1 + sin(iTime * 0.3) * 0.5);

if(iMouse.z > 0.0)
{
euler.x = -((iMouse.y / iResolution.y) * 2.0 - 1.0);
euler.y = -((iMouse.x / iResolution.x) * 2.0 - 1.0);
euler.z = 0.0;
}
rd = RotateX(rd, euler.x);
rd = RotateY(rd, euler.y);
rd = RotateZ(rd, euler.z);

// Nebulae Background
float pi = 3.141592654;
q.x = 0.5 + atan(rd.z, rd.x)/(2.*pi);
q.y = 0.5 - asin(rd.y)/pi + 0.512 + 0.001*iTime;
q *= 2.34;

vec2 wa = vec2(0.);
vec2 wb = vec2(0.);
float f = dowarp(q, wa, wb);
f = 0.5+0.5*f;

vec3 col = vec3(f);
float wc = 0.;
wc = f;
col = vec3(wc, wc*wc, wc*wc*wc);
wc = abs(wa.x);
col -= vec3(wc*wc, wc, wc*wc*wc);
wc = abs(wb.x);
col += vec3(wc*wc*wc, wc*wc, wc);
col *= 0.7;
col.x = pow(col.x, 2.18);
col.z = pow(col.z, 1.88);
col = smoothstep(0., 1., col);
col = 0.5 - (1.4*col-0.7)*(1.4*col-0.7);
col = 0.75*sqrt(col);
col *= 1. - 0.5*fbm4(8.*q);
col = clamp(col, 0., 1.);

// StarField
float fShade = 0.0;
float a = 0.2;
float b = 10.0;
float c = 1.0;
float fZPos = 5.0;// + iTime * c + sin(iTime * a) * b;
float fSpeed = 0.; //c + a * b * cos(a * iTime);

fParticleLength = 0.25 * fSpeed / 60.0;

float fSeed = 0.0;

vec3 vResult = vec3(0.);

vec3 red = vec3(0.7,0.4,0.3);
vec3 blue = vec3(0.3,0.4,0.7);
vec3 tint = vec3(0.);
float ti = 1./float(PASS_COUNT-1);
float t = 0.;
for(int i=0; i<PASS_COUNT; i++)
{
tint = mix(red,blue,t);
vResult += 1.1*tint*Starfield(rd, fZPos, fSeed);
t += ti;
fSeed += 1.234;
rd = RotateX(rd, 0.25*euler.x);
}

col += sqrt(vResult);

// Vignetting
vec2 r = -1.0 + 2.0*(uv);
float vb = max(abs(r.x), abs(r.y));
col *= (0.15 + 0.85*(1.0-exp(-(1.0-vb)*30.0)));
gl_FragColor = vec4( col, 1.0 );
}

Time_coordinates.fs
Code: [Select]
// Created by Daniel Burke - burito/2014
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

// Inspiration from Dr Who (2005) S7E13 - The Name of the Doctor

uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

vec2 rot(vec2 p, float a)
{
    float c = cos(a);
    float s = sin(a);
    return vec2(p.x*c + p.y*s,
                -p.x*s + p.y*c);
}

float circle(vec2 pos, float radius)
{
    return clamp(((1.0-abs(length(pos)-radius))-0.99)*100.0, 0.0, 1.0);
   
}

float circleFill(vec2 pos, float radius)
{
    return clamp(((1.0-(length(pos)-radius))-0.99)*100.0, 0.0, 1.0);   
}

// Thanks Iñigo Quilez!
float line( in vec2 p, in vec2 a, in vec2 b )
{
    vec2 pa = -p - a;
    vec2 ba = b - a;
    float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
    float d = length( pa - ba*h );
   
    return clamp(((1.0 - d)-0.99)*100.0, 0.0, 1.0);
}

// for posterity, the original evil function
float EvilLine(vec2 pos, vec2 start, vec2 finish)
{
    vec2 delta = finish - start;
    vec2 n = normalize(delta);
    float l = length(delta);
    float d = sign(n.x);
   
    float angle = atan(n.y / n.x);
    vec2 t = rot(-pos - start, angle);
   
    float s = d < 0.0 ? 0.0: d*l;
    float f = d < 0.0 ? d*l : 0.0;
    if(t.x > s || t.x < f)return 0.0;

    return clamp(((1.0 - abs(t.y))-0.99)*100.0, 0.0, 1.0);
}

void main()
{
vec2 uv = gl_FragCoord.xy / iResolution.xy;
    vec2 p = -1.0 + 2.0 * uv;
    p.x *= iResolution.x / iResolution.y;
 
    vec3 colour = vec3(0);
    vec3 white = vec3(1);
   
   
   
    float c = circle(p, 0.2);
    c += circle(p, 0.1);
    c += circle(p, 0.18);
    c += circleFill(p, 0.005);

//    c += circle(p, 1.3);
    c += circle(p, 1.0);
    if(p.x > 0.0)c += circle(p, 0.4);
    if(p.x > 0.0)c += circle(p, 0.42);
    if(p.x < 0.0)c += circle(p, 0.47);
    c += circleFill(p+vec2(0.47, 0.0), 0.02);
    c += circleFill(p+vec2(0.84147*0.47, 0.54030*0.47), 0.02);
    c += circleFill(p+vec2(0.84147*0.47, -0.54030*0.47), 0.02);
    c += circleFill(p+vec2(0.41614*0.47, 0.90929*0.47), 0.02);
    c += circleFill(p+vec2(0.41614*0.47, -0.90929*0.47), 0.02);
   
    float t = iTime;
    float t2 = t * -0.01;
    float t3 = t * 0.03;
   
    vec2 angle1 = vec2(sin(t), cos(t));
    vec2 a = angle1 * 0.7;
   
    t *= 0.5;
    vec2 angle2 = vec2(sin(t), cos(t));
    vec2 b = angle2 * 0.8;
   
    vec2 angle3 = vec2(sin(t2), cos(t2));
    vec2 d = b + angle3* 0.4;

    vec2 angle4 = vec2(sin(t3), cos(t3));
    vec2 e = angle4 * 0.9;

    vec2 angle5 = vec2(sin(t3+4.0), cos(t3+4.0));
    vec2 f = angle5 * 0.8;
   
    vec2 angle6 = vec2(sin(t*-0.1+5.0), cos(t*-0.1+5.0));
    vec2 h = angle6 * 0.8;
   
   

   
   
    float tt = t * 1.4;
   
    float tm = mod(tt, 0.5);
    float tmt = tt - tm;
    if( tm > 0.4) tmt += (tm-0.4)*5.0;
    vec2 tangle1 = vec2(sin(tmt), cos(tmt));

tt *= 0.8;
    tm = mod(tt, 0.6);
    float tmt2 = tt - tm;
    if( tm > 0.2) tmt2 += (tm-0.2)*1.5;
   
    vec2 tangle2 = vec2(sin(tmt2*-4.0), cos(tmt2*-4.0));
   
    vec2 tangle3 = vec2(sin(tmt2), cos(tmt2));
   
    tt = t+3.0;
    tm = mod(tt, 0.2);
    tmt = tt - tm;
    if( tm > 0.1) tmt += (tm-0.1)*2.0;
    vec2 tangle4 = vec2(sin(-tmt), cos(-tmt)); tmt += 0.9;
    vec2 tangle41 = vec2(sin(-tmt), cos(-tmt)); tmt += 0.5;
    vec2 tangle42 = vec2(sin(-tmt), cos(-tmt)); tmt += 0.5;
    vec2 tangle43 = vec2(sin(-tmt), cos(-tmt)); tmt += 0.5;
    vec2 tangle44 = vec2(sin(-tmt), cos(-tmt)); tmt += 0.5;
    vec2 tangle45 = vec2(sin(-tmt), cos(-tmt));

    tt = iTime+0.001;
    tm = mod(tt, 1.0);
    tmt = tt - tm;
    if( tm > 0.9) tmt += (tm-0.9)*10.0;

    vec2 tangle51 = 0.17*vec2(sin(-tmt), cos(-tmt)); tmt += 1.0471975511965976;
    vec2 tangle52 = 0.17*vec2(sin(-tmt), cos(-tmt)); tmt += 1.0471975511965976;
    vec2 tangle53 = 0.17*vec2(sin(-tmt), cos(-tmt));
   
    c += line(p, tangle51, -tangle53);
    c += line(p, tangle52, tangle51);
    c += line(p, tangle53, tangle52);
    c += line(p, -tangle51, tangle53);
    c += line(p, -tangle52, -tangle51);
    c += line(p, -tangle53, -tangle52);

    c += circleFill(p+tangle51, 0.01);
    c += circleFill(p+tangle52, 0.01);
    c += circleFill(p+tangle53, 0.01);
    c += circleFill(p-tangle51, 0.01);
    c += circleFill(p-tangle52, 0.01);
    c += circleFill(p-tangle53, 0.01);
   
   
   
    c += circle(p+a, 0.2);
    c += circle(p+a, 0.14);
    c += circle(p+a, 0.1);
    c += circleFill(p+a, 0.04);
    c += circleFill(p+a+tangle3*0.2, 0.025);   
   
   
    c += circle(p+a, 0.14);


    c += circle(p+b, 0.2);
    c += circle(p+b, 0.03);
    c += circle(p+b, 0.15);
    c += circle(p+b, 0.45);
    c += circleFill(p+b+tangle1*0.05, 0.01);
    c += circleFill(p+b+tangle1*0.09, 0.02);
    c += circleFill(p+b+tangle1*0.15, 0.03);
    c += circle(p+b+tangle1*-0.15, 0.03);
    c += circle(p+b+tangle1*-0.07, 0.015);

    c += circle(p+d, 0.08);


    c += circle(p+e, 0.08);
   

    c += circle(p+f, 0.12);
    c += circle(p+f, 0.10);
    c += circleFill(p+f+tangle2*0.05, 0.01);
    c += circleFill(p+f+tangle2*0.10, 0.01);
    c += circle(p+f-tangle2*0.03, 0.01);
    c += circleFill(p+f+vec2(0.085), 0.005);
    c += circleFill(p+f, 0.005);

   
    vec2 g = tangle4 * 0.16;
    c += circle(p+h, 0.05);
    c += circle(p+h, 0.1);
    c += circle(p+h, 0.17);
    c += circle(p+h, 0.2);
    c += circleFill(p+h+tangle41 *0.16, 0.01);
    c += circleFill(p+h+tangle42 *0.16, 0.01);
    c += circleFill(p+h+tangle43 *0.16, 0.01);
    c += circleFill(p+h+tangle44 *0.16, 0.01);
    c += circleFill(p+h+tangle45 *0.16, 0.01);
    c += circleFill(p+h+angle1 *0.06, 0.02);
    c += circleFill(p+h+tangle43*-0.16, 0.01);
   
   
    c += line(p, vec2(0.0), a);
    c += circleFill(p+b, 0.005);
    c += circleFill(p+d, 0.005);
    c += circleFill(p+e, 0.005);

    c += line(p, b, a);
    c += line(p, d, e);
    c += line(p, b+tangle1*0.15, e);
    c += line(p, e, f+vec2(0.085));

    c += line(p, h+angle1*0.06, f);
    c += line(p, h+tangle43*-0.16, d);
    c += line(p, h+tangle42*0.16, e);
   
   
    // of course I'd write a line function that
    // doesn't handle perfectly vertical lines
    c += line(p, vec2(0.001, -0.5), vec2(0.0001, 0.5));
    c += circleFill(p+vec2(0.001, -0.5), 0.005);
    c += circleFill(p+vec2(0.001, 0.5), 0.005);
   
    c = clamp(c, 0.0, 1.0);
    colour = white * c;
   

    gl_FragColor = vec4(colour, 1.0);
}

Sanctuary2.fs
Code: [Select]
// srtuss, 2018
//
// This began as an elaborate soundshader-experiment. I tried to create very clear-sounding
// instruments and mix them nicely, with a feel of depth and dark atmosphere to it. I added
// visuals based the images this music spawns in my head. Hope you enjoy it. :)
//
// Here is a recording of how the shader sounds, on the computers i created/tested it on:
// http://srtuss.thrill-project.com/art/sanctuary_soundtrack.ogg
//
// Music production with a soundshader: :)
// http://srtuss.thrill-project.com/music/shader.ogg
//

uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

uniform sampler2D Stone_jpg;

vec2 rotate(vec2 p, float a)
{
    float co = cos(a), si = sin(a);
    return p * mat2(co, si, -si, co);
}

vec2 scene(vec3 p, bool details)
{
    float v = 1e38;
   
    float wall = 3. - dot(vec2(abs(p.x), p.y), normalize(vec2(1., .3)));
    float floorr = p.y;
    v = min(v, wall);
    float srs = .8;
    float strut = max(wall - .5, abs(fract(p.z * srs) - .5) / srs - .1);
    v = min(v, strut);
    v = min(v, max(strut, floorr) - .1);
   
    v = min(v, max(strut - .1, abs(floorr - 2.) - .5));
   
    float hole = 1.2 - length(p.xz);
    v = min(v, max(floorr, hole));
    v = min(v, max(abs(floorr), abs(hole)) - .2);
   
    vec3 q = p + vec3(0., sin(iTime) * .1 - 1., 0.);
    //float sphere = length(q) - .4;
    float sphere = length(q) - .02; // PAT 12-14-2019
   
    v = min(v, sphere);
   
    return vec2(v, step(sphere, v));
}

vec3 normal(vec3 p)
{
    float c = scene(p, true).x;
    vec2 h = vec2(.005, 0.);
    return normalize(vec3(scene(p + h.xyy, true).x - c, scene(p + h.yxy, true).x - c, scene(p + h.yyx, true).x - c));
}

vec4 trip(vec3 nml, vec3 pos)
{
    vec3 b = abs(nml);
    b = pow(b, vec3(50.));
    b /= dot(b, vec3(1.));
    return texture(Stone_jpg, pos.yz) * b.x + texture(Stone_jpg, pos.xz) * b.y + texture(Stone_jpg, pos.xy) * b.z;
}

float softshadow( in vec3 ro, in vec3 rd, float mint, float k )
{
float res = 1.0;
    float t = mint;
for(int i = 0; i < 32; ++i)
{
float h = scene(ro + rd * t, false).x;
if(h < 0.001)
return 0.0;
res = min(res, k * h / t);
t += h;
}
return res;
}

float amb_occ(vec3 p, float h)
{
float acc = 0.0;
acc += scene(p + vec3(-h, -h, -h), false).x;
acc += scene(p + vec3(-h, -h, +h), false).x;
acc += scene(p + vec3(-h, +h, -h), false).x;
acc += scene(p + vec3(-h, +h, +h), false).x;
acc += scene(p + vec3(+h, -h, -h), false).x;
acc += scene(p + vec3(+h, -h, +h), false).x;
acc += scene(p + vec3(+h, +h, -h), false).x;
acc += scene(p + vec3(+h ,+h, +h), false).x;
return acc / h;
}

void main()
{
    vec2 uv = gl_FragCoord / iResolution.xy;
    uv = uv * 2. - 1.;
    uv.x *= iResolution.x / iResolution.y;

    vec3 rd = normalize(vec3(uv, 1.66));
    vec3 ro = vec3(0., 1., -2.);
    float tilt = sin(iTime * .1 + 1.5) * .2 + .2;
    ro.yz = rotate(ro.yz, tilt);
    rd.yz = rotate(rd.yz, tilt);
   
    ro.xz = rotate(ro.xz, sin(iTime * .1) * .5);
    rd.xz = rotate(rd.xz, sin(iTime * .1) * .5);
   
    float d = 0.;
    for(int i = 0; i < 60; ++i)
    {
        d += scene(ro + rd * d, false).x;
    }
   
    vec3 hit = ro + rd * d;
    vec3 nml = normal(hit);
   
    vec3 lpos1 = vec3(0.5, 2., 4.);
   
    float mtl = scene(hit, false).y;
    vec3 diffMap = vec3(0.);
    if(mtl < .5)
    {
        float k = .001;
        diffMap = trip(nml, hit * 1.111).xyz;
        vec3 diffMap2 = trip(nml, hit * 1.111 + vec3(.005)).xyz;
        nml = normalize(nml + (diffMap.x - diffMap2.x) * .7);
    }
    else
    {
        vec3 mov = hit + vec3(0., sin(iTime) * .1 - 1., 0.);
        //nml = normalize(nml + sin(hit * 200.) * .03);
       
        float k = .001;
        diffMap = trip(nml, mov * 1.111).xyz;
        vec3 diffMap2 = trip(nml, mov * 1.111 + vec3(.005)).xyz;
        nml = normalize(nml + (diffMap.x - diffMap2.x) * .7);
    }
   
vec3 col = vec3(0.);// * exp(length(hit.xy - vec2(0., 1.)) * -1.) * exp(d * -.3);
   
    for(int i = 0; i < 2; ++i)
    {
        vec3 light = i == 1 ? lpos1 : vec3(cos(iTime * .4), 2., sin(iTime) + 1.);
        vec3 vLight = light - hit;
        vec3 lcol = i == 1 ? vec3(1, 1., .7) : vec3(.3, .7, 1.);
        float lfade = exp(length(vLight) * -1.3);
        vec3 diff = max(dot(nml, normalize(vLight)), 0.) * lfade * lcol;
        vec3 ref = reflect(rd, nml);
        float spec = pow(max(0., dot(normalize(vLight), ref)), 32.);

        vec3 ccol = vec3(1.);
        ccol *= pow(diffMap, vec3(2.));

        ccol *= diff;
        ccol += vec3(.4) * spec * lfade;
       
        col += ccol;
    }
   
    col *= smoothstep(-5., 1., amb_occ(hit, .15));
   
    //col = nml * .5 + .5;
   
    col += exp((7. - dot(rd, lpos1 - ro)) * -6.);// * softshadow(ro, normalize(lpos1 - ro), .1, 128.);
   
    float pt = iTime * .2;
    for(int i = 0; i < 20; ++i)
    {
        float pd = 2.;
        hit = ro + rd * pd;
        float h = float(i);
        if(d > pd)
        {
            col += exp(length(hit.xy - vec2(sin(h) * .4 + sin(pt + h) * .1, cos(pt + h) * .1 + fract(pt * .1 + cos(h)))) * -400.) * .05 * (1.1 + sin(h * 10.));
        }
    }
   
    col = sqrt(col);
    col *= 2.9;
   
    gl_FragColor = vec4(col,1.0);
}
« Last Edit: December 14, 2019, 07:46:37 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #93 on: December 14, 2019, 08:08:26 pm »
I have translated this one
https://www.shadertoy.com/view/ll3fz4

however the colors do not match the original  :(

I've_seen.fs
Code: [Select]
// Author: ocb
// Title: I've seen...

/***********************************************************************
Evolution based on Hope shader:  https://www.shadertoy.com/view/MllfDX
Still playing around with grids, (intersecting - overlaping...) to manage
lots of objects in order to generate all kind of cities.
Three intersecting grids generate variable size voxels which contains
cylinder (pipe), or sphere (little dome) or squared building.
One overlaping grid to generate big dome.

Using Shane's functions (the famous "Old nVidia tutorial) to create the decrepit
surface of the building.

Use mouse to look around

Sorry for thr unreadable code.
************************************************************************/

uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

uniform sampler2D Metal_jpg;
uniform sampler2D Moss_jpg;
uniform sampler2D Cloth_jpg;
uniform sampler2D Organic_jpg;

#define PI 3.141592653589793
#define PIdiv2 1.57079632679489
#define TwoPI 6.283185307179586
#define INFINI 1000000.
#define MAXSTEP 127
#define TOP_SURFACE 2.81

/*************  GRID ****************************************************/
#define A .13
#define B .41
#define C .47

#define G2 .02
#define GS .003

/*************  Object **************************************************/
#define GND 0
#define SKY 1
#define CYL 2
#define SPH 3
#define SIDE 4
#define SPHBIS 5

#define DUST vec3(1.,.9,.7)



#define moonCtr vec3(.10644925908247,.266123147706175,.958043331742229)
#define moonShad vec3(-0.435448415412873,0.224265278324226,0.87183126948543)
#define moonRefl vec3(0.524134547566281, 0.21940212059613, 0.822888622794975)

#define starLight vec3(0.814613079962557,0.203653269990639,-0.543075386641705)

int hitObj = SKY;
float hitScale = 1.;
bool WINDOW = false;
bool SIDEWIN = false;

float Hsh(in float v) {
    return fract(sin(v) * 437585.);
}


float Hsh2(in vec2 st) {
    return fract(sin(dot(st,vec2(12.9898,8.233))) * 43758.5453123);
}


float sphereImpact(in vec3 pos, in vec3 ray, in vec3 O, in float R, inout vec3 norm ){
    float d=0., t = INFINI;
    vec3 a = O - pos;
    float b = dot(a, ray);
   
    if (b >= 0.){ // check if object in frontside first (not behind screen)
        float c = dot(a,a) - R*R;
    d = b*b - c;
    if (d >= 0.){
        float sd = sqrt(d);
            t = b - sd;
            norm = normalize(pos + t*ray - O);
        }
    }
   
    return t;
}

float cylinderImpact(in vec2 pos,in vec2 ray, in vec2 O, in float R, inout vec2 norm){
    float t=INFINI;
    vec2 d = pos - O;
    float a = dot(ray,ray);
    float b = dot(d, ray);
    float c = dot(d,d) - R*R;
    float discr = b*b - a*c;
    if (discr >= 0.){
        t = (-b - sqrt(discr))/a;
        if (t < 0.001) t = (-b + sqrt(discr))/a;
        if (t < 0.001) t=INFINI;

        norm = normalize(pos + t*ray - O);
    }
return t;
}


vec4 voxInfo(in vec2 xz){
vec2 dtp = fract(xz*A)/A;
    vec2 dtq = fract((xz)*B)/B;
    vec2 dtr = fract((xz)*C)/C;
    vec2 dm1 = min(min(dtp,dtq),dtr);
   
    dtp = 1./A-dtp;
    dtq = 1./B-dtq;
    dtr = 1./C-dtr;
    vec2 dm2 = min(min(dtp,dtq),dtr);

    vec2 size = dm1+dm2;
    vec2 ctr = xz+.5*(dm2-dm1);
   
    return vec4(ctr,size);
   
}

vec4 voxInfoBis(in vec2 xz){
    vec2 size = vec2(1./G2);
    vec2 ctr = (floor(xz*G2)+.5)*size;
    return vec4(ctr,size);
   
}

vec4 getNextPlan(in vec2 xz, in vec2 v){
    vec2 s = sign(v);
    vec2 d = step(0.,s);
vec2 dtp = (d-fract(xz*A))/A/v;
    vec2 dtq = (d-fract((xz)*B))/B/v;
    vec2 dtr = (d-fract((xz)*C))/C/v;

    vec2 dmin = min(min(dtp,dtq),dtr);
    float tmin = min(dmin.x, dmin.y);
   
    s *= -step(dmin,vec2(tmin));
   
    return vec4(s.x,0.,s.y,tmin);
}

vec4 getNextPlanBis(in vec2 xz, in vec2 v){
    vec2 s = sign(v);
    vec2 d = step(0.,s);
vec2 dtp = (d-fract(xz*G2))/G2/v;
   
    float tmin = min(dtp.x, dtp.y);
   
    s *= -step(tmin,vec2(tmin));
   
    return vec4(s.x,0.,s.y,tmin);
}


float gndFactor(in vec2 p) // use for cam anti-collision
{
vec2 f = 1.5-3.*abs(fract(p.xy*G2)-.5);
    f=smoothstep(.9,1.8,f);
    return 1.5*(f.x+f.y);   
}

float map(in vec2 xz)
{   
    vec2 p = floor(xz*A)/A;
    vec2 q = floor((xz)*B)/B;
    vec2 r = floor((xz)*C)/C;
   
    vec2 f = 1.5-abs(fract(p*G2)-.5)-abs(fract(q*G2)-.5)-abs(fract(r*G2)-.5);
    f=smoothstep(.9,1.8,f);
    float c = 1.5*(f.x+f.y);
   
    float Hp = c*Hsh2(p), Hq = c*Hsh2(q), Hr = c*Hsh2(r);
    float Pp = step(.6,Hp), Pq = step(.6,Hq), Pr = step(.5,Hr);
   
    float tex = 1.*Hp*Pp + .5*Hq*Pq +.3*Hr*Pr;  
    hitScale = Pp + 2.5*Pq + 5.*Pr;
   
    return tex;
}


vec4 trace(in vec3 pos, in vec3 ray, inout vec4 flam)
{
    float dh = 0.;
    float t = 0.;
   
    if(pos.y > TOP_SURFACE){ // navigating directly to the top surface (perfos)
        if(ray.y >= 0.) return vec4(vec3(0.),INFINI);
t = (TOP_SURFACE - pos.y)/ray.y + 0.00001;
    }
   
    vec4 wall = vec4(0.); // wall.xyz is the normal of the wall. wall.w is the t parameter.
   
    for(int i = 0;i<MAXSTEP;i++){ // entering the voxel run
       
        vec3 p = pos+t*ray;
        if(p.y > TOP_SURFACE) break; // when "looking" up, you may fly out before hiting
        // break immediately (perfos)
        float h = map(p.xz);
        float dh = p.y - h;
        if(dh<.0) return vec4(wall.xyz,t-.00002); // you are suddenly below the floor?
        // you hit the previous wall
       
        wall = getNextPlan(p.xz,ray.xz); // find the next wall
        float tt = 0.;
       
        float th = dh/(-ray.y); // find the floor
        th += step(th,0.)*INFINI;
       
        vec4 vox = voxInfo(p.xz); // get voxel info: center and size
        float H = Hsh2(floor(100.*vox.xy));
       
        vec3 normsph = vec3(0.); // Little dome
        float ts = INFINI;
        if(bool(step(H,.6)) && t<150.){
        ts = sphereImpact(p, ray, vec3(vox.x,h-.5,vox.y), H*min(vox.z,vox.w), normsph );
        }
           
        vec3 normcyl = vec3(0.); // Pipe
        float tc = INFINI;
        if(bool(step(H,.2)) && t<100.){
            vec2 c = vox.xy+ (4.*H-.4)*vox.zw;
            float r = .025*min(vox.z,vox.w);
            float top = 2.5*H*TOP_SURFACE;
            tc = cylinderImpact(p.xz, ray.xz, c, r, normcyl.xz );
            tc += step(top,p.y+tc*ray.y)*INFINI;
           
            float Hc = (H-.15)*20.;
        float ti = iTime*.4;
            // Flam calculation
        if(bool(step(.15,H)*step(.95,Hsh(.0001*(vox.x+vox.y)*floor(Hc+ti))) )){
                float fti = fract(Hc+ti);
                vec2 len = c-pos.xz;
                float h = length(len)*ray.y/length(ray.xz)+pos.y;
                float dh = h - top;
                float d = abs(ray.z*len.x - ray.x*len.y);
                float mvt = 1.+cos(5.*dh);
                flam.rgb += min(1.,min(1.,min(vox.z,vox.w))*.2*mvt*(r+dh)/d-.1)
                       *step(0.,dh)
                       *((.8-abs(fti-.5))/(dh+.2) -.3 )
                       *texture(Organic_jpg,vec2(.2*h-.5*ti+Hc,d*(1.+fti)*dh*mvt+Hc)).rgb;
                flam*=flam*(2.-fti);
                flam.w = t;
            }
        }
           

        tt = min(min(ts,th),tc);
        tt = min(wall.w,tt); // keep the min between floor and wall distance
        if(tt==th) return vec4(0.,1.,0.,t+tt); // if first hit = floor return hit info (floor)
        else if(tt==ts){hitObj = SPH; return vec4(normsph,t+tt);}
        else if(tt==tc){hitObj = CYL; return vec4(normcyl,t+tt);}
        else tt = wall.w; // else keep the local t parameter to the next wall
       
        t+= tt+.00001; // update global t and do again
        if(t>250.) break; // not necessary to go too far (perfos)
    }
   
   
    return vec4(0.,0.,0.,INFINI);
}

vec4 traceBis(in vec3 pos, in vec3 ray)
{
    float dh = 0.;
    float t = 0.;
   
    if(pos.y > TOP_SURFACE){ // navigating directly to the top surface (perfos)
        if(ray.y >= 0.) return vec4(vec3(0.),INFINI);
t = (TOP_SURFACE - pos.y)/ray.y + 0.00001;
    }
   
    vec4 wall = vec4(0.); // wall.xyz is the normal of the wall. wall.w is the t parameter.
   
    for(int i = 0;i<MAXSTEP;i++){ // entering the voxel run
       
        vec3 p = pos+t*ray;
        if(p.y > TOP_SURFACE) break; // when "looking" up, you may fly out before hiting
        // break immediately (perfos)
       
        wall = getNextPlanBis(p.xz,ray.xz); // find the next wall
               
        vec4 vox = voxInfoBis(p.xz);
        vec3 normsph;
        float radius = 25.;//.5*min(vox.z,vox.w);
        float tt = sphereImpact(p, ray, vec3(vox.x,TOP_SURFACE-radius-1.,vox.y), radius , normsph );
       
        if(tt<INFINI) return vec4(normsph,t+tt);
        else tt = wall.w; // else keep the local t parameter to the next wall
       
        t+= tt+.00001; // update global t and do again
        if(t>250.) break; // not necessary to go too far (perfos)
    }
   
   
    return vec4(0.,0.,0.,INFINI);
}


float mapGnd(in vec3 p){return .5*texture(Organic_jpg, GS*p.xz).r +.2*texture(Organic_jpg, 2.*GS*p.xz).r;}

vec4 traceGround(in vec3 pos, in vec3 ray)
{
if(ray.y>0.) return vec4(0.,0.,0.,INFINI);

    float t = (mapGnd(pos) - pos.y)/ray.y;
       
    for(int i = 0;i<MAXSTEP;i++){
       
        vec3 p = pos+t*ray;
        float dh = p.y-mapGnd(p);
       
        if(abs(dh) < .003){
vec2 e = vec2(-.2,.2);   
vec3 norm = normalize(e.yxx*mapGnd(p + e.yxx) + e.xxy*mapGnd(p + e.xxy) +
         e.xyx*mapGnd(p + e.xyx) + e.yyy*mapGnd(p + e.yyy) );   
           
            return vec4(norm,t);
        }
       
        t += dh;
       
        if(t>250.) break;
    }
   
    return vec4(0.,0.,0.,INFINI);
}


vec4 boxImpact( in vec3 pos, in vec3 ray, in vec3 ctr, in vec3 dim)
{
    vec3 m = 1.0/ray;
    vec3 n = m*(ctr-pos);
    vec3 k = abs(m)*dim;

    vec3 t1 = n - k;
    vec3 t2 = n + k;

float tmax = max( max( t1.x, t1.y ), t1.z );
float tmin = min( min( t2.x, t2.y ), t2.z );

if( tmax > tmin || tmin < 0.0) return vec4(vec3(0.),INFINI);

    vec3 norm = -sign(ray)*step(t2, vec3(tmin));
    return vec4(norm, tmin);
}


bool checkWindow(in vec3 ctr){
    float hash = Hsh2(ctr.xz+ctr.yy);
    float a = step(.4,hash)*step(mod(ctr.y,10.),0.);
    float b = step(.7,hash)*step(mod(ctr.y-1.,10.),0.);
    return bool(a+b);
}

vec4 traceWindow(in vec3 pos, in vec3 ray, in float t, in vec3 norm){
    float d, sh, sv;
    if(hitObj == SPHBIS){d=.03; sh=2.5; sv=1.;}
    else if(hitObj == SPH){d=.03; sh=.5; sv=.75;}
    else if(hitObj == CYL){d=.01; sh=.1; sv= 1.;}
    else {d=.1; sh=1.; sv=1.;}
   
    vec3 p = pos + t*ray;
    vec4 info = vec4(norm,t);

    vec3 boxDim = vec3(sh*.25,sv*.025,sh*.25);
vec3 boxCtr;
   
    for(int i=0; i<5; i++){
    boxCtr = vec3(floor(p.x*2./sh),floor(p.y*20./sv),floor(p.z*2./sh));
        if(checkWindow(boxCtr)){
            SIDEWIN = true;
            float tf = t + d/dot(ray,-norm);
            info = boxImpact(pos, ray, (boxCtr+.5)*vec3(sh*.5,sv*.05,sh*.5), boxDim);
            if(tf < info.w){
                WINDOW = true;
                info = vec4(norm,tf);
                break;
            }
            p = pos + (info.w+.001)*ray;
        }
        else break;
    }
    return info;
}

vec3 starGlow(in vec3 ray, in float a){
    vec3 col = vec3(.001/(1.0001-a));
    return col;
}

vec3 moonGlow(in vec3 ray, in float a){
    float dl = dot(moonRefl,ray);
    float moon = smoothstep(.9,.93,a);
    float shad = 1.-smoothstep(.7,.9,dot(moonShad, ray));
    float refl = .001/(1.0013-dl);
float clouds = .5*texture(Organic_jpg,ray.xy).r+.3*texture(Organic_jpg,3.*ray.xy).r;
    vec3 col = .8*(vec3(.5,.3,.0)+clouds*vec3(.3,.4,.1))*moon+vec3(1.,1.,.7)*refl;
    col += vec3(.3,.5,.8)*smoothstep(.89,.90,a)*(1.-smoothstep(.89,.99,a))*(dl-.9)*15.;
col *= shad;
    col -= vec3(.1,.3,.6)*(1.-moon*shad);
    col = clamp(col,0.,1.);
    return col;
}

vec3 stars(in vec3 ray){
    vec3 col = vec3(0.);
    float az = atan(.5*ray.z,-.5*ray.x)/PIdiv2;
    vec2 a = vec2(az,ray.y);
   
    float gr = -.5+a.x+a.y;
    float milky = 1.-smoothstep(0.,1.2,abs(gr));
float nebu = 1.-smoothstep(0.,.7,abs(gr));

    vec3 tex = texture(Organic_jpg,a+.3).rgb;
    vec3 tex2 = texture(Organic_jpg,a*.1).rgb;
vec3 tex3 = texture(Organic_jpg,a*5.).rgb;
float dark = 1.-smoothstep(0.,.3*tex.r,abs(gr));
   
    vec2 dty =a*12.;
    col += step(.85,Hsh2(floor(dty)))*(tex+vec3(.0,.1,.1))*max(0.,(.01/length(fract(dty)-.5)-.05));
   
    dty =a*30.;
    col += step(.8,Hsh2(floor(dty)))*tex*max(0.,(.01/length(fract(dty)-.5)-.05))*milky;
   
    dty =a*1000.;
    col += max(0.,Hsh2(floor(dty))-.9)*3.*tex3*milky;
   
    col += (.075+.7*smoothstep(.1,1.,(tex+vec3(.15,0.,0.))*.3))*nebu;
    col += .5*smoothstep(0.,1.,(tex2+vec3(0.,.2,.2))*.2)*milky;
col -= .15*(tex3 * dark);
   
    return col;
}

vec3 fewStars(in vec3 ray){
vec3 col = vec3(0.);
    float az = atan(.5*ray.z,-.5*ray.x)/PIdiv2;
    vec2 a = vec2(az,ray.y);
   
    vec3 tex = texture(Organic_jpg,a+.3).rgb;
    vec2 dty =a*14.;
    col += step(.85,Hsh2(floor(dty)))*(tex+vec3(.0,.1,.1))*max(0.,(.01/length(fract(dty)-.5)-.05));

    return col;
}

bool shadTrace(in vec3 pos, in vec3 v){
float dh = 0.;
    float t = 0.;
    vec4 wall = vec4(0.);
   
    for(int i = 0;i<10;i++){       
        vec3 p = pos + t*v;
        if(p.y > TOP_SURFACE) break;
       
        float h = map(p.xz);
        float dh = p.y - h;
        if(dh<.0) return true;
       
        vec4 vox = voxInfo(p.xz);
        float H = Hsh2(floor(100.*vox.xy));
        vec3 normsph;
        float ts = sphereImpact(p, v, vec3(vox.x,h-.5,vox.y), step(H,.6)*H*min(vox.z,vox.w), normsph );
        if(ts<INFINI) return true;
       
        vec3 normcyl = vec3(0.);
        float tc = cylinderImpact(p.xz, v.xz, vec2(vox.x,vox.y)+ (4.*H-.4)*vox.zw, .025*min(vox.z,vox.w), normcyl.xz );
        tc += step(step(H,.2)*2.5*H*TOP_SURFACE,p.y+tc*v.y)*INFINI;
        if(tc<INFINI) return true;
       
        wall = getNextPlan(p.xz,v.xz);       
        t+= wall.w + .0001 ;
    }   
    return false;   
}

bool shadTraceBis(in vec3 pos, in vec3 v){
float dh = 0.;
    float t = 0.;
    vec4 wall = vec4(0.);
   
    for(int i = 0;i<10;i++){       
        vec3 p = pos + t*v;
        if(p.y > TOP_SURFACE) break;
       
        vec4 vox = voxInfoBis(p.xz);
        vec3 normsph;
        float radius = 25.;
        float ts = sphereImpact(p, v, vec3(vox.x,TOP_SURFACE-radius-1.,vox.y), radius , normsph );
        if(ts<INFINI) return true;
       
        wall = getNextPlanBis(p.xz,v.xz);       
        t+= wall.w + .0001 ;
    }   
    return false;   
}

float shadow(in vec3 p){
    p += .00001*starLight;
    if(shadTrace(p,starLight)) return .1;
    if(shadTraceBis(p,starLight)) return .1;
    return 1.;
}

vec3 winGlow(in vec2 uv){
    uv.x *= .2;
    uv.y *= .5;
    vec2 k1 = (uv-.05*sin(uv*10.))*10.,
         k2 = (uv-.02*sin(uv*25.))*25.,
         k3 = (uv-.01*sin(uv*50.))*50.;
   
   
    vec2 p = floor(k1)/10.,
         q = floor(k2)/25.,
    s = floor(k3)/50.;
   
    vec2 bp = abs(fract(k1)-.5)
    + abs(fract(k2)-.5)
    + abs(fract(k3)-.5);
    bp /= 1.5;
    bp*=bp*bp;
   
    vec3 tex = texture(Cloth_jpg,p).rgb
    + texture(Cloth_jpg,q).rgb
    + texture(Cloth_jpg,s).rgb;
   
    tex += .5*(bp.x+bp.y);
    tex *= smoothstep(1.,2.8,tex.r);
   
return tex;
}


float metalPlate(in vec2 st){
    float coef = 0.;
   
    vec2 p = floor(st);
    float hp = Hsh2(p*0.543234); hp *= step(.2,abs(hp-.5));
    vec2 fp = fract(st)-.5;
    vec2 sfp = smoothstep(.475,.5,abs(fp));
   
    st *= vec2(.5,1.);
    vec2 q = floor(st*4.-.25);
    float hq = Hsh2(q*0.890976); hq *= step(.35,abs(hq-.5));
    vec2 fq = fract(st*4.-.25)-.5;
    vec2 sfq = smoothstep(.45,.5,abs(fq));

    st *= vec2(5.,.1);
    vec2 r = floor(st*8.-.25);
    float hr = Hsh2(r*0.123456); hr *= step(.47,abs(hr-.5));
    vec2 fr = fract(st*8.-.25)-.5;
    vec2 sfr = smoothstep(.4,.5,abs(fr));
   
    float h = max(max(hp,hq),hr);
    if(bool(h)){
        vec2 plate =    step(h,hp)*sfp*sign(fp)
                      + step(h,hq)*sfq*sign(fq)
                      + step(h,hr)*sfr*sign(fr);
       
        coef += .2*h+.8;
        coef += .5*min(1.,plate.x+plate.y);
    }
    else coef = 1.;
   
    return coef;
}


float flare(in vec3 ref, in vec3 ctr){
    float c = 0.;
    vec3
s = normalize(ref);
    float sc = dot(s,-starLight);
    c += .6*smoothstep(.9995,1.,sc);
   
    s = normalize(ref+.9*ctr);
    sc = dot(s,-starLight);
    c += .7*smoothstep(.99,1.,sc);
   
    s = normalize(ref-.7*ctr);
    sc = dot(s,-starLight);
    c += .2*smoothstep(.7,1.,sc);
   
    return c;
}

vec3 lensflare3D(in vec3 ray, in vec3 ctr)
{
    vec3 red = vec3(1.,.6,.3);
    vec3 green = vec3(.6,1.,.6);
    vec3 blue = vec3(.6,.3,.6);
vec3 col = vec3(0.);
    vec3 ref = reflect(ray,ctr);

    col += red*flare(ref,ctr);
    col += green*flare(ref-.07*ctr,ctr);
    col += blue*flare(ref-.14*ctr,ctr);
   
    ref = reflect(ctr,ray);
    col += red*flare(ref,ctr);
    col += green*flare(ref+.07*ctr,ctr);
    col += blue*flare(ref+.14*ctr,ctr);
   
    float d = dot(ctr,starLight);
return .4*col*max(0.,d*d*d*d*d);
}

vec3 lava(in vec2 p){
float tex = abs(texture(Organic_jpg,p*.05).r-.5+.3*sin(iTime*.2));
    vec3 lav = vec3(0.);
    lav.r += .5*(1.-smoothstep(.0,.2,tex));
    lav.rg += (1.-smoothstep(.0,.02,tex));
return lav;
}

vec3 getCamPos(in vec3 camTarget){
    float rau = 15.,
            alpha = iMouse.x/iResolution.x*4.*PI,
            theta = iMouse.y/iResolution.y*PI+(PI/2.0001);
   
            // to start shader
    if (iMouse.xy == vec2(0.)){
                float ts = smoothstep(18.,22.,iTime)*(iTime-20.);
                alpha = iTime*.04;
                theta = .3*(1.-cos(iTime*.1));
            }
    return rau*vec3(-cos(theta)*sin(alpha),sin(theta),cos(theta)*cos(alpha))+camTarget;
}

vec3 getRay(in vec2 st, in vec3 pos, in vec3 camTarget){
    float focal = 1.;
    vec3 ww = normalize( camTarget - pos);
    vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0)) ) ;
    vec3 vv = cross(uu,ww);
// create view ray
return normalize( st.x*uu + st.y*vv + focal*ww );
}

// 2 functions from Shane
// the famous "Old Nvidia tutorial"!
vec3 tex3D( sampler2D tex, in vec3 p, in vec3 n ){
 
    n = max((abs(n) - 0.2)*7., 0.001);
    n /= (n.x + n.y + n.z );     
vec3 tx = (texture(tex, p.yz)*n.x + texture(tex, p.zx)*n.y + texture(tex, p.xy)*n.z).xyz;   
    return tx*tx;
}

vec3 texBump( sampler2D tx, in vec3 p, in vec3 n, float bf, in float t, in vec3 ray){   
    //const vec2 e = vec2(0.001, 0);   
    vec2 e = vec2(.2*t/iResolution.x/dot(-ray,n),0.);    // AA purpose
    //vec2 e = vec2(.5*t/iResolution.x,0.);
    mat3 m = mat3( tex3D(tx, p - e.xyy, n), tex3D(tx, p - e.yxy, n), tex3D(tx, p - e.yyx, n));   
    vec3 g = vec3(0.299, 0.587, 0.114)*m;
    g = (g - dot(tex3D(tx,  p , n), vec3(0.299, 0.587, 0.114)) )/e.x; g -= n*dot(n, g);                     
    return normalize( n + g*bf );
}


void main(){
    vec2 st = ( gl_FragCoord.xy
               //-.5*vec2(mod(gl_FragCoord.y,2.),mod(gl_FragCoord.x,2.))
               - .5*iResolution.xy ) / iResolution.y;
   
    // camera def
    vec3 camTarget = vec3(100.*sin(iTime*.01),1.,-60.*sin(iTime*.015));
   
    vec3 pos = getCamPos(camTarget);
   
    pos.y = max(pos.y,1.5*gndFactor(pos.xz)+1.); // Cam anti-collision
   
    vec3 ray = getRay(st, pos,camTarget);
   
    float moonArea = dot(ray,moonCtr);
    float starArea = dot(ray,starLight);
    bool starside = bool(step(0.,starArea));
    bool moonside = bool(step(0.,moonArea));

    vec3 color = vec3(.0);
    vec4 flamInfo = vec4(0.);
    float t = INFINI;
    vec3 norm = vec3(0.);

    vec4 info = trace(pos, ray, flamInfo);
    float sc = hitScale;
    t = info.w;
    norm = info.xyz;
   
    info = traceBis(pos, ray);
    if(info.w < t){
        t=info.w;
        norm = info.xyz;
        hitObj = SPHBIS;
  if(flamInfo.w > t) flamInfo.rgb = vec3(0.);
    }
   
    info = traceGround(pos,ray);
    if(info.w < t){
        t=info.w;
        norm = info.xyz;
        hitObj = GND;
    }
   
    float shadow = shadow(pos+t*ray);
   
    if(t==INFINI){
        float moonMask = 1.-smoothstep(.925,.93,moonArea);
        float starMask = 1.-smoothstep(.4,.9,starArea);
        if(starside) color += .7*starGlow(ray,starArea);
        if(moonside) color += moonGlow(ray,moonArea);
       
        color += fewStars(ray)*moonMask*starMask;
        color += stars(ray)*moonMask*starMask;
        color *= min(1.,abs(10.*ray.y*ray.y));
        color += .006/(ray.y*ray.y+.015)*DUST;
    }
    else{
        if(norm.y < .99 && hitObj != GND) {
            info = traceWindow(pos ,ray, t, norm);
            if(bool(info.w)) {
                norm = info.xyz;
                t = info.w;
            }
        }
       
        vec3 p = pos + t*ray;

        if(hitObj == SPH){
            if(WINDOW){
                vec2 d = p.xz - voxInfo(p.xz).xy;
                vec3 window = winGlow(vec2(.5*atan(d.x,d.y),.8*length(d)));
                vec3 refl = reflect(ray,norm);
                color += smoothstep(.95,1.,dot(starLight,refl))*norm.z*step(1.,shadow);
                color += window*min(1., 30./t);
        }
            else{
                vec2 ang;
                if(SIDEWIN) ang = p.xz;
                else ang = vec2(atan(norm.x,norm.z), atan(norm.y,length(norm.xz)));
                color += texture(Metal_jpg,ang).rgb;
                color *= metalPlate(4.*ang);
                color += .015*vec3(.5*sc,abs(sc-4.),8.-sc) * min(1.,10./t);
                norm = texBump( Organic_jpg,.2*norm, norm, .005, t, ray);
                color *= max(dot(norm, starLight),.0);
                if(SIDEWIN) color += vec3(.1,.05,.0);
                else color *= shadow;
            }
        }
        else if(hitObj == CYL){
            if(WINDOW){
                vec3 window = winGlow(2.*p.zy);
                vec3 refl = reflect(ray,norm);
                color += smoothstep(.95,1.,dot(starLight,refl))*norm.z*step(1.,shadow);
                color += window*min(1., 30./t);
        }
            else{
                vec2 ang;
                if(SIDEWIN) ang = p.xz;
                else ang = vec2(atan(norm.x,norm.z), 2.*p.y);
                color += texture(Metal_jpg,ang).rgb;
                color *= metalPlate(2.*ang);
                color += .015*vec3(.5*sc,abs(sc-4.),8.-sc) * min(1.,10./t);
                color *= max(dot(norm, starLight),.0);
                if(SIDEWIN) color += vec3(.1,.05,.0);
                else color *= shadow;
            }
        }
        else if(hitObj == SPHBIS){
            if(WINDOW){
                vec2 d = p.xz - voxInfoBis(p.xz).xy;
                vec3 window = .5*winGlow(vec2(3.*atan(d.x,d.y),.25*length(d)));
                vec3 refl = reflect(ray,norm);
                color += smoothstep(.95,1.,dot(starLight,refl))*norm.z*step(1.,shadow);
                color += window*min(1., 30./t);
        }
            else{
                vec2 ang;
                if(SIDEWIN) ang = .5*p.xz;
                else ang = vec2(atan(norm.x,norm.z), atan(norm.y,length(norm.xz)));
                color += texture(Metal_jpg,ang).rgb;
                color *= metalPlate(4.*ang);
                sc =1.;
                color += .015*vec3(.5*sc,abs(sc-4.),8.-sc) * min(1.,10./t);
                norm = texBump( Organic_jpg,2.*norm, norm, .002, t, ray);
                color *= max(dot(norm, starLight),.0);
                if(SIDEWIN) color += vec3(.1,.05,.0);
                else color *= shadow;

            }
        }   
        else if(hitObj == GND){
            vec3 dirt = texture(Organic_jpg,GS*p.xz).rgb;
            color = 1.5*p.y*dirt*dirt;
           
            color *= max(0.,dot(norm, -starLight));
            color *= shadow;
           
            vec2 e = t/iResolution.x/ray.y*ray.xz; // 2 lines for AA purpose
            vec3 lavaCol = (lava(p.xz)+lava(p.xz+e)+lava(p.xz-e))/3.;
           
color += .8*lavaCol*(1.-smoothstep(.0,.1,dirt.r));
        }
        else{
            if(p.y <.01) color = vec3(0.);
            else{
                if(WINDOW){
                    vec3 window = winGlow( (p.xy+p.z)*norm.z + (p.zy+p.x)*norm.x);
                    vec3 refl = reflect(ray,norm);
                    color += smoothstep(.95,1.,dot(starLight,refl))*norm.z*step(1.,shadow);
                    color += window*min(1., 30./t);
                }
                else{
                    vec2 side = .5*vec2(p.x,-p.z)*norm.y + .5*vec2(-p.x,-p.y)*norm.z + .5*vec2(p.y,-p.z)*norm.x;
                    color += texture(Metal_jpg,side).rgb;
                   
                    vec2 e = vec2(2.*t/iResolution.x/dot(-ray,norm),0.); // 2 lines for AA purpose
                    float mp =  ( metalPlate(4.*side)
                            + metalPlate(4.*side+e)
                        + metalPlate(4.*side-e)
                        + metalPlate(4.*side+e.yx)
                        + metalPlate(4.*side-e.yx)) /5.;
                   
                    color *= mp;
                    color += .015*vec3(.5*sc,abs(sc-4.),8.-sc) * min(1.,10./t);

                    norm = texBump( Organic_jpg, .2*p, norm, .003, t, ray);

                    color *= clamp(dot(norm, starLight)+.2,.3,1.);
                    if(SIDEWIN) color += vec3(.1,.05,.0);
                    else color *= shadow;

                    vec3 refl = reflect(ray,norm);
                    color += .3*smoothstep(.9,1.,dot(starLight,refl))*norm.z*step(1.,shadow);;
                    color = clamp(color,0.,1.);
                }
            }
        }
        color *= min(1., 20./t);
        color += min(.003*t,.35)*DUST;
    }
   
    color += flamInfo.rgb*flamInfo.rgb;

    if(starside)
    //if(!shadTrace(pos,starLight))
    color += lensflare3D(ray, getRay(vec2(0.), pos,camTarget));
   
gl_FragColor = vec4(1.5*color,1.);
}
   
   
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #94 on: December 14, 2019, 08:53:21 pm »
My friend,

I'm absolutely happy that you've finally come to enjoy shaders. :D

Thank you for your work!

Regarding I'veSeen, your colors are incorrect because it's a two pass shader that needs two FBO's to get rendered as intended. (see there are TWO CODE TABS on ShaderToy?)

Such shaders need to run in two render passes, like background+PP shaders combined, which we can't do yet in our OR. Please try to port only one-FBO shaders -- those whose code is written in one code tab only! (not counting the sound tab if present)

P.S. Now that there's a genuine Wood.jpg in the \Animated folder, please open up my FractalFlythrough.fs and change all multiple occurrences of metal_jpg to wood_jpg. Now the metal structure colors will be exactly like they are on ShaderToy.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #95 on: December 14, 2019, 09:42:14 pm »
Patrice,

I'veSeen.fs can safely be run in one pass (with one buffer) but all its textures should not be mipmapped.

To this end, the names of samplers throughout the code should be prefixed with nomip_. (actually nomip_moss_jpg is not used in the shader code at all)

Enjoy! :D

Code: [Select]
// Author: ocb
// Title: I've seen...

/***********************************************************************
Evolution based on Hope shader:  https://www.shadertoy.com/view/MllfDX
Still playing around with grids, (intersecting - overlaping...) to manage
lots of objects in order to generate all kind of cities.
Three intersecting grids generate variable size voxels which contains
cylinder (pipe), or sphere (little dome) or squared building.
One overlaping grid to generate big dome.

Using Shane's functions (the famous "Old nVidia tutorial) to create the decrepit
surface of the building.

Use mouse to look around

Sorry for thr unreadable code.
************************************************************************/

uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

uniform sampler2D nomip_metal_jpg;
//uniform sampler2D Moss_jpg; // MLL: not used
uniform sampler2D nomip_cloth_jpg;
uniform sampler2D nomip_organic_jpg;

#define PI 3.141592653589793
#define PIdiv2 1.57079632679489
#define TwoPI 6.283185307179586
#define INFINI 1000000.
#define MAXSTEP 127
#define TOP_SURFACE 2.81

/*************  GRID ****************************************************/
#define A .13
#define B .41
#define C .47

#define G2 .02
#define GS .003

/*************  Object **************************************************/
#define GND 0
#define SKY 1
#define CYL 2
#define SPH 3
#define SIDE 4
#define SPHBIS 5

#define DUST vec3(1.,.9,.7)



#define moonCtr vec3(.10644925908247,.266123147706175,.958043331742229)
#define moonShad vec3(-0.435448415412873,0.224265278324226,0.87183126948543)
#define moonRefl vec3(0.524134547566281, 0.21940212059613, 0.822888622794975)

#define starLight vec3(0.814613079962557,0.203653269990639,-0.543075386641705)

int hitObj = SKY;
float hitScale = 1.;
bool WINDOW = false;
bool SIDEWIN = false;

float Hsh(in float v) {
    return fract(sin(v) * 437585.);
}


float Hsh2(in vec2 st) {
    return fract(sin(dot(st,vec2(12.9898,8.233))) * 43758.5453123);
}


float sphereImpact(in vec3 pos, in vec3 ray, in vec3 O, in float R, inout vec3 norm ){
    float d=0., t = INFINI;
    vec3 a = O - pos;
    float b = dot(a, ray);

    if (b >= 0.){ // check if object in frontside first (not behind screen)
        float c = dot(a,a) - R*R;
    d = b*b - c;
    if (d >= 0.){
        float sd = sqrt(d);
            t = b - sd;
            norm = normalize(pos + t*ray - O);
        }
    }

    return t;
}

float cylinderImpact(in vec2 pos,in vec2 ray, in vec2 O, in float R, inout vec2 norm){
    float t=INFINI;
    vec2 d = pos - O;
    float a = dot(ray,ray);
    float b = dot(d, ray);
    float c = dot(d,d) - R*R;
    float discr = b*b - a*c;
    if (discr >= 0.){
        t = (-b - sqrt(discr))/a;
        if (t < 0.001) t = (-b + sqrt(discr))/a;
        if (t < 0.001) t=INFINI;

        norm = normalize(pos + t*ray - O);
    }
return t;
}


vec4 voxInfo(in vec2 xz){
vec2 dtp = fract(xz*A)/A;
    vec2 dtq = fract((xz)*B)/B;
    vec2 dtr = fract((xz)*C)/C;
    vec2 dm1 = min(min(dtp,dtq),dtr);

    dtp = 1./A-dtp;
    dtq = 1./B-dtq;
    dtr = 1./C-dtr;
    vec2 dm2 = min(min(dtp,dtq),dtr);

    vec2 size = dm1+dm2;
    vec2 ctr = xz+.5*(dm2-dm1);

    return vec4(ctr,size);

}

vec4 voxInfoBis(in vec2 xz){
    vec2 size = vec2(1./G2);
    vec2 ctr = (floor(xz*G2)+.5)*size;
    return vec4(ctr,size);

}

vec4 getNextPlan(in vec2 xz, in vec2 v){
    vec2 s = sign(v);
    vec2 d = step(0.,s);
vec2 dtp = (d-fract(xz*A))/A/v;
    vec2 dtq = (d-fract((xz)*B))/B/v;
    vec2 dtr = (d-fract((xz)*C))/C/v;

    vec2 dmin = min(min(dtp,dtq),dtr);
    float tmin = min(dmin.x, dmin.y);

    s *= -step(dmin,vec2(tmin));

    return vec4(s.x,0.,s.y,tmin);
}

vec4 getNextPlanBis(in vec2 xz, in vec2 v){
    vec2 s = sign(v);
    vec2 d = step(0.,s);
vec2 dtp = (d-fract(xz*G2))/G2/v;

    float tmin = min(dtp.x, dtp.y);

    s *= -step(tmin,vec2(tmin));

    return vec4(s.x,0.,s.y,tmin);
}


float gndFactor(in vec2 p) // use for cam anti-collision
{
vec2 f = 1.5-3.*abs(fract(p.xy*G2)-.5);
    f=smoothstep(.9,1.8,f);
    return 1.5*(f.x+f.y);
}

float map(in vec2 xz)
{
    vec2 p = floor(xz*A)/A;
    vec2 q = floor((xz)*B)/B;
    vec2 r = floor((xz)*C)/C;

    vec2 f = 1.5-abs(fract(p*G2)-.5)-abs(fract(q*G2)-.5)-abs(fract(r*G2)-.5);
    f=smoothstep(.9,1.8,f);
    float c = 1.5*(f.x+f.y);

    float Hp = c*Hsh2(p), Hq = c*Hsh2(q), Hr = c*Hsh2(r);
    float Pp = step(.6,Hp), Pq = step(.6,Hq), Pr = step(.5,Hr);

    float tex = 1.*Hp*Pp + .5*Hq*Pq +.3*Hr*Pr;
    hitScale = Pp + 2.5*Pq + 5.*Pr;

    return tex;
}


vec4 trace(in vec3 pos, in vec3 ray, inout vec4 flam)
{
    float dh = 0.;
    float t = 0.;

    if(pos.y > TOP_SURFACE){ // navigating directly to the top surface (perfos)
        if(ray.y >= 0.) return vec4(vec3(0.),INFINI);
t = (TOP_SURFACE - pos.y)/ray.y + 0.00001;
    }

    vec4 wall = vec4(0.); // wall.xyz is the normal of the wall. wall.w is the t parameter.

    for(int i = 0;i<MAXSTEP;i++){ // entering the voxel run

        vec3 p = pos+t*ray;
        if(p.y > TOP_SURFACE) break; // when "looking" up, you may fly out before hiting
        // break immediately (perfos)
        float h = map(p.xz);
        float dh = p.y - h;
        if(dh<.0) return vec4(wall.xyz,t-.00002); // you are suddenly below the floor?
        // you hit the previous wall

        wall = getNextPlan(p.xz,ray.xz); // find the next wall
        float tt = 0.;

        float th = dh/(-ray.y); // find the floor
        th += step(th,0.)*INFINI;

        vec4 vox = voxInfo(p.xz); // get voxel info: center and size
        float H = Hsh2(floor(100.*vox.xy));

        vec3 normsph = vec3(0.); // Little dome
        float ts = INFINI;
        if(bool(step(H,.6)) && t<150.){
        ts = sphereImpact(p, ray, vec3(vox.x,h-.5,vox.y), H*min(vox.z,vox.w), normsph );
        }

        vec3 normcyl = vec3(0.); // Pipe
        float tc = INFINI;
        if(bool(step(H,.2)) && t<100.){
            vec2 c = vox.xy+ (4.*H-.4)*vox.zw;
            float r = .025*min(vox.z,vox.w);
            float top = 2.5*H*TOP_SURFACE;
            tc = cylinderImpact(p.xz, ray.xz, c, r, normcyl.xz );
            tc += step(top,p.y+tc*ray.y)*INFINI;

            float Hc = (H-.15)*20.;
        float ti = iTime*.4;
            // Flam calculation
        if(bool(step(.15,H)*step(.95,Hsh(.0001*(vox.x+vox.y)*floor(Hc+ti))) )){
                float fti = fract(Hc+ti);
                vec2 len = c-pos.xz;
                float h = length(len)*ray.y/length(ray.xz)+pos.y;
                float dh = h - top;
                float d = abs(ray.z*len.x - ray.x*len.y);
                float mvt = 1.+cos(5.*dh);
                flam.rgb += min(1.,min(1.,min(vox.z,vox.w))*.2*mvt*(r+dh)/d-.1)
                       *step(0.,dh)
                       *((.8-abs(fti-.5))/(dh+.2) -.3 )
                       *texture(nomip_organic_jpg,vec2(.2*h-.5*ti+Hc,d*(1.+fti)*dh*mvt+Hc)).rgb;
                flam*=flam*(2.-fti);
                flam.w = t;
            }
        }


        tt = min(min(ts,th),tc);
        tt = min(wall.w,tt); // keep the min between floor and wall distance
        if(tt==th) return vec4(0.,1.,0.,t+tt); // if first hit = floor return hit info (floor)
        else if(tt==ts){hitObj = SPH; return vec4(normsph,t+tt);}
        else if(tt==tc){hitObj = CYL; return vec4(normcyl,t+tt);}
        else tt = wall.w; // else keep the local t parameter to the next wall

        t+= tt+.00001; // update global t and do again
        if(t>250.) break; // not necessary to go too far (perfos)
    }


    return vec4(0.,0.,0.,INFINI);
}

vec4 traceBis(in vec3 pos, in vec3 ray)
{
    float dh = 0.;
    float t = 0.;

    if(pos.y > TOP_SURFACE){ // navigating directly to the top surface (perfos)
        if(ray.y >= 0.) return vec4(vec3(0.),INFINI);
t = (TOP_SURFACE - pos.y)/ray.y + 0.00001;
    }

    vec4 wall = vec4(0.); // wall.xyz is the normal of the wall. wall.w is the t parameter.

    for(int i = 0;i<MAXSTEP;i++){ // entering the voxel run

        vec3 p = pos+t*ray;
        if(p.y > TOP_SURFACE) break; // when "looking" up, you may fly out before hiting
        // break immediately (perfos)

        wall = getNextPlanBis(p.xz,ray.xz); // find the next wall

        vec4 vox = voxInfoBis(p.xz);
        vec3 normsph;
        float radius = 25.;//.5*min(vox.z,vox.w);
        float tt = sphereImpact(p, ray, vec3(vox.x,TOP_SURFACE-radius-1.,vox.y), radius , normsph );

        if(tt<INFINI) return vec4(normsph,t+tt);
        else tt = wall.w; // else keep the local t parameter to the next wall

        t+= tt+.00001; // update global t and do again
        if(t>250.) break; // not necessary to go too far (perfos)
    }


    return vec4(0.,0.,0.,INFINI);
}


float mapGnd(in vec3 p){return .5*texture(nomip_organic_jpg, GS*p.xz).r +.2*texture(nomip_organic_jpg, 2.*GS*p.xz).r;}

vec4 traceGround(in vec3 pos, in vec3 ray)
{
if(ray.y>0.) return vec4(0.,0.,0.,INFINI);

    float t = (mapGnd(pos) - pos.y)/ray.y;

    for(int i = 0;i<MAXSTEP;i++){

        vec3 p = pos+t*ray;
        float dh = p.y-mapGnd(p);

        if(abs(dh) < .003){
vec2 e = vec2(-.2,.2);
vec3 norm = normalize(e.yxx*mapGnd(p + e.yxx) + e.xxy*mapGnd(p + e.xxy) +
         e.xyx*mapGnd(p + e.xyx) + e.yyy*mapGnd(p + e.yyy) );

            return vec4(norm,t);
        }

        t += dh;

        if(t>250.) break;
    }

    return vec4(0.,0.,0.,INFINI);
}


vec4 boxImpact( in vec3 pos, in vec3 ray, in vec3 ctr, in vec3 dim)
{
    vec3 m = 1.0/ray;
    vec3 n = m*(ctr-pos);
    vec3 k = abs(m)*dim;

    vec3 t1 = n - k;
    vec3 t2 = n + k;

float tmax = max( max( t1.x, t1.y ), t1.z );
float tmin = min( min( t2.x, t2.y ), t2.z );

if( tmax > tmin || tmin < 0.0) return vec4(vec3(0.),INFINI);

    vec3 norm = -sign(ray)*step(t2, vec3(tmin));
    return vec4(norm, tmin);
}


bool checkWindow(in vec3 ctr){
    float hash = Hsh2(ctr.xz+ctr.yy);
    float a = step(.4,hash)*step(mod(ctr.y,10.),0.);
    float b = step(.7,hash)*step(mod(ctr.y-1.,10.),0.);
    return bool(a+b);
}

vec4 traceWindow(in vec3 pos, in vec3 ray, in float t, in vec3 norm){
    float d, sh, sv;
    if(hitObj == SPHBIS){d=.03; sh=2.5; sv=1.;}
    else if(hitObj == SPH){d=.03; sh=.5; sv=.75;}
    else if(hitObj == CYL){d=.01; sh=.1; sv= 1.;}
    else {d=.1; sh=1.; sv=1.;}

    vec3 p = pos + t*ray;
    vec4 info = vec4(norm,t);

    vec3 boxDim = vec3(sh*.25,sv*.025,sh*.25);
vec3 boxCtr;

    for(int i=0; i<5; i++){
    boxCtr = vec3(floor(p.x*2./sh),floor(p.y*20./sv),floor(p.z*2./sh));
        if(checkWindow(boxCtr)){
            SIDEWIN = true;
            float tf = t + d/dot(ray,-norm);
            info = boxImpact(pos, ray, (boxCtr+.5)*vec3(sh*.5,sv*.05,sh*.5), boxDim);
            if(tf < info.w){
                WINDOW = true;
                info = vec4(norm,tf);
                break;
            }
            p = pos + (info.w+.001)*ray;
        }
        else break;
    }
    return info;
}

vec3 starGlow(in vec3 ray, in float a){
    vec3 col = vec3(.001/(1.0001-a));
    return col;
}

vec3 moonGlow(in vec3 ray, in float a){
    float dl = dot(moonRefl,ray);
    float moon = smoothstep(.9,.93,a);
    float shad = 1.-smoothstep(.7,.9,dot(moonShad, ray));
    float refl = .001/(1.0013-dl);
float clouds = .5*texture(nomip_organic_jpg,ray.xy).r+.3*texture(nomip_organic_jpg,3.*ray.xy).r;
    vec3 col = .8*(vec3(.5,.3,.0)+clouds*vec3(.3,.4,.1))*moon+vec3(1.,1.,.7)*refl;
    col += vec3(.3,.5,.8)*smoothstep(.89,.90,a)*(1.-smoothstep(.89,.99,a))*(dl-.9)*15.;
col *= shad;
    col -= vec3(.1,.3,.6)*(1.-moon*shad);
    col = clamp(col,0.,1.);
    return col;
}

vec3 stars(in vec3 ray){
    vec3 col = vec3(0.);
    float az = atan(.5*ray.z,-.5*ray.x)/PIdiv2;
    vec2 a = vec2(az,ray.y);

    float gr = -.5+a.x+a.y;
    float milky = 1.-smoothstep(0.,1.2,abs(gr));
float nebu = 1.-smoothstep(0.,.7,abs(gr));

    vec3 tex = texture(nomip_organic_jpg,a+.3).rgb;
    vec3 tex2 = texture(nomip_organic_jpg,a*.1).rgb;
vec3 tex3 = texture(nomip_organic_jpg,a*5.).rgb;
float dark = 1.-smoothstep(0.,.3*tex.r,abs(gr));

    vec2 dty =a*12.;
    col += step(.85,Hsh2(floor(dty)))*(tex+vec3(.0,.1,.1))*max(0.,(.01/length(fract(dty)-.5)-.05));

    dty =a*30.;
    col += step(.8,Hsh2(floor(dty)))*tex*max(0.,(.01/length(fract(dty)-.5)-.05))*milky;

    dty =a*1000.;
    col += max(0.,Hsh2(floor(dty))-.9)*3.*tex3*milky;

    col += (.075+.7*smoothstep(.1,1.,(tex+vec3(.15,0.,0.))*.3))*nebu;
    col += .5*smoothstep(0.,1.,(tex2+vec3(0.,.2,.2))*.2)*milky;
col -= .15*(tex3 * dark);

    return col;
}

vec3 fewStars(in vec3 ray){
vec3 col = vec3(0.);
    float az = atan(.5*ray.z,-.5*ray.x)/PIdiv2;
    vec2 a = vec2(az,ray.y);

    vec3 tex = texture(nomip_organic_jpg,a+.3).rgb;
    vec2 dty =a*14.;
    col += step(.85,Hsh2(floor(dty)))*(tex+vec3(.0,.1,.1))*max(0.,(.01/length(fract(dty)-.5)-.05));

    return col;
}

bool shadTrace(in vec3 pos, in vec3 v){
float dh = 0.;
    float t = 0.;
    vec4 wall = vec4(0.);

    for(int i = 0;i<10;i++){
        vec3 p = pos + t*v;
        if(p.y > TOP_SURFACE) break;

        float h = map(p.xz);
        float dh = p.y - h;
        if(dh<.0) return true;

        vec4 vox = voxInfo(p.xz);
        float H = Hsh2(floor(100.*vox.xy));
        vec3 normsph;
        float ts = sphereImpact(p, v, vec3(vox.x,h-.5,vox.y), step(H,.6)*H*min(vox.z,vox.w), normsph );
        if(ts<INFINI) return true;

        vec3 normcyl = vec3(0.);
        float tc = cylinderImpact(p.xz, v.xz, vec2(vox.x,vox.y)+ (4.*H-.4)*vox.zw, .025*min(vox.z,vox.w), normcyl.xz );
        tc += step(step(H,.2)*2.5*H*TOP_SURFACE,p.y+tc*v.y)*INFINI;
        if(tc<INFINI) return true;

        wall = getNextPlan(p.xz,v.xz);
        t+= wall.w + .0001 ;
    }
    return false;
}

bool shadTraceBis(in vec3 pos, in vec3 v){
float dh = 0.;
    float t = 0.;
    vec4 wall = vec4(0.);

    for(int i = 0;i<10;i++){
        vec3 p = pos + t*v;
        if(p.y > TOP_SURFACE) break;

        vec4 vox = voxInfoBis(p.xz);
        vec3 normsph;
        float radius = 25.;
        float ts = sphereImpact(p, v, vec3(vox.x,TOP_SURFACE-radius-1.,vox.y), radius , normsph );
        if(ts<INFINI) return true;

        wall = getNextPlanBis(p.xz,v.xz);
        t+= wall.w + .0001 ;
    }
    return false;
}

float shadow(in vec3 p){
    p += .00001*starLight;
    if(shadTrace(p,starLight)) return .1;
    if(shadTraceBis(p,starLight)) return .1;
    return 1.;
}

vec3 winGlow(in vec2 uv){
    uv.x *= .2;
    uv.y *= .5;
    vec2 k1 = (uv-.05*sin(uv*10.))*10.,
         k2 = (uv-.02*sin(uv*25.))*25.,
         k3 = (uv-.01*sin(uv*50.))*50.;


    vec2 p = floor(k1)/10.,
         q = floor(k2)/25.,
    s = floor(k3)/50.;

    vec2 bp = abs(fract(k1)-.5)
    + abs(fract(k2)-.5)
    + abs(fract(k3)-.5);
    bp /= 1.5;
    bp*=bp*bp;

    vec3 tex = texture(nomip_cloth_jpg,p).rgb
    + texture(nomip_cloth_jpg,q).rgb
    + texture(nomip_cloth_jpg,s).rgb;

    tex += .5*(bp.x+bp.y);
    tex *= smoothstep(1.,2.8,tex.r);

return tex;
}


float metalPlate(in vec2 st){
    float coef = 0.;

    vec2 p = floor(st);
    float hp = Hsh2(p*0.543234); hp *= step(.2,abs(hp-.5));
    vec2 fp = fract(st)-.5;
    vec2 sfp = smoothstep(.475,.5,abs(fp));

    st *= vec2(.5,1.);
    vec2 q = floor(st*4.-.25);
    float hq = Hsh2(q*0.890976); hq *= step(.35,abs(hq-.5));
    vec2 fq = fract(st*4.-.25)-.5;
    vec2 sfq = smoothstep(.45,.5,abs(fq));

    st *= vec2(5.,.1);
    vec2 r = floor(st*8.-.25);
    float hr = Hsh2(r*0.123456); hr *= step(.47,abs(hr-.5));
    vec2 fr = fract(st*8.-.25)-.5;
    vec2 sfr = smoothstep(.4,.5,abs(fr));

    float h = max(max(hp,hq),hr);
    if(bool(h)){
        vec2 plate =    step(h,hp)*sfp*sign(fp)
                      + step(h,hq)*sfq*sign(fq)
                      + step(h,hr)*sfr*sign(fr);

        coef += .2*h+.8;
        coef += .5*min(1.,plate.x+plate.y);
    }
    else coef = 1.;

    return coef;
}


float flare(in vec3 ref, in vec3 ctr){
    float c = 0.;
    vec3
s = normalize(ref);
    float sc = dot(s,-starLight);
    c += .6*smoothstep(.9995,1.,sc);

    s = normalize(ref+.9*ctr);
    sc = dot(s,-starLight);
    c += .7*smoothstep(.99,1.,sc);

    s = normalize(ref-.7*ctr);
    sc = dot(s,-starLight);
    c += .2*smoothstep(.7,1.,sc);

    return c;
}

vec3 lensflare3D(in vec3 ray, in vec3 ctr)
{
    vec3 red = vec3(1.,.6,.3);
    vec3 green = vec3(.6,1.,.6);
    vec3 blue = vec3(.6,.3,.6);
vec3 col = vec3(0.);
    vec3 ref = reflect(ray,ctr);

    col += red*flare(ref,ctr);
    col += green*flare(ref-.07*ctr,ctr);
    col += blue*flare(ref-.14*ctr,ctr);

    ref = reflect(ctr,ray);
    col += red*flare(ref,ctr);
    col += green*flare(ref+.07*ctr,ctr);
    col += blue*flare(ref+.14*ctr,ctr);

    float d = dot(ctr,starLight);
return .4*col*max(0.,d*d*d*d*d);
}

vec3 lava(in vec2 p){
float tex = abs(texture(nomip_organic_jpg,p*.05).r-.5+.3*sin(iTime*.2));
    vec3 lav = vec3(0.);
    lav.r += .5*(1.-smoothstep(.0,.2,tex));
    lav.rg += (1.-smoothstep(.0,.02,tex));
return lav;
}

vec3 getCamPos(in vec3 camTarget){
    float rau = 15.,
            alpha = iMouse.x/iResolution.x*4.*PI,
            theta = iMouse.y/iResolution.y*PI+(PI/2.0001);

            // to start shader
    if (iMouse.xy == vec2(0.)){
                float ts = smoothstep(18.,22.,iTime)*(iTime-20.);
                alpha = iTime*.04;
                theta = .3*(1.-cos(iTime*.1));
            }
    return rau*vec3(-cos(theta)*sin(alpha),sin(theta),cos(theta)*cos(alpha))+camTarget;
}

vec3 getRay(in vec2 st, in vec3 pos, in vec3 camTarget){
    float focal = 1.;
    vec3 ww = normalize( camTarget - pos);
    vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0)) ) ;
    vec3 vv = cross(uu,ww);
// create view ray
return normalize( st.x*uu + st.y*vv + focal*ww );
}

// 2 functions from Shane
// the famous "Old Nvidia tutorial"!
vec3 tex3D( sampler2D tex, in vec3 p, in vec3 n ){

    n = max((abs(n) - 0.2)*7., 0.001);
    n /= (n.x + n.y + n.z );
vec3 tx = (texture(tex, p.yz)*n.x + texture(tex, p.zx)*n.y + texture(tex, p.xy)*n.z).xyz;
    return tx*tx;
}

vec3 texBump( sampler2D tx, in vec3 p, in vec3 n, float bf, in float t, in vec3 ray){
    //const vec2 e = vec2(0.001, 0);
    vec2 e = vec2(.2*t/iResolution.x/dot(-ray,n),0.);    // AA purpose
    //vec2 e = vec2(.5*t/iResolution.x,0.);
    mat3 m = mat3( tex3D(tx, p - e.xyy, n), tex3D(tx, p - e.yxy, n), tex3D(tx, p - e.yyx, n));
    vec3 g = vec3(0.299, 0.587, 0.114)*m;
    g = (g - dot(tex3D(tx,  p , n), vec3(0.299, 0.587, 0.114)) )/e.x; g -= n*dot(n, g);
    return normalize( n + g*bf );
}


void main(){
    vec2 st = ( gl_FragCoord.xy
               //-.5*vec2(mod(gl_FragCoord.y,2.),mod(gl_FragCoord.x,2.))
               - .5*iResolution.xy ) / iResolution.y;

    // camera def
    vec3 camTarget = vec3(100.*sin(iTime*.01),1.,-60.*sin(iTime*.015));

    vec3 pos = getCamPos(camTarget);

    pos.y = max(pos.y,1.5*gndFactor(pos.xz)+1.); // Cam anti-collision

    vec3 ray = getRay(st, pos,camTarget);

    float moonArea = dot(ray,moonCtr);
    float starArea = dot(ray,starLight);
    bool starside = bool(step(0.,starArea));
    bool moonside = bool(step(0.,moonArea));

    vec3 color = vec3(.0);
    vec4 flamInfo = vec4(0.);
    float t = INFINI;
    vec3 norm = vec3(0.);

    vec4 info = trace(pos, ray, flamInfo);
    float sc = hitScale;
    t = info.w;
    norm = info.xyz;

    info = traceBis(pos, ray);
    if(info.w < t){
        t=info.w;
        norm = info.xyz;
        hitObj = SPHBIS;
  if(flamInfo.w > t) flamInfo.rgb = vec3(0.);
    }

    info = traceGround(pos,ray);
    if(info.w < t){
        t=info.w;
        norm = info.xyz;
        hitObj = GND;
    }

    float shadow = shadow(pos+t*ray);

    if(t==INFINI){
        float moonMask = 1.-smoothstep(.925,.93,moonArea);
        float starMask = 1.-smoothstep(.4,.9,starArea);
        if(starside) color += .7*starGlow(ray,starArea);
        if(moonside) color += moonGlow(ray,moonArea);

        color += fewStars(ray)*moonMask*starMask;
        color += stars(ray)*moonMask*starMask;
        color *= min(1.,abs(10.*ray.y*ray.y));
        color += .006/(ray.y*ray.y+.015)*DUST;
    }
    else{
        if(norm.y < .99 && hitObj != GND) {
            info = traceWindow(pos ,ray, t, norm);
            if(bool(info.w)) {
                norm = info.xyz;
                t = info.w;
            }
        }

        vec3 p = pos + t*ray;

        if(hitObj == SPH){
            if(WINDOW){
                vec2 d = p.xz - voxInfo(p.xz).xy;
                vec3 window = winGlow(vec2(.5*atan(d.x,d.y),.8*length(d)));
                vec3 refl = reflect(ray,norm);
                color += smoothstep(.95,1.,dot(starLight,refl))*norm.z*step(1.,shadow);
                color += window*min(1., 30./t);
        }
            else{
                vec2 ang;
                if(SIDEWIN) ang = p.xz;
                else ang = vec2(atan(norm.x,norm.z), atan(norm.y,length(norm.xz)));
                color += texture(nomip_metal_jpg,ang).rgb;
                color *= metalPlate(4.*ang);
                color += .015*vec3(.5*sc,abs(sc-4.),8.-sc) * min(1.,10./t);
                norm = texBump( nomip_organic_jpg,.2*norm, norm, .005, t, ray);
                color *= max(dot(norm, starLight),.0);
                if(SIDEWIN) color += vec3(.1,.05,.0);
                else color *= shadow;
            }
        }
        else if(hitObj == CYL){
            if(WINDOW){
                vec3 window = winGlow(2.*p.zy);
                vec3 refl = reflect(ray,norm);
                color += smoothstep(.95,1.,dot(starLight,refl))*norm.z*step(1.,shadow);
                color += window*min(1., 30./t);
        }
            else{
                vec2 ang;
                if(SIDEWIN) ang = p.xz;
                else ang = vec2(atan(norm.x,norm.z), 2.*p.y);
                color += texture(nomip_metal_jpg,ang).rgb;
                color *= metalPlate(2.*ang);
                color += .015*vec3(.5*sc,abs(sc-4.),8.-sc) * min(1.,10./t);
                color *= max(dot(norm, starLight),.0);
                if(SIDEWIN) color += vec3(.1,.05,.0);
                else color *= shadow;
            }
        }
        else if(hitObj == SPHBIS){
            if(WINDOW){
                vec2 d = p.xz - voxInfoBis(p.xz).xy;
                vec3 window = .5*winGlow(vec2(3.*atan(d.x,d.y),.25*length(d)));
                vec3 refl = reflect(ray,norm);
                color += smoothstep(.95,1.,dot(starLight,refl))*norm.z*step(1.,shadow);
                color += window*min(1., 30./t);
        }
            else{
                vec2 ang;
                if(SIDEWIN) ang = .5*p.xz;
                else ang = vec2(atan(norm.x,norm.z), atan(norm.y,length(norm.xz)));
                color += texture(nomip_metal_jpg,ang).rgb;
                color *= metalPlate(4.*ang);
                sc =1.;
                color += .015*vec3(.5*sc,abs(sc-4.),8.-sc) * min(1.,10./t);
                norm = texBump( nomip_organic_jpg,2.*norm, norm, .002, t, ray);
                color *= max(dot(norm, starLight),.0);
                if(SIDEWIN) color += vec3(.1,.05,.0);
                else color *= shadow;

            }
        }
        else if(hitObj == GND){
            vec3 dirt = texture(nomip_organic_jpg,GS*p.xz).rgb;
            color = 1.5*p.y*dirt*dirt;

            color *= max(0.,dot(norm, -starLight));
            color *= shadow;

            vec2 e = t/iResolution.x/ray.y*ray.xz; // 2 lines for AA purpose
            vec3 lavaCol = (lava(p.xz)+lava(p.xz+e)+lava(p.xz-e))/3.;

color += .8*lavaCol*(1.-smoothstep(.0,.1,dirt.r));
        }
        else{
            if(p.y <.01) color = vec3(0.);
            else{
                if(WINDOW){
                    vec3 window = winGlow( (p.xy+p.z)*norm.z + (p.zy+p.x)*norm.x);
                    vec3 refl = reflect(ray,norm);
                    color += smoothstep(.95,1.,dot(starLight,refl))*norm.z*step(1.,shadow);
                    color += window*min(1., 30./t);
                }
                else{
                    vec2 side = .5*vec2(p.x,-p.z)*norm.y + .5*vec2(-p.x,-p.y)*norm.z + .5*vec2(p.y,-p.z)*norm.x;
                    color += texture(nomip_metal_jpg,side).rgb;

                    vec2 e = vec2(2.*t/iResolution.x/dot(-ray,norm),0.); // 2 lines for AA purpose
                    float mp =  ( metalPlate(4.*side)
                            + metalPlate(4.*side+e)
                        + metalPlate(4.*side-e)
                        + metalPlate(4.*side+e.yx)
                        + metalPlate(4.*side-e.yx)) /5.;

                    color *= mp;
                    color += .015*vec3(.5*sc,abs(sc-4.),8.-sc) * min(1.,10./t);

                    norm = texBump( nomip_organic_jpg, .2*p, norm, .003, t, ray);

                    color *= clamp(dot(norm, starLight)+.2,.3,1.);
                    if(SIDEWIN) color += vec3(.1,.05,.0);
                    else color *= shadow;

                    vec3 refl = reflect(ray,norm);
                    color += .3*smoothstep(.9,1.,dot(starLight,refl))*norm.z*step(1.,shadow);;
                    color = clamp(color,0.,1.);
                }
            }
        }
        color *= min(1., 20./t);
        color += min(.003*t,.35)*DUST;
    }

    color += flamInfo.rgb*flamInfo.rgb;

    if(starside)
    //if(!shadTrace(pos,starLight))
    color += lensflare3D(ray, getRay(vec2(0.), pos,camTarget));

gl_FragColor = vec4(1.5*color,1.);
}
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #96 on: December 14, 2019, 09:51:10 pm »
Did you checked the latest OR code changes?

Thank you very much for the I'veSeen.fs fix, it looks great!
« Last Edit: December 14, 2019, 09:58:28 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #97 on: December 14, 2019, 09:53:13 pm »
Not yet. I'll do it early in the morning when I'm going to have my usual insomnia. ;)

Are you satisfied with the fixed shader?
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #98 on: December 14, 2019, 09:59:22 pm »
See my previous answer (cross posting)  :)
Patrice
(Always working with the latest Windows version available...)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #99 on: December 14, 2019, 11:03:32 pm »
Sanctuary revisited, altogether with visible light animation  :o
« Last Edit: December 14, 2019, 11:09:17 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #100 on: December 14, 2019, 11:21:58 pm »
Do you mean shader colors are affected by model colors?!  :o
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #101 on: December 15, 2019, 03:13:19 am »
Re. your modes: I added them all. What they really do is remove duplicate calls to shader reset because it is done at new shader parse time anyway.

Your fixes did not however cure listview focus repositioning. What did cure it was, in case WM_NOTIFY of WndProc() somewhere near line 3045, adding a forced redraw of listview control:

........
                    } else {
                        Path_Combine(gP.mt.FullName, EXEresource(), zTxt);
                        if (ZI_UpdateNamedGLTextureFromFileEx(gP.mt.FullName, gP.mt.Texture, gP.mt.Square) == 0) {
                            Mobj_setWallPaper(gP.mt.FullName);
                            WindowRedraw(hCtrl); // MLL: 12-15-2019
                            gP.bRedraw = TRUE; // Redraw the OpenGL scene
                        }
                    }
                }
            }
        } else {
........


And one last thing. Earlier I could D&D my monkey directly into non-default static or animated backgrounds without resetting them to default. Now it is impossible; the background is always changed to static default unless otherwise specified in the model's MTL file. Okay, I can live with that.

But now if you D&D an audio file into an empty viewport, you can't get rid of that audio for good even if you Close all and clear scene. You can only shut it up temporarily with the audio checkbox. So, I've made gl_CloseAll() unconditional on clicking the Close all... menu. Now I can shoot that audio dead together with background animation (if any) when the viewport is still empty: (see ProcessMenu() somewhere near line 2040)

    case MENU_FILE_CLOSE: // MLL 12-20-2018:
        /*if (gP.bObjectLoaded)*/ { // MLL: 12-15-2019
            gl_CloseAll();
            HWND hCtrl = GetDlgItem(gP.hMain, IDC_AUDIO);        // PAT: 12-03-2019
            if (IsWindow(hCtrl)) {
                SendMessage(hCtrl, BM_SETCHECK, BST_UNCHECKED, 0);
                EnableWindow(hCtrl, FALSE);
            }
            hCtrl = GetDlgItem(gP.hMain, IDC_GAUGE_VOLUME);      // PAT: 12-05-2019
            if (IsWindow(hCtrl)) { EnableWindow(hCtrl, FALSE); } // PAT: 12-05-2019
        }
        break;


Now we can consider OR more or less compatible with Win 7. Congrats! :D
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #102 on: December 15, 2019, 09:50:50 am »
The original OR version was using ListBox rather than ListView, that is a much more complex control, and the reason why we have to fight against the slow priority of the WM_PAINT message with WindowRedraw, especially when dealing with the high priority of the OpenGL animations.

Right now, i am looking into glsl_LoadShaderFromFile to let a @local shader work with local textures rather than L"Animated\\
« Last Edit: December 15, 2019, 09:56:03 am by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #103 on: December 15, 2019, 12:33:29 pm »
Patrice,

I think you should rather add one more "sister" function, say, glsl_LoadLocalShaderFromFile(), probably even with somewhat duplicate code, to load @local shaders -- rather than obscure, bloat and slow down the existing glsl_LoadShaderFromFile() function.

In fact, in my source code, the function you're working with is currently called glsl_LoadBkgndShaderFromFile() as opposed to glsl_LoadShaderFromFile() that's reserved exclusively for the blazing fast loading of "system" shaders such as the ones used for post-processing (brightness/contrast, hue/saturation, sepia, vibrance, and vignette ATM).

I'm very proud of speeds we've been able to achieve so far in our indie product, and I think we wouldn't want to slow it down unnecessarily with excessive branching in over-complicated functions. E.g. it takes ShaderToy/my Firefox/WebGL 2.0 4.7 seconds to recompile the I'veSeen shader while it takes ObjReader as little as 0.125 seconds only to reparse all its sampler2d names and recompile it once its name is clicked in the listview. That's almost 40 times faster! ;)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #104 on: December 15, 2019, 02:30:16 pm »
The changes i am doing won't impact the loading speed at all.

Just changing the path to the model folder rather than OR's Animated folder when using
#wallpaper @shader.fs

Added:
Problem solved, now i can do what i want, and load the specific .fs texture from the model folder.
This allows me to provide a new .fs animation altogether with the model, even if it is not already available in the default OR's Animated folder.

Attachments
ObjReader64.7z (a copy of my binary file)
planar.7z (an example of local shader animation using a local texture)

Syncing
in shaders.h, near line 177
            if (p = strstr(samplerMap, "_")) // replace '_' with '.' to get valid map file name
                *p = '.';

            if (wcsstr(fName, L"\\")) { // PAT: 12-15-2019
                Path_Combine(wTmp, gP.wModelPath, cswconv(samplerMap));
            } else {
                Path_Combine(wTmp, EXEresource(), L"Animated\\");
                Add_Str(wTmp, cswconv(samplerMap));
            }


            if (Mobj_createGlTextureFromFileEX(wTmp, X, Y, lpArray, TEX_REPEAT)) {


in Main.cpp, near line 1957

        if (nCount) {
            LVFINDINFO lvfi = { 0 };
            lvfi.flags = LVFI_STRING;
            //lvfi.psz = L"voronoi.fs"; // PAT: 11-25-2019

            if (wcsstr(fName, L"\\") == 0) { // PAT: 12-15-2019
                lvfi.psz = fName;
                long nFound = ListView_FindItem(hList, -1, &lvfi);
                if (nFound < 0)
                    nFound = 0;
                ListView_SelectPlus(hList, nFound);
            }


            SendMessage(hList, WM_SETREDRAW, TRUE, 0);
            RedrawWindow(hList, NULL, NULL, // this combination of flags seems to do the trick
                RDW_INVALIDATE | RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ALLCHILDREN | RDW_UPDATENOW);


« Last Edit: December 15, 2019, 07:36:11 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)