visual_shader_editor_plugin.cpp 203 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842
  1. /*************************************************************************/
  2. /* visual_shader_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "visual_shader_editor_plugin.h"
  31. #include "core/input/input.h"
  32. #include "core/io/resource_loader.h"
  33. #include "core/math/math_defs.h"
  34. #include "core/os/keyboard.h"
  35. #include "core/project_settings.h"
  36. #include "core/version.h"
  37. #include "editor/editor_log.h"
  38. #include "editor/editor_properties.h"
  39. #include "editor/editor_scale.h"
  40. #include "scene/animation/animation_player.h"
  41. #include "scene/gui/menu_button.h"
  42. #include "scene/gui/panel.h"
  43. #include "scene/main/window.h"
  44. #include "scene/resources/visual_shader_nodes.h"
  45. #include "servers/display_server.h"
  46. #include "servers/rendering/shader_types.h"
  47. Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) {
  48. if (get_script_instance()) {
  49. return get_script_instance()->call("create_editor", p_parent_resource, p_node);
  50. }
  51. return nullptr;
  52. }
  53. void VisualShaderNodePlugin::_bind_methods() {
  54. BIND_VMETHOD(MethodInfo(Variant::OBJECT, "create_editor", PropertyInfo(Variant::OBJECT, "parent_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::OBJECT, "for_node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode")));
  55. }
  56. ///////////////////
  57. static Ref<StyleBoxEmpty> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {
  58. Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty));
  59. style->set_default_margin(MARGIN_LEFT, p_margin_left * EDSCALE);
  60. style->set_default_margin(MARGIN_RIGHT, p_margin_right * EDSCALE);
  61. style->set_default_margin(MARGIN_BOTTOM, p_margin_bottom * EDSCALE);
  62. style->set_default_margin(MARGIN_TOP, p_margin_top * EDSCALE);
  63. return style;
  64. }
  65. ///////////////////
  66. VisualShaderGraphPlugin::VisualShaderGraphPlugin() {
  67. }
  68. void VisualShaderGraphPlugin::_bind_methods() {
  69. ClassDB::bind_method("add_node", &VisualShaderGraphPlugin::add_node);
  70. ClassDB::bind_method("remove_node", &VisualShaderGraphPlugin::remove_node);
  71. ClassDB::bind_method("connect_nodes", &VisualShaderGraphPlugin::connect_nodes);
  72. ClassDB::bind_method("disconnect_nodes", &VisualShaderGraphPlugin::disconnect_nodes);
  73. ClassDB::bind_method("set_node_position", &VisualShaderGraphPlugin::set_node_position);
  74. ClassDB::bind_method("set_node_size", &VisualShaderGraphPlugin::set_node_size);
  75. ClassDB::bind_method("show_port_preview", &VisualShaderGraphPlugin::show_port_preview);
  76. ClassDB::bind_method("update_property_editor", &VisualShaderGraphPlugin::update_property_editor);
  77. ClassDB::bind_method("update_property_editor_deferred", &VisualShaderGraphPlugin::update_property_editor_deferred);
  78. ClassDB::bind_method("set_input_port_default_value", &VisualShaderGraphPlugin::set_input_port_default_value);
  79. }
  80. void VisualShaderGraphPlugin::register_shader(VisualShader *p_shader) {
  81. visual_shader = Ref<VisualShader>(p_shader);
  82. }
  83. void VisualShaderGraphPlugin::set_connections(List<VisualShader::Connection> &p_connections) {
  84. connections = p_connections;
  85. }
  86. void VisualShaderGraphPlugin::show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id) {
  87. if (visual_shader->get_shader_type() == p_type && links.has(p_node_id)) {
  88. for (Map<int, Port>::Element *E = links[p_node_id].output_ports.front(); E; E = E->next()) {
  89. E->value().preview_button->set_pressed(false);
  90. }
  91. if (links[p_node_id].preview_visible && !is_dirty() && links[p_node_id].preview_box != nullptr) {
  92. links[p_node_id].graph_node->remove_child(links[p_node_id].preview_box);
  93. memdelete(links[p_node_id].preview_box);
  94. links[p_node_id].graph_node->set_size(Vector2(-1, -1));
  95. links[p_node_id].preview_visible = false;
  96. }
  97. if (p_port_id != -1) {
  98. if (is_dirty()) {
  99. links[p_node_id].preview_pos = links[p_node_id].graph_node->get_child_count();
  100. }
  101. VBoxContainer *vbox = memnew(VBoxContainer);
  102. links[p_node_id].graph_node->add_child(vbox);
  103. if (links[p_node_id].preview_pos != -1) {
  104. links[p_node_id].graph_node->move_child(vbox, links[p_node_id].preview_pos);
  105. }
  106. Control *offset = memnew(Control);
  107. offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  108. vbox->add_child(offset);
  109. VisualShaderNodePortPreview *port_preview = memnew(VisualShaderNodePortPreview);
  110. port_preview->setup(visual_shader, visual_shader->get_shader_type(), p_node_id, p_port_id);
  111. port_preview->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
  112. vbox->add_child(port_preview);
  113. links[p_node_id].preview_visible = true;
  114. links[p_node_id].preview_box = vbox;
  115. links[p_node_id].output_ports[p_port_id].preview_button->set_pressed(true);
  116. }
  117. }
  118. }
  119. void VisualShaderGraphPlugin::update_property_editor_deferred(VisualShader::Type p_type, int p_node_id) {
  120. call_deferred("update_property_editor", p_type, p_node_id);
  121. }
  122. void VisualShaderGraphPlugin::update_property_editor(VisualShader::Type p_type, int p_node_id) {
  123. if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id)) {
  124. return;
  125. }
  126. Control *custom_editor = links[p_node_id].custom_editor;
  127. if (custom_editor != nullptr) {
  128. links[p_node_id].graph_node->remove_child(custom_editor);
  129. memdelete(custom_editor);
  130. custom_editor = nullptr;
  131. }
  132. links[p_node_id].visual_node->set_meta("id", p_node_id);
  133. links[p_node_id].visual_node->set_meta("shader_type", (int)p_type);
  134. for (int i = 0; i < VisualShaderEditor::get_singleton()->plugins.size(); i++) {
  135. custom_editor = VisualShaderEditor::get_singleton()->plugins.write[i]->create_editor(visual_shader, links[p_node_id].visual_node);
  136. if (custom_editor) {
  137. break;
  138. }
  139. }
  140. links[p_node_id].visual_node->remove_meta("id");
  141. links[p_node_id].visual_node->remove_meta("shader_type");
  142. links[p_node_id].custom_editor = custom_editor;
  143. if (custom_editor) {
  144. links[p_node_id].graph_node->add_child(custom_editor);
  145. links[p_node_id].graph_node->move_child(custom_editor, links[p_node_id].editor_pos);
  146. Ref<VisualShaderNode> vsnode = Ref<VisualShaderNode>(links[p_node_id].visual_node);
  147. Ref<VisualShaderNodeFloatUniform> float_uniform = vsnode;
  148. Ref<VisualShaderNodeIntUniform> int_uniform = vsnode;
  149. Ref<VisualShaderNodeVec3Uniform> vec3_uniform = vsnode;
  150. Ref<VisualShaderNodeColorUniform> color_uniform = vsnode;
  151. Ref<VisualShaderNodeBooleanUniform> bool_uniform = vsnode;
  152. Ref<VisualShaderNodeTransformUniform> transform_uniform = vsnode;
  153. if (float_uniform.is_valid() || int_uniform.is_valid() || vec3_uniform.is_valid() || color_uniform.is_valid() || bool_uniform.is_valid() || transform_uniform.is_valid()) {
  154. custom_editor->call_deferred("_show_prop_names", true);
  155. }
  156. }
  157. links[p_node_id].graph_node->set_size(Vector2(-1, -1));
  158. }
  159. void VisualShaderGraphPlugin::set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, Variant p_value) {
  160. if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id)) {
  161. return;
  162. }
  163. Button *button = links[p_node_id].input_ports[p_port_id].default_input_button;
  164. switch (p_value.get_type()) {
  165. case Variant::COLOR: {
  166. button->set_custom_minimum_size(Size2(30, 0) * EDSCALE);
  167. if (!button->is_connected("draw", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_draw_color_over_button))) {
  168. button->connect("draw", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_draw_color_over_button), varray(button, p_value));
  169. }
  170. } break;
  171. case Variant::BOOL: {
  172. button->set_text(((bool)p_value) ? "true" : "false");
  173. } break;
  174. case Variant::INT:
  175. case Variant::FLOAT: {
  176. button->set_text(String::num(p_value, 4));
  177. } break;
  178. case Variant::VECTOR3: {
  179. Vector3 v = p_value;
  180. button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3) + "," + String::num(v.z, 3));
  181. } break;
  182. default: {
  183. }
  184. }
  185. }
  186. void VisualShaderGraphPlugin::register_default_input_button(int p_node_id, int p_port_id, Button *p_button) {
  187. links[p_node_id].input_ports.insert(p_port_id, { p_button });
  188. }
  189. VisualShader::Type VisualShaderGraphPlugin::get_shader_type() const {
  190. return visual_shader->get_shader_type();
  191. }
  192. void VisualShaderGraphPlugin::set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position) {
  193. if (visual_shader->get_shader_type() == p_type && links.has(p_id)) {
  194. links[p_id].graph_node->set_offset(p_position);
  195. }
  196. }
  197. void VisualShaderGraphPlugin::set_node_size(VisualShader::Type p_type, int p_id, const Vector2 &p_size) {
  198. if (visual_shader->get_shader_type() == p_type && links.has(p_id)) {
  199. links[p_id].graph_node->set_size(p_size);
  200. }
  201. }
  202. bool VisualShaderGraphPlugin::is_preview_visible(int p_id) const {
  203. return links[p_id].preview_visible;
  204. }
  205. void VisualShaderGraphPlugin::clear_links() {
  206. links.clear();
  207. }
  208. bool VisualShaderGraphPlugin::is_dirty() const {
  209. return dirty;
  210. }
  211. void VisualShaderGraphPlugin::make_dirty(bool p_enabled) {
  212. dirty = p_enabled;
  213. }
  214. void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) {
  215. links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, -1 });
  216. }
  217. void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) {
  218. links[p_node_id].output_ports.insert(p_port, { p_button });
  219. }
  220. void VisualShaderGraphPlugin::register_custom_editor(int p_node_id, Control *p_custom_editor) {
  221. links[p_node_id].custom_editor = p_custom_editor;
  222. }
  223. void VisualShaderGraphPlugin::register_editor_pos(int p_node_id, int p_pos) {
  224. links[p_node_id].editor_pos = p_pos;
  225. }
  226. void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
  227. if (p_type != visual_shader->get_shader_type()) {
  228. return;
  229. }
  230. Control *offset;
  231. static Ref<StyleBoxEmpty> label_style = make_empty_stylebox(2, 1, 2, 1);
  232. static const Color type_color[6] = {
  233. Color(0.38, 0.85, 0.96), // scalar (float)
  234. Color(0.49, 0.78, 0.94), // scalar (int)
  235. Color(0.84, 0.49, 0.93), // vector
  236. Color(0.55, 0.65, 0.94), // boolean
  237. Color(0.96, 0.66, 0.43), // transform
  238. Color(1.0, 1.0, 0.0), // sampler
  239. };
  240. Ref<VisualShaderNode> vsnode = visual_shader->get_node(p_type, p_id);
  241. Ref<VisualShaderNodeGroupBase> group_node = Object::cast_to<VisualShaderNodeGroupBase>(vsnode.ptr());
  242. bool is_group = !group_node.is_null();
  243. Size2 size = Size2(0, 0);
  244. Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(group_node.ptr());
  245. bool is_expression = !expression_node.is_null();
  246. String expression = "";
  247. GraphNode *node = memnew(GraphNode);
  248. register_link(p_type, p_id, vsnode.ptr(), node);
  249. if (is_group) {
  250. size = group_node->get_size();
  251. node->set_resizable(true);
  252. node->connect("resize_request", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_node_resized), varray((int)p_type, p_id));
  253. }
  254. if (is_expression) {
  255. expression = expression_node->get_expression();
  256. }
  257. node->set_offset(visual_shader->get_node_position(p_type, p_id));
  258. node->set_title(vsnode->get_caption());
  259. node->set_name(itos(p_id));
  260. if (p_id >= 2) {
  261. node->set_show_close_button(true);
  262. node->connect("close_request", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_delete_request), varray(p_id), CONNECT_DEFERRED);
  263. }
  264. node->connect("dragged", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_node_dragged), varray(p_id));
  265. Control *custom_editor = nullptr;
  266. int port_offset = 0;
  267. if (is_group) {
  268. port_offset += 2;
  269. }
  270. Ref<VisualShaderNodeUniform> uniform = vsnode;
  271. if (uniform.is_valid()) {
  272. VisualShaderEditor::get_singleton()->call_deferred("_update_uniforms");
  273. }
  274. Ref<VisualShaderNodeFloatUniform> float_uniform = vsnode;
  275. Ref<VisualShaderNodeIntUniform> int_uniform = vsnode;
  276. Ref<VisualShaderNodeVec3Uniform> vec3_uniform = vsnode;
  277. Ref<VisualShaderNodeColorUniform> color_uniform = vsnode;
  278. Ref<VisualShaderNodeBooleanUniform> bool_uniform = vsnode;
  279. Ref<VisualShaderNodeTransformUniform> transform_uniform = vsnode;
  280. if (uniform.is_valid()) {
  281. VisualShaderEditor::get_singleton()->graph->add_child(node);
  282. VisualShaderEditor::get_singleton()->_update_created_node(node);
  283. LineEdit *uniform_name = memnew(LineEdit);
  284. uniform_name->set_text(uniform->get_uniform_name());
  285. node->add_child(uniform_name);
  286. uniform_name->connect("text_entered", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_line_edit_changed), varray(uniform_name, p_id));
  287. uniform_name->connect("focus_exited", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_line_edit_focus_out), varray(uniform_name, p_id));
  288. String error = vsnode->get_warning(visual_shader->get_mode(), p_type);
  289. if (error != String()) {
  290. offset = memnew(Control);
  291. offset->set_custom_minimum_size(Size2(0, 4 * EDSCALE));
  292. node->add_child(offset);
  293. Label *error_label = memnew(Label);
  294. error_label->add_theme_color_override("font_color", VisualShaderEditor::get_singleton()->get_theme_color("error_color", "Editor"));
  295. error_label->set_text(error);
  296. node->add_child(error_label);
  297. }
  298. if (vsnode->get_input_port_count() == 0 && vsnode->get_output_port_count() == 1 && vsnode->get_output_port_name(0) == "") {
  299. //shortcut
  300. VisualShaderNode::PortType port_right = vsnode->get_output_port_type(0);
  301. node->set_slot(0, false, VisualShaderNode::PORT_TYPE_SCALAR, Color(), true, port_right, type_color[port_right]);
  302. if (!float_uniform.is_valid() && !int_uniform.is_valid() && !vec3_uniform.is_valid() && !color_uniform.is_valid() && !bool_uniform.is_valid() && !transform_uniform.is_valid()) {
  303. return;
  304. }
  305. }
  306. port_offset++;
  307. }
  308. for (int i = 0; i < VisualShaderEditor::get_singleton()->plugins.size(); i++) {
  309. vsnode->set_meta("id", p_id);
  310. vsnode->set_meta("shader_type", (int)p_type);
  311. custom_editor = VisualShaderEditor::get_singleton()->plugins.write[i]->create_editor(visual_shader, vsnode);
  312. vsnode->remove_meta("id");
  313. vsnode->remove_meta("shader_type");
  314. if (custom_editor) {
  315. break;
  316. }
  317. }
  318. if (custom_editor && !float_uniform.is_valid() && !int_uniform.is_valid() && !vec3_uniform.is_valid() && !bool_uniform.is_valid() && !transform_uniform.is_valid() && vsnode->get_output_port_count() > 0 && vsnode->get_output_port_name(0) == "" && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == "")) {
  319. //will be embedded in first port
  320. } else if (custom_editor) {
  321. register_editor_pos(p_id, port_offset);
  322. port_offset++;
  323. node->add_child(custom_editor);
  324. register_custom_editor(p_id, custom_editor);
  325. if (color_uniform.is_valid()) {
  326. custom_editor->call_deferred("_show_prop_names", true);
  327. }
  328. if (float_uniform.is_valid() || int_uniform.is_valid() || vec3_uniform.is_valid() || bool_uniform.is_valid() || transform_uniform.is_valid()) {
  329. custom_editor->call_deferred("_show_prop_names", true);
  330. return;
  331. }
  332. custom_editor = nullptr;
  333. }
  334. if (is_group) {
  335. offset = memnew(Control);
  336. offset->set_custom_minimum_size(Size2(0, 6 * EDSCALE));
  337. node->add_child(offset);
  338. if (group_node->is_editable()) {
  339. HBoxContainer *hb2 = memnew(HBoxContainer);
  340. Button *add_input_btn = memnew(Button);
  341. add_input_btn->set_text(TTR("Add Input"));
  342. add_input_btn->connect("pressed", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_add_input_port), varray(p_id, group_node->get_free_input_port_id(), VisualShaderNode::PORT_TYPE_VECTOR, "input" + itos(group_node->get_free_input_port_id())), CONNECT_DEFERRED);
  343. hb2->add_child(add_input_btn);
  344. hb2->add_spacer();
  345. Button *add_output_btn = memnew(Button);
  346. add_output_btn->set_text(TTR("Add Output"));
  347. add_output_btn->connect("pressed", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_add_output_port), varray(p_id, group_node->get_free_output_port_id(), VisualShaderNode::PORT_TYPE_VECTOR, "output" + itos(group_node->get_free_output_port_id())), CONNECT_DEFERRED);
  348. hb2->add_child(add_output_btn);
  349. node->add_child(hb2);
  350. }
  351. }
  352. for (int i = 0; i < MAX(vsnode->get_input_port_count(), vsnode->get_output_port_count()); i++) {
  353. if (vsnode->is_port_separator(i)) {
  354. node->add_child(memnew(HSeparator));
  355. port_offset++;
  356. }
  357. bool valid_left = i < vsnode->get_input_port_count();
  358. VisualShaderNode::PortType port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  359. bool port_left_used = false;
  360. String name_left;
  361. if (valid_left) {
  362. name_left = vsnode->get_input_port_name(i);
  363. port_left = vsnode->get_input_port_type(i);
  364. for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) {
  365. if (E->get().to_node == p_id && E->get().to_port == i) {
  366. port_left_used = true;
  367. }
  368. }
  369. }
  370. bool valid_right = i < vsnode->get_output_port_count();
  371. VisualShaderNode::PortType port_right = VisualShaderNode::PORT_TYPE_SCALAR;
  372. String name_right;
  373. if (valid_right) {
  374. name_right = vsnode->get_output_port_name(i);
  375. port_right = vsnode->get_output_port_type(i);
  376. }
  377. HBoxContainer *hb = memnew(HBoxContainer);
  378. hb->add_theme_constant_override("separation", 7 * EDSCALE);
  379. Variant default_value;
  380. if (valid_left && !port_left_used) {
  381. default_value = vsnode->get_input_port_default_value(i);
  382. }
  383. if (default_value.get_type() != Variant::NIL) { // only a label
  384. Button *button = memnew(Button);
  385. hb->add_child(button);
  386. button->connect("pressed", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_edit_port_default_input), varray(button, p_id, i));
  387. register_default_input_button(p_id, i, button);
  388. set_input_port_default_value(p_type, p_id, i, default_value);
  389. }
  390. if (i == 0 && custom_editor) {
  391. hb->add_child(custom_editor);
  392. custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  393. } else {
  394. if (valid_left) {
  395. if (is_group) {
  396. OptionButton *type_box = memnew(OptionButton);
  397. hb->add_child(type_box);
  398. type_box->add_item(TTR("Float"));
  399. type_box->add_item(TTR("Int"));
  400. type_box->add_item(TTR("Vector"));
  401. type_box->add_item(TTR("Boolean"));
  402. type_box->add_item(TTR("Transform"));
  403. type_box->add_item(TTR("Sampler"));
  404. type_box->select(group_node->get_input_port_type(i));
  405. type_box->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  406. type_box->connect("item_selected", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_change_input_port_type), varray(p_id, i), CONNECT_DEFERRED);
  407. LineEdit *name_box = memnew(LineEdit);
  408. hb->add_child(name_box);
  409. name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0));
  410. name_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  411. name_box->set_text(name_left);
  412. name_box->connect("text_entered", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_change_input_port_name), varray(name_box, p_id, i));
  413. name_box->connect("focus_exited", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_port_name_focus_out), varray(name_box, p_id, i, false));
  414. Button *remove_btn = memnew(Button);
  415. remove_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Remove", "EditorIcons"));
  416. remove_btn->set_tooltip(TTR("Remove") + " " + name_left);
  417. remove_btn->connect("pressed", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_remove_input_port), varray(p_id, i), CONNECT_DEFERRED);
  418. hb->add_child(remove_btn);
  419. } else {
  420. Label *label = memnew(Label);
  421. label->set_text(name_left);
  422. label->add_theme_style_override("normal", label_style); //more compact
  423. hb->add_child(label);
  424. if (vsnode->get_input_port_default_hint(i) != "" && !port_left_used) {
  425. Label *hint_label = memnew(Label);
  426. hint_label->set_text("[" + vsnode->get_input_port_default_hint(i) + "]");
  427. hint_label->add_theme_color_override("font_color", VisualShaderEditor::get_singleton()->get_theme_color("font_color_readonly", "TextEdit"));
  428. hint_label->add_theme_style_override("normal", label_style);
  429. hb->add_child(hint_label);
  430. }
  431. }
  432. }
  433. if (!is_group) {
  434. hb->add_spacer();
  435. }
  436. if (valid_right) {
  437. if (is_group) {
  438. Button *remove_btn = memnew(Button);
  439. remove_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Remove", "EditorIcons"));
  440. remove_btn->set_tooltip(TTR("Remove") + " " + name_left);
  441. remove_btn->connect("pressed", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_remove_output_port), varray(p_id, i), CONNECT_DEFERRED);
  442. hb->add_child(remove_btn);
  443. LineEdit *name_box = memnew(LineEdit);
  444. hb->add_child(name_box);
  445. name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0));
  446. name_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  447. name_box->set_text(name_right);
  448. name_box->connect("text_entered", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_change_output_port_name), varray(name_box, p_id, i));
  449. name_box->connect("focus_exited", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_port_name_focus_out), varray(name_box, p_id, i, true));
  450. OptionButton *type_box = memnew(OptionButton);
  451. hb->add_child(type_box);
  452. type_box->add_item(TTR("Float"));
  453. type_box->add_item(TTR("Int"));
  454. type_box->add_item(TTR("Vector"));
  455. type_box->add_item(TTR("Boolean"));
  456. type_box->add_item(TTR("Transform"));
  457. type_box->select(group_node->get_output_port_type(i));
  458. type_box->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  459. type_box->connect("item_selected", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_change_output_port_type), varray(p_id, i), CONNECT_DEFERRED);
  460. } else {
  461. Label *label = memnew(Label);
  462. label->set_text(name_right);
  463. label->add_theme_style_override("normal", label_style); //more compact
  464. hb->add_child(label);
  465. }
  466. }
  467. }
  468. if (valid_right && visual_shader->get_shader_type() == VisualShader::TYPE_FRAGMENT && port_right != VisualShaderNode::PORT_TYPE_TRANSFORM && port_right != VisualShaderNode::PORT_TYPE_SAMPLER) {
  469. TextureButton *preview = memnew(TextureButton);
  470. preview->set_toggle_mode(true);
  471. preview->set_normal_texture(VisualShaderEditor::get_singleton()->get_theme_icon("GuiVisibilityHidden", "EditorIcons"));
  472. preview->set_pressed_texture(VisualShaderEditor::get_singleton()->get_theme_icon("GuiVisibilityVisible", "EditorIcons"));
  473. preview->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  474. register_output_port(p_id, i, preview);
  475. preview->connect("pressed", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_preview_select_port), varray(p_id, i), CONNECT_DEFERRED);
  476. hb->add_child(preview);
  477. }
  478. if (is_group) {
  479. offset = memnew(Control);
  480. offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  481. node->add_child(offset);
  482. port_offset++;
  483. }
  484. node->add_child(hb);
  485. node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], valid_right, port_right, type_color[port_right]);
  486. }
  487. if (vsnode->get_output_port_for_preview() >= 0) {
  488. show_port_preview(p_type, p_id, vsnode->get_output_port_for_preview());
  489. }
  490. offset = memnew(Control);
  491. offset->set_custom_minimum_size(Size2(0, 4 * EDSCALE));
  492. node->add_child(offset);
  493. String error = vsnode->get_warning(visual_shader->get_mode(), p_type);
  494. if (error != String()) {
  495. Label *error_label = memnew(Label);
  496. error_label->add_theme_color_override("font_color", VisualShaderEditor::get_singleton()->get_theme_color("error_color", "Editor"));
  497. error_label->set_text(error);
  498. node->add_child(error_label);
  499. }
  500. if (is_expression) {
  501. CodeEdit *expression_box = memnew(CodeEdit);
  502. Ref<CodeHighlighter> expression_syntax_highlighter;
  503. expression_syntax_highlighter.instance();
  504. expression_node->set_control(expression_box, 0);
  505. node->add_child(expression_box);
  506. Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
  507. Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
  508. Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
  509. Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color");
  510. Color symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color");
  511. Color function_color = EDITOR_GET("text_editor/highlighting/function_color");
  512. Color number_color = EDITOR_GET("text_editor/highlighting/number_color");
  513. Color members_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
  514. expression_box->set_syntax_highlighter(expression_syntax_highlighter);
  515. expression_box->add_theme_color_override("background_color", background_color);
  516. for (List<String>::Element *E = VisualShaderEditor::get_singleton()->keyword_list.front(); E; E = E->next()) {
  517. expression_syntax_highlighter->add_keyword_color(E->get(), keyword_color);
  518. }
  519. expression_box->add_theme_font_override("font", VisualShaderEditor::get_singleton()->get_theme_font("expression", "EditorFonts"));
  520. expression_box->add_theme_color_override("font_color", text_color);
  521. expression_syntax_highlighter->set_number_color(number_color);
  522. expression_syntax_highlighter->set_symbol_color(symbol_color);
  523. expression_syntax_highlighter->set_function_color(function_color);
  524. expression_syntax_highlighter->set_member_variable_color(members_color);
  525. expression_syntax_highlighter->add_color_region("/*", "*/", comment_color, false);
  526. expression_syntax_highlighter->add_color_region("//", "", comment_color, true);
  527. expression_box->set_text(expression);
  528. expression_box->set_context_menu_enabled(false);
  529. expression_box->set_draw_line_numbers(true);
  530. expression_box->connect("focus_exited", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_expression_focus_out), varray(expression_box, p_id));
  531. }
  532. if (!uniform.is_valid()) {
  533. VisualShaderEditor::get_singleton()->graph->add_child(node);
  534. VisualShaderEditor::get_singleton()->_update_created_node(node);
  535. if (is_group) {
  536. call_deferred("_set_node_size", (int)p_type, p_id, size);
  537. }
  538. }
  539. }
  540. void VisualShaderGraphPlugin::remove_node(VisualShader::Type p_type, int p_id) {
  541. if (visual_shader->get_shader_type() == p_type && links.has(p_id)) {
  542. Ref<VisualShaderNodeUniform> uniform = Ref<VisualShaderNode>(links[p_id].visual_node);
  543. if (uniform.is_valid()) {
  544. VisualShaderEditor::get_singleton()->call_deferred("_update_uniforms");
  545. }
  546. links[p_id].graph_node->get_parent()->remove_child(links[p_id].graph_node);
  547. memdelete(links[p_id].graph_node);
  548. links.erase(p_id);
  549. }
  550. }
  551. void VisualShaderGraphPlugin::connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
  552. if (visual_shader->get_shader_type() == p_type) {
  553. VisualShaderEditor::get_singleton()->graph->connect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
  554. }
  555. }
  556. void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
  557. if (visual_shader->get_shader_type() == p_type) {
  558. VisualShaderEditor::get_singleton()->graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
  559. }
  560. }
  561. VisualShaderGraphPlugin::~VisualShaderGraphPlugin() {
  562. }
  563. /////////////////
  564. void VisualShaderEditor::edit(VisualShader *p_visual_shader) {
  565. bool changed = false;
  566. if (p_visual_shader) {
  567. if (visual_shader.is_null()) {
  568. changed = true;
  569. } else {
  570. if (visual_shader.ptr() != p_visual_shader) {
  571. changed = true;
  572. }
  573. }
  574. visual_shader = Ref<VisualShader>(p_visual_shader);
  575. graph_plugin->register_shader(visual_shader.ptr());
  576. if (!visual_shader->is_connected("changed", callable_mp(this, &VisualShaderEditor::_update_preview))) {
  577. visual_shader->connect("changed", callable_mp(this, &VisualShaderEditor::_update_preview));
  578. }
  579. #ifndef DISABLE_DEPRECATED
  580. String version = VERSION_BRANCH;
  581. if (visual_shader->get_version() != version) {
  582. visual_shader->update_version(version);
  583. }
  584. #endif
  585. visual_shader->set_graph_offset(graph->get_scroll_ofs() / EDSCALE);
  586. _set_mode(visual_shader->get_mode());
  587. } else {
  588. if (visual_shader.is_valid()) {
  589. if (visual_shader->is_connected("changed", callable_mp(this, &VisualShaderEditor::_update_preview))) {
  590. visual_shader->disconnect("changed", callable_mp(this, &VisualShaderEditor::_update_preview));
  591. }
  592. }
  593. visual_shader.unref();
  594. }
  595. if (visual_shader.is_null()) {
  596. hide();
  597. } else {
  598. if (changed) { // to avoid tree collapse
  599. _clear_buffer();
  600. _update_options_menu();
  601. _update_preview();
  602. _update_graph();
  603. }
  604. }
  605. }
  606. void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
  607. if (plugins.find(p_plugin) != -1) {
  608. return;
  609. }
  610. plugins.push_back(p_plugin);
  611. }
  612. void VisualShaderEditor::remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
  613. plugins.erase(p_plugin);
  614. }
  615. void VisualShaderEditor::clear_custom_types() {
  616. for (int i = 0; i < add_options.size(); i++) {
  617. if (add_options[i].is_custom) {
  618. add_options.remove(i);
  619. i--;
  620. }
  621. }
  622. }
  623. void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend) {
  624. ERR_FAIL_COND(!p_name.is_valid_identifier());
  625. ERR_FAIL_COND(!p_script.is_valid());
  626. for (int i = 0; i < add_options.size(); i++) {
  627. if (add_options[i].is_custom) {
  628. if (add_options[i].script == p_script) {
  629. return;
  630. }
  631. }
  632. }
  633. AddOption ao;
  634. ao.name = p_name;
  635. ao.script = p_script;
  636. ao.return_type = p_return_icon_type;
  637. ao.description = p_description;
  638. ao.category = p_category;
  639. ao.highend = p_highend;
  640. ao.is_custom = true;
  641. bool begin = false;
  642. String root = p_category.split("/")[0];
  643. for (int i = 0; i < add_options.size(); i++) {
  644. if (add_options[i].is_custom) {
  645. if (add_options[i].category == root) {
  646. if (!begin) {
  647. begin = true;
  648. }
  649. } else {
  650. if (begin) {
  651. add_options.insert(i, ao);
  652. return;
  653. }
  654. }
  655. }
  656. }
  657. add_options.push_back(ao);
  658. }
  659. bool VisualShaderEditor::_is_available(int p_mode) {
  660. int current_mode = edit_type->get_selected();
  661. if (p_mode != -1) {
  662. switch (current_mode) {
  663. case 0: // Vertex or Emit
  664. current_mode = 1;
  665. break;
  666. case 1: // Fragment or Process
  667. current_mode = 2;
  668. break;
  669. case 2: // Light or End
  670. current_mode = 4;
  671. break;
  672. default:
  673. break;
  674. }
  675. }
  676. return (p_mode == -1 || (p_mode & current_mode) != 0);
  677. }
  678. void VisualShaderEditor::update_custom_nodes() {
  679. if (members_dialog->is_visible()) {
  680. return;
  681. }
  682. clear_custom_types();
  683. List<StringName> class_list;
  684. ScriptServer::get_global_class_list(&class_list);
  685. Dictionary added;
  686. for (int i = 0; i < class_list.size(); i++) {
  687. if (ScriptServer::get_global_class_native_base(class_list[i]) == "VisualShaderNodeCustom") {
  688. String script_path = ScriptServer::get_global_class_path(class_list[i]);
  689. Ref<Resource> res = ResourceLoader::load(script_path);
  690. ERR_FAIL_COND(res.is_null());
  691. ERR_FAIL_COND(!res->is_class("Script"));
  692. Ref<Script> script = Ref<Script>(res);
  693. Ref<VisualShaderNodeCustom> ref;
  694. ref.instance();
  695. ref->set_script(script);
  696. String name;
  697. if (ref->has_method("_get_name")) {
  698. name = (String)ref->call("_get_name");
  699. } else {
  700. name = "Unnamed";
  701. }
  702. String description = "";
  703. if (ref->has_method("_get_description")) {
  704. description = (String)ref->call("_get_description");
  705. }
  706. int return_icon_type = -1;
  707. if (ref->has_method("_get_return_icon_type")) {
  708. return_icon_type = (int)ref->call("_get_return_icon_type");
  709. }
  710. String category = "";
  711. if (ref->has_method("_get_category")) {
  712. category = (String)ref->call("_get_category");
  713. }
  714. String subcategory = "";
  715. if (ref->has_method("_get_subcategory")) {
  716. subcategory = (String)ref->call("_get_subcategory");
  717. }
  718. bool highend = false;
  719. if (ref->has_method("_is_highend")) {
  720. highend = (bool)ref->call("_is_highend");
  721. }
  722. Dictionary dict;
  723. dict["name"] = name;
  724. dict["script"] = script;
  725. dict["description"] = description;
  726. dict["return_icon_type"] = return_icon_type;
  727. category = category.rstrip("/");
  728. category = category.lstrip("/");
  729. category = "Addons/" + category;
  730. if (subcategory != "") {
  731. category += "/" + subcategory;
  732. }
  733. dict["category"] = category;
  734. dict["highend"] = highend;
  735. String key;
  736. key = category + "/" + name;
  737. added[key] = dict;
  738. }
  739. }
  740. Array keys = added.keys();
  741. keys.sort();
  742. for (int i = 0; i < keys.size(); i++) {
  743. const Variant &key = keys.get(i);
  744. const Dictionary &value = (Dictionary)added[key];
  745. add_custom_type(value["name"], value["script"], value["description"], value["return_icon_type"], value["category"], value["highend"]);
  746. }
  747. _update_options_menu();
  748. }
  749. String VisualShaderEditor::_get_description(int p_idx) {
  750. return add_options[p_idx].description;
  751. }
  752. void VisualShaderEditor::_update_options_menu() {
  753. node_desc->set_text("");
  754. members_dialog->get_ok()->set_disabled(true);
  755. members->clear();
  756. TreeItem *root = members->create_item();
  757. String filter = node_filter->get_text().strip_edges();
  758. bool use_filter = !filter.empty();
  759. bool is_first_item = true;
  760. Color unsupported_color = get_theme_color("error_color", "Editor");
  761. Color supported_color = get_theme_color("warning_color", "Editor");
  762. static bool low_driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name") == "GLES2";
  763. Map<String, TreeItem *> folders;
  764. int current_func = -1;
  765. if (!visual_shader.is_null()) {
  766. current_func = visual_shader->get_mode();
  767. }
  768. Vector<AddOption> custom_options;
  769. Vector<AddOption> embedded_options;
  770. for (int i = 0; i < add_options.size(); i++) {
  771. if (!use_filter || add_options[i].name.findn(filter) != -1) {
  772. if ((add_options[i].func != current_func && add_options[i].func != -1) || !_is_available(add_options[i].mode)) {
  773. continue;
  774. }
  775. const_cast<AddOption &>(add_options[i]).temp_idx = i; // save valid id
  776. if (add_options[i].is_custom) {
  777. custom_options.push_back(add_options[i]);
  778. } else {
  779. embedded_options.push_back(add_options[i]);
  780. }
  781. }
  782. }
  783. Vector<AddOption> options;
  784. SortArray<AddOption, _OptionComparator> sorter;
  785. sorter.sort(custom_options.ptrw(), custom_options.size());
  786. options.append_array(custom_options);
  787. options.append_array(embedded_options);
  788. for (int i = 0; i < options.size(); i++) {
  789. String path = options[i].category;
  790. Vector<String> subfolders = path.split("/");
  791. TreeItem *category = nullptr;
  792. if (!folders.has(path)) {
  793. category = root;
  794. String path_temp = "";
  795. for (int j = 0; j < subfolders.size(); j++) {
  796. path_temp += subfolders[j];
  797. if (!folders.has(path_temp)) {
  798. category = members->create_item(category);
  799. category->set_selectable(0, false);
  800. category->set_collapsed(!use_filter);
  801. category->set_text(0, subfolders[j]);
  802. folders.insert(path_temp, category);
  803. } else {
  804. category = folders[path_temp];
  805. }
  806. }
  807. } else {
  808. category = folders[path];
  809. }
  810. TreeItem *item = members->create_item(category);
  811. if (options[i].highend && low_driver) {
  812. item->set_custom_color(0, unsupported_color);
  813. } else if (options[i].highend) {
  814. item->set_custom_color(0, supported_color);
  815. }
  816. item->set_text(0, options[i].name);
  817. if (is_first_item && use_filter) {
  818. item->select(0);
  819. node_desc->set_text(options[i].description);
  820. is_first_item = false;
  821. }
  822. switch (options[i].return_type) {
  823. case VisualShaderNode::PORT_TYPE_SCALAR:
  824. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon("float", "EditorIcons"));
  825. break;
  826. case VisualShaderNode::PORT_TYPE_SCALAR_INT:
  827. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon("int", "EditorIcons"));
  828. break;
  829. case VisualShaderNode::PORT_TYPE_VECTOR:
  830. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Vector3", "EditorIcons"));
  831. break;
  832. case VisualShaderNode::PORT_TYPE_BOOLEAN:
  833. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon("bool", "EditorIcons"));
  834. break;
  835. case VisualShaderNode::PORT_TYPE_TRANSFORM:
  836. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Transform", "EditorIcons"));
  837. break;
  838. case VisualShaderNode::PORT_TYPE_SAMPLER:
  839. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon("ImageTexture", "EditorIcons"));
  840. break;
  841. default:
  842. break;
  843. }
  844. item->set_meta("id", options[i].temp_idx);
  845. }
  846. }
  847. void VisualShaderEditor::_set_mode(int p_which) {
  848. if (p_which == VisualShader::MODE_PARTICLES) {
  849. edit_type_standart->set_visible(false);
  850. edit_type_particles->set_visible(true);
  851. edit_type = edit_type_particles;
  852. particles_mode = true;
  853. } else {
  854. edit_type_particles->set_visible(false);
  855. edit_type_standart->set_visible(true);
  856. edit_type = edit_type_standart;
  857. particles_mode = false;
  858. }
  859. visual_shader->set_shader_type(get_current_shader_type());
  860. }
  861. Size2 VisualShaderEditor::get_minimum_size() const {
  862. return Size2(10, 200);
  863. }
  864. void VisualShaderEditor::_draw_color_over_button(Object *obj, Color p_color) {
  865. Button *button = Object::cast_to<Button>(obj);
  866. if (!button) {
  867. return;
  868. }
  869. Ref<StyleBox> normal = get_theme_stylebox("normal", "Button");
  870. button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
  871. }
  872. void VisualShaderEditor::_update_created_node(GraphNode *node) {
  873. if (EditorSettings::get_singleton()->get("interface/theme/use_graph_node_headers")) {
  874. Ref<StyleBoxFlat> sb = node->get_theme_stylebox("frame", "GraphNode");
  875. Color c = sb->get_border_color();
  876. Color ic;
  877. Color mono_color;
  878. if (((c.r + c.g + c.b) / 3) < 0.7) {
  879. mono_color = Color(1.0, 1.0, 1.0);
  880. ic = Color(0.0, 0.0, 0.0, 0.7);
  881. } else {
  882. mono_color = Color(0.0, 0.0, 0.0);
  883. ic = Color(1.0, 1.0, 1.0, 0.7);
  884. }
  885. mono_color.a = 0.85;
  886. c = mono_color;
  887. node->add_theme_color_override("title_color", c);
  888. c.a = 0.7;
  889. node->add_theme_color_override("close_color", c);
  890. node->add_theme_color_override("resizer_color", ic);
  891. }
  892. }
  893. void VisualShaderEditor::_update_uniforms() {
  894. VisualShaderNodeUniformRef::clear_uniforms();
  895. for (int t = 0; t < VisualShader::TYPE_MAX; t++) {
  896. Vector<int> tnodes = visual_shader->get_node_list((VisualShader::Type)t);
  897. for (int i = 0; i < tnodes.size(); i++) {
  898. Ref<VisualShaderNode> vsnode = visual_shader->get_node((VisualShader::Type)t, tnodes[i]);
  899. Ref<VisualShaderNodeUniform> uniform = vsnode;
  900. if (uniform.is_valid()) {
  901. Ref<VisualShaderNodeFloatUniform> float_uniform = vsnode;
  902. Ref<VisualShaderNodeIntUniform> int_uniform = vsnode;
  903. Ref<VisualShaderNodeVec3Uniform> vec3_uniform = vsnode;
  904. Ref<VisualShaderNodeColorUniform> color_uniform = vsnode;
  905. Ref<VisualShaderNodeBooleanUniform> bool_uniform = vsnode;
  906. Ref<VisualShaderNodeTransformUniform> transform_uniform = vsnode;
  907. VisualShaderNodeUniformRef::UniformType uniform_type;
  908. if (float_uniform.is_valid()) {
  909. uniform_type = VisualShaderNodeUniformRef::UniformType::UNIFORM_TYPE_FLOAT;
  910. } else if (int_uniform.is_valid()) {
  911. uniform_type = VisualShaderNodeUniformRef::UniformType::UNIFORM_TYPE_INT;
  912. } else if (bool_uniform.is_valid()) {
  913. uniform_type = VisualShaderNodeUniformRef::UniformType::UNIFORM_TYPE_BOOLEAN;
  914. } else if (vec3_uniform.is_valid()) {
  915. uniform_type = VisualShaderNodeUniformRef::UniformType::UNIFORM_TYPE_VECTOR;
  916. } else if (transform_uniform.is_valid()) {
  917. uniform_type = VisualShaderNodeUniformRef::UniformType::UNIFORM_TYPE_TRANSFORM;
  918. } else if (color_uniform.is_valid()) {
  919. uniform_type = VisualShaderNodeUniformRef::UniformType::UNIFORM_TYPE_COLOR;
  920. } else {
  921. uniform_type = VisualShaderNodeUniformRef::UniformType::UNIFORM_TYPE_SAMPLER;
  922. }
  923. VisualShaderNodeUniformRef::add_uniform(uniform->get_uniform_name(), uniform_type);
  924. }
  925. }
  926. }
  927. }
  928. void VisualShaderEditor::_update_graph() {
  929. if (updating) {
  930. return;
  931. }
  932. if (visual_shader.is_null()) {
  933. return;
  934. }
  935. graph->set_scroll_ofs(visual_shader->get_graph_offset() * EDSCALE);
  936. VisualShader::Type type = get_current_shader_type();
  937. graph->clear_connections();
  938. //erase all nodes
  939. for (int i = 0; i < graph->get_child_count(); i++) {
  940. if (Object::cast_to<GraphNode>(graph->get_child(i))) {
  941. Node *node = graph->get_child(i);
  942. graph->remove_child(node);
  943. memdelete(node);
  944. i--;
  945. }
  946. }
  947. List<VisualShader::Connection> connections;
  948. visual_shader->get_node_connections(type, &connections);
  949. graph_plugin->set_connections(connections);
  950. Vector<int> nodes = visual_shader->get_node_list(type);
  951. _update_uniforms();
  952. graph_plugin->clear_links();
  953. graph_plugin->make_dirty(true);
  954. for (int n_i = 0; n_i < nodes.size(); n_i++) {
  955. graph_plugin->add_node(type, nodes[n_i]);
  956. }
  957. graph_plugin->make_dirty(false);
  958. for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) {
  959. int from = E->get().from_node;
  960. int from_idx = E->get().from_port;
  961. int to = E->get().to_node;
  962. int to_idx = E->get().to_port;
  963. graph->connect_node(itos(from), from_idx, itos(to), to_idx);
  964. }
  965. }
  966. VisualShader::Type VisualShaderEditor::get_current_shader_type() const {
  967. VisualShader::Type type;
  968. if (particles_mode) {
  969. type = VisualShader::Type(edit_type->get_selected() + 3);
  970. } else {
  971. type = VisualShader::Type(edit_type->get_selected());
  972. }
  973. return type;
  974. }
  975. void VisualShaderEditor::_add_input_port(int p_node, int p_port, int p_port_type, const String &p_name) {
  976. VisualShader::Type type = get_current_shader_type();
  977. Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node);
  978. if (node.is_null()) {
  979. return;
  980. }
  981. undo_redo->create_action(TTR("Add input port"));
  982. undo_redo->add_do_method(node.ptr(), "add_input_port", p_port, p_port_type, p_name);
  983. undo_redo->add_undo_method(node.ptr(), "remove_input_port", p_port);
  984. undo_redo->add_do_method(this, "_update_graph");
  985. undo_redo->add_undo_method(this, "_update_graph");
  986. undo_redo->add_do_method(this, "_rebuild");
  987. undo_redo->add_undo_method(this, "_rebuild");
  988. undo_redo->commit_action();
  989. }
  990. void VisualShaderEditor::_add_output_port(int p_node, int p_port, int p_port_type, const String &p_name) {
  991. VisualShader::Type type = get_current_shader_type();
  992. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  993. if (node.is_null()) {
  994. return;
  995. }
  996. undo_redo->create_action(TTR("Add output port"));
  997. undo_redo->add_do_method(node.ptr(), "add_output_port", p_port, p_port_type, p_name);
  998. undo_redo->add_undo_method(node.ptr(), "remove_output_port", p_port);
  999. undo_redo->add_do_method(this, "_update_graph");
  1000. undo_redo->add_undo_method(this, "_update_graph");
  1001. undo_redo->add_do_method(this, "_rebuild");
  1002. undo_redo->add_undo_method(this, "_rebuild");
  1003. undo_redo->commit_action();
  1004. }
  1005. void VisualShaderEditor::_change_input_port_type(int p_type, int p_node, int p_port) {
  1006. VisualShader::Type type = get_current_shader_type();
  1007. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  1008. if (node.is_null()) {
  1009. return;
  1010. }
  1011. undo_redo->create_action(TTR("Change input port type"));
  1012. undo_redo->add_do_method(node.ptr(), "set_input_port_type", p_port, p_type);
  1013. undo_redo->add_undo_method(node.ptr(), "set_input_port_type", p_port, node->get_input_port_type(p_port));
  1014. undo_redo->add_do_method(this, "_update_graph");
  1015. undo_redo->add_undo_method(this, "_update_graph");
  1016. undo_redo->add_do_method(this, "_rebuild");
  1017. undo_redo->add_undo_method(this, "_rebuild");
  1018. undo_redo->commit_action();
  1019. }
  1020. void VisualShaderEditor::_change_output_port_type(int p_type, int p_node, int p_port) {
  1021. VisualShader::Type type = get_current_shader_type();
  1022. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  1023. if (node.is_null()) {
  1024. return;
  1025. }
  1026. undo_redo->create_action(TTR("Change output port type"));
  1027. undo_redo->add_do_method(node.ptr(), "set_output_port_type", p_port, p_type);
  1028. undo_redo->add_undo_method(node.ptr(), "set_output_port_type", p_port, node->get_output_port_type(p_port));
  1029. undo_redo->add_do_method(this, "_update_graph");
  1030. undo_redo->add_undo_method(this, "_update_graph");
  1031. undo_redo->add_do_method(this, "_rebuild");
  1032. undo_redo->add_undo_method(this, "_rebuild");
  1033. undo_redo->commit_action();
  1034. }
  1035. void VisualShaderEditor::_change_input_port_name(const String &p_text, Object *line_edit, int p_node_id, int p_port_id) {
  1036. VisualShader::Type type = get_current_shader_type();
  1037. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  1038. ERR_FAIL_COND(!node.is_valid());
  1039. undo_redo->create_action(TTR("Change input port name"));
  1040. undo_redo->add_do_method(node.ptr(), "set_input_port_name", p_port_id, p_text);
  1041. undo_redo->add_undo_method(node.ptr(), "set_input_port_name", p_port_id, node->get_input_port_name(p_port_id));
  1042. undo_redo->add_do_method(this, "_rebuild");
  1043. undo_redo->add_undo_method(this, "_rebuild");
  1044. undo_redo->commit_action();
  1045. }
  1046. void VisualShaderEditor::_change_output_port_name(const String &p_text, Object *line_edit, int p_node_id, int p_port_id) {
  1047. VisualShader::Type type = get_current_shader_type();
  1048. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  1049. ERR_FAIL_COND(!node.is_valid());
  1050. undo_redo->create_action(TTR("Change output port name"));
  1051. undo_redo->add_do_method(node.ptr(), "set_output_port_name", p_port_id, p_text);
  1052. undo_redo->add_undo_method(node.ptr(), "set_output_port_name", p_port_id, node->get_output_port_name(p_port_id));
  1053. undo_redo->add_do_method(this, "_rebuild");
  1054. undo_redo->add_undo_method(this, "_rebuild");
  1055. undo_redo->commit_action();
  1056. }
  1057. void VisualShaderEditor::_remove_input_port(int p_node, int p_port) {
  1058. VisualShader::Type type = get_current_shader_type();
  1059. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  1060. if (node.is_null()) {
  1061. return;
  1062. }
  1063. undo_redo->create_action(TTR("Remove input port"));
  1064. List<VisualShader::Connection> conns;
  1065. visual_shader->get_node_connections(type, &conns);
  1066. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  1067. int from_node = E->get().from_node;
  1068. int from_port = E->get().from_port;
  1069. int to_node = E->get().to_node;
  1070. int to_port = E->get().to_port;
  1071. if (to_node == p_node) {
  1072. if (to_port == p_port) {
  1073. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_port, to_node, to_port);
  1074. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, from_node, from_port, to_node, to_port);
  1075. } else if (to_port > p_port) {
  1076. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_port, to_node, to_port);
  1077. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, from_node, from_port, to_node, to_port);
  1078. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes_forced", type, from_node, from_port, to_node, to_port - 1);
  1079. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_port, to_node, to_port - 1);
  1080. }
  1081. }
  1082. }
  1083. undo_redo->add_do_method(node.ptr(), "remove_input_port", p_port);
  1084. undo_redo->add_undo_method(node.ptr(), "add_input_port", p_port, (int)node->get_input_port_type(p_port), node->get_input_port_name(p_port));
  1085. undo_redo->add_do_method(this, "_update_graph");
  1086. undo_redo->add_undo_method(this, "_update_graph");
  1087. undo_redo->add_do_method(this, "_rebuild");
  1088. undo_redo->add_undo_method(this, "_rebuild");
  1089. undo_redo->commit_action();
  1090. }
  1091. void VisualShaderEditor::_remove_output_port(int p_node, int p_port) {
  1092. VisualShader::Type type = get_current_shader_type();
  1093. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  1094. if (node.is_null()) {
  1095. return;
  1096. }
  1097. undo_redo->create_action(TTR("Remove output port"));
  1098. List<VisualShader::Connection> conns;
  1099. visual_shader->get_node_connections(type, &conns);
  1100. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  1101. int from_node = E->get().from_node;
  1102. int from_port = E->get().from_port;
  1103. int to_node = E->get().to_node;
  1104. int to_port = E->get().to_port;
  1105. if (from_node == p_node) {
  1106. if (from_port == p_port) {
  1107. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_port, to_node, to_port);
  1108. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, from_node, from_port, to_node, to_port);
  1109. } else if (from_port > p_port) {
  1110. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_port, to_node, to_port);
  1111. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, from_node, from_port, to_node, to_port);
  1112. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes_forced", type, from_node, from_port - 1, to_node, to_port);
  1113. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_port - 1, to_node, to_port);
  1114. }
  1115. }
  1116. }
  1117. undo_redo->add_do_method(node.ptr(), "remove_output_port", p_port);
  1118. undo_redo->add_undo_method(node.ptr(), "add_output_port", p_port, (int)node->get_output_port_type(p_port), node->get_output_port_name(p_port));
  1119. undo_redo->add_do_method(this, "_update_graph");
  1120. undo_redo->add_undo_method(this, "_update_graph");
  1121. undo_redo->add_do_method(this, "_rebuild");
  1122. undo_redo->add_undo_method(this, "_rebuild");
  1123. undo_redo->commit_action();
  1124. }
  1125. void VisualShaderEditor::_expression_focus_out(Object *code_edit, int p_node) {
  1126. VisualShader::Type type = get_current_shader_type();
  1127. Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node);
  1128. if (node.is_null()) {
  1129. return;
  1130. }
  1131. CodeEdit *expression_box = Object::cast_to<CodeEdit>(code_edit);
  1132. if (node->get_expression() == expression_box->get_text()) {
  1133. return;
  1134. }
  1135. undo_redo->create_action(TTR("Set expression"));
  1136. undo_redo->add_do_method(node.ptr(), "set_expression", expression_box->get_text());
  1137. undo_redo->add_undo_method(node.ptr(), "set_expression", node->get_expression());
  1138. undo_redo->add_do_method(this, "_rebuild");
  1139. undo_redo->add_undo_method(this, "_rebuild");
  1140. undo_redo->commit_action();
  1141. }
  1142. void VisualShaderEditor::_rebuild() {
  1143. if (visual_shader != nullptr) {
  1144. EditorNode::get_singleton()->get_log()->clear();
  1145. visual_shader->rebuild();
  1146. }
  1147. }
  1148. void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p_size) {
  1149. VisualShader::Type type = get_current_shader_type();
  1150. Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
  1151. if (node.is_null()) {
  1152. return;
  1153. }
  1154. Ref<VisualShaderNodeGroupBase> group_node = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
  1155. if (group_node.is_null()) {
  1156. return;
  1157. }
  1158. Vector2 size = p_size;
  1159. group_node->set_size(size);
  1160. GraphNode *gn = nullptr;
  1161. if (edit_type->get_selected() == p_type) { // check - otherwise the error will be emitted
  1162. Node *node2 = graph->get_node(itos(p_node));
  1163. gn = Object::cast_to<GraphNode>(node2);
  1164. if (!gn) {
  1165. return;
  1166. }
  1167. gn->set_custom_minimum_size(size);
  1168. gn->set_size(Size2(1, 1));
  1169. }
  1170. Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  1171. if (!expression_node.is_null()) {
  1172. Control *text_box = expression_node->get_control(0);
  1173. Size2 box_size = size;
  1174. if (gn != nullptr) {
  1175. if (box_size.x < 150 * EDSCALE || box_size.y < 0) {
  1176. box_size.x = gn->get_size().x;
  1177. }
  1178. }
  1179. box_size.x -= text_box->get_margin(MARGIN_LEFT);
  1180. box_size.x -= 28 * EDSCALE;
  1181. box_size.y -= text_box->get_margin(MARGIN_TOP);
  1182. box_size.y -= 28 * EDSCALE;
  1183. text_box->set_custom_minimum_size(Size2(box_size.x, box_size.y));
  1184. text_box->set_size(Size2(1, 1));
  1185. }
  1186. }
  1187. void VisualShaderEditor::_node_resized(const Vector2 &p_new_size, int p_type, int p_node) {
  1188. VisualShader::Type type = get_current_shader_type();
  1189. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  1190. if (node.is_null()) {
  1191. return;
  1192. }
  1193. undo_redo->create_action(TTR("Resize VisualShader node"), UndoRedo::MERGE_ENDS);
  1194. undo_redo->add_do_method(this, "_set_node_size", p_type, p_node, p_new_size);
  1195. undo_redo->add_undo_method(this, "_set_node_size", p_type, p_node, node->get_size());
  1196. undo_redo->commit_action();
  1197. }
  1198. void VisualShaderEditor::_preview_select_port(int p_node, int p_port) {
  1199. VisualShader::Type type = get_current_shader_type();
  1200. Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
  1201. if (node.is_null()) {
  1202. return;
  1203. }
  1204. int prev_port = node->get_output_port_for_preview();
  1205. if (node->get_output_port_for_preview() == p_port) {
  1206. p_port = -1; //toggle it
  1207. }
  1208. undo_redo->create_action(p_port == -1 ? TTR("Hide Port Preview") : TTR("Show Port Preview"));
  1209. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", p_port);
  1210. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", prev_port);
  1211. undo_redo->add_do_method(graph_plugin.ptr(), "show_port_preview", (int)type, p_node, p_port);
  1212. undo_redo->add_undo_method(graph_plugin.ptr(), "show_port_preview", (int)type, p_node, prev_port);
  1213. undo_redo->commit_action();
  1214. }
  1215. void VisualShaderEditor::_line_edit_changed(const String &p_text, Object *line_edit, int p_node_id) {
  1216. VisualShader::Type type = get_current_shader_type();
  1217. Ref<VisualShaderNodeUniform> node = visual_shader->get_node(type, p_node_id);
  1218. ERR_FAIL_COND(!node.is_valid());
  1219. String validated_name = visual_shader->validate_uniform_name(p_text, node);
  1220. updating = true;
  1221. undo_redo->create_action(TTR("Set Uniform Name"));
  1222. undo_redo->add_do_method(node.ptr(), "set_uniform_name", validated_name);
  1223. undo_redo->add_undo_method(node.ptr(), "set_uniform_name", node->get_uniform_name());
  1224. undo_redo->add_do_method(this, "_update_graph");
  1225. undo_redo->add_undo_method(this, "_update_graph");
  1226. undo_redo->commit_action();
  1227. updating = false;
  1228. Object::cast_to<LineEdit>(line_edit)->set_text(validated_name);
  1229. }
  1230. void VisualShaderEditor::_line_edit_focus_out(Object *line_edit, int p_node_id) {
  1231. String text = Object::cast_to<LineEdit>(line_edit)->get_text();
  1232. _line_edit_changed(text, line_edit, p_node_id);
  1233. }
  1234. void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output) {
  1235. VisualShader::Type type = get_current_shader_type();
  1236. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  1237. ERR_FAIL_COND(!node.is_valid());
  1238. String text = Object::cast_to<LineEdit>(line_edit)->get_text();
  1239. if (!p_output) {
  1240. if (node->get_input_port_name(p_port_id) == text) {
  1241. return;
  1242. }
  1243. } else {
  1244. if (node->get_output_port_name(p_port_id) == text) {
  1245. return;
  1246. }
  1247. }
  1248. List<String> input_names;
  1249. List<String> output_names;
  1250. for (int i = 0; i < node->get_input_port_count(); i++) {
  1251. if (!p_output && i == p_port_id) {
  1252. continue;
  1253. }
  1254. input_names.push_back(node->get_input_port_name(i));
  1255. }
  1256. for (int i = 0; i < node->get_output_port_count(); i++) {
  1257. if (p_output && i == p_port_id) {
  1258. continue;
  1259. }
  1260. output_names.push_back(node->get_output_port_name(i));
  1261. }
  1262. String validated_name = visual_shader->validate_port_name(text, input_names, output_names);
  1263. if (validated_name == "") {
  1264. if (!p_output) {
  1265. Object::cast_to<LineEdit>(line_edit)->set_text(node->get_input_port_name(p_port_id));
  1266. } else {
  1267. Object::cast_to<LineEdit>(line_edit)->set_text(node->get_output_port_name(p_port_id));
  1268. }
  1269. return;
  1270. }
  1271. if (!p_output) {
  1272. _change_input_port_name(validated_name, line_edit, p_node_id, p_port_id);
  1273. } else {
  1274. _change_output_port_name(validated_name, line_edit, p_node_id, p_port_id);
  1275. }
  1276. }
  1277. void VisualShaderEditor::_port_edited() {
  1278. VisualShader::Type type = get_current_shader_type();
  1279. Variant value = property_editor->get_variant();
  1280. Ref<VisualShaderNode> vsn = visual_shader->get_node(type, editing_node);
  1281. ERR_FAIL_COND(!vsn.is_valid());
  1282. undo_redo->create_action(TTR("Set Input Default Port"));
  1283. undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, value);
  1284. undo_redo->add_undo_method(vsn.ptr(), "set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
  1285. undo_redo->add_do_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, value);
  1286. undo_redo->add_undo_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, vsn->get_input_port_default_value(editing_port));
  1287. undo_redo->commit_action();
  1288. property_editor->hide();
  1289. }
  1290. void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, int p_port) {
  1291. VisualShader::Type type = get_current_shader_type();
  1292. Ref<VisualShaderNode> vsn = visual_shader->get_node(type, p_node);
  1293. Button *button = Object::cast_to<Button>(p_button);
  1294. ERR_FAIL_COND(!button);
  1295. Variant value = vsn->get_input_port_default_value(p_port);
  1296. property_editor->set_position(button->get_screen_position() + Vector2(0, button->get_size().height));
  1297. property_editor->edit(nullptr, "", value.get_type(), value, 0, "");
  1298. property_editor->popup();
  1299. editing_node = p_node;
  1300. editing_port = p_port;
  1301. }
  1302. void VisualShaderEditor::_add_custom_node(const String &p_path) {
  1303. int idx = -1;
  1304. for (int i = custom_node_option_idx; i < add_options.size(); i++) {
  1305. if (add_options[i].script.is_valid()) {
  1306. if (add_options[i].script->get_path() == p_path) {
  1307. idx = i;
  1308. break;
  1309. }
  1310. }
  1311. }
  1312. if (idx != -1) {
  1313. _add_node(idx);
  1314. }
  1315. }
  1316. void VisualShaderEditor::_add_texture_node(const String &p_path) {
  1317. VisualShaderNodeTexture *texture = (VisualShaderNodeTexture *)_add_node(texture_node_option_idx, -1);
  1318. texture->set_texture(ResourceLoader::load(p_path));
  1319. }
  1320. VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
  1321. ERR_FAIL_INDEX_V(p_idx, add_options.size(), nullptr);
  1322. Ref<VisualShaderNode> vsnode;
  1323. bool is_custom = add_options[p_idx].is_custom;
  1324. if (!is_custom && add_options[p_idx].type != String()) {
  1325. VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(add_options[p_idx].type));
  1326. ERR_FAIL_COND_V(!vsn, nullptr);
  1327. VisualShaderNodeFloatConstant *constant = Object::cast_to<VisualShaderNodeFloatConstant>(vsn);
  1328. if (constant) {
  1329. if ((int)add_options[p_idx].value != -1) {
  1330. constant->set_constant(add_options[p_idx].value);
  1331. }
  1332. }
  1333. if (p_op_idx != -1) {
  1334. VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(vsn);
  1335. if (input) {
  1336. input->set_input_name(add_options[p_idx].sub_func_str);
  1337. }
  1338. VisualShaderNodeIs *is = Object::cast_to<VisualShaderNodeIs>(vsn);
  1339. if (is) {
  1340. is->set_function((VisualShaderNodeIs::Function)p_op_idx);
  1341. }
  1342. VisualShaderNodeCompare *cmp = Object::cast_to<VisualShaderNodeCompare>(vsn);
  1343. if (cmp) {
  1344. cmp->set_function((VisualShaderNodeCompare::Function)p_op_idx);
  1345. }
  1346. VisualShaderNodeColorOp *colorOp = Object::cast_to<VisualShaderNodeColorOp>(vsn);
  1347. if (colorOp) {
  1348. colorOp->set_operator((VisualShaderNodeColorOp::Operator)p_op_idx);
  1349. }
  1350. VisualShaderNodeColorFunc *colorFunc = Object::cast_to<VisualShaderNodeColorFunc>(vsn);
  1351. if (colorFunc) {
  1352. colorFunc->set_function((VisualShaderNodeColorFunc::Function)p_op_idx);
  1353. }
  1354. VisualShaderNodeFloatOp *floatOp = Object::cast_to<VisualShaderNodeFloatOp>(vsn);
  1355. if (floatOp) {
  1356. floatOp->set_operator((VisualShaderNodeFloatOp::Operator)p_op_idx);
  1357. }
  1358. VisualShaderNodeIntOp *intOp = Object::cast_to<VisualShaderNodeIntOp>(vsn);
  1359. if (intOp) {
  1360. intOp->set_operator((VisualShaderNodeIntOp::Operator)p_op_idx);
  1361. }
  1362. VisualShaderNodeFloatFunc *floatFunc = Object::cast_to<VisualShaderNodeFloatFunc>(vsn);
  1363. if (floatFunc) {
  1364. floatFunc->set_function((VisualShaderNodeFloatFunc::Function)p_op_idx);
  1365. }
  1366. VisualShaderNodeIntFunc *intFunc = Object::cast_to<VisualShaderNodeIntFunc>(vsn);
  1367. if (intFunc) {
  1368. intFunc->set_function((VisualShaderNodeIntFunc::Function)p_op_idx);
  1369. }
  1370. VisualShaderNodeVectorOp *vecOp = Object::cast_to<VisualShaderNodeVectorOp>(vsn);
  1371. if (vecOp) {
  1372. vecOp->set_operator((VisualShaderNodeVectorOp::Operator)p_op_idx);
  1373. }
  1374. VisualShaderNodeVectorFunc *vecFunc = Object::cast_to<VisualShaderNodeVectorFunc>(vsn);
  1375. if (vecFunc) {
  1376. vecFunc->set_function((VisualShaderNodeVectorFunc::Function)p_op_idx);
  1377. }
  1378. VisualShaderNodeTransformFunc *matFunc = Object::cast_to<VisualShaderNodeTransformFunc>(vsn);
  1379. if (matFunc) {
  1380. matFunc->set_function((VisualShaderNodeTransformFunc::Function)p_op_idx);
  1381. }
  1382. VisualShaderNodeScalarDerivativeFunc *sderFunc = Object::cast_to<VisualShaderNodeScalarDerivativeFunc>(vsn);
  1383. if (sderFunc) {
  1384. sderFunc->set_function((VisualShaderNodeScalarDerivativeFunc::Function)p_op_idx);
  1385. }
  1386. VisualShaderNodeVectorDerivativeFunc *vderFunc = Object::cast_to<VisualShaderNodeVectorDerivativeFunc>(vsn);
  1387. if (vderFunc) {
  1388. vderFunc->set_function((VisualShaderNodeVectorDerivativeFunc::Function)p_op_idx);
  1389. }
  1390. VisualShaderNodeMultiplyAdd *fmaFunc = Object::cast_to<VisualShaderNodeMultiplyAdd>(vsn);
  1391. if (fmaFunc) {
  1392. fmaFunc->set_type((VisualShaderNodeMultiplyAdd::Type)p_op_idx);
  1393. }
  1394. }
  1395. vsnode = Ref<VisualShaderNode>(vsn);
  1396. } else {
  1397. ERR_FAIL_COND_V(add_options[p_idx].script.is_null(), nullptr);
  1398. String base_type = add_options[p_idx].script->get_instance_base_type();
  1399. VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(base_type));
  1400. ERR_FAIL_COND_V(!vsn, nullptr);
  1401. vsnode = Ref<VisualShaderNode>(vsn);
  1402. vsnode->set_script(add_options[p_idx].script);
  1403. }
  1404. Point2 position = graph->get_scroll_ofs();
  1405. if (saved_node_pos_dirty) {
  1406. position += saved_node_pos;
  1407. } else {
  1408. position += graph->get_size() * 0.5;
  1409. position /= EDSCALE;
  1410. }
  1411. saved_node_pos_dirty = false;
  1412. VisualShader::Type type = get_current_shader_type();
  1413. int id_to_use = visual_shader->get_valid_node_id(type);
  1414. undo_redo->create_action(TTR("Add Node to Visual Shader"));
  1415. undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, vsnode, position, id_to_use);
  1416. undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_to_use);
  1417. undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_to_use);
  1418. undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_to_use);
  1419. VisualShaderNodeExpression *expr = Object::cast_to<VisualShaderNodeExpression>(vsnode.ptr());
  1420. if (expr) {
  1421. undo_redo->add_do_method(expr, "set_size", Size2(250 * EDSCALE, 150 * EDSCALE));
  1422. }
  1423. if (to_node != -1 && to_slot != -1) {
  1424. if (vsnode->get_output_port_count() > 0) {
  1425. int _from_node = id_to_use;
  1426. int _from_slot = 0;
  1427. if (visual_shader->is_port_types_compatible(vsnode->get_output_port_type(_from_slot), visual_shader->get_node(type, to_node)->get_input_port_type(to_slot))) {
  1428. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  1429. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  1430. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  1431. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  1432. }
  1433. }
  1434. } else if (from_node != -1 && from_slot != -1) {
  1435. if (vsnode->get_input_port_count() > 0) {
  1436. int _to_node = id_to_use;
  1437. int _to_slot = 0;
  1438. if (visual_shader->is_port_types_compatible(visual_shader->get_node(type, from_node)->get_output_port_type(from_slot), vsnode->get_input_port_type(_to_slot))) {
  1439. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  1440. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  1441. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  1442. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  1443. }
  1444. }
  1445. }
  1446. undo_redo->commit_action();
  1447. return vsnode.ptr();
  1448. }
  1449. void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) {
  1450. VisualShader::Type type = get_current_shader_type();
  1451. undo_redo->create_action(TTR("Node Moved"));
  1452. undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", type, p_node, p_to);
  1453. undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", type, p_node, p_from);
  1454. undo_redo->add_do_method(graph_plugin.ptr(), "set_node_position", type, p_node, p_to);
  1455. undo_redo->add_undo_method(graph_plugin.ptr(), "set_node_position", type, p_node, p_from);
  1456. undo_redo->commit_action();
  1457. }
  1458. void VisualShaderEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  1459. VisualShader::Type type = get_current_shader_type();
  1460. int from = p_from.to_int();
  1461. int to = p_to.to_int();
  1462. if (!visual_shader->can_connect_nodes(type, from, p_from_index, to, p_to_index)) {
  1463. return;
  1464. }
  1465. undo_redo->create_action(TTR("Nodes Connected"));
  1466. List<VisualShader::Connection> conns;
  1467. visual_shader->get_node_connections(type, &conns);
  1468. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  1469. if (E->get().to_node == to && E->get().to_port == p_to_index) {
  1470. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1471. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1472. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1473. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1474. }
  1475. }
  1476. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  1477. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  1478. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  1479. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  1480. undo_redo->commit_action();
  1481. }
  1482. void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  1483. graph->disconnect_node(p_from, p_from_index, p_to, p_to_index);
  1484. VisualShader::Type type = get_current_shader_type();
  1485. int from = p_from.to_int();
  1486. int to = p_to.to_int();
  1487. //updating = true; seems graph edit can handle this, no need to protect
  1488. undo_redo->create_action(TTR("Nodes Disconnected"));
  1489. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  1490. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  1491. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  1492. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  1493. undo_redo->commit_action();
  1494. //updating = false;
  1495. }
  1496. void VisualShaderEditor::_connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position) {
  1497. from_node = p_from.to_int();
  1498. from_slot = p_from_slot;
  1499. _show_members_dialog(true);
  1500. }
  1501. void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position) {
  1502. to_node = p_to.to_int();
  1503. to_slot = p_to_slot;
  1504. _show_members_dialog(true);
  1505. }
  1506. void VisualShaderEditor::_delete_request(int which) {
  1507. VisualShader::Type type = get_current_shader_type();
  1508. Ref<VisualShaderNode> node = Ref<VisualShaderNode>(visual_shader->get_node(type, which));
  1509. undo_redo->create_action(TTR("Delete Node"));
  1510. List<VisualShader::Connection> conns;
  1511. visual_shader->get_node_connections(type, &conns);
  1512. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  1513. if (E->get().from_node == which || E->get().to_node == which) {
  1514. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1515. }
  1516. }
  1517. undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, which);
  1518. undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, which), which);
  1519. undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, which);
  1520. undo_redo->add_do_method(this, "_clear_buffer");
  1521. undo_redo->add_undo_method(this, "_clear_buffer");
  1522. // restore size, inputs and outputs if node is group
  1523. VisualShaderNodeGroupBase *group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
  1524. if (group) {
  1525. undo_redo->add_undo_method(group, "set_size", group->get_size());
  1526. undo_redo->add_undo_method(group, "set_inputs", group->get_inputs());
  1527. undo_redo->add_undo_method(group, "set_outputs", group->get_outputs());
  1528. }
  1529. // restore expression text if node is expression
  1530. VisualShaderNodeExpression *expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  1531. if (expression) {
  1532. undo_redo->add_undo_method(expression, "set_expression", expression->get_expression());
  1533. }
  1534. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  1535. if (E->get().from_node == which || E->get().to_node == which) {
  1536. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1537. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1538. }
  1539. }
  1540. // delete a node from the graph
  1541. undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, which);
  1542. undo_redo->commit_action();
  1543. }
  1544. void VisualShaderEditor::_node_selected(Object *p_node) {
  1545. VisualShader::Type type = get_current_shader_type();
  1546. GraphNode *gn = Object::cast_to<GraphNode>(p_node);
  1547. ERR_FAIL_COND(!gn);
  1548. int id = String(gn->get_name()).to_int();
  1549. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  1550. ERR_FAIL_COND(!vsnode.is_valid());
  1551. //do not rely on this, makes editor more complex
  1552. //EditorNode::get_singleton()->push_item(vsnode.ptr(), "", true);
  1553. }
  1554. void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
  1555. Ref<InputEventMouseButton> mb = p_event;
  1556. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) {
  1557. List<int> to_change;
  1558. for (int i = 0; i < graph->get_child_count(); i++) {
  1559. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  1560. if (gn) {
  1561. if (gn->is_selected() && gn->is_close_button_visible()) {
  1562. to_change.push_back(gn->get_name().operator String().to_int());
  1563. }
  1564. }
  1565. }
  1566. if (to_change.empty() && copy_nodes_buffer.empty()) {
  1567. _show_members_dialog(true);
  1568. } else {
  1569. popup_menu->set_item_disabled(NodeMenuOptions::COPY, to_change.empty());
  1570. popup_menu->set_item_disabled(NodeMenuOptions::PASTE, copy_nodes_buffer.empty());
  1571. popup_menu->set_item_disabled(NodeMenuOptions::DELETE, to_change.empty());
  1572. popup_menu->set_item_disabled(NodeMenuOptions::DUPLICATE, to_change.empty());
  1573. menu_point = graph->get_local_mouse_position();
  1574. Point2 gpos = Input::get_singleton()->get_mouse_position();
  1575. popup_menu->set_position(gpos);
  1576. popup_menu->popup();
  1577. }
  1578. }
  1579. }
  1580. void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos) {
  1581. if (at_mouse_pos) {
  1582. saved_node_pos_dirty = true;
  1583. saved_node_pos = graph->get_local_mouse_position();
  1584. Point2 gpos = Input::get_singleton()->get_mouse_position();
  1585. members_dialog->popup();
  1586. members_dialog->set_position(gpos);
  1587. } else {
  1588. members_dialog->popup();
  1589. saved_node_pos_dirty = false;
  1590. members_dialog->set_position(graph->get_global_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  1591. }
  1592. // keep dialog within window bounds
  1593. Size2 window_size = DisplayServer::get_singleton()->window_get_size();
  1594. Rect2 dialog_rect = Rect2(members_dialog->get_position(), members_dialog->get_size());
  1595. if (dialog_rect.position.y + dialog_rect.size.y > window_size.y) {
  1596. int difference = dialog_rect.position.y + dialog_rect.size.y - window_size.y;
  1597. members_dialog->set_position(members_dialog->get_position() - Point2(0, difference));
  1598. }
  1599. if (dialog_rect.position.x + dialog_rect.size.x > window_size.x) {
  1600. int difference = dialog_rect.position.x + dialog_rect.size.x - window_size.x;
  1601. members_dialog->set_position(members_dialog->get_position() - Point2(difference, 0));
  1602. }
  1603. node_filter->call_deferred("grab_focus"); // still not visible
  1604. node_filter->select_all();
  1605. }
  1606. void VisualShaderEditor::_sbox_input(const Ref<InputEvent> &p_ie) {
  1607. Ref<InputEventKey> ie = p_ie;
  1608. if (ie.is_valid() && (ie->get_keycode() == KEY_UP ||
  1609. ie->get_keycode() == KEY_DOWN ||
  1610. ie->get_keycode() == KEY_ENTER ||
  1611. ie->get_keycode() == KEY_KP_ENTER)) {
  1612. members->call("_gui_input", ie);
  1613. node_filter->accept_event();
  1614. }
  1615. }
  1616. void VisualShaderEditor::_notification(int p_what) {
  1617. if (p_what == NOTIFICATION_ENTER_TREE) {
  1618. node_filter->set_clear_button_enabled(true);
  1619. // collapse tree by default
  1620. TreeItem *category = members->get_root()->get_children();
  1621. while (category) {
  1622. category->set_collapsed(true);
  1623. TreeItem *sub_category = category->get_children();
  1624. while (sub_category) {
  1625. sub_category->set_collapsed(true);
  1626. sub_category = sub_category->get_next();
  1627. }
  1628. category = category->get_next();
  1629. }
  1630. }
  1631. if (p_what == NOTIFICATION_DRAG_BEGIN) {
  1632. Dictionary dd = get_viewport()->gui_get_drag_data();
  1633. if (members->is_visible_in_tree() && dd.has("id")) {
  1634. members->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
  1635. }
  1636. } else if (p_what == NOTIFICATION_DRAG_END) {
  1637. members->set_drop_mode_flags(0);
  1638. }
  1639. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  1640. highend_label->set_modulate(get_theme_color("vulkan_color", "Editor"));
  1641. error_panel->add_theme_style_override("panel", get_theme_stylebox("bg", "Tree"));
  1642. error_label->add_theme_color_override("font_color", get_theme_color("error_color", "Editor"));
  1643. node_filter->set_right_icon(Control::get_theme_icon("Search", "EditorIcons"));
  1644. preview_shader->set_icon(Control::get_theme_icon("Shader", "EditorIcons"));
  1645. {
  1646. Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
  1647. Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
  1648. Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
  1649. Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color");
  1650. Color symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color");
  1651. Color function_color = EDITOR_GET("text_editor/highlighting/function_color");
  1652. Color number_color = EDITOR_GET("text_editor/highlighting/number_color");
  1653. Color members_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
  1654. preview_text->add_theme_color_override("background_color", background_color);
  1655. for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) {
  1656. syntax_highlighter->add_keyword_color(E->get(), keyword_color);
  1657. }
  1658. preview_text->add_theme_font_override("font", get_theme_font("expression", "EditorFonts"));
  1659. preview_text->add_theme_color_override("font_color", text_color);
  1660. syntax_highlighter->set_number_color(number_color);
  1661. syntax_highlighter->set_symbol_color(symbol_color);
  1662. syntax_highlighter->set_function_color(function_color);
  1663. syntax_highlighter->set_member_variable_color(members_color);
  1664. syntax_highlighter->clear_color_regions();
  1665. syntax_highlighter->add_color_region("/*", "*/", comment_color, false);
  1666. syntax_highlighter->add_color_region("//", "", comment_color, true);
  1667. error_text->add_theme_font_override("font", get_theme_font("status_source", "EditorFonts"));
  1668. error_text->add_theme_color_override("font_color", get_theme_color("error_color", "Editor"));
  1669. }
  1670. tools->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Tools", "EditorIcons"));
  1671. if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) {
  1672. _update_graph();
  1673. }
  1674. }
  1675. }
  1676. void VisualShaderEditor::_scroll_changed(const Vector2 &p_scroll) {
  1677. if (updating) {
  1678. return;
  1679. }
  1680. updating = true;
  1681. visual_shader->set_graph_offset(p_scroll / EDSCALE);
  1682. updating = false;
  1683. }
  1684. void VisualShaderEditor::_node_changed(int p_id) {
  1685. if (updating) {
  1686. return;
  1687. }
  1688. if (is_visible_in_tree()) {
  1689. _update_graph();
  1690. }
  1691. }
  1692. void VisualShaderEditor::_dup_update_excluded(int p_type, Set<int> &r_excluded) {
  1693. r_excluded.clear();
  1694. VisualShader::Type type = (VisualShader::Type)p_type;
  1695. for (int i = 0; i < graph->get_child_count(); i++) {
  1696. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  1697. if (gn) {
  1698. int id = String(gn->get_name()).to_int();
  1699. Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
  1700. Ref<VisualShaderNodeOutput> output = node;
  1701. if (output.is_valid()) {
  1702. r_excluded.insert(id);
  1703. continue;
  1704. }
  1705. r_excluded.insert(id);
  1706. }
  1707. }
  1708. }
  1709. void VisualShaderEditor::_dup_copy_nodes(int p_type, List<int> &r_nodes, Set<int> &r_excluded) {
  1710. VisualShader::Type type = (VisualShader::Type)p_type;
  1711. selection_center.x = 0.0f;
  1712. selection_center.y = 0.0f;
  1713. for (int i = 0; i < graph->get_child_count(); i++) {
  1714. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  1715. if (gn) {
  1716. int id = String(gn->get_name()).to_int();
  1717. Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
  1718. Ref<VisualShaderNodeOutput> output = node;
  1719. if (output.is_valid()) { // can't duplicate output
  1720. r_excluded.insert(id);
  1721. continue;
  1722. }
  1723. if (node.is_valid() && gn->is_selected()) {
  1724. Vector2 pos = visual_shader->get_node_position(type, id);
  1725. selection_center += pos;
  1726. r_nodes.push_back(id);
  1727. }
  1728. r_excluded.insert(id);
  1729. }
  1730. }
  1731. selection_center /= (float)r_nodes.size();
  1732. }
  1733. void VisualShaderEditor::_dup_paste_nodes(int p_type, int p_pasted_type, List<int> &r_nodes, Set<int> &r_excluded, const Vector2 &p_offset, bool p_select) {
  1734. VisualShader::Type type = (VisualShader::Type)p_type;
  1735. VisualShader::Type pasted_type = (VisualShader::Type)p_pasted_type;
  1736. int base_id = visual_shader->get_valid_node_id(type);
  1737. int id_from = base_id;
  1738. Map<int, int> connection_remap;
  1739. Set<int> unsupported_set;
  1740. for (List<int>::Element *E = r_nodes.front(); E; E = E->next()) {
  1741. connection_remap[E->get()] = id_from;
  1742. Ref<VisualShaderNode> node = visual_shader->get_node(pasted_type, E->get());
  1743. bool unsupported = false;
  1744. for (int i = 0; i < add_options.size(); i++) {
  1745. if (add_options[i].type == node->get_class_name()) {
  1746. if (!_is_available(add_options[i].mode)) {
  1747. unsupported = true;
  1748. }
  1749. break;
  1750. }
  1751. }
  1752. if (unsupported) {
  1753. unsupported_set.insert(E->get());
  1754. continue;
  1755. }
  1756. Ref<VisualShaderNode> dupli = node->duplicate();
  1757. undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, dupli, visual_shader->get_node_position(pasted_type, E->get()) + p_offset, id_from);
  1758. undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_from);
  1759. // duplicate size, inputs and outputs if node is group
  1760. Ref<VisualShaderNodeGroupBase> group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
  1761. if (!group.is_null()) {
  1762. undo_redo->add_do_method(dupli.ptr(), "set_size", group->get_size());
  1763. undo_redo->add_do_method(graph_plugin.ptr(), "set_node_size", type, id_from, group->get_size());
  1764. undo_redo->add_do_method(dupli.ptr(), "set_inputs", group->get_inputs());
  1765. undo_redo->add_do_method(dupli.ptr(), "set_outputs", group->get_outputs());
  1766. }
  1767. // duplicate expression text if node is expression
  1768. Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  1769. if (!expression.is_null()) {
  1770. undo_redo->add_do_method(dupli.ptr(), "set_expression", expression->get_expression());
  1771. }
  1772. id_from++;
  1773. }
  1774. List<VisualShader::Connection> conns;
  1775. visual_shader->get_node_connections(pasted_type, &conns);
  1776. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  1777. if (unsupported_set.has(E->get().from_node) || unsupported_set.has(E->get().to_node)) {
  1778. continue;
  1779. }
  1780. if (connection_remap.has(E->get().from_node) && connection_remap.has(E->get().to_node)) {
  1781. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, connection_remap[E->get().from_node], E->get().from_port, connection_remap[E->get().to_node], E->get().to_port);
  1782. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, connection_remap[E->get().from_node], E->get().from_port, connection_remap[E->get().to_node], E->get().to_port);
  1783. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, connection_remap[E->get().from_node], E->get().from_port, connection_remap[E->get().to_node], E->get().to_port);
  1784. }
  1785. }
  1786. id_from = base_id;
  1787. for (List<int>::Element *E = r_nodes.front(); E; E = E->next()) {
  1788. undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_from);
  1789. undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_from);
  1790. id_from++;
  1791. }
  1792. undo_redo->commit_action();
  1793. if (p_select) {
  1794. // reselect duplicated nodes by excluding the other ones
  1795. for (int i = 0; i < graph->get_child_count(); i++) {
  1796. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  1797. if (gn) {
  1798. int id = String(gn->get_name()).to_int();
  1799. if (!r_excluded.has(id)) {
  1800. gn->set_selected(true);
  1801. } else {
  1802. gn->set_selected(false);
  1803. }
  1804. }
  1805. }
  1806. }
  1807. }
  1808. void VisualShaderEditor::_clear_buffer() {
  1809. copy_nodes_buffer.clear();
  1810. copy_nodes_excluded_buffer.clear();
  1811. }
  1812. void VisualShaderEditor::_duplicate_nodes() {
  1813. int type = edit_type->get_selected();
  1814. List<int> nodes;
  1815. Set<int> excluded;
  1816. _dup_copy_nodes(type, nodes, excluded);
  1817. if (nodes.empty()) {
  1818. return;
  1819. }
  1820. undo_redo->create_action(TTR("Duplicate Nodes"));
  1821. _dup_paste_nodes(type, type, nodes, excluded, Vector2(10, 10) * EDSCALE, true);
  1822. }
  1823. void VisualShaderEditor::_copy_nodes() {
  1824. copy_type = edit_type->get_selected();
  1825. _clear_buffer();
  1826. _dup_copy_nodes(copy_type, copy_nodes_buffer, copy_nodes_excluded_buffer);
  1827. }
  1828. void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2 &p_custom_position) {
  1829. if (copy_nodes_buffer.empty()) {
  1830. return;
  1831. }
  1832. int type = edit_type->get_selected();
  1833. undo_redo->create_action(TTR("Paste Nodes"));
  1834. float scale = graph->get_zoom();
  1835. Vector2 mpos;
  1836. if (p_use_custom_position) {
  1837. mpos = p_custom_position;
  1838. } else {
  1839. mpos = graph->get_local_mouse_position();
  1840. }
  1841. _dup_paste_nodes(type, copy_type, copy_nodes_buffer, copy_nodes_excluded_buffer, (graph->get_scroll_ofs() / scale + mpos / scale - selection_center), false);
  1842. _dup_update_excluded(type, copy_nodes_excluded_buffer); // to prevent selection of previous copies at new paste
  1843. }
  1844. void VisualShaderEditor::_delete_nodes() {
  1845. VisualShader::Type type = get_current_shader_type();
  1846. List<int> to_erase;
  1847. for (int i = 0; i < graph->get_child_count(); i++) {
  1848. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  1849. if (gn) {
  1850. if (gn->is_selected() && gn->is_close_button_visible()) {
  1851. to_erase.push_back(gn->get_name().operator String().to_int());
  1852. }
  1853. }
  1854. }
  1855. if (to_erase.empty()) {
  1856. return;
  1857. }
  1858. undo_redo->create_action(TTR("Delete Nodes"));
  1859. List<VisualShader::Connection> conns;
  1860. visual_shader->get_node_connections(type, &conns);
  1861. for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
  1862. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  1863. if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
  1864. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1865. }
  1866. }
  1867. }
  1868. for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
  1869. Ref<VisualShaderNode> node = visual_shader->get_node(type, F->get());
  1870. undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F->get());
  1871. undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F->get()), F->get());
  1872. undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F->get());
  1873. undo_redo->add_do_method(this, "_clear_buffer");
  1874. undo_redo->add_undo_method(this, "_clear_buffer");
  1875. // restore size, inputs and outputs if node is group
  1876. VisualShaderNodeGroupBase *group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
  1877. if (group) {
  1878. undo_redo->add_undo_method(group, "set_size", group->get_size());
  1879. undo_redo->add_undo_method(group, "set_inputs", group->get_inputs());
  1880. undo_redo->add_undo_method(group, "set_outputs", group->get_outputs());
  1881. }
  1882. // restore expression text if node is expression
  1883. VisualShaderNodeExpression *expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  1884. if (expression) {
  1885. undo_redo->add_undo_method(expression, "set_expression", expression->get_expression());
  1886. }
  1887. }
  1888. List<VisualShader::Connection> used_conns;
  1889. for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
  1890. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  1891. if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
  1892. bool cancel = false;
  1893. for (List<VisualShader::Connection>::Element *R = used_conns.front(); R; R = R->next()) {
  1894. if (R->get().from_node == E->get().from_node && R->get().from_port == E->get().from_port && R->get().to_node == E->get().to_node && R->get().to_port == E->get().to_port) {
  1895. cancel = true; // to avoid ERR_ALREADY_EXISTS warning
  1896. break;
  1897. }
  1898. }
  1899. if (!cancel) {
  1900. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1901. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1902. used_conns.push_back(E->get());
  1903. }
  1904. }
  1905. }
  1906. }
  1907. // delete nodes from the graph
  1908. for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
  1909. undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, F->get());
  1910. }
  1911. undo_redo->commit_action();
  1912. }
  1913. void VisualShaderEditor::_mode_selected(int p_id) {
  1914. visual_shader->set_shader_type(particles_mode ? VisualShader::Type(p_id + 3) : VisualShader::Type(p_id));
  1915. _update_options_menu();
  1916. _update_graph();
  1917. }
  1918. void VisualShaderEditor::_input_select_item(Ref<VisualShaderNodeInput> input, String name) {
  1919. String prev_name = input->get_input_name();
  1920. if (name == prev_name) {
  1921. return;
  1922. }
  1923. bool type_changed = input->get_input_type_by_name(name) != input->get_input_type_by_name(prev_name);
  1924. UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
  1925. undo_redo->create_action(TTR("Visual Shader Input Type Changed"));
  1926. undo_redo->add_do_method(input.ptr(), "set_input_name", name);
  1927. undo_redo->add_undo_method(input.ptr(), "set_input_name", prev_name);
  1928. if (type_changed) {
  1929. //restore connections if type changed
  1930. VisualShader::Type type = get_current_shader_type();
  1931. int id = visual_shader->find_node_id(type, input);
  1932. List<VisualShader::Connection> conns;
  1933. visual_shader->get_node_connections(type, &conns);
  1934. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  1935. if (E->get().from_node == id) {
  1936. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1937. }
  1938. }
  1939. }
  1940. undo_redo->add_do_method(VisualShaderEditor::get_singleton(), "_update_graph");
  1941. undo_redo->add_undo_method(VisualShaderEditor::get_singleton(), "_update_graph");
  1942. undo_redo->commit_action();
  1943. }
  1944. void VisualShaderEditor::_uniform_select_item(Ref<VisualShaderNodeUniformRef> p_uniform_ref, String p_name) {
  1945. String prev_name = p_uniform_ref->get_uniform_name();
  1946. if (p_name == prev_name) {
  1947. return;
  1948. }
  1949. bool type_changed = p_uniform_ref->get_uniform_type_by_name(p_name) != p_uniform_ref->get_uniform_type_by_name(prev_name);
  1950. UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
  1951. undo_redo->create_action(TTR("UniformRef Name Changed"));
  1952. undo_redo->add_do_method(p_uniform_ref.ptr(), "set_uniform_name", p_name);
  1953. undo_redo->add_undo_method(p_uniform_ref.ptr(), "set_uniform_name", prev_name);
  1954. if (type_changed) {
  1955. //restore connections if type changed
  1956. VisualShader::Type type = get_current_shader_type();
  1957. int id = visual_shader->find_node_id(type, p_uniform_ref);
  1958. List<VisualShader::Connection> conns;
  1959. visual_shader->get_node_connections(type, &conns);
  1960. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  1961. if (E->get().from_node == id) {
  1962. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1963. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1964. }
  1965. }
  1966. }
  1967. undo_redo->add_do_method(VisualShaderEditor::get_singleton(), "_update_graph");
  1968. undo_redo->add_undo_method(VisualShaderEditor::get_singleton(), "_update_graph");
  1969. undo_redo->commit_action();
  1970. }
  1971. void VisualShaderEditor::_member_filter_changed(const String &p_text) {
  1972. _update_options_menu();
  1973. }
  1974. void VisualShaderEditor::_member_selected() {
  1975. TreeItem *item = members->get_selected();
  1976. if (item != nullptr && item->has_meta("id")) {
  1977. members_dialog->get_ok()->set_disabled(false);
  1978. highend_label->set_visible(add_options[item->get_meta("id")].highend);
  1979. node_desc->set_text(_get_description(item->get_meta("id")));
  1980. } else {
  1981. highend_label->set_visible(false);
  1982. members_dialog->get_ok()->set_disabled(true);
  1983. node_desc->set_text("");
  1984. }
  1985. }
  1986. void VisualShaderEditor::_member_unselected() {
  1987. }
  1988. void VisualShaderEditor::_member_create() {
  1989. TreeItem *item = members->get_selected();
  1990. if (item != nullptr && item->has_meta("id")) {
  1991. int idx = members->get_selected()->get_meta("id");
  1992. _add_node(idx, add_options[idx].sub_func);
  1993. members_dialog->hide();
  1994. }
  1995. }
  1996. void VisualShaderEditor::_member_cancel() {
  1997. to_node = -1;
  1998. to_slot = -1;
  1999. from_node = -1;
  2000. from_slot = -1;
  2001. }
  2002. void VisualShaderEditor::_tools_menu_option(int p_idx) {
  2003. TreeItem *category = members->get_root()->get_children();
  2004. switch (p_idx) {
  2005. case EXPAND_ALL:
  2006. while (category) {
  2007. category->set_collapsed(false);
  2008. TreeItem *sub_category = category->get_children();
  2009. while (sub_category) {
  2010. sub_category->set_collapsed(false);
  2011. sub_category = sub_category->get_next();
  2012. }
  2013. category = category->get_next();
  2014. }
  2015. break;
  2016. case COLLAPSE_ALL:
  2017. while (category) {
  2018. category->set_collapsed(true);
  2019. TreeItem *sub_category = category->get_children();
  2020. while (sub_category) {
  2021. sub_category->set_collapsed(true);
  2022. sub_category = sub_category->get_next();
  2023. }
  2024. category = category->get_next();
  2025. }
  2026. break;
  2027. default:
  2028. break;
  2029. }
  2030. }
  2031. void VisualShaderEditor::_node_menu_id_pressed(int p_idx) {
  2032. switch (p_idx) {
  2033. case NodeMenuOptions::ADD:
  2034. _show_members_dialog(true);
  2035. break;
  2036. case NodeMenuOptions::COPY:
  2037. _copy_nodes();
  2038. break;
  2039. case NodeMenuOptions::PASTE:
  2040. _paste_nodes(true, menu_point);
  2041. break;
  2042. case NodeMenuOptions::DELETE:
  2043. _delete_nodes();
  2044. break;
  2045. case NodeMenuOptions::DUPLICATE:
  2046. _duplicate_nodes();
  2047. break;
  2048. }
  2049. }
  2050. Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  2051. if (p_from == members) {
  2052. TreeItem *it = members->get_item_at_position(p_point);
  2053. if (!it) {
  2054. return Variant();
  2055. }
  2056. if (!it->has_meta("id")) {
  2057. return Variant();
  2058. }
  2059. int id = it->get_meta("id");
  2060. AddOption op = add_options[id];
  2061. Dictionary d;
  2062. d["id"] = id;
  2063. if (op.sub_func == -1) {
  2064. d["sub_func"] = op.sub_func_str;
  2065. } else {
  2066. d["sub_func"] = op.sub_func;
  2067. }
  2068. Label *label = memnew(Label);
  2069. label->set_text(it->get_text(0));
  2070. set_drag_preview(label);
  2071. return d;
  2072. }
  2073. return Variant();
  2074. }
  2075. bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  2076. if (p_from == graph) {
  2077. Dictionary d = p_data;
  2078. if (d.has("id")) {
  2079. return true;
  2080. }
  2081. if (d.has("files")) {
  2082. return true;
  2083. }
  2084. }
  2085. return false;
  2086. }
  2087. void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  2088. if (p_from == graph) {
  2089. Dictionary d = p_data;
  2090. if (d.has("id")) {
  2091. int idx = d["id"];
  2092. saved_node_pos = p_point;
  2093. saved_node_pos_dirty = true;
  2094. _add_node(idx, add_options[idx].sub_func);
  2095. } else if (d.has("files")) {
  2096. if (d["files"].get_type() == Variant::PACKED_STRING_ARRAY) {
  2097. int j = 0;
  2098. PackedStringArray arr = d["files"];
  2099. for (int i = 0; i < arr.size(); i++) {
  2100. String type = ResourceLoader::get_resource_type(arr[i]);
  2101. if (type == "GDScript") {
  2102. Ref<Script> script = ResourceLoader::load(arr[i]);
  2103. if (script->get_instance_base_type() == "VisualShaderNodeCustom") {
  2104. saved_node_pos = p_point + Vector2(0, j * 210 * EDSCALE);
  2105. saved_node_pos_dirty = true;
  2106. _add_custom_node(arr[i]);
  2107. j++;
  2108. }
  2109. } else if (ClassDB::get_parent_class(type) == "Texture2D") {
  2110. saved_node_pos = p_point + Vector2(0, j * 210 * EDSCALE);
  2111. saved_node_pos_dirty = true;
  2112. _add_texture_node(arr[i]);
  2113. j++;
  2114. }
  2115. }
  2116. }
  2117. }
  2118. }
  2119. }
  2120. void VisualShaderEditor::_show_preview_text() {
  2121. preview_showed = !preview_showed;
  2122. preview_vbox->set_visible(preview_showed);
  2123. if (preview_showed) {
  2124. if (pending_update_preview) {
  2125. _update_preview();
  2126. pending_update_preview = false;
  2127. }
  2128. }
  2129. }
  2130. static ShaderLanguage::DataType _get_global_variable_type(const StringName &p_variable) {
  2131. RS::GlobalVariableType gvt = RS::get_singleton()->global_variable_get_type(p_variable);
  2132. return RS::global_variable_type_get_shader_datatype(gvt);
  2133. }
  2134. void VisualShaderEditor::_update_preview() {
  2135. if (!preview_showed) {
  2136. pending_update_preview = true;
  2137. return;
  2138. }
  2139. String code = visual_shader->get_code();
  2140. preview_text->set_text(code);
  2141. ShaderLanguage sl;
  2142. Error err = sl.compile(code, ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(visual_shader->get_mode())), ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(visual_shader->get_mode())), ShaderTypes::get_singleton()->get_types(), _get_global_variable_type);
  2143. for (int i = 0; i < preview_text->get_line_count(); i++) {
  2144. preview_text->set_line_as_marked(i, false);
  2145. }
  2146. if (err != OK) {
  2147. preview_text->set_line_as_marked(sl.get_error_line() - 1, true);
  2148. error_text->set_visible(true);
  2149. String text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text();
  2150. error_text->set_text(text);
  2151. shader_error = true;
  2152. } else {
  2153. error_text->set_visible(false);
  2154. shader_error = false;
  2155. }
  2156. }
  2157. void VisualShaderEditor::_bind_methods() {
  2158. ClassDB::bind_method("_rebuild", &VisualShaderEditor::_rebuild);
  2159. ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph);
  2160. ClassDB::bind_method("_update_options_menu", &VisualShaderEditor::_update_options_menu);
  2161. ClassDB::bind_method("_add_node", &VisualShaderEditor::_add_node);
  2162. ClassDB::bind_method("_node_changed", &VisualShaderEditor::_node_changed);
  2163. ClassDB::bind_method("_input_select_item", &VisualShaderEditor::_input_select_item);
  2164. ClassDB::bind_method("_uniform_select_item", &VisualShaderEditor::_uniform_select_item);
  2165. ClassDB::bind_method("_set_node_size", &VisualShaderEditor::_set_node_size);
  2166. ClassDB::bind_method("_clear_buffer", &VisualShaderEditor::_clear_buffer);
  2167. ClassDB::bind_method("_update_uniforms", &VisualShaderEditor::_update_uniforms);
  2168. ClassDB::bind_method("_set_mode", &VisualShaderEditor::_set_mode);
  2169. ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &VisualShaderEditor::get_drag_data_fw);
  2170. ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &VisualShaderEditor::can_drop_data_fw);
  2171. ClassDB::bind_method(D_METHOD("drop_data_fw"), &VisualShaderEditor::drop_data_fw);
  2172. ClassDB::bind_method("_is_available", &VisualShaderEditor::_is_available);
  2173. }
  2174. VisualShaderEditor *VisualShaderEditor::singleton = nullptr;
  2175. VisualShaderEditor::VisualShaderEditor() {
  2176. singleton = this;
  2177. updating = false;
  2178. saved_node_pos_dirty = false;
  2179. saved_node_pos = Point2(0, 0);
  2180. ShaderLanguage::get_keyword_list(&keyword_list);
  2181. preview_showed = false;
  2182. pending_update_preview = false;
  2183. shader_error = false;
  2184. to_node = -1;
  2185. to_slot = -1;
  2186. from_node = -1;
  2187. from_slot = -1;
  2188. main_box = memnew(HSplitContainer);
  2189. main_box->set_v_size_flags(SIZE_EXPAND_FILL);
  2190. main_box->set_h_size_flags(SIZE_EXPAND_FILL);
  2191. add_child(main_box);
  2192. graph = memnew(GraphEdit);
  2193. graph->get_zoom_hbox()->set_h_size_flags(SIZE_EXPAND_FILL);
  2194. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  2195. graph->set_h_size_flags(SIZE_EXPAND_FILL);
  2196. main_box->add_child(graph);
  2197. graph->set_drag_forwarding(this);
  2198. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR);
  2199. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_INT);
  2200. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN);
  2201. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR);
  2202. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_TRANSFORM);
  2203. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SAMPLER);
  2204. //graph->add_valid_left_disconnect_type(0);
  2205. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  2206. graph->connect("connection_request", callable_mp(this, &VisualShaderEditor::_connection_request), varray(), CONNECT_DEFERRED);
  2207. graph->connect("disconnection_request", callable_mp(this, &VisualShaderEditor::_disconnection_request), varray(), CONNECT_DEFERRED);
  2208. graph->connect("node_selected", callable_mp(this, &VisualShaderEditor::_node_selected));
  2209. graph->connect("scroll_offset_changed", callable_mp(this, &VisualShaderEditor::_scroll_changed));
  2210. graph->connect("duplicate_nodes_request", callable_mp(this, &VisualShaderEditor::_duplicate_nodes));
  2211. graph->connect("copy_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes));
  2212. graph->connect("paste_nodes_request", callable_mp(this, &VisualShaderEditor::_paste_nodes));
  2213. graph->connect("delete_nodes_request", callable_mp(this, &VisualShaderEditor::_delete_nodes));
  2214. graph->connect("gui_input", callable_mp(this, &VisualShaderEditor::_graph_gui_input));
  2215. graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty));
  2216. graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty));
  2217. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR);
  2218. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  2219. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR);
  2220. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_BOOLEAN);
  2221. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  2222. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR);
  2223. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR);
  2224. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_BOOLEAN);
  2225. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR, VisualShaderNode::PORT_TYPE_SCALAR);
  2226. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  2227. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR, VisualShaderNode::PORT_TYPE_VECTOR);
  2228. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR, VisualShaderNode::PORT_TYPE_BOOLEAN);
  2229. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR);
  2230. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  2231. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR);
  2232. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_BOOLEAN);
  2233. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShaderNode::PORT_TYPE_TRANSFORM);
  2234. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SAMPLER, VisualShaderNode::PORT_TYPE_SAMPLER);
  2235. VSeparator *vs = memnew(VSeparator);
  2236. graph->get_zoom_hbox()->add_child(vs);
  2237. graph->get_zoom_hbox()->move_child(vs, 0);
  2238. edit_type_standart = memnew(OptionButton);
  2239. edit_type_standart->add_item(TTR("Vertex"));
  2240. edit_type_standart->add_item(TTR("Fragment"));
  2241. edit_type_standart->add_item(TTR("Light"));
  2242. edit_type_standart->select(1);
  2243. edit_type_standart->connect("item_selected", callable_mp(this, &VisualShaderEditor::_mode_selected));
  2244. edit_type_particles = memnew(OptionButton);
  2245. edit_type_particles->add_item(TTR("Emit"));
  2246. edit_type_particles->add_item(TTR("Process"));
  2247. edit_type_particles->add_item(TTR("End"));
  2248. edit_type_particles->select(0);
  2249. edit_type_particles->connect("item_selected", callable_mp(this, &VisualShaderEditor::_mode_selected));
  2250. edit_type = edit_type_standart;
  2251. graph->get_zoom_hbox()->add_child(edit_type_particles);
  2252. graph->get_zoom_hbox()->move_child(edit_type_particles, 0);
  2253. graph->get_zoom_hbox()->add_child(edit_type_standart);
  2254. graph->get_zoom_hbox()->move_child(edit_type_standart, 0);
  2255. add_node = memnew(Button);
  2256. add_node->set_flat(true);
  2257. graph->get_zoom_hbox()->add_child(add_node);
  2258. add_node->set_text(TTR("Add Node..."));
  2259. graph->get_zoom_hbox()->move_child(add_node, 0);
  2260. add_node->connect("pressed", callable_mp(this, &VisualShaderEditor::_show_members_dialog), varray(false));
  2261. preview_shader = memnew(Button);
  2262. preview_shader->set_flat(true);
  2263. preview_shader->set_toggle_mode(true);
  2264. preview_shader->set_tooltip(TTR("Show resulted shader code."));
  2265. graph->get_zoom_hbox()->add_child(preview_shader);
  2266. preview_shader->connect("pressed", callable_mp(this, &VisualShaderEditor::_show_preview_text));
  2267. ///////////////////////////////////////
  2268. // PREVIEW PANEL
  2269. ///////////////////////////////////////
  2270. preview_vbox = memnew(VBoxContainer);
  2271. preview_vbox->set_visible(preview_showed);
  2272. main_box->add_child(preview_vbox);
  2273. preview_text = memnew(CodeEdit);
  2274. syntax_highlighter.instance();
  2275. preview_vbox->add_child(preview_text);
  2276. preview_text->set_h_size_flags(SIZE_EXPAND_FILL);
  2277. preview_text->set_v_size_flags(SIZE_EXPAND_FILL);
  2278. preview_text->set_custom_minimum_size(Size2(400 * EDSCALE, 0));
  2279. preview_text->set_syntax_highlighter(syntax_highlighter);
  2280. preview_text->set_draw_line_numbers(true);
  2281. preview_text->set_readonly(true);
  2282. error_text = memnew(Label);
  2283. preview_vbox->add_child(error_text);
  2284. error_text->set_visible(false);
  2285. ///////////////////////////////////////
  2286. // POPUP MENU
  2287. ///////////////////////////////////////
  2288. popup_menu = memnew(PopupMenu);
  2289. add_child(popup_menu);
  2290. popup_menu->add_item("Add Node", NodeMenuOptions::ADD);
  2291. popup_menu->add_separator();
  2292. popup_menu->add_item("Copy", NodeMenuOptions::COPY);
  2293. popup_menu->add_item("Paste", NodeMenuOptions::PASTE);
  2294. popup_menu->add_item("Delete", NodeMenuOptions::DELETE);
  2295. popup_menu->add_item("Duplicate", NodeMenuOptions::DUPLICATE);
  2296. popup_menu->connect("id_pressed", callable_mp(this, &VisualShaderEditor::_node_menu_id_pressed));
  2297. ///////////////////////////////////////
  2298. // SHADER NODES TREE
  2299. ///////////////////////////////////////
  2300. VBoxContainer *members_vb = memnew(VBoxContainer);
  2301. members_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  2302. HBoxContainer *filter_hb = memnew(HBoxContainer);
  2303. members_vb->add_child(filter_hb);
  2304. node_filter = memnew(LineEdit);
  2305. filter_hb->add_child(node_filter);
  2306. node_filter->connect("text_changed", callable_mp(this, &VisualShaderEditor::_member_filter_changed));
  2307. node_filter->connect("gui_input", callable_mp(this, &VisualShaderEditor::_sbox_input));
  2308. node_filter->set_h_size_flags(SIZE_EXPAND_FILL);
  2309. node_filter->set_placeholder(TTR("Search"));
  2310. tools = memnew(MenuButton);
  2311. filter_hb->add_child(tools);
  2312. tools->set_tooltip(TTR("Options"));
  2313. tools->get_popup()->connect("id_pressed", callable_mp(this, &VisualShaderEditor::_tools_menu_option));
  2314. tools->get_popup()->add_item(TTR("Expand All"), EXPAND_ALL);
  2315. tools->get_popup()->add_item(TTR("Collapse All"), COLLAPSE_ALL);
  2316. members = memnew(Tree);
  2317. members_vb->add_child(members);
  2318. members->set_drag_forwarding(this);
  2319. members->set_h_size_flags(SIZE_EXPAND_FILL);
  2320. members->set_v_size_flags(SIZE_EXPAND_FILL);
  2321. members->set_hide_root(true);
  2322. members->set_allow_reselect(true);
  2323. members->set_hide_folding(false);
  2324. members->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE));
  2325. members->connect("item_activated", callable_mp(this, &VisualShaderEditor::_member_create));
  2326. members->connect("item_selected", callable_mp(this, &VisualShaderEditor::_member_selected));
  2327. members->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_member_unselected));
  2328. HBoxContainer *desc_hbox = memnew(HBoxContainer);
  2329. members_vb->add_child(desc_hbox);
  2330. Label *desc_label = memnew(Label);
  2331. desc_hbox->add_child(desc_label);
  2332. desc_label->set_text(TTR("Description:"));
  2333. desc_hbox->add_spacer();
  2334. highend_label = memnew(Label);
  2335. desc_hbox->add_child(highend_label);
  2336. highend_label->set_visible(false);
  2337. highend_label->set_text("Vulkan");
  2338. highend_label->set_mouse_filter(Control::MOUSE_FILTER_STOP);
  2339. highend_label->set_tooltip(TTR("High-end node"));
  2340. node_desc = memnew(RichTextLabel);
  2341. members_vb->add_child(node_desc);
  2342. node_desc->set_h_size_flags(SIZE_EXPAND_FILL);
  2343. node_desc->set_v_size_flags(SIZE_FILL);
  2344. node_desc->set_custom_minimum_size(Size2(0, 70 * EDSCALE));
  2345. members_dialog = memnew(ConfirmationDialog);
  2346. members_dialog->set_title(TTR("Create Shader Node"));
  2347. members_dialog->set_exclusive(false);
  2348. members_dialog->add_child(members_vb);
  2349. members_dialog->get_ok()->set_text(TTR("Create"));
  2350. members_dialog->get_ok()->connect("pressed", callable_mp(this, &VisualShaderEditor::_member_create));
  2351. members_dialog->get_ok()->set_disabled(true);
  2352. members_dialog->connect("cancelled", callable_mp(this, &VisualShaderEditor::_member_cancel));
  2353. add_child(members_dialog);
  2354. alert = memnew(AcceptDialog);
  2355. alert->get_label()->set_autowrap(true);
  2356. alert->get_label()->set_align(Label::ALIGN_CENTER);
  2357. alert->get_label()->set_valign(Label::VALIGN_CENTER);
  2358. alert->get_label()->set_custom_minimum_size(Size2(400, 60) * EDSCALE);
  2359. add_child(alert);
  2360. ///////////////////////////////////////
  2361. // SHADER NODES TREE OPTIONS
  2362. ///////////////////////////////////////
  2363. // COLOR
  2364. add_options.push_back(AddOption("ColorFunc", "Color", "Common", "VisualShaderNodeColorFunc", TTR("Color function."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2365. add_options.push_back(AddOption("ColorOp", "Color", "Common", "VisualShaderNodeColorOp", TTR("Color operator."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2366. add_options.push_back(AddOption("Grayscale", "Color", "Functions", "VisualShaderNodeColorFunc", TTR("Grayscale function."), VisualShaderNodeColorFunc::FUNC_GRAYSCALE, VisualShaderNode::PORT_TYPE_VECTOR));
  2367. add_options.push_back(AddOption("HSV2RGB", "Color", "Functions", "VisualShaderNodeVectorFunc", TTR("Converts HSV vector to RGB equivalent."), VisualShaderNodeVectorFunc::FUNC_HSV2RGB, VisualShaderNode::PORT_TYPE_VECTOR));
  2368. add_options.push_back(AddOption("RGB2HSV", "Color", "Functions", "VisualShaderNodeVectorFunc", TTR("Converts RGB vector to HSV equivalent."), VisualShaderNodeVectorFunc::FUNC_RGB2HSV, VisualShaderNode::PORT_TYPE_VECTOR));
  2369. add_options.push_back(AddOption("Sepia", "Color", "Functions", "VisualShaderNodeColorFunc", TTR("Sepia function."), VisualShaderNodeColorFunc::FUNC_SEPIA, VisualShaderNode::PORT_TYPE_VECTOR));
  2370. add_options.push_back(AddOption("Burn", "Color", "Operators", "VisualShaderNodeColorOp", TTR("Burn operator."), VisualShaderNodeColorOp::OP_BURN, VisualShaderNode::PORT_TYPE_VECTOR));
  2371. add_options.push_back(AddOption("Darken", "Color", "Operators", "VisualShaderNodeColorOp", TTR("Darken operator."), VisualShaderNodeColorOp::OP_DARKEN, VisualShaderNode::PORT_TYPE_VECTOR));
  2372. add_options.push_back(AddOption("Difference", "Color", "Operators", "VisualShaderNodeColorOp", TTR("Difference operator."), VisualShaderNodeColorOp::OP_DIFFERENCE, VisualShaderNode::PORT_TYPE_VECTOR));
  2373. add_options.push_back(AddOption("Dodge", "Color", "Operators", "VisualShaderNodeColorOp", TTR("Dodge operator."), VisualShaderNodeColorOp::OP_DODGE, VisualShaderNode::PORT_TYPE_VECTOR));
  2374. add_options.push_back(AddOption("HardLight", "Color", "Operators", "VisualShaderNodeColorOp", TTR("HardLight operator."), VisualShaderNodeColorOp::OP_HARD_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR));
  2375. add_options.push_back(AddOption("Lighten", "Color", "Operators", "VisualShaderNodeColorOp", TTR("Lighten operator."), VisualShaderNodeColorOp::OP_LIGHTEN, VisualShaderNode::PORT_TYPE_VECTOR));
  2376. add_options.push_back(AddOption("Overlay", "Color", "Operators", "VisualShaderNodeColorOp", TTR("Overlay operator."), VisualShaderNodeColorOp::OP_OVERLAY, VisualShaderNode::PORT_TYPE_VECTOR));
  2377. add_options.push_back(AddOption("Screen", "Color", "Operators", "VisualShaderNodeColorOp", TTR("Screen operator."), VisualShaderNodeColorOp::OP_SCREEN, VisualShaderNode::PORT_TYPE_VECTOR));
  2378. add_options.push_back(AddOption("SoftLight", "Color", "Operators", "VisualShaderNodeColorOp", TTR("SoftLight operator."), VisualShaderNodeColorOp::OP_SOFT_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR));
  2379. add_options.push_back(AddOption("ColorConstant", "Color", "Variables", "VisualShaderNodeColorConstant", TTR("Color constant."), -1, -1));
  2380. add_options.push_back(AddOption("ColorUniform", "Color", "Variables", "VisualShaderNodeColorUniform", TTR("Color uniform."), -1, -1));
  2381. // CONDITIONAL
  2382. const String &compare_func_desc = TTR("Returns the boolean result of the %s comparison between two parameters.");
  2383. add_options.push_back(AddOption("Equal", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Equal (==)")), VisualShaderNodeCompare::FUNC_EQUAL, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2384. add_options.push_back(AddOption("GreaterThan", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Greater Than (>)")), VisualShaderNodeCompare::FUNC_GREATER_THAN, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2385. add_options.push_back(AddOption("GreaterThanEqual", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Greater Than or Equal (>=)")), VisualShaderNodeCompare::FUNC_GREATER_THAN_EQUAL, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2386. add_options.push_back(AddOption("If", "Conditional", "Functions", "VisualShaderNodeIf", TTR("Returns an associated vector if the provided scalars are equal, greater or less."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2387. add_options.push_back(AddOption("IsInf", "Conditional", "Functions", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between INF and a scalar parameter."), VisualShaderNodeIs::FUNC_IS_INF, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2388. add_options.push_back(AddOption("IsNaN", "Conditional", "Functions", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between NaN and a scalar parameter."), VisualShaderNodeIs::FUNC_IS_NAN, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2389. add_options.push_back(AddOption("LessThan", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than (<)")), VisualShaderNodeCompare::FUNC_LESS_THAN, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2390. add_options.push_back(AddOption("LessThanEqual", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than or Equal (<=)")), VisualShaderNodeCompare::FUNC_LESS_THAN_EQUAL, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2391. add_options.push_back(AddOption("NotEqual", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Not Equal (!=)")), VisualShaderNodeCompare::FUNC_NOT_EQUAL, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2392. add_options.push_back(AddOption("Switch", "Conditional", "Functions", "VisualShaderNodeSwitch", TTR("Returns an associated vector if the provided boolean value is true or false."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2393. add_options.push_back(AddOption("SwitchS", "Conditional", "Functions", "VisualShaderNodeScalarSwitch", TTR("Returns an associated scalar if the provided boolean value is true or false."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2394. add_options.push_back(AddOption("Compare", "Conditional", "Common", "VisualShaderNodeCompare", TTR("Returns the boolean result of the comparison between two parameters."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2395. add_options.push_back(AddOption("Is", "Conditional", "Common", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between INF (or NaN) and a scalar parameter."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2396. add_options.push_back(AddOption("BooleanConstant", "Conditional", "Variables", "VisualShaderNodeBooleanConstant", TTR("Boolean constant."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2397. add_options.push_back(AddOption("BooleanUniform", "Conditional", "Variables", "VisualShaderNodeBooleanUniform", TTR("Boolean uniform."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN));
  2398. // INPUT
  2399. // SPATIAL-FOR-ALL
  2400. const String input_param_shader_modes = TTR("'%s' input parameter for all shader modes.");
  2401. add_options.push_back(AddOption("Camera", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "camera"), "camera", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL));
  2402. add_options.push_back(AddOption("InvCamera", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "inv_camera"), "inv_camera", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL));
  2403. add_options.push_back(AddOption("InvProjection", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "inv_projection"), "inv_projection", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL));
  2404. add_options.push_back(AddOption("Normal", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "normal"), "normal", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_SPATIAL));
  2405. add_options.push_back(AddOption("OutputIsSRGB", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "output_is_srgb"), "output_is_srgb", VisualShaderNode::PORT_TYPE_BOOLEAN, -1, Shader::MODE_SPATIAL));
  2406. add_options.push_back(AddOption("Projection", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "camera"), "projection", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL));
  2407. add_options.push_back(AddOption("Time", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL));
  2408. add_options.push_back(AddOption("ViewportSize", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "viewport_size"), "viewport_size", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_SPATIAL));
  2409. add_options.push_back(AddOption("World", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "world"), "world", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL));
  2410. // CANVASITEM-FOR-ALL
  2411. add_options.push_back(AddOption("Alpha", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "alpha"), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_CANVAS_ITEM));
  2412. add_options.push_back(AddOption("Color", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_CANVAS_ITEM));
  2413. add_options.push_back(AddOption("TexturePixelSize", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "texture_pixel_size"), "texture_pixel_size", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_CANVAS_ITEM));
  2414. add_options.push_back(AddOption("Time", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_CANVAS_ITEM));
  2415. add_options.push_back(AddOption("UV", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "uv"), "uv", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_CANVAS_ITEM));
  2416. /////////////////
  2417. add_options.push_back(AddOption("Input", "Input", "Common", "VisualShaderNodeInput", TTR("Input parameter.")));
  2418. // SPATIAL INPUTS
  2419. const String input_param_for_vertex_and_fragment_shader_modes = TTR("'%s' input parameter for vertex and fragment shader modes.");
  2420. const String input_param_for_fragment_and_light_shader_modes = TTR("'%s' input parameter for fragment and light shader modes.");
  2421. const String input_param_for_fragment_shader_mode = TTR("'%s' input parameter for fragment shader mode.");
  2422. const String input_param_for_light_shader_mode = TTR("'%s' input parameter for light shader mode.");
  2423. const String input_param_for_vertex_shader_mode = TTR("'%s' input parameter for vertex shader mode.");
  2424. const String input_param_for_emit_shader_mode = TTR("'%s' input parameter for emit shader mode.");
  2425. const String input_param_for_process_shader_mode = TTR("'%s' input parameter for process shader mode.");
  2426. const String input_param_for_end_shader_mode = TTR("'%s' input parameter for end shader mode.");
  2427. const String input_param_for_emit_and_process_shader_mode = TTR("'%s' input parameter for emit and process shader mode.");
  2428. const String input_param_for_vertex_and_fragment_shader_mode = TTR("'%s' input parameter for vertex and fragment shader mode.");
  2429. add_options.push_back(AddOption("Alpha", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "alpha"), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2430. add_options.push_back(AddOption("Binormal", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "binormal"), "binormal", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2431. add_options.push_back(AddOption("Color", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2432. add_options.push_back(AddOption("DepthTexture", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "depth_texture"), "depth_texture", VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2433. add_options.push_back(AddOption("FragCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2434. add_options.push_back(AddOption("FrontFacing", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "front_facing"), "front_facing", VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2435. add_options.push_back(AddOption("PointCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "point_coord"), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2436. add_options.push_back(AddOption("ScreenTexture", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_texture"), "screen_texture", VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2437. add_options.push_back(AddOption("ScreenUV", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_uv"), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2438. add_options.push_back(AddOption("Side", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "side"), "side", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2439. add_options.push_back(AddOption("Tangent", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "tangent"), "tangent", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2440. add_options.push_back(AddOption("UV", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "uv"), "uv", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2441. add_options.push_back(AddOption("UV2", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "uv2"), "uv2", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2442. add_options.push_back(AddOption("Vertex", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "vertex"), "vertex", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2443. add_options.push_back(AddOption("View", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "view"), "view", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  2444. add_options.push_back(AddOption("Albedo", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "albedo"), "albedo", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2445. add_options.push_back(AddOption("Attenuation", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "attenuation"), "attenuation", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2446. add_options.push_back(AddOption("Diffuse", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "diffuse"), "diffuse", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2447. add_options.push_back(AddOption("FragCoord", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2448. add_options.push_back(AddOption("Light", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light"), "light", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2449. add_options.push_back(AddOption("LightColor", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_color"), "light_color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2450. add_options.push_back(AddOption("Roughness", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "roughness"), "roughness", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2451. add_options.push_back(AddOption("Specular", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "specular"), "specular", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2452. add_options.push_back(AddOption("Transmission", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "transmission"), "transmission", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2453. add_options.push_back(AddOption("View", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "view"), "view", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2454. add_options.push_back(AddOption("Alpha", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "alpha"), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  2455. add_options.push_back(AddOption("Binormal", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "binormal"), "binormal", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  2456. add_options.push_back(AddOption("Color", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  2457. add_options.push_back(AddOption("ModelView", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "modelview"), "modelview", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  2458. add_options.push_back(AddOption("PointSize", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "point_size"), "point_size", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  2459. add_options.push_back(AddOption("Tangent", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_mode, "tangent"), "tangent", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  2460. add_options.push_back(AddOption("UV", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "uv"), "uv", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  2461. add_options.push_back(AddOption("UV2", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "uv2"), "uv2", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  2462. add_options.push_back(AddOption("Vertex", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "vertex"), "vertex", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  2463. // CANVASITEM INPUTS
  2464. add_options.push_back(AddOption("FragCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  2465. add_options.push_back(AddOption("LightPass", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "light_pass"), "light_pass", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  2466. add_options.push_back(AddOption("NormalTexture", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "normal_texture"), "normal_texture", VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  2467. add_options.push_back(AddOption("PointCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "point_coord"), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  2468. add_options.push_back(AddOption("ScreenPixelSize", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_pixel_size"), "screen_pixel_size", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  2469. add_options.push_back(AddOption("ScreenTexture", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_texture"), "screen_texture", VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  2470. add_options.push_back(AddOption("ScreenUV", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "screen_uv"), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  2471. add_options.push_back(AddOption("Texture", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "texture"), "texture", VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  2472. add_options.push_back(AddOption("FragCoord", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2473. add_options.push_back(AddOption("LightAlpha", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_alpha"), "light_alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2474. add_options.push_back(AddOption("LightColor", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_color"), "light_color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2475. add_options.push_back(AddOption("LightHeight", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_height"), "light_height", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2476. add_options.push_back(AddOption("LightUV", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_uv"), "light_uv", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2477. add_options.push_back(AddOption("LightVector", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_vec"), "light_vec", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2478. add_options.push_back(AddOption("Normal", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "normal"), "normal", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2479. add_options.push_back(AddOption("PointCoord", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "point_coord"), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2480. add_options.push_back(AddOption("ScreenUV", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "screen_uv"), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2481. add_options.push_back(AddOption("ShadowAlpha", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "shadow_alpha"), "shadow_alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2482. add_options.push_back(AddOption("ShadowColor", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "shadow_color"), "shadow_color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2483. add_options.push_back(AddOption("ShadowVec", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "shadow_vec"), "shadow_vec", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2484. add_options.push_back(AddOption("Texture", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "texture"), "texture", VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  2485. add_options.push_back(AddOption("Extra", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "extra"), "extra", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  2486. add_options.push_back(AddOption("LightPass", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "light_pass"), "light_pass", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  2487. add_options.push_back(AddOption("PointSize", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "point_size"), "point_size", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  2488. add_options.push_back(AddOption("Projection", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "projection"), "projection", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  2489. add_options.push_back(AddOption("Vertex", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "vertex"), "vertex", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  2490. add_options.push_back(AddOption("World", "Input", "Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "world"), "world", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  2491. // PARTICLES INPUTS
  2492. add_options.push_back(AddOption("Active", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "active"), "active", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2493. add_options.push_back(AddOption("Alpha", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "alpha"), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2494. add_options.push_back(AddOption("Color", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2495. add_options.push_back(AddOption("Custom", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "custom"), "custom", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2496. add_options.push_back(AddOption("CustomAlpha", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "custom_alpha"), "custom_alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2497. add_options.push_back(AddOption("Delta", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "delta"), "delta", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2498. add_options.push_back(AddOption("EmissionTransform", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "emission_transform"), "emission_transform", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2499. add_options.push_back(AddOption("Index", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "index"), "index", VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2500. add_options.push_back(AddOption("LifeTime", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "lifetime"), "lifetime", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2501. add_options.push_back(AddOption("Restart", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "restart"), "restart", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2502. add_options.push_back(AddOption("Time", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2503. add_options.push_back(AddOption("Transform", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "transform"), "transform", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2504. add_options.push_back(AddOption("Velocity", "Input", "Emit", "VisualShaderNodeInput", vformat(input_param_shader_modes, "velocity"), "velocity", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  2505. add_options.push_back(AddOption("Active", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "active"), "active", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2506. add_options.push_back(AddOption("Alpha", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "alpha"), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2507. add_options.push_back(AddOption("Color", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2508. add_options.push_back(AddOption("Custom", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "custom"), "custom", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2509. add_options.push_back(AddOption("CustomAlpha", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "custom_alpha"), "custom_alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2510. add_options.push_back(AddOption("Delta", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "delta"), "delta", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2511. add_options.push_back(AddOption("EmissionTransform", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "emission_transform"), "emission_transform", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2512. add_options.push_back(AddOption("Index", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "index"), "index", VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2513. add_options.push_back(AddOption("LifeTime", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "lifetime"), "lifetime", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2514. add_options.push_back(AddOption("Restart", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "restart"), "restart", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2515. add_options.push_back(AddOption("Time", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2516. add_options.push_back(AddOption("Transform", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "transform"), "transform", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2517. add_options.push_back(AddOption("Velocity", "Input", "Process", "VisualShaderNodeInput", vformat(input_param_shader_modes, "velocity"), "velocity", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  2518. add_options.push_back(AddOption("Active", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "active"), "active", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2519. add_options.push_back(AddOption("Alpha", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "alpha"), "alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2520. add_options.push_back(AddOption("Color", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2521. add_options.push_back(AddOption("Custom", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "custom"), "custom", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2522. add_options.push_back(AddOption("CustomAlpha", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "custom_alpha"), "custom_alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2523. add_options.push_back(AddOption("Delta", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "delta"), "delta", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2524. add_options.push_back(AddOption("EmissionTransform", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "emission_transform"), "emission_transform", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2525. add_options.push_back(AddOption("Index", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "index"), "index", VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2526. add_options.push_back(AddOption("LifeTime", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "lifetime"), "lifetime", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2527. add_options.push_back(AddOption("Restart", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "restart"), "restart", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2528. add_options.push_back(AddOption("Time", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2529. add_options.push_back(AddOption("Transform", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "transform"), "transform", VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2530. add_options.push_back(AddOption("Velocity", "Input", "End", "VisualShaderNodeInput", vformat(input_param_shader_modes, "velocity"), "velocity", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_END, Shader::MODE_PARTICLES));
  2531. // SKY INPUTS
  2532. add_options.push_back(AddOption("AtCubeMapPass", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "at_cubemap_pass"), "at_cubemap_pass", VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2533. add_options.push_back(AddOption("AtHalfResPass", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "at_half_res_pass"), "at_half_res_pass", VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2534. add_options.push_back(AddOption("AtQuarterResPass", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "at_quarter_res_pass"), "at_quarter_res_pass", VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2535. add_options.push_back(AddOption("EyeDir", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "eyedir"), "eyedir", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2536. add_options.push_back(AddOption("HalfResColor", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "half_res_color"), "half_res_color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2537. add_options.push_back(AddOption("HalfResAlpha", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "half_res_alpha"), "half_res_alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2538. add_options.push_back(AddOption("Light0Color", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light0_color"), "light0_color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2539. add_options.push_back(AddOption("Light0Direction", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light0_direction"), "light0_direction", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2540. add_options.push_back(AddOption("Light0Enabled", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light0_enabled"), "light0_enabled", VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2541. add_options.push_back(AddOption("Light0Energy", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light0_energy"), "light0_energy", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2542. add_options.push_back(AddOption("Light1Color", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light1_color"), "light1_color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2543. add_options.push_back(AddOption("Light1Direction", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light1_direction"), "light1_direction", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2544. add_options.push_back(AddOption("Light1Enabled", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light1_enabled"), "light1_enabled", VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2545. add_options.push_back(AddOption("Light1Energy", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light1_energy"), "light1_energy", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2546. add_options.push_back(AddOption("Light2Color", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light2_color"), "light2_color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2547. add_options.push_back(AddOption("Light2Direction", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light2_direction"), "light2_direction", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2548. add_options.push_back(AddOption("Light2Enabled", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light2_enabled"), "light2_enabled", VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2549. add_options.push_back(AddOption("Light2Energy", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light2_energy"), "light2_energy", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2550. add_options.push_back(AddOption("Light3Color", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light3_color"), "light3_color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2551. add_options.push_back(AddOption("Light3Direction", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light3_direction"), "light3_direction", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2552. add_options.push_back(AddOption("Light3Enabled", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light3_enabled"), "light3_enabled", VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2553. add_options.push_back(AddOption("Light3Energy", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "light3_energy"), "light3_energy", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2554. add_options.push_back(AddOption("Position", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "position"), "position", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2555. add_options.push_back(AddOption("QuarterResColor", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "quarter_res_color"), "quarter_res_color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2556. add_options.push_back(AddOption("QuarterResAlpha", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "quarter_res_alpha"), "quarter_res_alpha", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2557. add_options.push_back(AddOption("Radiance", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "radiance"), "radiance", VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2558. add_options.push_back(AddOption("ScreenUV", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_uv"), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2559. add_options.push_back(AddOption("SkyCoords", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "sky_coords"), "sky_coords", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2560. add_options.push_back(AddOption("Time", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SKY));
  2561. // SCALAR
  2562. add_options.push_back(AddOption("FloatFunc", "Scalar", "Common", "VisualShaderNodeFloatFunc", TTR("Float function."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2563. add_options.push_back(AddOption("IntFunc", "Scalar", "Common", "VisualShaderNodeIntFunc", TTR("Integer function."), -1, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2564. add_options.push_back(AddOption("FloatOp", "Scalar", "Common", "VisualShaderNodeFloatOp", TTR("Float operator."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2565. add_options.push_back(AddOption("IntOp", "Scalar", "Common", "VisualShaderNodeIntOp", TTR("Integer operator."), -1, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2566. //CONSTANTS
  2567. add_options.push_back(AddOption("E", "Scalar", "Constants", "VisualShaderNodeFloatConstant", TTR("E constant (2.718282). Represents the base of the natural logarithm."), -1, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, Math_E));
  2568. add_options.push_back(AddOption("Epsilon", "Scalar", "Constants", "VisualShaderNodeFloatConstant", TTR("Epsilon constant (0.00001). Smallest possible scalar number."), -1, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, CMP_EPSILON));
  2569. add_options.push_back(AddOption("Phi", "Scalar", "Constants", "VisualShaderNodeFloatConstant", TTR("Phi constant (1.618034). Golden ratio."), -1, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, 1.618034f));
  2570. add_options.push_back(AddOption("Pi/4", "Scalar", "Constants", "VisualShaderNodeFloatConstant", TTR("Pi/4 constant (0.785398) or 45 degrees."), -1, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, Math_PI / 4));
  2571. add_options.push_back(AddOption("Pi/2", "Scalar", "Constants", "VisualShaderNodeFloatConstant", TTR("Pi/2 constant (1.570796) or 90 degrees."), -1, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, Math_PI / 2));
  2572. add_options.push_back(AddOption("Pi", "Scalar", "Constants", "VisualShaderNodeFloatConstant", TTR("Pi constant (3.141593) or 180 degrees."), -1, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, Math_PI));
  2573. add_options.push_back(AddOption("Tau", "Scalar", "Constants", "VisualShaderNodeFloatConstant", TTR("Tau constant (6.283185) or 360 degrees."), -1, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, Math_TAU));
  2574. add_options.push_back(AddOption("Sqrt2", "Scalar", "Constants", "VisualShaderNodeFloatConstant", TTR("Sqrt2 constant (1.414214). Square root of 2."), -1, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, Math_SQRT2));
  2575. // FUNCTIONS
  2576. add_options.push_back(AddOption("Abs", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the absolute value of the parameter."), VisualShaderNodeFloatFunc::FUNC_ABS, VisualShaderNode::PORT_TYPE_SCALAR));
  2577. add_options.push_back(AddOption("Abs", "Scalar", "Functions", "VisualShaderNodeIntFunc", TTR("Returns the absolute value of the parameter."), VisualShaderNodeIntFunc::FUNC_ABS, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2578. add_options.push_back(AddOption("ACos", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-cosine of the parameter."), VisualShaderNodeFloatFunc::FUNC_ACOS, VisualShaderNode::PORT_TYPE_SCALAR));
  2579. add_options.push_back(AddOption("ACosH", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), VisualShaderNodeFloatFunc::FUNC_ACOSH, VisualShaderNode::PORT_TYPE_SCALAR));
  2580. add_options.push_back(AddOption("ASin", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-sine of the parameter."), VisualShaderNodeFloatFunc::FUNC_ASIN, VisualShaderNode::PORT_TYPE_SCALAR));
  2581. add_options.push_back(AddOption("ASinH", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), VisualShaderNodeFloatFunc::FUNC_ASINH, VisualShaderNode::PORT_TYPE_SCALAR));
  2582. add_options.push_back(AddOption("ATan", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-tangent of the parameter."), VisualShaderNodeFloatFunc::FUNC_ATAN, VisualShaderNode::PORT_TYPE_SCALAR));
  2583. add_options.push_back(AddOption("ATan2", "Scalar", "Functions", "VisualShaderNodeFloatOp", TTR("Returns the arc-tangent of the parameters."), VisualShaderNodeFloatOp::OP_ATAN2, VisualShaderNode::PORT_TYPE_SCALAR));
  2584. add_options.push_back(AddOption("ATanH", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), VisualShaderNodeFloatFunc::FUNC_ATANH, VisualShaderNode::PORT_TYPE_SCALAR));
  2585. add_options.push_back(AddOption("Ceil", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer that is greater than or equal to the parameter."), VisualShaderNodeFloatFunc::FUNC_CEIL, VisualShaderNode::PORT_TYPE_SCALAR));
  2586. add_options.push_back(AddOption("Clamp", "Scalar", "Functions", "VisualShaderNodeScalarClamp", TTR("Constrains a value to lie between two further values."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2587. add_options.push_back(AddOption("Clamp", "Scalar", "Functions", "VisualShaderNodeIntFunc", TTR("Constrains a value to lie between two further values."), VisualShaderNodeIntFunc::FUNC_CLAMP, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2588. add_options.push_back(AddOption("Cos", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the cosine of the parameter."), VisualShaderNodeFloatFunc::FUNC_COS, VisualShaderNode::PORT_TYPE_SCALAR));
  2589. add_options.push_back(AddOption("CosH", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic cosine of the parameter."), VisualShaderNodeFloatFunc::FUNC_COSH, VisualShaderNode::PORT_TYPE_SCALAR));
  2590. add_options.push_back(AddOption("Degrees", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in radians to degrees."), VisualShaderNodeFloatFunc::FUNC_DEGREES, VisualShaderNode::PORT_TYPE_SCALAR));
  2591. add_options.push_back(AddOption("Exp", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Base-e Exponential."), VisualShaderNodeFloatFunc::FUNC_EXP, VisualShaderNode::PORT_TYPE_SCALAR));
  2592. add_options.push_back(AddOption("Exp2", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 Exponential."), VisualShaderNodeFloatFunc::FUNC_EXP2, VisualShaderNode::PORT_TYPE_SCALAR));
  2593. add_options.push_back(AddOption("Floor", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer less than or equal to the parameter."), VisualShaderNodeFloatFunc::FUNC_FLOOR, VisualShaderNode::PORT_TYPE_SCALAR));
  2594. add_options.push_back(AddOption("Fract", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Computes the fractional part of the argument."), VisualShaderNodeFloatFunc::FUNC_FRAC, VisualShaderNode::PORT_TYPE_SCALAR));
  2595. add_options.push_back(AddOption("InverseSqrt", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the inverse of the square root of the parameter."), VisualShaderNodeFloatFunc::FUNC_INVERSE_SQRT, VisualShaderNode::PORT_TYPE_SCALAR));
  2596. add_options.push_back(AddOption("Log", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Natural logarithm."), VisualShaderNodeFloatFunc::FUNC_LOG, VisualShaderNode::PORT_TYPE_SCALAR));
  2597. add_options.push_back(AddOption("Log2", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 logarithm."), VisualShaderNodeFloatFunc::FUNC_LOG2, VisualShaderNode::PORT_TYPE_SCALAR));
  2598. add_options.push_back(AddOption("Max", "Scalar", "Functions", "VisualShaderNodeFloatOp", TTR("Returns the greater of two values."), VisualShaderNodeFloatOp::OP_MAX, VisualShaderNode::PORT_TYPE_SCALAR));
  2599. add_options.push_back(AddOption("Min", "Scalar", "Functions", "VisualShaderNodeFloatOp", TTR("Returns the lesser of two values."), VisualShaderNodeFloatOp::OP_MIN, VisualShaderNode::PORT_TYPE_SCALAR));
  2600. add_options.push_back(AddOption("Mix", "Scalar", "Functions", "VisualShaderNodeScalarInterp", TTR("Linear interpolation between two scalars."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2601. add_options.push_back(AddOption("MultiplyAdd", "Scalar", "Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on scalars."), VisualShaderNodeMultiplyAdd::TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR));
  2602. add_options.push_back(AddOption("Negate", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the opposite value of the parameter."), VisualShaderNodeFloatFunc::FUNC_NEGATE, VisualShaderNode::PORT_TYPE_SCALAR));
  2603. add_options.push_back(AddOption("Negate", "Scalar", "Functions", "VisualShaderNodeIntFunc", TTR("Returns the opposite value of the parameter."), VisualShaderNodeIntFunc::FUNC_NEGATE, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2604. add_options.push_back(AddOption("OneMinus", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("1.0 - scalar"), VisualShaderNodeFloatFunc::FUNC_ONEMINUS, VisualShaderNode::PORT_TYPE_SCALAR));
  2605. add_options.push_back(AddOption("Pow", "Scalar", "Functions", "VisualShaderNodeFloatOp", TTR("Returns the value of the first parameter raised to the power of the second."), VisualShaderNodeFloatOp::OP_POW, VisualShaderNode::PORT_TYPE_SCALAR));
  2606. add_options.push_back(AddOption("Radians", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in degrees to radians."), VisualShaderNodeFloatFunc::FUNC_RADIANS, VisualShaderNode::PORT_TYPE_SCALAR));
  2607. add_options.push_back(AddOption("Reciprocal", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("1.0 / scalar"), VisualShaderNodeFloatFunc::FUNC_RECIPROCAL, VisualShaderNode::PORT_TYPE_SCALAR));
  2608. add_options.push_back(AddOption("Round", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer to the parameter."), VisualShaderNodeFloatFunc::FUNC_ROUND, VisualShaderNode::PORT_TYPE_SCALAR));
  2609. add_options.push_back(AddOption("RoundEven", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest even integer to the parameter."), VisualShaderNodeFloatFunc::FUNC_ROUNDEVEN, VisualShaderNode::PORT_TYPE_SCALAR));
  2610. add_options.push_back(AddOption("Saturate", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Clamps the value between 0.0 and 1.0."), VisualShaderNodeFloatFunc::FUNC_SATURATE, VisualShaderNode::PORT_TYPE_SCALAR));
  2611. add_options.push_back(AddOption("Sign", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Extracts the sign of the parameter."), VisualShaderNodeFloatFunc::FUNC_SIGN, VisualShaderNode::PORT_TYPE_SCALAR));
  2612. add_options.push_back(AddOption("Sign", "Scalar", "Functions", "VisualShaderNodeIntFunc", TTR("Extracts the sign of the parameter."), VisualShaderNodeIntFunc::FUNC_SIGN, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2613. add_options.push_back(AddOption("Sin", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the sine of the parameter."), VisualShaderNodeFloatFunc::FUNC_SIN, VisualShaderNode::PORT_TYPE_SCALAR));
  2614. add_options.push_back(AddOption("SinH", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic sine of the parameter."), VisualShaderNodeFloatFunc::FUNC_SINH, VisualShaderNode::PORT_TYPE_SCALAR));
  2615. add_options.push_back(AddOption("Sqrt", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the square root of the parameter."), VisualShaderNodeFloatFunc::FUNC_SQRT, VisualShaderNode::PORT_TYPE_SCALAR));
  2616. add_options.push_back(AddOption("SmoothStep", "Scalar", "Functions", "VisualShaderNodeScalarSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if x is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2617. add_options.push_back(AddOption("Step", "Scalar", "Functions", "VisualShaderNodeFloatOp", TTR("Step function( scalar(edge), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), VisualShaderNodeFloatOp::OP_STEP, VisualShaderNode::PORT_TYPE_SCALAR));
  2618. add_options.push_back(AddOption("Tan", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the tangent of the parameter."), VisualShaderNodeFloatFunc::FUNC_TAN, VisualShaderNode::PORT_TYPE_SCALAR));
  2619. add_options.push_back(AddOption("TanH", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic tangent of the parameter."), VisualShaderNodeFloatFunc::FUNC_TANH, VisualShaderNode::PORT_TYPE_SCALAR));
  2620. add_options.push_back(AddOption("Trunc", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Finds the truncated value of the parameter."), VisualShaderNodeFloatFunc::FUNC_TRUNC, VisualShaderNode::PORT_TYPE_SCALAR));
  2621. add_options.push_back(AddOption("Add", "Scalar", "Operators", "VisualShaderNodeFloatOp", TTR("Sums two floating-point scalars."), VisualShaderNodeFloatOp::OP_ADD, VisualShaderNode::PORT_TYPE_SCALAR));
  2622. add_options.push_back(AddOption("Add", "Scalar", "Operators", "VisualShaderNodeIntOp", TTR("Sums two integer scalars."), VisualShaderNodeIntOp::OP_ADD, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2623. add_options.push_back(AddOption("Divide", "Scalar", "Operators", "VisualShaderNodeFloatOp", TTR("Divides two floating-point scalars."), VisualShaderNodeFloatOp::OP_DIV, VisualShaderNode::PORT_TYPE_SCALAR));
  2624. add_options.push_back(AddOption("Divide", "Scalar", "Operators", "VisualShaderNodeIntOp", TTR("Divides two integer scalars."), VisualShaderNodeIntOp::OP_DIV, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2625. add_options.push_back(AddOption("Multiply", "Scalar", "Operators", "VisualShaderNodeFloatOp", TTR("Multiplies two floating-point scalars."), VisualShaderNodeFloatOp::OP_MUL, VisualShaderNode::PORT_TYPE_SCALAR));
  2626. add_options.push_back(AddOption("Multiply", "Scalar", "Operators", "VisualShaderNodeIntOp", TTR("Multiplies two integer scalars."), VisualShaderNodeIntOp::OP_MUL, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2627. add_options.push_back(AddOption("Remainder", "Scalar", "Operators", "VisualShaderNodeFloatOp", TTR("Returns the remainder of the two floating-point scalars."), VisualShaderNodeFloatOp::OP_MOD, VisualShaderNode::PORT_TYPE_SCALAR));
  2628. add_options.push_back(AddOption("Remainder", "Scalar", "Operators", "VisualShaderNodeIntOp", TTR("Returns the remainder of the two integer scalars."), VisualShaderNodeIntOp::OP_MOD, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2629. add_options.push_back(AddOption("Subtract", "Scalar", "Operators", "VisualShaderNodeFloatOp", TTR("Subtracts two floating-point scalars."), VisualShaderNodeFloatOp::OP_SUB, VisualShaderNode::PORT_TYPE_SCALAR));
  2630. add_options.push_back(AddOption("Subtract", "Scalar", "Operators", "VisualShaderNodeIntOp", TTR("Subtracts two integer scalars."), VisualShaderNodeIntOp::OP_SUB, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2631. add_options.push_back(AddOption("FloatConstant", "Scalar", "Variables", "VisualShaderNodeFloatConstant", TTR("Scalar floating-point constant."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2632. add_options.push_back(AddOption("IntConstant", "Scalar", "Variables", "VisualShaderNodeIntConstant", TTR("Scalar integer constant."), -1, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2633. add_options.push_back(AddOption("FloatUniform", "Scalar", "Variables", "VisualShaderNodeFloatUniform", TTR("Scalar floating-point uniform."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2634. add_options.push_back(AddOption("IntUniform", "Scalar", "Variables", "VisualShaderNodeIntUniform", TTR("Scalar integer uniform."), -1, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  2635. // TEXTURES
  2636. add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubemap", TTR("Perform the cubic texture lookup."), -1, -1));
  2637. texture_node_option_idx = add_options.size();
  2638. add_options.push_back(AddOption("Texture2D", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the 2D texture lookup."), -1, -1));
  2639. add_options.push_back(AddOption("Texture2DArray", "Textures", "Functions", "VisualShaderNodeTexture2DArray", TTR("Perform the 2D-array texture lookup."), -1, -1, -1, -1, -1));
  2640. add_options.push_back(AddOption("Texture3D", "Textures", "Functions", "VisualShaderNodeTexture3D", TTR("Perform the 3D texture lookup."), -1, -1));
  2641. add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubemapUniform", TTR("Cubic texture uniform lookup."), -1, -1));
  2642. add_options.push_back(AddOption("TextureUniform", "Textures", "Variables", "VisualShaderNodeTextureUniform", TTR("2D texture uniform lookup."), -1, -1));
  2643. add_options.push_back(AddOption("TextureUniformTriplanar", "Textures", "Variables", "VisualShaderNodeTextureUniformTriplanar", TTR("2D texture uniform lookup with triplanar."), -1, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  2644. add_options.push_back(AddOption("Texture2DArrayUniform", "Textures", "Variables", "VisualShaderNodeTexture2DArrayUniform", TTR("2D array of textures uniform lookup."), -1, -1, -1, -1, -1));
  2645. add_options.push_back(AddOption("Texture3DUniform", "Textures", "Variables", "VisualShaderNodeTexture3DUniform", TTR("3D texture uniform lookup."), -1, -1, -1, -1, -1));
  2646. // TRANSFORM
  2647. add_options.push_back(AddOption("TransformFunc", "Transform", "Common", "VisualShaderNodeTransformFunc", TTR("Transform function."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
  2648. add_options.push_back(AddOption("OuterProduct", "Transform", "Composition", "VisualShaderNodeOuterProduct", TTR("Calculate the outer product of a pair of vectors.\n\nOuterProduct treats the first parameter 'c' as a column vector (matrix with one column) and the second parameter 'r' as a row vector (matrix with one row) and does a linear algebraic matrix multiply 'c * r', yielding a matrix whose number of rows is the number of components in 'c' and whose number of columns is the number of components in 'r'."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
  2649. add_options.push_back(AddOption("TransformCompose", "Transform", "Composition", "VisualShaderNodeTransformCompose", TTR("Composes transform from four vectors."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
  2650. add_options.push_back(AddOption("TransformDecompose", "Transform", "Composition", "VisualShaderNodeTransformDecompose", TTR("Decomposes transform to four vectors.")));
  2651. add_options.push_back(AddOption("Determinant", "Transform", "Functions", "VisualShaderNodeDeterminant", TTR("Calculates the determinant of a transform."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2652. add_options.push_back(AddOption("Inverse", "Transform", "Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the inverse of a transform."), VisualShaderNodeTransformFunc::FUNC_INVERSE, VisualShaderNode::PORT_TYPE_TRANSFORM));
  2653. add_options.push_back(AddOption("Transpose", "Transform", "Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the transpose of a transform."), VisualShaderNodeTransformFunc::FUNC_TRANSPOSE, VisualShaderNode::PORT_TYPE_TRANSFORM));
  2654. add_options.push_back(AddOption("TransformMult", "Transform", "Operators", "VisualShaderNodeTransformMult", TTR("Multiplies transform by transform."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
  2655. add_options.push_back(AddOption("TransformVectorMult", "Transform", "Operators", "VisualShaderNodeTransformVecMult", TTR("Multiplies vector by transform."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2656. add_options.push_back(AddOption("TransformConstant", "Transform", "Variables", "VisualShaderNodeTransformConstant", TTR("Transform constant."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
  2657. add_options.push_back(AddOption("TransformUniform", "Transform", "Variables", "VisualShaderNodeTransformUniform", TTR("Transform uniform."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM));
  2658. // VECTOR
  2659. add_options.push_back(AddOption("VectorFunc", "Vector", "Common", "VisualShaderNodeVectorFunc", TTR("Vector function."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2660. add_options.push_back(AddOption("VectorOp", "Vector", "Common", "VisualShaderNodeVectorOp", TTR("Vector operator."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2661. add_options.push_back(AddOption("VectorCompose", "Vector", "Composition", "VisualShaderNodeVectorCompose", TTR("Composes vector from three scalars."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2662. add_options.push_back(AddOption("VectorDecompose", "Vector", "Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes vector to three scalars.")));
  2663. add_options.push_back(AddOption("Abs", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the absolute value of the parameter."), VisualShaderNodeVectorFunc::FUNC_ABS, VisualShaderNode::PORT_TYPE_VECTOR));
  2664. add_options.push_back(AddOption("ACos", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_ACOS, VisualShaderNode::PORT_TYPE_VECTOR));
  2665. add_options.push_back(AddOption("ACosH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_ACOSH, VisualShaderNode::PORT_TYPE_VECTOR));
  2666. add_options.push_back(AddOption("ASin", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_ASIN, VisualShaderNode::PORT_TYPE_VECTOR));
  2667. add_options.push_back(AddOption("ASinH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_ASINH, VisualShaderNode::PORT_TYPE_VECTOR));
  2668. add_options.push_back(AddOption("ATan", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_ATAN, VisualShaderNode::PORT_TYPE_VECTOR));
  2669. add_options.push_back(AddOption("ATan2", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the arc-tangent of the parameters."), VisualShaderNodeVectorOp::OP_ATAN2, VisualShaderNode::PORT_TYPE_VECTOR));
  2670. add_options.push_back(AddOption("ATanH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_ATANH, VisualShaderNode::PORT_TYPE_VECTOR));
  2671. add_options.push_back(AddOption("Ceil", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer that is greater than or equal to the parameter."), VisualShaderNodeVectorFunc::FUNC_CEIL, VisualShaderNode::PORT_TYPE_VECTOR));
  2672. add_options.push_back(AddOption("Clamp", "Vector", "Functions", "VisualShaderNodeVectorClamp", TTR("Constrains a value to lie between two further values."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2673. add_options.push_back(AddOption("Cos", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_COS, VisualShaderNode::PORT_TYPE_VECTOR));
  2674. add_options.push_back(AddOption("CosH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_COSH, VisualShaderNode::PORT_TYPE_VECTOR));
  2675. add_options.push_back(AddOption("Cross", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Calculates the cross product of two vectors."), VisualShaderNodeVectorOp::OP_CROSS, VisualShaderNode::PORT_TYPE_VECTOR));
  2676. add_options.push_back(AddOption("Degrees", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in radians to degrees."), VisualShaderNodeVectorFunc::FUNC_DEGREES, VisualShaderNode::PORT_TYPE_VECTOR));
  2677. add_options.push_back(AddOption("Distance", "Vector", "Functions", "VisualShaderNodeVectorDistance", TTR("Returns the distance between two points."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2678. add_options.push_back(AddOption("Dot", "Vector", "Functions", "VisualShaderNodeDotProduct", TTR("Calculates the dot product of two vectors."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2679. add_options.push_back(AddOption("Exp", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Base-e Exponential."), VisualShaderNodeVectorFunc::FUNC_EXP, VisualShaderNode::PORT_TYPE_VECTOR));
  2680. add_options.push_back(AddOption("Exp2", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 Exponential."), VisualShaderNodeVectorFunc::FUNC_EXP2, VisualShaderNode::PORT_TYPE_VECTOR));
  2681. add_options.push_back(AddOption("FaceForward", "Vector", "Functions", "VisualShaderNodeFaceForward", TTR("Returns the vector that points in the same direction as a reference vector. The function has three vector parameters : N, the vector to orient, I, the incident vector, and Nref, the reference vector. If the dot product of I and Nref is smaller than zero the return value is N. Otherwise -N is returned."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2682. add_options.push_back(AddOption("Floor", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer less than or equal to the parameter."), VisualShaderNodeVectorFunc::FUNC_FLOOR, VisualShaderNode::PORT_TYPE_VECTOR));
  2683. add_options.push_back(AddOption("Fract", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Computes the fractional part of the argument."), VisualShaderNodeVectorFunc::FUNC_FRAC, VisualShaderNode::PORT_TYPE_VECTOR));
  2684. add_options.push_back(AddOption("InverseSqrt", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse of the square root of the parameter."), VisualShaderNodeVectorFunc::FUNC_INVERSE_SQRT, VisualShaderNode::PORT_TYPE_VECTOR));
  2685. add_options.push_back(AddOption("Length", "Vector", "Functions", "VisualShaderNodeVectorLen", TTR("Calculates the length of a vector."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2686. add_options.push_back(AddOption("Log", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Natural logarithm."), VisualShaderNodeVectorFunc::FUNC_LOG, VisualShaderNode::PORT_TYPE_VECTOR));
  2687. add_options.push_back(AddOption("Log2", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 logarithm."), VisualShaderNodeVectorFunc::FUNC_LOG2, VisualShaderNode::PORT_TYPE_VECTOR));
  2688. add_options.push_back(AddOption("Max", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), VisualShaderNodeVectorOp::OP_MAX, VisualShaderNode::PORT_TYPE_VECTOR));
  2689. add_options.push_back(AddOption("Min", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), VisualShaderNodeVectorOp::OP_MIN, VisualShaderNode::PORT_TYPE_VECTOR));
  2690. add_options.push_back(AddOption("Mix", "Vector", "Functions", "VisualShaderNodeVectorInterp", TTR("Linear interpolation between two vectors."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2691. add_options.push_back(AddOption("MixS", "Vector", "Functions", "VisualShaderNodeVectorScalarMix", TTR("Linear interpolation between two vectors using scalar."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2692. add_options.push_back(AddOption("MultiplyAdd", "Vector", "Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on vectors."), VisualShaderNodeMultiplyAdd::TYPE_VECTOR, VisualShaderNode::PORT_TYPE_VECTOR));
  2693. add_options.push_back(AddOption("Negate", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNode::PORT_TYPE_VECTOR));
  2694. add_options.push_back(AddOption("Normalize", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNode::PORT_TYPE_VECTOR));
  2695. add_options.push_back(AddOption("OneMinus", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("1.0 - vector"), VisualShaderNodeVectorFunc::FUNC_ONEMINUS, VisualShaderNode::PORT_TYPE_VECTOR));
  2696. add_options.push_back(AddOption("Pow", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the value of the first parameter raised to the power of the second."), VisualShaderNodeVectorOp::OP_POW, VisualShaderNode::PORT_TYPE_VECTOR));
  2697. add_options.push_back(AddOption("Radians", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in degrees to radians."), VisualShaderNodeVectorFunc::FUNC_RADIANS, VisualShaderNode::PORT_TYPE_VECTOR));
  2698. add_options.push_back(AddOption("Reciprocal", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("1.0 / vector"), VisualShaderNodeVectorFunc::FUNC_RECIPROCAL, VisualShaderNode::PORT_TYPE_VECTOR));
  2699. add_options.push_back(AddOption("Reflect", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the vector that points in the direction of reflection ( a : incident vector, b : normal vector )."), VisualShaderNodeVectorOp::OP_REFLECT, VisualShaderNode::PORT_TYPE_VECTOR));
  2700. add_options.push_back(AddOption("Refract", "Vector", "Functions", "VisualShaderNodeVectorRefract", TTR("Returns the vector that points in the direction of refraction."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2701. add_options.push_back(AddOption("Round", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer to the parameter."), VisualShaderNodeVectorFunc::FUNC_ROUND, VisualShaderNode::PORT_TYPE_VECTOR));
  2702. add_options.push_back(AddOption("RoundEven", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest even integer to the parameter."), VisualShaderNodeVectorFunc::FUNC_ROUNDEVEN, VisualShaderNode::PORT_TYPE_VECTOR));
  2703. add_options.push_back(AddOption("Saturate", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Clamps the value between 0.0 and 1.0."), VisualShaderNodeVectorFunc::FUNC_SATURATE, VisualShaderNode::PORT_TYPE_VECTOR));
  2704. add_options.push_back(AddOption("Sign", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Extracts the sign of the parameter."), VisualShaderNodeVectorFunc::FUNC_SIGN, VisualShaderNode::PORT_TYPE_VECTOR));
  2705. add_options.push_back(AddOption("Sin", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_SIN, VisualShaderNode::PORT_TYPE_VECTOR));
  2706. add_options.push_back(AddOption("SinH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNode::PORT_TYPE_VECTOR));
  2707. add_options.push_back(AddOption("Sqrt", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the square root of the parameter."), VisualShaderNodeVectorFunc::FUNC_SQRT, VisualShaderNode::PORT_TYPE_VECTOR));
  2708. add_options.push_back(AddOption("SmoothStep", "Vector", "Functions", "VisualShaderNodeVectorSmoothStep", TTR("SmoothStep function( vector(edge0), vector(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2709. add_options.push_back(AddOption("SmoothStepS", "Vector", "Functions", "VisualShaderNodeVectorScalarSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2710. add_options.push_back(AddOption("Step", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Step function( vector(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), VisualShaderNodeVectorOp::OP_STEP, VisualShaderNode::PORT_TYPE_VECTOR));
  2711. add_options.push_back(AddOption("StepS", "Vector", "Functions", "VisualShaderNodeVectorScalarStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2712. add_options.push_back(AddOption("Tan", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_TAN, VisualShaderNode::PORT_TYPE_VECTOR));
  2713. add_options.push_back(AddOption("TanH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNode::PORT_TYPE_VECTOR));
  2714. add_options.push_back(AddOption("Trunc", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNode::PORT_TYPE_VECTOR));
  2715. add_options.push_back(AddOption("Add", "Vector", "Operators", "VisualShaderNodeVectorOp", TTR("Adds vector to vector."), VisualShaderNodeVectorOp::OP_ADD, VisualShaderNode::PORT_TYPE_VECTOR));
  2716. add_options.push_back(AddOption("Divide", "Vector", "Operators", "VisualShaderNodeVectorOp", TTR("Divides vector by vector."), VisualShaderNodeVectorOp::OP_DIV, VisualShaderNode::PORT_TYPE_VECTOR));
  2717. add_options.push_back(AddOption("Multiply", "Vector", "Operators", "VisualShaderNodeVectorOp", TTR("Multiplies vector by vector."), VisualShaderNodeVectorOp::OP_MUL, VisualShaderNode::PORT_TYPE_VECTOR));
  2718. add_options.push_back(AddOption("Remainder", "Vector", "Operators", "VisualShaderNodeVectorOp", TTR("Returns the remainder of the two vectors."), VisualShaderNodeVectorOp::OP_MOD, VisualShaderNode::PORT_TYPE_VECTOR));
  2719. add_options.push_back(AddOption("Subtract", "Vector", "Operators", "VisualShaderNodeVectorOp", TTR("Subtracts vector from vector."), VisualShaderNodeVectorOp::OP_SUB, VisualShaderNode::PORT_TYPE_VECTOR));
  2720. add_options.push_back(AddOption("VectorConstant", "Vector", "Variables", "VisualShaderNodeVec3Constant", TTR("Vector constant."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2721. add_options.push_back(AddOption("VectorUniform", "Vector", "Variables", "VisualShaderNodeVec3Uniform", TTR("Vector uniform."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
  2722. // SPECIAL
  2723. add_options.push_back(AddOption("Expression", "Special", "", "VisualShaderNodeExpression", TTR("Custom Godot Shader Language expression, with custom amount of input and output ports. This is a direct injection of code into the vertex/fragment/light function, do not use it to write the function declarations inside.")));
  2724. add_options.push_back(AddOption("Fresnel", "Special", "", "VisualShaderNodeFresnel", TTR("Returns falloff based on the dot product of surface normal and view direction of camera (pass associated inputs to it)."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
  2725. add_options.push_back(AddOption("GlobalExpression", "Special", "", "VisualShaderNodeGlobalExpression", TTR("Custom Godot Shader Language expression, which is placed on top of the resulted shader. You can place various function definitions inside and call it later in the Expressions. You can also declare varyings, uniforms and constants.")));
  2726. add_options.push_back(AddOption("UniformRef", "Special", "", "VisualShaderNodeUniformRef", TTR("A reference to an existing uniform.")));
  2727. add_options.push_back(AddOption("ScalarDerivativeFunc", "Special", "Common", "VisualShaderNodeScalarDerivativeFunc", TTR("(Fragment/Light mode only) Scalar derivative function."), -1, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, -1, true));
  2728. add_options.push_back(AddOption("VectorDerivativeFunc", "Special", "Common", "VisualShaderNodeVectorDerivativeFunc", TTR("(Fragment/Light mode only) Vector derivative function."), -1, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, -1, true));
  2729. add_options.push_back(AddOption("DdX", "Special", "Derivative", "VisualShaderNodeVectorDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'x' using local differencing."), VisualShaderNodeVectorDerivativeFunc::FUNC_X, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, -1, true));
  2730. add_options.push_back(AddOption("DdXS", "Special", "Derivative", "VisualShaderNodeScalarDerivativeFunc", TTR("(Fragment/Light mode only) (Scalar) Derivative in 'x' using local differencing."), VisualShaderNodeScalarDerivativeFunc::FUNC_X, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, -1, true));
  2731. add_options.push_back(AddOption("DdY", "Special", "Derivative", "VisualShaderNodeVectorDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'y' using local differencing."), VisualShaderNodeVectorDerivativeFunc::FUNC_Y, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, -1, true));
  2732. add_options.push_back(AddOption("DdYS", "Special", "Derivative", "VisualShaderNodeScalarDerivativeFunc", TTR("(Fragment/Light mode only) (Scalar) Derivative in 'y' using local differencing."), VisualShaderNodeScalarDerivativeFunc::FUNC_Y, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, -1, true));
  2733. add_options.push_back(AddOption("Sum", "Special", "Derivative", "VisualShaderNodeVectorDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Sum of absolute derivative in 'x' and 'y'."), VisualShaderNodeVectorDerivativeFunc::FUNC_SUM, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, -1, true));
  2734. add_options.push_back(AddOption("SumS", "Special", "Derivative", "VisualShaderNodeScalarDerivativeFunc", TTR("(Fragment/Light mode only) (Scalar) Sum of absolute derivative in 'x' and 'y'."), VisualShaderNodeScalarDerivativeFunc::FUNC_SUM, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, -1, true));
  2735. custom_node_option_idx = add_options.size();
  2736. /////////////////////////////////////////////////////////////////////
  2737. _update_options_menu();
  2738. error_panel = memnew(PanelContainer);
  2739. add_child(error_panel);
  2740. error_label = memnew(Label);
  2741. error_panel->add_child(error_label);
  2742. error_label->set_text("eh");
  2743. error_panel->hide();
  2744. undo_redo = EditorNode::get_singleton()->get_undo_redo();
  2745. Ref<VisualShaderNodePluginDefault> default_plugin;
  2746. default_plugin.instance();
  2747. add_plugin(default_plugin);
  2748. graph_plugin.instance();
  2749. property_editor = memnew(CustomPropertyEditor);
  2750. add_child(property_editor);
  2751. property_editor->connect("variant_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
  2752. }
  2753. /////////////////
  2754. void VisualShaderEditorPlugin::edit(Object *p_object) {
  2755. visual_shader_editor->edit(Object::cast_to<VisualShader>(p_object));
  2756. }
  2757. bool VisualShaderEditorPlugin::handles(Object *p_object) const {
  2758. return p_object->is_class("VisualShader");
  2759. }
  2760. void VisualShaderEditorPlugin::make_visible(bool p_visible) {
  2761. if (p_visible) {
  2762. //editor->hide_animation_player_editors();
  2763. //editor->animation_panel_make_visible(true);
  2764. button->show();
  2765. editor->make_bottom_panel_item_visible(visual_shader_editor);
  2766. visual_shader_editor->update_custom_nodes();
  2767. visual_shader_editor->set_process_input(true);
  2768. //visual_shader_editor->set_process(true);
  2769. } else {
  2770. if (visual_shader_editor->is_visible_in_tree()) {
  2771. editor->hide_bottom_panel();
  2772. }
  2773. button->hide();
  2774. visual_shader_editor->set_process_input(false);
  2775. //visual_shader_editor->set_process(false);
  2776. }
  2777. }
  2778. VisualShaderEditorPlugin::VisualShaderEditorPlugin(EditorNode *p_node) {
  2779. editor = p_node;
  2780. visual_shader_editor = memnew(VisualShaderEditor);
  2781. visual_shader_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE);
  2782. button = editor->add_bottom_panel_item(TTR("VisualShader"), visual_shader_editor);
  2783. button->hide();
  2784. }
  2785. VisualShaderEditorPlugin::~VisualShaderEditorPlugin() {
  2786. }
  2787. ////////////////
  2788. class VisualShaderNodePluginInputEditor : public OptionButton {
  2789. GDCLASS(VisualShaderNodePluginInputEditor, OptionButton);
  2790. Ref<VisualShaderNodeInput> input;
  2791. public:
  2792. void _notification(int p_what) {
  2793. if (p_what == NOTIFICATION_READY) {
  2794. connect("item_selected", callable_mp(this, &VisualShaderNodePluginInputEditor::_item_selected));
  2795. }
  2796. }
  2797. void _item_selected(int p_item) {
  2798. VisualShaderEditor::get_singleton()->call_deferred("_input_select_item", input, get_item_text(p_item));
  2799. }
  2800. void setup(const Ref<VisualShaderNodeInput> &p_input) {
  2801. input = p_input;
  2802. Ref<Texture2D> type_icon[6] = {
  2803. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("float", "EditorIcons"),
  2804. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("int", "EditorIcons"),
  2805. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Vector3", "EditorIcons"),
  2806. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("bool", "EditorIcons"),
  2807. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Transform", "EditorIcons"),
  2808. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("ImageTexture", "EditorIcons"),
  2809. };
  2810. add_item("[None]");
  2811. int to_select = -1;
  2812. for (int i = 0; i < input->get_input_index_count(); i++) {
  2813. if (input->get_input_name() == input->get_input_index_name(i)) {
  2814. to_select = i + 1;
  2815. }
  2816. add_icon_item(type_icon[input->get_input_index_type(i)], input->get_input_index_name(i));
  2817. }
  2818. if (to_select >= 0) {
  2819. select(to_select);
  2820. }
  2821. }
  2822. };
  2823. ////////////////
  2824. class VisualShaderNodePluginUniformRefEditor : public OptionButton {
  2825. GDCLASS(VisualShaderNodePluginUniformRefEditor, OptionButton);
  2826. Ref<VisualShaderNodeUniformRef> uniform_ref;
  2827. public:
  2828. void _notification(int p_what) {
  2829. if (p_what == NOTIFICATION_READY) {
  2830. connect("item_selected", callable_mp(this, &VisualShaderNodePluginUniformRefEditor::_item_selected));
  2831. }
  2832. }
  2833. void _item_selected(int p_item) {
  2834. VisualShaderEditor::get_singleton()->call_deferred("_uniform_select_item", uniform_ref, get_item_text(p_item));
  2835. }
  2836. void setup(const Ref<VisualShaderNodeUniformRef> &p_uniform_ref) {
  2837. uniform_ref = p_uniform_ref;
  2838. Ref<Texture2D> type_icon[7] = {
  2839. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("float", "EditorIcons"),
  2840. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("int", "EditorIcons"),
  2841. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("bool", "EditorIcons"),
  2842. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Vector3", "EditorIcons"),
  2843. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Transform", "EditorIcons"),
  2844. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Color", "EditorIcons"),
  2845. EditorNode::get_singleton()->get_gui_base()->get_theme_icon("ImageTexture", "EditorIcons"),
  2846. };
  2847. add_item("[None]");
  2848. int to_select = -1;
  2849. for (int i = 0; i < p_uniform_ref->get_uniforms_count(); i++) {
  2850. if (p_uniform_ref->get_uniform_name() == p_uniform_ref->get_uniform_name_by_index(i)) {
  2851. to_select = i + 1;
  2852. }
  2853. add_icon_item(type_icon[p_uniform_ref->get_uniform_type_by_index(i)], p_uniform_ref->get_uniform_name_by_index(i));
  2854. }
  2855. if (to_select >= 0) {
  2856. select(to_select);
  2857. }
  2858. }
  2859. };
  2860. ////////////////
  2861. class VisualShaderNodePluginDefaultEditor : public VBoxContainer {
  2862. GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer);
  2863. Ref<Resource> parent_resource;
  2864. int node_id;
  2865. VisualShader::Type shader_type;
  2866. public:
  2867. void _property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false) {
  2868. if (p_changing) {
  2869. return;
  2870. }
  2871. UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
  2872. updating = true;
  2873. undo_redo->create_action(TTR("Edit Visual Property") + ": " + p_property, UndoRedo::MERGE_ENDS);
  2874. undo_redo->add_do_property(node.ptr(), p_property, p_value);
  2875. undo_redo->add_undo_property(node.ptr(), p_property, node->get(p_property));
  2876. if (p_value.get_type() == Variant::OBJECT) {
  2877. RES prev_res = node->get(p_property);
  2878. RES curr_res = p_value;
  2879. if (curr_res.is_null()) {
  2880. undo_redo->add_do_method(this, "_open_inspector", (RES)parent_resource.ptr());
  2881. } else {
  2882. undo_redo->add_do_method(this, "_open_inspector", (RES)curr_res.ptr());
  2883. }
  2884. if (!prev_res.is_null()) {
  2885. undo_redo->add_undo_method(this, "_open_inspector", (RES)prev_res.ptr());
  2886. } else {
  2887. undo_redo->add_undo_method(this, "_open_inspector", (RES)parent_resource.ptr());
  2888. }
  2889. }
  2890. if (p_property != "constant") {
  2891. undo_redo->add_do_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_property_editor_deferred", shader_type, node_id);
  2892. undo_redo->add_undo_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_property_editor_deferred", shader_type, node_id);
  2893. }
  2894. undo_redo->commit_action();
  2895. updating = false;
  2896. }
  2897. void _node_changed() {
  2898. if (updating) {
  2899. return;
  2900. }
  2901. for (int i = 0; i < properties.size(); i++) {
  2902. properties[i]->update_property();
  2903. }
  2904. }
  2905. void _resource_selected(const String &p_path, RES p_resource) {
  2906. _open_inspector(p_resource);
  2907. }
  2908. void _open_inspector(RES p_resource) {
  2909. EditorNode::get_singleton()->get_inspector()->edit(p_resource.ptr());
  2910. }
  2911. bool updating;
  2912. Ref<VisualShaderNode> node;
  2913. Vector<EditorProperty *> properties;
  2914. Vector<Label *> prop_names;
  2915. void _show_prop_names(bool p_show) {
  2916. for (int i = 0; i < prop_names.size(); i++) {
  2917. prop_names[i]->set_visible(p_show);
  2918. }
  2919. }
  2920. void setup(Ref<Resource> p_parent_resource, Vector<EditorProperty *> p_properties, const Vector<StringName> &p_names, Ref<VisualShaderNode> p_node) {
  2921. parent_resource = p_parent_resource;
  2922. updating = false;
  2923. node = p_node;
  2924. properties = p_properties;
  2925. node_id = (int)p_node->get_meta("id");
  2926. shader_type = VisualShader::Type((int)p_node->get_meta("shader_type"));
  2927. for (int i = 0; i < p_properties.size(); i++) {
  2928. HBoxContainer *hbox = memnew(HBoxContainer);
  2929. hbox->set_h_size_flags(SIZE_EXPAND_FILL);
  2930. add_child(hbox);
  2931. Label *prop_name = memnew(Label);
  2932. String prop_name_str = p_names[i];
  2933. prop_name_str = prop_name_str.capitalize() + ":";
  2934. prop_name->set_text(prop_name_str);
  2935. prop_name->set_visible(false);
  2936. hbox->add_child(prop_name);
  2937. prop_names.push_back(prop_name);
  2938. p_properties[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2939. hbox->add_child(p_properties[i]);
  2940. bool res_prop = Object::cast_to<EditorPropertyResource>(p_properties[i]);
  2941. if (res_prop) {
  2942. p_properties[i]->connect("resource_selected", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_resource_selected));
  2943. }
  2944. properties[i]->connect("property_changed", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_property_changed));
  2945. properties[i]->set_object_and_property(node.ptr(), p_names[i]);
  2946. properties[i]->update_property();
  2947. properties[i]->set_name_split_ratio(0);
  2948. }
  2949. node->connect("changed", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_node_changed));
  2950. }
  2951. static void _bind_methods() {
  2952. ClassDB::bind_method("_open_inspector", &VisualShaderNodePluginDefaultEditor::_open_inspector); // Used by UndoRedo.
  2953. ClassDB::bind_method("_show_prop_names", &VisualShaderNodePluginDefaultEditor::_show_prop_names); // Used with call_deferred.
  2954. }
  2955. };
  2956. Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) {
  2957. if (p_node->is_class("VisualShaderNodeUniformRef")) {
  2958. //create input
  2959. VisualShaderNodePluginUniformRefEditor *uniform_editor = memnew(VisualShaderNodePluginUniformRefEditor);
  2960. uniform_editor->setup(p_node);
  2961. return uniform_editor;
  2962. }
  2963. if (p_node->is_class("VisualShaderNodeInput")) {
  2964. //create input
  2965. VisualShaderNodePluginInputEditor *input_editor = memnew(VisualShaderNodePluginInputEditor);
  2966. input_editor->setup(p_node);
  2967. return input_editor;
  2968. }
  2969. Vector<StringName> properties = p_node->get_editable_properties();
  2970. if (properties.size() == 0) {
  2971. return nullptr;
  2972. }
  2973. List<PropertyInfo> props;
  2974. p_node->get_property_list(&props);
  2975. Vector<PropertyInfo> pinfo;
  2976. for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
  2977. for (int i = 0; i < properties.size(); i++) {
  2978. if (E->get().name == String(properties[i])) {
  2979. pinfo.push_back(E->get());
  2980. }
  2981. }
  2982. }
  2983. if (pinfo.size() == 0) {
  2984. return nullptr;
  2985. }
  2986. properties.clear();
  2987. Ref<VisualShaderNode> node = p_node;
  2988. Vector<EditorProperty *> editors;
  2989. for (int i = 0; i < pinfo.size(); i++) {
  2990. EditorProperty *prop = EditorInspector::instantiate_property_editor(node.ptr(), pinfo[i].type, pinfo[i].name, pinfo[i].hint, pinfo[i].hint_string, pinfo[i].usage);
  2991. if (!prop) {
  2992. return nullptr;
  2993. }
  2994. if (Object::cast_to<EditorPropertyResource>(prop)) {
  2995. Object::cast_to<EditorPropertyResource>(prop)->set_use_sub_inspector(false);
  2996. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  2997. } else if (Object::cast_to<EditorPropertyTransform>(prop) || Object::cast_to<EditorPropertyVector3>(prop)) {
  2998. prop->set_custom_minimum_size(Size2(250 * EDSCALE, 0));
  2999. } else if (Object::cast_to<EditorPropertyFloat>(prop)) {
  3000. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  3001. } else if (Object::cast_to<EditorPropertyEnum>(prop)) {
  3002. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  3003. Object::cast_to<EditorPropertyEnum>(prop)->set_option_button_clip(false);
  3004. }
  3005. editors.push_back(prop);
  3006. properties.push_back(pinfo[i].name);
  3007. }
  3008. VisualShaderNodePluginDefaultEditor *editor = memnew(VisualShaderNodePluginDefaultEditor);
  3009. editor->setup(p_parent_resource, editors, properties, p_node);
  3010. return editor;
  3011. }
  3012. void EditorPropertyShaderMode::_option_selected(int p_which) {
  3013. //will not use this, instead will do all the logic setting manually
  3014. //emit_signal("property_changed", get_edited_property(), p_which);
  3015. Ref<VisualShader> visual_shader(Object::cast_to<VisualShader>(get_edited_object()));
  3016. if (visual_shader->get_mode() == p_which) {
  3017. return;
  3018. }
  3019. UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
  3020. undo_redo->create_action(TTR("Visual Shader Mode Changed"));
  3021. //do is easy
  3022. undo_redo->add_do_method(visual_shader.ptr(), "set_mode", p_which);
  3023. undo_redo->add_undo_method(visual_shader.ptr(), "set_mode", visual_shader->get_mode());
  3024. undo_redo->add_do_method(VisualShaderEditor::get_singleton(), "_set_mode", p_which);
  3025. undo_redo->add_undo_method(VisualShaderEditor::get_singleton(), "_set_mode", visual_shader->get_mode());
  3026. //now undo is hell
  3027. //1. restore connections to output
  3028. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  3029. VisualShader::Type type = VisualShader::Type(i);
  3030. List<VisualShader::Connection> conns;
  3031. visual_shader->get_node_connections(type, &conns);
  3032. for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
  3033. if (E->get().to_node == VisualShader::NODE_ID_OUTPUT) {
  3034. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  3035. }
  3036. }
  3037. }
  3038. //2. restore input indices
  3039. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  3040. VisualShader::Type type = VisualShader::Type(i);
  3041. Vector<int> nodes = visual_shader->get_node_list(type);
  3042. for (int j = 0; j < nodes.size(); j++) {
  3043. Ref<VisualShaderNodeInput> input = visual_shader->get_node(type, nodes[j]);
  3044. if (!input.is_valid()) {
  3045. continue;
  3046. }
  3047. undo_redo->add_undo_method(input.ptr(), "set_input_name", input->get_input_name());
  3048. }
  3049. }
  3050. //3. restore enums and flags
  3051. List<PropertyInfo> props;
  3052. visual_shader->get_property_list(&props);
  3053. for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
  3054. if (E->get().name.begins_with("flags/") || E->get().name.begins_with("modes/")) {
  3055. undo_redo->add_undo_property(visual_shader.ptr(), E->get().name, visual_shader->get(E->get().name));
  3056. }
  3057. }
  3058. undo_redo->add_do_method(VisualShaderEditor::get_singleton(), "_update_options_menu");
  3059. undo_redo->add_undo_method(VisualShaderEditor::get_singleton(), "_update_options_menu");
  3060. //update graph
  3061. undo_redo->add_do_method(VisualShaderEditor::get_singleton(), "_update_graph");
  3062. undo_redo->add_undo_method(VisualShaderEditor::get_singleton(), "_update_graph");
  3063. undo_redo->commit_action();
  3064. }
  3065. void EditorPropertyShaderMode::update_property() {
  3066. int which = get_edited_object()->get(get_edited_property());
  3067. options->select(which);
  3068. }
  3069. void EditorPropertyShaderMode::setup(const Vector<String> &p_options) {
  3070. for (int i = 0; i < p_options.size(); i++) {
  3071. options->add_item(p_options[i], i);
  3072. }
  3073. }
  3074. void EditorPropertyShaderMode::set_option_button_clip(bool p_enable) {
  3075. options->set_clip_text(p_enable);
  3076. }
  3077. void EditorPropertyShaderMode::_bind_methods() {
  3078. }
  3079. EditorPropertyShaderMode::EditorPropertyShaderMode() {
  3080. options = memnew(OptionButton);
  3081. options->set_clip_text(true);
  3082. add_child(options);
  3083. add_focusable(options);
  3084. options->connect("item_selected", callable_mp(this, &EditorPropertyShaderMode::_option_selected));
  3085. }
  3086. bool EditorInspectorShaderModePlugin::can_handle(Object *p_object) {
  3087. return true; //can handle everything
  3088. }
  3089. void EditorInspectorShaderModePlugin::parse_begin(Object *p_object) {
  3090. //do none
  3091. }
  3092. bool EditorInspectorShaderModePlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) {
  3093. if (p_path == "mode" && p_object->is_class("VisualShader") && p_type == Variant::INT) {
  3094. EditorPropertyShaderMode *editor = memnew(EditorPropertyShaderMode);
  3095. Vector<String> options = p_hint_text.split(",");
  3096. editor->setup(options);
  3097. add_property_editor(p_path, editor);
  3098. return true;
  3099. }
  3100. return false; //can be overridden, although it will most likely be last anyway
  3101. }
  3102. void EditorInspectorShaderModePlugin::parse_end() {
  3103. //do none
  3104. }
  3105. //////////////////////////////////
  3106. void VisualShaderNodePortPreview::_shader_changed() {
  3107. if (shader.is_null()) {
  3108. return;
  3109. }
  3110. Vector<VisualShader::DefaultTextureParam> default_textures;
  3111. String shader_code = shader->generate_preview_shader(type, node, port, default_textures);
  3112. Ref<Shader> preview_shader;
  3113. preview_shader.instance();
  3114. preview_shader->set_code(shader_code);
  3115. for (int i = 0; i < default_textures.size(); i++) {
  3116. preview_shader->set_default_texture_param(default_textures[i].name, default_textures[i].param);
  3117. }
  3118. Ref<ShaderMaterial> material;
  3119. material.instance();
  3120. material->set_shader(preview_shader);
  3121. //find if a material is also being edited and copy parameters to this one
  3122. for (int i = EditorNode::get_singleton()->get_editor_history()->get_path_size() - 1; i >= 0; i--) {
  3123. Object *object = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_history()->get_path_object(i));
  3124. if (!object) {
  3125. continue;
  3126. }
  3127. ShaderMaterial *src_mat = Object::cast_to<ShaderMaterial>(object);
  3128. if (src_mat && src_mat->get_shader().is_valid()) {
  3129. List<PropertyInfo> params;
  3130. src_mat->get_shader()->get_param_list(&params);
  3131. for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) {
  3132. material->set(E->get().name, src_mat->get(E->get().name));
  3133. }
  3134. }
  3135. }
  3136. set_material(material);
  3137. }
  3138. void VisualShaderNodePortPreview::setup(const Ref<VisualShader> &p_shader, VisualShader::Type p_type, int p_node, int p_port) {
  3139. shader = p_shader;
  3140. shader->connect("changed", callable_mp(this, &VisualShaderNodePortPreview::_shader_changed));
  3141. type = p_type;
  3142. port = p_port;
  3143. node = p_node;
  3144. update();
  3145. _shader_changed();
  3146. }
  3147. Size2 VisualShaderNodePortPreview::get_minimum_size() const {
  3148. return Size2(100, 100) * EDSCALE;
  3149. }
  3150. void VisualShaderNodePortPreview::_notification(int p_what) {
  3151. if (p_what == NOTIFICATION_DRAW) {
  3152. Vector<Vector2> points;
  3153. Vector<Vector2> uvs;
  3154. Vector<Color> colors;
  3155. points.push_back(Vector2());
  3156. uvs.push_back(Vector2(0, 0));
  3157. colors.push_back(Color(1, 1, 1, 1));
  3158. points.push_back(Vector2(get_size().width, 0));
  3159. uvs.push_back(Vector2(1, 0));
  3160. colors.push_back(Color(1, 1, 1, 1));
  3161. points.push_back(get_size());
  3162. uvs.push_back(Vector2(1, 1));
  3163. colors.push_back(Color(1, 1, 1, 1));
  3164. points.push_back(Vector2(0, get_size().height));
  3165. uvs.push_back(Vector2(0, 1));
  3166. colors.push_back(Color(1, 1, 1, 1));
  3167. draw_primitive(points, colors, uvs);
  3168. }
  3169. }
  3170. void VisualShaderNodePortPreview::_bind_methods() {
  3171. }
  3172. VisualShaderNodePortPreview::VisualShaderNodePortPreview() {
  3173. }
  3174. //////////////////////////////////
  3175. String VisualShaderConversionPlugin::converts_to() const {
  3176. return "Shader";
  3177. }
  3178. bool VisualShaderConversionPlugin::handles(const Ref<Resource> &p_resource) const {
  3179. Ref<VisualShader> vshader = p_resource;
  3180. return vshader.is_valid();
  3181. }
  3182. Ref<Resource> VisualShaderConversionPlugin::convert(const Ref<Resource> &p_resource) const {
  3183. Ref<VisualShader> vshader = p_resource;
  3184. ERR_FAIL_COND_V(!vshader.is_valid(), Ref<Resource>());
  3185. Ref<Shader> shader;
  3186. shader.instance();
  3187. String code = vshader->get_code();
  3188. shader->set_code(code);
  3189. return shader;
  3190. }