*/}}

ourshader.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. /*
  2. * Our Paint: A light weight GPU powered painting program.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "ourpaint.h"
  19. const char OUR_SHADER_VERSION_430[]="#version 430\n"
  20. "#define WORKGROUP_SIZE 32\n";
  21. const char OUR_SHADER_VERSION_320ES[]="#version 320 es\n"
  22. "#define OUR_GLES\n#define WORKGROUP_SIZE 16\n";
  23. const char OUR_SHADER_COMMON[]=R"(
  24. #ifdef OUR_GLES
  25. vec4 cunpack(uint d){
  26. return vec4(float(d&0xFFu)/255.,float((d>>8u)&0xFFu)/255.,float((d>>16u)&0xFFu)/255.,float((d>>24u)&0xFFu)/255.);
  27. }
  28. uvec4 cpack(vec4 c){
  29. uint v= uint(uint(c.r*255.) | (uint(c.g*255.)<<8u) | (uint(c.b*255.)<<16u) | (uint(c.a*255.)<<24u));
  30. return uvec4(v,v,v,v);
  31. }
  32. #define OurImageLoad(img, p) \
  33. (cunpack(imageLoad(img,p).x))
  34. #define OurImageStore(img, p, color) \
  35. imageStore(img,p,cpack(color))
  36. #else
  37. #define OurImageLoad(img, p) \
  38. (vec4(imageLoad(img,p))/65535.)
  39. #define OurImageStore(img, p, color) \
  40. imageStore(img,p,uvec4(vec4(color)*65535.))
  41. #endif
  42. )";
  43. const char OUR_CANVAS_SHADER[]=R"(
  44. layout(local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1) in;
  45. #ifdef OUR_GLES
  46. precision highp uimage2D;
  47. precision highp float;
  48. precision highp int;
  49. layout(r32ui, binding = 0) uniform uimage2D img;
  50. layout(r32ui, binding = 1) coherent uniform uimage2D smudge_buckets;
  51. #define OUR_FLT_EPS (1.0/255.0f)
  52. #else
  53. layout(rgba16ui, binding = 0) uniform uimage2D img;
  54. layout(rgba16ui, binding = 1) coherent uniform uimage2D smudge_buckets;
  55. #define OUR_FLT_EPS (1e-4)
  56. #endif
  57. uniform int uCanvasType;
  58. uniform int uCanvasRandom;
  59. uniform float uCanvasFactor;
  60. uniform ivec2 uImageOffset;
  61. uniform ivec2 uBrushCorner;
  62. uniform vec2 uBrushCenter;
  63. uniform float uBrushSize;
  64. uniform float uBrushHardness;
  65. uniform float uBrushSmudge;
  66. uniform float uBrushSlender;
  67. uniform float uBrushAngle;
  68. uniform vec2 uBrushDirection;
  69. uniform float uBrushForce;
  70. uniform float uBrushGunkyness;
  71. uniform float uBrushRecentness;
  72. uniform vec4 uBrushColor;
  73. uniform vec4 uBackgroundColor;
  74. uniform int uBrushErasing;
  75. uniform int uBrushMix;
  76. #ifdef OUR_GLES
  77. uniform int uBrushRoutineSelectionES;
  78. uniform int uMixRoutineSelectionES;
  79. #endif
  80. #ifdef OUR_CANVAS_MODE_PIGMENT
  81. #with OUR_PIGMENT_COMMON
  82. layout(std140) uniform BrushPigmentBlock{
  83. PigmentData p;
  84. }uBrushPigment;
  85. #endif
  86. #with OUR_SHADER_COMMON
  87. const vec4 p1_22=vec4(1.0/2.2,1.0/2.2,1.0/2.2,1.0/2.2);
  88. const vec4 p22=vec4(2.2,2.2,2.2,2.2);
  89. const float WGM_EPSILON=0.001f;
  90. const float T_MATRIX_SMALL[30] = float[30](0.026595621243689,0.049779426257903,0.022449850859496,-0.218453689278271
  91. ,-0.256894883201278,0.445881722194840,0.772365886289756,0.194498761382537
  92. ,0.014038157587820,0.007687264480513
  93. ,-0.032601672674412,-0.061021043498478,-0.052490001018404
  94. ,0.206659098273522,0.572496335158169,0.317837248815438,-0.021216624031211
  95. ,-0.019387668756117,-0.001521339050858,-0.000835181622534
  96. ,0.339475473216284,0.635401374177222,0.771520797089589,0.113222640692379
  97. ,-0.055251113343776,-0.048222578468680,-0.012966666339586
  98. ,-0.001523814504223,-0.000094718948810,-0.000051604594741);
  99. const float spectral_r_small[10] = float[10](0.009281362787953,0.009732627042016,0.011254252737167,0.015105578649573
  100. ,0.024797924177217,0.083622585502406,0.977865045723212,1.000000000000000
  101. ,0.999961046144372,0.999999992756822);
  102. const float spectral_g_small[10] = float[10](0.002854127435775,0.003917589679914,0.012132151699187,0.748259205918013
  103. ,1.000000000000000,0.865695937531795,0.037477469241101,0.022816789725717
  104. ,0.021747419446456,0.021384940572308);
  105. const float spectral_b_small[10] = float[10](0.537052150373386,0.546646402401469,0.575501819073983,0.258778829633924
  106. ,0.041709923751716,0.012662638828324,0.007485593127390,0.006766900622462
  107. ,0.006699764779016,0.006676219883241);
  108. void rgb_to_spectral (vec3 rgb, out float spectral_[10]) {
  109. float offset = 1.0 - WGM_EPSILON;
  110. float r = rgb.r * offset + WGM_EPSILON;
  111. float g = rgb.g * offset + WGM_EPSILON;
  112. float b = rgb.b * offset + WGM_EPSILON;
  113. float spec_r[10] = float[10](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.); for (int i=0; i < 10; i++) {spec_r[i] = spectral_r_small[i] * r;}
  114. float spec_g[10] = float[10](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.); for (int i=0; i < 10; i++) {spec_g[i] = spectral_g_small[i] * g;}
  115. float spec_b[10] = float[10](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.); for (int i=0; i < 10; i++) {spec_b[i] = spectral_b_small[i] * b;}
  116. for (int i=0; i<10; i++) {spectral_[i] = spec_r[i] + spec_g[i] + spec_b[i];}
  117. }
  118. vec3 spectral_to_rgb (float spectral[10]) {
  119. float offset = 1.0 - WGM_EPSILON;
  120. // We need this tmp. array to allow auto vectorization. <-- How about on GPU?
  121. float tmp[3] = float[3](0.,0.,0.);
  122. for (int i=0; i<10; i++) {
  123. tmp[0] += T_MATRIX_SMALL[i] * spectral[i];
  124. tmp[1] += T_MATRIX_SMALL[10+i] * spectral[i];
  125. tmp[2] += T_MATRIX_SMALL[20+i] * spectral[i];
  126. }
  127. vec3 rgb_;
  128. for (int i=0; i<3; i++) {rgb_[i] = clamp((tmp[i] - WGM_EPSILON) / offset, 0.0f, 1.0f);}
  129. return rgb_;
  130. }
  131. vec2 hash( vec2 p ){
  132. p = vec2( dot(p,vec2(127.1,311.7)), dot(p,vec2(269.5,183.3)) );
  133. return -1.0 + 2.0*fract(sin(p)*43758.5453123);
  134. }
  135. float rand(vec2 co){
  136. return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
  137. }
  138. float noise(in vec2 p){ // from iq
  139. const float K1 = 0.366025404; // (sqrt(3)-1)/2;
  140. const float K2 = 0.211324865; // (3-sqrt(3))/6;
  141. vec2 i = floor( p + (p.x+p.y)*K1 );
  142. vec2 a = p - i + (i.x+i.y)*K2;
  143. float m = step(a.y,a.x);
  144. vec2 o = vec2(m,1.0-m);
  145. vec2 b = a - o + K2;
  146. vec2 c = a - 1.0 + 2.0*K2;
  147. vec3 h = max( 0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 );
  148. vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0)));
  149. return dot( n, vec3(70.0) );
  150. }
  151. #define HEIGHT_STRAND(x,y) abs(fract(x)-.5)<.48? \
  152. (.4+.2*sin(3.14*(y+ceil(x))))* \
  153. ((max(abs(sin(3.14*x*2.)+0.2),abs(sin(3.14*x*2.)-0.2))+2.*abs(sin(3.14*x)))/2.+0.5):0.1
  154. #define PATTERN_CANVAS(x,y) \
  155. (max(HEIGHT_STRAND((x),(y)),HEIGHT_STRAND(-(y),(x))))
  156. float HEIGHT_CANVAS(float x,float y){
  157. if(uCanvasType == 1){
  158. return PATTERN_CANVAS(x,y);
  159. }else if(uCanvasType == 2){
  160. vec2 uv=vec2(x,y); float f; uv*=0.1; // from iq
  161. f = 0.2*noise( uv ); uv*=5.;
  162. f += 0.6*noise( uv ); uv*=3.;
  163. f += 0.5*noise( uv );
  164. f = 0.55 + 0.55*f;
  165. return pow(f,0.5);
  166. }
  167. return 1.;
  168. }
  169. float SampleCanvas(vec2 U, vec2 dir,float rfac, float force, float gunky){
  170. if(uCanvasType==0 || abs(gunky)<1.e-2){ return rfac; }
  171. U+=vec2(uImageOffset); U/=20.3; U.x=U.x+rand(U)/10.; U.y=U.y+rand(U)/10.;
  172. mat2 m = mat2(1.6,1.2,-1.2,1.6); vec2 _uv=U; _uv.x+=float(uCanvasRandom%65535)/174.41; _uv.y+=float(uCanvasRandom%65535)/439.87; _uv/=500.;
  173. U.x+=noise(_uv)*2.1; _uv = m*_uv; U.x+=noise(_uv)*0.71;
  174. _uv.y+=365.404;
  175. U.y+=noise(_uv)*1.9; _uv = m*_uv; U.y+=noise(_uv)*0.83;
  176. float d=0.1;
  177. float h=HEIGHT_CANVAS(U.x,U.y);
  178. float hr=HEIGHT_CANVAS(U.x+d,U.y);
  179. float hu=HEIGHT_CANVAS(U.x,U.y+d);
  180. vec3 vx=normalize(vec3(d,0,hr)-vec3(0,0,h)),vy=normalize(vec3(0,d,hu)-vec3(0,0,h)),vz=cross(vx,vy);
  181. float useforce=force*rfac;
  182. float scrape=dot(normalize(vz),vec3(-normalize(dir).xy,0))*mix(0.3,1.,useforce);
  183. float top=h-(1.-pow(useforce,1.5)*2.); float tophard=smoothstep(0.4,0.6,top);
  184. float fac=(gunky>=0.)?mix(mix(1.,top,gunky),tophard,gunky):mix(1.,1.-h,-gunky*0.8);
  185. fac=max(fac,scrape*clamp(gunky,0.,1.));
  186. fac=clamp(fac,0.,1.);
  187. fac*=rfac;
  188. return mix(rfac,fac,uCanvasFactor);
  189. }
  190. #ifndef OUR_GLES
  191. subroutine vec4 MixRoutines(vec4 a, vec4 b, float fac_a);
  192. #endif
  193. #ifndef OUR_GLES
  194. subroutine(MixRoutines)
  195. #endif
  196. vec4 DoMixNormal(vec4 a, vec4 b, float fac_a){
  197. return mix(a,b,1.0f-fac_a);
  198. }
  199. #ifndef OUR_GLES
  200. subroutine(MixRoutines)
  201. #endif
  202. vec4 DoMixSpectral(vec4 a, vec4 b, float fac_a){
  203. vec4 result = vec4(0,0,0,0);
  204. result.a=mix(a.a,b.a,1.0f-fac_a);
  205. float spec_a[10] = float[10](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.); rgb_to_spectral(a.rgb, spec_a);
  206. float spec_b[10] = float[10](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.); rgb_to_spectral(b.rgb, spec_b);
  207. float spectralmix[10] = float[10](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.);
  208. for (int i=0; i < 10; i++) { spectralmix[i] = pow(spec_a[i], fac_a) * pow(spec_b[i], 1.0f-fac_a); }
  209. result.rgb=spectral_to_rgb(spectralmix);
  210. return result;
  211. }
  212. #ifdef OUR_GLES
  213. vec4 uMixRoutineSelection(vec4 a, vec4 b, float fac_a){
  214. if(uMixRoutineSelectionES==0){ return DoMixNormal(a,b,fac_a); }
  215. else{ return DoMixSpectral(a,b,fac_a); }
  216. }
  217. #else
  218. subroutine uniform MixRoutines uMixRoutineSelection;
  219. #endif
  220. vec4 spectral_mix(vec4 a, vec4 b, float fac_a){
  221. return uMixRoutineSelection(a,b,fac_a);
  222. }
  223. vec4 spectral_mix_always(vec4 colora, vec4 colorb, float fac){
  224. #ifndef OUR_STRAIGHT_ALPHA
  225. vec4 ca=(colora.a==0.0f)?colora:vec4(colora.rgb/colora.a,colora.a);
  226. vec4 cb=(colorb.a==0.0f)?colorb:vec4(colorb.rgb/colorb.a,colorb.a);
  227. #else
  228. vec4 ca=colora; vec4 cb=colorb;
  229. #endif
  230. float af=colora.a*(1.0f-fac);
  231. float aa=af/(af+fac*colorb.a+0.000001);
  232. vec4 result=spectral_mix(ca,cb,aa);
  233. result.a=mix(colora.a,colorb.a,fac);
  234. #ifndef OUR_STRAIGHT_ALPHA
  235. result = vec4(result.rgb*result.a,result.a);
  236. #endif
  237. return result;
  238. }
  239. float atan2(in float y, in float x){
  240. bool s = (abs(x) > abs(y)); return mix(3.1415926535/2.0 - atan(x,y), atan(y,x), s);
  241. }
  242. vec2 rotate(vec2 v, float angle) {
  243. float s = sin(angle); float c = cos(angle);
  244. return mat2(c,-s,s,c) * v;
  245. }
  246. float brightness(vec4 color) {
  247. return color.r*0.2126+color.b*0.7152+color.g*0.0722;
  248. }
  249. vec4 mix_over(vec4 colora, vec4 colorb){
  250. #ifndef OUR_STRAIGHT_ALPHA
  251. vec4 a=(colora.a==0.0f)?colora:vec4(colora.rgb/colora.a,colora.a);
  252. vec4 b=(colorb.a==0.0f)?colorb:vec4(colorb.rgb/colorb.a,colorb.a);
  253. #else
  254. vec4 a=colora; vec4 b=colorb;
  255. #endif
  256. vec4 m=vec4(0,0,0,0); float aa=colora.a/(colora.a+(1.0f-colora.a)*colorb.a+OUR_FLT_EPS);
  257. m=spectral_mix(a,b,aa);
  258. m.a=colora.a+colorb.a*(1.0f-colora.a);
  259. #ifndef OUR_STRAIGHT_ALPHA
  260. m=vec4(m.rgb*m.a,m.a);
  261. #endif
  262. return m;
  263. }
  264. int dab(float d, vec2 fpx, vec4 color, float size, float hardness, float smudge, vec4 smudge_color, vec4 last_color, out vec4 final){
  265. vec4 cc=color;
  266. float fac=1.0f-pow(d/size,1.0f+1.0f/(1.0f-hardness+OUR_FLT_EPS));
  267. float canvas=SampleCanvas(fpx,uBrushDirection,fac,uBrushForce,uBrushGunkyness);
  268. cc.a=color.a*canvas*(1.0f-smudge);
  269. #ifndef OUR_STRAIGHT_ALPHA
  270. cc.rgb=cc.rgb*cc.a;
  271. #endif
  272. float erasing=float(uBrushErasing);
  273. cc=cc*(1.0f-erasing);
  274. // this looks better than the one commented out below
  275. vec4 c2=spectral_mix_always(last_color,smudge_color,smudge*fac*color.a*canvas);
  276. c2=mix_over(cc,c2);
  277. //vec4 c2=mix_over(cc,last_color);
  278. //c2=spectral_mix_always(c2,smudge_color,smudge*fac*color.a*canvas);
  279. c2=spectral_mix_always(c2,c2*(1.0f-fac*color.a),erasing*canvas);
  280. final=c2;
  281. return 1;
  282. }
  283. #ifndef saturate
  284. #define saturate(v) clamp(v, 0., 1.)
  285. #endif
  286. const float HCV_EPSILON = 1e-10;
  287. const float HCY_EPSILON = 1e-10;
  288. vec3 hue_to_rgb(float hue){
  289. float R = abs(hue * 6. - 3.) - 1.;
  290. float G = 2. - abs(hue * 6. - 2.);
  291. float B = 2. - abs(hue * 6. - 4.);
  292. return saturate(vec3(R,G,B));
  293. }
  294. vec3 hcy_to_rgb(vec3 hcy){
  295. const vec3 HCYwts = vec3(0.299, 0.587, 0.114);
  296. vec3 RGB = hue_to_rgb(hcy.x);
  297. float Z = dot(RGB, HCYwts);
  298. if (hcy.z < Z) { hcy.y *= hcy.z / Z; }
  299. else if (Z < 1.) { hcy.y *= (1. - hcy.z) / (1. - Z); }
  300. return (RGB - Z) * hcy.y + hcy.z;
  301. }
  302. vec3 rgb_to_hcv(vec3 rgb){
  303. // Based on work by Sam Hocevar and Emil Persson
  304. vec4 P = (rgb.g < rgb.b) ? vec4(rgb.bg, -1.0, 2.0/3.0) : vec4(rgb.gb, 0.0, -1.0/3.0);
  305. vec4 Q = (rgb.r < P.x) ? vec4(P.xyw, rgb.r) : vec4(rgb.r, P.yzx);
  306. float C = Q.x - min(Q.w, Q.y);
  307. float H = abs((Q.w - Q.y) / (6. * C + HCV_EPSILON) + Q.z);
  308. return vec3(H, C, Q.x);
  309. }
  310. vec3 rgb_to_hcy(vec3 rgb){
  311. const vec3 HCYwts = vec3(0.299, 0.587, 0.114);
  312. // Corrected by David Schaeffer
  313. vec3 HCV = rgb_to_hcv(rgb);
  314. float Y = dot(rgb, HCYwts);
  315. float Z = dot(hue_to_rgb(HCV.x), HCYwts);
  316. if (Y < Z) { HCV.y *= Z / (HCY_EPSILON + Y); }
  317. else { HCV.y *= (1. - Z) / (HCY_EPSILON + 1. - Y); }
  318. return vec3(HCV.x, HCV.y, Y);
  319. }
  320. #ifndef OUR_GLES
  321. subroutine void BrushRoutines();
  322. #endif
  323. #ifdef OUR_CANVAS_MODE_RGB
  324. #ifndef OUR_GLES
  325. subroutine(BrushRoutines)
  326. #endif
  327. void DoDabs(){
  328. ivec2 px = ivec2(gl_GlobalInvocationID.xy)+uBrushCorner;
  329. if(px.x<0||px.y<0||px.x>1024||px.y>1024) return;
  330. vec2 fpx=vec2(px),origfpx=fpx;
  331. fpx=uBrushCenter+rotate(fpx-uBrushCenter,uBrushAngle);
  332. fpx.x=uBrushCenter.x+(fpx.x-uBrushCenter.x)*(1.+uBrushSlender);
  333. float dd=distance(fpx,uBrushCenter); if(dd>uBrushSize) return;
  334. vec4 dabc=OurImageLoad(img, px);
  335. vec4 smudgec=pow(spectral_mix_always(pow(OurImageLoad(smudge_buckets,ivec2(1,0)),p1_22),pow(OurImageLoad(smudge_buckets,ivec2(0,0)),p1_22),uBrushRecentness),p22);
  336. vec4 final_color;
  337. dab(dd,origfpx,uBrushColor,uBrushSize,uBrushHardness,uBrushSmudge,smudgec,dabc,final_color);
  338. if(final_color.a>0.){
  339. if(uBrushMix==0){ dabc=final_color; }
  340. else if(uBrushMix==1){ dabc.rgb=final_color.rgb/final_color.a*dabc.a;}
  341. else if(uBrushMix==2){ vec3 xyz=rgb_to_hcy(dabc.rgb); xyz.xy=rgb_to_hcy(final_color.rgb).xy; dabc.rgb=hcy_to_rgb(xyz); }
  342. else if(uBrushMix==3){ dabc.rgb=dabc.rgb+final_color.rgb*0.01;dabc.a=dabc.a*0.99+final_color.a*0.01; }
  343. OurImageStore(img, px, dabc);
  344. }
  345. }
  346. #ifndef OUR_GLES
  347. subroutine(BrushRoutines)
  348. #endif
  349. void DoSample(){
  350. ivec2 p=ivec2(gl_GlobalInvocationID.xy);
  351. int DoSample=1; vec4 color;
  352. if(p.y==0){
  353. vec2 sp=round(vec2(sin(float(p.x)),cos(float(p.x)))*uBrushSize);
  354. ivec2 px=ivec2(sp)+uBrushCorner; if(px.x<0||px.y<0||px.x>=1024||px.y>=1024){ DoSample=0; }
  355. if(DoSample!=0){
  356. ivec2 b=uBrushCorner; if(b.x>=0&&b.y>=0&&b.x<1024&&b.y<1024){ OurImageStore(smudge_buckets,ivec2(128+WORKGROUP_SIZE,0),OurImageLoad(img, b)); }
  357. color=OurImageLoad(img, px);
  358. OurImageStore(smudge_buckets,ivec2(p.x+128,0),color);
  359. }
  360. }else{DoSample=0;}
  361. memoryBarrier();barrier(); if(DoSample==0) return;
  362. if(uBrushErasing==0 || p.x!=0) return;
  363. color=vec4(0.,0.,0.,0.); for(int i=0;i<WORKGROUP_SIZE;i++){ color=color+OurImageLoad(smudge_buckets, ivec2(i+128,0)); }
  364. color=spectral_mix_always(color/vec4(WORKGROUP_SIZE),OurImageLoad(smudge_buckets, ivec2(128+WORKGROUP_SIZE,0)),0.6*(1.0f-uBrushColor.a)); vec4 oldcolor=OurImageLoad(smudge_buckets, ivec2(0,0));
  365. OurImageStore(smudge_buckets,ivec2(1,0),uBrushErasing==2?color:oldcolor);
  366. OurImageStore(smudge_buckets,ivec2(0,0),color);
  367. }
  368. #endif // canvas mode rgb
  369. #ifdef OUR_CANVAS_MODE_PIGMENT //========================================================================================
  370. #define GetImgPixel(tex, uv, p) \
  371. { \
  372. uvec4 c0=imageLoad(tex,uv); \
  373. uvec4 c1=imageLoad(tex,ivec2(uv.x,uv.y+1)); \
  374. uvec4 c2=imageLoad(tex,ivec2(uv.x+1,uv.y)); \
  375. uvec4 c3=imageLoad(tex,ivec2(uv.x+1,uv.y+1)); \
  376. setRL(c0,p); setRH(c1,p); setAL(c2,p); setAH(c3,p); \
  377. }
  378. #define WriteImgPixel(tex, uv, p) \
  379. { \
  380. uvec4 c0=getRL(p); uvec4 c1=getRH(p); uvec4 c2=getAL(p); uvec4 c3=getAH(p); \
  381. imageStore(tex,uv,c0); \
  382. imageStore(tex,ivec2(uv.x,uv.y+1),c1); \
  383. imageStore(tex,ivec2(uv.x+1,uv.y),c2); \
  384. imageStore(tex,ivec2(uv.x+1,uv.y+1),c3); \
  385. }
  386. int dab_pigment(float d, vec2 fpx, PigmentData color, float size, float hardness,
  387. float smudge, PigmentData smudge_color, PigmentData last_color, out PigmentData final){
  388. PigmentData cc=(uBrushErasing!=0)?PIGMENT_BLANK:color;
  389. float erasing=float(uBrushErasing);
  390. float fac=1.0f-safepow(d/size,1.0f+1.0f/(1.0f-hardness+OUR_FLT_EPS));
  391. float canvas=SampleCanvas(fpx,uBrushDirection,fac,uBrushForce,uBrushGunkyness);
  392. if(uBrushErasing!=0){
  393. PigmentData smudged_color=PigmentMix(last_color,smudge_color,smudge*fac*canvas);
  394. final=PigmentMix(smudged_color,PIGMENT_BLANK,erasing*canvas*fac);
  395. }else{
  396. cc.a[15]=color.a[15]*canvas*fac*(1.-smudge);
  397. cc.r[15]=color.r[15]*canvas*fac*(1.-smudge);
  398. PigmentData smudged_color=PigmentMix(last_color,smudge_color,smudge*fac*canvas);
  399. PigmentData added_color=PigmentOver(cc,smudged_color);
  400. final=added_color;
  401. }
  402. return 1;
  403. }
  404. #ifndef OUR_GLES
  405. subroutine(BrushRoutines)
  406. #endif
  407. void DoDabs(){
  408. ivec2 px = ivec2(gl_GlobalInvocationID.xy)*2+uBrushCorner; px/=2; px*=2;
  409. if(px.x<0||px.y<0||px.x>=1024||px.y>=1024) return; vec2 fpx=vec2(px),origfpx=fpx;
  410. fpx=uBrushCenter+rotate(fpx-uBrushCenter,uBrushAngle);
  411. fpx.x=uBrushCenter.x+(fpx.x-uBrushCenter.x)*(1.+uBrushSlender);
  412. float dd=distance(fpx,uBrushCenter); if(dd>uBrushSize) return;
  413. PigmentData dabc; GetImgPixel(img, px, dabc);
  414. PigmentData sm_old; ivec2 oldvec=ivec2(2,0); GetImgPixel(smudge_buckets,oldvec,sm_old);
  415. PigmentData sm_new; ivec2 newvec=ivec2(0,0); GetImgPixel(smudge_buckets,newvec,sm_new);
  416. PigmentData smudgec=PigmentMix(sm_old,sm_new,uBrushRecentness);
  417. PigmentData final_color;
  418. dab_pigment(dd,origfpx,uBrushPigment.p,uBrushSize,uBrushHardness,uBrushSmudge,smudgec,dabc,final_color);
  419. if(final_color.a[15]>0. || final_color.r[15]>0.){
  420. WriteImgPixel(img, px, final_color);
  421. }
  422. }
  423. #ifndef OUR_GLES
  424. subroutine(BrushRoutines)
  425. #endif
  426. void DoSample(){
  427. ivec2 p=ivec2(gl_GlobalInvocationID.xy);
  428. int DoSample=1; ivec2 corner=ivec2(uBrushCenter);
  429. if(p.y==0){
  430. vec2 sp=round(vec2(sin(float(p.x)),cos(float(p.x)))*(uBrushSize+2.));
  431. ivec2 px=ivec2(sp)+corner; px/=2; px*=2; if(px.x<0||px.y<0||px.x>=1024||px.y>=1024){ DoSample=0; }
  432. if(DoSample!=0){
  433. PigmentData dabc; GetImgPixel(img, px, dabc);
  434. WriteImgPixel(smudge_buckets,ivec2(p.x*2+128,0),dabc);
  435. }
  436. }else{DoSample=0;}
  437. memoryBarrier();barrier(); if(DoSample==0) return;
  438. if(uBrushErasing==0 || p.x!=0) return;
  439. PigmentData color=PIGMENT_BLANK; for(int i=0;i<WORKGROUP_SIZE;i++){
  440. PigmentData dabc; GetImgPixel(smudge_buckets, ivec2(i*2+128,0), dabc); color=PigmentMix(color,dabc,1.0/(float(i)+1.));
  441. }
  442. PigmentData oldcolor; GetImgPixel(smudge_buckets, ivec2(0,0), oldcolor);
  443. //PigmentMultiply(color,2./WORKGROUP_SIZE);
  444. WriteImgPixel(smudge_buckets,ivec2(2,0),uBrushErasing==2?color:oldcolor);
  445. WriteImgPixel(smudge_buckets,ivec2(0,0),color);
  446. }
  447. #endif // canvas mode pigment
  448. #ifdef OUR_GLES
  449. void uBrushRoutineSelection(){
  450. if(uBrushRoutineSelectionES==0){ DoDabs(); }
  451. else{ DoSample(); }
  452. }
  453. #else
  454. subroutine uniform BrushRoutines uBrushRoutineSelection;
  455. #endif
  456. void main() {
  457. uBrushRoutineSelection();
  458. }
  459. )";
  460. const char OUR_COMPOSITION_SHADER[] = R"(
  461. layout(local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1) in;
  462. #ifdef OUR_GLES
  463. precision highp uimage2D;
  464. precision highp float;
  465. precision highp int;
  466. layout(r32ui, binding = 0) uniform uimage2D top;
  467. layout(r32ui, binding = 1) uniform uimage2D bottom;
  468. #else
  469. layout(rgba16ui, binding = 0) uniform uimage2D top;
  470. layout(rgba16ui, binding = 1) uniform uimage2D bottom;
  471. #endif
  472. uniform int uBlendMode;
  473. uniform float uAlphaTop;
  474. uniform float uAlphaBottom;
  475. #with OUR_SHADER_COMMON
  476. vec4 mix_over(vec4 colora, vec4 colorb){
  477. colora=colora*uAlphaTop/uAlphaBottom;
  478. vec4 c; c.a=colora.a+colorb.a*(1.0f-colora.a);
  479. c.rgb=(colora.rgb+colorb.rgb*(1.0f-colora.a));
  480. return c;
  481. }
  482. vec4 add_over(vec4 colora, vec4 colorb){
  483. colora=colora*uAlphaTop/uAlphaBottom;
  484. vec4 a=colora+colorb; a.a=clamp(a.a,0.,1.); return a;
  485. }
  486. void main() {
  487. ivec2 px=ivec2(gl_GlobalInvocationID.xy);
  488. vec4 c1=OurImageLoad(top,px); vec4 c2=OurImageLoad(bottom,px);
  489. vec4 c=(uBlendMode==0)?mix_over(c1,c2):add_over(c1,c2);
  490. OurImageStore(bottom,px,c);
  491. OurImageStore(top,px,vec4(1.));
  492. }
  493. )";
  494. const char OUR_PIGMENT_COMMON[]=R"(
  495. #define POW_EPS (1e-9)
  496. #define USE_SAFE_POW 1
  497. #if USE_SAFE_POW
  498. float safepow(float a, float b){
  499. return pow(max(a,POW_EPS),b);
  500. }
  501. #else
  502. #define safepow pow
  503. #endif
  504. #define PREC_FIX (0.5/255.)
  505. #define l8f(a) (float(((a)&0x00ffu)>>0)/255.)
  506. #define h8f(a) (float(((a)&0xff00u)>>8)/255.)
  507. #define lh16f(a) (float(a)/65535.)
  508. #define fl16(l,h) (clamp((uint((l+PREC_FIX)*255.)),0u,255u)|(clamp((uint((h+PREC_FIX)*255.)),0u,255u)<<8))
  509. #define fl16w(a) (uint(a*65535.))
  510. #define OUR_SPECTRAL_SLICES 14
  511. struct PigmentData{ float r[16]; float a[16]; };
  512. const PigmentData PIGMENT_BLANK=
  513. PigmentData(float[16](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.),float[16](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.));
  514. const PigmentData PIGMENT_WHITE=
  515. PigmentData(float[16](1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.),float[16](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.));
  516. const PigmentData PIGMENT_BLACK=
  517. PigmentData(float[16](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,1.),float[16](0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.));
  518. void setRL(uvec4 c, inout PigmentData p){
  519. p.r[0]=l8f(c[0]); p.r[1]=h8f(c[0]); p.r[2]=l8f(c[1]); p.r[3]=h8f(c[1]);
  520. p.r[4]=l8f(c[2]); p.r[5]=h8f(c[2]); p.r[6]=l8f(c[3]); p.r[7]=h8f(c[3]);
  521. }
  522. void setRH(uvec4 c, inout PigmentData p){
  523. p.r[8]= l8f(c[0]); p.r[9] =h8f(c[0]); p.r[10]=l8f(c[1]); p.r[11]=h8f(c[1]);
  524. p.r[12]=l8f(c[2]); p.r[13]=h8f(c[2]); p.r[14]=0.; p.r[15]=lh16f(c[3]); //p.r[14]=l8f(c[3]); p.r[15]=h8f(c[3]);
  525. }
  526. void setAL(uvec4 c, inout PigmentData p){
  527. p.a[0]=l8f(c[0]); p.a[1]=h8f(c[0]); p.a[2]=l8f(c[1]); p.a[3]=h8f(c[1]);
  528. p.a[4]=l8f(c[2]); p.a[5]=h8f(c[2]); p.a[6]=l8f(c[3]); p.a[7]=h8f(c[3]);
  529. }
  530. void setAH(uvec4 c, inout PigmentData p){
  531. p.a[8]= l8f(c[0]); p.a[9] =h8f(c[0]); p.a[10]=l8f(c[1]); p.a[11]=h8f(c[1]);
  532. p.a[12]=l8f(c[2]); p.a[13]=h8f(c[2]); p.a[14]=0.; p.a[15]=lh16f(c[3]); //p.a[14]=l8f(c[3]); p.a[15]=h8f(c[3]);
  533. }
  534. uvec4 getRL(PigmentData p){ uvec4 c;
  535. c[0]=fl16(p.r[0],p.r[1]); c[1]=fl16(p.r[2],p.r[3]);
  536. c[2]=fl16(p.r[4],p.r[5]); c[3]=fl16(p.r[6],p.r[7]); return c;
  537. }
  538. uvec4 getRH(PigmentData p){ uvec4 c;
  539. c[0]=fl16(p.r[8],p.r[9]); c[1]=fl16(p.r[10],p.r[11]);
  540. c[2]=fl16(p.r[12],p.r[13]); c[3]=fl16w(p.r[15]); //c[3]=fl16(p.r[14],p.r[15]);
  541. return c;
  542. }
  543. uvec4 getAL(PigmentData p){ uvec4 c;
  544. c[0]=fl16(p.a[0],p.a[1]); c[1]=fl16(p.a[2],p.a[3]);
  545. c[2]=fl16(p.a[4],p.a[5]); c[3]=fl16(p.a[6],p.a[7]); return c;
  546. }
  547. uvec4 getAH(PigmentData p){ uvec4 c;
  548. c[0]=fl16(p.a[8],p.a[9]); c[1]=fl16(p.a[10],p.a[11]);
  549. c[2]=fl16(p.a[12],p.a[13]); c[3]=fl16w(p.a[15]); //c[3]=fl16(p.a[14],p.a[15]);
  550. return c;
  551. }
  552. const uvec4 DB[4]=uvec4[4](uvec4(0,1,2,3),uvec4(1,0,3,2),uvec4(2,3,0,1),uvec4(3,2,1,0));
  553. PigmentData GetPixelDebayer(highp usampler2D tex, ivec2 uv){
  554. uvec4 c[4];
  555. c[0]=texelFetch(tex,uv,0);
  556. c[1]=texelFetch(tex,ivec2(uv.x,uv.y+1),0);
  557. c[2]=texelFetch(tex,ivec2(uv.x+1,uv.y),0);
  558. c[3]=texelFetch(tex,ivec2(uv.x+1,uv.y+1),0);
  559. int s=uv.x%2*2+uv.y%2;
  560. PigmentData p;
  561. setRL(c[DB[s][0]],p); setRH(c[DB[s][1]],p); setAL(c[DB[s][2]],p); setAH(c[DB[s][3]],p);
  562. return p;
  563. }
  564. PigmentData GetPixel(highp usampler2D tex, ivec2 uv){
  565. uvec4 c0=texelFetch(tex,uv,0);
  566. uvec4 c1=texelFetch(tex,ivec2(uv.x,uv.y+1),0);
  567. uvec4 c2=texelFetch(tex,ivec2(uv.x+1,uv.y),0);
  568. uvec4 c3=texelFetch(tex,ivec2(uv.x+1,uv.y+1),0);
  569. PigmentData p;
  570. setRL(c0,p); setRH(c1,p); setAL(c2,p); setAH(c3,p);
  571. return p;
  572. }
  573. uvec4 PackPixel(PigmentData p, int choose){
  574. switch(choose){
  575. case 0: return getRL(p); case 1: return getRH(p);
  576. case 2: return getAL(p); case 3: return getAH(p);
  577. default: return uvec4(65535,0,65535,65535);
  578. }
  579. }
  580. void PigmentMixSlices(float a[16], inout float b[16], float factor){
  581. if(factor==1.) return; if(factor==0.){ for(int i=0;i<16;i++){b[i]=a[i];} return; }
  582. float fac=(1.0f-factor)*a[15]; float fac1=factor*b[15]; if(fac+fac1==0.){ return; }
  583. float scale=1.0/(fac+fac1); b[15]=mix(a[15],b[15],factor); fac*=scale; fac1*=scale;
  584. for(int i=0;i<OUR_SPECTRAL_SLICES;i++){
  585. b[i]=safepow(a[i],fac)*safepow(b[i],fac1);
  586. }
  587. }
  588. void PigmentMixSlicesInverted(float a[16], inout float b[16], float factor){
  589. if(factor==1.) return; if(factor==0.){ for(int i=0;i<16;i++){b[i]=a[i];} return; }
  590. float fac=(1.0f-factor)*a[15]; float fac1=factor*b[15]; if(fac+fac1==0.){ return; }
  591. float scale=1.0/(fac+fac1); b[15]=mix(a[15],b[15],factor); fac*=scale; fac1*=scale;
  592. for(int i=0;i<OUR_SPECTRAL_SLICES;i++){
  593. b[i]=1.-safepow(1.-a[i],fac)*safepow(1.-b[i],fac1);
  594. }
  595. }
  596. void PigmentOverSlices(float a[16], inout float b[16]){
  597. float fac=a[15]; float fac1=(1.0f-fac)*b[15]; if(fac==0.) return;
  598. float scale=1.0/(fac+fac1); b[15]=fac1+fac; fac*=scale; fac1*=scale;
  599. for(int i=0;i<OUR_SPECTRAL_SLICES;i++){
  600. b[i]=safepow(a[i],fac)*safepow(b[i],fac1);
  601. }
  602. }
  603. void PigmentOverSlicesInverted(float a[16], inout float b[16]){
  604. float fac=a[15]; float fac1=(1.0f-fac)*b[15]; if(fac==0.) return;
  605. float scale=1.0/(fac+fac1); b[15]=fac1+fac; fac*=scale; fac1*=scale;
  606. for(int i=0;i<OUR_SPECTRAL_SLICES;i++){
  607. b[i]=1.-safepow((1.-a[i]),fac)*safepow((1.-b[i]),fac1);
  608. }
  609. }
  610. void PigmentMultiplySlicesInverted(float a[16], inout float b[16], float factor){
  611. float fac=a[15]*factor; float fac1=b[15]; if(fac==0.) return;
  612. b[15]=1.-(1.-fac1)*(1.-fac);
  613. for(int i=0;i<OUR_SPECTRAL_SLICES;i++){
  614. float pre=1.-b[i]*fac1; float mult=pre*(1.-a[i]*fac);
  615. b[i]=(1.-mult)/b[15];
  616. //b[i]=1.-(1.-a[i]*fac)*(1.-b[i]);
  617. }
  618. }
  619. PigmentData PigmentMix(PigmentData p0, PigmentData p1, float factor){
  620. PigmentData result=p1;
  621. PigmentMixSlicesInverted(p0.a,result.a,factor);
  622. PigmentMixSlices(p0.r,result.r,factor);
  623. return result;
  624. }
  625. PigmentData PigmentOver(PigmentData p0, PigmentData p1){
  626. PigmentData result=p1; float mfac=1.0;//p0.r[15];
  627. //for(int i=0;i<15;i++){ result.r[i]=result.r[i]*(1.0-result.a[i]*safepow(result.a[15],2.)); }
  628. float rfac=p0.r[15]; result.a[15]=mix(result.a[15],0.,safepow(rfac,2.));
  629. PigmentOverSlices(p0.r,result.r);
  630. PigmentMultiplySlicesInverted(p0.a,result.a,mfac);
  631. return result;
  632. }
  633. void PigmentAdd(inout PigmentData p, PigmentData on_top){
  634. for(int i=0;i<16;i++){ p.r[i]+=on_top.r[i]; p.a[i]+=on_top.a[i]; }
  635. }
  636. void PigmentMultiply(inout PigmentData p, float a){
  637. for(int i=0;i<15;i++){ p.r[i]*=a; p.a[i]*=a; }
  638. }
  639. PigmentData PigmentInterpolate(PigmentData p0, PigmentData p1, float fac){
  640. PigmentData a; for(int i=0;i<16;i++){ a.r[i]=mix(p0.r[i],p1.r[i],fac); a.a[i]=mix(p0.a[i],p1.a[i],fac); } return a;
  641. }
  642. vec3 XYZ2sRGB(vec3 xyz){
  643. mat3 mat=mat3(vec3(3.2404542,-1.5371385,-0.4985314),
  644. vec3(-0.9692660,1.8760108,0.0415560),
  645. vec3(0.0556434,-0.2040259,1.0572252));
  646. return xyz*mat;
  647. }
  648. float srgb_transfer_function(float a){
  649. return .0031308f >= a ? 12.92f * a : 1.055f * pow(a, .4166666666666667f) - .055f;
  650. }
  651. vec3 to_log_srgb(vec3 color){
  652. return vec3(srgb_transfer_function(color.r),srgb_transfer_function(color.g),srgb_transfer_function(color.b));
  653. }
  654. float PigmentCMF[3][14]=float[3][14](
  655. float[14](0.0343533436363636,0.220925140909091,0.328355822727273,0.2018815,0.0360974655,0.0285879281818182,0.215876535454545,0.525338609090909,0.906198259090909,1.13085586363636,0.895278031818182,0.435115186363636,0.138809882272727,0.0324976972727273),
  656. float[14](0.00359930259090909,0.0236005122727273,0.0565472954545455,0.114833071818182,0.236568031818182,0.535090640909091,0.876579286363636,0.992233536363636,0.923666477272727,0.708120895454545,0.419073681818182,0.178679336363636,0.0541232845454545,0.0124627878181818),
  657. float[14](0.171746535909091,1.15671911363636,1.84186645454545,1.32759531363636,0.488183445454546,0.12631411,0.0225265765,0.00293351760909091,0.000351412640909091,4.70501886363636E-05,3.51041136363636E-06,0.,0.,0.)
  658. );
  659. const float PigmentCMFNormalize=5.13517814086364;
  660. vec3 Spectral2XYZ(float spec[OUR_SPECTRAL_SLICES]){
  661. vec3 xyz=vec3(0.,0.,0.);
  662. for(int i=0;i<OUR_SPECTRAL_SLICES;i++){
  663. xyz[0]+=spec[i]*PigmentCMF[0][i];
  664. xyz[1]+=spec[i]*PigmentCMF[1][i];
  665. xyz[2]+=spec[i]*PigmentCMF[2][i];
  666. }
  667. vec3 XYZ;
  668. XYZ[0]=xyz[0]/PigmentCMFNormalize;
  669. XYZ[1]=xyz[1]/PigmentCMFNormalize;
  670. XYZ[2]=xyz[2]/PigmentCMFNormalize;
  671. return XYZ;
  672. }
  673. vec3 PigmentToRGB(PigmentData pd, PigmentData light){
  674. float slices[OUR_SPECTRAL_SLICES];
  675. for(int i=0;i<OUR_SPECTRAL_SLICES-1;i++){
  676. float absfac=1.0f-pd.a[i]*pow(pd.a[15],1.); if(absfac<0.)absfac=0.; slices[i]=pd.r[i]*absfac;
  677. slices[i]*=light.r[i];
  678. }
  679. vec3 xyz=Spectral2XYZ(slices); vec3 rgb=XYZ2sRGB(xyz); return rgb;
  680. }
  681. )";
  682. const char OUR_PIGMENT_TEXTURE_MIX_SHADER[]=R"(
  683. #extension GL_ARB_shading_language_420pack : enable // uniform sampler binding
  684. precision highp float;
  685. precision highp int;
  686. layout (binding=2) uniform highp usampler2D TexColorUI0;
  687. layout (binding=5) uniform highp usampler2D TexColorUI1;
  688. in vec2 fUV;
  689. layout(location = 0) out uvec4 outColor;
  690. #with OUR_PIGMENT_COMMON
  691. void main(){
  692. ivec2 iuv=ivec2(ivec2(fUV*512.)*2);
  693. ivec2 iuvscr=ivec2(gl_FragCoord.xy); int xof=iuvscr.x%2; int yof=iuvscr.y%2; iuvscr.x-=xof; iuvscr.y-=yof;
  694. PigmentData p0 = GetPixel(TexColorUI0,iuv);
  695. PigmentData p1 = GetPixel(TexColorUI1,iuvscr);
  696. PigmentData result = PigmentOver(p0,p1);
  697. int choose = xof*2+yof;
  698. uvec4 pixel = PackPixel(p0,choose);
  699. outColor=pixel;
  700. }
  701. )";
  702. const char OUR_PIGMENT_TEXTURE_DISPLAY_SHADER[]=R"(
  703. #extension GL_ARB_shading_language_420pack : enable // uniform sampler binding
  704. precision highp float;
  705. precision highp int;
  706. layout (binding=2) uniform highp usampler2D TexColorUI;
  707. uniform uvec2 display_size;
  708. in vec2 fUV;
  709. layout(location = 0) out vec4 outColor;
  710. #with OUR_PIGMENT_COMMON
  711. layout(std140) uniform CanvasPigmentBlock{
  712. PigmentData light;
  713. PigmentData paper;
  714. }uCanvasPigment;
  715. void main(){
  716. ivec2 iuv=ivec2(fUV*vec2(display_size)); //int xof=iuv.x%2; int yof=iuv.y%2; iuv.x-=xof; iuv.y-=yof;
  717. PigmentData p0 = GetPixelDebayer(TexColorUI,iuv);
  718. PigmentData final = PigmentOver(p0,uCanvasPigment.paper);
  719. vec3 pixel = to_log_srgb(PigmentToRGB(final,uCanvasPigment.light));
  720. outColor=vec4(pixel,1.0);
  721. }
  722. )";