MakeBlur.hx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package arm.node;
  2. import arm.node.MaterialShader;
  3. class MakeBlur {
  4. public static function run(vert: MaterialShader, frag: MaterialShader) {
  5. #if (kha_opengl || kha_webgl)
  6. frag.write('vec2 texCoordInp = texelFetch(gbuffer2, ivec2(sp.x * gbufferSize.x, (1.0 - sp.y) * gbufferSize.y), 0).ba;');
  7. #else
  8. frag.write('vec2 texCoordInp = texelFetch(gbuffer2, ivec2(sp.x * gbufferSize.x, sp.y * gbufferSize.y), 0).ba;');
  9. #end
  10. frag.write('vec3 basecol = vec3(0.0, 0.0, 0.0);');
  11. frag.write('float roughness = 0.0;');
  12. frag.write('float metallic = 0.0;');
  13. frag.write('float occlusion = 0.0;');
  14. frag.write('vec3 nortan = vec3(0.0, 0.0, 0.0);');
  15. frag.write('float height = 0.0;');
  16. frag.write('float opacity = 1.0 * brushOpacity;');
  17. if (Context.material.paintEmis) {
  18. frag.write('float emis = 0.0;');
  19. }
  20. if (Context.material.paintSubs) {
  21. frag.write('float subs = 0.0;');
  22. }
  23. #if (kha_direct3d11 || kha_direct3d12)
  24. frag.write('const float blur_weight[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};');
  25. #else
  26. frag.write('const float blur_weight[15] = float[](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);');
  27. #end
  28. frag.add_uniform('float texpaintSize', '_texpaintSize');
  29. frag.write('float blur_step = 1.0 / texpaintSize;');
  30. frag.write('for (int i = -7; i <= 7; i++) {');
  31. frag.write('basecol += texture(texpaint_undo, texCoordInp + vec2(blur_step * i, 0.0)).rgb * blur_weight[i + 7];');
  32. frag.write('vec3 texpaint_pack_sample = texture(texpaint_pack_undo, texCoordInp + vec2(blur_step * i, 0.0)).rgb * blur_weight[i + 7];');
  33. frag.write('roughness += texpaint_pack_sample.g;');
  34. frag.write('metallic += texpaint_pack_sample.b;');
  35. frag.write('occlusion += texpaint_pack_sample.r;');
  36. frag.write('nortan += texture(texpaint_nor_undo, texCoordInp + vec2(blur_step * i, 0.0)).rgb * blur_weight[i + 7];');
  37. frag.write('}');
  38. frag.write('for (int i = -7; i <= 7; i++) {');
  39. frag.write('basecol += texture(texpaint_undo, texCoordInp + vec2(0.0, blur_step * i)).rgb * blur_weight[i + 7];');
  40. frag.write('vec3 texpaint_pack_sample = texture(texpaint_pack_undo, texCoordInp + vec2(0.0, blur_step * i)).rgb * blur_weight[i + 7];');
  41. frag.write('roughness += texpaint_pack_sample.g;');
  42. frag.write('metallic += texpaint_pack_sample.b;');
  43. frag.write('occlusion += texpaint_pack_sample.r;');
  44. frag.write('nortan += texture(texpaint_nor_undo, texCoordInp + vec2(0.0, blur_step * i)).rgb * blur_weight[i + 7];');
  45. frag.write('}');
  46. }
  47. }