make_material.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. let make_material_default_scon: shader_context_t = null;
  2. let make_material_default_mcon: material_context_t = null;
  3. let make_material_height_used: bool = false;
  4. let make_material_emis_used: bool = false;
  5. let make_material_subs_used: bool = false;
  6. function make_material_get_mout(): bool {
  7. for (let i: i32 = 0; i < context_raw.material.canvas.nodes.length; ++i) {
  8. let n: ui_node_t = context_raw.material.canvas.nodes[i];
  9. if (n.type == "OUTPUT_MATERIAL_PBR") {
  10. return true;
  11. }
  12. }
  13. return false;
  14. }
  15. function make_material_parse_mesh_material() {
  16. let m: material_data_t = project_materials[0].data;
  17. for (let i: i32 = 0; i < m._.shader.contexts.length; ++i) {
  18. let c: shader_context_t = m._.shader.contexts[i];
  19. if (c.name == "mesh") {
  20. array_remove(m._.shader.contexts, c);
  21. make_material_delete_context(c);
  22. break;
  23. }
  24. }
  25. if (make_mesh_layer_pass_count > 1) {
  26. let i: i32 = 0;
  27. while (i < m._.shader.contexts.length) {
  28. let c: shader_context_t = m._.shader.contexts[i];
  29. for (let j: i32 = 1; j < make_mesh_layer_pass_count; ++j) {
  30. let name: string = "mesh" + j;
  31. if (c.name == name) {
  32. array_remove(m._.shader.contexts, c);
  33. make_material_delete_context(c);
  34. i--;
  35. break;
  36. }
  37. }
  38. i++;
  39. }
  40. i = 0;
  41. while (i < m.contexts.length) {
  42. let c: material_context_t = m.contexts[i];
  43. for (let j: i32 = 1; j < make_mesh_layer_pass_count; ++j) {
  44. let name: string = "mesh" + j;
  45. if (c.name == name) {
  46. array_remove(m.contexts, c);
  47. i--;
  48. break;
  49. }
  50. }
  51. i++;
  52. }
  53. }
  54. let mm: material_t = {name : "Material", canvas : null};
  55. let con: node_shader_context_t = make_mesh_run(mm);
  56. shader_context_load(con.data);
  57. array_push(m._.shader.contexts, con.data);
  58. for (let i: i32 = 1; i < make_mesh_layer_pass_count; ++i) {
  59. let mm: material_t = {name : "Material", canvas : null};
  60. let con: node_shader_context_t = make_mesh_run(mm, i);
  61. shader_context_load(con.data);
  62. array_push(m._.shader.contexts, con.data);
  63. let mcon: material_context_t = {name : "mesh" + i, bind_textures : []};
  64. material_context_load(mcon);
  65. array_push(m.contexts, mcon);
  66. }
  67. context_raw.ddirty = 2;
  68. render_path_raytrace_dirty = 1;
  69. }
  70. function make_material_parse_mesh_preview_material(md: material_data_t = null) {
  71. if (!make_material_get_mout()) {
  72. return;
  73. }
  74. let m: material_data_t = md == null ? project_materials[0].data : md;
  75. let scon: shader_context_t = null;
  76. for (let i: i32 = 0; i < m._.shader.contexts.length; ++i) {
  77. let c: shader_context_t = m._.shader.contexts[i];
  78. if (c.name == "mesh") {
  79. scon = c;
  80. break;
  81. }
  82. }
  83. array_remove(m._.shader.contexts, scon);
  84. let mcon: material_context_t = {name : "mesh", bind_textures : []};
  85. let sd: material_t = {name : "Material", canvas : null};
  86. let con: node_shader_context_t = make_mesh_preview_run(sd, mcon);
  87. for (let i: i32 = 0; i < m.contexts.length; ++i) {
  88. if (m.contexts[i].name == "mesh") {
  89. material_context_load(mcon);
  90. m.contexts[i] = mcon;
  91. break;
  92. }
  93. }
  94. if (scon != null) {
  95. make_material_delete_context(scon);
  96. }
  97. let compile_error: bool = false;
  98. shader_context_load(con.data);
  99. if (con.data == null) {
  100. compile_error = true;
  101. }
  102. scon = con.data;
  103. if (compile_error) {
  104. return;
  105. }
  106. array_push(m._.shader.contexts, scon);
  107. }
  108. function make_material_parse_paint_material(bake_previews: bool = true) {
  109. if (!make_material_get_mout()) {
  110. return;
  111. }
  112. if (bake_previews) {
  113. let current: gpu_texture_t = _draw_current;
  114. let in_use: bool = gpu_in_use;
  115. if (in_use)
  116. draw_end();
  117. make_material_bake_node_previews();
  118. if (in_use)
  119. draw_begin(current);
  120. }
  121. let m: material_data_t = project_materials[0].data;
  122. for (let i: i32 = 0; i < m._.shader.contexts.length; ++i) {
  123. let c: shader_context_t = m._.shader.contexts[i];
  124. if (c.name == "paint") {
  125. array_remove(m._.shader.contexts, c);
  126. if (c != make_material_default_scon) {
  127. make_material_delete_context(c);
  128. }
  129. break;
  130. }
  131. }
  132. for (let i: i32 = 0; i < m.contexts.length; ++i) {
  133. let c: material_context_t = m.contexts[i];
  134. if (c.name == "paint") {
  135. array_remove(m.contexts, c);
  136. break;
  137. }
  138. }
  139. let sdata: material_t = {name : "Material", canvas : context_raw.material.canvas};
  140. let tmcon: material_context_t = {name : "paint", bind_textures : []};
  141. let con: node_shader_context_t = make_paint_run(sdata, tmcon);
  142. let compile_error: bool = false;
  143. let scon: shader_context_t;
  144. shader_context_load(con.data);
  145. if (con.data == null) {
  146. compile_error = true;
  147. }
  148. scon = con.data;
  149. if (compile_error) {
  150. return;
  151. }
  152. material_context_load(tmcon);
  153. let mcon: material_context_t = tmcon;
  154. array_push(m._.shader.contexts, scon);
  155. array_push(m.contexts, mcon);
  156. if (make_material_default_scon == null) {
  157. make_material_default_scon = scon;
  158. }
  159. if (make_material_default_mcon == null) {
  160. make_material_default_mcon = mcon;
  161. }
  162. }
  163. function make_material_bake_node_previews() {
  164. context_raw.node_previews_used = [];
  165. if (context_raw.node_previews == null) {
  166. context_raw.node_previews = map_create();
  167. }
  168. let empty: ui_node_t[] = [];
  169. make_material_traverse_nodes(context_raw.material.canvas.nodes, null, empty);
  170. let keys: string[] = map_keys(context_raw.node_previews);
  171. for (let i: i32 = 0; i < keys.length; ++i) {
  172. let key: string = keys[i];
  173. if (array_index_of(context_raw.node_previews_used, key) == -1) {
  174. let image: gpu_texture_t = map_get(context_raw.node_previews, key);
  175. gpu_delete_texture(image);
  176. map_delete(context_raw.node_previews, key);
  177. }
  178. }
  179. }
  180. function make_material_traverse_nodes(nodes: ui_node_t[], group: ui_node_canvas_t, parents: ui_node_t[]) {
  181. for (let i: i32 = 0; i < nodes.length; ++i) {
  182. let node: ui_node_t = nodes[i];
  183. make_material_bake_node_preview(node, group, parents);
  184. if (node.type == "GROUP") {
  185. for (let j: i32 = 0; j < project_material_groups.length; ++j) {
  186. let g: node_group_t = project_material_groups[j];
  187. let cname: string = g.canvas.name;
  188. if (cname == node.name) {
  189. array_push(parents, node);
  190. make_material_traverse_nodes(g.canvas.nodes, g.canvas, parents);
  191. array_pop(parents);
  192. break;
  193. }
  194. }
  195. }
  196. }
  197. }
  198. function make_material_bake_node_preview(node: ui_node_t, group: ui_node_canvas_t, parents: ui_node_t[]) {
  199. if (node.type == "BLUR") {
  200. let id: string = parser_material_node_name(node, parents);
  201. let image: gpu_texture_t = map_get(context_raw.node_previews, id);
  202. array_push(context_raw.node_previews_used, id);
  203. let res_x: i32 = math_floor(config_get_texture_res_x() / 4);
  204. let res_y: i32 = math_floor(config_get_texture_res_y() / 4);
  205. if (image == null || image.width != res_x || image.height != res_y) {
  206. if (image != null) {
  207. gpu_delete_texture(image);
  208. }
  209. image = gpu_create_render_target(res_x, res_y);
  210. map_set(context_raw.node_previews, id, image);
  211. }
  212. parser_material_blur_passthrough = true;
  213. util_render_make_node_preview(context_raw.material.canvas, node, image, group, parents);
  214. parser_material_blur_passthrough = false;
  215. }
  216. else if (node.type == "DIRECT_WARP") {
  217. let id: string = parser_material_node_name(node, parents);
  218. let image: gpu_texture_t = map_get(context_raw.node_previews, id);
  219. array_push(context_raw.node_previews_used, id);
  220. let res_x: i32 = math_floor(config_get_texture_res_x());
  221. let res_y: i32 = math_floor(config_get_texture_res_y());
  222. if (image == null || image.width != res_x || image.height != res_y) {
  223. if (image != null) {
  224. gpu_delete_texture(image);
  225. }
  226. image = gpu_create_render_target(res_x, res_y);
  227. map_set(context_raw.node_previews, id, image);
  228. }
  229. parser_material_warp_passthrough = true;
  230. util_render_make_node_preview(context_raw.material.canvas, node, image, group, parents);
  231. parser_material_warp_passthrough = false;
  232. }
  233. else if (node.type == "BAKE_CURVATURE") {
  234. let id: string = parser_material_node_name(node, parents);
  235. let image: gpu_texture_t = map_get(context_raw.node_previews, id);
  236. array_push(context_raw.node_previews_used, id);
  237. let res_x: i32 = math_floor(config_get_texture_res_x());
  238. let res_y: i32 = math_floor(config_get_texture_res_y());
  239. if (image == null || image.width != res_x || image.height != res_y) {
  240. if (image != null) {
  241. gpu_delete_texture(image);
  242. }
  243. image = gpu_create_render_target(res_x, res_y, gpu_texture_format_t.R8);
  244. map_set(context_raw.node_previews, id, image);
  245. }
  246. if (render_path_paint_live_layer == null) {
  247. render_path_paint_live_layer = slot_layer_create("_live");
  248. }
  249. let _tool: tool_type_t = context_raw.tool;
  250. let _bake_type: bake_type_t = context_raw.bake_type;
  251. context_raw.tool = tool_type_t.BAKE;
  252. context_raw.bake_type = bake_type_t.CURVATURE;
  253. parser_material_bake_passthrough = true;
  254. parser_material_start_node = node;
  255. parser_material_start_group = group;
  256. parser_material_start_parents = parents;
  257. make_material_parse_paint_material(false);
  258. parser_material_bake_passthrough = false;
  259. parser_material_start_node = null;
  260. parser_material_start_group = null;
  261. parser_material_start_parents = null;
  262. context_raw.pdirty = 1;
  263. render_path_paint_use_live_layer(true);
  264. render_path_paint_commands_paint(false);
  265. render_path_paint_dilate(true, false);
  266. render_path_paint_use_live_layer(false);
  267. context_raw.pdirty = 0;
  268. context_raw.tool = _tool;
  269. context_raw.bake_type = _bake_type;
  270. make_material_parse_paint_material(false);
  271. let rts: map_t<string, render_target_t> = render_path_render_targets;
  272. let texpaint_live: render_target_t = map_get(rts, "texpaint_live");
  273. draw_begin(image);
  274. draw_image(texpaint_live._image, 0, 0);
  275. draw_end();
  276. }
  277. }
  278. type parse_node_preview_result_t = {
  279. scon: shader_context_t; mcon : material_context_t;
  280. };
  281. function make_material_parse_node_preview_material(node: ui_node_t, group: ui_node_canvas_t = null, parents: ui_node_t[] = null): parse_node_preview_result_t {
  282. if (node.outputs.length == 0) {
  283. return null;
  284. }
  285. let sdata: material_t = {name : "Material", canvas : context_raw.material.canvas};
  286. let mcon_raw: material_context_t = {name : "mesh", bind_textures : []};
  287. let con: node_shader_context_t = make_node_preview_run(sdata, mcon_raw, node, group, parents);
  288. let compile_error: bool = false;
  289. let scon: shader_context_t;
  290. shader_context_load(con.data);
  291. if (con.data == null) {
  292. compile_error = true;
  293. }
  294. scon = con.data;
  295. if (compile_error) {
  296. return null;
  297. }
  298. material_context_load(mcon_raw);
  299. let mcon: material_context_t = mcon_raw;
  300. let result: parse_node_preview_result_t = {scon : scon, mcon : mcon};
  301. return result;
  302. }
  303. function make_material_parse_brush() {
  304. parser_logic_parse(context_raw.brush.canvas);
  305. }
  306. function make_material_blend_mode(kong: node_shader_t, blending: i32, cola: string, colb: string, opac: string): string {
  307. if (blending == blend_type_t.MIX) {
  308. return "lerp3(" + cola + ", " + colb + ", " + opac + ")";
  309. }
  310. else if (blending == blend_type_t.DARKEN) {
  311. return "lerp3(" + cola + ", min3(" + cola + ", " + colb + "), " + opac + ")";
  312. }
  313. else if (blending == blend_type_t.MULTIPLY) {
  314. return "lerp3(" + cola + ", " + cola + " * " + colb + ", " + opac + ")";
  315. }
  316. else if (blending == blend_type_t.BURN) {
  317. return "lerp3(" + cola + ", float3(1.0, 1.0, 1.0) - (float3(1.0, 1.0, 1.0) - " + cola + ") / " + colb + ", " + opac + ")";
  318. }
  319. else if (blending == blend_type_t.LIGHTEN) {
  320. return "max3(" + cola + ", " + colb + " * " + opac + ")";
  321. }
  322. else if (blending == blend_type_t.SCREEN) {
  323. return "(float3(1.0, 1.0, 1.0) - (float3(1.0 - " + opac + ", 1.0 - " + opac + ", 1.0 - " + opac + ") + " + opac + " * (float3(1.0, 1.0, 1.0) - " +
  324. colb + ")) * (float3(1.0, 1.0, 1.0) - " + cola + "))";
  325. }
  326. else if (blending == blend_type_t.DODGE) {
  327. return "lerp3(" + cola + ", " + cola + " / (float3(1.0, 1.0, 1.0) - " + colb + "), " + opac + ")";
  328. }
  329. else if (blending == blend_type_t.ADD) {
  330. return "lerp3(" + cola + ", " + cola + " + " + colb + ", " + opac + ")";
  331. }
  332. else if (blending == blend_type_t.OVERLAY) {
  333. // return "lerp3(" + cola + ", float3( \
  334. // " + cola + ".r < 0.5 ? 2.0 * " + cola + ".r * " + colb + ".r : 1.0 - 2.0 * (1.0 - " + cola + ".r) * (1.0 - " + colb + ".r), \
  335. // " + cola + ".g < 0.5 ? 2.0 * " + cola + ".g * " + colb + ".g : 1.0 - 2.0 * (1.0 - " + cola + ".g) * (1.0 - " + colb + ".g), \
  336. // " + cola + ".b < 0.5 ? 2.0 * " + cola + ".b * " + colb + ".b : 1.0 - 2.0 * (1.0 - " + cola + ".b) * (1.0 - " + colb + ".b) \
  337. // ), " + opac + ")";
  338. let cola_rgb: string = string_replace_all(cola, ".", "_") + "_rgb";
  339. let colb_rgb: string = string_replace_all(colb, ".", "_") + "_rgb";
  340. let res_r: string = string_replace_all(cola, ".", "_") + "_res_r";
  341. let res_g: string = string_replace_all(cola, ".", "_") + "_res_g";
  342. let res_b: string = string_replace_all(cola, ".", "_") + "_res_b";
  343. node_shader_write_frag(kong, "var " + res_r + ": float;");
  344. node_shader_write_frag(kong, "var " + res_g + ": float;");
  345. node_shader_write_frag(kong, "var " + res_b + ": float;");
  346. node_shader_write_frag(kong, "var " + cola_rgb + ": float3 = " + cola + ";"); // cola_rgb = cola.rgb
  347. node_shader_write_frag(kong, "var " + colb_rgb + ": float3 = " + colb + ";");
  348. node_shader_write_frag(kong, "if (" + cola_rgb + ".r < 0.5) { " + res_r + " = 2.0 * " + cola_rgb + ".r * " + colb_rgb + ".r; } else { " + res_r +
  349. " = 1.0 - 2.0 * (1.0 - " + cola_rgb + ".r) * (1.0 - " + colb_rgb + ".r); }");
  350. node_shader_write_frag(kong, "if (" + cola_rgb + ".g < 0.5) { " + res_g + " = 2.0 * " + cola_rgb + ".g * " + colb_rgb + ".g; } else { " + res_g +
  351. " = 1.0 - 2.0 * (1.0 - " + cola_rgb + ".g) * (1.0 - " + colb_rgb + ".g); }");
  352. node_shader_write_frag(kong, "if (" + cola_rgb + ".b < 0.5) { " + res_b + " = 2.0 * " + cola_rgb + ".b * " + colb_rgb + ".b; } else { " + res_b +
  353. " = 1.0 - 2.0 * (1.0 - " + cola_rgb + ".b) * (1.0 - " + colb_rgb + ".b); }");
  354. return "lerp3(" + cola + ", float3(" + res_r + ", " + res_g + ", " + res_b + "), " + opac + ")";
  355. }
  356. else if (blending == blend_type_t.SOFT_LIGHT) {
  357. return "((1.0 - " + opac + ") * " + cola + " + " + opac + " * ((float3(1.0, 1.0, 1.0) - " + cola + ") * " + colb + " * " + cola + " + " + cola +
  358. " * (float3(1.0, 1.0, 1.0) - (float3(1.0, 1.0, 1.0) - " + colb + ") * (float3(1.0, 1.0, 1.0) - " + cola + "))))";
  359. }
  360. else if (blending == blend_type_t.LINEAR_LIGHT) {
  361. return "(" + cola + " + " + opac + " * (float3(2.0, 2.0, 2.0) * (" + colb + " - float3(0.5, 0.5, 0.5))))";
  362. }
  363. else if (blending == blend_type_t.DIFFERENCE) {
  364. return "lerp3(" + cola + ", abs3(" + cola + " - " + colb + "), " + opac + ")";
  365. }
  366. else if (blending == blend_type_t.SUBTRACT) {
  367. return "lerp3(" + cola + ", " + cola + " - " + colb + ", " + opac + ")";
  368. }
  369. else if (blending == blend_type_t.DIVIDE) {
  370. return "float3(1.0 - " + opac + ", 1.0 - " + opac + ", 1.0 - " + opac + ") * " + cola + " + float3(" + opac + ", " + opac + ", " + opac + ") * " +
  371. cola + " / " + colb + "";
  372. }
  373. else if (blending == blend_type_t.HUE) {
  374. node_shader_add_function(kong, str_hue_sat);
  375. return "lerp3(" + cola + ", hsv_to_rgb(float3(rgb_to_hsv(" + colb + ").r, rgb_to_hsv(" + cola + ").g, rgb_to_hsv(" + cola + ").b)), " + opac + ")";
  376. }
  377. else if (blending == blend_type_t.SATURATION) {
  378. node_shader_add_function(kong, str_hue_sat);
  379. return "lerp3(" + cola + ", hsv_to_rgb(float3(rgb_to_hsv(" + cola + ").r, rgb_to_hsv(" + colb + ").g, rgb_to_hsv(" + cola + ").b)), " + opac + ")";
  380. }
  381. else if (blending == blend_type_t.COLOR) {
  382. node_shader_add_function(kong, str_hue_sat);
  383. return "lerp3(" + cola + ", hsv_to_rgb(float3(rgb_to_hsv(" + colb + ").r, rgb_to_hsv(" + colb + ").g, rgb_to_hsv(" + cola + ").b)), " + opac + ")";
  384. }
  385. else { // BlendValue
  386. node_shader_add_function(kong, str_hue_sat);
  387. return "lerp3(" + cola + ", hsv_to_rgb(float3(rgb_to_hsv(" + cola + ").r, rgb_to_hsv(" + cola + ").g, rgb_to_hsv(" + colb + ").b)), " + opac + ")";
  388. }
  389. }
  390. function make_material_blend_mode_mask(kong: node_shader_t, blending: i32, cola: string, colb: string, opac: string): string {
  391. if (blending == blend_type_t.MIX) {
  392. return "lerp(" + cola + ", " + colb + ", " + opac + ")";
  393. }
  394. else if (blending == blend_type_t.DARKEN) {
  395. return "lerp(" + cola + ", min(" + cola + ", " + colb + "), " + opac + ")";
  396. }
  397. else if (blending == blend_type_t.MULTIPLY) {
  398. return "lerp(" + cola + ", " + cola + " * " + colb + ", " + opac + ")";
  399. }
  400. else if (blending == blend_type_t.BURN) {
  401. return "lerp(" + cola + ", 1.0 - (1.0 - " + cola + ") / " + colb + ", " + opac + ")";
  402. }
  403. else if (blending == blend_type_t.LIGHTEN) {
  404. return "max(" + cola + ", " + colb + " * " + opac + ")";
  405. }
  406. else if (blending == blend_type_t.SCREEN) {
  407. return "(1.0 - ((1.0 - " + opac + ") + " + opac + " * (1.0 - " + colb + ")) * (1.0 - " + cola + "))";
  408. }
  409. else if (blending == blend_type_t.DODGE) {
  410. return "lerp(" + cola + ", " + cola + " / (1.0 - " + colb + "), " + opac + ")";
  411. }
  412. else if (blending == blend_type_t.ADD) {
  413. return "lerp(" + cola + ", " + cola + " + " + colb + ", " + opac + ")";
  414. }
  415. else if (blending == blend_type_t.OVERLAY) {
  416. // return "lerp(" + cola + ", " + cola + " < 0.5 ? 2.0 * " + cola + " * " + colb + " : 1.0 - 2.0 * (1.0 - " + cola + ") * (1.0 - " + colb + "), " + opac
  417. // + ")";
  418. let res: string = string_replace_all(cola, ".", "_") + "_res";
  419. node_shader_write_frag(kong, "var " + res + ": float;");
  420. node_shader_write_frag(kong, "if (" + cola + " < 0.5) { " + res + " = 2.0 * " + cola + " * " + colb + "; } else { " + res + " = 1.0 - 2.0 * (1.0 - " +
  421. cola + ") * (1.0 - " + colb + "); }");
  422. return "lerp(" + cola + ", " + res + ", " + opac + ")";
  423. }
  424. else if (blending == blend_type_t.SOFT_LIGHT) {
  425. return "((1.0 - " + opac + ") * " + cola + " + " + opac + " * ((1.0 - " + cola + ") * " + colb + " * " + cola + " + " + cola + " * (1.0 - (1.0 - " +
  426. colb + ") * (1.0 - " + cola + "))))";
  427. }
  428. else if (blending == blend_type_t.LINEAR_LIGHT) {
  429. return "(" + cola + " + " + opac + " * (2.0 * (" + colb + " - 0.5)))";
  430. }
  431. else if (blending == blend_type_t.DIFFERENCE) {
  432. return "lerp(" + cola + ", abs(" + cola + " - " + colb + "), " + opac + ")";
  433. }
  434. else if (blending == blend_type_t.SUBTRACT) {
  435. return "lerp(" + cola + ", " + cola + " - " + colb + ", " + opac + ")";
  436. }
  437. else if (blending == blend_type_t.DIVIDE) {
  438. return "(1.0 - " + opac + ") * " + cola + " + " + opac + " * " + cola + " / " + colb + "";
  439. }
  440. else { // BlendHue, BlendSaturation, BlendColor, BlendValue
  441. return "lerp(" + cola + ", " + colb + ", " + opac + ")";
  442. }
  443. }
  444. function make_material_get_displace_strength(): f32 {
  445. let sc: vec4_t = context_main_object().base.transform.scale;
  446. return config_raw.displace_strength * 0.02 * sc.x;
  447. }
  448. function make_material_delete_context(c: shader_context_t) {
  449. sys_notify_on_next_frame(function(c: shader_context_t) { // Ensure pipeline is no longer in use
  450. shader_context_delete(c);
  451. }, c);
  452. }