make_blur.ts 6.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. function make_blur_run(kong: node_shader_t) {
  2. // node_shader_write_frag(kong, "var tex_coord_inp: float2 = gbuffer2[uint2(sp.x * constants.gbuffer_size.x, sp.y * constants.gbuffer_size.y)].ba;");
  3. node_shader_write_frag(kong, "var tex_coord_inp4: float4 = gbuffer2[uint2(uint(sp.x * constants.gbuffer_size.x), uint(sp.y * constants.gbuffer_size.y))];");
  4. node_shader_write_frag(kong, "var tex_coord_inp: float2 = tex_coord_inp4.ba;");
  5. node_shader_write_frag(kong, "var basecol: float3 = float3(0.0, 0.0, 0.0);");
  6. node_shader_write_frag(kong, "var roughness: float = 0.0;");
  7. node_shader_write_frag(kong, "var metallic: float = 0.0;");
  8. node_shader_write_frag(kong, "var occlusion: float = 0.0;");
  9. node_shader_write_frag(kong, "var nortan: float3 = float3(0.0, 0.0, 0.0);");
  10. node_shader_write_frag(kong, "var height: float = 0.0;");
  11. node_shader_write_frag(kong, "var mat_opacity: float = 1.0;");
  12. let is_mask: bool = slot_layer_is_mask(context_raw.layer);
  13. if (is_mask) {
  14. node_shader_write_frag(kong, "var opacity: float = 1.0;");
  15. }
  16. else {
  17. node_shader_write_frag(kong, "var opacity: float = 0.0;");
  18. }
  19. if (context_raw.material.paint_emis) {
  20. node_shader_write_frag(kong, "var emis: float = 0.0;");
  21. }
  22. if (context_raw.material.paint_subs) {
  23. node_shader_write_frag(kong, "var subs: float = 0.0;");
  24. }
  25. node_shader_add_constant(kong, "texpaint_size: float2", "_texpaint_size");
  26. node_shader_write_frag(kong, "var blur_step: float = 1.0 / constants.texpaint_size.x;");
  27. if (context_raw.tool == tool_type_t.SMUDGE) {
  28. // node_shader_write_frag(kong, "const blur_weight: float[7] = {1.0 / 28.0, 2.0 / 28.0, 3.0 / 28.0, 4.0 / 28.0, 5.0 / 28.0, 6.0 / 28.0, 7.0 / 28.0};");
  29. node_shader_add_function(kong, str_get_smudge_tool_weight);
  30. node_shader_add_constant(kong, "brush_direction: float3", "_brush_direction");
  31. node_shader_write_frag(kong, "var blur_direction: float2 = constants.brush_direction.yx;");
  32. node_shader_write_frag(kong, "for (var i: int = 0; i < 7; i += 1) {");
  33. // node_shader_write_frag(kong, "var tex_coord_inp2: float2 = gbuffer2[uint2((sp.x + blur_direction.x * blur_step * float(i)) * constants.gbuffer_size.x, (sp.y + blur_direction.y * blur_step * float(i)) * constants.gbuffer_size.y)].ba;");
  34. node_shader_write_frag(kong, "var tex_coord_inp24: float4 = gbuffer2[uint2(uint((sp.x + blur_direction.x * blur_step * float(i)) * constants.gbuffer_size.x), uint((sp.y + blur_direction.y * blur_step * float(i)) * constants.gbuffer_size.y))];");
  35. node_shader_write_frag(kong, "var tex_coord_inp2: float2 = tex_coord_inp24.ba;");
  36. node_shader_write_frag(kong, "var texpaint_sample: float4 = sample(texpaint_undo, sampler_linear, tex_coord_inp2);");
  37. node_shader_write_frag(kong, "var blur_weight_i: float = get_smudge_tool_weight(i);");
  38. node_shader_write_frag(kong, "opacity += texpaint_sample.a * blur_weight_i;");
  39. node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * blur_weight_i;");
  40. node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_undo, sampler_linear, tex_coord_inp2) * blur_weight_i;");
  41. node_shader_write_frag(kong, "roughness += texpaint_pack_sample.g;");
  42. node_shader_write_frag(kong, "metallic += texpaint_pack_sample.b;");
  43. node_shader_write_frag(kong, "occlusion += texpaint_pack_sample.r;");
  44. node_shader_write_frag(kong, "height += texpaint_pack_sample.a;");
  45. node_shader_write_frag(kong, "nortan += sample(texpaint_nor_undo, sampler_linear, tex_coord_inp2).rgb * blur_weight_i;");
  46. node_shader_write_frag(kong, "}");
  47. }
  48. else {
  49. // node_shader_write_frag(kong, "const blur_weight: float[15] = {0.034619 / 2.0, 0.044859 / 2.0, 0.055857 / 2.0, 0.066833 / 2.0, 0.076841 / 2.0, 0.084894 / 2.0, 0.090126 / 2.0, 0.09194 / 2.0, 0.090126 / 2.0, 0.084894 / 2.0, 0.076841 / 2.0, 0.066833 / 2.0, 0.055857 / 2.0, 0.044859 / 2.0, 0.034619 / 2.0};");
  50. node_shader_add_function(kong, str_get_blur_tool_weight);
  51. // X
  52. node_shader_write_frag(kong, "for (var i: int = 0; i <= 14; i += 1) {");
  53. node_shader_write_frag(kong, "var texpaint_sample: float4 = sample(texpaint_undo, sampler_linear, tex_coord_inp + float2(blur_step * float(i - 7), 0.0));");
  54. node_shader_write_frag(kong, "var blur_weight_i: float = get_blur_tool_weight(i);");
  55. node_shader_write_frag(kong, "opacity += texpaint_sample.a * blur_weight_i;");
  56. node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * blur_weight_i;");
  57. node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_undo, sampler_linear, tex_coord_inp + float2(blur_step * float(i - 7), 0.0)) * blur_weight_i;");
  58. node_shader_write_frag(kong, "roughness += texpaint_pack_sample.g;");
  59. node_shader_write_frag(kong, "metallic += texpaint_pack_sample.b;");
  60. node_shader_write_frag(kong, "occlusion += texpaint_pack_sample.r;");
  61. node_shader_write_frag(kong, "height += texpaint_pack_sample.a;");
  62. node_shader_write_frag(kong, "nortan += sample(texpaint_nor_undo, sampler_linear, tex_coord_inp + float2(blur_step * float(i - 7), 0.0)).rgb * blur_weight_i;");
  63. node_shader_write_frag(kong, "}");
  64. // Y
  65. node_shader_write_frag(kong, "for (var j: int = 0; j <= 14; j += 1) {");
  66. node_shader_write_frag(kong, "var texpaint_sample: float4 = sample(texpaint_undo, sampler_linear, tex_coord_inp + float2(0.0, blur_step * float(j - 7)));");
  67. node_shader_write_frag(kong, "var blur_weight_j: float = get_blur_tool_weight(j);");
  68. node_shader_write_frag(kong, "opacity += texpaint_sample.a * blur_weight_j;");
  69. node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * blur_weight_j;");
  70. node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_undo, sampler_linear, tex_coord_inp + float2(0.0, blur_step * float(j - 7))) * blur_weight_j;");
  71. node_shader_write_frag(kong, "roughness += texpaint_pack_sample.g;");
  72. node_shader_write_frag(kong, "metallic += texpaint_pack_sample.b;");
  73. node_shader_write_frag(kong, "occlusion += texpaint_pack_sample.r;");
  74. node_shader_write_frag(kong, "height += texpaint_pack_sample.a;");
  75. node_shader_write_frag(kong, "nortan += sample(texpaint_nor_undo, sampler_linear, tex_coord_inp + float2(0.0, blur_step * float(j - 7))).rgb * blur_weight_j;");
  76. node_shader_write_frag(kong, "}");
  77. }
  78. node_shader_write_frag(kong, "opacity *= constants.brush_opacity;");
  79. }