diff --git a/CMakeLists.txt b/CMakeLists.txt index 80f3aed78fd1faf4eaa52977e3dbced0c94f4762..03ed52de87ad6c0bb156b77e9547beed9ec664ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,7 +210,7 @@ if (GLCV_FULL_BUILD) ${SAMPLES_DIR}/infinite_zoom.ini "-r${SAMPLES_DIR}/infinite_zoom-noartifact.xml" ${CONFIGS_DIR}/noise.fsh) - render_sample(bad_noise_zoom ${SAMPLES_DIR}/bad_noise_zoom.ini + render_sample(bad_noise_zoom ${SAMPLES_DIR}/bad_noise_zoom.ini "" ${CONFIGS_DIR}/np.fsh) render_sample(tuning_noise_temporal @@ -222,6 +222,106 @@ if (GLCV_FULL_BUILD) "" ${SAMPLES_DIR}/tuning_noise_spatial.fsh) + # Defense samples + render_sample(3advect_nofix + ${SAMPLES_DIR}/3advect.ini + "-DFIXMODE=0;-W256;--render.end=376" + ${SAMPLES_DIR}/3advect.fsh) + + render_sample(3advect_fix + ${SAMPLES_DIR}/3advect.ini + "-DFIXMODE=1;-W256;--render.end=376" + ${SAMPLES_DIR}/3advect.fsh) + + render_sample(wn_raw_00 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=0;-W512;--render.end=600;-Dh=.125" + ${SAMPLES_DIR}/wn_raw.fsh) + + # Normal and contrast corrected, no rnd + render_sample(wn_raw_01 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=0;-W512;--render.end=600;-Dh=.125;-Dai_fun=ai_fun_exp" + ${SAMPLES_DIR}/wn_raw.fsh) + + render_sample(wn_raw_02 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=1;-W512;--render.end=600;-Dh=.125;-Dai_fun=ai_fun_exp;-Dphi=phi_linear" + ${SAMPLES_DIR}/wn_raw.fsh) + + render_sample(wn_raw_03 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=2;-W512;--render.end=600;-Dh=.125;-Dai_fun=ai_fun_exp;-Dphi=phi_linear" + ${SAMPLES_DIR}/wn_raw.fsh) + + render_sample(wn_raw_04 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=3;-W512;--render.end=600;-Dh=.125;-Dai_fun=ai_fun_exp;-Dphi=phi_linear" + ${SAMPLES_DIR}/wn_raw.fsh) + + # Contrast corrected samples with rnd + render_sample(wn_raw_05 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=0;-W512;--render.end=600;-Dh=.125;-Dai_fun=ai_fun_exp;-Dphi=phi_linear;-Dpos_fun=pos_fun_rnd" + ${SAMPLES_DIR}/wn_raw.fsh) + + render_sample(wn_raw_06 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=1;-W512;--render.end=600;-Dh=.125;-Dai_fun=ai_fun_exp;-Dphi=phi_linear;-Dpos_fun=pos_fun_rnd" + ${SAMPLES_DIR}/wn_raw.fsh) + + render_sample(wn_raw_07 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=2;-W512;--render.end=600;-Dh=.125;-Dai_fun=ai_fun_exp;-Dphi=phi_linear;-Dpos_fun=pos_fun_rnd" + ${SAMPLES_DIR}/wn_raw.fsh) + + render_sample(wn_raw_08 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=3;-W512;--render.end=600;-Dh=.125;-Dai_fun=ai_fun_exp;-Dphi=phi_linear;-Dpos_fun=pos_fun_rnd" + ${SAMPLES_DIR}/wn_raw.fsh) + + # Layer counts + render_sample(wn_raw_09 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=0;-W512;--render.end=600;-Dh=.6667;-Dai_fun=ai_fun_exp" + ${SAMPLES_DIR}/wn_raw.fsh) + render_sample(wn_raw_10 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=0;-W512;--render.end=600;-Dh=.500;-Dai_fun=ai_fun_exp" + ${SAMPLES_DIR}/wn_raw.fsh) + render_sample(wn_raw_11 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=0;-W512;--render.end=600;-Dh=.250;-Dai_fun=ai_fun_exp" + ${SAMPLES_DIR}/wn_raw.fsh) + render_sample(wn_raw_12 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=0;-W512;--render.end=600;-Dh=.125;-Dai_fun=ai_fun_exp" + ${SAMPLES_DIR}/wn_raw.fsh) + render_sample(wn_raw_13 + ${SAMPLES_DIR}/wn_raw.ini + "-DNORM_METHOD=0;-W512;--render.end=600;-Dh=.0833;-Dai_fun=ai_fun_exp" + ${SAMPLES_DIR}/wn_raw.fsh) + + render_sample(ccblending_fix_nosprite + ${SAMPLES_DIR}/ccblending.ini + "-DFIXMODE=1;-DDRAWPATCHES=0;--render.end=600" + ${SAMPLES_DIR}/ccblending.fsh) + + render_sample(ccblending_nofix_nosprite + ${SAMPLES_DIR}/ccblending.ini + "-DFIXMODE=0;-DDRAWPATCHES=0;--render.end=600" + ${SAMPLES_DIR}/ccblending.fsh) + + render_sample(ccblending_nofix_sprite + ${SAMPLES_DIR}/ccblending.ini + "-DFIXMODE=0;-DDRAWPATCHES=1;--render.end=600" + ${SAMPLES_DIR}/ccblending.fsh) + + render_sample(ccblending_fix_sprite + ${SAMPLES_DIR}/ccblending.ini + "-DFIXMODE=1;-DDRAWPATCHES=1;--render.end=600" + ${SAMPLES_DIR}/ccblending.fsh) + add_custom_target(samples DEPENDS ${SAMPLE_OUTPUTS}) if (OLD_RENDER_DIRECTORY) set(CMD "([ ! -e ${OLD_RENDER_DIRECTORY} ] && ln -fs ${RENDER_DIRECTORY} ${OLD_RENDER_DIRECTORY}) | true") @@ -439,6 +539,12 @@ if (GLCV_FULL_BUILD) render_still_take_cv(optical_flow wn-exp-lin-08-opt png png ${SAMPLES_DIR}/wn_raw.ini 0 5 "-Dphi=phi_linear;-Dai_fun=ai_fun_exp;-Dpos_fun=pos_fun_lin;-Dh=.2500;-W512;--postprocess=../configs/pp_optical_flow.fsh" ${WN_DEPS}) render_still_take_cv(optical_flow wn-exp-rnd-08-opt png png ${SAMPLES_DIR}/wn_raw.ini 0 5 "-Dphi=phi_linear;-Dai_fun=ai_fun_exp;-Dpos_fun=pos_fun_rnd;-Dh=.2500;-W512;--postprocess=../configs/pp_optical_flow.fsh" ${WN_DEPS}) + render_still(procmarble-step0 png png ${SAMPLES_DIR}/procmarble.ini 1 "-DTEXSTEP=0;-W512" ${SAMPLES_DIR}/procmarble.fsh) + render_still(procmarble-step1 png png ${SAMPLES_DIR}/procmarble.ini 1 "-DTEXSTEP=1;-W512" ${SAMPLES_DIR}/procmarble.fsh) + render_still(procmarble-step2 png png ${SAMPLES_DIR}/procmarble.ini 1 "-DTEXSTEP=2;-W512" ${SAMPLES_DIR}/procmarble.fsh) + render_still(procmarble-step3 png png ${SAMPLES_DIR}/procmarble.ini 1 "-DTEXSTEP=3;-W512" ${SAMPLES_DIR}/procmarble.fsh) + render_still(procmarble-step4 png png ${SAMPLES_DIR}/procmarble.ini 1 "-DTEXSTEP=4;-W512" ${SAMPLES_DIR}/procmarble.fsh) + add_custom_target(stills DEPENDS ${STILLS_OUTPUTS}) if (OLD_RENDER_DIRECTORY) set(CMD "([ ! -e ${OLD_RENDER_DIRECTORY} ] && ln -fs ${RENDER_DIRECTORY} ${OLD_RENDER_DIRECTORY}) | true") diff --git a/samples/3advect.fsh b/samples/3advect.fsh new file mode 100644 index 0000000000000000000000000000000000000000..ebecee8b582208697f2b63c28a14d418b9479295 --- /dev/null +++ b/samples/3advect.fsh @@ -0,0 +1,32 @@ +// cf https://hal.inria.fr/inria-00537472 ( also exist in Lagrangian form ) + +#define rot(a) mat2(cos(a),-sin(a),sin(a),cos(a)) + +void mainImage( out vec4 O, in vec2 U ) +{ + float t = mod(iGlobalTime,6.283); + + vec2 uv = U / iResolution.xy - .5; + + O-=O; + + for (float i=0.; i<3.; i++) { + float ti = t+ 6.283/3.*i, + wi = (.5-.5*cos(ti))/1.5, + v = 3./(.01+length(uv)); + vec2 uvi = uv*rot(.3*(-.5+fract(ti/6.283))*v); + //if (i>0.) break;// else wi=1.; // uncomment to show smearing / trick with 1 layer +#ifndef FIXMODE + if (uv.x < 0.) + O += texture(iChannel0, .5 + uvi ) * wi; + else + O[int(i)] += texture(iChannel1, .5 + uvi ).x * wi; // show each phase in colors +#else +#if FIXMODE==0 + O += texture(iChannel0, .5 + uvi ); break; +#else + O += texture(iChannel0, .5 + uvi ) * wi; +#endif +#endif + } +} \ No newline at end of file diff --git a/samples/3advect.ini b/samples/3advect.ini new file mode 100644 index 0000000000000000000000000000000000000000..07d59d034207b61063373463f8a2e72f9e42e9d9 --- /dev/null +++ b/samples/3advect.ini @@ -0,0 +1,8 @@ +[image] +shader = 3advect.fsh + +[image.0] +type=noise + +[image.1] +type=checker diff --git a/samples/ccblending.fsh b/samples/ccblending.fsh new file mode 100644 index 0000000000000000000000000000000000000000..73e27b374b9eec806574746762075a444e2c1d2e --- /dev/null +++ b/samples/ccblending.fsh @@ -0,0 +1,43 @@ +// NB: trick published in https://hal.inria.fr/inria-00536064v2 + +// try textures random, checker, etc +#define T(U) texture(iChannel0,2.*U)*1.3 // *1.3 only for dark texture +#define mean texture(iChannel0,2.*U,10.)*1.3 +// variants: +// #define mean vec4(65,54,46,1)/255. // mean for Britney video +// #define T(U) vec4(.5+.5*sin(120.*U.x)) // Gabor noise. mean = .5 +// #define T(U) K(U) // simple blob. mean = .5 +// #define mean .5 + +#define K(U) smoothstep(.2, .0, length(U)) // smooth kernel +#define rnd(i) fract(1e4*sin(i+vec2(0,73.17))) // texture + + +void mainImage( out vec4 O, vec2 U ) +{ + O-=O; + vec2 R = iResolution.xy, r=R/R.y; + //if (abs(U.x-R.x/2.)<2.) {O++; return;} + + U /= R.y; + float s=0., s2=0., v; + for (int i=0; i<150; i++) + { + vec2 V = U-rnd(vec2(i))*r + .1*cos(vec2(i)+iDate.w+vec2(0,1.6)); // sprite position + v = K(V); s += v; s2 += v*v; // kernel and momentums + O += v*T(V); + +#if DRAWPATCHES==1 + if (i > 50 && mod(float(i),5.)==0.) + O *= 1.-vec4(abs(K(V)*100.-1.)<.5?1.:0.); +#endif + } + + // normalization +#if FIXMODE==0 + O /= s; // linear blend +#elif FIXMODE==1 + O = mean + (O-s*mean)/sqrt(s2); // variance preserving blend +#endif +} + diff --git a/samples/ccblending.ini b/samples/ccblending.ini new file mode 100644 index 0000000000000000000000000000000000000000..7749ee91da76167eb6e5b3fcc9346f41abc08fae --- /dev/null +++ b/samples/ccblending.ini @@ -0,0 +1,7 @@ +[image] +shader = ccblending.fsh + +[image.0] +type = texture +source = textures/tex13.jpg + diff --git a/samples/procmarble.fsh b/samples/procmarble.fsh index 9fd418fb5bb01bb16bbcb393e6edc2f7f89e84dd..f73a90e7c5dd0799a971d29562ed35f79adf0a98 100644 --- a/samples/procmarble.fsh +++ b/samples/procmarble.fsh @@ -1,11 +1,195 @@ -void mainImage(out vec4 O, in vec2 U) +float scale = 75.; +//------------------------------------------------------------------------ +// Camera +// +// Move the camera. In this case it's using time and the mouse position +// to orbitate the camera around the origin of the world (0,0,0), where +// the yellow sphere is. +//------------------------------------------------------------------------ +void doCamera( out vec3 camPos, out vec3 camTar, in float time, in float mouseX ) +{ + float an = 0.3*iGlobalTime + 10.0*mouseX; + camPos = vec3(3.5*sin(an),1.0,3.5*cos(an)); + camTar = vec3(0.0,0.0,0.0); +} + + +//------------------------------------------------------------------------ +// Background +// +// The background color. In this case it's just a black color. +//------------------------------------------------------------------------ +vec3 doBackground( void ) +{ + return vec3( 0.0, 0.0, 0.0); +} + +//------------------------------------------------------------------------ +// Modelling +// +// Defines the shapes (a sphere in this case) through a distance field, in +// this case it's a sphere of radius 1. +//------------------------------------------------------------------------ +float doModel( vec3 p ) +{ + return length(p) - 1.0; +} + +//------------------------------------------------------------------------ +// Material +// +// Defines the material (colors, shading, pattern, texturing) of the model +// at every point based on its position and normal. In this case, it simply +// returns a constant yellow color. +//------------------------------------------------------------------------ +vec3 doMaterial( in vec3 pos, in vec3 nor ) +{ + return texelFetch(iChannel1, ivec2(511*(1. + sin(floor(scale*(length(pos.xy - .5) + .1*(sin(12.*pos.x))*texture(iChannel0, pos.xy).r))))/2., 0), 0).rgb/4.; +} + +//------------------------------------------------------------------------ +// Lighting +//------------------------------------------------------------------------ +float calcSoftshadow( in vec3 ro, in vec3 rd ); + +vec3 doLighting( in vec3 pos, in vec3 nor, in vec3 rd, in float dis, in vec3 mal ) +{ + vec3 lin = vec3(0.0); + + // key light + //----------------------------- + vec3 lig = normalize(vec3(1.0,0.7,0.9)); + float dif = max(dot(nor,lig),0.0); + float sha = 0.0; if( dif>0.01 ) sha=calcSoftshadow( pos+0.01*nor, lig ); + lin += dif*vec3(4.00,4.00,4.00)*sha; + + // ambient light + //----------------------------- + lin += vec3(0.50,0.50,0.50); + + + // surface-light interacion + //----------------------------- + vec3 col = mal*lin; + + + // fog + //----------------------------- + col *= exp(-0.01*dis*dis); + + return col; +} + +float calcIntersection( in vec3 ro, in vec3 rd ) { - if (iMouse.x/iResolution.x > .5) + const float maxd = 20.0; // max trace distance + const float precis = 0.001; // precission of the intersection + float h = precis*2.0; + float t = 0.0; + float res = -1.0; + for( int i=0; i<90; i++ ) // max number of raymarching iterations is 90 { - O = vec4((1. + sin(floor(100.*(iMouse.y/iResolution.y))*(length(U/iResolution.xy - .5) + .1*texture(iChannel0, U/iResolution.xy).r))))/2.; + if( h<precis||t>maxd ) break; + h = doModel( ro+rd*t ); + t += h; } - else + + if( t<maxd ) res = t; + return res; +} + +vec3 calcNormal( in vec3 pos ) +{ + const float eps = 0.002; // precision of the normal computation + + const vec3 v1 = vec3( 1.0,-1.0,-1.0); + const vec3 v2 = vec3(-1.0,-1.0, 1.0); + const vec3 v3 = vec3(-1.0, 1.0,-1.0); + const vec3 v4 = vec3( 1.0, 1.0, 1.0); + + return normalize( v1*doModel( pos + v1*eps ) + + v2*doModel( pos + v2*eps ) + + v3*doModel( pos + v3*eps ) + + v4*doModel( pos + v4*eps ) ); +} + +float calcSoftshadow( in vec3 ro, in vec3 rd ) +{ + float res = 1.0; + float t = 0.0005; // selfintersection avoidance distance + float h = 1.0; + for( int i=0; i<40; i++ ) // 40 is the max numnber of raymarching steps + { + h = doModel(ro + rd*t); + res = min( res, 64.0*h/t ); // 64 is the hardness of the shadows + t += clamp( h, 0.02, 2.0 ); // limit the max and min stepping distances + } + return clamp(res,0.0,1.0); +} + +mat3 calcLookAtMatrix( in vec3 ro, in vec3 ta, in float roll ) +{ + vec3 ww = normalize( ta - ro ); + vec3 uu = normalize( cross(ww,vec3(sin(roll),cos(roll),0.0) ) ); + vec3 vv = normalize( cross(uu,ww)); + return mat3( uu, vv, ww ); +} + +void mainImage(out vec4 O, in vec2 U) +{ +#if TEXSTEP==0 + O = vec4((1. + sin(floor(scale*(length(U/iResolution.xy - .5))))))/2.; +#elif TEXSTEP==1 + O = vec4((1. + sin(floor(scale*(length(U/iResolution.xy - .5) + .1*texture(iChannel0, U/iResolution.xy).r)))))/2.; +#elif TEXSTEP==2 + O = vec4((1. + sin(floor(scale*(length(U/iResolution.xy - .5) + .1*(sin(12.*U.x/iResolution.x))*texture(iChannel0, U/iResolution.xy).r)))))/2.; +#elif TEXSTEP==3 + O = texelFetch(iChannel1, ivec2(511*(1. + sin(floor(scale*(length(U/iResolution.xy - .5) + .1*(sin(12.*U.x/iResolution.x))*texture(iChannel0, U/iResolution.xy).r))))/2., 0), 0); +#elif TEXSTEP==4 + + vec2 p = (-iResolution.xy + 2.0*U.xy)/iResolution.y; + vec2 m = iMouse.xy/iResolution.xy; + + //----------------------------------------------------- + // camera + //----------------------------------------------------- + + // camera movement + vec3 ro, ta; + doCamera( ro, ta, iGlobalTime, m.x ); + + // camera matrix + mat3 camMat = calcLookAtMatrix( ro, ta, 0.0 ); // 0.0 is the camera roll + + // create view ray + vec3 rd = normalize( camMat * vec3(p.xy,2.0) ); // 2.0 is the lens length + + //----------------------------------------------------- + // render + //----------------------------------------------------- + + vec3 col = doBackground(); + + // raymarch + float t = calcIntersection( ro, rd ); + if( t>-0.5 ) { - O = texelFetch(iChannel1, ivec2(511*(1. + sin(floor(100.*(iMouse.y/iResolution.y))*(length(U/iResolution.xy - .5) + .1*texture(iChannel0, U/iResolution.xy).r)))/2., 0), 0); + // geometry + vec3 pos = ro + t*rd; + vec3 nor = calcNormal(pos); + + // materials + vec3 mal = doMaterial( pos, nor ); + + col = doLighting( pos, nor, rd, t, mal ); } + + //----------------------------------------------------- + // postprocessing + //----------------------------------------------------- + // gamma + col = pow( clamp(col,0.0,1.0), vec3(0.4545) ); + + O = vec4( col, 1.0 ); +#endif }