@@ -4,7 +4,7 @@ require "colors"
44local luv = require " colors_luv"
55local bwrite = require " blobwriter"
66local bread = require " blobreader"
7- local size_mult = 0.5
7+ size_mult = size_mult or 0.5
88local ffi = require (" ffi" )
99--[[
1010 TODO:
@@ -17,6 +17,8 @@ local ffi = require("ffi")
1717 - do real (from chrom. abber.) tonemapping
1818 - maybe 2d map of colors?
1919 - multiplicative blending for "absorption" like thing
20+ - clear to blackbody
21+ - stamp with "multiply" and "pow(absorbtion,depth)"
2022 save hd buffer with tonemapping applied
2123--]]
2224
@@ -25,8 +27,8 @@ win_h=win_h or 0
2527
2628aspect_ratio = aspect_ratio or 1
2729function update_size ()
28- local trg_w = 1440 * size_mult
29- local trg_h = 1440 * size_mult
30+ local trg_w = 1024 * size_mult
31+ local trg_h = 1024 * size_mult
3032 -- this is a workaround because if everytime you save
3133 -- you do __set_window_size it starts sending mouse through windows. SPOOKY
3234 if win_w ~= trg_w or win_h ~= trg_h then
@@ -42,7 +44,7 @@ local size=STATE.size
4244local max_palette_size = 50
4345local need_clear = false
4446local oversample = 1
45- local complex = true
47+ local complex = false
4648local init_zero = false
4749local sample_count = math.pow (2 ,20 )
4850
@@ -138,7 +140,7 @@ config=make_config({
138140 -- {"gen_radius",2,type="float",min=0,max=10},
139141
140142 {" gamma" ,1 ,type = " float" ,min = 0.01 ,max = 5 },
141- -- {"exposure",1,type="float",min=0,max=10},
143+ {" exposure" ,1 ,type = " float" ,min = 0 ,max = 10 },
142144 {" white_point" ,1 ,type = " float" ,min = 0 ,max = 10 },
143145 --[[ other tonemapping
144146
@@ -176,7 +178,7 @@ uniform float white_point;
176178uniform float uchimura_params[6];
177179
178180#define M_PI 3.14159265358979323846264338327950288
179-
181+ #define SHOW_PALETTE 0
180182vec4 mix_palette(float value )
181183{
182184 if (palette_size==0)
@@ -345,8 +347,11 @@ vec3 tonemap(vec3 light)
345347 float x=light.x/sum;
346348 float y=light.y/sum;
347349 float Y=light.y;
348-
349- Y=Y/(9.6*avg_lum);
350+ #if SHOW_PALETTE
351+ Y=Y*exposure/(9.6);
352+ #else
353+ Y=Y*exposure/(9.6*avg_lum);
354+ #endif
350355 //Y=(Y-min_max.x)/(min_max.y-min_max.x);
351356 //Y=(log(Y+1)-log(min_max.x+1))/(log(min_max.y+1)-log(min_max.x+1));
352357 //Y=log(Y+1)/log(min_max.y+1);
@@ -367,12 +372,18 @@ vec3 tonemap(vec3 light)
367372 light.x = light.y*(small_x / small_y);
368373 light.z = light.x / small_x - light.x - light.y;
369374 //light=clamp(light,0,1);
370- return xyz2rgb(light*100);
375+ float s=length(light);
376+ //s=pow(s,1/8);
377+ return mix(xyz2rgb(light*100),vec3(1),smoothstep(0.0,1,s/16));
378+ //return xyz2rgb(light*100);
371379}
372380void main(){
373381 vec2 normed=(pos.xy+vec2(1,1))/2;
374- //vec3 ccol=texture(tex_main,normed).xyz;
382+ #if SHOW_PALETTE
383+ vec3 ccol=mix_palette2(normed.x).xyz;
384+ #else
375385 vec3 ccol=texture(tex_main,normed).xyz;
386+ #endif
376387
377388 /*
378389 if(ccol.x<0)ccol.x=log(1-ccol.x);
@@ -385,6 +396,7 @@ void main(){
385396 ccol=pow(ccol,vec3(v_gamma));
386397 //ccol*=exp(v_gamma);
387398 color = vec4(tonemap(ccol),1);
399+ //color.xyz=pow(color.xyz,vec3(v_gamma));
388400 color.xyz=pow(color.xyz,vec3(2.2));
389401 color.a=1;
390402}
@@ -486,7 +498,7 @@ function draw_visits( )
486498 display_shader :set_i (" tex_main" ,0 )
487499 display_shader :set (" v_gamma" ,config .gamma )
488500
489- -- display_shader:set("exposure",config.exposure)
501+ display_shader :set (" exposure" ,config .exposure )
490502 display_shader :set (" white_point" ,config .white_point )
491503 display_shader :draw_quad ()
492504
@@ -669,7 +681,7 @@ function D65_blackbody(iter, temp)
669681 local b65 = black_body (iter ,6503.5 );
670682 return D65_approx (iter )* (black_body (iter ,temp )/ b65 );
671683end
672- function gaussian ( x , alpha , mu , sigma1 , sigma2 )
684+ function gaussian_value ( x , alpha , mu , sigma1 , sigma2 )
673685 local s = sigma1
674686 if x >= mu then
675687 s = sigma2
@@ -680,19 +692,36 @@ end
680692
681693function xyz_from_normed_waves (v_in )
682694 local ret = {}
683- ret .x = gaussian (v_in , 1.056 , 0.6106 , 0.10528 , 0.0861 )
684- + gaussian (v_in , 0.362 , 0.1722 , 0.04444 , 0.0742 )
685- + gaussian (v_in , - 0.065 , 0.3364 , 0.05667 , 0.0728 );
695+ ret .x = gaussian_value (v_in , 1.056 , 0.6106 , 0.10528 , 0.0861 )
696+ + gaussian_value (v_in , 0.362 , 0.1722 , 0.04444 , 0.0742 )
697+ + gaussian_value (v_in , - 0.065 , 0.3364 , 0.05667 , 0.0728 );
686698
687- ret .y = gaussian (v_in , 0.821 , 0.5244 , 0.1303 , 0.1125 )
688- + gaussian (v_in , 0.286 , 0.4192 , 0.0452 , 0.0864 );
699+ ret .y = gaussian_value (v_in , 0.821 , 0.5244 , 0.1303 , 0.1125 )
700+ + gaussian_value (v_in , 0.286 , 0.4192 , 0.0452 , 0.0864 );
689701
690- ret .z = gaussian (v_in , 1.217 , 0.1583 , 0.0328 , 0.1 )
691- + gaussian (v_in , 0.681 , 0.2194 , 0.0722 , 0.0383 );
702+ ret .z = gaussian_value (v_in , 1.217 , 0.1583 , 0.0328 , 0.1 )
703+ + gaussian_value (v_in , 0.681 , 0.2194 , 0.0722 , 0.0383 );
692704
693705 return ret ;
694706end
695-
707+ function gen_layers ( min ,max ,count )
708+ local ret = {}
709+ for i = 1 ,count do
710+ -- local d=math.random()*(max-min)+min
711+ local d = gaussian ((max - min )/ 2 ,max - min )
712+ table.insert (ret ,d )
713+ end
714+ return ret
715+ end
716+ function phase_difference (layers ,n1 ,n0 ,angle ,wavelen ,layer_count )
717+ layer_count = layer_count or # layers
718+ local ret = 0
719+ for i = 1 ,layer_count do
720+ local d = layers [i ]
721+ ret = ret + d * (n1 / n0 )* math.cos (angle )/ wavelen
722+ end
723+ return ret * math.pi * 4
724+ end
696725palette .generators = {
697726 {" random" ,function (ret , hue_range ,sat_range ,lit_range )
698727 local count = math.random (20 ,50 )
@@ -810,8 +839,8 @@ palette.generators={
810839
811840 table.insert (ret ,new_color (h2 ,s2 ,l2 ,((i )/ max_step )* (max_palette_size - 1 )))
812841 end
813- end },
814- {" fullspectrum" ,function (ret , hue_range ,sat_range ,lit_range )
842+ end
843+ }, {" fullspectrum" ,function (ret , hue_range ,sat_range ,lit_range )
815844 local s = 0.4
816845 local l = 0.33
817846 palette .is_xyz = true
@@ -825,7 +854,32 @@ palette.generators={
825854 w .z = w .z * b
826855 table.insert (ret ,new_color (w .x ,w .y ,w .z ,(i / (max_palette_size - 1 ))* (max_palette_size - 1 )))
827856 end
828- end }
857+ end ,
858+ },{" pearl" ,function (ret , hue_range ,sat_range ,lit_range )
859+ palette .is_xyz = true
860+ local layers = gen_layers (400 ,700 ,1000 )
861+ for i = 0 ,max_palette_size - 1 do
862+ local s = {x = 0 ,y = 0 ,z = 0 }
863+ local h = i / (max_palette_size - 1 )
864+ local angle = h * math.pi / 4
865+ local step_size = 0.01
866+ for nw = 0 ,1 ,step_size do
867+ local w = xyz_from_normed_waves (nw )
868+ local b = D65_blackbody (nw ,6503.5 )-- 6503.5)
869+ -- local b=black_body(h,6503.5)--6503.5)
870+ -- thickness 400->700nm
871+ local wl = mix (380 ,740 ,nw );
872+ -- function phase_difference(layer_thickness_min,layer_thickness_max,count,n1,n0,angle,wavelen)
873+ local eta = phase_difference (layers ,1.53 ,1.0 ,math.pi / 8 ,wl ,math.floor (800 * h )+ 200 )
874+ b = b * (math.cos (eta )+ 1 )* step_size
875+ s .x = s .x + w .x * b
876+ s .y = s .y + w .y * b
877+ s .z = s .z + w .z * b
878+ end
879+ table.insert (ret ,new_color (s .x ,s .y ,s .z ,(i / (max_palette_size - 1 ))* (max_palette_size - 1 )))
880+ end
881+ end
882+ }
829883}
830884function gen_palette ( )
831885 local ret = {}
@@ -1461,18 +1515,22 @@ function rand_function( )
14611515 local s = random_math (rand_complexity )
14621516 -- str_cmplx=random_math_complex(rand_complexity,nil,{"s","p","vec2(cos(global_seed*2*M_PI),sin(global_seed*2*M_PI))","params.xy","params.zw"})--{"vec2(global_seed,0)","vec2(0,1-global_seed)"})
14631517 -- str_cmplx=random_math_complex(rand_complexity,nil,{"s","c_mul(p,vec2(exp(-npl),1-exp(-npl)))","c_mul(params.xy,vec2(cos(global_seed*2*M_PI),sin(global_seed*2*M_PI)))","params.zw"})
1464- -- local tbl_insert={"vec2(cos(length(s)*M_PI*5+move_dist),sin(length(s)*M_PI*5+move_dist))*(0.25+global_seed)","vec2(cos(length(p)*M_PI*4+global_seed),sin(length(p)*M_PI*4+global_seed))*(move_dist)","params.xy","params.zw","vec2(s.x,p.y)","vec2(p.x,s.y)"}
1465- local tbl_insert = {" mix(s,s/length(s),1-global_seed)" ," mix(p,p/length(p),global_seed)" ," params.xy" ," params.zw" }-- "mix(p,p/length(p),global_seed)"
1518+ -- local tbl_insert_cmplx={"vec2(cos(length(s)*M_PI*5+move_dist),sin(length(s)*M_PI*5+move_dist))*(0.25+global_seed)","vec2(cos(length(p)*M_PI*4+global_seed),sin(length(p)*M_PI*4+global_seed))*(move_dist)","params.xy","params.zw","vec2(s.x,p.y)","vec2(p.x,s.y)"}
1519+ local tbl_insert_cmplx = {" s" ," p" ," params.xy" ," params.zw" ," vec2(cos(global_seed*M_PI*2),sin(global_seed*M_PI*2))*move_dist" }-- "mix(p,p/length(p),global_seed)"
1520+ -- local tbl_insert_cmplx={"mix(s,s/length(s),1-global_seed)","mix(p,p/length(p),global_seed)","params.xy","params.zw"}--"mix(p,p/length(p),global_seed)"
1521+
1522+ local tbl_insert_x = {" s.x+cos(global_seed*M_PI*2)" ," p.y+params.x" ," params.x" ," params.y" }
1523+ local tbl_insert_y = {" s.y+sin(global_seed*M_PI*2)" ," p.x+params.y" ," params.z" ," params.w" }
14661524 --[[
14671525 local point_count=3
14681526 for i=1,point_count do
14691527 local v=(i-1)/point_count
14701528 local vr=v*math.pi*2
14711529 local r=0.1
1472- table.insert(tbl_insert ,string.format("vec2(%g,%g)",math.cos(vr)*r,math.sin(vr)*r))
1530+ table.insert(tbl_insert_cmplx ,string.format("vec2(%g,%g)",math.cos(vr)*r,math.sin(vr)*r))
14731531 end
14741532 --]]
1475- -- [==[
1533+ --[==[
14761534 local tex_variants={
14771535 -- [[
14781536 "tex_p.xy","tex_p.yz","tex_p.zx",
@@ -1484,16 +1542,35 @@ function rand_function( )
14841542 "vec2(atan(tex_s.y,tex_s.x),atan(tex_p.y,tex_p.x))/M_PI","vec2(atan(tex_p.y,tex_p.x),atan(tex_s.y,tex_s.x))/M_PI",
14851543 "vec2(atan(tex_s.x,tex_s.z),atan(tex_p.x,tex_p.z))/M_PI","vec2(atan(tex_p.x,tex_p.z),atan(tex_s.x,tex_s.z))/M_PI"
14861544 }
1487- -- [[
1488- local num_tex = 1
1545+
1546+ local num_tex=5
14891547 for i=1,num_tex do
14901548 --table.insert(tbl_insert,"c_mul("..tex_variants[math.random(1,#tex_variants)]..",vec2(cos(global_seed*M_PI*2),sin(global_seed*M_PI*2)))")
1491- table.insert (tbl_insert ,tex_variants [math.random (1 ,# tex_variants )])
1549+ table.insert(tbl_insert_cmplx,tex_variants[math.random(1,#tex_variants)])
1550+ --table.insert(tbl_insert_x,tex_variants[math.random(1,#tex_variants)])
1551+ --table.insert(tbl_insert_y,tex_variants[math.random(1,#tex_variants)])
1552+ end
1553+ --]==]
1554+
1555+ local tex_variants_real = {
1556+ -- [[
1557+ " tex_p.x" ," tex_p.y" ," tex_p.z" ,
1558+ " tex_s.x" ," tex_s.y" ," tex_s.z" ,
1559+
1560+ -- ]]
1561+ " atan(tex_s.y,tex_s.x)/M_PI" ," atan(tex_p.y,tex_p.x)/M_PI" ,
1562+ " atan(tex_s.x,tex_s.z)/M_PI" ," atan(tex_p.x,tex_p.z)/M_PI"
1563+ }
1564+ -- [[
1565+ local num_tex = 2
1566+ for i = 1 ,num_tex do
1567+ table.insert (tbl_insert_x ,tex_variants_real [math.random (1 ,# tex_variants_real )])
1568+ table.insert (tbl_insert_y ,tex_variants_real [math.random (1 ,# tex_variants_real )])
14921569 end
14931570 -- ]]
14941571 -- ]==]
14951572 -- chebyshev_poly_series(10)
1496- str_cmplx = random_math_complex (rand_complexity ,nil ,tbl_insert )
1573+ str_cmplx = random_math_complex (rand_complexity ,nil ,tbl_insert_cmplx )
14971574 -- str_cmplx=random_math_complex(15,"cheb_eval(R)",tbl_insert)
14981575 -- str_cmplx=random_math_complex(15,"c_mul(cheb_eval(c_mul(vec2(cos(global_seed*M_PI*2),sin(global_seed*M_PI*2)),(s-p))),R)",tbl_insert)
14991576 -- str_cmplx=newton_fractal(rand_complexity)
@@ -1574,8 +1651,8 @@ function rand_function( )
15741651 -- str_y="cos("..s.."-s.y*s.x)"
15751652 -- str_x=random_math_centered(3,rand_complexity)
15761653 -- str_y=random_math_centered(3,rand_complexity)
1577- str_x = random_math (rand_complexity ,nil ,{ " s.x+cos(global_seed*M_PI*2)*(p.y+1.0) " , " p.y " , " params.x " , " params.y " } )
1578- str_y = random_math (rand_complexity ,nil ,{ " s.y+sin(global_seed*M_PI*2)*(p.x-1.0) " , " p.x " , " params.z " , " params.w " } )
1654+ str_x = random_math (rand_complexity ,nil ,tbl_insert_x )
1655+ str_y = random_math (rand_complexity ,nil ,tbl_insert_y )
15791656
15801657 --[[
15811658 local str1="p.x"
@@ -1700,16 +1777,16 @@ function rand_function( )
17001777 --str_postamble=str_postamble.."vec2 ds=s-last_s;float ls=length(ds);s=last_s+ds*(move_dist/ls);"
17011778 --str_postamble=str_postamble.."vec2 ds=s-last_s;float ls=length(ds);float vv=1-atan(ls*move_dist)/(M_PI/2);s=last_s+ds*(move_dist*vv/ls);"
17021779 --str_postamble=str_postamble.."vec2 ds=s-last_s;float ls=length(ds);float vv=1-atan(ls*(global_seed*8))/(M_PI/2);s=last_s+ds*((global_seed*7)*vv/ls);"
1703- str_postamble=str_postamble.."vec2 ds=s-last_s;float ls=length(ds);float vv=exp(-1/ dot(s,s));s=last_s+ds*(move_dist*vv/ls);"
1704- -- str_postamble=str_postamble.."vec2 ds=s-last_s;float ls=length(ds);float vv=exp(-1/npl);s=last_s+ds*(move_dist*vv/ls);"
1780+ -- str_postamble=str_postamble.."vec2 ds=s-last_s;float ls=length(ds);float vv=exp(-dot(s,s)/global_seed );s=last_s+ds*(move_dist*vv/ls);"
1781+ str_postamble=str_postamble.."vec2 ds=s-last_s;float ls=length(ds);float vv=exp(-1/npl);s=last_s+ds*(move_dist*vv/ls);"
17051782 --]]
17061783 --[[ move towards circle
17071784 str_postamble=str_postamble.."vec2 tow_c=s+vec2(cos(normed_iter*M_PI*2),sin(normed_iter*M_PI*2))*move_dist;s=(dot(tow_c,s)*tow_c/length(tow_c));"
17081785 --]]
17091786 --[[ boost
17101787 str_preamble=str_preamble.."s*=move_dist;"
17111788 --]]
1712- --[[ boost less with distance
1789+ -- [[ boost less with distance
17131790 str_preamble = str_preamble .. " s*=move_dist*exp(-1/dot(s,s));"
17141791 -- str_preamble=str_preamble.."s*=global_seed*exp(-1/dot(s,s));"
17151792 -- ]]
@@ -1787,7 +1864,7 @@ function rand_function( )
17871864 str_preamble=str_preamble.."vec2 os=s;"
17881865 --str_postamble=str_postamble.."s/=length(s);s=os+s*move_dist*exp(1/-dot(p,p));"
17891866 --str_postamble=str_postamble.."s/=length(s);s=os+s*exp(-dot(p,p)/move_dist);"
1790- str_postamble=str_postamble.."s/=length(s);s=os+s*dot(tex_s,tex_s)/move_dist;"
1867+ str_postamble=str_postamble.."s/=length(s);s=os+s*dot(tex_s,tex_s)/( move_dist*cos(global_seed*M_PI*2)) ;"
17911868 --str_postamble=str_postamble.."s/=length(s);s=os+s*move_dist;"
17921869 --str_postamble=str_postamble.."s/=length(s);s=os+c_mul(s,vec2(params.zw));"
17931870 --str_postamble=str_postamble.."s/=length(s);s=os+c_mul(s,vec2(params.zw)*floor(global_seed*move_dist+1)/move_dist);"
@@ -1808,7 +1885,7 @@ function rand_function( )
18081885 str_preamble=str_preamble.."s=to_polar(s);p=to_polar(p);"
18091886 str_postamble=str_postamble.."s=from_polar(s);p=from_polar(p);"
18101887 --]]
1811- --[[ centered-polar
1888+ -- [[ centered-polar
18121889 str_preamble = str_preamble .. " s=to_polar(s-p);"
18131890 str_postamble = str_postamble .. " s=from_polar(s)+p;"
18141891 -- ]]
@@ -1821,8 +1898,8 @@ function rand_function( )
18211898 --[[ unrotate POST
18221899 --str_postamble=str_postamble.."s=vec2(cos(-params.z)*s.x-sin(-params.z)*s.y,cos(-params.z)*s.y+sin(-params.z)*s.x);"
18231900 --str_postamble=str_postamble.."s=vec2(cos(-0.7853981)*s.x-sin(-0.7853981)*s.y,cos(-0.7853981)*s.y+sin(-0.7853981)*s.x);"
1824- -- str_postamble=str_postamble.."p=vec2(cos(-params.z*M_PI*2)*p.x-sin(-params.z*M_PI*2)*p.y,cos(-params.z*M_PI*2)*p.y+sin(-params.z*M_PI*2)*p.x);"
1825- str_postamble=str_postamble.."s=vec2(cos(-normed_iter*M_PI*2)*s.x-sin(-normed_iter*M_PI*2)*s.y,cos(-normed_iter*M_PI*2)*s.y+sin(-normed_iter*M_PI*2)*s.x);"
1901+ str_postamble=str_postamble.."p=vec2(cos(-params.z*M_PI*2)*p.x-sin(-params.z*M_PI*2)*p.y,cos(-params.z*M_PI*2)*p.y+sin(-params.z*M_PI*2)*p.x);"
1902+ -- str_postamble=str_postamble.."s=vec2(cos(-normed_iter*M_PI*2)*s.x-sin(-normed_iter*M_PI*2)*s.y,cos(-normed_iter*M_PI*2)*s.y+sin(-normed_iter*M_PI*2)*s.x);"
18261903 --]]
18271904 --[[ unoffset POST
18281905 str_postamble=str_postamble.."s-=params.xy;"
@@ -2452,7 +2529,7 @@ vec2 mapping(vec2 p)
24522529 //return p; //normal - do nothing
24532530 //return abs(p)-vec2(1);
24542531 //return mod(p+vec2(1),2)-vec2(1); //modulo, has ugly artifacts when point is HUGE
2455- /*
2532+ /// *
24562533 if(length(p)<50) //modulo, but no artifacts because far away points are far away
24572534 {
24582535 float size=2.005; //0.005 overdraw as it smooths the tiling when using non 1 sized points
@@ -2724,7 +2801,7 @@ void main(){
27242801 else
27252802 c=rgb2xyz(mix_palette(color_value).xyz);
27262803 c*=a*intensity;
2727- c+=vec3(0.01);
2804+ // c+=vec3(0.01);
27282805 //c*=(sin(start_l*M_PI*16)+0.6);
27292806 //c*=(sin(normed_iter*M_PI*8)+0.1);
27302807 //c*=(sin(start_l*M_PI*8)+0.0);
0 commit comments