visual_shader_editor_plugin.cpp 443 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472
  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) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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/config/project_settings.h"
  32. #include "core/io/resource_loader.h"
  33. #include "core/math/math_defs.h"
  34. #include "core/os/keyboard.h"
  35. #include "core/version_generated.gen.h"
  36. #include "editor/docks/filesystem_dock.h"
  37. #include "editor/docks/inspector_dock.h"
  38. #include "editor/editor_node.h"
  39. #include "editor/editor_string_names.h"
  40. #include "editor/editor_undo_redo_manager.h"
  41. #include "editor/file_system/editor_paths.h"
  42. #include "editor/gui/editor_toaster.h"
  43. #include "editor/inspector/editor_properties.h"
  44. #include "editor/inspector/editor_properties_vector.h"
  45. #include "editor/scene/curve_editor_plugin.h"
  46. #include "editor/scene/material_editor_plugin.h"
  47. #include "editor/settings/editor_settings.h"
  48. #include "editor/shader/shader_editor_plugin.h"
  49. #include "editor/themes/editor_scale.h"
  50. #include "editor/themes/editor_theme_manager.h"
  51. #include "scene/animation/tween.h"
  52. #include "scene/gui/button.h"
  53. #include "scene/gui/check_box.h"
  54. #include "scene/gui/code_edit.h"
  55. #include "scene/gui/color_picker.h"
  56. #include "scene/gui/flow_container.h"
  57. #include "scene/gui/graph_edit.h"
  58. #include "scene/gui/menu_button.h"
  59. #include "scene/gui/option_button.h"
  60. #include "scene/gui/popup.h"
  61. #include "scene/gui/rich_text_label.h"
  62. #include "scene/gui/separator.h"
  63. #include "scene/gui/split_container.h"
  64. #include "scene/gui/texture_rect.h"
  65. #include "scene/gui/tree.h"
  66. #include "scene/gui/view_panner.h"
  67. #include "scene/main/window.h"
  68. #include "scene/resources/curve_texture.h"
  69. #include "scene/resources/style_box_flat.h"
  70. #include "scene/resources/visual_shader_nodes.h"
  71. #include "scene/resources/visual_shader_particle_nodes.h"
  72. #include "servers/display/display_server.h"
  73. #include "servers/rendering/shader_preprocessor.h"
  74. #include "servers/rendering/shader_types.h"
  75. struct FloatConstantDef {
  76. String name;
  77. float value = 0;
  78. const char *desc_key;
  79. };
  80. static FloatConstantDef float_constant_defs[] = {
  81. { "E", Math::E, TTRC("E constant (2.718282). Represents the base of the natural logarithm.") },
  82. { "Epsilon", CMP_EPSILON, TTRC("Epsilon constant (0.00001). Smallest possible scalar number.") },
  83. { "Phi", 1.618034f, TTRC("Phi constant (1.618034). Golden ratio.") },
  84. { "Pi/4", Math::PI / 4, TTRC("Pi/4 constant (0.785398) or 45 degrees.") },
  85. { "Pi/2", Math::PI / 2, TTRC("Pi/2 constant (1.570796) or 90 degrees.") },
  86. { "Pi", Math::PI, TTRC("Pi constant (3.141593) or 180 degrees.") },
  87. { "Tau", Math::TAU, TTRC("Tau constant (6.283185) or 360 degrees.") },
  88. { "Sqrt2", Math::SQRT2, TTRC("Sqrt2 constant (1.414214). Square root of 2.") }
  89. };
  90. constexpr int MAX_FLOAT_CONST_DEFS = std_size(float_constant_defs);
  91. ///////////////////
  92. void VisualShaderNodePlugin::set_editor(VisualShaderEditor *p_editor) {
  93. vseditor = p_editor;
  94. }
  95. Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) {
  96. Object *ret = nullptr;
  97. GDVIRTUAL_CALL(_create_editor, p_parent_resource, p_node, ret);
  98. return Object::cast_to<Control>(ret);
  99. }
  100. void VisualShaderNodePlugin::_bind_methods() {
  101. GDVIRTUAL_BIND(_create_editor, "parent_resource", "visual_shader_node");
  102. }
  103. ///////////////////
  104. void VSGraphNode::_draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color, const Color &p_rim_color) {
  105. Ref<Texture2D> port_icon = p_left ? get_slot_custom_icon_left(p_slot_index) : get_slot_custom_icon_right(p_slot_index);
  106. Point2 icon_offset;
  107. if (port_icon.is_null()) {
  108. port_icon = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
  109. }
  110. icon_offset = -port_icon->get_size() * 0.5;
  111. // Draw "shadow"/outline in the connection rim color.
  112. draw_texture_rect(port_icon, Rect2(p_pos + (icon_offset - Size2(2, 2)) * EDSCALE, (port_icon->get_size() + Size2(4, 4)) * EDSCALE), false, p_rim_color);
  113. draw_texture_rect(port_icon, Rect2(p_pos + icon_offset * EDSCALE, port_icon->get_size() * EDSCALE), false, p_color);
  114. }
  115. void VSGraphNode::draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) {
  116. Color rim_color = get_theme_color(SNAME("connection_rim_color"), SNAME("GraphEdit"));
  117. _draw_port(p_slot_index, p_pos, p_left, p_color, rim_color);
  118. }
  119. ///////////////////
  120. void VSRerouteNode::_notification(int p_what) {
  121. switch (p_what) {
  122. case NOTIFICATION_READY: {
  123. connect(SceneStringName(mouse_entered), callable_mp(this, &VSRerouteNode::_on_mouse_entered));
  124. connect(SceneStringName(mouse_exited), callable_mp(this, &VSRerouteNode::_on_mouse_exited));
  125. } break;
  126. case NOTIFICATION_DRAW: {
  127. Vector2 offset = Vector2(0, -16 * EDSCALE);
  128. Color drag_bg_color = get_theme_color(SNAME("drag_background"), SNAME("VSRerouteNode"));
  129. draw_circle(get_size() * 0.5 + offset, 16 * EDSCALE, Color(drag_bg_color, selected ? 1 : icon_opacity), true, -1, true);
  130. Ref<Texture2D> icon = get_editor_theme_icon(SNAME("ToolMove"));
  131. Point2 icon_offset = -icon->get_size() * 0.5 + get_size() * 0.5 + offset;
  132. draw_texture(icon, icon_offset, Color(1, 1, 1, selected ? 1 : icon_opacity));
  133. } break;
  134. }
  135. }
  136. void VSRerouteNode::draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) {
  137. Color rim_color = selected ? get_theme_color("selected_rim_color", "VSRerouteNode") : get_theme_color("connection_rim_color", "GraphEdit");
  138. _draw_port(p_slot_index, p_pos, p_left, p_color, rim_color);
  139. }
  140. VSRerouteNode::VSRerouteNode() {
  141. Label *title_lbl = Object::cast_to<Label>(get_titlebar_hbox()->get_child(0));
  142. title_lbl->hide();
  143. const Size2 size = Size2(32, 32) * EDSCALE;
  144. Control *slot_area = memnew(Control);
  145. slot_area->set_custom_minimum_size(size);
  146. slot_area->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
  147. add_child(slot_area);
  148. // Lay the input and output ports on top of each other to create the illusion of a single port.
  149. add_theme_constant_override("port_h_offset", size.width / 2);
  150. }
  151. void VSRerouteNode::set_icon_opacity(float p_opacity) {
  152. icon_opacity = p_opacity;
  153. queue_redraw();
  154. }
  155. void VSRerouteNode::_on_mouse_entered() {
  156. Ref<Tween> tween = create_tween();
  157. tween->tween_method(callable_mp(this, &VSRerouteNode::set_icon_opacity), 0.0, 1.0, FADE_ANIMATION_LENGTH_SEC);
  158. }
  159. void VSRerouteNode::_on_mouse_exited() {
  160. Ref<Tween> tween = create_tween();
  161. tween->tween_method(callable_mp(this, &VSRerouteNode::set_icon_opacity), 1.0, 0.0, FADE_ANIMATION_LENGTH_SEC);
  162. }
  163. ///////////////////
  164. VisualShaderGraphPlugin::VisualShaderGraphPlugin() {
  165. vs_msdf_fonts_theme.instantiate();
  166. }
  167. void VisualShaderGraphPlugin::_bind_methods() {
  168. ClassDB::bind_method("add_node", &VisualShaderGraphPlugin::add_node);
  169. ClassDB::bind_method("remove_node", &VisualShaderGraphPlugin::remove_node);
  170. ClassDB::bind_method("connect_nodes", &VisualShaderGraphPlugin::connect_nodes);
  171. ClassDB::bind_method("disconnect_nodes", &VisualShaderGraphPlugin::disconnect_nodes);
  172. ClassDB::bind_method("set_node_position", &VisualShaderGraphPlugin::set_node_position);
  173. ClassDB::bind_method("update_node", &VisualShaderGraphPlugin::update_node);
  174. ClassDB::bind_method("update_node_deferred", &VisualShaderGraphPlugin::update_node_deferred);
  175. ClassDB::bind_method("set_input_port_default_value", &VisualShaderGraphPlugin::set_input_port_default_value);
  176. ClassDB::bind_method("set_parameter_name", &VisualShaderGraphPlugin::set_parameter_name);
  177. ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression);
  178. ClassDB::bind_method("update_curve", &VisualShaderGraphPlugin::update_curve);
  179. ClassDB::bind_method("update_curve_xyz", &VisualShaderGraphPlugin::update_curve_xyz);
  180. ClassDB::bind_method(D_METHOD("attach_node_to_frame", "type", "id", "frame"), &VisualShaderGraphPlugin::attach_node_to_frame);
  181. ClassDB::bind_method(D_METHOD("detach_node_from_frame", "type", "id"), &VisualShaderGraphPlugin::detach_node_from_frame);
  182. ClassDB::bind_method(D_METHOD("set_frame_color_enabled", "type", "id", "enabled"), &VisualShaderGraphPlugin::set_frame_color_enabled);
  183. ClassDB::bind_method(D_METHOD("set_frame_color", "type", "id", "color"), &VisualShaderGraphPlugin::set_frame_color);
  184. ClassDB::bind_method(D_METHOD("set_frame_autoshrink_enabled", "type", "id", "enabled"), &VisualShaderGraphPlugin::set_frame_autoshrink_enabled);
  185. }
  186. void VisualShaderGraphPlugin::set_editor(VisualShaderEditor *p_editor) {
  187. editor = p_editor;
  188. }
  189. void VisualShaderGraphPlugin::register_shader(VisualShader *p_shader) {
  190. visual_shader = Ref<VisualShader>(p_shader);
  191. }
  192. void VisualShaderGraphPlugin::set_connections(const List<VisualShader::Connection> &p_connections) {
  193. connections = p_connections;
  194. }
  195. void VisualShaderGraphPlugin::show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id, bool p_is_valid) {
  196. if (editor->get_current_shader_type() == p_type && links.has(p_node_id) && links[p_node_id].output_ports.has(p_port_id)) {
  197. Link &link = links[p_node_id];
  198. for (const KeyValue<int, Port> &E : link.output_ports) {
  199. if (E.value.preview_button != nullptr) {
  200. E.value.preview_button->set_pressed(false);
  201. }
  202. }
  203. bool is_dirty = link.preview_pos < 0;
  204. if (!is_dirty && link.preview_visible && link.preview_box != nullptr) {
  205. link.graph_element->remove_child(link.preview_box);
  206. memdelete(link.preview_box);
  207. link.preview_box = nullptr;
  208. link.graph_element->reset_size();
  209. link.preview_visible = false;
  210. }
  211. if (p_port_id != -1 && link.output_ports[p_port_id].preview_button != nullptr) {
  212. if (is_dirty) {
  213. link.preview_pos = link.graph_element->get_child_count();
  214. }
  215. VBoxContainer *vbox = memnew(VBoxContainer);
  216. link.graph_element->add_child(vbox);
  217. link.graph_element->move_child(vbox, link.preview_pos);
  218. GraphNode *graph_node = Object::cast_to<GraphNode>(link.graph_element);
  219. if (graph_node) {
  220. graph_node->set_slot_draw_stylebox(vbox->get_index(false), false);
  221. }
  222. Control *offset = memnew(Control);
  223. offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  224. vbox->add_child(offset);
  225. VisualShaderNodePortPreview *port_preview = memnew(VisualShaderNodePortPreview);
  226. port_preview->setup(visual_shader, editor->preview_material, editor->get_current_shader_type(), links[p_node_id].output_ports[p_port_id].type == VisualShaderNode::PORT_TYPE_VECTOR_4D, p_node_id, p_port_id, p_is_valid);
  227. port_preview->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
  228. vbox->add_child(port_preview);
  229. link.preview_visible = true;
  230. link.preview_box = vbox;
  231. link.output_ports[p_port_id].preview_button->set_pressed(true);
  232. }
  233. }
  234. }
  235. void VisualShaderGraphPlugin::update_node_deferred(VisualShader::Type p_type, int p_node_id) {
  236. callable_mp(this, &VisualShaderGraphPlugin::update_node).call_deferred(p_type, p_node_id);
  237. }
  238. void VisualShaderGraphPlugin::update_node(VisualShader::Type p_type, int p_node_id) {
  239. if (p_type != editor->get_current_shader_type() || !links.has(p_node_id)) {
  240. return;
  241. }
  242. remove_node(p_type, p_node_id, true);
  243. add_node(p_type, p_node_id, true, true);
  244. // TODO: Restore focus here?
  245. }
  246. void VisualShaderGraphPlugin::set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, const Variant &p_value) {
  247. if (p_type != editor->get_current_shader_type() || !links.has(p_node_id)) {
  248. return;
  249. }
  250. Button *button = links[p_node_id].input_ports[p_port_id].default_input_button;
  251. switch (p_value.get_type()) {
  252. case Variant::COLOR: {
  253. button->set_custom_minimum_size(Size2(30, 0) * EDSCALE);
  254. Callable ce = callable_mp(editor, &VisualShaderEditor::_draw_color_over_button);
  255. if (!button->is_connected(SceneStringName(draw), ce)) {
  256. button->connect(SceneStringName(draw), ce.bind(button, p_value));
  257. }
  258. } break;
  259. case Variant::BOOL: {
  260. button->set_text(((bool)p_value) ? "true" : "false");
  261. } break;
  262. case Variant::INT:
  263. case Variant::FLOAT: {
  264. button->set_text(String::num(p_value, 4));
  265. } break;
  266. case Variant::VECTOR2: {
  267. Vector2 v = p_value;
  268. button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3));
  269. } break;
  270. case Variant::VECTOR3: {
  271. Vector3 v = p_value;
  272. button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3) + "," + String::num(v.z, 3));
  273. } break;
  274. case Variant::VECTOR4: {
  275. Vector4 v = p_value;
  276. button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3) + "," + String::num(v.z, 3) + "," + String::num(v.w, 3));
  277. } break;
  278. default: {
  279. }
  280. }
  281. }
  282. void VisualShaderGraphPlugin::set_parameter_name(VisualShader::Type p_type, int p_node_id, const String &p_name) {
  283. if (editor->get_current_shader_type() == p_type && links.has(p_node_id) && links[p_node_id].parameter_name != nullptr) {
  284. links[p_node_id].parameter_name->set_text(p_name);
  285. }
  286. }
  287. void VisualShaderGraphPlugin::update_curve(int p_node_id) {
  288. if (links.has(p_node_id) && links[p_node_id].curve_editors[0]) {
  289. Ref<VisualShaderNodeCurveTexture> tex = Object::cast_to<VisualShaderNodeCurveTexture>(links[p_node_id].visual_node);
  290. ERR_FAIL_COND(tex.is_null());
  291. if (tex->get_texture().is_valid()) {
  292. links[p_node_id].curve_editors[0]->set_curve(tex->get_texture()->get_curve());
  293. }
  294. tex->emit_changed();
  295. }
  296. }
  297. void VisualShaderGraphPlugin::update_curve_xyz(int p_node_id) {
  298. if (links.has(p_node_id) && links[p_node_id].curve_editors[0] && links[p_node_id].curve_editors[1] && links[p_node_id].curve_editors[2]) {
  299. Ref<VisualShaderNodeCurveXYZTexture> tex = Object::cast_to<VisualShaderNodeCurveXYZTexture>(links[p_node_id].visual_node);
  300. ERR_FAIL_COND(tex.is_null());
  301. if (tex->get_texture().is_valid()) {
  302. links[p_node_id].curve_editors[0]->set_curve(tex->get_texture()->get_curve_x());
  303. links[p_node_id].curve_editors[1]->set_curve(tex->get_texture()->get_curve_y());
  304. links[p_node_id].curve_editors[2]->set_curve(tex->get_texture()->get_curve_z());
  305. }
  306. tex->emit_changed();
  307. }
  308. }
  309. int VisualShaderGraphPlugin::get_constant_index(float p_constant) const {
  310. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  311. if (Math::is_equal_approx(p_constant, float_constant_defs[i].value)) {
  312. return i + 1;
  313. }
  314. }
  315. return 0;
  316. }
  317. void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression) {
  318. if (p_type != editor->get_current_shader_type() || !links.has(p_node_id) || !links[p_node_id].expression_edit) {
  319. return;
  320. }
  321. links[p_node_id].expression_edit->set_text(p_expression);
  322. }
  323. void VisualShaderGraphPlugin::attach_node_to_frame(VisualShader::Type p_type, int p_node_id, int p_frame_id) {
  324. if (p_type != editor->get_current_shader_type() || !links.has(p_node_id) || !links.has(p_frame_id)) {
  325. return;
  326. }
  327. GraphEdit *graph = editor->graph;
  328. if (!graph) {
  329. return;
  330. }
  331. // Get the hint label and hide it before attaching the node to prevent resizing issues with the frame.
  332. GraphFrame *frame = Object::cast_to<GraphFrame>(links[p_frame_id].graph_element);
  333. ERR_FAIL_COND_MSG(!frame, "VisualShader node to attach to is not a frame node.");
  334. Label *frame_hint_label = Object::cast_to<Label>(frame->get_child(0, false));
  335. if (frame_hint_label) {
  336. frame_hint_label->hide();
  337. }
  338. graph->attach_graph_element_to_frame(itos(p_node_id), itos(p_frame_id));
  339. }
  340. void VisualShaderGraphPlugin::detach_node_from_frame(VisualShader::Type p_type, int p_node_id) {
  341. GraphEdit *graph = editor->graph;
  342. if (!graph) {
  343. return;
  344. }
  345. const StringName node_name = itos(p_node_id);
  346. GraphFrame *frame = graph->get_element_frame(node_name);
  347. if (!frame) {
  348. return;
  349. }
  350. graph->detach_graph_element_from_frame(node_name);
  351. bool no_more_frames_attached = graph->get_attached_nodes_of_frame(frame->get_name()).is_empty();
  352. if (no_more_frames_attached) {
  353. // Get the hint label and show it.
  354. Label *frame_hint_label = Object::cast_to<Label>(frame->get_child(0, false));
  355. ERR_FAIL_COND_MSG(!frame_hint_label, "Frame node does not have a hint label.");
  356. frame_hint_label->show();
  357. }
  358. }
  359. void VisualShaderGraphPlugin::set_frame_color_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable) {
  360. GraphEdit *graph = editor->graph;
  361. ERR_FAIL_COND(!graph);
  362. const NodePath node_name = itos(p_node_id);
  363. GraphFrame *frame = Object::cast_to<GraphFrame>(graph->get_node_or_null(node_name));
  364. if (!frame) {
  365. return;
  366. }
  367. frame->set_tint_color_enabled(p_enable);
  368. }
  369. void VisualShaderGraphPlugin::set_frame_color(VisualShader::Type p_type, int p_node_id, const Color &p_color) {
  370. GraphEdit *graph = editor->graph;
  371. ERR_FAIL_COND(!graph);
  372. const NodePath node_name = itos(p_node_id);
  373. GraphFrame *frame = Object::cast_to<GraphFrame>(graph->get_node_or_null(node_name));
  374. if (!frame) {
  375. return;
  376. }
  377. frame->set_tint_color(p_color);
  378. }
  379. void VisualShaderGraphPlugin::set_frame_autoshrink_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable) {
  380. GraphEdit *graph = editor->graph;
  381. ERR_FAIL_COND(!graph);
  382. const NodePath node_name = itos(p_node_id);
  383. GraphFrame *frame = Object::cast_to<GraphFrame>(graph->get_node_or_null(node_name));
  384. if (!frame) {
  385. return;
  386. }
  387. frame->set_autoshrink_enabled(p_enable);
  388. }
  389. void VisualShaderGraphPlugin::update_reroute_nodes() {
  390. for (const KeyValue<int, Link> &E : links) {
  391. Ref<VisualShaderNodeReroute> reroute_node = Object::cast_to<VisualShaderNodeReroute>(E.value.visual_node);
  392. if (reroute_node.is_valid()) {
  393. update_node(editor->get_current_shader_type(), E.key);
  394. }
  395. }
  396. }
  397. Ref<Script> VisualShaderGraphPlugin::get_node_script(int p_node_id) const {
  398. if (!links.has(p_node_id)) {
  399. return Ref<Script>();
  400. }
  401. Ref<VisualShaderNodeCustom> custom = Ref<VisualShaderNodeCustom>(links[p_node_id].visual_node);
  402. if (custom.is_valid()) {
  403. return custom->get_script();
  404. }
  405. return Ref<Script>();
  406. }
  407. void VisualShaderGraphPlugin::register_default_input_button(int p_node_id, int p_port_id, Button *p_button) {
  408. links[p_node_id].input_ports.insert(p_port_id, { p_button });
  409. }
  410. void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit *p_expression_edit) {
  411. links[p_node_id].expression_edit = p_expression_edit;
  412. }
  413. void VisualShaderGraphPlugin::register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor) {
  414. links[p_node_id].curve_editors[p_index] = p_curve_editor;
  415. }
  416. void VisualShaderGraphPlugin::update_parameter_refs() {
  417. for (KeyValue<int, Link> &E : links) {
  418. VisualShaderNodeParameterRef *ref = Object::cast_to<VisualShaderNodeParameterRef>(E.value.visual_node);
  419. if (ref) {
  420. remove_node(E.value.type, E.key, true);
  421. add_node(E.value.type, E.key, true, true);
  422. }
  423. }
  424. }
  425. // Only updates the linked frames of the given node, not the node itself (in case it's a frame node).
  426. void VisualShaderGraphPlugin::update_frames(VisualShader::Type p_type, int p_node) {
  427. GraphEdit *graph = editor->graph;
  428. if (!graph) {
  429. return;
  430. }
  431. Ref<VisualShaderNode> vsnode = visual_shader->get_node(p_type, p_node);
  432. if (vsnode.is_null()) {
  433. WARN_PRINT("Update linked frames: Node not found.");
  434. return;
  435. }
  436. int frame_vsnode_id = vsnode->get_frame();
  437. if (frame_vsnode_id == -1) {
  438. return;
  439. }
  440. Ref<VisualShaderNodeFrame> frame_node = visual_shader->get_node(p_type, frame_vsnode_id);
  441. if (frame_node.is_null() || !links.has(frame_vsnode_id)) {
  442. return;
  443. }
  444. GraphFrame *frame = Object::cast_to<GraphFrame>(links[frame_vsnode_id].graph_element);
  445. if (!frame) {
  446. return;
  447. }
  448. // Update the frame node recursively.
  449. editor->graph->_update_graph_frame(frame);
  450. }
  451. void VisualShaderGraphPlugin::set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position) {
  452. if (editor->get_current_shader_type() == p_type && links.has(p_id)) {
  453. links[p_id].graph_element->set_position_offset(p_position);
  454. }
  455. }
  456. bool VisualShaderGraphPlugin::is_preview_visible(int p_id) const {
  457. return links[p_id].preview_visible;
  458. }
  459. void VisualShaderGraphPlugin::clear_links() {
  460. links.clear();
  461. }
  462. void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphElement *p_graph_element) {
  463. links.insert(p_id, { p_type, p_visual_node, p_graph_element, p_visual_node->get_output_port_for_preview() != -1, -1, HashMap<int, InputPort>(), HashMap<int, Port>(), nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } });
  464. }
  465. void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, VisualShaderNode::PortType p_port_type, TextureButton *p_button) {
  466. links[p_node_id].output_ports.insert(p_port, { p_port_type, p_button });
  467. }
  468. void VisualShaderGraphPlugin::register_parameter_name(int p_node_id, LineEdit *p_parameter_name) {
  469. links[p_node_id].parameter_name = p_parameter_name;
  470. }
  471. void VisualShaderGraphPlugin::update_theme() {
  472. vector_expanded_color[0] = editor->get_theme_color(SNAME("axis_x_color"), EditorStringName(Editor)); // red
  473. vector_expanded_color[1] = editor->get_theme_color(SNAME("axis_y_color"), EditorStringName(Editor)); // green
  474. vector_expanded_color[2] = editor->get_theme_color(SNAME("axis_z_color"), EditorStringName(Editor)); // blue
  475. vector_expanded_color[3] = editor->get_theme_color(SNAME("axis_w_color"), EditorStringName(Editor)); // alpha
  476. Ref<Font> label_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_msdf", EditorStringName(EditorFonts));
  477. Ref<Font> label_bold_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_bold_msdf", EditorStringName(EditorFonts));
  478. vs_msdf_fonts_theme->set_font(SceneStringName(font), "Label", label_font);
  479. vs_msdf_fonts_theme->set_font(SceneStringName(font), "GraphNodeTitleLabel", label_bold_font);
  480. if (!EditorThemeManager::is_dark_theme()) {
  481. // Override the color to white for light themes.
  482. vs_msdf_fonts_theme->set_color(SceneStringName(font_color), "GraphNodeTitleLabel", Color(1, 1, 1));
  483. }
  484. vs_msdf_fonts_theme->set_font(SceneStringName(font), "LineEdit", label_font);
  485. vs_msdf_fonts_theme->set_font(SceneStringName(font), "Button", label_font);
  486. }
  487. bool VisualShaderGraphPlugin::is_node_has_parameter_instances_relatively(VisualShader::Type p_type, int p_node) const {
  488. bool result = false;
  489. Ref<VisualShaderNodeParameter> parameter_node = Object::cast_to<VisualShaderNodeParameter>(visual_shader->get_node_unchecked(p_type, p_node).ptr());
  490. if (parameter_node.is_valid()) {
  491. if (parameter_node->get_qualifier() == VisualShaderNodeParameter::QUAL_INSTANCE) {
  492. return true;
  493. }
  494. }
  495. const LocalVector<int> &prev_connected_nodes = visual_shader->get_prev_connected_nodes(p_type, p_node);
  496. for (const int &E : prev_connected_nodes) {
  497. result = is_node_has_parameter_instances_relatively(p_type, E);
  498. if (result) {
  499. break;
  500. }
  501. }
  502. return result;
  503. }
  504. void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool p_just_update, bool p_update_frames) {
  505. if (visual_shader.is_null() || p_type != editor->get_current_shader_type()) {
  506. return;
  507. }
  508. GraphEdit *graph = editor->graph;
  509. if (!graph) {
  510. return;
  511. }
  512. VisualShaderGraphPlugin *graph_plugin = editor->get_graph_plugin();
  513. if (!graph_plugin) {
  514. return;
  515. }
  516. Shader::Mode mode = visual_shader->get_mode();
  517. Control *offset;
  518. const Color type_color[] = {
  519. EDITOR_GET("editors/visual_editors/connection_colors/scalar_color"),
  520. EDITOR_GET("editors/visual_editors/connection_colors/scalar_color"),
  521. EDITOR_GET("editors/visual_editors/connection_colors/scalar_color"),
  522. EDITOR_GET("editors/visual_editors/connection_colors/vector2_color"),
  523. EDITOR_GET("editors/visual_editors/connection_colors/vector3_color"),
  524. EDITOR_GET("editors/visual_editors/connection_colors/vector4_color"),
  525. EDITOR_GET("editors/visual_editors/connection_colors/boolean_color"),
  526. EDITOR_GET("editors/visual_editors/connection_colors/transform_color"),
  527. EDITOR_GET("editors/visual_editors/connection_colors/sampler_color"),
  528. };
  529. // Keep in sync with VisualShaderNode::Category.
  530. const Color category_color[VisualShaderNode::Category::CATEGORY_MAX] = {
  531. Color(0.0, 0.0, 0.0), // None (default, not used)
  532. EDITOR_GET("editors/visual_editors/category_colors/output_color"),
  533. EDITOR_GET("editors/visual_editors/category_colors/color_color"),
  534. EDITOR_GET("editors/visual_editors/category_colors/conditional_color"),
  535. EDITOR_GET("editors/visual_editors/category_colors/input_color"),
  536. EDITOR_GET("editors/visual_editors/category_colors/scalar_color"),
  537. EDITOR_GET("editors/visual_editors/category_colors/textures_color"),
  538. EDITOR_GET("editors/visual_editors/category_colors/transform_color"),
  539. EDITOR_GET("editors/visual_editors/category_colors/utility_color"),
  540. EDITOR_GET("editors/visual_editors/category_colors/vector_color"),
  541. EDITOR_GET("editors/visual_editors/category_colors/special_color"),
  542. EDITOR_GET("editors/visual_editors/category_colors/particle_color"),
  543. };
  544. static const String vector_expanded_name[4] = { "red", "green", "blue", "alpha" };
  545. Ref<VisualShaderNode> vsnode = visual_shader->get_node(p_type, p_id);
  546. ERR_FAIL_COND(vsnode.is_null());
  547. Ref<VisualShaderNodeResizableBase> resizable_node = vsnode;
  548. bool is_resizable = resizable_node.is_valid();
  549. Size2 size = Size2(0, 0);
  550. Ref<VisualShaderNodeGroupBase> group_node = vsnode;
  551. bool is_group = group_node.is_valid();
  552. Ref<VisualShaderNodeFrame> frame_node = vsnode;
  553. bool is_frame = frame_node.is_valid();
  554. Ref<VisualShaderNodeExpression> expression_node = group_node;
  555. bool is_expression = expression_node.is_valid();
  556. String expression = "";
  557. Ref<VisualShaderNodeReroute> reroute_node = vsnode;
  558. bool is_reroute = reroute_node.is_valid();
  559. Ref<VisualShaderNodeCustom> custom_node = vsnode;
  560. if (custom_node.is_valid()) {
  561. custom_node->_set_initialized(true);
  562. }
  563. GraphElement *node;
  564. if (is_frame) {
  565. GraphFrame *frame = memnew(GraphFrame);
  566. frame->set_title(vsnode->get_caption());
  567. node = frame;
  568. } else if (is_reroute) {
  569. VSRerouteNode *reroute_gnode = memnew(VSRerouteNode);
  570. reroute_gnode->set_ignore_invalid_connection_type(true);
  571. node = reroute_gnode;
  572. } else {
  573. VSGraphNode *gnode = memnew(VSGraphNode);
  574. gnode->set_title(vsnode->get_caption());
  575. node = gnode;
  576. }
  577. node->set_name(itos(p_id));
  578. // All nodes are closable except the output node.
  579. if (p_id >= 2) {
  580. vsnode->set_deletable(true);
  581. node->connect("delete_request", callable_mp(editor, &VisualShaderEditor::_delete_node_request).bind(p_type, p_id), CONNECT_DEFERRED);
  582. }
  583. graph->add_child(node);
  584. node->set_theme(vs_msdf_fonts_theme);
  585. // Set the node's titlebar color based on its category.
  586. if (vsnode->get_category() != VisualShaderNode::CATEGORY_NONE && !is_frame && !is_reroute) {
  587. Ref<StyleBoxFlat> sb_colored = editor->get_theme_stylebox("titlebar", "GraphNode")->duplicate();
  588. sb_colored->set_bg_color(category_color[vsnode->get_category()]);
  589. node->add_theme_style_override("titlebar", sb_colored);
  590. Ref<StyleBoxFlat> sb_colored_selected = editor->get_theme_stylebox("titlebar_selected", "GraphNode")->duplicate();
  591. sb_colored_selected->set_bg_color(category_color[vsnode->get_category()].lightened(0.2));
  592. node->add_theme_style_override("titlebar_selected", sb_colored_selected);
  593. }
  594. if (p_just_update) {
  595. Link &link = links[p_id];
  596. link.visual_node = vsnode.ptr();
  597. link.graph_element = node;
  598. link.preview_box = nullptr;
  599. link.preview_pos = -1;
  600. link.output_ports.clear();
  601. link.input_ports.clear();
  602. } else {
  603. register_link(p_type, p_id, vsnode.ptr(), node);
  604. }
  605. if (is_resizable) {
  606. size = resizable_node->get_size();
  607. node->set_resizable(true);
  608. node->connect("resize_end", callable_mp(editor, &VisualShaderEditor::_node_resized).bind((int)p_type, p_id));
  609. node->set_size(size);
  610. // node->call_deferred(SNAME("set_size"), size);
  611. // editor->call_deferred(SNAME("_set_node_size"), (int)p_type, p_id, size);
  612. }
  613. if (is_expression) {
  614. expression = expression_node->get_expression();
  615. }
  616. node->set_position_offset(visual_shader->get_node_position(p_type, p_id));
  617. node->connect("dragged", callable_mp(editor, &VisualShaderEditor::_node_dragged).bind(p_id));
  618. Control *custom_editor = nullptr;
  619. int port_offset = 1;
  620. if (p_update_frames) {
  621. if (vsnode->get_frame() > -1) {
  622. graph->attach_graph_element_to_frame(itos(p_id), itos(vsnode->get_frame()));
  623. } else {
  624. graph->detach_graph_element_from_frame(itos(p_id));
  625. }
  626. }
  627. if (is_frame) {
  628. GraphFrame *graph_frame = Object::cast_to<GraphFrame>(node);
  629. ERR_FAIL_NULL(graph_frame);
  630. graph_frame->set_tint_color_enabled(frame_node->is_tint_color_enabled());
  631. graph_frame->set_tint_color(frame_node->get_tint_color());
  632. // Add hint label.
  633. Label *frame_hint_label = memnew(Label);
  634. frame_hint_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  635. node->add_child(frame_hint_label);
  636. frame_hint_label->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER);
  637. frame_hint_label->set_vertical_alignment(VerticalAlignment::VERTICAL_ALIGNMENT_CENTER);
  638. frame_hint_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  639. frame_hint_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  640. frame_hint_label->set_text(TTR("Drag and drop nodes here to attach them."));
  641. frame_hint_label->set_modulate(Color(1.0, 1.0, 1.0, 0.3));
  642. graph_frame->set_autoshrink_enabled(frame_node->is_autoshrink_enabled());
  643. if (frame_node->get_attached_nodes().is_empty()) {
  644. frame_hint_label->show();
  645. } else {
  646. frame_hint_label->hide();
  647. }
  648. // Attach all nodes.
  649. if (p_update_frames && frame_node->get_attached_nodes().size() > 0) {
  650. for (const int &id : frame_node->get_attached_nodes()) {
  651. graph->attach_graph_element_to_frame(itos(id), node->get_name());
  652. }
  653. }
  654. // We should be done here.
  655. return;
  656. }
  657. if (!is_reroute) {
  658. Control *content_offset = memnew(Control);
  659. content_offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  660. node->add_child(content_offset);
  661. }
  662. if (is_group) {
  663. port_offset += 1;
  664. }
  665. // Set the minimum width of a node based on the preview size to avoid a resize when toggling the preview.
  666. Ref<StyleBoxFlat> graph_node_stylebox = graph->get_theme_stylebox(SceneStringName(panel), "GraphNode");
  667. int port_preview_size = EDITOR_GET("editors/visual_editors/visual_shader/port_preview_size");
  668. if (!is_frame && !is_reroute) {
  669. node->set_custom_minimum_size(Size2((Math::ceil(graph_node_stylebox->get_minimum_size().width) + port_preview_size) * EDSCALE, 0));
  670. }
  671. Ref<VisualShaderNodeParticleEmit> emit = vsnode;
  672. if (emit.is_valid()) {
  673. node->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
  674. }
  675. Ref<VisualShaderNodeParameterRef> parameter_ref = vsnode;
  676. if (parameter_ref.is_valid()) {
  677. parameter_ref->set_shader_rid(visual_shader->get_rid());
  678. parameter_ref->update_parameter_type();
  679. }
  680. Ref<VisualShaderNodeVarying> varying = vsnode;
  681. if (varying.is_valid()) {
  682. varying->set_shader_rid(visual_shader->get_rid());
  683. }
  684. Ref<VisualShaderNodeParameter> parameter = vsnode;
  685. HBoxContainer *hb = nullptr;
  686. if (parameter.is_valid()) {
  687. LineEdit *parameter_name = memnew(LineEdit);
  688. register_parameter_name(p_id, parameter_name);
  689. parameter_name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  690. parameter_name->set_text(parameter->get_parameter_name());
  691. parameter_name->connect(SceneStringName(text_submitted), callable_mp(editor, &VisualShaderEditor::_parameter_line_edit_changed).bind(p_id));
  692. parameter_name->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_parameter_line_edit_focus_out).bind(parameter_name, p_id));
  693. if (vsnode->get_output_port_count() == 1 && vsnode->get_output_port_name(0) == "") {
  694. hb = memnew(HBoxContainer);
  695. hb->add_child(parameter_name);
  696. node->add_child(hb);
  697. } else {
  698. node->add_child(parameter_name);
  699. }
  700. port_offset++;
  701. }
  702. for (int i = 0; i < editor->plugins.size(); i++) {
  703. vsnode->set_meta("id", p_id);
  704. vsnode->set_meta("shader_type", (int)p_type);
  705. custom_editor = editor->plugins.write[i]->create_editor(visual_shader, vsnode);
  706. vsnode->remove_meta("id");
  707. vsnode->remove_meta("shader_type");
  708. if (custom_editor) {
  709. if (vsnode->is_show_prop_names()) {
  710. custom_editor->call_deferred(SNAME("_show_prop_names"), true);
  711. }
  712. break;
  713. }
  714. }
  715. if (custom_node.is_valid()) {
  716. bool first = true;
  717. VBoxContainer *vbox = nullptr;
  718. int i = 0;
  719. for (List<VisualShaderNodeCustom::DropDownListProperty>::ConstIterator itr = custom_node->dp_props.begin(); itr != custom_node->dp_props.end(); ++itr, ++i) {
  720. const VisualShaderNodeCustom::DropDownListProperty &dp = *itr;
  721. if (first) {
  722. first = false;
  723. vbox = memnew(VBoxContainer);
  724. node->add_child(vbox);
  725. port_offset++;
  726. }
  727. HBoxContainer *hbox = memnew(HBoxContainer);
  728. vbox->add_child(hbox);
  729. hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  730. String prop_name = dp.name.strip_edges();
  731. if (!prop_name.is_empty()) {
  732. Label *label = memnew(Label);
  733. label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  734. label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  735. label->set_text(prop_name + ":");
  736. hbox->add_child(label);
  737. }
  738. OptionButton *op = memnew(OptionButton);
  739. hbox->add_child(op);
  740. op->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  741. op->connect(SceneStringName(item_selected), callable_mp(editor, &VisualShaderEditor::_set_custom_node_option).bind(p_id, i), CONNECT_DEFERRED);
  742. for (const String &s : dp.options) {
  743. op->add_item(s);
  744. }
  745. if (custom_node->dp_selected_cache.has(i)) {
  746. op->select(custom_node->dp_selected_cache[i]);
  747. } else {
  748. op->select(0);
  749. }
  750. }
  751. }
  752. Ref<VisualShaderNodeCurveTexture> curve = vsnode;
  753. Ref<VisualShaderNodeCurveXYZTexture> curve_xyz = vsnode;
  754. bool is_curve = curve.is_valid() || curve_xyz.is_valid();
  755. if (is_curve) {
  756. hb = memnew(HBoxContainer);
  757. node->add_child(hb);
  758. }
  759. if (curve.is_valid()) {
  760. custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  761. if (curve->get_texture().is_valid()) {
  762. curve->get_texture()->connect_changed(callable_mp(graph_plugin, &VisualShaderGraphPlugin::update_curve).bind(p_id));
  763. }
  764. CurveEditor *curve_editor = memnew(CurveEditor);
  765. node->add_child(curve_editor);
  766. register_curve_editor(p_id, 0, curve_editor);
  767. curve_editor->set_custom_minimum_size(Size2(300, 0));
  768. curve_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  769. if (curve->get_texture().is_valid()) {
  770. curve_editor->set_curve(curve->get_texture()->get_curve());
  771. }
  772. }
  773. if (curve_xyz.is_valid()) {
  774. custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  775. if (curve_xyz->get_texture().is_valid()) {
  776. curve_xyz->get_texture()->connect_changed(callable_mp(graph_plugin, &VisualShaderGraphPlugin::update_curve_xyz).bind(p_id));
  777. }
  778. CurveEditor *curve_editor_x = memnew(CurveEditor);
  779. node->add_child(curve_editor_x);
  780. register_curve_editor(p_id, 0, curve_editor_x);
  781. curve_editor_x->set_custom_minimum_size(Size2(300, 0));
  782. curve_editor_x->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  783. if (curve_xyz->get_texture().is_valid()) {
  784. curve_editor_x->set_curve(curve_xyz->get_texture()->get_curve_x());
  785. }
  786. CurveEditor *curve_editor_y = memnew(CurveEditor);
  787. node->add_child(curve_editor_y);
  788. register_curve_editor(p_id, 1, curve_editor_y);
  789. curve_editor_y->set_custom_minimum_size(Size2(300, 0));
  790. curve_editor_y->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  791. if (curve_xyz->get_texture().is_valid()) {
  792. curve_editor_y->set_curve(curve_xyz->get_texture()->get_curve_y());
  793. }
  794. CurveEditor *curve_editor_z = memnew(CurveEditor);
  795. node->add_child(curve_editor_z);
  796. register_curve_editor(p_id, 2, curve_editor_z);
  797. curve_editor_z->set_custom_minimum_size(Size2(300, 0));
  798. curve_editor_z->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  799. if (curve_xyz->get_texture().is_valid()) {
  800. curve_editor_z->set_curve(curve_xyz->get_texture()->get_curve_z());
  801. }
  802. }
  803. if (custom_editor) {
  804. if (is_curve || (hb == nullptr && !vsnode->is_use_prop_slots() && (vsnode->get_output_port_count() == 0 || vsnode->get_output_port_name(0) == "") && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == ""))) {
  805. // Will be embedded in first port.
  806. } else {
  807. port_offset++;
  808. node->add_child(custom_editor);
  809. custom_editor = nullptr;
  810. }
  811. }
  812. if (is_group) {
  813. if (group_node->is_editable()) {
  814. HBoxContainer *hb2 = memnew(HBoxContainer);
  815. String input_port_name = "input" + itos(group_node->get_free_input_port_id());
  816. String output_port_name = "output" + itos(group_node->get_free_output_port_id());
  817. for (int i = 0; i < MAX(vsnode->get_input_port_count(), vsnode->get_output_port_count()); i++) {
  818. if (i < vsnode->get_input_port_count()) {
  819. if (input_port_name == vsnode->get_input_port_name(i)) {
  820. input_port_name = "_" + input_port_name;
  821. }
  822. }
  823. if (i < vsnode->get_output_port_count()) {
  824. if (output_port_name == vsnode->get_output_port_name(i)) {
  825. output_port_name = "_" + output_port_name;
  826. }
  827. }
  828. }
  829. Button *add_input_btn = memnew(Button);
  830. add_input_btn->set_text(TTR("Add Input"));
  831. add_input_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_add_input_port).bind(p_id, group_node->get_free_input_port_id(), VisualShaderNode::PORT_TYPE_VECTOR_3D, input_port_name), CONNECT_DEFERRED);
  832. hb2->add_child(add_input_btn);
  833. hb2->add_spacer();
  834. Button *add_output_btn = memnew(Button);
  835. add_output_btn->set_text(TTR("Add Output"));
  836. add_output_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_add_output_port).bind(p_id, group_node->get_free_output_port_id(), VisualShaderNode::PORT_TYPE_VECTOR_3D, output_port_name), CONNECT_DEFERRED);
  837. hb2->add_child(add_output_btn);
  838. node->add_child(hb2);
  839. }
  840. }
  841. int output_port_count = 0;
  842. for (int i = 0; i < vsnode->get_output_port_count(); i++) {
  843. if (vsnode->_is_output_port_expanded(i)) {
  844. switch (vsnode->get_output_port_type(i)) {
  845. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  846. output_port_count += 2;
  847. } break;
  848. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  849. output_port_count += 3;
  850. } break;
  851. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  852. output_port_count += 4;
  853. } break;
  854. default:
  855. break;
  856. }
  857. }
  858. output_port_count++;
  859. }
  860. int max_ports = MAX(vsnode->get_input_port_count(), output_port_count);
  861. VisualShaderNode::PortType expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  862. int expanded_port_counter = 0;
  863. for (int i = 0, j = 0; i < max_ports; i++, j++) {
  864. switch (expanded_type) {
  865. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  866. if (expanded_port_counter >= 2) {
  867. expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  868. expanded_port_counter = 0;
  869. i -= 2;
  870. }
  871. } break;
  872. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  873. if (expanded_port_counter >= 3) {
  874. expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  875. expanded_port_counter = 0;
  876. i -= 3;
  877. }
  878. } break;
  879. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  880. if (expanded_port_counter >= 4) {
  881. expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  882. expanded_port_counter = 0;
  883. i -= 4;
  884. }
  885. } break;
  886. default:
  887. break;
  888. }
  889. if (vsnode->is_port_separator(i)) {
  890. node->add_child(memnew(HSeparator));
  891. port_offset++;
  892. }
  893. bool valid_left = j < vsnode->get_input_port_count();
  894. VisualShaderNode::PortType port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  895. bool port_left_used = false;
  896. String name_left;
  897. if (valid_left) {
  898. name_left = vsnode->get_input_port_name(j);
  899. port_left = vsnode->get_input_port_type(j);
  900. for (const VisualShader::Connection &E : connections) {
  901. if (E.to_node == p_id && E.to_port == j) {
  902. port_left_used = true;
  903. break;
  904. }
  905. }
  906. }
  907. bool valid_right = true;
  908. VisualShaderNode::PortType port_right = VisualShaderNode::PORT_TYPE_SCALAR;
  909. String name_right;
  910. if (expanded_type == VisualShaderNode::PORT_TYPE_SCALAR) {
  911. valid_right = i < vsnode->get_output_port_count();
  912. if (valid_right) {
  913. name_right = vsnode->get_output_port_name(i);
  914. port_right = vsnode->get_output_port_type(i);
  915. }
  916. } else {
  917. name_right = vector_expanded_name[expanded_port_counter++];
  918. }
  919. bool is_first_hbox = false;
  920. if (i == 0 && hb != nullptr) {
  921. is_first_hbox = true;
  922. } else {
  923. hb = memnew(HBoxContainer);
  924. }
  925. hb->add_theme_constant_override("separation", 7 * EDSCALE);
  926. // Default value button/property editor.
  927. Variant default_value;
  928. if (valid_left && !port_left_used) {
  929. default_value = vsnode->get_input_port_default_value(j);
  930. }
  931. Button *default_input_btn = memnew(Button);
  932. hb->add_child(default_input_btn);
  933. register_default_input_button(p_id, j, default_input_btn);
  934. default_input_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_edit_port_default_input).bind(default_input_btn, p_id, j));
  935. if (default_value.get_type() != Variant::NIL) { // only a label
  936. set_input_port_default_value(p_type, p_id, j, default_value);
  937. } else {
  938. default_input_btn->hide();
  939. }
  940. if (j == 0 && custom_editor) {
  941. hb->add_child(custom_editor);
  942. custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  943. } else {
  944. if (valid_left) {
  945. if (is_group) {
  946. OptionButton *type_box = memnew(OptionButton);
  947. hb->add_child(type_box);
  948. type_box->add_item(TTR("Float"));
  949. type_box->add_item(TTR("Int"));
  950. type_box->add_item(TTR("UInt"));
  951. type_box->add_item(TTR("Vector2"));
  952. type_box->add_item(TTR("Vector3"));
  953. type_box->add_item(TTR("Vector4"));
  954. type_box->add_item(TTR("Boolean"));
  955. type_box->add_item(TTR("Transform"));
  956. type_box->add_item(TTR("Sampler"));
  957. type_box->select(group_node->get_input_port_type(j));
  958. type_box->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  959. type_box->connect(SceneStringName(item_selected), callable_mp(editor, &VisualShaderEditor::_change_input_port_type).bind(p_id, j), CONNECT_DEFERRED);
  960. LineEdit *name_box = memnew(LineEdit);
  961. hb->add_child(name_box);
  962. name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0));
  963. name_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  964. name_box->set_text(name_left);
  965. name_box->connect(SceneStringName(text_submitted), callable_mp(editor, &VisualShaderEditor::_change_input_port_name).bind(name_box, p_id, j), CONNECT_DEFERRED);
  966. name_box->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_port_name_focus_out).bind(name_box, p_id, j, false), CONNECT_DEFERRED);
  967. Button *remove_btn = memnew(Button);
  968. remove_btn->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Remove"), EditorStringName(EditorIcons)));
  969. remove_btn->set_tooltip_text(TTR("Remove") + " " + name_left);
  970. remove_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_remove_input_port).bind(p_id, j), CONNECT_DEFERRED);
  971. hb->add_child(remove_btn);
  972. } else {
  973. Label *label = memnew(Label);
  974. label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  975. label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  976. label->set_text(name_left);
  977. label->add_theme_style_override(CoreStringName(normal), editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor")));
  978. hb->add_child(label);
  979. if (vsnode->is_input_port_default(j, mode) && !port_left_used) {
  980. Label *hint_label = memnew(Label);
  981. hint_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  982. hint_label->set_text(TTR("[default]"));
  983. hint_label->add_theme_color_override(SceneStringName(font_color), editor->get_theme_color(SNAME("font_readonly_color"), SNAME("TextEdit")));
  984. hint_label->add_theme_style_override(CoreStringName(normal), editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor")));
  985. hb->add_child(hint_label);
  986. }
  987. }
  988. }
  989. if (!is_group && !is_first_hbox) {
  990. hb->add_spacer();
  991. }
  992. if (valid_right) {
  993. if (is_group) {
  994. Button *remove_btn = memnew(Button);
  995. remove_btn->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Remove"), EditorStringName(EditorIcons)));
  996. remove_btn->set_tooltip_text(TTR("Remove") + " " + name_left);
  997. remove_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_remove_output_port).bind(p_id, i), CONNECT_DEFERRED);
  998. hb->add_child(remove_btn);
  999. LineEdit *name_box = memnew(LineEdit);
  1000. hb->add_child(name_box);
  1001. name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0));
  1002. name_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1003. name_box->set_text(name_right);
  1004. name_box->connect(SceneStringName(text_submitted), callable_mp(editor, &VisualShaderEditor::_change_output_port_name).bind(name_box, p_id, i), CONNECT_DEFERRED);
  1005. name_box->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_port_name_focus_out).bind(name_box, p_id, i, true), CONNECT_DEFERRED);
  1006. OptionButton *type_box = memnew(OptionButton);
  1007. hb->add_child(type_box);
  1008. type_box->add_item(TTR("Float"));
  1009. type_box->add_item(TTR("Int"));
  1010. type_box->add_item(TTR("UInt"));
  1011. type_box->add_item(TTR("Vector2"));
  1012. type_box->add_item(TTR("Vector3"));
  1013. type_box->add_item(TTR("Vector4"));
  1014. type_box->add_item(TTR("Boolean"));
  1015. type_box->add_item(TTR("Transform"));
  1016. type_box->select(group_node->get_output_port_type(i));
  1017. type_box->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  1018. type_box->connect(SceneStringName(item_selected), callable_mp(editor, &VisualShaderEditor::_change_output_port_type).bind(p_id, i), CONNECT_DEFERRED);
  1019. } else {
  1020. Label *label = memnew(Label);
  1021. label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  1022. label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  1023. label->set_text(name_right);
  1024. label->add_theme_style_override(CoreStringName(normal), editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact
  1025. hb->add_child(label);
  1026. }
  1027. }
  1028. }
  1029. if (valid_right) {
  1030. if (expanded_port_counter == 0 && vsnode->is_output_port_expandable(i)) {
  1031. TextureButton *expand = memnew(TextureButton);
  1032. expand->set_accessibility_name(TTRC("Expand output port"));
  1033. expand->set_toggle_mode(true);
  1034. expand->set_texture_normal(editor->get_editor_theme_icon(SNAME("GuiTreeArrowRight")));
  1035. expand->set_texture_pressed(editor->get_editor_theme_icon(SNAME("GuiTreeArrowDown")));
  1036. expand->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  1037. expand->set_pressed(vsnode->_is_output_port_expanded(i));
  1038. expand->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_expand_output_port).bind(p_id, i, !vsnode->_is_output_port_expanded(i)), CONNECT_DEFERRED);
  1039. hb->add_child(expand);
  1040. }
  1041. if (vsnode->has_output_port_preview(i) && port_right != VisualShaderNode::PORT_TYPE_TRANSFORM && port_right != VisualShaderNode::PORT_TYPE_SAMPLER) {
  1042. TextureButton *preview = memnew(TextureButton);
  1043. preview->set_accessibility_name(TTRC("Select preview port"));
  1044. preview->set_toggle_mode(true);
  1045. preview->set_texture_normal(editor->get_editor_theme_icon(SNAME("GuiVisibilityHidden")));
  1046. preview->set_texture_pressed(editor->get_editor_theme_icon(SNAME("GuiVisibilityVisible")));
  1047. preview->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  1048. register_output_port(p_id, j, port_right, preview);
  1049. preview->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_preview_select_port).bind(p_id, j), CONNECT_DEFERRED);
  1050. hb->add_child(preview);
  1051. }
  1052. }
  1053. if (is_group) {
  1054. offset = memnew(Control);
  1055. offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  1056. node->add_child(offset);
  1057. port_offset++;
  1058. }
  1059. if (!is_first_hbox && !is_reroute) {
  1060. node->add_child(hb);
  1061. if (curve_xyz.is_valid()) {
  1062. node->move_child(hb, 1 + expanded_port_counter);
  1063. }
  1064. }
  1065. if (expanded_type != VisualShaderNode::PORT_TYPE_SCALAR) {
  1066. continue;
  1067. }
  1068. int idx = is_first_hbox ? 1 : i + port_offset;
  1069. if (is_reroute) {
  1070. idx = 0;
  1071. }
  1072. if (!is_frame) {
  1073. GraphNode *graph_node = Object::cast_to<GraphNode>(node);
  1074. graph_node->set_slot(idx, valid_left, port_left, type_color[port_left], valid_right, port_right, type_color[port_right]);
  1075. if (vsnode->_is_output_port_expanded(i)) {
  1076. switch (vsnode->get_output_port_type(i)) {
  1077. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  1078. port_offset++;
  1079. valid_left = (i + 1) < vsnode->get_input_port_count();
  1080. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1081. if (valid_left) {
  1082. port_left = vsnode->get_input_port_type(i + 1);
  1083. }
  1084. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]);
  1085. port_offset++;
  1086. valid_left = (i + 2) < vsnode->get_input_port_count();
  1087. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1088. if (valid_left) {
  1089. port_left = vsnode->get_input_port_type(i + 2);
  1090. }
  1091. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]);
  1092. expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_2D;
  1093. } break;
  1094. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  1095. port_offset++;
  1096. valid_left = (i + 1) < vsnode->get_input_port_count();
  1097. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1098. if (valid_left) {
  1099. port_left = vsnode->get_input_port_type(i + 1);
  1100. }
  1101. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]);
  1102. port_offset++;
  1103. valid_left = (i + 2) < vsnode->get_input_port_count();
  1104. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1105. if (valid_left) {
  1106. port_left = vsnode->get_input_port_type(i + 2);
  1107. }
  1108. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]);
  1109. port_offset++;
  1110. valid_left = (i + 3) < vsnode->get_input_port_count();
  1111. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1112. if (valid_left) {
  1113. port_left = vsnode->get_input_port_type(i + 3);
  1114. }
  1115. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]);
  1116. expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_3D;
  1117. } break;
  1118. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  1119. port_offset++;
  1120. valid_left = (i + 1) < vsnode->get_input_port_count();
  1121. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1122. if (valid_left) {
  1123. port_left = vsnode->get_input_port_type(i + 1);
  1124. }
  1125. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]);
  1126. port_offset++;
  1127. valid_left = (i + 2) < vsnode->get_input_port_count();
  1128. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1129. if (valid_left) {
  1130. port_left = vsnode->get_input_port_type(i + 2);
  1131. }
  1132. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]);
  1133. port_offset++;
  1134. valid_left = (i + 3) < vsnode->get_input_port_count();
  1135. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1136. if (valid_left) {
  1137. port_left = vsnode->get_input_port_type(i + 3);
  1138. }
  1139. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]);
  1140. port_offset++;
  1141. valid_left = (i + 4) < vsnode->get_input_port_count();
  1142. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1143. if (valid_left) {
  1144. port_left = vsnode->get_input_port_type(i + 4);
  1145. }
  1146. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[3]);
  1147. expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_4D;
  1148. } break;
  1149. default:
  1150. break;
  1151. }
  1152. }
  1153. }
  1154. }
  1155. bool has_relative_parameter_instances = false;
  1156. if (vsnode->get_output_port_for_preview() >= 0) {
  1157. has_relative_parameter_instances = is_node_has_parameter_instances_relatively(p_type, p_id);
  1158. show_port_preview(p_type, p_id, vsnode->get_output_port_for_preview(), !has_relative_parameter_instances);
  1159. } else if (!is_reroute) {
  1160. offset = memnew(Control);
  1161. offset->set_custom_minimum_size(Size2(0, 4 * EDSCALE));
  1162. node->add_child(offset);
  1163. }
  1164. String error = vsnode->get_warning(mode, p_type);
  1165. if (has_relative_parameter_instances) {
  1166. error += "\n" + TTR("The 2D preview cannot correctly show the result retrieved from instance parameter.");
  1167. }
  1168. if (!error.is_empty()) {
  1169. Label *error_label = memnew(Label);
  1170. error_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  1171. error_label->add_theme_color_override(SceneStringName(font_color), editor->get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
  1172. error_label->set_text(error);
  1173. error_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  1174. node->add_child(error_label);
  1175. }
  1176. if (is_expression) {
  1177. CodeEdit *expression_box = memnew(CodeEdit);
  1178. Ref<CodeHighlighter> expression_syntax_highlighter;
  1179. expression_syntax_highlighter.instantiate();
  1180. expression_node->set_ctrl_pressed(expression_box, 0);
  1181. expression_box->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1182. node->add_child(expression_box);
  1183. register_expression_edit(p_id, expression_box);
  1184. Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color");
  1185. Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color");
  1186. Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
  1187. Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color");
  1188. Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
  1189. Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color");
  1190. Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color");
  1191. Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color");
  1192. Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color");
  1193. expression_box->set_syntax_highlighter(expression_syntax_highlighter);
  1194. expression_box->add_theme_color_override("background_color", background_color);
  1195. for (const String &E : editor->keyword_list) {
  1196. if (ShaderLanguage::is_control_flow_keyword(E)) {
  1197. expression_syntax_highlighter->add_keyword_color(E, control_flow_keyword_color);
  1198. } else {
  1199. expression_syntax_highlighter->add_keyword_color(E, keyword_color);
  1200. }
  1201. }
  1202. expression_box->begin_bulk_theme_override();
  1203. expression_box->add_theme_font_override(SceneStringName(font), editor->get_theme_font(SNAME("expression"), EditorStringName(EditorFonts)));
  1204. expression_box->add_theme_font_size_override(SceneStringName(font_size), editor->get_theme_font_size(SNAME("expression_size"), EditorStringName(EditorFonts)));
  1205. expression_box->add_theme_color_override(SceneStringName(font_color), text_color);
  1206. expression_box->end_bulk_theme_override();
  1207. expression_syntax_highlighter->set_number_color(number_color);
  1208. expression_syntax_highlighter->set_symbol_color(symbol_color);
  1209. expression_syntax_highlighter->set_function_color(function_color);
  1210. expression_syntax_highlighter->set_member_variable_color(members_color);
  1211. expression_syntax_highlighter->add_color_region("/*", "*/", comment_color, false);
  1212. expression_syntax_highlighter->add_color_region("//", "", comment_color, true);
  1213. expression_box->clear_comment_delimiters();
  1214. expression_box->add_comment_delimiter("/*", "*/", false);
  1215. expression_box->add_comment_delimiter("//", "", true);
  1216. if (!expression_box->has_auto_brace_completion_open_key("/*")) {
  1217. expression_box->add_auto_brace_completion_pair("/*", "*/");
  1218. }
  1219. expression_box->set_text(expression);
  1220. expression_box->set_context_menu_enabled(false);
  1221. expression_box->set_draw_line_numbers(true);
  1222. expression_box->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_expression_focus_out).bind(expression_box, p_id));
  1223. }
  1224. }
  1225. void VisualShaderGraphPlugin::remove_node(VisualShader::Type p_type, int p_id, bool p_just_update) {
  1226. if (editor->get_current_shader_type() == p_type && links.has(p_id)) {
  1227. GraphEdit *graph_edit = editor->graph;
  1228. if (!graph_edit) {
  1229. return;
  1230. }
  1231. graph_edit->remove_child(links[p_id].graph_element);
  1232. memdelete(links[p_id].graph_element);
  1233. if (!p_just_update) {
  1234. links.erase(p_id);
  1235. }
  1236. }
  1237. }
  1238. void VisualShaderGraphPlugin::connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
  1239. GraphEdit *graph = editor->graph;
  1240. if (!graph) {
  1241. return;
  1242. }
  1243. if (visual_shader.is_valid() && editor->get_current_shader_type() == p_type) {
  1244. // Update reroute nodes since their port type might have changed.
  1245. Ref<VisualShaderNodeReroute> reroute_to = visual_shader->get_node(p_type, p_to_node);
  1246. Ref<VisualShaderNodeReroute> reroute_from = visual_shader->get_node(p_type, p_from_node);
  1247. if (reroute_to.is_valid() || reroute_from.is_valid()) {
  1248. update_reroute_nodes();
  1249. }
  1250. graph->connect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
  1251. connections.push_back({ p_from_node, p_from_port, p_to_node, p_to_port });
  1252. if (links[p_to_node].input_ports.has(p_to_port) && links[p_to_node].input_ports[p_to_port].default_input_button != nullptr) {
  1253. links[p_to_node].input_ports[p_to_port].default_input_button->hide();
  1254. }
  1255. }
  1256. }
  1257. void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
  1258. GraphEdit *graph = editor->graph;
  1259. if (!graph) {
  1260. return;
  1261. }
  1262. if (visual_shader.is_valid() && editor->get_current_shader_type() == p_type) {
  1263. graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
  1264. for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) {
  1265. if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
  1266. connections.erase(E);
  1267. break;
  1268. }
  1269. }
  1270. if (links[p_to_node].input_ports.has(p_to_port) && links[p_to_node].input_ports[p_to_port].default_input_button != nullptr && links[p_to_node].visual_node->get_input_port_default_value(p_to_port).get_type() != Variant::NIL) {
  1271. links[p_to_node].input_ports[p_to_port].default_input_button->show();
  1272. set_input_port_default_value(p_type, p_to_node, p_to_port, links[p_to_node].visual_node->get_input_port_default_value(p_to_port));
  1273. }
  1274. }
  1275. }
  1276. /////////////////
  1277. void VisualShaderEditedProperty::_bind_methods() {
  1278. ClassDB::bind_method(D_METHOD("set_edited_property", "value"), &VisualShaderEditedProperty::set_edited_property);
  1279. ClassDB::bind_method(D_METHOD("get_edited_property"), &VisualShaderEditedProperty::get_edited_property);
  1280. ADD_PROPERTY(PropertyInfo(Variant::NIL, "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_edited_property", "get_edited_property");
  1281. }
  1282. void VisualShaderEditedProperty::set_edited_property(const Variant &p_variant) {
  1283. edited_property = p_variant;
  1284. }
  1285. Variant VisualShaderEditedProperty::get_edited_property() const {
  1286. return edited_property;
  1287. }
  1288. /////////////////
  1289. Vector2 VisualShaderEditor::selection_center;
  1290. List<VisualShaderEditor::CopyItem> VisualShaderEditor::copy_items_buffer;
  1291. List<VisualShader::Connection> VisualShaderEditor::copy_connections_buffer;
  1292. void VisualShaderEditor::edit_shader(const Ref<Shader> &p_shader) {
  1293. shader_fully_loaded = false;
  1294. bool changed = false;
  1295. VisualShader *visual_shader_ptr = Object::cast_to<VisualShader>(p_shader.ptr());
  1296. if (visual_shader_ptr) {
  1297. if (visual_shader.is_null()) {
  1298. changed = true;
  1299. } else {
  1300. if (visual_shader.ptr() != visual_shader_ptr) {
  1301. changed = true;
  1302. }
  1303. }
  1304. visual_shader = p_shader;
  1305. graph_plugin->register_shader(visual_shader.ptr());
  1306. visual_shader->connect_changed(callable_mp(this, &VisualShaderEditor::_update_preview));
  1307. _set_mode(visual_shader->get_mode());
  1308. preview_material->set_shader(visual_shader);
  1309. _update_nodes();
  1310. } else {
  1311. if (visual_shader.is_valid()) {
  1312. visual_shader->disconnect_changed(callable_mp(this, &VisualShaderEditor::_update_preview));
  1313. }
  1314. visual_shader.unref();
  1315. }
  1316. if (visual_shader.is_null()) {
  1317. hide();
  1318. } else {
  1319. if (changed) { // to avoid tree collapse
  1320. _update_varying_tree();
  1321. _update_options_menu();
  1322. _update_preview();
  1323. _update_graph();
  1324. callable_mp(this, &VisualShaderEditor::_restore_editor_state).call_deferred();
  1325. }
  1326. }
  1327. }
  1328. void VisualShaderEditor::use_menu_bar_items(MenuButton *p_file_menu, Button *p_make_floating) {
  1329. p_file_menu->set_switch_on_hover(false);
  1330. toolbar_hflow->add_child(p_file_menu);
  1331. toolbar_hflow->move_child(p_file_menu, 2); // Toggle Files Panel button + separator.
  1332. toolbar_hflow->add_child(p_make_floating);
  1333. }
  1334. void VisualShaderEditor::apply_shaders() {
  1335. // Stub. TODO: Implement apply_shaders in visual shaders for parity with text shaders.
  1336. }
  1337. bool VisualShaderEditor::is_unsaved() const {
  1338. // Stub. TODO: Implement is_unsaved in visual shaders for parity with text shaders.
  1339. return false;
  1340. }
  1341. void VisualShaderEditor::save_external_data(const String &p_str) {
  1342. ResourceSaver::save(visual_shader, visual_shader->get_path());
  1343. }
  1344. void VisualShaderEditor::validate_script() {
  1345. if (visual_shader.is_valid()) {
  1346. _update_nodes();
  1347. }
  1348. }
  1349. void VisualShaderEditor::save_editor_layout() {
  1350. const String id_string = _get_cache_id_string();
  1351. const String offset_cache_key = _get_cache_key("offset");
  1352. const String zoom_cache_key = _get_cache_key("zoom");
  1353. vs_editor_cache->set_value(id_string, offset_cache_key, graph->get_scroll_offset() / EDSCALE);
  1354. vs_editor_cache->set_value(id_string, zoom_cache_key, graph->get_zoom());
  1355. vs_editor_cache->save(EditorPaths::get_singleton()->get_project_settings_dir().path_join("vs_editor_cache.cfg"));
  1356. }
  1357. void VisualShaderEditor::set_current_shader_type(VisualShader::Type p_type) {
  1358. current_type = p_type;
  1359. const String id_string = _get_cache_id_string();
  1360. vs_editor_cache->set_value(id_string, "edited_type", p_type);
  1361. vs_editor_cache->save(EditorPaths::get_singleton()->get_project_settings_dir().path_join("vs_editor_cache.cfg"));
  1362. const String offset_cache_key = _get_cache_key("offset");
  1363. const String zoom_cache_key = _get_cache_key("zoom");
  1364. const Vector2 saved_scroll_offset = vs_editor_cache->get_value(id_string, offset_cache_key, Vector2());
  1365. const real_t saved_zoom = vs_editor_cache->get_value(id_string, zoom_cache_key, 1.0);
  1366. graph->set_scroll_offset(saved_scroll_offset);
  1367. graph->set_zoom(saved_zoom);
  1368. }
  1369. VisualShader::Type VisualShaderEditor::get_current_shader_type() const {
  1370. return current_type;
  1371. }
  1372. void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
  1373. if (plugins.has(p_plugin)) {
  1374. return;
  1375. }
  1376. plugins.push_back(p_plugin);
  1377. }
  1378. void VisualShaderEditor::remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
  1379. plugins.erase(p_plugin);
  1380. }
  1381. void VisualShaderEditor::clear_custom_types() {
  1382. for (int i = 0; i < add_options.size(); i++) {
  1383. if (add_options[i].is_custom) {
  1384. add_options.remove_at(i);
  1385. i--;
  1386. }
  1387. }
  1388. }
  1389. void VisualShaderEditor::add_custom_type(const String &p_name, const String &p_type, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend) {
  1390. ERR_FAIL_COND(!p_name.is_valid_ascii_identifier());
  1391. ERR_FAIL_COND(p_type.is_empty() && p_script.is_null());
  1392. for (int i = 0; i < add_options.size(); i++) {
  1393. const AddOption &op = add_options[i];
  1394. if (op.is_custom) {
  1395. if (!p_type.is_empty()) {
  1396. if (op.type == p_type) {
  1397. return;
  1398. }
  1399. } else if (op.script == p_script) {
  1400. return;
  1401. }
  1402. }
  1403. }
  1404. AddOption ao;
  1405. ao.name = p_name;
  1406. ao.type = p_type;
  1407. ao.script = p_script;
  1408. ao.return_type = p_return_icon_type;
  1409. ao.description = p_description;
  1410. ao.category = p_category;
  1411. ao.highend = p_highend;
  1412. ao.is_custom = true;
  1413. ao.is_native = !p_type.is_empty();
  1414. bool begin = false;
  1415. String root = p_category.get_slicec('/', 0);
  1416. for (int i = 0; i < add_options.size(); i++) {
  1417. if (add_options[i].is_custom) {
  1418. if (add_options[i].category == root) {
  1419. if (!begin) {
  1420. begin = true;
  1421. }
  1422. } else {
  1423. if (begin) {
  1424. add_options.insert(i, ao);
  1425. return;
  1426. }
  1427. }
  1428. }
  1429. }
  1430. add_options.push_back(ao);
  1431. }
  1432. Dictionary VisualShaderEditor::get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node) {
  1433. Dictionary dict;
  1434. dict["script"] = p_custom_node->get_script();
  1435. dict["name"] = p_custom_node->_get_name();
  1436. dict["description"] = p_custom_node->_get_description();
  1437. dict["return_icon_type"] = p_custom_node->_get_return_icon_type();
  1438. dict["highend"] = p_custom_node->_is_highend();
  1439. String category = p_custom_node->_get_category();
  1440. category = category.rstrip("/");
  1441. category = category.lstrip("/");
  1442. category = "Addons/" + category;
  1443. if (p_custom_node->has_method("_get_subcategory")) {
  1444. String subcategory = (String)p_custom_node->call("_get_subcategory");
  1445. if (!subcategory.is_empty()) {
  1446. category += "/" + subcategory;
  1447. }
  1448. }
  1449. dict["category"] = category;
  1450. return dict;
  1451. }
  1452. void VisualShaderEditor::_get_current_mode_limits(int &r_begin_type, int &r_end_type) const {
  1453. switch (visual_shader->get_mode()) {
  1454. case Shader::MODE_CANVAS_ITEM:
  1455. case Shader::MODE_SPATIAL: {
  1456. r_begin_type = VisualShader::TYPE_VERTEX;
  1457. r_end_type = VisualShader::TYPE_START;
  1458. } break;
  1459. case Shader::MODE_PARTICLES: {
  1460. r_begin_type = VisualShader::TYPE_START;
  1461. r_end_type = VisualShader::TYPE_SKY;
  1462. } break;
  1463. case Shader::MODE_SKY: {
  1464. r_begin_type = VisualShader::TYPE_SKY;
  1465. r_end_type = VisualShader::TYPE_FOG;
  1466. } break;
  1467. case Shader::MODE_FOG: {
  1468. r_begin_type = VisualShader::TYPE_FOG;
  1469. r_end_type = VisualShader::TYPE_MAX;
  1470. } break;
  1471. default: {
  1472. } break;
  1473. }
  1474. }
  1475. void VisualShaderEditor::_script_created(const Ref<Script> &p_script) {
  1476. if (p_script.is_null() || p_script->get_instance_base_type() != "VisualShaderNodeCustom") {
  1477. return;
  1478. }
  1479. Ref<VisualShaderNodeCustom> ref;
  1480. ref.instantiate();
  1481. ref->set_script(p_script);
  1482. Dictionary dict = get_custom_node_data(ref);
  1483. add_custom_type(dict["name"], String(), dict["script"], dict["description"], dict["return_icon_type"], dict["category"], dict["highend"]);
  1484. _update_options_menu();
  1485. }
  1486. void VisualShaderEditor::_update_custom_script(const Ref<Script> &p_script) {
  1487. if (p_script.is_null() || p_script->get_instance_base_type() != "VisualShaderNodeCustom") {
  1488. return;
  1489. }
  1490. Ref<VisualShaderNodeCustom> ref;
  1491. ref.instantiate();
  1492. ref->set_script(p_script);
  1493. if (!ref->is_available(visual_shader->get_mode(), get_current_shader_type())) {
  1494. for (int i = 0; i < add_options.size(); i++) {
  1495. if (add_options[i].is_custom && add_options[i].script == p_script) {
  1496. add_options.remove_at(i);
  1497. _update_options_menu();
  1498. // TODO: Make indication for the existed custom nodes with that script on graph to be disabled.
  1499. break;
  1500. }
  1501. }
  1502. return;
  1503. }
  1504. Dictionary dict = get_custom_node_data(ref);
  1505. bool found_type = false;
  1506. bool need_rebuild = false;
  1507. for (int i = custom_node_option_idx; i < add_options.size(); i++) {
  1508. if (add_options[i].script == p_script) {
  1509. found_type = true;
  1510. add_options.write[i].name = dict["name"];
  1511. add_options.write[i].return_type = dict["return_icon_type"];
  1512. add_options.write[i].description = dict["description"];
  1513. add_options.write[i].category = dict["category"];
  1514. add_options.write[i].highend = dict["highend"];
  1515. int begin_type = 0;
  1516. int end_type = 0;
  1517. _get_current_mode_limits(begin_type, end_type);
  1518. for (int t = begin_type; t < end_type; t++) {
  1519. VisualShader::Type type = (VisualShader::Type)t;
  1520. Vector<int> nodes = visual_shader->get_node_list(type);
  1521. List<VisualShader::Connection> node_connections;
  1522. visual_shader->get_node_connections(type, &node_connections);
  1523. List<VisualShader::Connection> custom_node_input_connections;
  1524. List<VisualShader::Connection> custom_node_output_connections;
  1525. for (const VisualShader::Connection &E : node_connections) {
  1526. int from = E.from_node;
  1527. int from_port = E.from_port;
  1528. int to = E.to_node;
  1529. int to_port = E.to_port;
  1530. if (graph_plugin->get_node_script(from) == p_script) {
  1531. custom_node_output_connections.push_back({ from, from_port, to, to_port });
  1532. } else if (graph_plugin->get_node_script(to) == p_script) {
  1533. custom_node_input_connections.push_back({ from, from_port, to, to_port });
  1534. }
  1535. }
  1536. for (int node_id : nodes) {
  1537. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  1538. if (vsnode.is_null()) {
  1539. continue;
  1540. }
  1541. Ref<VisualShaderNodeCustom> custom_node = vsnode;
  1542. if (custom_node.is_null() || custom_node->get_script() != p_script) {
  1543. continue;
  1544. }
  1545. need_rebuild = true;
  1546. // Removes invalid connections.
  1547. {
  1548. int prev_input_port_count = custom_node->get_input_port_count();
  1549. int prev_output_port_count = custom_node->get_output_port_count();
  1550. custom_node->update_ports();
  1551. int input_port_count = custom_node->get_input_port_count();
  1552. int output_port_count = custom_node->get_output_port_count();
  1553. if (output_port_count != prev_output_port_count) {
  1554. for (const VisualShader::Connection &E : custom_node_output_connections) {
  1555. int from = E.from_node;
  1556. int from_idx = E.from_port;
  1557. int to = E.to_node;
  1558. int to_idx = E.to_port;
  1559. if (from_idx >= output_port_count) {
  1560. visual_shader->disconnect_nodes(type, from, from_idx, to, to_idx);
  1561. graph_plugin->disconnect_nodes(type, from, from_idx, to, to_idx);
  1562. }
  1563. }
  1564. }
  1565. if (input_port_count != prev_input_port_count) {
  1566. for (const VisualShader::Connection &E : custom_node_input_connections) {
  1567. int from = E.from_node;
  1568. int from_idx = E.from_port;
  1569. int to = E.to_node;
  1570. int to_idx = E.to_port;
  1571. if (to_idx >= input_port_count) {
  1572. visual_shader->disconnect_nodes(type, from, from_idx, to, to_idx);
  1573. graph_plugin->disconnect_nodes(type, from, from_idx, to, to_idx);
  1574. }
  1575. }
  1576. }
  1577. }
  1578. graph_plugin->update_node(type, node_id);
  1579. }
  1580. }
  1581. break;
  1582. }
  1583. }
  1584. if (!found_type) {
  1585. add_custom_type(dict["name"], String(), dict["script"], dict["description"], dict["return_icon_type"], dict["category"], dict["highend"]);
  1586. }
  1587. // To prevent updating options multiple times when multiple scripts are saved.
  1588. if (!_block_update_options_menu) {
  1589. _block_update_options_menu = true;
  1590. callable_mp(this, &VisualShaderEditor::_update_options_menu_deferred);
  1591. }
  1592. // To prevent rebuilding the shader multiple times when multiple scripts are saved.
  1593. if (need_rebuild && !_block_rebuild_shader) {
  1594. _block_rebuild_shader = true;
  1595. callable_mp(this, &VisualShaderEditor::_rebuild_shader_deferred);
  1596. }
  1597. }
  1598. void VisualShaderEditor::_resource_saved(const Ref<Resource> &p_resource) {
  1599. _update_custom_script(Ref<Script>(p_resource.ptr()));
  1600. }
  1601. void VisualShaderEditor::_resources_removed() {
  1602. bool has_any_instance = false;
  1603. for (const Ref<Script> &scr : custom_scripts_to_delete) {
  1604. for (int i = custom_node_option_idx; i < add_options.size(); i++) {
  1605. if (add_options[i].script == scr) {
  1606. add_options.remove_at(i);
  1607. // Removes all node instances using that script from the graph.
  1608. {
  1609. int begin_type = 0;
  1610. int end_type = 0;
  1611. _get_current_mode_limits(begin_type, end_type);
  1612. for (int t = begin_type; t < end_type; t++) {
  1613. VisualShader::Type type = (VisualShader::Type)t;
  1614. List<VisualShader::Connection> node_connections;
  1615. visual_shader->get_node_connections(type, &node_connections);
  1616. for (const VisualShader::Connection &E : node_connections) {
  1617. int from = E.from_node;
  1618. int from_port = E.from_port;
  1619. int to = E.to_node;
  1620. int to_port = E.to_port;
  1621. if (graph_plugin->get_node_script(from) == scr || graph_plugin->get_node_script(to) == scr) {
  1622. visual_shader->disconnect_nodes(type, from, from_port, to, to_port);
  1623. graph_plugin->disconnect_nodes(type, from, from_port, to, to_port);
  1624. }
  1625. }
  1626. Vector<int> nodes = visual_shader->get_node_list(type);
  1627. for (int node_id : nodes) {
  1628. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  1629. if (vsnode.is_null()) {
  1630. continue;
  1631. }
  1632. Ref<VisualShaderNodeCustom> custom_node = vsnode;
  1633. if (custom_node.is_null() || custom_node->get_script() != scr) {
  1634. continue;
  1635. }
  1636. visual_shader->remove_node(type, node_id);
  1637. graph_plugin->remove_node(type, node_id, false);
  1638. has_any_instance = true;
  1639. }
  1640. }
  1641. }
  1642. break;
  1643. }
  1644. }
  1645. }
  1646. if (has_any_instance) {
  1647. EditorUndoRedoManager::get_singleton()->clear_history(); // Need to clear undo history, otherwise it may lead to hard-detected errors and crashes (since the script was removed).
  1648. ResourceSaver::save(visual_shader, visual_shader->get_path());
  1649. }
  1650. _update_options_menu();
  1651. custom_scripts_to_delete.clear();
  1652. pending_custom_scripts_to_delete = false;
  1653. }
  1654. void VisualShaderEditor::_resource_removed(const Ref<Resource> &p_resource) {
  1655. Ref<Script> scr = Ref<Script>(p_resource.ptr());
  1656. if (scr.is_null() || scr->get_instance_base_type() != "VisualShaderNodeCustom") {
  1657. return;
  1658. }
  1659. custom_scripts_to_delete.push_back(scr);
  1660. if (!pending_custom_scripts_to_delete) {
  1661. pending_custom_scripts_to_delete = true;
  1662. callable_mp(this, &VisualShaderEditor::_resources_removed).call_deferred();
  1663. }
  1664. }
  1665. void VisualShaderEditor::_update_options_menu_deferred() {
  1666. _update_options_menu();
  1667. _block_update_options_menu = false;
  1668. }
  1669. void VisualShaderEditor::_rebuild_shader_deferred() {
  1670. if (visual_shader.is_valid()) {
  1671. visual_shader->rebuild();
  1672. }
  1673. _block_rebuild_shader = false;
  1674. }
  1675. bool VisualShaderEditor::_is_available(int p_mode) {
  1676. int current_mode = edit_type->get_selected();
  1677. if (p_mode != -1) {
  1678. switch (current_mode) {
  1679. case 0: // Vertex / Emit
  1680. current_mode = 1;
  1681. break;
  1682. case 1: // Fragment / Process
  1683. current_mode = 2;
  1684. break;
  1685. case 2: // Light / Collide
  1686. current_mode = 4;
  1687. break;
  1688. default:
  1689. break;
  1690. }
  1691. }
  1692. return (p_mode == -1 || (p_mode & current_mode) != 0);
  1693. }
  1694. bool VisualShaderEditor::_update_preview_parameter_tree() {
  1695. bool found = false;
  1696. bool use_filter = !param_filter_name.is_empty();
  1697. parameters->clear();
  1698. TreeItem *root = parameters->create_item();
  1699. for (const KeyValue<String, PropertyInfo> &prop : parameter_props) {
  1700. String param_name = prop.value.name;
  1701. if (use_filter && !param_name.containsn(param_filter_name)) {
  1702. continue;
  1703. }
  1704. TreeItem *item = parameters->create_item(root);
  1705. item->set_text(0, param_name);
  1706. item->set_meta("id", param_name);
  1707. if (param_name == selected_param_id) {
  1708. parameters->set_selected(item);
  1709. found = true;
  1710. }
  1711. if (prop.value.type == Variant::OBJECT) {
  1712. item->set_icon(0, get_editor_theme_icon(SNAME("ImageTexture")));
  1713. } else {
  1714. item->set_icon(0, get_editor_theme_icon(Variant::get_type_name(prop.value.type)));
  1715. }
  1716. }
  1717. return found;
  1718. }
  1719. void VisualShaderEditor::_preview_tools_menu_option(int p_idx) {
  1720. ShaderMaterial *src_mat = nullptr;
  1721. if (p_idx == COPY_PARAMS_FROM_MATERIAL || p_idx == PASTE_PARAMS_TO_MATERIAL) {
  1722. for (int i = EditorNode::get_singleton()->get_editor_selection_history()->get_path_size() - 1; i >= 0; i--) {
  1723. Object *object = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_selection_history()->get_path_object(i));
  1724. ShaderMaterial *src_mat2;
  1725. if (!object) {
  1726. continue;
  1727. }
  1728. if (object->has_method("get_material_override")) { // Trying to get material from MeshInstance.
  1729. src_mat2 = Object::cast_to<ShaderMaterial>(object->call("get_material_override"));
  1730. } else if (object->has_method("get_material")) { // From CanvasItem/Node2D.
  1731. src_mat2 = Object::cast_to<ShaderMaterial>(object->call("get_material"));
  1732. } else {
  1733. src_mat2 = Object::cast_to<ShaderMaterial>(object);
  1734. }
  1735. if (src_mat2 && src_mat2->get_shader().is_valid() && src_mat2->get_shader() == visual_shader) {
  1736. src_mat = src_mat2;
  1737. break;
  1738. }
  1739. }
  1740. }
  1741. switch (p_idx) {
  1742. case COPY_PARAMS_FROM_MATERIAL:
  1743. if (src_mat) {
  1744. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1745. undo_redo->create_action(TTR("Copy Preview Shader Parameters From Material"));
  1746. List<PropertyInfo> params;
  1747. preview_material->get_shader()->get_shader_uniform_list(&params);
  1748. for (const PropertyInfo &E : params) {
  1749. undo_redo->add_do_method(visual_shader.ptr(), "_set_preview_shader_parameter", E.name, src_mat->get_shader_parameter(E.name));
  1750. undo_redo->add_undo_method(visual_shader.ptr(), "_set_preview_shader_parameter", E.name, preview_material->get_shader_parameter(E.name));
  1751. }
  1752. undo_redo->commit_action();
  1753. }
  1754. break;
  1755. case PASTE_PARAMS_TO_MATERIAL:
  1756. if (src_mat) {
  1757. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1758. undo_redo->create_action(TTR("Paste Preview Shader Parameters To Material"));
  1759. List<PropertyInfo> params;
  1760. preview_material->get_shader()->get_shader_uniform_list(&params);
  1761. for (const PropertyInfo &E : params) {
  1762. undo_redo->add_do_method(src_mat, "set_shader_parameter", E.name, preview_material->get_shader_parameter(E.name));
  1763. undo_redo->add_undo_method(src_mat, "set_shader_parameter", E.name, src_mat->get_shader_parameter(E.name));
  1764. }
  1765. undo_redo->commit_action();
  1766. }
  1767. break;
  1768. default:
  1769. break;
  1770. }
  1771. }
  1772. void VisualShaderEditor::_clear_preview_param() {
  1773. selected_param_id = "";
  1774. current_prop = nullptr;
  1775. if (param_vbox2->get_child_count() > 0) {
  1776. param_vbox2->remove_child(param_vbox2->get_child(0));
  1777. }
  1778. param_vbox->hide();
  1779. }
  1780. void VisualShaderEditor::_update_preview_parameter_list() {
  1781. material_editor->edit(preview_material.ptr(), env);
  1782. List<PropertyInfo> properties;
  1783. RenderingServer::get_singleton()->get_shader_parameter_list(visual_shader->get_rid(), &properties);
  1784. HashSet<String> params_to_remove;
  1785. for (const KeyValue<String, PropertyInfo> &E : parameter_props) {
  1786. params_to_remove.insert(E.key);
  1787. }
  1788. parameter_props.clear();
  1789. for (const PropertyInfo &prop : properties) {
  1790. String param_name = prop.name;
  1791. if (visual_shader->_has_preview_shader_parameter(param_name)) {
  1792. preview_material->set_shader_parameter(param_name, visual_shader->_get_preview_shader_parameter(param_name));
  1793. } else {
  1794. preview_material->set_shader_parameter(param_name, RenderingServer::get_singleton()->shader_get_parameter_default(visual_shader->get_rid(), param_name));
  1795. }
  1796. parameter_props.insert(param_name, prop);
  1797. params_to_remove.erase(param_name);
  1798. if (param_name == selected_param_id) {
  1799. current_prop->update_property();
  1800. current_prop->update_editor_property_status();
  1801. current_prop->update_cache();
  1802. }
  1803. }
  1804. _update_preview_parameter_tree();
  1805. // Removes invalid parameters.
  1806. for (const String &param_name : params_to_remove) {
  1807. preview_material->set_shader_parameter(param_name, Variant());
  1808. if (visual_shader->_has_preview_shader_parameter(param_name)) {
  1809. visual_shader->_set_preview_shader_parameter(param_name, Variant());
  1810. }
  1811. if (param_name == selected_param_id) {
  1812. _clear_preview_param();
  1813. }
  1814. }
  1815. }
  1816. void VisualShaderEditor::_update_nodes() {
  1817. clear_custom_types();
  1818. Dictionary added;
  1819. // Add GDScript classes.
  1820. {
  1821. LocalVector<StringName> class_list;
  1822. ScriptServer::get_global_class_list(class_list);
  1823. for (const StringName &class_name : class_list) {
  1824. if (ScriptServer::get_global_class_native_base(class_name) == "VisualShaderNodeCustom") {
  1825. String script_path = ScriptServer::get_global_class_path(class_name);
  1826. Ref<Resource> res = ResourceLoader::load(script_path);
  1827. ERR_CONTINUE(res.is_null());
  1828. ERR_CONTINUE(!res->is_class("Script"));
  1829. Ref<Script> scr = Ref<Script>(res);
  1830. Ref<VisualShaderNodeCustom> ref;
  1831. ref.instantiate();
  1832. ref->set_script(scr);
  1833. if (!ref->is_available(visual_shader->get_mode(), get_current_shader_type())) {
  1834. continue;
  1835. }
  1836. Dictionary dict = get_custom_node_data(ref);
  1837. dict["type"] = String();
  1838. String key;
  1839. key = String(dict["category"]) + "/" + String(dict["name"]);
  1840. added[key] = dict;
  1841. }
  1842. }
  1843. }
  1844. // Add GDExtension classes.
  1845. {
  1846. LocalVector<StringName> class_list;
  1847. ClassDB::get_class_list(class_list);
  1848. for (const StringName &class_name : class_list) {
  1849. if (ClassDB::get_parent_class(class_name) == "VisualShaderNodeCustom") {
  1850. Object *instance = ClassDB::instantiate(class_name);
  1851. Ref<VisualShaderNodeCustom> ref = Object::cast_to<VisualShaderNodeCustom>(instance);
  1852. ERR_CONTINUE(ref.is_null());
  1853. if (!ref->is_available(visual_shader->get_mode(), get_current_shader_type())) {
  1854. continue;
  1855. }
  1856. Dictionary dict = get_custom_node_data(ref);
  1857. dict["type"] = class_name;
  1858. dict["script"] = Ref<Script>();
  1859. String key;
  1860. key = String(dict["category"]) + "/" + String(dict["name"]);
  1861. added[key] = dict;
  1862. }
  1863. }
  1864. }
  1865. // Disables not-supported copied items.
  1866. {
  1867. for (CopyItem &item : copy_items_buffer) {
  1868. Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(item.node.ptr());
  1869. if (custom.is_valid()) {
  1870. if (!custom->is_available(visual_shader->get_mode(), get_current_shader_type())) {
  1871. item.disabled = true;
  1872. } else {
  1873. item.disabled = false;
  1874. }
  1875. } else {
  1876. for (int i = 0; i < add_options.size(); i++) {
  1877. if (add_options[i].type == item.node->get_class_name()) {
  1878. if ((add_options[i].func != visual_shader->get_mode() && add_options[i].func != -1) || !_is_available(add_options[i].mode)) {
  1879. item.disabled = true;
  1880. } else {
  1881. item.disabled = false;
  1882. }
  1883. break;
  1884. }
  1885. }
  1886. }
  1887. }
  1888. }
  1889. LocalVector<Variant> keys = added.get_key_list();
  1890. keys.sort_custom<StringLikeVariantOrder>();
  1891. for (const Variant &key : keys) {
  1892. const Dictionary &value = (Dictionary)added[key];
  1893. add_custom_type(value["name"], value["type"], value["script"], value["description"], value["return_icon_type"], value["category"], value["highend"]);
  1894. }
  1895. _update_options_menu();
  1896. }
  1897. String VisualShaderEditor::_get_description(int p_idx) {
  1898. return add_options[p_idx].description;
  1899. }
  1900. void VisualShaderEditor::_update_options_menu() {
  1901. node_desc->set_text("");
  1902. highend_label->set_visible(false);
  1903. members_dialog->get_ok_button()->set_disabled(true);
  1904. members->clear();
  1905. TreeItem *root = members->create_item();
  1906. String filter = node_filter->get_text().strip_edges();
  1907. bool use_filter = !filter.is_empty();
  1908. bool is_first_item = true;
  1909. Color unsupported_color = get_theme_color(SNAME("error_color"), EditorStringName(Editor));
  1910. Color supported_color = get_theme_color(SNAME("warning_color"), EditorStringName(Editor));
  1911. static bool low_driver = GLOBAL_GET("rendering/renderer/rendering_method") == "gl_compatibility";
  1912. HashMap<String, TreeItem *> folders;
  1913. int current_func = -1;
  1914. if (visual_shader.is_valid()) {
  1915. current_func = visual_shader->get_mode();
  1916. }
  1917. Vector<AddOption> custom_options;
  1918. Vector<AddOption> embedded_options;
  1919. static Vector<String> type_filter_exceptions;
  1920. if (type_filter_exceptions.is_empty()) {
  1921. type_filter_exceptions.append("VisualShaderNodeExpression");
  1922. type_filter_exceptions.append("VisualShaderNodeReroute");
  1923. }
  1924. for (int i = 0; i < add_options.size(); i++) {
  1925. if (!use_filter || add_options[i].name.containsn(filter)) {
  1926. // port type filtering
  1927. if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX || members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1928. Ref<VisualShaderNode> vsn;
  1929. int check_result = 0;
  1930. if (!add_options[i].is_custom) {
  1931. vsn = Ref<VisualShaderNode>(Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[i].type)));
  1932. if (vsn.is_null()) {
  1933. continue;
  1934. }
  1935. if (type_filter_exceptions.has(add_options[i].type)) {
  1936. check_result = 1;
  1937. }
  1938. Ref<VisualShaderNodeInput> input = Object::cast_to<VisualShaderNodeInput>(vsn.ptr());
  1939. if (input.is_valid()) {
  1940. input->set_shader_mode(visual_shader->get_mode());
  1941. input->set_shader_type(get_current_shader_type());
  1942. if (!add_options[i].ops.is_empty() && add_options[i].ops[0].is_string()) {
  1943. input->set_input_name((String)add_options[i].ops[0]);
  1944. }
  1945. }
  1946. Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(vsn.ptr());
  1947. if (expression.is_valid()) {
  1948. if (members_input_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) {
  1949. check_result = -1; // expressions creates a port with required type automatically (except for sampler output)
  1950. }
  1951. }
  1952. Ref<VisualShaderNodeParameterRef> parameter_ref = Object::cast_to<VisualShaderNodeParameterRef>(vsn.ptr());
  1953. if (parameter_ref.is_valid() && parameter_ref->is_shader_valid()) {
  1954. check_result = -1;
  1955. if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1956. for (int j = 0; j < parameter_ref->get_parameters_count(); j++) {
  1957. if (visual_shader->is_port_types_compatible(parameter_ref->get_port_type_by_index(j), members_input_port_type)) {
  1958. check_result = 1;
  1959. break;
  1960. }
  1961. }
  1962. }
  1963. }
  1964. } else {
  1965. check_result = 1;
  1966. }
  1967. if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1968. if (check_result == 0) {
  1969. for (int j = 0; j < vsn->get_input_port_count(); j++) {
  1970. if (visual_shader->is_port_types_compatible(vsn->get_input_port_type(j), members_output_port_type)) {
  1971. check_result = 1;
  1972. break;
  1973. }
  1974. }
  1975. }
  1976. if (check_result != 1) {
  1977. continue;
  1978. }
  1979. }
  1980. if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1981. if (check_result == 0) {
  1982. for (int j = 0; j < vsn->get_output_port_count(); j++) {
  1983. if (visual_shader->is_port_types_compatible(vsn->get_output_port_type(j), members_input_port_type)) {
  1984. check_result = 1;
  1985. break;
  1986. }
  1987. }
  1988. }
  1989. if (check_result != 1) {
  1990. continue;
  1991. }
  1992. }
  1993. }
  1994. if ((add_options[i].func != current_func && add_options[i].func != -1) || !_is_available(add_options[i].mode)) {
  1995. continue;
  1996. }
  1997. add_options[i].temp_idx = i; // save valid id
  1998. if (add_options[i].is_custom) {
  1999. custom_options.push_back(add_options[i]);
  2000. } else {
  2001. embedded_options.push_back(add_options[i]);
  2002. }
  2003. }
  2004. }
  2005. Vector<AddOption> options;
  2006. SortArray<AddOption, _OptionComparator> sorter;
  2007. sorter.sort(custom_options.ptrw(), custom_options.size());
  2008. options.append_array(custom_options);
  2009. options.append_array(embedded_options);
  2010. for (int i = 0; i < options.size(); i++) {
  2011. String path = options[i].category;
  2012. Vector<String> subfolders = path.split("/");
  2013. TreeItem *category = nullptr;
  2014. if (!folders.has(path)) {
  2015. category = root;
  2016. String path_temp = "";
  2017. for (int j = 0; j < subfolders.size(); j++) {
  2018. path_temp += subfolders[j];
  2019. if (!folders.has(path_temp)) {
  2020. category = members->create_item(category);
  2021. category->set_selectable(0, false);
  2022. category->set_collapsed(!use_filter);
  2023. category->set_text(0, subfolders[j]);
  2024. folders.insert(path_temp, category);
  2025. } else {
  2026. category = folders[path_temp];
  2027. }
  2028. }
  2029. } else {
  2030. category = folders[path];
  2031. }
  2032. TreeItem *item = members->create_item(category);
  2033. if (options[i].highend && low_driver) {
  2034. item->set_custom_color(0, unsupported_color);
  2035. } else if (options[i].highend) {
  2036. item->set_custom_color(0, supported_color);
  2037. }
  2038. item->set_text(0, options[i].name);
  2039. if (is_first_item && use_filter) {
  2040. item->select(0);
  2041. node_desc->set_text(options[i].description);
  2042. is_first_item = false;
  2043. members_dialog->get_ok_button()->set_disabled(false);
  2044. }
  2045. switch (options[i].return_type) {
  2046. case VisualShaderNode::PORT_TYPE_SCALAR:
  2047. item->set_icon(0, get_editor_theme_icon(SNAME("float")));
  2048. break;
  2049. case VisualShaderNode::PORT_TYPE_SCALAR_INT:
  2050. item->set_icon(0, get_editor_theme_icon(SNAME("int")));
  2051. break;
  2052. case VisualShaderNode::PORT_TYPE_SCALAR_UINT:
  2053. item->set_icon(0, get_editor_theme_icon(SNAME("uint")));
  2054. break;
  2055. case VisualShaderNode::PORT_TYPE_VECTOR_2D:
  2056. item->set_icon(0, get_editor_theme_icon(SNAME("Vector2")));
  2057. break;
  2058. case VisualShaderNode::PORT_TYPE_VECTOR_3D:
  2059. item->set_icon(0, get_editor_theme_icon(SNAME("Vector3")));
  2060. break;
  2061. case VisualShaderNode::PORT_TYPE_VECTOR_4D:
  2062. item->set_icon(0, get_editor_theme_icon(SNAME("Vector4")));
  2063. break;
  2064. case VisualShaderNode::PORT_TYPE_BOOLEAN:
  2065. item->set_icon(0, get_editor_theme_icon(SNAME("bool")));
  2066. break;
  2067. case VisualShaderNode::PORT_TYPE_TRANSFORM:
  2068. item->set_icon(0, get_editor_theme_icon(SNAME("Transform3D")));
  2069. break;
  2070. case VisualShaderNode::PORT_TYPE_SAMPLER:
  2071. item->set_icon(0, get_editor_theme_icon(SNAME("ImageTexture")));
  2072. break;
  2073. default:
  2074. break;
  2075. }
  2076. item->set_meta("id", options[i].temp_idx);
  2077. }
  2078. }
  2079. void VisualShaderEditor::_set_mode(int p_which) {
  2080. if (p_which == VisualShader::MODE_SKY) {
  2081. edit_type_standard->set_visible(false);
  2082. edit_type_particles->set_visible(false);
  2083. edit_type_sky->set_visible(true);
  2084. edit_type_fog->set_visible(false);
  2085. edit_type = edit_type_sky;
  2086. custom_mode_box->set_visible(false);
  2087. varying_button->hide();
  2088. mode = MODE_FLAGS_SKY;
  2089. } else if (p_which == VisualShader::MODE_FOG) {
  2090. edit_type_standard->set_visible(false);
  2091. edit_type_particles->set_visible(false);
  2092. edit_type_sky->set_visible(false);
  2093. edit_type_fog->set_visible(true);
  2094. edit_type = edit_type_fog;
  2095. custom_mode_box->set_visible(false);
  2096. varying_button->hide();
  2097. mode = MODE_FLAGS_FOG;
  2098. } else if (p_which == VisualShader::MODE_PARTICLES) {
  2099. edit_type_standard->set_visible(false);
  2100. edit_type_particles->set_visible(true);
  2101. edit_type_sky->set_visible(false);
  2102. edit_type_fog->set_visible(false);
  2103. edit_type = edit_type_particles;
  2104. if ((edit_type->get_selected() + 3) > VisualShader::TYPE_PROCESS) {
  2105. custom_mode_box->set_visible(false);
  2106. } else {
  2107. custom_mode_box->set_visible(true);
  2108. }
  2109. varying_button->hide();
  2110. mode = MODE_FLAGS_PARTICLES;
  2111. } else {
  2112. edit_type_particles->set_visible(false);
  2113. edit_type_standard->set_visible(true);
  2114. edit_type_sky->set_visible(false);
  2115. edit_type_fog->set_visible(false);
  2116. edit_type = edit_type_standard;
  2117. custom_mode_box->set_visible(false);
  2118. varying_button->show();
  2119. mode = MODE_FLAGS_SPATIAL_CANVASITEM;
  2120. }
  2121. const String id_string = _get_cache_id_string();
  2122. int default_type = VisualShader::TYPE_VERTEX;
  2123. int upper_type = VisualShader::TYPE_START;
  2124. if (mode & MODE_FLAGS_PARTICLES) {
  2125. default_type = VisualShader::TYPE_START;
  2126. upper_type = VisualShader::TYPE_SKY;
  2127. } else if (mode & MODE_FLAGS_SKY) {
  2128. default_type = VisualShader::TYPE_SKY;
  2129. upper_type = VisualShader::TYPE_FOG;
  2130. } else if (mode & MODE_FLAGS_FOG) {
  2131. default_type = VisualShader::TYPE_FOG;
  2132. upper_type = VisualShader::TYPE_MAX;
  2133. }
  2134. int saved_type = vs_editor_cache->get_value(id_string, "edited_type", default_type);
  2135. if (saved_type >= upper_type || saved_type < default_type) {
  2136. saved_type = default_type;
  2137. }
  2138. if (mode & MODE_FLAGS_PARTICLES && saved_type - default_type >= 3) {
  2139. edit_type->select(saved_type - default_type - 3);
  2140. custom_mode_box->set_pressed(true);
  2141. } else {
  2142. edit_type->select(saved_type - default_type);
  2143. }
  2144. set_current_shader_type((VisualShader::Type)saved_type);
  2145. }
  2146. Size2 VisualShaderEditor::get_minimum_size() const {
  2147. return Size2(10, 200);
  2148. }
  2149. void VisualShaderEditor::update_toggle_files_button() {
  2150. ERR_FAIL_NULL(toggle_files_list);
  2151. bool forward = toggle_files_list->is_visible() == is_layout_rtl();
  2152. toggle_files_button->set_button_icon(get_editor_theme_icon(forward ? SNAME("Forward") : SNAME("Back")));
  2153. toggle_files_button->set_tooltip_text(vformat("%s (%s)", TTR("Toggle Files Panel"), ED_GET_SHORTCUT("script_editor/toggle_files_panel")->get_as_text()));
  2154. }
  2155. void VisualShaderEditor::_draw_color_over_button(Object *p_obj, Color p_color) {
  2156. Button *button = Object::cast_to<Button>(p_obj);
  2157. if (!button) {
  2158. return;
  2159. }
  2160. Ref<StyleBox> normal = get_theme_stylebox(CoreStringName(normal), SNAME("Button"));
  2161. button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
  2162. }
  2163. void VisualShaderEditor::_update_parameters(bool p_update_refs) {
  2164. VisualShaderNodeParameterRef::clear_parameters(visual_shader->get_rid());
  2165. for (int t = 0; t < VisualShader::TYPE_MAX; t++) {
  2166. Vector<int> tnodes = visual_shader->get_node_list((VisualShader::Type)t);
  2167. for (int i = 0; i < tnodes.size(); i++) {
  2168. Ref<VisualShaderNode> vsnode = visual_shader->get_node((VisualShader::Type)t, tnodes[i]);
  2169. Ref<VisualShaderNodeParameter> parameter = vsnode;
  2170. if (parameter.is_valid()) {
  2171. Ref<VisualShaderNodeFloatParameter> float_parameter = vsnode;
  2172. Ref<VisualShaderNodeIntParameter> int_parameter = vsnode;
  2173. Ref<VisualShaderNodeUIntParameter> uint_parameter = vsnode;
  2174. Ref<VisualShaderNodeVec2Parameter> vec2_parameter = vsnode;
  2175. Ref<VisualShaderNodeVec3Parameter> vec3_parameter = vsnode;
  2176. Ref<VisualShaderNodeVec4Parameter> vec4_parameter = vsnode;
  2177. Ref<VisualShaderNodeColorParameter> color_parameter = vsnode;
  2178. Ref<VisualShaderNodeBooleanParameter> boolean_parameter = vsnode;
  2179. Ref<VisualShaderNodeTransformParameter> transform_parameter = vsnode;
  2180. VisualShaderNodeParameterRef::ParameterType parameter_type;
  2181. if (float_parameter.is_valid()) {
  2182. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_FLOAT;
  2183. } else if (int_parameter.is_valid()) {
  2184. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_INT;
  2185. } else if (uint_parameter.is_valid()) {
  2186. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_UINT;
  2187. } else if (boolean_parameter.is_valid()) {
  2188. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_BOOLEAN;
  2189. } else if (vec2_parameter.is_valid()) {
  2190. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR2;
  2191. } else if (vec3_parameter.is_valid()) {
  2192. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR3;
  2193. } else if (vec4_parameter.is_valid()) {
  2194. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR4;
  2195. } else if (transform_parameter.is_valid()) {
  2196. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_TRANSFORM;
  2197. } else if (color_parameter.is_valid()) {
  2198. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_COLOR;
  2199. } else {
  2200. parameter_type = VisualShaderNodeParameterRef::UNIFORM_TYPE_SAMPLER;
  2201. }
  2202. VisualShaderNodeParameterRef::add_parameter(visual_shader->get_rid(), parameter->get_parameter_name(), parameter_type);
  2203. }
  2204. }
  2205. }
  2206. if (p_update_refs) {
  2207. graph_plugin->update_parameter_refs();
  2208. }
  2209. }
  2210. void VisualShaderEditor::_update_parameter_refs(HashSet<String> &p_deleted_names) {
  2211. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2212. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  2213. VisualShader::Type type = VisualShader::Type(i);
  2214. Vector<int> nodes = visual_shader->get_node_list(type);
  2215. for (int j = 0; j < nodes.size(); j++) {
  2216. if (j > 0) {
  2217. Ref<VisualShaderNodeParameterRef> ref = visual_shader->get_node(type, nodes[j]);
  2218. if (ref.is_valid()) {
  2219. if (p_deleted_names.has(ref->get_parameter_name())) {
  2220. undo_redo->add_do_method(ref.ptr(), "set_parameter_name", "[None]");
  2221. undo_redo->add_undo_method(ref.ptr(), "set_parameter_name", ref->get_parameter_name());
  2222. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", VisualShader::Type(i), nodes[j]);
  2223. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", VisualShader::Type(i), nodes[j]);
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. }
  2230. void VisualShaderEditor::_update_graph() {
  2231. if (visual_shader.is_null()) {
  2232. return;
  2233. }
  2234. VisualShader::Type type = get_current_shader_type();
  2235. graph->clear_connections();
  2236. // Remove all nodes.
  2237. for (int i = 0; i < graph->get_child_count(); i++) {
  2238. if (Object::cast_to<GraphElement>(graph->get_child(i))) {
  2239. Node *node = graph->get_child(i);
  2240. graph->remove_child(node);
  2241. memdelete(node);
  2242. i--;
  2243. }
  2244. }
  2245. List<VisualShader::Connection> node_connections;
  2246. visual_shader->get_node_connections(type, &node_connections);
  2247. graph_plugin->set_connections(node_connections);
  2248. Vector<int> nodes = visual_shader->get_node_list(type);
  2249. _update_parameters(false);
  2250. _update_varyings();
  2251. graph_plugin->clear_links();
  2252. graph_plugin->update_theme();
  2253. for (int n_i = 0; n_i < nodes.size(); n_i++) {
  2254. // Update frame related stuff later since we need to have all nodes in the graph.
  2255. graph_plugin->add_node(type, nodes[n_i], false, false);
  2256. }
  2257. for (const VisualShader::Connection &E : node_connections) {
  2258. int from = E.from_node;
  2259. int from_idx = E.from_port;
  2260. int to = E.to_node;
  2261. int to_idx = E.to_port;
  2262. graph->connect_node(itos(from), from_idx, itos(to), to_idx);
  2263. }
  2264. // Attach nodes to frames.
  2265. for (int node_id : nodes) {
  2266. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  2267. ERR_CONTINUE_MSG(vsnode.is_null(), "Node is null.");
  2268. if (vsnode->get_frame() != -1) {
  2269. int frame_name = vsnode->get_frame();
  2270. graph->attach_graph_element_to_frame(itos(node_id), itos(frame_name));
  2271. }
  2272. }
  2273. float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity");
  2274. graph->set_minimap_opacity(graph_minimap_opacity);
  2275. float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature");
  2276. graph->set_connection_lines_curvature(graph_lines_curvature);
  2277. }
  2278. void VisualShaderEditor::_restore_editor_state() {
  2279. const String id_string = _get_cache_id_string();
  2280. const String offset_cache_key = _get_cache_key("offset");
  2281. const String zoom_cache_key = _get_cache_key("zoom");
  2282. const Vector2 saved_scroll_offset = vs_editor_cache->get_value(id_string, offset_cache_key, Vector2());
  2283. const real_t saved_zoom = vs_editor_cache->get_value(id_string, zoom_cache_key, 1.0);
  2284. // Setting the scroll offset needs to be further deferred because it requires min/max scroll offset to be final (as it gets clamped).
  2285. callable_mp(graph, &GraphEdit::set_zoom).call_deferred(saved_zoom);
  2286. callable_mp(graph, &GraphEdit::set_scroll_offset).call_deferred(saved_scroll_offset);
  2287. shader_fully_loaded = true;
  2288. }
  2289. String VisualShaderEditor::_get_cache_id_string() const {
  2290. String id_string = visual_shader->get_path();
  2291. const ResourceUID::ID uid = EditorFileSystem::get_singleton()->get_file_uid(id_string);
  2292. if (uid != ResourceUID::INVALID_ID) {
  2293. id_string = ResourceUID::get_singleton()->id_to_text(uid);
  2294. }
  2295. return id_string;
  2296. }
  2297. String VisualShaderEditor::_get_cache_key(const String &p_prop_name) const {
  2298. const int type = get_current_shader_type();
  2299. return "type" + itos(type) + ":" + p_prop_name;
  2300. }
  2301. void VisualShaderEditor::_add_input_port(int p_node, int p_port, int p_port_type, const String &p_name) {
  2302. VisualShader::Type type = get_current_shader_type();
  2303. Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node);
  2304. if (node.is_null()) {
  2305. return;
  2306. }
  2307. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2308. undo_redo->create_action(TTR("Add Input Port"));
  2309. undo_redo->add_do_method(node.ptr(), "add_input_port", p_port, p_port_type, p_name);
  2310. undo_redo->add_undo_method(node.ptr(), "remove_input_port", p_port);
  2311. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2312. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2313. undo_redo->commit_action();
  2314. }
  2315. void VisualShaderEditor::_add_output_port(int p_node, int p_port, int p_port_type, const String &p_name) {
  2316. VisualShader::Type type = get_current_shader_type();
  2317. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2318. if (node.is_null()) {
  2319. return;
  2320. }
  2321. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2322. undo_redo->create_action(TTR("Add Output Port"));
  2323. undo_redo->add_do_method(node.ptr(), "add_output_port", p_port, p_port_type, p_name);
  2324. undo_redo->add_undo_method(node.ptr(), "remove_output_port", p_port);
  2325. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2326. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2327. undo_redo->commit_action();
  2328. }
  2329. void VisualShaderEditor::_change_input_port_type(int p_type, int p_node, int p_port) {
  2330. VisualShader::Type type = get_current_shader_type();
  2331. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2332. if (node.is_null()) {
  2333. return;
  2334. }
  2335. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2336. undo_redo->create_action(TTR("Change Input Port Type"));
  2337. undo_redo->add_do_method(node.ptr(), "set_input_port_type", p_port, p_type);
  2338. undo_redo->add_undo_method(node.ptr(), "set_input_port_type", p_port, node->get_input_port_type(p_port));
  2339. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2340. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2341. undo_redo->commit_action();
  2342. }
  2343. void VisualShaderEditor::_change_output_port_type(int p_type, int p_node, int p_port) {
  2344. VisualShader::Type type = get_current_shader_type();
  2345. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2346. if (node.is_null()) {
  2347. return;
  2348. }
  2349. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2350. undo_redo->create_action(TTR("Change Output Port Type"));
  2351. undo_redo->add_do_method(node.ptr(), "set_output_port_type", p_port, p_type);
  2352. undo_redo->add_undo_method(node.ptr(), "set_output_port_type", p_port, node->get_output_port_type(p_port));
  2353. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2354. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2355. undo_redo->commit_action();
  2356. }
  2357. void VisualShaderEditor::_change_input_port_name(const String &p_text, Object *p_line_edit, int p_node_id, int p_port_id) {
  2358. VisualShader::Type type = get_current_shader_type();
  2359. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  2360. ERR_FAIL_COND(node.is_null());
  2361. String prev_name = node->get_input_port_name(p_port_id);
  2362. if (prev_name == p_text) {
  2363. return;
  2364. }
  2365. LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
  2366. ERR_FAIL_NULL(line_edit);
  2367. String validated_name = visual_shader->validate_port_name(p_text, node.ptr(), p_port_id, false);
  2368. if (validated_name.is_empty() || prev_name == validated_name) {
  2369. line_edit->set_text(node->get_input_port_name(p_port_id));
  2370. return;
  2371. }
  2372. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2373. undo_redo->create_action(TTR("Change Input Port Name"));
  2374. undo_redo->add_do_method(node.ptr(), "set_input_port_name", p_port_id, validated_name);
  2375. undo_redo->add_undo_method(node.ptr(), "set_input_port_name", p_port_id, node->get_input_port_name(p_port_id));
  2376. undo_redo->commit_action();
  2377. }
  2378. void VisualShaderEditor::_change_output_port_name(const String &p_text, Object *p_line_edit, int p_node_id, int p_port_id) {
  2379. VisualShader::Type type = get_current_shader_type();
  2380. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  2381. ERR_FAIL_COND(node.is_null());
  2382. String prev_name = node->get_output_port_name(p_port_id);
  2383. if (prev_name == p_text) {
  2384. return;
  2385. }
  2386. LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
  2387. ERR_FAIL_NULL(line_edit);
  2388. String validated_name = visual_shader->validate_port_name(p_text, node.ptr(), p_port_id, true);
  2389. if (validated_name.is_empty() || prev_name == validated_name) {
  2390. line_edit->set_text(node->get_output_port_name(p_port_id));
  2391. return;
  2392. }
  2393. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2394. undo_redo->create_action(TTR("Change Output Port Name"));
  2395. undo_redo->add_do_method(node.ptr(), "set_output_port_name", p_port_id, validated_name);
  2396. undo_redo->add_undo_method(node.ptr(), "set_output_port_name", p_port_id, prev_name);
  2397. undo_redo->commit_action();
  2398. }
  2399. void VisualShaderEditor::_expand_output_port(int p_node, int p_port, bool p_expand) {
  2400. VisualShader::Type type = get_current_shader_type();
  2401. Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
  2402. ERR_FAIL_COND(node.is_null());
  2403. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2404. if (p_expand) {
  2405. undo_redo->create_action(TTR("Expand Output Port"));
  2406. } else {
  2407. undo_redo->create_action(TTR("Shrink Output Port"));
  2408. }
  2409. undo_redo->add_do_method(node.ptr(), "_set_output_port_expanded", p_port, p_expand);
  2410. undo_redo->add_undo_method(node.ptr(), "_set_output_port_expanded", p_port, !p_expand);
  2411. int type_size = 0;
  2412. switch (node->get_output_port_type(p_port)) {
  2413. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  2414. type_size = 2;
  2415. } break;
  2416. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  2417. type_size = 3;
  2418. } break;
  2419. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  2420. type_size = 4;
  2421. } break;
  2422. default:
  2423. break;
  2424. }
  2425. List<VisualShader::Connection> conns;
  2426. visual_shader->get_node_connections(type, &conns);
  2427. for (const VisualShader::Connection &E : conns) {
  2428. int cn_from_node = E.from_node;
  2429. int cn_from_port = E.from_port;
  2430. int cn_to_node = E.to_node;
  2431. int cn_to_port = E.to_port;
  2432. if (cn_from_node == p_node) {
  2433. if (p_expand) {
  2434. if (cn_from_port > p_port) { // reconnect ports after expanded ports
  2435. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2436. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2437. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2438. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2439. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port + type_size, cn_to_node, cn_to_port);
  2440. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port + type_size, cn_to_node, cn_to_port);
  2441. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port + type_size, cn_to_node, cn_to_port);
  2442. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port + type_size, cn_to_node, cn_to_port);
  2443. }
  2444. } else {
  2445. if (cn_from_port > p_port + type_size) { // reconnect ports after expanded ports
  2446. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2447. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2448. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2449. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2450. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, cn_from_node, cn_from_port - type_size, cn_to_node, cn_to_port);
  2451. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - type_size, cn_to_node, cn_to_port);
  2452. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port - type_size, cn_to_node, cn_to_port);
  2453. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - type_size, cn_to_node, cn_to_port);
  2454. } else if (cn_from_port > p_port) { // disconnect component ports
  2455. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2456. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2457. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2458. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2459. }
  2460. }
  2461. }
  2462. }
  2463. int preview_port = node->get_output_port_for_preview();
  2464. if (p_expand) {
  2465. if (preview_port > p_port) {
  2466. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port + type_size);
  2467. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2468. }
  2469. } else {
  2470. if (preview_port > p_port + type_size) {
  2471. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - type_size);
  2472. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2473. }
  2474. }
  2475. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2476. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2477. undo_redo->commit_action();
  2478. }
  2479. void VisualShaderEditor::_remove_input_port(int p_node, int p_port) {
  2480. VisualShader::Type type = get_current_shader_type();
  2481. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2482. if (node.is_null()) {
  2483. return;
  2484. }
  2485. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2486. undo_redo->create_action(TTR("Remove Input Port"));
  2487. List<VisualShader::Connection> conns;
  2488. visual_shader->get_node_connections(type, &conns);
  2489. for (const VisualShader::Connection &E : conns) {
  2490. int cn_from_node = E.from_node;
  2491. int cn_from_port = E.from_port;
  2492. int cn_to_node = E.to_node;
  2493. int cn_to_port = E.to_port;
  2494. if (cn_to_node == p_node) {
  2495. if (cn_to_port == p_port) {
  2496. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2497. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2498. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2499. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2500. } else if (cn_to_port > p_port) {
  2501. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2502. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2503. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2504. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2505. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2506. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2507. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2508. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2509. }
  2510. }
  2511. }
  2512. undo_redo->add_do_method(node.ptr(), "remove_input_port", p_port);
  2513. 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));
  2514. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2515. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2516. undo_redo->commit_action();
  2517. }
  2518. void VisualShaderEditor::_remove_output_port(int p_node, int p_port) {
  2519. VisualShader::Type type = get_current_shader_type();
  2520. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2521. if (node.is_null()) {
  2522. return;
  2523. }
  2524. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2525. undo_redo->create_action(TTR("Remove Output Port"));
  2526. List<VisualShader::Connection> conns;
  2527. visual_shader->get_node_connections(type, &conns);
  2528. for (const VisualShader::Connection &E : conns) {
  2529. int cn_from_node = E.from_node;
  2530. int cn_from_port = E.from_port;
  2531. int cn_to_node = E.to_node;
  2532. int cn_to_port = E.to_port;
  2533. if (cn_from_node == p_node) {
  2534. if (cn_from_port == p_port) {
  2535. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2536. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2537. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2538. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2539. } else if (cn_from_port > p_port) {
  2540. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2541. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2542. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2543. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2544. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2545. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2546. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2547. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2548. }
  2549. }
  2550. }
  2551. int preview_port = node->get_output_port_for_preview();
  2552. if (preview_port != -1) {
  2553. if (preview_port == p_port) {
  2554. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", -1);
  2555. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2556. } else if (preview_port > p_port) {
  2557. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - 1);
  2558. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2559. }
  2560. }
  2561. undo_redo->add_do_method(node.ptr(), "remove_output_port", p_port);
  2562. 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));
  2563. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2564. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2565. undo_redo->commit_action();
  2566. }
  2567. void VisualShaderEditor::_expression_focus_out(Object *p_code_edit, int p_node) {
  2568. VisualShader::Type type = get_current_shader_type();
  2569. Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node);
  2570. if (node.is_null()) {
  2571. return;
  2572. }
  2573. CodeEdit *expression_box = Object::cast_to<CodeEdit>(p_code_edit);
  2574. if (node->get_expression() == expression_box->get_text()) {
  2575. return;
  2576. }
  2577. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2578. undo_redo->create_action(TTR("Set VisualShader Expression"));
  2579. undo_redo->add_do_method(node.ptr(), "set_expression", expression_box->get_text());
  2580. undo_redo->add_undo_method(node.ptr(), "set_expression", node->get_expression());
  2581. undo_redo->add_do_method(graph_plugin.ptr(), "set_expression", type, p_node, expression_box->get_text());
  2582. undo_redo->add_undo_method(graph_plugin.ptr(), "set_expression", type, p_node, node->get_expression());
  2583. undo_redo->commit_action();
  2584. }
  2585. void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p_size) {
  2586. VisualShader::Type type = VisualShader::Type(p_type);
  2587. Ref<VisualShaderNodeResizableBase> node = visual_shader->get_node(type, p_node);
  2588. if (node.is_null()) {
  2589. return;
  2590. }
  2591. Size2 size = p_size;
  2592. if (!node->is_allow_v_resize()) {
  2593. size.y = 0;
  2594. }
  2595. node->set_size(size);
  2596. if (get_current_shader_type() == type) {
  2597. Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  2598. Control *text_box = nullptr;
  2599. if (expression_node.is_valid()) {
  2600. text_box = expression_node->is_ctrl_pressed(0);
  2601. if (text_box) {
  2602. text_box->set_custom_minimum_size(Size2(0, 0));
  2603. }
  2604. }
  2605. GraphElement *graph_element = nullptr;
  2606. Node *node2 = graph->get_node(itos(p_node));
  2607. graph_element = Object::cast_to<GraphElement>(node2);
  2608. if (!graph_element) {
  2609. return;
  2610. }
  2611. graph_element->set_size(size);
  2612. }
  2613. // Update all parent frames.
  2614. graph_plugin->update_frames(type, p_node);
  2615. }
  2616. // Called once after the node was resized.
  2617. void VisualShaderEditor::_node_resized(const Vector2 &p_new_size, int p_type, int p_node) {
  2618. Ref<VisualShaderNodeResizableBase> node = visual_shader->get_node(VisualShader::Type(p_type), p_node);
  2619. if (node.is_null()) {
  2620. return;
  2621. }
  2622. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_node(itos(p_node)));
  2623. if (!graph_element) {
  2624. return;
  2625. }
  2626. Size2 size = graph_element->get_size();
  2627. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2628. undo_redo->create_action(TTR("Resize VisualShader Node"));
  2629. undo_redo->add_do_method(this, "_set_node_size", p_type, p_node, size);
  2630. undo_redo->add_undo_method(this, "_set_node_size", p_type, p_node, node->get_size());
  2631. undo_redo->commit_action();
  2632. }
  2633. void VisualShaderEditor::_preview_select_port(int p_node, int p_port) {
  2634. VisualShader::Type type = get_current_shader_type();
  2635. Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
  2636. if (node.is_null()) {
  2637. return;
  2638. }
  2639. int prev_port = node->get_output_port_for_preview();
  2640. if (node->get_output_port_for_preview() == p_port) {
  2641. p_port = -1; //toggle it
  2642. }
  2643. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2644. undo_redo->create_action(p_port == -1 ? TTR("Hide Port Preview") : TTR("Show Port Preview"));
  2645. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", p_port);
  2646. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", prev_port);
  2647. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, p_node);
  2648. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, p_node);
  2649. undo_redo->commit_action();
  2650. }
  2651. void VisualShaderEditor::_frame_title_popup_show(const Point2 &p_position, int p_node_id) {
  2652. VisualShader::Type type = get_current_shader_type();
  2653. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2654. if (node.is_null()) {
  2655. return;
  2656. }
  2657. frame_title_change_edit->set_text(node->get_title());
  2658. frame_title_change_popup->set_meta("id", p_node_id);
  2659. frame_title_change_popup->set_position(p_position);
  2660. frame_title_change_popup->popup();
  2661. // Select current text.
  2662. frame_title_change_edit->grab_focus();
  2663. }
  2664. void VisualShaderEditor::_frame_title_text_changed(const String &p_new_text) {
  2665. frame_title_change_edit->reset_size();
  2666. frame_title_change_popup->reset_size();
  2667. }
  2668. void VisualShaderEditor::_frame_title_text_submitted(const String &p_new_text) {
  2669. frame_title_change_popup->hide();
  2670. }
  2671. void VisualShaderEditor::_frame_title_popup_focus_out() {
  2672. frame_title_change_popup->hide();
  2673. }
  2674. void VisualShaderEditor::_frame_title_popup_hide() {
  2675. int node_id = (int)frame_title_change_popup->get_meta("id", -1);
  2676. ERR_FAIL_COND(node_id == -1);
  2677. VisualShader::Type type = get_current_shader_type();
  2678. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id);
  2679. ERR_FAIL_COND(node.is_null());
  2680. if (node->get_title() == frame_title_change_edit->get_text()) {
  2681. return; // nothing changed - ignored
  2682. }
  2683. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2684. undo_redo->create_action(TTR("Set Frame Title"));
  2685. undo_redo->add_do_method(node.ptr(), "set_title", frame_title_change_edit->get_text());
  2686. undo_redo->add_undo_method(node.ptr(), "set_title", node->get_title());
  2687. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, node_id);
  2688. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, node_id);
  2689. undo_redo->commit_action();
  2690. }
  2691. void VisualShaderEditor::_frame_color_enabled_changed(int p_node_id) {
  2692. int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR);
  2693. // The new state.
  2694. bool tint_color_enabled = !popup_menu->is_item_checked(item_index);
  2695. popup_menu->set_item_checked(item_index, tint_color_enabled);
  2696. int frame_color_item_idx = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_COLOR);
  2697. if (tint_color_enabled && frame_color_item_idx == -1) {
  2698. popup_menu->add_item(TTR("Set Tint Color"), NodeMenuOptions::SET_FRAME_COLOR);
  2699. } else if (!tint_color_enabled && frame_color_item_idx != -1) {
  2700. popup_menu->remove_item(frame_color_item_idx);
  2701. }
  2702. VisualShader::Type type = get_current_shader_type();
  2703. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2704. ERR_FAIL_COND(node.is_null());
  2705. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2706. undo_redo->create_action(TTR("Toggle Frame Color"));
  2707. undo_redo->add_do_method(node.ptr(), "set_tint_color_enabled", tint_color_enabled);
  2708. undo_redo->add_undo_method(node.ptr(), "set_tint_color_enabled", node->is_tint_color_enabled());
  2709. undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_color_enabled", (int)type, p_node_id, tint_color_enabled);
  2710. undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_color_enabled", (int)type, p_node_id, node->is_tint_color_enabled());
  2711. undo_redo->commit_action();
  2712. }
  2713. void VisualShaderEditor::_frame_color_popup_show(const Point2 &p_position, int p_node_id) {
  2714. VisualShader::Type type = get_current_shader_type();
  2715. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2716. if (node.is_null()) {
  2717. return;
  2718. }
  2719. frame_tint_color_picker->set_pick_color(node->get_tint_color());
  2720. frame_tint_color_pick_popup->set_meta("id", p_node_id);
  2721. frame_tint_color_pick_popup->set_position(p_position);
  2722. frame_tint_color_pick_popup->popup();
  2723. }
  2724. void VisualShaderEditor::_frame_color_confirm() {
  2725. frame_tint_color_pick_popup->hide();
  2726. }
  2727. void VisualShaderEditor::_frame_color_changed(const Color &p_color) {
  2728. ERR_FAIL_COND(!frame_tint_color_pick_popup->has_meta("id"));
  2729. int node_id = (int)frame_tint_color_pick_popup->get_meta("id");
  2730. VisualShader::Type type = get_current_shader_type();
  2731. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id);
  2732. ERR_FAIL_COND(node.is_null());
  2733. node->set_tint_color(p_color);
  2734. graph_plugin->set_frame_color(type, node_id, p_color);
  2735. }
  2736. void VisualShaderEditor::_frame_color_popup_hide() {
  2737. ERR_FAIL_COND(!frame_tint_color_pick_popup->has_meta("id"));
  2738. int node_id = (int)frame_tint_color_pick_popup->get_meta("id");
  2739. VisualShader::Type type = get_current_shader_type();
  2740. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id);
  2741. ERR_FAIL_COND(node.is_null());
  2742. if (node->get_tint_color() == frame_tint_color_picker->get_pick_color()) {
  2743. return;
  2744. }
  2745. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2746. undo_redo->create_action(TTR("Set Frame Color"));
  2747. undo_redo->add_do_method(node.ptr(), "set_tint_color", frame_tint_color_picker->get_pick_color());
  2748. undo_redo->add_undo_method(node.ptr(), "set_tint_color", node->get_tint_color());
  2749. undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_color", (int)type, node_id, frame_tint_color_picker->get_pick_color());
  2750. undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_color", (int)type, node_id, node->get_tint_color());
  2751. undo_redo->commit_action();
  2752. }
  2753. void VisualShaderEditor::_frame_autoshrink_enabled_changed(int p_node_id) {
  2754. int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  2755. bool autoshrink_enabled = popup_menu->is_item_checked(item_index);
  2756. popup_menu->set_item_checked(item_index, !autoshrink_enabled);
  2757. VisualShader::Type type = get_current_shader_type();
  2758. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2759. ERR_FAIL_COND(node.is_null());
  2760. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2761. undo_redo->create_action(TTR("Toggle Auto Shrink"));
  2762. undo_redo->add_do_method(node.ptr(), "set_autoshrink_enabled", !autoshrink_enabled);
  2763. undo_redo->add_undo_method(node.ptr(), "set_autoshrink_enabled", autoshrink_enabled);
  2764. undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_autoshrink_enabled", (int)type, p_node_id, !autoshrink_enabled);
  2765. undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_autoshrink_enabled", (int)type, p_node_id, autoshrink_enabled);
  2766. undo_redo->commit_action();
  2767. popup_menu->hide();
  2768. }
  2769. void VisualShaderEditor::_parameter_line_edit_changed(const String &p_text, int p_node_id) {
  2770. VisualShader::Type type = get_current_shader_type();
  2771. Ref<VisualShaderNodeParameter> node = visual_shader->get_node(type, p_node_id);
  2772. ERR_FAIL_COND(node.is_null());
  2773. String validated_name = visual_shader->validate_parameter_name(p_text, node);
  2774. if (validated_name == node->get_parameter_name()) {
  2775. return;
  2776. }
  2777. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2778. undo_redo->create_action(TTR("Set Parameter Name"));
  2779. undo_redo->add_do_method(node.ptr(), "set_parameter_name", validated_name);
  2780. undo_redo->add_undo_method(node.ptr(), "set_parameter_name", node->get_parameter_name());
  2781. undo_redo->add_do_method(graph_plugin.ptr(), "set_parameter_name", type, p_node_id, validated_name);
  2782. undo_redo->add_undo_method(graph_plugin.ptr(), "set_parameter_name", type, p_node_id, node->get_parameter_name());
  2783. undo_redo->add_do_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id);
  2784. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id);
  2785. undo_redo->add_do_method(this, "_update_parameters", true);
  2786. undo_redo->add_undo_method(this, "_update_parameters", true);
  2787. HashSet<String> changed_names;
  2788. changed_names.insert(node->get_parameter_name());
  2789. _update_parameter_refs(changed_names);
  2790. undo_redo->commit_action();
  2791. }
  2792. void VisualShaderEditor::_parameter_line_edit_focus_out(Object *line_edit, int p_node_id) {
  2793. _parameter_line_edit_changed(Object::cast_to<LineEdit>(line_edit)->get_text(), p_node_id);
  2794. }
  2795. void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output) {
  2796. if (!p_output) {
  2797. _change_input_port_name(Object::cast_to<LineEdit>(line_edit)->get_text(), line_edit, p_node_id, p_port_id);
  2798. } else {
  2799. _change_output_port_name(Object::cast_to<LineEdit>(line_edit)->get_text(), line_edit, p_node_id, p_port_id);
  2800. }
  2801. }
  2802. void VisualShaderEditor::_port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
  2803. VisualShader::Type type = get_current_shader_type();
  2804. Ref<VisualShaderNode> vsn = visual_shader->get_node(type, editing_node);
  2805. ERR_FAIL_COND(vsn.is_null());
  2806. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2807. undo_redo->create_action(TTR("Set Input Default Port"));
  2808. Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(vsn.ptr());
  2809. if (custom.is_valid()) {
  2810. undo_redo->add_do_method(custom.ptr(), "_set_input_port_default_value", editing_port, p_value);
  2811. undo_redo->add_undo_method(custom.ptr(), "_set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
  2812. } else {
  2813. undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, p_value);
  2814. undo_redo->add_undo_method(vsn.ptr(), "set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
  2815. }
  2816. undo_redo->add_do_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, p_value);
  2817. 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));
  2818. undo_redo->commit_action();
  2819. }
  2820. void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, int p_port) {
  2821. VisualShader::Type type = get_current_shader_type();
  2822. Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, p_node);
  2823. Variant value = vs_node->get_input_port_default_value(p_port);
  2824. edited_property_holder->set_edited_property(value);
  2825. editing_node = p_node;
  2826. editing_port = p_port;
  2827. if (property_editor) {
  2828. property_editor->disconnect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
  2829. property_editor_popup->remove_child(property_editor);
  2830. }
  2831. // TODO: Define these properties with actual PropertyInfo and feed it to the property editor widget.
  2832. property_editor = EditorInspector::instantiate_property_editor(edited_property_holder.ptr(), value.get_type(), "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE, true);
  2833. ERR_FAIL_NULL_MSG(property_editor, "Failed to create property editor for type: " + Variant::get_type_name(value.get_type()));
  2834. // Determine the best size for the popup based on the property type.
  2835. // This is done here, since the property editors are also used in the inspector where they have different layout requirements, so we can't just change their default minimum size.
  2836. Size2 popup_pref_size;
  2837. switch (value.get_type()) {
  2838. case Variant::VECTOR3:
  2839. case Variant::BASIS:
  2840. popup_pref_size.width = 320;
  2841. break;
  2842. case Variant::VECTOR4:
  2843. case Variant::PLANE:
  2844. case Variant::TRANSFORM2D:
  2845. case Variant::TRANSFORM3D:
  2846. case Variant::PROJECTION:
  2847. popup_pref_size.width = 480;
  2848. break;
  2849. default:
  2850. popup_pref_size.width = 180;
  2851. break;
  2852. }
  2853. property_editor_popup->set_min_size(popup_pref_size * EDSCALE);
  2854. property_editor->set_object_and_property(edited_property_holder.ptr(), "edited_property");
  2855. property_editor->update_property();
  2856. property_editor->set_name_split_ratio(0);
  2857. property_editor_popup->add_child(property_editor);
  2858. property_editor->connect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
  2859. Button *button = Object::cast_to<Button>(p_button);
  2860. if (button) {
  2861. property_editor_popup->set_position(button->get_screen_position() + Vector2(0, button->get_size().height) * graph->get_zoom());
  2862. }
  2863. property_editor_popup->reset_size();
  2864. if (button) {
  2865. property_editor_popup->popup();
  2866. } else {
  2867. property_editor_popup->popup_centered_ratio();
  2868. }
  2869. property_editor->select(0); // Focus the first focusable control.
  2870. }
  2871. void VisualShaderEditor::_set_custom_node_option(int p_index, int p_node, int p_op) {
  2872. VisualShader::Type type = get_current_shader_type();
  2873. Ref<VisualShaderNodeCustom> node = visual_shader->get_node(type, p_node);
  2874. if (node.is_null()) {
  2875. return;
  2876. }
  2877. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2878. undo_redo->create_action(TTR("Set Custom Node Option"));
  2879. undo_redo->add_do_method(node.ptr(), "_set_option_index", p_op, p_index);
  2880. undo_redo->add_undo_method(node.ptr(), "_set_option_index", p_op, node->get_option_index(p_op));
  2881. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2882. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2883. undo_redo->commit_action();
  2884. }
  2885. void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops) {
  2886. // INPUT
  2887. {
  2888. VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(p_node);
  2889. if (input) {
  2890. ERR_FAIL_COND(!p_ops[0].is_string());
  2891. input->set_input_name((String)p_ops[0]);
  2892. return;
  2893. }
  2894. }
  2895. // FLOAT_CONST
  2896. {
  2897. VisualShaderNodeFloatConstant *float_const = Object::cast_to<VisualShaderNodeFloatConstant>(p_node);
  2898. if (float_const) {
  2899. ERR_FAIL_COND(p_ops[0].get_type() != Variant::FLOAT);
  2900. float_const->set_constant((float)p_ops[0]);
  2901. return;
  2902. }
  2903. }
  2904. // FLOAT_OP
  2905. {
  2906. VisualShaderNodeFloatOp *float_op = Object::cast_to<VisualShaderNodeFloatOp>(p_node);
  2907. if (float_op) {
  2908. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2909. float_op->set_operator((VisualShaderNodeFloatOp::Operator)(int)p_ops[0]);
  2910. return;
  2911. }
  2912. }
  2913. // FLOAT_FUNC
  2914. {
  2915. VisualShaderNodeFloatFunc *float_func = Object::cast_to<VisualShaderNodeFloatFunc>(p_node);
  2916. if (float_func) {
  2917. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2918. float_func->set_function((VisualShaderNodeFloatFunc::Function)(int)p_ops[0]);
  2919. return;
  2920. }
  2921. }
  2922. // VECTOR_OP
  2923. {
  2924. VisualShaderNodeVectorOp *vec_op = Object::cast_to<VisualShaderNodeVectorOp>(p_node);
  2925. if (vec_op) {
  2926. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2927. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  2928. vec_op->set_operator((VisualShaderNodeVectorOp::Operator)(int)p_ops[0]);
  2929. vec_op->set_op_type((VisualShaderNodeVectorOp::OpType)(int)p_ops[1]);
  2930. return;
  2931. }
  2932. }
  2933. // VECTOR_FUNC
  2934. {
  2935. VisualShaderNodeVectorFunc *vec_func = Object::cast_to<VisualShaderNodeVectorFunc>(p_node);
  2936. if (vec_func) {
  2937. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2938. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  2939. vec_func->set_function((VisualShaderNodeVectorFunc::Function)(int)p_ops[0]);
  2940. vec_func->set_op_type((VisualShaderNodeVectorFunc::OpType)(int)p_ops[1]);
  2941. return;
  2942. }
  2943. }
  2944. // COLOR_OP
  2945. {
  2946. VisualShaderNodeColorOp *color_op = Object::cast_to<VisualShaderNodeColorOp>(p_node);
  2947. if (color_op) {
  2948. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2949. color_op->set_operator((VisualShaderNodeColorOp::Operator)(int)p_ops[0]);
  2950. return;
  2951. }
  2952. }
  2953. // COLOR_FUNC
  2954. {
  2955. VisualShaderNodeColorFunc *color_func = Object::cast_to<VisualShaderNodeColorFunc>(p_node);
  2956. if (color_func) {
  2957. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2958. color_func->set_function((VisualShaderNodeColorFunc::Function)(int)p_ops[0]);
  2959. return;
  2960. }
  2961. }
  2962. // INT_OP
  2963. {
  2964. VisualShaderNodeIntOp *int_op = Object::cast_to<VisualShaderNodeIntOp>(p_node);
  2965. if (int_op) {
  2966. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2967. int_op->set_operator((VisualShaderNodeIntOp::Operator)(int)p_ops[0]);
  2968. return;
  2969. }
  2970. }
  2971. // INT_FUNC
  2972. {
  2973. VisualShaderNodeIntFunc *int_func = Object::cast_to<VisualShaderNodeIntFunc>(p_node);
  2974. if (int_func) {
  2975. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2976. int_func->set_function((VisualShaderNodeIntFunc::Function)(int)p_ops[0]);
  2977. return;
  2978. }
  2979. }
  2980. // UINT_OP
  2981. {
  2982. VisualShaderNodeUIntOp *uint_op = Object::cast_to<VisualShaderNodeUIntOp>(p_node);
  2983. if (uint_op) {
  2984. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2985. uint_op->set_operator((VisualShaderNodeUIntOp::Operator)(int)p_ops[0]);
  2986. return;
  2987. }
  2988. }
  2989. // UINT_FUNC
  2990. {
  2991. VisualShaderNodeUIntFunc *uint_func = Object::cast_to<VisualShaderNodeUIntFunc>(p_node);
  2992. if (uint_func) {
  2993. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2994. uint_func->set_function((VisualShaderNodeUIntFunc::Function)(int)p_ops[0]);
  2995. return;
  2996. }
  2997. }
  2998. // TRANSFORM_OP
  2999. {
  3000. VisualShaderNodeTransformOp *mat_op = Object::cast_to<VisualShaderNodeTransformOp>(p_node);
  3001. if (mat_op) {
  3002. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3003. mat_op->set_operator((VisualShaderNodeTransformOp::Operator)(int)p_ops[0]);
  3004. return;
  3005. }
  3006. }
  3007. // TRANSFORM_FUNC
  3008. {
  3009. VisualShaderNodeTransformFunc *mat_func = Object::cast_to<VisualShaderNodeTransformFunc>(p_node);
  3010. if (mat_func) {
  3011. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3012. mat_func->set_function((VisualShaderNodeTransformFunc::Function)(int)p_ops[0]);
  3013. return;
  3014. }
  3015. }
  3016. // VECTOR_COMPOSE
  3017. {
  3018. VisualShaderNodeVectorCompose *vec_compose = Object::cast_to<VisualShaderNodeVectorCompose>(p_node);
  3019. if (vec_compose) {
  3020. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3021. vec_compose->set_op_type((VisualShaderNodeVectorCompose::OpType)(int)p_ops[0]);
  3022. return;
  3023. }
  3024. }
  3025. // VECTOR_DECOMPOSE
  3026. {
  3027. VisualShaderNodeVectorDecompose *vec_decompose = Object::cast_to<VisualShaderNodeVectorDecompose>(p_node);
  3028. if (vec_decompose) {
  3029. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3030. vec_decompose->set_op_type((VisualShaderNodeVectorDecompose::OpType)(int)p_ops[0]);
  3031. return;
  3032. }
  3033. }
  3034. // UV_FUNC
  3035. {
  3036. VisualShaderNodeUVFunc *uv_func = Object::cast_to<VisualShaderNodeUVFunc>(p_node);
  3037. if (uv_func) {
  3038. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3039. uv_func->set_function((VisualShaderNodeUVFunc::Function)(int)p_ops[0]);
  3040. return;
  3041. }
  3042. }
  3043. // IS
  3044. {
  3045. VisualShaderNodeIs *is = Object::cast_to<VisualShaderNodeIs>(p_node);
  3046. if (is) {
  3047. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3048. is->set_function((VisualShaderNodeIs::Function)(int)p_ops[0]);
  3049. return;
  3050. }
  3051. }
  3052. // COMPARE
  3053. {
  3054. VisualShaderNodeCompare *cmp = Object::cast_to<VisualShaderNodeCompare>(p_node);
  3055. if (cmp) {
  3056. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3057. cmp->set_function((VisualShaderNodeCompare::Function)(int)p_ops[0]);
  3058. return;
  3059. }
  3060. }
  3061. // DISTANCE
  3062. {
  3063. VisualShaderNodeVectorDistance *dist = Object::cast_to<VisualShaderNodeVectorDistance>(p_node);
  3064. if (dist) {
  3065. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3066. dist->set_op_type((VisualShaderNodeVectorDistance::OpType)(int)p_ops[0]);
  3067. return;
  3068. }
  3069. }
  3070. // DERIVATIVE
  3071. {
  3072. VisualShaderNodeDerivativeFunc *der_func = Object::cast_to<VisualShaderNodeDerivativeFunc>(p_node);
  3073. if (der_func) {
  3074. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3075. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  3076. der_func->set_function((VisualShaderNodeDerivativeFunc::Function)(int)p_ops[0]);
  3077. der_func->set_op_type((VisualShaderNodeDerivativeFunc::OpType)(int)p_ops[1]);
  3078. return;
  3079. }
  3080. }
  3081. // MIX
  3082. {
  3083. VisualShaderNodeMix *mix = Object::cast_to<VisualShaderNodeMix>(p_node);
  3084. if (mix) {
  3085. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3086. mix->set_op_type((VisualShaderNodeMix::OpType)(int)p_ops[0]);
  3087. return;
  3088. }
  3089. }
  3090. // CLAMP
  3091. {
  3092. VisualShaderNodeClamp *clamp_func = Object::cast_to<VisualShaderNodeClamp>(p_node);
  3093. if (clamp_func) {
  3094. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3095. clamp_func->set_op_type((VisualShaderNodeClamp::OpType)(int)p_ops[0]);
  3096. return;
  3097. }
  3098. }
  3099. // SWITCH
  3100. {
  3101. VisualShaderNodeSwitch *switch_func = Object::cast_to<VisualShaderNodeSwitch>(p_node);
  3102. if (switch_func) {
  3103. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3104. switch_func->set_op_type((VisualShaderNodeSwitch::OpType)(int)p_ops[0]);
  3105. return;
  3106. }
  3107. }
  3108. // FACEFORWARD
  3109. {
  3110. VisualShaderNodeFaceForward *face_forward = Object::cast_to<VisualShaderNodeFaceForward>(p_node);
  3111. if (face_forward) {
  3112. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3113. face_forward->set_op_type((VisualShaderNodeFaceForward::OpType)(int)p_ops[0]);
  3114. return;
  3115. }
  3116. }
  3117. // LENGTH
  3118. {
  3119. VisualShaderNodeVectorLen *length = Object::cast_to<VisualShaderNodeVectorLen>(p_node);
  3120. if (length) {
  3121. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3122. length->set_op_type((VisualShaderNodeVectorLen::OpType)(int)p_ops[0]);
  3123. return;
  3124. }
  3125. }
  3126. // SMOOTHSTEP
  3127. {
  3128. VisualShaderNodeSmoothStep *smooth_step_func = Object::cast_to<VisualShaderNodeSmoothStep>(p_node);
  3129. if (smooth_step_func) {
  3130. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3131. smooth_step_func->set_op_type((VisualShaderNodeSmoothStep::OpType)(int)p_ops[0]);
  3132. return;
  3133. }
  3134. }
  3135. // STEP
  3136. {
  3137. VisualShaderNodeStep *step_func = Object::cast_to<VisualShaderNodeStep>(p_node);
  3138. if (step_func) {
  3139. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3140. step_func->set_op_type((VisualShaderNodeStep::OpType)(int)p_ops[0]);
  3141. return;
  3142. }
  3143. }
  3144. // MULTIPLY_ADD
  3145. {
  3146. VisualShaderNodeMultiplyAdd *fma_func = Object::cast_to<VisualShaderNodeMultiplyAdd>(p_node);
  3147. if (fma_func) {
  3148. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3149. fma_func->set_op_type((VisualShaderNodeMultiplyAdd::OpType)(int)p_ops[0]);
  3150. }
  3151. }
  3152. // REMAP
  3153. {
  3154. VisualShaderNodeRemap *remap_func = Object::cast_to<VisualShaderNodeRemap>(p_node);
  3155. if (remap_func) {
  3156. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3157. remap_func->set_op_type((VisualShaderNodeRemap::OpType)(int)p_ops[0]);
  3158. }
  3159. }
  3160. }
  3161. void VisualShaderEditor::_add_node(int p_idx, const Vector<Variant> &p_ops, const String &p_resource_path, int p_node_idx) {
  3162. ERR_FAIL_INDEX(p_idx, add_options.size());
  3163. VisualShader::Type type = get_current_shader_type();
  3164. Ref<VisualShaderNode> vsnode;
  3165. bool is_custom = add_options[p_idx].is_custom;
  3166. if (!is_custom && !add_options[p_idx].type.is_empty()) {
  3167. VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[p_idx].type));
  3168. ERR_FAIL_NULL(vsn);
  3169. if (!p_ops.is_empty()) {
  3170. _setup_node(vsn, p_ops);
  3171. }
  3172. VisualShaderNodeParameterRef *parameter_ref = Object::cast_to<VisualShaderNodeParameterRef>(vsn);
  3173. if (parameter_ref && to_node != -1 && to_slot != -1) {
  3174. VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot);
  3175. bool success = false;
  3176. for (int i = 0; i < parameter_ref->get_parameters_count(); i++) {
  3177. if (parameter_ref->get_port_type_by_index(i) == input_port_type) {
  3178. parameter_ref->set_parameter_name(parameter_ref->get_parameter_name_by_index(i));
  3179. success = true;
  3180. break;
  3181. }
  3182. }
  3183. if (!success) {
  3184. for (int i = 0; i < parameter_ref->get_parameters_count(); i++) {
  3185. if (visual_shader->is_port_types_compatible(parameter_ref->get_port_type_by_index(i), input_port_type)) {
  3186. parameter_ref->set_parameter_name(parameter_ref->get_parameter_name_by_index(i));
  3187. break;
  3188. }
  3189. }
  3190. }
  3191. }
  3192. vsnode = Ref<VisualShaderNode>(vsn);
  3193. } else {
  3194. StringName base_type;
  3195. bool is_native = add_options[p_idx].is_native;
  3196. if (is_native) {
  3197. base_type = add_options[p_idx].type;
  3198. } else {
  3199. ERR_FAIL_COND(add_options[p_idx].script.is_null());
  3200. base_type = add_options[p_idx].script->get_instance_base_type();
  3201. }
  3202. VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(base_type));
  3203. ERR_FAIL_NULL(vsn);
  3204. vsnode = Ref<VisualShaderNode>(vsn);
  3205. if (!is_native) {
  3206. vsnode->set_script(add_options[p_idx].script);
  3207. }
  3208. VisualShaderNodeCustom *custom_node = Object::cast_to<VisualShaderNodeCustom>(vsn);
  3209. ERR_FAIL_NULL(custom_node);
  3210. custom_node->update_property_default_values();
  3211. custom_node->update_input_port_default_values();
  3212. custom_node->update_properties();
  3213. }
  3214. bool is_texture2d = (Object::cast_to<VisualShaderNodeTexture>(vsnode.ptr()) != nullptr);
  3215. bool is_texture3d = (Object::cast_to<VisualShaderNodeTexture3D>(vsnode.ptr()) != nullptr);
  3216. bool is_texture2d_array = (Object::cast_to<VisualShaderNodeTexture2DArray>(vsnode.ptr()) != nullptr);
  3217. bool is_cubemap = (Object::cast_to<VisualShaderNodeCubemap>(vsnode.ptr()) != nullptr);
  3218. bool is_curve = (Object::cast_to<VisualShaderNodeCurveTexture>(vsnode.ptr()) != nullptr);
  3219. bool is_curve_xyz = (Object::cast_to<VisualShaderNodeCurveXYZTexture>(vsnode.ptr()) != nullptr);
  3220. bool is_parameter = (Object::cast_to<VisualShaderNodeParameter>(vsnode.ptr()) != nullptr);
  3221. bool is_mesh_emitter = (Object::cast_to<VisualShaderNodeParticleMeshEmitter>(vsnode.ptr()) != nullptr);
  3222. Point2 position = graph->get_scroll_offset();
  3223. if (saved_node_pos_dirty) {
  3224. position += saved_node_pos;
  3225. } else {
  3226. position += graph->get_size() * 0.5;
  3227. position /= EDSCALE;
  3228. }
  3229. position /= graph->get_zoom();
  3230. saved_node_pos_dirty = false;
  3231. int id_to_use = visual_shader->get_valid_node_id(type);
  3232. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3233. if (p_resource_path.is_empty()) {
  3234. undo_redo->create_action(TTR("Add Node to Visual Shader"));
  3235. } else {
  3236. id_to_use += p_node_idx;
  3237. }
  3238. undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, vsnode, position, id_to_use);
  3239. undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_to_use);
  3240. undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_to_use, false, true);
  3241. undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_to_use, false);
  3242. VisualShaderNodeExpression *expr = Object::cast_to<VisualShaderNodeExpression>(vsnode.ptr());
  3243. if (expr) {
  3244. expr->set_size(Size2(250 * EDSCALE, 150 * EDSCALE));
  3245. }
  3246. Ref<VisualShaderNodeFrame> frame = vsnode;
  3247. if (frame.is_valid()) {
  3248. frame->set_size(Size2(320 * EDSCALE, 180 * EDSCALE));
  3249. }
  3250. Ref<VisualShaderNodeReroute> reroute = vsnode;
  3251. bool created_expression_port = false;
  3252. // A node is inserted in an already present connection.
  3253. if (from_node != -1 && from_slot != -1 && to_node != -1 && to_slot != -1) {
  3254. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, to_node, to_slot);
  3255. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, to_node, to_slot);
  3256. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, to_node, to_slot);
  3257. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, to_node, to_slot);
  3258. }
  3259. // Create a connection from the output port of an existing node to the new one.
  3260. if (from_node != -1 && from_slot != -1) {
  3261. VisualShaderNode::PortType output_port_type = visual_shader->get_node(type, from_node)->get_output_port_type(from_slot);
  3262. if (expr && expr->is_editable()) {
  3263. expr->add_input_port(0, output_port_type, "input0");
  3264. created_expression_port = true;
  3265. }
  3266. if (vsnode->get_input_port_count() > 0 || created_expression_port) {
  3267. int _to_node = id_to_use;
  3268. if (created_expression_port) {
  3269. int _to_slot = 0;
  3270. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3271. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3272. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3273. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3274. } else {
  3275. int _to_slot = -1;
  3276. // Attempting to connect to the default input port or to the first correct port (if it's not found).
  3277. for (int i = 0; i < vsnode->get_input_port_count(); i++) {
  3278. if (visual_shader->is_port_types_compatible(output_port_type, vsnode->get_input_port_type(i)) || reroute.is_valid()) {
  3279. if (i == vsnode->get_default_input_port(output_port_type)) {
  3280. _to_slot = i;
  3281. break;
  3282. } else if (_to_slot == -1) {
  3283. _to_slot = i;
  3284. }
  3285. }
  3286. }
  3287. if (_to_slot >= 0) {
  3288. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3289. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3290. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3291. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3292. }
  3293. }
  3294. if (output_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) {
  3295. if (is_texture2d) {
  3296. undo_redo->force_fixed_history(); // vsnode is freshly created and has no path, so history can't be correctly determined.
  3297. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeTexture::SOURCE_PORT);
  3298. }
  3299. if (is_texture3d || is_texture2d_array) {
  3300. undo_redo->force_fixed_history();
  3301. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeSample3D::SOURCE_PORT);
  3302. }
  3303. if (is_cubemap) {
  3304. undo_redo->force_fixed_history();
  3305. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeCubemap::SOURCE_PORT);
  3306. }
  3307. }
  3308. }
  3309. }
  3310. // Create a connection from the new node to an input port of an existing one.
  3311. if (to_node != -1 && to_slot != -1) {
  3312. VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot);
  3313. if (expr && expr->is_editable() && input_port_type != VisualShaderNode::PORT_TYPE_SAMPLER) {
  3314. expr->add_output_port(0, input_port_type, "output0");
  3315. String initial_expression_code;
  3316. switch (input_port_type) {
  3317. case VisualShaderNode::PORT_TYPE_SCALAR:
  3318. initial_expression_code = "output0 = 1.0;";
  3319. break;
  3320. case VisualShaderNode::PORT_TYPE_SCALAR_INT:
  3321. initial_expression_code = "output0 = 1;";
  3322. break;
  3323. case VisualShaderNode::PORT_TYPE_SCALAR_UINT:
  3324. initial_expression_code = "output0 = 1u;";
  3325. break;
  3326. case VisualShaderNode::PORT_TYPE_VECTOR_2D:
  3327. initial_expression_code = "output0 = vec2(1.0, 1.0);";
  3328. break;
  3329. case VisualShaderNode::PORT_TYPE_VECTOR_3D:
  3330. initial_expression_code = "output0 = vec3(1.0, 1.0, 1.0);";
  3331. break;
  3332. case VisualShaderNode::PORT_TYPE_VECTOR_4D:
  3333. initial_expression_code = "output0 = vec4(1.0, 1.0, 1.0, 1.0);";
  3334. break;
  3335. case VisualShaderNode::PORT_TYPE_BOOLEAN:
  3336. initial_expression_code = "output0 = true;";
  3337. break;
  3338. case VisualShaderNode::PORT_TYPE_TRANSFORM:
  3339. initial_expression_code = "output0 = mat4(1.0);";
  3340. break;
  3341. default:
  3342. break;
  3343. }
  3344. expr->set_expression(initial_expression_code);
  3345. expr->set_size(Size2(500 * EDSCALE, 200 * EDSCALE));
  3346. created_expression_port = true;
  3347. }
  3348. if (vsnode->get_output_port_count() > 0 || created_expression_port) {
  3349. int _from_node = id_to_use;
  3350. if (created_expression_port) {
  3351. int _from_slot = 0;
  3352. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  3353. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  3354. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  3355. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  3356. } else {
  3357. // Need to setting up Input node properly before committing since `is_port_types_compatible` (calling below) is using `mode` and `shader_type`.
  3358. VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(vsnode.ptr());
  3359. if (input) {
  3360. input->set_shader_mode(visual_shader->get_mode());
  3361. input->set_shader_type(get_current_shader_type());
  3362. }
  3363. // Attempting to connect to the first correct port.
  3364. for (int i = 0; i < vsnode->get_output_port_count(); i++) {
  3365. if (visual_shader->is_port_types_compatible(vsnode->get_output_port_type(i), input_port_type) || reroute.is_valid()) {
  3366. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot);
  3367. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot);
  3368. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot);
  3369. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot);
  3370. break;
  3371. }
  3372. }
  3373. }
  3374. }
  3375. }
  3376. _member_cancel();
  3377. if (is_parameter) {
  3378. undo_redo->add_do_method(this, "_update_parameters", true);
  3379. undo_redo->add_undo_method(this, "_update_parameters", true);
  3380. }
  3381. if (is_curve) {
  3382. callable_mp(graph_plugin.ptr(), &VisualShaderGraphPlugin::update_curve).call_deferred(id_to_use);
  3383. }
  3384. if (is_curve_xyz) {
  3385. callable_mp(graph_plugin.ptr(), &VisualShaderGraphPlugin::update_curve_xyz).call_deferred(id_to_use);
  3386. }
  3387. if (p_resource_path.is_empty()) {
  3388. undo_redo->commit_action();
  3389. } else {
  3390. //post-initialization
  3391. if (is_texture2d || is_texture3d || is_curve || is_curve_xyz) {
  3392. undo_redo->force_fixed_history();
  3393. undo_redo->add_do_method(vsnode.ptr(), "set_texture", ResourceLoader::load(p_resource_path));
  3394. return;
  3395. }
  3396. if (is_cubemap) {
  3397. undo_redo->force_fixed_history();
  3398. undo_redo->add_do_method(vsnode.ptr(), "set_cube_map", ResourceLoader::load(p_resource_path));
  3399. return;
  3400. }
  3401. if (is_texture2d_array) {
  3402. undo_redo->force_fixed_history();
  3403. undo_redo->add_do_method(vsnode.ptr(), "set_texture_array", ResourceLoader::load(p_resource_path));
  3404. return;
  3405. }
  3406. if (is_mesh_emitter) {
  3407. undo_redo->add_do_method(vsnode.ptr(), "set_mesh", ResourceLoader::load(p_resource_path));
  3408. return;
  3409. }
  3410. }
  3411. }
  3412. void VisualShaderEditor::_add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type) {
  3413. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3414. undo_redo->create_action(vformat(TTR("Add Varying to Visual Shader: %s"), p_name));
  3415. undo_redo->add_do_method(visual_shader.ptr(), "add_varying", p_name, p_mode, p_type);
  3416. undo_redo->add_undo_method(visual_shader.ptr(), "remove_varying", p_name);
  3417. undo_redo->add_do_method(this, "_update_varyings");
  3418. undo_redo->add_undo_method(this, "_update_varyings");
  3419. for (int i = 0; i <= VisualShader::TYPE_LIGHT; i++) {
  3420. if (p_mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT && i == 0) {
  3421. continue;
  3422. }
  3423. VisualShader::Type type = VisualShader::Type(i);
  3424. Vector<int> nodes = visual_shader->get_node_list(type);
  3425. for (int j = 0; j < nodes.size(); j++) {
  3426. int node_id = nodes[j];
  3427. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  3428. Ref<VisualShaderNodeVarying> var = vsnode;
  3429. if (var.is_valid()) {
  3430. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, node_id);
  3431. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, node_id);
  3432. }
  3433. }
  3434. }
  3435. undo_redo->add_do_method(this, "_update_varying_tree");
  3436. undo_redo->add_undo_method(this, "_update_varying_tree");
  3437. undo_redo->commit_action();
  3438. }
  3439. void VisualShaderEditor::_remove_varying(const String &p_name) {
  3440. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3441. undo_redo->create_action(vformat(TTR("Remove Varying from Visual Shader: %s"), p_name));
  3442. VisualShader::VaryingMode var_mode = visual_shader->get_varying_mode(p_name);
  3443. undo_redo->add_do_method(visual_shader.ptr(), "remove_varying", p_name);
  3444. undo_redo->add_undo_method(visual_shader.ptr(), "add_varying", p_name, var_mode, visual_shader->get_varying_type(p_name));
  3445. undo_redo->add_do_method(this, "_update_varyings");
  3446. undo_redo->add_undo_method(this, "_update_varyings");
  3447. for (int i = 0; i <= VisualShader::TYPE_LIGHT; i++) {
  3448. if (var_mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT && i == 0) {
  3449. continue;
  3450. }
  3451. VisualShader::Type type = VisualShader::Type(i);
  3452. Vector<int> nodes = visual_shader->get_node_list(type);
  3453. for (int j = 0; j < nodes.size(); j++) {
  3454. int node_id = nodes[j];
  3455. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  3456. Ref<VisualShaderNodeVarying> var = vsnode;
  3457. if (var.is_valid()) {
  3458. String var_name = var->get_varying_name();
  3459. if (var_name == p_name) {
  3460. undo_redo->add_do_method(var.ptr(), "set_varying_name", "[None]");
  3461. undo_redo->add_undo_method(var.ptr(), "set_varying_name", var_name);
  3462. undo_redo->add_do_method(var.ptr(), "set_varying_type", VisualShader::VARYING_TYPE_FLOAT);
  3463. undo_redo->add_undo_method(var.ptr(), "set_varying_type", var->get_varying_type());
  3464. }
  3465. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, node_id);
  3466. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, node_id);
  3467. }
  3468. }
  3469. List<VisualShader::Connection> node_connections;
  3470. visual_shader->get_node_connections(type, &node_connections);
  3471. for (VisualShader::Connection &E : node_connections) {
  3472. Ref<VisualShaderNodeVaryingGetter> var_getter = Object::cast_to<VisualShaderNodeVaryingGetter>(visual_shader->get_node(type, E.from_node).ptr());
  3473. if (var_getter.is_valid() && E.from_port > 0) {
  3474. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3475. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3476. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3477. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3478. }
  3479. Ref<VisualShaderNodeVaryingSetter> var_setter = Object::cast_to<VisualShaderNodeVaryingSetter>(visual_shader->get_node(type, E.to_node).ptr());
  3480. if (var_setter.is_valid() && E.to_port > 0) {
  3481. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3482. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3483. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3484. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3485. }
  3486. }
  3487. }
  3488. undo_redo->add_do_method(this, "_update_varying_tree");
  3489. undo_redo->add_undo_method(this, "_update_varying_tree");
  3490. undo_redo->commit_action();
  3491. }
  3492. void VisualShaderEditor::_update_varyings() {
  3493. VisualShaderNodeVarying::clear_varyings(visual_shader->get_rid());
  3494. for (int i = 0; i < visual_shader->get_varyings_count(); i++) {
  3495. const VisualShader::Varying *var = visual_shader->get_varying_by_index(i);
  3496. if (var != nullptr) {
  3497. VisualShaderNodeVarying::add_varying(visual_shader->get_rid(), var->name, var->mode, var->type);
  3498. }
  3499. }
  3500. }
  3501. void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) {
  3502. VisualShader::Type type = get_current_shader_type();
  3503. drag_buffer.push_back({ type, p_node, p_from, p_to });
  3504. if (!drag_dirty) {
  3505. callable_mp(this, &VisualShaderEditor::_nodes_dragged).call_deferred();
  3506. }
  3507. drag_dirty = true;
  3508. }
  3509. void VisualShaderEditor::_nodes_dragged() {
  3510. drag_dirty = false;
  3511. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3512. if (frame_node_id_to_link_to == -1) {
  3513. undo_redo->create_action(TTR("Move VisualShader Node(s)"));
  3514. } else {
  3515. undo_redo->create_action(TTR("Move and Attach VisualShader Node(s) to parent frame"));
  3516. }
  3517. for (const DragOp &E : drag_buffer) {
  3518. undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.to);
  3519. undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.from);
  3520. undo_redo->add_do_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.to);
  3521. undo_redo->add_undo_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.from);
  3522. }
  3523. for (const int node_id : nodes_link_to_frame_buffer) {
  3524. VisualShader::Type type = get_current_shader_type();
  3525. Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, node_id);
  3526. undo_redo->add_do_method(visual_shader.ptr(), "attach_node_to_frame", type, node_id, frame_node_id_to_link_to);
  3527. undo_redo->add_do_method(graph_plugin.ptr(), "attach_node_to_frame", type, node_id, frame_node_id_to_link_to);
  3528. undo_redo->add_undo_method(graph_plugin.ptr(), "detach_node_from_frame", type, node_id);
  3529. undo_redo->add_undo_method(visual_shader.ptr(), "detach_node_from_frame", type, node_id);
  3530. }
  3531. undo_redo->commit_action();
  3532. _handle_node_drop_on_connection();
  3533. drag_buffer.clear();
  3534. nodes_link_to_frame_buffer.clear();
  3535. frame_node_id_to_link_to = -1;
  3536. }
  3537. void VisualShaderEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  3538. VisualShader::Type type = get_current_shader_type();
  3539. int from = p_from.to_int();
  3540. int to = p_to.to_int();
  3541. bool swap = last_to_node != -1 && Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL);
  3542. if (!visual_shader->can_connect_nodes(type, from, p_from_index, to, p_to_index)) {
  3543. return;
  3544. }
  3545. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3546. undo_redo->create_action(TTR("Nodes Connected"));
  3547. List<VisualShader::Connection> conns;
  3548. visual_shader->get_node_connections(type, &conns);
  3549. for (const VisualShader::Connection &E : conns) {
  3550. if (E.to_node == to && E.to_port == p_to_index) {
  3551. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3552. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3553. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3554. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3555. if (swap) {
  3556. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port);
  3557. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port);
  3558. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port);
  3559. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port);
  3560. }
  3561. break;
  3562. }
  3563. }
  3564. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3565. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3566. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3567. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3568. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, from);
  3569. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, from);
  3570. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3571. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3572. undo_redo->commit_action();
  3573. last_to_node = -1;
  3574. last_to_port = -1;
  3575. }
  3576. void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  3577. graph->disconnect_node(p_from, p_from_index, p_to, p_to_index);
  3578. VisualShader::Type type = get_current_shader_type();
  3579. int from = p_from.to_int();
  3580. int to = p_to.to_int();
  3581. last_to_node = to;
  3582. last_to_port = p_to_index;
  3583. info_label->show();
  3584. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3585. undo_redo->create_action(TTR("Nodes Disconnected"));
  3586. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3587. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3588. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3589. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3590. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3591. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3592. undo_redo->commit_action();
  3593. }
  3594. void VisualShaderEditor::_connection_drag_ended() {
  3595. info_label->hide();
  3596. }
  3597. void VisualShaderEditor::_connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position) {
  3598. from_node = p_from.to_int();
  3599. from_slot = p_from_slot;
  3600. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3601. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3602. Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), from_node);
  3603. if (node.is_valid()) {
  3604. output_port_type = node->get_output_port_type(from_slot);
  3605. }
  3606. _show_members_dialog(true, input_port_type, output_port_type);
  3607. }
  3608. void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position) {
  3609. to_node = p_to.to_int();
  3610. to_slot = p_to_slot;
  3611. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3612. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3613. Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), to_node);
  3614. if (node.is_valid()) {
  3615. input_port_type = node->get_input_port_type(to_slot);
  3616. }
  3617. _show_members_dialog(true, input_port_type, output_port_type);
  3618. }
  3619. bool VisualShaderEditor::_check_node_drop_on_connection(const Vector2 &p_position, Ref<GraphEdit::Connection> *r_closest_connection, int *r_from_port, int *r_to_port) {
  3620. VisualShader::Type shader_type = get_current_shader_type();
  3621. // Get selected graph node.
  3622. Ref<VisualShaderNode> selected_vsnode;
  3623. int selected_node_id = -1;
  3624. int selected_node_count = 0;
  3625. Rect2 selected_node_rect;
  3626. for (int i = 0; i < graph->get_child_count(); i++) {
  3627. GraphNode *graph_node = Object::cast_to<GraphNode>(graph->get_child(i));
  3628. if (graph_node && graph_node->is_selected()) {
  3629. selected_node_id = String(graph_node->get_name()).to_int();
  3630. Ref<VisualShaderNode> vsnode = visual_shader->get_node(shader_type, selected_node_id);
  3631. if (!vsnode->is_deletable()) {
  3632. continue;
  3633. }
  3634. selected_node_count += 1;
  3635. Ref<VisualShaderNode> node = visual_shader->get_node(shader_type, selected_node_id);
  3636. selected_vsnode = node;
  3637. selected_node_rect = graph_node->get_rect();
  3638. }
  3639. }
  3640. // Only a single node - which has both input and output ports but is not connected yet - can be inserted.
  3641. if (selected_node_count != 1 || selected_vsnode.is_null()) {
  3642. return false;
  3643. }
  3644. // Check whether the dragged node was dropped over a connection.
  3645. List<Ref<GraphEdit::Connection>> intersecting_connections = graph->get_connections_intersecting_with_rect(selected_node_rect);
  3646. if (intersecting_connections.is_empty()) {
  3647. return false;
  3648. }
  3649. Ref<GraphEdit::Connection> intersecting_connection = intersecting_connections.front()->get();
  3650. if (selected_vsnode->is_any_port_connected() || selected_vsnode->get_input_port_count() == 0 || selected_vsnode->get_output_port_count() == 0) {
  3651. return false;
  3652. }
  3653. VisualShaderNode::PortType original_port_type_from = visual_shader->get_node(shader_type, String(intersecting_connection->from_node).to_int())->get_output_port_type(intersecting_connection->from_port);
  3654. VisualShaderNode::PortType original_port_type_to = visual_shader->get_node(shader_type, String(intersecting_connection->to_node).to_int())->get_input_port_type(intersecting_connection->to_port);
  3655. Ref<VisualShaderNodeReroute> reroute_node = selected_vsnode;
  3656. // Searching for the default port or the first compatible input port of the node to insert.
  3657. int _to_port = -1;
  3658. for (int i = 0; i < selected_vsnode->get_input_port_count(); i++) {
  3659. if (visual_shader->is_port_types_compatible(original_port_type_from, selected_vsnode->get_input_port_type(i)) || reroute_node.is_valid()) {
  3660. if (i == selected_vsnode->get_default_input_port(original_port_type_from)) {
  3661. _to_port = i;
  3662. break;
  3663. } else if (_to_port == -1) {
  3664. _to_port = i;
  3665. }
  3666. }
  3667. }
  3668. // Searching for the first compatible output port of the node to insert.
  3669. int _from_port = -1;
  3670. for (int i = 0; i < selected_vsnode->get_output_port_count(); i++) {
  3671. if (visual_shader->is_port_types_compatible(selected_vsnode->get_output_port_type(i), original_port_type_to) || reroute_node.is_valid()) {
  3672. _from_port = i;
  3673. break;
  3674. }
  3675. }
  3676. if (_to_port == -1 || _from_port == -1) {
  3677. return false;
  3678. }
  3679. if (r_closest_connection != nullptr) {
  3680. *r_closest_connection = intersecting_connection;
  3681. }
  3682. if (r_from_port != nullptr) {
  3683. *r_from_port = _from_port;
  3684. }
  3685. if (r_to_port != nullptr) {
  3686. *r_to_port = _to_port;
  3687. }
  3688. return true;
  3689. }
  3690. void VisualShaderEditor::_handle_node_drop_on_connection() {
  3691. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3692. undo_redo->create_action(TTR("Insert node"));
  3693. // Check whether the dragged node was dropped over a connection.
  3694. Ref<GraphEdit::Connection> closest_connection;
  3695. int _from_port = -1;
  3696. int _to_port = -1;
  3697. if (!_check_node_drop_on_connection(graph->get_local_mouse_position(), &closest_connection, &_from_port, &_to_port)) {
  3698. return;
  3699. }
  3700. int selected_node_id = drag_buffer.front()->get().node;
  3701. VisualShader::Type shader_type = get_current_shader_type();
  3702. Ref<VisualShaderNode> selected_vsnode = visual_shader->get_node(shader_type, selected_node_id);
  3703. // Delete the old connection.
  3704. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port);
  3705. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port);
  3706. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port);
  3707. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port);
  3708. // Add the connection to the dropped node.
  3709. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, selected_node_id, _to_port);
  3710. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, selected_node_id, _to_port);
  3711. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, selected_node_id, _to_port);
  3712. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, selected_node_id, _to_port);
  3713. // Add the connection from the dropped node.
  3714. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", shader_type, selected_node_id, _from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port);
  3715. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", shader_type, selected_node_id, _from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port);
  3716. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", shader_type, selected_node_id, _from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port);
  3717. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", shader_type, selected_node_id, _from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port);
  3718. undo_redo->commit_action();
  3719. call_deferred(SNAME("_update_graph"));
  3720. }
  3721. void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) {
  3722. VisualShader::Type type = VisualShader::Type(p_type);
  3723. List<VisualShader::Connection> conns;
  3724. visual_shader->get_node_connections(type, &conns);
  3725. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3726. for (const int &F : p_nodes) {
  3727. for (const VisualShader::Connection &E : conns) {
  3728. if (E.from_node == F || E.to_node == F) {
  3729. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3730. }
  3731. }
  3732. }
  3733. // The VS nodes need to be added before attaching them to frames.
  3734. for (const int &F : p_nodes) {
  3735. Ref<VisualShaderNode> node = visual_shader->get_node(type, F);
  3736. undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F), F);
  3737. undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F, false, false);
  3738. }
  3739. // Update frame references.
  3740. for (const int &node_id : p_nodes) {
  3741. Ref<VisualShaderNodeFrame> frame = visual_shader->get_node(type, node_id);
  3742. if (frame.is_valid()) {
  3743. for (const int &attached_node_id : frame->get_attached_nodes()) {
  3744. undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", type, attached_node_id);
  3745. undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", type, attached_node_id);
  3746. undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", type, attached_node_id, node_id);
  3747. undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", type, attached_node_id, node_id);
  3748. }
  3749. }
  3750. Ref<VisualShaderNode> node = visual_shader->get_node(type, node_id);
  3751. if (node->get_frame() == -1) {
  3752. continue;
  3753. }
  3754. undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", type, node_id);
  3755. undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", type, node_id);
  3756. undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", type, node_id, node->get_frame());
  3757. undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", type, node_id, node->get_frame());
  3758. }
  3759. // Restore size of the frame nodes.
  3760. for (const int &F : p_nodes) {
  3761. Ref<VisualShaderNodeFrame> frame = visual_shader->get_node(type, F);
  3762. if (frame.is_valid()) {
  3763. undo_redo->add_undo_method(this, "_set_node_size", type, F, frame->get_size());
  3764. }
  3765. }
  3766. HashSet<String> parameter_names;
  3767. for (const int &F : p_nodes) {
  3768. Ref<VisualShaderNode> node = visual_shader->get_node(type, F);
  3769. undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F);
  3770. VisualShaderNodeParameter *parameter = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  3771. if (parameter) {
  3772. parameter_names.insert(parameter->get_parameter_name());
  3773. }
  3774. }
  3775. List<VisualShader::Connection> used_conns;
  3776. for (const int &F : p_nodes) {
  3777. for (const VisualShader::Connection &E : conns) {
  3778. if (E.from_node == F || E.to_node == F) {
  3779. bool cancel = false;
  3780. for (const VisualShader::Connection &R : used_conns) {
  3781. if (R.from_node == E.from_node && R.from_port == E.from_port && R.to_node == E.to_node && R.to_port == E.to_port) {
  3782. cancel = true; // to avoid ERR_ALREADY_EXISTS warning
  3783. break;
  3784. }
  3785. }
  3786. if (!cancel) {
  3787. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3788. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3789. used_conns.push_back(E);
  3790. }
  3791. }
  3792. }
  3793. }
  3794. // Delete nodes from the graph.
  3795. for (const int &F : p_nodes) {
  3796. undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, F, false);
  3797. }
  3798. // Update parameter refs if any parameter has been deleted.
  3799. if (parameter_names.size() > 0) {
  3800. undo_redo->add_do_method(this, "_update_parameters", true);
  3801. undo_redo->add_undo_method(this, "_update_parameters", true);
  3802. _update_parameter_refs(parameter_names);
  3803. }
  3804. }
  3805. void VisualShaderEditor::_replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to) {
  3806. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3807. undo_redo->add_do_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_to);
  3808. undo_redo->add_undo_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_from);
  3809. }
  3810. void VisualShaderEditor::_update_constant(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port) {
  3811. Ref<VisualShaderNode> node = visual_shader->get_node(p_type_id, p_node_id);
  3812. ERR_FAIL_COND(node.is_null());
  3813. ERR_FAIL_COND(!node->has_method("set_constant"));
  3814. node->call("set_constant", p_var);
  3815. if (p_preview_port != -1) {
  3816. node->set_output_port_for_preview(p_preview_port);
  3817. }
  3818. }
  3819. void VisualShaderEditor::_update_parameter(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port) {
  3820. Ref<VisualShaderNodeParameter> parameter = visual_shader->get_node(p_type_id, p_node_id);
  3821. ERR_FAIL_COND(parameter.is_null());
  3822. String valid_name = visual_shader->validate_parameter_name(parameter->get_parameter_name(), parameter);
  3823. parameter->set_parameter_name(valid_name);
  3824. graph_plugin->set_parameter_name(p_type_id, p_node_id, valid_name);
  3825. if (parameter->has_method("set_default_value_enabled")) {
  3826. parameter->call("set_default_value_enabled", true);
  3827. parameter->call("set_default_value", p_var);
  3828. }
  3829. if (p_preview_port != -1) {
  3830. parameter->set_output_port_for_preview(p_preview_port);
  3831. }
  3832. }
  3833. void VisualShaderEditor::_convert_constants_to_parameters(bool p_vice_versa) {
  3834. VisualShader::Type type_id = get_current_shader_type();
  3835. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3836. if (!p_vice_versa) {
  3837. undo_redo->create_action(TTR("Convert Constant Node(s) To Parameter(s)"));
  3838. } else {
  3839. undo_redo->create_action(TTR("Convert Parameter Node(s) To Constant(s)"));
  3840. }
  3841. const HashSet<int> &current_set = p_vice_versa ? selected_parameters : selected_constants;
  3842. HashSet<String> deleted_names;
  3843. for (const int &E : current_set) {
  3844. int node_id = E;
  3845. Ref<VisualShaderNode> node = visual_shader->get_node(type_id, node_id);
  3846. bool caught = false;
  3847. Variant var;
  3848. // float
  3849. if (!p_vice_versa) {
  3850. Ref<VisualShaderNodeFloatConstant> float_const = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
  3851. if (float_const.is_valid()) {
  3852. _replace_node(type_id, node_id, "VisualShaderNodeFloatConstant", "VisualShaderNodeFloatParameter");
  3853. var = float_const->get_constant();
  3854. caught = true;
  3855. }
  3856. } else {
  3857. Ref<VisualShaderNodeFloatParameter> float_parameter = Object::cast_to<VisualShaderNodeFloatParameter>(node.ptr());
  3858. if (float_parameter.is_valid()) {
  3859. _replace_node(type_id, node_id, "VisualShaderNodeFloatParameter", "VisualShaderNodeFloatConstant");
  3860. var = float_parameter->get_default_value();
  3861. caught = true;
  3862. }
  3863. }
  3864. // int
  3865. if (!caught) {
  3866. if (!p_vice_versa) {
  3867. Ref<VisualShaderNodeIntConstant> int_const = Object::cast_to<VisualShaderNodeIntConstant>(node.ptr());
  3868. if (int_const.is_valid()) {
  3869. _replace_node(type_id, node_id, "VisualShaderNodeIntConstant", "VisualShaderNodeIntParameter");
  3870. var = int_const->get_constant();
  3871. caught = true;
  3872. }
  3873. } else {
  3874. Ref<VisualShaderNodeIntParameter> int_parameter = Object::cast_to<VisualShaderNodeIntParameter>(node.ptr());
  3875. if (int_parameter.is_valid()) {
  3876. _replace_node(type_id, node_id, "VisualShaderNodeIntParameter", "VisualShaderNodeIntConstant");
  3877. var = int_parameter->get_default_value();
  3878. caught = true;
  3879. }
  3880. }
  3881. }
  3882. // boolean
  3883. if (!caught) {
  3884. if (!p_vice_versa) {
  3885. Ref<VisualShaderNodeBooleanConstant> boolean_const = Object::cast_to<VisualShaderNodeBooleanConstant>(node.ptr());
  3886. if (boolean_const.is_valid()) {
  3887. _replace_node(type_id, node_id, "VisualShaderNodeBooleanConstant", "VisualShaderNodeBooleanParameter");
  3888. var = boolean_const->get_constant();
  3889. caught = true;
  3890. }
  3891. } else {
  3892. Ref<VisualShaderNodeBooleanParameter> boolean_parameter = Object::cast_to<VisualShaderNodeBooleanParameter>(node.ptr());
  3893. if (boolean_parameter.is_valid()) {
  3894. _replace_node(type_id, node_id, "VisualShaderNodeBooleanParameter", "VisualShaderNodeBooleanConstant");
  3895. var = boolean_parameter->get_default_value();
  3896. caught = true;
  3897. }
  3898. }
  3899. }
  3900. // vec2
  3901. if (!caught) {
  3902. if (!p_vice_versa) {
  3903. Ref<VisualShaderNodeVec2Constant> vec2_const = Object::cast_to<VisualShaderNodeVec2Constant>(node.ptr());
  3904. if (vec2_const.is_valid()) {
  3905. _replace_node(type_id, node_id, "VisualShaderNodeVec2Constant", "VisualShaderNodeVec2Parameter");
  3906. var = vec2_const->get_constant();
  3907. caught = true;
  3908. }
  3909. } else {
  3910. Ref<VisualShaderNodeVec2Parameter> vec2_parameter = Object::cast_to<VisualShaderNodeVec2Parameter>(node.ptr());
  3911. if (vec2_parameter.is_valid()) {
  3912. _replace_node(type_id, node_id, "VisualShaderNodeVec2Parameter", "VisualShaderNodeVec2Constant");
  3913. var = vec2_parameter->get_default_value();
  3914. caught = true;
  3915. }
  3916. }
  3917. }
  3918. // vec3
  3919. if (!caught) {
  3920. if (!p_vice_versa) {
  3921. Ref<VisualShaderNodeVec3Constant> vec3_const = Object::cast_to<VisualShaderNodeVec3Constant>(node.ptr());
  3922. if (vec3_const.is_valid()) {
  3923. _replace_node(type_id, node_id, "VisualShaderNodeVec3Constant", "VisualShaderNodeVec3Parameter");
  3924. var = vec3_const->get_constant();
  3925. caught = true;
  3926. }
  3927. } else {
  3928. Ref<VisualShaderNodeVec3Parameter> vec3_parameter = Object::cast_to<VisualShaderNodeVec3Parameter>(node.ptr());
  3929. if (vec3_parameter.is_valid()) {
  3930. _replace_node(type_id, node_id, "VisualShaderNodeVec3Parameter", "VisualShaderNodeVec3Constant");
  3931. var = vec3_parameter->get_default_value();
  3932. caught = true;
  3933. }
  3934. }
  3935. }
  3936. // vec4
  3937. if (!caught) {
  3938. if (!p_vice_versa) {
  3939. Ref<VisualShaderNodeVec4Constant> vec4_const = Object::cast_to<VisualShaderNodeVec4Constant>(node.ptr());
  3940. if (vec4_const.is_valid()) {
  3941. _replace_node(type_id, node_id, "VisualShaderNodeVec4Constant", "VisualShaderNodeVec4Parameter");
  3942. var = vec4_const->get_constant();
  3943. caught = true;
  3944. }
  3945. } else {
  3946. Ref<VisualShaderNodeVec4Parameter> vec4_parameter = Object::cast_to<VisualShaderNodeVec4Parameter>(node.ptr());
  3947. if (vec4_parameter.is_valid()) {
  3948. _replace_node(type_id, node_id, "VisualShaderNodeVec4Parameter", "VisualShaderNodeVec4Constant");
  3949. var = vec4_parameter->get_default_value();
  3950. caught = true;
  3951. }
  3952. }
  3953. }
  3954. // color
  3955. if (!caught) {
  3956. if (!p_vice_versa) {
  3957. Ref<VisualShaderNodeColorConstant> color_const = Object::cast_to<VisualShaderNodeColorConstant>(node.ptr());
  3958. if (color_const.is_valid()) {
  3959. _replace_node(type_id, node_id, "VisualShaderNodeColorConstant", "VisualShaderNodeColorParameter");
  3960. var = color_const->get_constant();
  3961. caught = true;
  3962. }
  3963. } else {
  3964. Ref<VisualShaderNodeColorParameter> color_parameter = Object::cast_to<VisualShaderNodeColorParameter>(node.ptr());
  3965. if (color_parameter.is_valid()) {
  3966. _replace_node(type_id, node_id, "VisualShaderNodeColorParameter", "VisualShaderNodeColorConstant");
  3967. var = color_parameter->get_default_value();
  3968. caught = true;
  3969. }
  3970. }
  3971. }
  3972. // transform
  3973. if (!caught) {
  3974. if (!p_vice_versa) {
  3975. Ref<VisualShaderNodeTransformConstant> transform_const = Object::cast_to<VisualShaderNodeTransformConstant>(node.ptr());
  3976. if (transform_const.is_valid()) {
  3977. _replace_node(type_id, node_id, "VisualShaderNodeTransformConstant", "VisualShaderNodeTransformParameter");
  3978. var = transform_const->get_constant();
  3979. caught = true;
  3980. }
  3981. } else {
  3982. Ref<VisualShaderNodeTransformParameter> transform_parameter = Object::cast_to<VisualShaderNodeTransformParameter>(node.ptr());
  3983. if (transform_parameter.is_valid()) {
  3984. _replace_node(type_id, node_id, "VisualShaderNodeTransformParameter", "VisualShaderNodeTransformConstant");
  3985. var = transform_parameter->get_default_value();
  3986. caught = true;
  3987. }
  3988. }
  3989. }
  3990. ERR_CONTINUE(!caught);
  3991. int preview_port = node->get_output_port_for_preview();
  3992. if (!p_vice_versa) {
  3993. undo_redo->add_do_method(this, "_update_parameter", type_id, node_id, var, preview_port);
  3994. undo_redo->add_undo_method(this, "_update_constant", type_id, node_id, var, preview_port);
  3995. } else {
  3996. undo_redo->add_do_method(this, "_update_constant", type_id, node_id, var, preview_port);
  3997. undo_redo->add_undo_method(this, "_update_parameter", type_id, node_id, var, preview_port);
  3998. Ref<VisualShaderNodeParameter> parameter = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  3999. ERR_CONTINUE(parameter.is_null());
  4000. deleted_names.insert(parameter->get_parameter_name());
  4001. }
  4002. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type_id, node_id);
  4003. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type_id, node_id);
  4004. }
  4005. undo_redo->add_do_method(this, "_update_parameters", true);
  4006. undo_redo->add_undo_method(this, "_update_parameters", true);
  4007. if (deleted_names.size() > 0) {
  4008. _update_parameter_refs(deleted_names);
  4009. }
  4010. undo_redo->commit_action();
  4011. }
  4012. void VisualShaderEditor::_detach_nodes_from_frame(int p_type, const List<int> &p_nodes) {
  4013. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4014. for (int node_id : p_nodes) {
  4015. Ref<VisualShaderNode> node = visual_shader->get_node((VisualShader::Type)p_type, node_id);
  4016. if (node.is_null()) {
  4017. continue;
  4018. }
  4019. int frame_id = node->get_frame();
  4020. if (frame_id != -1) {
  4021. undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", p_type, node_id);
  4022. undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", p_type, node_id);
  4023. undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", p_type, node_id, frame_id);
  4024. undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", p_type, node_id, frame_id);
  4025. }
  4026. }
  4027. }
  4028. void VisualShaderEditor::_detach_nodes_from_frame_request() {
  4029. // Called from context menu.
  4030. List<int> to_detach_node_ids;
  4031. for (int i = 0; i < graph->get_child_count(); i++) {
  4032. GraphElement *gn = Object::cast_to<GraphElement>(graph->get_child(i));
  4033. if (gn) {
  4034. int id = String(gn->get_name()).to_int();
  4035. if (gn->is_selected()) {
  4036. to_detach_node_ids.push_back(id);
  4037. }
  4038. }
  4039. }
  4040. if (to_detach_node_ids.is_empty()) {
  4041. return;
  4042. }
  4043. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4044. undo_redo->create_action(TTR("Detach VisualShader Node(s) from Frame"));
  4045. _detach_nodes_from_frame(get_current_shader_type(), to_detach_node_ids);
  4046. undo_redo->commit_action();
  4047. }
  4048. void VisualShaderEditor::_delete_node_request(int p_type, int p_node) {
  4049. Ref<VisualShaderNode> node = visual_shader->get_node((VisualShader::Type)p_type, p_node);
  4050. if (!node->is_deletable()) {
  4051. return;
  4052. }
  4053. List<int> to_erase;
  4054. to_erase.push_back(p_node);
  4055. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4056. undo_redo->create_action(TTR("Delete VisualShader Node"));
  4057. _delete_nodes(p_type, to_erase);
  4058. undo_redo->commit_action();
  4059. }
  4060. void VisualShaderEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) {
  4061. List<int> to_erase;
  4062. if (p_nodes.is_empty()) {
  4063. // Called from context menu.
  4064. for (int i = 0; i < graph->get_child_count(); i++) {
  4065. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  4066. if (!graph_element) {
  4067. continue;
  4068. }
  4069. VisualShader::Type type = get_current_shader_type();
  4070. int id = String(graph_element->get_name()).to_int();
  4071. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  4072. if (vsnode->is_deletable() && graph_element->is_selected()) {
  4073. to_erase.push_back(graph_element->get_name().operator String().to_int());
  4074. }
  4075. }
  4076. } else {
  4077. VisualShader::Type type = get_current_shader_type();
  4078. for (int i = 0; i < p_nodes.size(); i++) {
  4079. int id = p_nodes[i].operator String().to_int();
  4080. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  4081. if (vsnode->is_deletable()) {
  4082. to_erase.push_back(id);
  4083. }
  4084. }
  4085. }
  4086. if (to_erase.is_empty()) {
  4087. return;
  4088. }
  4089. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4090. undo_redo->create_action(TTR("Delete VisualShader Node(s)"));
  4091. _delete_nodes(get_current_shader_type(), to_erase);
  4092. undo_redo->commit_action();
  4093. }
  4094. void VisualShaderEditor::_node_selected(Object *p_node) {
  4095. VisualShader::Type type = get_current_shader_type();
  4096. GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
  4097. ERR_FAIL_NULL(graph_element);
  4098. int id = String(graph_element->get_name()).to_int();
  4099. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  4100. ERR_FAIL_COND(vsnode.is_null());
  4101. }
  4102. void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
  4103. Ref<InputEventMouseMotion> mm = p_event;
  4104. Ref<InputEventMouseButton> mb = p_event;
  4105. VisualShader::Type type = get_current_shader_type();
  4106. // Highlight valid connection on which a node can be dropped.
  4107. if (mm.is_valid() && mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) {
  4108. Ref<GraphEdit::Connection> closest_connection;
  4109. graph->reset_all_connection_activity();
  4110. if (_check_node_drop_on_connection(graph->get_local_mouse_position(), &closest_connection)) {
  4111. graph->set_connection_activity(closest_connection->from_node, closest_connection->from_port, closest_connection->to_node, closest_connection->to_port, 1.0);
  4112. }
  4113. }
  4114. Ref<VisualShaderNode> selected_vsnode;
  4115. // Right click actions.
  4116. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {
  4117. selected_constants.clear();
  4118. selected_parameters.clear();
  4119. selected_frame = -1;
  4120. selected_float_constant = -1;
  4121. List<int> selected_deletable_graph_elements;
  4122. List<GraphElement *> selected_graph_elements;
  4123. for (int i = 0; i < graph->get_child_count(); i++) {
  4124. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  4125. if (!graph_element) {
  4126. continue;
  4127. }
  4128. int id = String(graph_element->get_name()).to_int();
  4129. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  4130. if (!graph_element->is_selected()) {
  4131. continue;
  4132. }
  4133. selected_graph_elements.push_back(graph_element);
  4134. if (!vsnode->is_deletable()) {
  4135. continue;
  4136. }
  4137. selected_deletable_graph_elements.push_back(id);
  4138. Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
  4139. selected_vsnode = node;
  4140. VisualShaderNodeFrame *frame_node = Object::cast_to<VisualShaderNodeFrame>(node.ptr());
  4141. if (frame_node != nullptr) {
  4142. selected_frame = id;
  4143. }
  4144. VisualShaderNodeConstant *constant_node = Object::cast_to<VisualShaderNodeConstant>(node.ptr());
  4145. if (constant_node != nullptr) {
  4146. selected_constants.insert(id);
  4147. }
  4148. VisualShaderNodeFloatConstant *float_constant_node = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
  4149. if (float_constant_node != nullptr) {
  4150. selected_float_constant = id;
  4151. }
  4152. VisualShaderNodeParameter *parameter_node = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  4153. if (parameter_node != nullptr && parameter_node->is_convertible_to_constant()) {
  4154. selected_parameters.insert(id);
  4155. }
  4156. }
  4157. if (selected_deletable_graph_elements.size() > 1) {
  4158. selected_frame = -1;
  4159. selected_float_constant = -1;
  4160. }
  4161. bool copy_buffer_empty = true;
  4162. for (const CopyItem &item : copy_items_buffer) {
  4163. if (!item.disabled) {
  4164. copy_buffer_empty = false;
  4165. break;
  4166. }
  4167. }
  4168. menu_point = graph->get_local_mouse_position();
  4169. Point2 gpos = get_screen_position() + get_local_mouse_position();
  4170. Ref<GraphEdit::Connection> closest_connection = graph->get_closest_connection_at_point(menu_point);
  4171. if (closest_connection.is_valid()) {
  4172. clicked_connection = closest_connection;
  4173. saved_node_pos = graph->get_local_mouse_position();
  4174. saved_node_pos_dirty = true;
  4175. connection_popup_menu->set_position(gpos);
  4176. connection_popup_menu->reset_size();
  4177. connection_popup_menu->popup();
  4178. } else if (selected_graph_elements.is_empty() && copy_buffer_empty) {
  4179. _show_members_dialog(true);
  4180. } else {
  4181. popup_menu->set_item_disabled(NodeMenuOptions::CUT, selected_deletable_graph_elements.is_empty());
  4182. popup_menu->set_item_disabled(NodeMenuOptions::COPY, selected_deletable_graph_elements.is_empty());
  4183. popup_menu->set_item_disabled(NodeMenuOptions::PASTE, copy_buffer_empty);
  4184. popup_menu->set_item_disabled(NodeMenuOptions::DELETE_, selected_deletable_graph_elements.is_empty());
  4185. popup_menu->set_item_disabled(NodeMenuOptions::DUPLICATE, selected_deletable_graph_elements.is_empty());
  4186. popup_menu->set_item_disabled(NodeMenuOptions::CLEAR_COPY_BUFFER, copy_buffer_empty);
  4187. int temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR2);
  4188. if (temp != -1) {
  4189. popup_menu->remove_item(temp);
  4190. }
  4191. temp = popup_menu->get_item_index(NodeMenuOptions::FLOAT_CONSTANTS);
  4192. if (temp != -1) {
  4193. popup_menu->remove_item(temp);
  4194. }
  4195. temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS);
  4196. if (temp != -1) {
  4197. popup_menu->remove_item(temp);
  4198. }
  4199. temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS);
  4200. if (temp != -1) {
  4201. popup_menu->remove_item(temp);
  4202. }
  4203. temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR3);
  4204. if (temp != -1) {
  4205. popup_menu->remove_item(temp);
  4206. }
  4207. temp = popup_menu->get_item_index(NodeMenuOptions::UNLINK_FROM_PARENT_FRAME);
  4208. if (temp != -1) {
  4209. popup_menu->remove_item(temp);
  4210. }
  4211. temp = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_TITLE);
  4212. if (temp != -1) {
  4213. popup_menu->remove_item(temp);
  4214. }
  4215. temp = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR);
  4216. if (temp != -1) {
  4217. popup_menu->remove_item(temp);
  4218. }
  4219. temp = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_COLOR);
  4220. if (temp != -1) {
  4221. popup_menu->remove_item(temp);
  4222. }
  4223. temp = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  4224. if (temp != -1) {
  4225. popup_menu->remove_item(temp);
  4226. }
  4227. if (selected_constants.size() > 0 || selected_parameters.size() > 0) {
  4228. popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2);
  4229. if (selected_float_constant != -1) {
  4230. if (!constants_submenu) {
  4231. constants_submenu = memnew(PopupMenu);
  4232. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  4233. constants_submenu->add_item(float_constant_defs[i].name, i);
  4234. }
  4235. constants_submenu->connect("index_pressed", callable_mp(this, &VisualShaderEditor::_float_constant_selected));
  4236. }
  4237. popup_menu->add_submenu_node_item(TTR("Float Constants"), constants_submenu, int(NodeMenuOptions::FLOAT_CONSTANTS));
  4238. }
  4239. if (selected_constants.size() > 0) {
  4240. popup_menu->add_item(TTR("Convert Constant(s) to Parameter(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS);
  4241. }
  4242. if (selected_parameters.size() > 0) {
  4243. popup_menu->add_item(TTR("Convert Parameter(s) to Constant(s)"), NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS);
  4244. }
  4245. }
  4246. // Check if any selected node is attached to a frame.
  4247. bool is_attached_to_frame = false;
  4248. for (GraphElement *graph_element : selected_graph_elements) {
  4249. if (graph->get_element_frame(graph_element->get_name())) {
  4250. is_attached_to_frame = true;
  4251. break;
  4252. }
  4253. }
  4254. if (is_attached_to_frame) {
  4255. popup_menu->add_item(TTR("Detach from Parent Frame"), NodeMenuOptions::UNLINK_FROM_PARENT_FRAME);
  4256. }
  4257. if (selected_frame != -1) {
  4258. popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3);
  4259. popup_menu->add_item(TTR("Set Frame Title"), NodeMenuOptions::SET_FRAME_TITLE);
  4260. popup_menu->add_check_item(TTR("Enable Auto Shrink"), NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  4261. popup_menu->add_check_item(TTR("Enable Tint Color"), NodeMenuOptions::ENABLE_FRAME_COLOR);
  4262. VisualShaderNodeFrame *frame_ref = Object::cast_to<VisualShaderNodeFrame>(selected_vsnode.ptr());
  4263. if (frame_ref) {
  4264. int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR);
  4265. popup_menu->set_item_checked(item_index, frame_ref->is_tint_color_enabled());
  4266. if (frame_ref->is_tint_color_enabled()) {
  4267. popup_menu->add_item(TTR("Set Tint Color"), NodeMenuOptions::SET_FRAME_COLOR);
  4268. }
  4269. item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  4270. popup_menu->set_item_checked(item_index, frame_ref->is_autoshrink_enabled());
  4271. }
  4272. }
  4273. popup_menu->set_position(gpos);
  4274. popup_menu->reset_size();
  4275. popup_menu->popup();
  4276. }
  4277. }
  4278. }
  4279. void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type, VisualShaderNode::PortType p_output_port_type) {
  4280. if (members_input_port_type != p_input_port_type || members_output_port_type != p_output_port_type) {
  4281. members_input_port_type = p_input_port_type;
  4282. members_output_port_type = p_output_port_type;
  4283. _update_options_menu();
  4284. }
  4285. if (at_mouse_pos) {
  4286. saved_node_pos_dirty = true;
  4287. saved_node_pos = graph->get_local_mouse_position();
  4288. Point2 gpos = get_screen_position() + get_local_mouse_position();
  4289. members_dialog->set_position(gpos);
  4290. } else {
  4291. saved_node_pos_dirty = false;
  4292. members_dialog->set_position(graph->get_screen_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  4293. }
  4294. if (members_dialog->is_visible()) {
  4295. members_dialog->grab_focus();
  4296. return;
  4297. }
  4298. members_dialog->popup();
  4299. // Keep dialog within window bounds.
  4300. Rect2 window_rect = Rect2(get_window()->get_position(), get_window()->get_size());
  4301. Rect2 dialog_rect = Rect2(members_dialog->get_position(), members_dialog->get_size());
  4302. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0);
  4303. members_dialog->set_position(members_dialog->get_position() - difference);
  4304. node_filter->grab_focus();
  4305. node_filter->select_all();
  4306. }
  4307. void VisualShaderEditor::_varying_menu_id_pressed(int p_idx) {
  4308. switch (VaryingMenuOptions(p_idx)) {
  4309. case VaryingMenuOptions::ADD: {
  4310. _show_add_varying_dialog();
  4311. } break;
  4312. case VaryingMenuOptions::REMOVE: {
  4313. _show_remove_varying_dialog();
  4314. } break;
  4315. default:
  4316. break;
  4317. }
  4318. }
  4319. void VisualShaderEditor::_show_add_varying_dialog() {
  4320. _varying_name_changed(varying_name->get_text());
  4321. add_varying_dialog->set_position(graph->get_screen_position() + varying_button->get_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  4322. add_varying_dialog->popup();
  4323. varying_name->grab_focus();
  4324. // Keep dialog within window bounds.
  4325. Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size());
  4326. Rect2 dialog_rect = Rect2(add_varying_dialog->get_position(), add_varying_dialog->get_size());
  4327. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0);
  4328. add_varying_dialog->set_position(add_varying_dialog->get_position() - difference);
  4329. }
  4330. void VisualShaderEditor::_show_remove_varying_dialog() {
  4331. remove_varying_dialog->set_position(graph->get_screen_position() + varying_button->get_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  4332. remove_varying_dialog->popup();
  4333. varyings->grab_focus();
  4334. // Keep dialog within window bounds.
  4335. Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size());
  4336. Rect2 dialog_rect = Rect2(remove_varying_dialog->get_position(), remove_varying_dialog->get_size());
  4337. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0);
  4338. remove_varying_dialog->set_position(remove_varying_dialog->get_position() - difference);
  4339. }
  4340. void VisualShaderEditor::_sbox_input(const Ref<InputEvent> &p_event) {
  4341. // Redirect navigational key events to the tree.
  4342. Ref<InputEventKey> key = p_event;
  4343. if (key.is_valid()) {
  4344. if (key->is_action("ui_up", true) || key->is_action("ui_down", true) || key->is_action("ui_page_up") || key->is_action("ui_page_down")) {
  4345. members->gui_input(key);
  4346. node_filter->accept_event();
  4347. }
  4348. }
  4349. }
  4350. void VisualShaderEditor::_param_filter_changed(const String &p_text) {
  4351. param_filter_name = p_text;
  4352. if (!_update_preview_parameter_tree()) {
  4353. _clear_preview_param();
  4354. }
  4355. }
  4356. void VisualShaderEditor::_param_property_changed(const String &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
  4357. if (p_changing) {
  4358. return;
  4359. }
  4360. String raw_prop_name = p_property.trim_prefix("shader_parameter/");
  4361. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4362. undo_redo->create_action(vformat(TTR("Edit Preview Parameter: %s"), p_property));
  4363. undo_redo->add_do_method(visual_shader.ptr(), "_set_preview_shader_parameter", raw_prop_name, p_value);
  4364. undo_redo->add_undo_method(visual_shader.ptr(), "_set_preview_shader_parameter", raw_prop_name, preview_material->get(p_property));
  4365. undo_redo->add_do_method(this, "_update_current_param");
  4366. undo_redo->add_undo_method(this, "_update_current_param");
  4367. undo_redo->commit_action();
  4368. }
  4369. void VisualShaderEditor::_update_current_param() {
  4370. if (current_prop != nullptr) {
  4371. String name = current_prop->get_meta("id");
  4372. if (visual_shader->_has_preview_shader_parameter(name)) {
  4373. preview_material->set("shader_parameter/" + name, visual_shader->_get_preview_shader_parameter(name));
  4374. } else {
  4375. preview_material->set("shader_parameter/" + name, Variant());
  4376. }
  4377. current_prop->update_property();
  4378. current_prop->update_editor_property_status();
  4379. current_prop->update_cache();
  4380. }
  4381. }
  4382. void VisualShaderEditor::_param_selected() {
  4383. _clear_preview_param();
  4384. TreeItem *item = parameters->get_selected();
  4385. selected_param_id = item->get_meta("id");
  4386. PropertyInfo pi = parameter_props.get(selected_param_id);
  4387. EditorProperty *prop = EditorInspector::instantiate_property_editor(preview_material.ptr(), pi.type, pi.name, pi.hint, pi.hint_string, pi.usage);
  4388. if (!prop) {
  4389. return;
  4390. }
  4391. prop->connect("property_changed", callable_mp(this, &VisualShaderEditor::_param_property_changed));
  4392. prop->set_h_size_flags(SIZE_EXPAND_FILL);
  4393. prop->set_object_and_property(preview_material.ptr(), "shader_parameter/" + pi.name);
  4394. prop->set_label(TTR("Value:"));
  4395. prop->update_property();
  4396. prop->update_editor_property_status();
  4397. prop->update_cache();
  4398. current_prop = prop;
  4399. current_prop->set_meta("id", selected_param_id);
  4400. param_vbox2->add_child(prop);
  4401. param_vbox->show();
  4402. }
  4403. void VisualShaderEditor::_param_unselected() {
  4404. parameters->deselect_all();
  4405. _clear_preview_param();
  4406. }
  4407. void VisualShaderEditor::_help_open() {
  4408. OS::get_singleton()->shell_open(vformat("%s/tutorials/shaders/visual_shaders.html", GODOT_VERSION_DOCS_URL));
  4409. }
  4410. void VisualShaderEditor::_notification(int p_what) {
  4411. switch (p_what) {
  4412. case NOTIFICATION_POSTINITIALIZE: {
  4413. _update_options_menu();
  4414. } break;
  4415. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  4416. if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/panning")) {
  4417. graph->get_panner()->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EDITOR_GET("editors/panning/simple_panning")));
  4418. graph->set_warped_panning(EDITOR_GET("editors/panning/warped_mouse_panning"));
  4419. }
  4420. if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/visual_editors")) {
  4421. graph->set_minimap_opacity(EDITOR_GET("editors/visual_editors/minimap_opacity"));
  4422. graph->set_grid_pattern((GraphEdit::GridPattern) int(EDITOR_GET("editors/visual_editors/grid_pattern")));
  4423. graph->set_connection_lines_curvature(EDITOR_GET("editors/visual_editors/lines_curvature"));
  4424. _update_graph();
  4425. }
  4426. } break;
  4427. case NOTIFICATION_ENTER_TREE: {
  4428. node_filter->set_clear_button_enabled(true);
  4429. // collapse tree by default
  4430. TreeItem *category = members->get_root()->get_first_child();
  4431. while (category) {
  4432. category->set_collapsed(true);
  4433. TreeItem *sub_category = category->get_first_child();
  4434. while (sub_category) {
  4435. sub_category->set_collapsed(true);
  4436. sub_category = sub_category->get_next();
  4437. }
  4438. category = category->get_next();
  4439. }
  4440. graph->get_panner()->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EDITOR_GET("editors/panning/simple_panning")));
  4441. graph->set_warped_panning(EDITOR_GET("editors/panning/warped_mouse_panning"));
  4442. } break;
  4443. case NOTIFICATION_THEME_CHANGED: {
  4444. site_search->set_button_icon(get_editor_theme_icon(SNAME("ExternalLink")));
  4445. highend_label->set_modulate(get_theme_color(SNAME("highend_color"), EditorStringName(Editor)));
  4446. param_filter->set_right_icon(Control::get_editor_theme_icon(SNAME("Search")));
  4447. node_filter->set_right_icon(Control::get_editor_theme_icon(SNAME("Search")));
  4448. code_preview_button->set_button_icon(Control::get_editor_theme_icon(SNAME("Shader")));
  4449. shader_preview_button->set_button_icon(Control::get_editor_theme_icon(SNAME("SubViewport")));
  4450. {
  4451. Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color");
  4452. Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color");
  4453. Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
  4454. Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color");
  4455. Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
  4456. Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color");
  4457. Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color");
  4458. Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color");
  4459. Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color");
  4460. Color error_color = get_theme_color(SNAME("error_color"), EditorStringName(Editor));
  4461. preview_text->add_theme_color_override("background_color", background_color);
  4462. varying_error_label->add_theme_color_override(SceneStringName(font_color), error_color);
  4463. for (const String &E : keyword_list) {
  4464. if (ShaderLanguage::is_control_flow_keyword(E)) {
  4465. syntax_highlighter->add_keyword_color(E, control_flow_keyword_color);
  4466. } else {
  4467. syntax_highlighter->add_keyword_color(E, keyword_color);
  4468. }
  4469. }
  4470. preview_text->begin_bulk_theme_override();
  4471. preview_text->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("expression"), EditorStringName(EditorFonts)));
  4472. preview_text->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("expression_size"), EditorStringName(EditorFonts)));
  4473. preview_text->add_theme_color_override(SceneStringName(font_color), text_color);
  4474. preview_text->end_bulk_theme_override();
  4475. syntax_highlighter->set_number_color(number_color);
  4476. syntax_highlighter->set_symbol_color(symbol_color);
  4477. syntax_highlighter->set_function_color(function_color);
  4478. syntax_highlighter->set_member_variable_color(members_color);
  4479. syntax_highlighter->clear_color_regions();
  4480. syntax_highlighter->add_color_region("/*", "*/", comment_color, false);
  4481. syntax_highlighter->add_color_region("//", "", comment_color, true);
  4482. preview_text->clear_comment_delimiters();
  4483. preview_text->add_comment_delimiter("/*", "*/", false);
  4484. preview_text->add_comment_delimiter("//", "", true);
  4485. error_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Panel")));
  4486. error_label->begin_bulk_theme_override();
  4487. error_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));
  4488. error_label->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));
  4489. error_label->add_theme_color_override(SceneStringName(font_color), error_color);
  4490. error_label->end_bulk_theme_override();
  4491. }
  4492. tools->set_button_icon(get_editor_theme_icon(SNAME("Tools")));
  4493. preview_tools->set_button_icon(get_editor_theme_icon(SNAME("Tools")));
  4494. if (is_visible_in_tree()) {
  4495. _update_graph();
  4496. }
  4497. update_toggle_files_button();
  4498. } break;
  4499. case NOTIFICATION_VISIBILITY_CHANGED: {
  4500. update_toggle_files_button();
  4501. } break;
  4502. case NOTIFICATION_DRAG_BEGIN: {
  4503. Dictionary dd = get_viewport()->gui_get_drag_data();
  4504. if (members->is_visible_in_tree() && dd.has("id")) {
  4505. members->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
  4506. }
  4507. } break;
  4508. case NOTIFICATION_DRAG_END: {
  4509. members->set_drop_mode_flags(0);
  4510. } break;
  4511. }
  4512. }
  4513. void VisualShaderEditor::_scroll_offset_changed(const Vector2 &p_scroll) {
  4514. if (!shader_fully_loaded) {
  4515. return;
  4516. }
  4517. panning_debounce_timer->start();
  4518. }
  4519. void VisualShaderEditor::_node_changed(int p_id) {
  4520. if (is_visible_in_tree()) {
  4521. _update_graph();
  4522. }
  4523. }
  4524. void VisualShaderEditor::_nodes_linked_to_frame_request(const TypedArray<StringName> &p_nodes, const StringName &p_frame) {
  4525. Vector<int> node_ids;
  4526. for (int i = 0; i < p_nodes.size(); i++) {
  4527. node_ids.push_back(p_nodes[i].operator String().to_int());
  4528. }
  4529. frame_node_id_to_link_to = p_frame.operator String().to_int();
  4530. nodes_link_to_frame_buffer = node_ids;
  4531. }
  4532. void VisualShaderEditor::_frame_rect_changed(const GraphFrame *p_frame, const Rect2 &p_new_rect) {
  4533. if (p_frame == nullptr) {
  4534. return;
  4535. }
  4536. int node_id = String(p_frame->get_name()).to_int();
  4537. Ref<VisualShaderNodeResizableBase> vsnode = visual_shader->get_node(get_current_shader_type(), node_id);
  4538. if (vsnode.is_null()) {
  4539. return;
  4540. }
  4541. vsnode->set_size(p_new_rect.size / graph->get_zoom());
  4542. }
  4543. void VisualShaderEditor::_dup_copy_nodes(int p_type, List<CopyItem> &r_items, List<VisualShader::Connection> &r_connections) {
  4544. VisualShader::Type type = (VisualShader::Type)p_type;
  4545. selection_center.x = 0.0f;
  4546. selection_center.y = 0.0f;
  4547. HashSet<int> nodes;
  4548. for (int i = 0; i < graph->get_child_count(); i++) {
  4549. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  4550. if (graph_element) {
  4551. int id = String(graph_element->get_name()).to_int();
  4552. Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
  4553. Ref<VisualShaderNodeOutput> output = node;
  4554. if (output.is_valid()) { // can't duplicate output
  4555. continue;
  4556. }
  4557. if (node.is_valid() && graph_element->is_selected()) {
  4558. Vector2 pos = visual_shader->get_node_position(type, id);
  4559. selection_center += pos;
  4560. CopyItem item;
  4561. item.id = id;
  4562. item.node = visual_shader->get_node(type, id)->duplicate();
  4563. item.position = visual_shader->get_node_position(type, id);
  4564. Ref<VisualShaderNodeResizableBase> resizable_base = node;
  4565. if (resizable_base.is_valid()) {
  4566. item.size = resizable_base->get_size();
  4567. }
  4568. Ref<VisualShaderNodeGroupBase> group = node;
  4569. if (group.is_valid()) {
  4570. item.group_inputs = group->get_inputs();
  4571. item.group_outputs = group->get_outputs();
  4572. }
  4573. Ref<VisualShaderNodeExpression> expression = node;
  4574. if (expression.is_valid()) {
  4575. item.expression = expression->get_expression();
  4576. }
  4577. r_items.push_back(item);
  4578. nodes.insert(id);
  4579. }
  4580. }
  4581. }
  4582. List<VisualShader::Connection> node_connections;
  4583. visual_shader->get_node_connections(type, &node_connections);
  4584. for (const VisualShader::Connection &E : node_connections) {
  4585. if (nodes.has(E.from_node) && nodes.has(E.to_node)) {
  4586. r_connections.push_back(E);
  4587. }
  4588. }
  4589. selection_center /= (float)r_items.size();
  4590. }
  4591. void VisualShaderEditor::_dup_paste_nodes(int p_type, List<CopyItem> &r_items, const List<VisualShader::Connection> &p_connections, const Vector2 &p_offset, bool p_duplicate) {
  4592. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4593. if (p_duplicate) {
  4594. undo_redo->create_action(TTR("Duplicate VisualShader Node(s)"));
  4595. } else {
  4596. bool copy_buffer_empty = true;
  4597. for (const CopyItem &item : copy_items_buffer) {
  4598. if (!item.disabled) {
  4599. copy_buffer_empty = false;
  4600. break;
  4601. }
  4602. }
  4603. if (copy_buffer_empty) {
  4604. return;
  4605. }
  4606. undo_redo->create_action(TTR("Paste VisualShader Node(s)"));
  4607. }
  4608. VisualShader::Type type = (VisualShader::Type)p_type;
  4609. int base_id = visual_shader->get_valid_node_id(type);
  4610. int id_from = base_id;
  4611. HashMap<int, int> connection_remap; // Used for connections and frame attachments.
  4612. HashSet<int> unsupported_set;
  4613. HashSet<int> added_set;
  4614. for (CopyItem &item : r_items) {
  4615. if (item.disabled) {
  4616. unsupported_set.insert(item.id);
  4617. continue;
  4618. }
  4619. connection_remap[item.id] = id_from;
  4620. Ref<VisualShaderNode> node = item.node->duplicate();
  4621. node->set_frame(-1); // Do not reattach nodes to frame (for now).
  4622. Ref<VisualShaderNodeResizableBase> resizable_base = Object::cast_to<VisualShaderNodeResizableBase>(node.ptr());
  4623. if (resizable_base.is_valid()) {
  4624. undo_redo->add_do_method(node.ptr(), "set_size", item.size);
  4625. }
  4626. Ref<VisualShaderNodeFrame> frame = Object::cast_to<VisualShaderNodeFrame>(node.ptr());
  4627. if (frame.is_valid()) {
  4628. // Do not reattach nodes to frame (for now).
  4629. undo_redo->add_do_method(node.ptr(), "set_attached_nodes", PackedInt32Array());
  4630. }
  4631. Ref<VisualShaderNodeGroupBase> group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
  4632. if (group.is_valid()) {
  4633. undo_redo->add_do_method(node.ptr(), "set_inputs", item.group_inputs);
  4634. undo_redo->add_do_method(node.ptr(), "set_outputs", item.group_outputs);
  4635. }
  4636. Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  4637. if (expression.is_valid()) {
  4638. undo_redo->add_do_method(node.ptr(), "set_expression", item.expression);
  4639. }
  4640. undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, node, item.position + p_offset, id_from);
  4641. undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_from, false, false);
  4642. added_set.insert(id_from);
  4643. id_from++;
  4644. }
  4645. // Attach nodes to frame.
  4646. for (const CopyItem &item : r_items) {
  4647. Ref<VisualShaderNode> node = item.node;
  4648. if (node->get_frame() == -1) {
  4649. continue;
  4650. }
  4651. int new_node_id = connection_remap[item.id];
  4652. int new_frame_id = node->get_frame();
  4653. undo_redo->add_do_method(visual_shader.ptr(), "attach_node_to_frame", type, new_node_id, new_frame_id);
  4654. undo_redo->add_do_method(graph_plugin.ptr(), "attach_node_to_frame", type, new_node_id, new_frame_id);
  4655. }
  4656. // Connect nodes.
  4657. for (const VisualShader::Connection &E : p_connections) {
  4658. if (unsupported_set.has(E.from_node) || unsupported_set.has(E.to_node)) {
  4659. continue;
  4660. }
  4661. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, connection_remap[E.from_node], E.from_port, connection_remap[E.to_node], E.to_port);
  4662. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, connection_remap[E.from_node], E.from_port, connection_remap[E.to_node], E.to_port);
  4663. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, connection_remap[E.from_node], E.from_port, connection_remap[E.to_node], E.to_port);
  4664. }
  4665. id_from = base_id;
  4666. for (const CopyItem &item : r_items) {
  4667. if (item.disabled) {
  4668. continue;
  4669. }
  4670. undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_from);
  4671. undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_from, false);
  4672. id_from++;
  4673. }
  4674. undo_redo->commit_action();
  4675. // Reselect nodes by excluding the other ones.
  4676. for (int i = 0; i < graph->get_child_count(); i++) {
  4677. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  4678. if (graph_element) {
  4679. int id = String(graph_element->get_name()).to_int();
  4680. if (added_set.has(id)) {
  4681. graph_element->set_selected(true);
  4682. } else {
  4683. graph_element->set_selected(false);
  4684. }
  4685. }
  4686. }
  4687. }
  4688. void VisualShaderEditor::_clear_copy_buffer() {
  4689. copy_items_buffer.clear();
  4690. copy_connections_buffer.clear();
  4691. }
  4692. void VisualShaderEditor::_duplicate_nodes() {
  4693. int type = get_current_shader_type();
  4694. List<CopyItem> items;
  4695. List<VisualShader::Connection> node_connections;
  4696. _dup_copy_nodes(type, items, node_connections);
  4697. if (items.is_empty()) {
  4698. return;
  4699. }
  4700. _dup_paste_nodes(type, items, node_connections, Vector2(10, 10) * EDSCALE, true);
  4701. }
  4702. void VisualShaderEditor::_copy_nodes(bool p_cut) {
  4703. _clear_copy_buffer();
  4704. _dup_copy_nodes(get_current_shader_type(), copy_items_buffer, copy_connections_buffer);
  4705. if (p_cut) {
  4706. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4707. undo_redo->create_action(TTR("Cut VisualShader Node(s)"));
  4708. List<int> ids;
  4709. for (const CopyItem &E : copy_items_buffer) {
  4710. ids.push_back(E.id);
  4711. }
  4712. _delete_nodes(get_current_shader_type(), ids);
  4713. undo_redo->commit_action();
  4714. }
  4715. }
  4716. void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2 &p_custom_position) {
  4717. if (copy_items_buffer.is_empty()) {
  4718. return;
  4719. }
  4720. int type = get_current_shader_type();
  4721. float scale = graph->get_zoom();
  4722. Vector2 mpos;
  4723. if (p_use_custom_position) {
  4724. mpos = p_custom_position;
  4725. } else {
  4726. mpos = graph->get_local_mouse_position();
  4727. }
  4728. _dup_paste_nodes(type, copy_items_buffer, copy_connections_buffer, graph->get_scroll_offset() / scale + mpos / scale - selection_center, false);
  4729. }
  4730. void VisualShaderEditor::_type_selected(int p_id) {
  4731. int offset = VisualShader::TYPE_VERTEX;
  4732. if (mode & MODE_FLAGS_PARTICLES) {
  4733. offset = VisualShader::TYPE_START;
  4734. if (p_id + offset > VisualShader::TYPE_PROCESS) {
  4735. custom_mode_box->set_visible(false);
  4736. custom_mode_enabled = false;
  4737. } else {
  4738. custom_mode_box->set_visible(true);
  4739. if (custom_mode_box->is_pressed()) {
  4740. custom_mode_enabled = true;
  4741. offset += 3;
  4742. }
  4743. }
  4744. } else if (mode & MODE_FLAGS_SKY) {
  4745. offset = VisualShader::TYPE_SKY;
  4746. } else if (mode & MODE_FLAGS_FOG) {
  4747. offset = VisualShader::TYPE_FOG;
  4748. }
  4749. set_current_shader_type(VisualShader::Type(p_id + offset));
  4750. _update_nodes();
  4751. _update_graph();
  4752. graph->grab_focus();
  4753. }
  4754. void VisualShaderEditor::_custom_mode_toggled(bool p_enabled) {
  4755. if (!(mode & MODE_FLAGS_PARTICLES)) {
  4756. return;
  4757. }
  4758. custom_mode_enabled = p_enabled;
  4759. int id = edit_type->get_selected() + 3;
  4760. if (p_enabled) {
  4761. set_current_shader_type(VisualShader::Type(id + 3));
  4762. } else {
  4763. set_current_shader_type(VisualShader::Type(id));
  4764. }
  4765. _update_options_menu();
  4766. _update_graph();
  4767. }
  4768. void VisualShaderEditor::_input_select_item(Ref<VisualShaderNodeInput> p_input, const String &p_name) {
  4769. String prev_name = p_input->get_input_name();
  4770. if (p_name == prev_name) {
  4771. return;
  4772. }
  4773. VisualShaderNode::PortType next_input_type = p_input->get_input_type_by_name(p_name);
  4774. VisualShaderNode::PortType prev_input_type = p_input->get_input_type_by_name(prev_name);
  4775. bool type_changed = next_input_type != prev_input_type;
  4776. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  4777. undo_redo_man->create_action(TTR("Visual Shader Input Type Changed"));
  4778. undo_redo_man->add_do_method(p_input.ptr(), "set_input_name", p_name);
  4779. undo_redo_man->add_undo_method(p_input.ptr(), "set_input_name", prev_name);
  4780. if (type_changed) {
  4781. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  4782. VisualShader::Type type = VisualShader::Type(type_id);
  4783. int id = visual_shader->find_node_id(type, p_input);
  4784. if (id != VisualShader::NODE_ID_INVALID) {
  4785. bool is_expanded = p_input->is_output_port_expandable(0) && p_input->_is_output_port_expanded(0);
  4786. int type_size = 0;
  4787. if (is_expanded) {
  4788. switch (next_input_type) {
  4789. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  4790. type_size = 2;
  4791. } break;
  4792. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  4793. type_size = 3;
  4794. } break;
  4795. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  4796. type_size = 4;
  4797. } break;
  4798. default:
  4799. break;
  4800. }
  4801. }
  4802. List<VisualShader::Connection> conns;
  4803. visual_shader->get_node_connections(type, &conns);
  4804. for (const VisualShader::Connection &E : conns) {
  4805. int cn_from_node = E.from_node;
  4806. int cn_from_port = E.from_port;
  4807. int cn_to_node = E.to_node;
  4808. int cn_to_port = E.to_port;
  4809. if (cn_from_node == id) {
  4810. bool is_incompatible_types = !visual_shader->is_port_types_compatible(p_input->get_input_type_by_name(p_name), visual_shader->get_node(type, cn_to_node)->get_input_port_type(cn_to_port));
  4811. if (is_incompatible_types || cn_from_port > type_size) {
  4812. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4813. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4814. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4815. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4816. }
  4817. }
  4818. }
  4819. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  4820. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  4821. }
  4822. }
  4823. }
  4824. undo_redo_man->commit_action();
  4825. }
  4826. void VisualShaderEditor::_parameter_ref_select_item(Ref<VisualShaderNodeParameterRef> p_parameter_ref, const String &p_name) {
  4827. String prev_name = p_parameter_ref->get_parameter_name();
  4828. if (p_name == prev_name) {
  4829. return;
  4830. }
  4831. bool type_changed = p_parameter_ref->get_parameter_type_by_name(p_name) != p_parameter_ref->get_parameter_type_by_name(prev_name);
  4832. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  4833. undo_redo_man->create_action(TTR("ParameterRef Name Changed"));
  4834. undo_redo_man->add_do_method(p_parameter_ref.ptr(), "set_parameter_name", p_name);
  4835. undo_redo_man->add_undo_method(p_parameter_ref.ptr(), "set_parameter_name", prev_name);
  4836. // update output port
  4837. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  4838. VisualShader::Type type = VisualShader::Type(type_id);
  4839. int id = visual_shader->find_node_id(type, p_parameter_ref);
  4840. if (id != VisualShader::NODE_ID_INVALID) {
  4841. if (type_changed) {
  4842. List<VisualShader::Connection> conns;
  4843. visual_shader->get_node_connections(type, &conns);
  4844. for (const VisualShader::Connection &E : conns) {
  4845. if (E.from_node == id) {
  4846. if (visual_shader->is_port_types_compatible(p_parameter_ref->get_parameter_type_by_name(p_name), visual_shader->get_node(type, E.to_node)->get_input_port_type(E.to_port))) {
  4847. continue;
  4848. }
  4849. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4850. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4851. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4852. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4853. }
  4854. }
  4855. }
  4856. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  4857. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  4858. break;
  4859. }
  4860. }
  4861. undo_redo_man->commit_action();
  4862. }
  4863. void VisualShaderEditor::_varying_select_item(Ref<VisualShaderNodeVarying> p_varying, const String &p_name) {
  4864. String prev_name = p_varying->get_varying_name();
  4865. if (p_name == prev_name) {
  4866. return;
  4867. }
  4868. bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid();
  4869. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  4870. undo_redo_man->create_action(TTR("Varying Name Changed"));
  4871. undo_redo_man->add_do_method(p_varying.ptr(), "set_varying_name", p_name);
  4872. undo_redo_man->add_undo_method(p_varying.ptr(), "set_varying_name", prev_name);
  4873. VisualShader::VaryingType vtype = p_varying->get_varying_type_by_name(p_name);
  4874. VisualShader::VaryingType prev_vtype = p_varying->get_varying_type_by_name(prev_name);
  4875. bool type_changed = vtype != prev_vtype;
  4876. if (type_changed) {
  4877. undo_redo_man->add_do_method(p_varying.ptr(), "set_varying_type", vtype);
  4878. undo_redo_man->add_undo_method(p_varying.ptr(), "set_varying_type", prev_vtype);
  4879. }
  4880. // update ports
  4881. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  4882. VisualShader::Type type = VisualShader::Type(type_id);
  4883. int id = visual_shader->find_node_id(type, p_varying);
  4884. if (id != VisualShader::NODE_ID_INVALID) {
  4885. if (type_changed) {
  4886. List<VisualShader::Connection> conns;
  4887. visual_shader->get_node_connections(type, &conns);
  4888. for (const VisualShader::Connection &E : conns) {
  4889. if (is_getter) {
  4890. if (E.from_node == id) {
  4891. if (visual_shader->is_port_types_compatible(p_varying->get_varying_type_by_name(p_name), visual_shader->get_node(type, E.to_node)->get_input_port_type(E.to_port))) {
  4892. continue;
  4893. }
  4894. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4895. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4896. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4897. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4898. }
  4899. } else {
  4900. if (E.to_node == id) {
  4901. if (visual_shader->is_port_types_compatible(p_varying->get_varying_type_by_name(p_name), visual_shader->get_node(type, E.from_node)->get_output_port_type(E.from_port))) {
  4902. continue;
  4903. }
  4904. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4905. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4906. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4907. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4908. }
  4909. }
  4910. }
  4911. }
  4912. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  4913. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  4914. break;
  4915. }
  4916. }
  4917. undo_redo_man->commit_action();
  4918. }
  4919. void VisualShaderEditor::_float_constant_selected(int p_which) {
  4920. ERR_FAIL_INDEX(p_which, MAX_FLOAT_CONST_DEFS);
  4921. VisualShader::Type type = get_current_shader_type();
  4922. Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, selected_float_constant);
  4923. ERR_FAIL_COND(node.is_null());
  4924. if (Math::is_equal_approx(node->get_constant(), float_constant_defs[p_which].value)) {
  4925. return; // same
  4926. }
  4927. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4928. undo_redo->create_action(vformat(TTR("Set Constant: %s"), float_constant_defs[p_which].name));
  4929. undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_which].value);
  4930. undo_redo->add_undo_method(node.ptr(), "set_constant", node->get_constant());
  4931. undo_redo->commit_action();
  4932. }
  4933. void VisualShaderEditor::_member_filter_changed(const String &p_text) {
  4934. _update_options_menu();
  4935. }
  4936. void VisualShaderEditor::_member_selected() {
  4937. TreeItem *item = members->get_selected();
  4938. if (item != nullptr && item->has_meta("id")) {
  4939. members_dialog->get_ok_button()->set_disabled(false);
  4940. highend_label->set_visible(add_options[item->get_meta("id")].highend);
  4941. node_desc->set_text(_get_description(item->get_meta("id")));
  4942. } else {
  4943. highend_label->set_visible(false);
  4944. members_dialog->get_ok_button()->set_disabled(true);
  4945. node_desc->set_text("");
  4946. }
  4947. }
  4948. void VisualShaderEditor::_member_create() {
  4949. TreeItem *item = members->get_selected();
  4950. if (item != nullptr && item->has_meta("id")) {
  4951. int idx = members->get_selected()->get_meta("id");
  4952. if (connection_node_insert_requested) {
  4953. from_node = String(clicked_connection->from_node).to_int();
  4954. from_slot = clicked_connection->from_port;
  4955. to_node = String(clicked_connection->to_node).to_int();
  4956. to_slot = clicked_connection->to_port;
  4957. connection_node_insert_requested = false;
  4958. saved_node_pos_dirty = true;
  4959. // Find both graph nodes and get their positions.
  4960. GraphNode *from_graph_element = Object::cast_to<GraphNode>(graph->get_node(itos(from_node)));
  4961. GraphNode *to_graph_element = Object::cast_to<GraphNode>(graph->get_node(itos(to_node)));
  4962. ERR_FAIL_NULL(from_graph_element);
  4963. ERR_FAIL_NULL(to_graph_element);
  4964. // Since the size of the node to add is not known yet, it's not possible to center it exactly.
  4965. float zoom = graph->get_zoom();
  4966. saved_node_pos = 0.5 * (from_graph_element->get_position() + zoom * from_graph_element->get_output_port_position(from_slot) + to_graph_element->get_position() + zoom * to_graph_element->get_input_port_position(to_slot));
  4967. }
  4968. _add_node(idx, add_options[idx].ops);
  4969. members_dialog->hide();
  4970. }
  4971. }
  4972. void VisualShaderEditor::_member_cancel() {
  4973. to_node = -1;
  4974. to_slot = -1;
  4975. from_node = -1;
  4976. from_slot = -1;
  4977. connection_node_insert_requested = false;
  4978. }
  4979. void VisualShaderEditor::_update_varying_tree() {
  4980. varyings->clear();
  4981. TreeItem *root = varyings->create_item();
  4982. int count = visual_shader->get_varyings_count();
  4983. for (int i = 0; i < count; i++) {
  4984. const VisualShader::Varying *varying = visual_shader->get_varying_by_index(i);
  4985. if (varying) {
  4986. TreeItem *item = varyings->create_item(root);
  4987. item->set_text(0, varying->name);
  4988. if (i == 0) {
  4989. item->select(0);
  4990. }
  4991. switch (varying->type) {
  4992. case VisualShader::VARYING_TYPE_FLOAT:
  4993. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)));
  4994. break;
  4995. case VisualShader::VARYING_TYPE_INT:
  4996. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)));
  4997. break;
  4998. case VisualShader::VARYING_TYPE_UINT:
  4999. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)));
  5000. break;
  5001. case VisualShader::VARYING_TYPE_VECTOR_2D:
  5002. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)));
  5003. break;
  5004. case VisualShader::VARYING_TYPE_VECTOR_3D:
  5005. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)));
  5006. break;
  5007. case VisualShader::VARYING_TYPE_VECTOR_4D:
  5008. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)));
  5009. break;
  5010. case VisualShader::VARYING_TYPE_BOOLEAN:
  5011. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)));
  5012. break;
  5013. case VisualShader::VARYING_TYPE_TRANSFORM:
  5014. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)));
  5015. break;
  5016. default:
  5017. break;
  5018. }
  5019. }
  5020. }
  5021. varying_button->get_popup()->set_item_disabled(int(VaryingMenuOptions::REMOVE), count == 0);
  5022. }
  5023. void VisualShaderEditor::_varying_create() {
  5024. _add_varying(varying_name->get_text(), (VisualShader::VaryingMode)varying_mode->get_selected(), (VisualShader::VaryingType)varying_type->get_selected());
  5025. add_varying_dialog->hide();
  5026. }
  5027. void VisualShaderEditor::_varying_validate() {
  5028. bool has_error = false;
  5029. String error;
  5030. String varname = varying_name->get_text();
  5031. if (!varname.is_valid_ascii_identifier()) {
  5032. error += TTR("Invalid name for varying.");
  5033. has_error = true;
  5034. } else if (visual_shader->has_varying(varname)) {
  5035. error += TTR("Varying with that name already exists.");
  5036. has_error = true;
  5037. }
  5038. if (varying_type->get_selected() == 6 && varying_mode->get_selected() == VisualShader::VaryingMode::VARYING_MODE_VERTEX_TO_FRAG_LIGHT) {
  5039. if (has_error) {
  5040. error += "\n";
  5041. }
  5042. error += vformat(TTR("Boolean type cannot be used with `%s` varying mode."), "Vertex -> [Fragment, Light]");
  5043. has_error = true;
  5044. }
  5045. if (has_error) {
  5046. varying_error_label->show();
  5047. varying_error_label->set_text(error);
  5048. add_varying_dialog->get_ok_button()->set_disabled(true);
  5049. } else {
  5050. varying_error_label->hide();
  5051. varying_error_label->set_text("");
  5052. add_varying_dialog->get_ok_button()->set_disabled(false);
  5053. }
  5054. add_varying_dialog->reset_size();
  5055. }
  5056. void VisualShaderEditor::_varying_type_changed(int p_index) {
  5057. _varying_validate();
  5058. }
  5059. void VisualShaderEditor::_varying_mode_changed(int p_index) {
  5060. _varying_validate();
  5061. }
  5062. void VisualShaderEditor::_varying_name_changed(const String &p_name) {
  5063. _varying_validate();
  5064. }
  5065. void VisualShaderEditor::_varying_deleted() {
  5066. TreeItem *item = varyings->get_selected();
  5067. if (item != nullptr) {
  5068. _remove_varying(item->get_text(0));
  5069. remove_varying_dialog->hide();
  5070. }
  5071. }
  5072. void VisualShaderEditor::_varying_selected() {
  5073. add_varying_dialog->get_ok_button()->set_disabled(false);
  5074. }
  5075. void VisualShaderEditor::_varying_unselected() {
  5076. add_varying_dialog->get_ok_button()->set_disabled(true);
  5077. }
  5078. void VisualShaderEditor::_tools_menu_option(int p_idx) {
  5079. TreeItem *category = members->get_root()->get_first_child();
  5080. switch (p_idx) {
  5081. case EXPAND_ALL:
  5082. while (category) {
  5083. category->set_collapsed(false);
  5084. TreeItem *sub_category = category->get_first_child();
  5085. while (sub_category) {
  5086. sub_category->set_collapsed(false);
  5087. sub_category = sub_category->get_next();
  5088. }
  5089. category = category->get_next();
  5090. }
  5091. break;
  5092. case COLLAPSE_ALL:
  5093. while (category) {
  5094. category->set_collapsed(true);
  5095. TreeItem *sub_category = category->get_first_child();
  5096. while (sub_category) {
  5097. sub_category->set_collapsed(true);
  5098. sub_category = sub_category->get_next();
  5099. }
  5100. category = category->get_next();
  5101. }
  5102. break;
  5103. default:
  5104. break;
  5105. }
  5106. }
  5107. void VisualShaderEditor::_node_menu_id_pressed(int p_idx) {
  5108. switch (p_idx) {
  5109. case NodeMenuOptions::ADD:
  5110. _show_members_dialog(true);
  5111. break;
  5112. case NodeMenuOptions::CUT:
  5113. _copy_nodes(true);
  5114. break;
  5115. case NodeMenuOptions::COPY:
  5116. _copy_nodes(false);
  5117. break;
  5118. case NodeMenuOptions::PASTE:
  5119. _paste_nodes(true, menu_point);
  5120. break;
  5121. case NodeMenuOptions::DELETE_:
  5122. _delete_nodes_request(TypedArray<StringName>());
  5123. break;
  5124. case NodeMenuOptions::DUPLICATE:
  5125. _duplicate_nodes();
  5126. break;
  5127. case NodeMenuOptions::CLEAR_COPY_BUFFER:
  5128. _clear_copy_buffer();
  5129. break;
  5130. case NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS:
  5131. _convert_constants_to_parameters(false);
  5132. break;
  5133. case NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS:
  5134. _convert_constants_to_parameters(true);
  5135. break;
  5136. case NodeMenuOptions::UNLINK_FROM_PARENT_FRAME:
  5137. _detach_nodes_from_frame_request();
  5138. break;
  5139. case NodeMenuOptions::SET_FRAME_TITLE:
  5140. _frame_title_popup_show(get_screen_position() + get_local_mouse_position(), selected_frame);
  5141. break;
  5142. case NodeMenuOptions::ENABLE_FRAME_COLOR:
  5143. _frame_color_enabled_changed(selected_frame);
  5144. break;
  5145. case NodeMenuOptions::SET_FRAME_COLOR:
  5146. _frame_color_popup_show(get_screen_position() + get_local_mouse_position(), selected_frame);
  5147. break;
  5148. case NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK:
  5149. _frame_autoshrink_enabled_changed(selected_frame);
  5150. break;
  5151. default:
  5152. break;
  5153. }
  5154. }
  5155. void VisualShaderEditor::_connection_menu_id_pressed(int p_idx) {
  5156. switch (p_idx) {
  5157. case ConnectionMenuOptions::DISCONNECT: {
  5158. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  5159. undo_redo->create_action(TTR("Disconnect"));
  5160. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", get_current_shader_type(), String(clicked_connection->from_node).to_int(), clicked_connection->from_port, String(clicked_connection->to_node).to_int(), clicked_connection->to_port);
  5161. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", get_current_shader_type(), String(clicked_connection->from_node).to_int(), clicked_connection->from_port, String(clicked_connection->to_node).to_int(), clicked_connection->to_port);
  5162. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", get_current_shader_type(), String(clicked_connection->from_node).to_int(), clicked_connection->from_port, String(clicked_connection->to_node).to_int(), clicked_connection->to_port);
  5163. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", get_current_shader_type(), String(clicked_connection->from_node).to_int(), clicked_connection->from_port, String(clicked_connection->to_node).to_int(), clicked_connection->to_port);
  5164. undo_redo->commit_action();
  5165. } break;
  5166. case ConnectionMenuOptions::INSERT_NEW_NODE: {
  5167. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  5168. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  5169. Ref<VisualShaderNode> node1 = visual_shader->get_node(get_current_shader_type(), String(clicked_connection->from_node).to_int());
  5170. if (node1.is_valid()) {
  5171. output_port_type = node1->get_output_port_type(from_slot);
  5172. }
  5173. Ref<VisualShaderNode> node2 = visual_shader->get_node(get_current_shader_type(), String(clicked_connection->to_node).to_int());
  5174. if (node2.is_valid()) {
  5175. input_port_type = node2->get_input_port_type(to_slot);
  5176. }
  5177. connection_node_insert_requested = true;
  5178. _show_members_dialog(true, input_port_type, output_port_type);
  5179. } break;
  5180. case ConnectionMenuOptions::INSERT_NEW_REROUTE: {
  5181. from_node = String(clicked_connection->from_node).to_int();
  5182. from_slot = clicked_connection->from_port;
  5183. to_node = String(clicked_connection->to_node).to_int();
  5184. to_slot = clicked_connection->to_port;
  5185. // Manual offset to place the port exactly at the mouse position.
  5186. saved_node_pos -= Vector2(11 * EDSCALE * graph->get_zoom(), 50 * EDSCALE * graph->get_zoom());
  5187. // Find reroute addoptions.
  5188. int idx = -1;
  5189. for (int i = 0; i < add_options.size(); i++) {
  5190. if (add_options[i].name == "Reroute") {
  5191. idx = i;
  5192. break;
  5193. }
  5194. }
  5195. _add_node(idx, add_options[idx].ops);
  5196. } break;
  5197. default:
  5198. break;
  5199. }
  5200. }
  5201. Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  5202. if (p_point == Vector2(Math::INF, Math::INF)) {
  5203. return Variant();
  5204. }
  5205. if (p_from == members) {
  5206. TreeItem *it = members->get_item_at_position(p_point);
  5207. if (!it) {
  5208. return Variant();
  5209. }
  5210. if (!it->has_meta("id")) {
  5211. return Variant();
  5212. }
  5213. int id = it->get_meta("id");
  5214. AddOption op = add_options[id];
  5215. Dictionary d;
  5216. d["id"] = id;
  5217. Label *label = memnew(Label);
  5218. label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  5219. label->set_text(it->get_text(0));
  5220. label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  5221. set_drag_preview(label);
  5222. return d;
  5223. }
  5224. return Variant();
  5225. }
  5226. bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  5227. if (p_point == Vector2(Math::INF, Math::INF)) {
  5228. return false;
  5229. }
  5230. if (p_from == graph) {
  5231. Dictionary d = p_data;
  5232. if (d.has("id")) {
  5233. return true;
  5234. }
  5235. if (d.has("files")) {
  5236. return true;
  5237. }
  5238. }
  5239. return false;
  5240. }
  5241. void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  5242. if (p_point == Vector2(Math::INF, Math::INF)) {
  5243. return;
  5244. }
  5245. if (p_from == graph) {
  5246. Dictionary d = p_data;
  5247. if (d.has("id")) {
  5248. int idx = d["id"];
  5249. saved_node_pos = p_point;
  5250. saved_node_pos_dirty = true;
  5251. _add_node(idx, add_options[idx].ops);
  5252. } else if (d.has("files")) {
  5253. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  5254. undo_redo->create_action(TTR("Add Node(s) to Visual Shader"));
  5255. if (d["files"].get_type() == Variant::PACKED_STRING_ARRAY) {
  5256. PackedStringArray arr = d["files"];
  5257. for (int i = 0; i < arr.size(); i++) {
  5258. String type = ResourceLoader::get_resource_type(arr[i]);
  5259. if (type == "GDScript") {
  5260. Ref<Script> scr = ResourceLoader::load(arr[i]);
  5261. if (scr->get_instance_base_type() == "VisualShaderNodeCustom") {
  5262. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5263. saved_node_pos_dirty = true;
  5264. int idx = -1;
  5265. for (int j = custom_node_option_idx; j < add_options.size(); j++) {
  5266. if (add_options[j].script.is_valid()) {
  5267. if (add_options[j].script->get_path() == arr[i]) {
  5268. idx = j;
  5269. break;
  5270. }
  5271. }
  5272. }
  5273. if (idx != -1) {
  5274. _add_node(idx, {}, arr[i], i);
  5275. }
  5276. }
  5277. } else if (type == "CurveTexture") {
  5278. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5279. saved_node_pos_dirty = true;
  5280. _add_node(curve_node_option_idx, {}, arr[i], i);
  5281. } else if (type == "CurveXYZTexture") {
  5282. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5283. saved_node_pos_dirty = true;
  5284. _add_node(curve_xyz_node_option_idx, {}, arr[i], i);
  5285. } else if (ClassDB::get_parent_class(type) == "Texture2D") {
  5286. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5287. saved_node_pos_dirty = true;
  5288. _add_node(texture2d_node_option_idx, {}, arr[i], i);
  5289. } else if (type == "Texture2DArray") {
  5290. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5291. saved_node_pos_dirty = true;
  5292. _add_node(texture2d_array_node_option_idx, {}, arr[i], i);
  5293. } else if (ClassDB::get_parent_class(type) == "Texture3D") {
  5294. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5295. saved_node_pos_dirty = true;
  5296. _add_node(texture3d_node_option_idx, {}, arr[i], i);
  5297. } else if (type == "Cubemap") {
  5298. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5299. saved_node_pos_dirty = true;
  5300. _add_node(cubemap_node_option_idx, {}, arr[i], i);
  5301. } else if (type == "Mesh" && visual_shader->get_mode() == Shader::MODE_PARTICLES &&
  5302. (get_current_shader_type() == VisualShader::TYPE_START || get_current_shader_type() == VisualShader::TYPE_START_CUSTOM)) {
  5303. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5304. saved_node_pos_dirty = true;
  5305. _add_node(mesh_emitter_option_idx, {}, arr[i], i);
  5306. }
  5307. }
  5308. }
  5309. undo_redo->commit_action();
  5310. }
  5311. }
  5312. }
  5313. void VisualShaderEditor::_show_preview_text() {
  5314. code_preview_showed = !code_preview_showed;
  5315. if (code_preview_showed) {
  5316. if (code_preview_first) {
  5317. code_preview_window->set_size(Size2(400 * EDSCALE, 600 * EDSCALE));
  5318. code_preview_window->popup_centered();
  5319. code_preview_first = false;
  5320. } else {
  5321. code_preview_window->popup();
  5322. }
  5323. if (pending_update_preview) {
  5324. _update_preview();
  5325. pending_update_preview = false;
  5326. }
  5327. } else {
  5328. code_preview_window->hide();
  5329. }
  5330. }
  5331. void VisualShaderEditor::_preview_close_requested() {
  5332. code_preview_showed = false;
  5333. code_preview_button->set_pressed(false);
  5334. }
  5335. static ShaderLanguage::DataType _visual_shader_editor_get_global_shader_uniform_type(const StringName &p_variable) {
  5336. RS::GlobalShaderParameterType gvt = RS::get_singleton()->global_shader_parameter_get_type(p_variable);
  5337. return (ShaderLanguage::DataType)RS::global_shader_uniform_type_get_shader_datatype(gvt);
  5338. }
  5339. void VisualShaderEditor::_update_preview() {
  5340. if (!code_preview_showed) {
  5341. pending_update_preview = true;
  5342. return;
  5343. }
  5344. String code = visual_shader->get_code();
  5345. preview_text->set_text(code);
  5346. ShaderLanguage::ShaderCompileInfo info;
  5347. info.functions = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(visual_shader->get_mode()));
  5348. info.render_modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(visual_shader->get_mode()));
  5349. info.stencil_modes = ShaderTypes::get_singleton()->get_stencil_modes(RenderingServer::ShaderMode(visual_shader->get_mode()));
  5350. info.shader_types = ShaderTypes::get_singleton()->get_types();
  5351. info.global_shader_uniform_type_func = _visual_shader_editor_get_global_shader_uniform_type;
  5352. for (int i = 0; i < preview_text->get_line_count(); i++) {
  5353. preview_text->set_line_background_color(i, Color(0, 0, 0, 0));
  5354. }
  5355. String preprocessed_code;
  5356. {
  5357. String path = visual_shader->get_path();
  5358. String error_pp;
  5359. List<ShaderPreprocessor::FilePosition> err_positions;
  5360. ShaderPreprocessor preprocessor;
  5361. Error err = preprocessor.preprocess(code, path, preprocessed_code, &error_pp, &err_positions);
  5362. if (err != OK) {
  5363. ERR_FAIL_COND(err_positions.is_empty());
  5364. String file = err_positions.front()->get().file;
  5365. int err_line = err_positions.front()->get().line;
  5366. Color error_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color");
  5367. preview_text->set_line_background_color(err_line - 1, error_line_color);
  5368. error_panel->show();
  5369. error_label->set_text("error(" + file + ":" + itos(err_line) + "): " + error_pp);
  5370. shader_error = true;
  5371. return;
  5372. }
  5373. }
  5374. ShaderLanguage sl;
  5375. Error err = sl.compile(preprocessed_code, info);
  5376. if (err != OK) {
  5377. int err_line;
  5378. String err_text;
  5379. Vector<ShaderLanguage::FilePosition> include_positions = sl.get_include_positions();
  5380. if (include_positions.size() > 1) {
  5381. // Error is in an include.
  5382. err_line = include_positions[0].line;
  5383. err_text = "error(" + itos(err_line) + ") in include " + include_positions[include_positions.size() - 1].file + ":" + itos(include_positions[include_positions.size() - 1].line) + ": " + sl.get_error_text();
  5384. } else {
  5385. err_line = sl.get_error_line();
  5386. err_text = "error(" + itos(err_line) + "): " + sl.get_error_text();
  5387. }
  5388. Color error_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color");
  5389. preview_text->set_line_background_color(err_line - 1, error_line_color);
  5390. error_panel->show();
  5391. error_label->set_text(err_text);
  5392. shader_error = true;
  5393. } else {
  5394. error_panel->hide();
  5395. shader_error = false;
  5396. }
  5397. }
  5398. void VisualShaderEditor::_update_next_previews(int p_node_id) {
  5399. VisualShader::Type type = get_current_shader_type();
  5400. LocalVector<int> nodes;
  5401. _get_next_nodes_recursively(type, p_node_id, nodes);
  5402. for (int node_id : nodes) {
  5403. if (graph_plugin->is_preview_visible(node_id)) {
  5404. graph_plugin->update_node_deferred(type, node_id);
  5405. }
  5406. }
  5407. }
  5408. void VisualShaderEditor::_get_next_nodes_recursively(VisualShader::Type p_type, int p_node_id, LocalVector<int> &r_nodes) const {
  5409. const LocalVector<int> &next_connections = visual_shader->get_next_connected_nodes(p_type, p_node_id);
  5410. for (int node_id : next_connections) {
  5411. r_nodes.push_back(node_id);
  5412. _get_next_nodes_recursively(p_type, node_id, r_nodes);
  5413. }
  5414. }
  5415. void VisualShaderEditor::_visibility_changed() {
  5416. if (!is_visible()) {
  5417. if (code_preview_window->is_visible()) {
  5418. code_preview_button->set_pressed(false);
  5419. code_preview_window->hide();
  5420. code_preview_showed = false;
  5421. }
  5422. }
  5423. }
  5424. void VisualShaderEditor::_show_shader_preview() {
  5425. shader_preview_showed = !shader_preview_showed;
  5426. if (shader_preview_showed) {
  5427. shader_preview_vbox->show();
  5428. } else {
  5429. shader_preview_vbox->hide();
  5430. _param_unselected();
  5431. }
  5432. }
  5433. void VisualShaderEditor::set_toggle_list_control(Control *p_control) {
  5434. toggle_files_list = p_control;
  5435. }
  5436. void VisualShaderEditor::_toggle_files_pressed() {
  5437. ERR_FAIL_NULL(toggle_files_list);
  5438. toggle_files_list->set_visible(!toggle_files_list->is_visible());
  5439. update_toggle_files_button();
  5440. }
  5441. void VisualShaderEditor::_bind_methods() {
  5442. ClassDB::bind_method("_update_nodes", &VisualShaderEditor::_update_nodes);
  5443. ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph);
  5444. ClassDB::bind_method("_input_select_item", &VisualShaderEditor::_input_select_item);
  5445. ClassDB::bind_method("_parameter_ref_select_item", &VisualShaderEditor::_parameter_ref_select_item);
  5446. ClassDB::bind_method("_varying_select_item", &VisualShaderEditor::_varying_select_item);
  5447. ClassDB::bind_method("_set_node_size", &VisualShaderEditor::_set_node_size);
  5448. ClassDB::bind_method("_update_parameters", &VisualShaderEditor::_update_parameters);
  5449. ClassDB::bind_method("_update_varyings", &VisualShaderEditor::_update_varyings);
  5450. ClassDB::bind_method("_update_varying_tree", &VisualShaderEditor::_update_varying_tree);
  5451. ClassDB::bind_method("_set_mode", &VisualShaderEditor::_set_mode);
  5452. ClassDB::bind_method("_update_constant", &VisualShaderEditor::_update_constant);
  5453. ClassDB::bind_method("_update_parameter", &VisualShaderEditor::_update_parameter);
  5454. ClassDB::bind_method("_update_next_previews", &VisualShaderEditor::_update_next_previews);
  5455. ClassDB::bind_method("_update_current_param", &VisualShaderEditor::_update_current_param);
  5456. }
  5457. VisualShaderEditor::VisualShaderEditor() {
  5458. vs_editor_cache.instantiate();
  5459. vs_editor_cache->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join("vs_editor_cache.cfg"));
  5460. ShaderLanguage::get_keyword_list(&keyword_list);
  5461. EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &VisualShaderEditor::_resource_saved));
  5462. FileSystemDock::get_singleton()->get_script_create_dialog()->connect("script_created", callable_mp(this, &VisualShaderEditor::_script_created));
  5463. FileSystemDock::get_singleton()->connect("resource_removed", callable_mp(this, &VisualShaderEditor::_resource_removed));
  5464. HSplitContainer *main_box = memnew(HSplitContainer);
  5465. main_box->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  5466. add_child(main_box);
  5467. graph = memnew(GraphEdit);
  5468. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  5469. graph->set_h_size_flags(SIZE_EXPAND_FILL);
  5470. graph->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
  5471. graph->set_grid_pattern(GraphEdit::GridPattern::GRID_PATTERN_DOTS);
  5472. int grid_pattern = EDITOR_GET("editors/visual_editors/grid_pattern");
  5473. graph->set_grid_pattern((GraphEdit::GridPattern)grid_pattern);
  5474. graph->set_show_zoom_label(true);
  5475. main_box->add_child(graph);
  5476. SET_DRAG_FORWARDING_GCD(graph, VisualShaderEditor);
  5477. float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity");
  5478. graph->set_minimap_opacity(graph_minimap_opacity);
  5479. float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature");
  5480. graph->set_connection_lines_curvature(graph_lines_curvature);
  5481. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR);
  5482. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5483. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5484. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN);
  5485. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5486. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5487. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5488. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_TRANSFORM);
  5489. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SAMPLER);
  5490. //graph->add_valid_left_disconnect_type(0);
  5491. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  5492. graph->connect("connection_request", callable_mp(this, &VisualShaderEditor::_connection_request), CONNECT_DEFERRED);
  5493. graph->connect("disconnection_request", callable_mp(this, &VisualShaderEditor::_disconnection_request), CONNECT_DEFERRED);
  5494. graph->connect("node_selected", callable_mp(this, &VisualShaderEditor::_node_selected));
  5495. graph->connect("scroll_offset_changed", callable_mp(this, &VisualShaderEditor::_scroll_offset_changed));
  5496. graph->connect("duplicate_nodes_request", callable_mp(this, &VisualShaderEditor::_duplicate_nodes));
  5497. graph->connect("copy_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes).bind(false));
  5498. graph->connect("cut_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes).bind(true));
  5499. graph->connect("paste_nodes_request", callable_mp(this, &VisualShaderEditor::_paste_nodes).bind(false, Point2()));
  5500. graph->connect("delete_nodes_request", callable_mp(this, &VisualShaderEditor::_delete_nodes_request));
  5501. graph->connect(SceneStringName(gui_input), callable_mp(this, &VisualShaderEditor::_graph_gui_input));
  5502. graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty));
  5503. graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty));
  5504. graph->connect("connection_drag_ended", callable_mp(this, &VisualShaderEditor::_connection_drag_ended));
  5505. graph->connect(SceneStringName(visibility_changed), callable_mp(this, &VisualShaderEditor::_visibility_changed));
  5506. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR);
  5507. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5508. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5509. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5510. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5511. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5512. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5513. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR);
  5514. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5515. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5516. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5517. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5518. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5519. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5520. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR);
  5521. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5522. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5523. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5524. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5525. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5526. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5527. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR);
  5528. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5529. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5530. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5531. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5532. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5533. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5534. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR);
  5535. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5536. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5537. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5538. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5539. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5540. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5541. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR);
  5542. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5543. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5544. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5545. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5546. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5547. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5548. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR);
  5549. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5550. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5551. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5552. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5553. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5554. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5555. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShaderNode::PORT_TYPE_TRANSFORM);
  5556. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SAMPLER, VisualShaderNode::PORT_TYPE_SAMPLER);
  5557. info_label = memnew(Label);
  5558. info_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  5559. info_label->set_text(vformat(TTR("Hold %s Key To Swap Connections"), keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL)));
  5560. info_label->set_anchors_and_offsets_preset(Control::PRESET_BOTTOM_WIDE, PRESET_MODE_MINSIZE, 20);
  5561. info_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  5562. info_label->hide();
  5563. graph->get_top_layer()->add_child(info_label);
  5564. PanelContainer *toolbar_panel = static_cast<PanelContainer *>(graph->get_menu_hbox()->get_parent());
  5565. toolbar_panel->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE, PRESET_MODE_MINSIZE, 10);
  5566. toolbar_panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
  5567. toolbar_hflow = memnew(HFlowContainer);
  5568. {
  5569. LocalVector<Node *> nodes;
  5570. for (int i = 0; i < graph->get_menu_hbox()->get_child_count(); i++) {
  5571. Node *child = graph->get_menu_hbox()->get_child(i);
  5572. nodes.push_back(child);
  5573. }
  5574. for (Node *node : nodes) {
  5575. graph->get_menu_hbox()->remove_child(node);
  5576. toolbar_hflow->add_child(node);
  5577. }
  5578. graph->get_menu_hbox()->hide();
  5579. toolbar_panel->add_child(toolbar_hflow);
  5580. }
  5581. VSeparator *vs = memnew(VSeparator);
  5582. toolbar_hflow->add_child(vs);
  5583. toolbar_hflow->move_child(vs, 0);
  5584. custom_mode_box = memnew(CheckBox);
  5585. custom_mode_box->set_text(TTR("Custom"));
  5586. custom_mode_box->set_pressed(false);
  5587. custom_mode_box->set_visible(false);
  5588. custom_mode_box->connect(SceneStringName(toggled), callable_mp(this, &VisualShaderEditor::_custom_mode_toggled));
  5589. edit_type_standard = memnew(OptionButton);
  5590. edit_type_standard->add_item(TTR("Vertex"));
  5591. edit_type_standard->add_item(TTR("Fragment"));
  5592. edit_type_standard->add_item(TTR("Light"));
  5593. edit_type_standard->select(1);
  5594. edit_type_standard->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected));
  5595. edit_type_particles = memnew(OptionButton);
  5596. edit_type_particles->add_item(TTR("Start"));
  5597. edit_type_particles->add_item(TTR("Process"));
  5598. edit_type_particles->add_item(TTR("Collide"));
  5599. edit_type_particles->select(0);
  5600. edit_type_particles->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected));
  5601. edit_type_sky = memnew(OptionButton);
  5602. edit_type_sky->add_item(TTR("Sky"));
  5603. edit_type_sky->select(0);
  5604. edit_type_sky->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected));
  5605. edit_type_fog = memnew(OptionButton);
  5606. edit_type_fog->add_item(TTR("Fog"));
  5607. edit_type_fog->select(0);
  5608. edit_type_fog->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected));
  5609. edit_type = edit_type_standard;
  5610. toolbar_hflow->add_child(custom_mode_box);
  5611. toolbar_hflow->move_child(custom_mode_box, 0);
  5612. toolbar_hflow->add_child(edit_type_standard);
  5613. toolbar_hflow->move_child(edit_type_standard, 0);
  5614. toolbar_hflow->add_child(edit_type_particles);
  5615. toolbar_hflow->move_child(edit_type_particles, 0);
  5616. toolbar_hflow->add_child(edit_type_sky);
  5617. toolbar_hflow->move_child(edit_type_sky, 0);
  5618. toolbar_hflow->add_child(edit_type_fog);
  5619. toolbar_hflow->move_child(edit_type_fog, 0);
  5620. add_node = memnew(Button);
  5621. add_node->set_theme_type_variation(SceneStringName(FlatButton));
  5622. add_node->set_text(TTR("Add Node..."));
  5623. toolbar_hflow->add_child(add_node);
  5624. toolbar_hflow->move_child(add_node, 0);
  5625. add_node->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_members_dialog).bind(false, VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PORT_TYPE_MAX));
  5626. graph->connect("graph_elements_linked_to_frame_request", callable_mp(this, &VisualShaderEditor::_nodes_linked_to_frame_request));
  5627. graph->connect("frame_rect_changed", callable_mp(this, &VisualShaderEditor::_frame_rect_changed));
  5628. varying_button = memnew(MenuButton);
  5629. varying_button->set_flat(false);
  5630. varying_button->set_theme_type_variation("FlatMenuButton");
  5631. varying_button->set_text(TTR("Manage Varyings"));
  5632. varying_button->set_switch_on_hover(true);
  5633. toolbar_hflow->add_child(varying_button);
  5634. PopupMenu *varying_menu = varying_button->get_popup();
  5635. varying_menu->add_item(TTR("Add Varying"), int(VaryingMenuOptions::ADD));
  5636. varying_menu->add_item(TTR("Remove Varying"), int(VaryingMenuOptions::REMOVE));
  5637. varying_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_varying_menu_id_pressed));
  5638. code_preview_button = memnew(Button);
  5639. code_preview_button->set_theme_type_variation(SceneStringName(FlatButton));
  5640. code_preview_button->set_toggle_mode(true);
  5641. code_preview_button->set_tooltip_text(TTR("Show generated shader code."));
  5642. toolbar_hflow->add_child(code_preview_button);
  5643. code_preview_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_preview_text));
  5644. shader_preview_button = memnew(Button);
  5645. shader_preview_button->set_theme_type_variation(SceneStringName(FlatButton));
  5646. shader_preview_button->set_toggle_mode(true);
  5647. shader_preview_button->set_tooltip_text(TTR("Toggle shader preview."));
  5648. shader_preview_button->set_pressed(true);
  5649. toolbar_hflow->add_child(shader_preview_button);
  5650. shader_preview_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_shader_preview));
  5651. Control *spacer = memnew(Control);
  5652. spacer->set_h_size_flags(Control::SIZE_EXPAND);
  5653. toolbar_hflow->add_child(spacer);
  5654. site_search = memnew(Button);
  5655. site_search->set_theme_type_variation(SceneStringName(FlatButton));
  5656. site_search->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_help_open));
  5657. site_search->set_text(TTR("Online Docs"));
  5658. site_search->set_tooltip_text(TTR("Open Godot online documentation."));
  5659. toolbar_hflow->add_child(site_search);
  5660. toolbar_hflow->add_child(memnew(VSeparator));
  5661. VSeparator *separator = memnew(VSeparator);
  5662. toolbar_hflow->add_child(separator);
  5663. toolbar_hflow->move_child(separator, 0);
  5664. separator = memnew(VSeparator);
  5665. toolbar_hflow->add_child(separator);
  5666. toolbar_hflow->move_child(separator, 0);
  5667. toggle_files_button = memnew(Button);
  5668. toggle_files_button->set_theme_type_variation(SceneStringName(FlatButton));
  5669. toggle_files_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_toggle_files_pressed));
  5670. toolbar_hflow->add_child(toggle_files_button);
  5671. toolbar_hflow->move_child(toggle_files_button, 0);
  5672. ///////////////////////////////////////
  5673. // CODE PREVIEW
  5674. ///////////////////////////////////////
  5675. code_preview_window = memnew(AcceptDialog);
  5676. code_preview_window->set_title(TTR("Generated Shader Code"));
  5677. code_preview_window->set_visible(code_preview_showed);
  5678. code_preview_window->set_ok_button_text(TTR("Close"));
  5679. code_preview_window->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_preview_close_requested));
  5680. code_preview_window->connect("canceled", callable_mp(this, &VisualShaderEditor::_preview_close_requested));
  5681. add_child(code_preview_window);
  5682. code_preview_vbox = memnew(VBoxContainer);
  5683. code_preview_window->add_child(code_preview_vbox);
  5684. code_preview_vbox->add_theme_constant_override("separation", 0);
  5685. preview_text = memnew(CodeEdit);
  5686. syntax_highlighter.instantiate();
  5687. code_preview_vbox->add_child(preview_text);
  5688. preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  5689. preview_text->set_syntax_highlighter(syntax_highlighter);
  5690. preview_text->set_draw_line_numbers(true);
  5691. preview_text->set_editable(false);
  5692. error_panel = memnew(PanelContainer);
  5693. code_preview_vbox->add_child(error_panel);
  5694. error_panel->set_visible(false);
  5695. error_label = memnew(Label);
  5696. error_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  5697. error_panel->add_child(error_label);
  5698. error_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  5699. ///////////////////////////////////////
  5700. // POPUP MENU
  5701. ///////////////////////////////////////
  5702. popup_menu = memnew(PopupMenu);
  5703. add_child(popup_menu);
  5704. popup_menu->set_hide_on_checkable_item_selection(false);
  5705. popup_menu->add_item(TTR("Add Node"), NodeMenuOptions::ADD);
  5706. popup_menu->add_separator();
  5707. popup_menu->add_item(TTR("Cut"), NodeMenuOptions::CUT);
  5708. popup_menu->add_item(TTR("Copy"), NodeMenuOptions::COPY);
  5709. popup_menu->add_item(TTR("Paste"), NodeMenuOptions::PASTE);
  5710. popup_menu->add_item(TTR("Delete"), NodeMenuOptions::DELETE_);
  5711. popup_menu->add_item(TTR("Duplicate"), NodeMenuOptions::DUPLICATE);
  5712. popup_menu->add_item(TTR("Clear Copy Buffer"), NodeMenuOptions::CLEAR_COPY_BUFFER);
  5713. popup_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_node_menu_id_pressed));
  5714. connection_popup_menu = memnew(PopupMenu);
  5715. add_child(connection_popup_menu);
  5716. connection_popup_menu->add_item(TTR("Disconnect"), ConnectionMenuOptions::DISCONNECT);
  5717. connection_popup_menu->add_item(TTR("Insert New Node"), ConnectionMenuOptions::INSERT_NEW_NODE);
  5718. connection_popup_menu->add_item(TTR("Insert New Reroute"), ConnectionMenuOptions::INSERT_NEW_REROUTE);
  5719. connection_popup_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_connection_menu_id_pressed));
  5720. ///////////////////////////////////////
  5721. // SHADER PREVIEW
  5722. ///////////////////////////////////////
  5723. shader_preview_vbox = memnew(VBoxContainer);
  5724. shader_preview_vbox->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
  5725. main_box->add_child(shader_preview_vbox);
  5726. VSplitContainer *preview_split = memnew(VSplitContainer);
  5727. preview_split->set_v_size_flags(SIZE_EXPAND_FILL);
  5728. shader_preview_vbox->add_child(preview_split);
  5729. // Initialize material editor.
  5730. {
  5731. env.instantiate();
  5732. Ref<Sky> sky = memnew(Sky());
  5733. env->set_sky(sky);
  5734. env->set_background(Environment::BG_COLOR);
  5735. env->set_ambient_source(Environment::AMBIENT_SOURCE_SKY);
  5736. env->set_reflection_source(Environment::REFLECTION_SOURCE_SKY);
  5737. preview_material.instantiate();
  5738. preview_material->connect(CoreStringName(property_list_changed), callable_mp(this, &VisualShaderEditor::_update_preview_parameter_list));
  5739. material_editor = memnew(MaterialEditor);
  5740. preview_split->add_child(material_editor);
  5741. }
  5742. VBoxContainer *params_vbox = memnew(VBoxContainer);
  5743. preview_split->add_child(params_vbox);
  5744. HBoxContainer *filter_hbox = memnew(HBoxContainer);
  5745. params_vbox->add_child(filter_hbox);
  5746. param_filter = memnew(LineEdit);
  5747. filter_hbox->add_child(param_filter);
  5748. param_filter->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_param_filter_changed));
  5749. param_filter->set_h_size_flags(SIZE_EXPAND_FILL);
  5750. param_filter->set_placeholder(TTR("Filter Parameters"));
  5751. preview_tools = memnew(MenuButton);
  5752. filter_hbox->add_child(preview_tools);
  5753. preview_tools->set_tooltip_text(TTR("Options"));
  5754. preview_tools->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_preview_tools_menu_option));
  5755. preview_tools->get_popup()->add_item(TTR("Copy Parameters From Material"), COPY_PARAMS_FROM_MATERIAL);
  5756. preview_tools->get_popup()->add_item(TTR("Paste Parameters To Material"), PASTE_PARAMS_TO_MATERIAL);
  5757. ScrollContainer *sc = memnew(ScrollContainer);
  5758. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  5759. params_vbox->add_child(sc);
  5760. parameters = memnew(Tree);
  5761. parameters->set_hide_root(true);
  5762. parameters->set_allow_reselect(true);
  5763. parameters->set_hide_folding(false);
  5764. parameters->set_h_size_flags(SIZE_EXPAND_FILL);
  5765. parameters->set_v_size_flags(SIZE_EXPAND_FILL);
  5766. parameters->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  5767. parameters->set_theme_type_variation("TreeSecondary");
  5768. parameters->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_param_selected));
  5769. parameters->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_param_unselected));
  5770. sc->add_child(parameters);
  5771. param_vbox = memnew(VBoxContainer);
  5772. param_vbox->set_v_size_flags(SIZE_EXPAND_FILL);
  5773. param_vbox->hide();
  5774. params_vbox->add_child(param_vbox);
  5775. ScrollContainer *sc2 = memnew(ScrollContainer);
  5776. sc2->set_v_size_flags(SIZE_EXPAND_FILL);
  5777. param_vbox->add_child(sc2);
  5778. param_vbox2 = memnew(VBoxContainer);
  5779. param_vbox2->set_h_size_flags(SIZE_EXPAND_FILL);
  5780. sc2->add_child(param_vbox2);
  5781. ///////////////////////////////////////
  5782. // SHADER NODES TREE
  5783. ///////////////////////////////////////
  5784. VBoxContainer *members_vb = memnew(VBoxContainer);
  5785. members_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  5786. HBoxContainer *filter_hb = memnew(HBoxContainer);
  5787. members_vb->add_child(filter_hb);
  5788. node_filter = memnew(LineEdit);
  5789. filter_hb->add_child(node_filter);
  5790. node_filter->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_member_filter_changed));
  5791. node_filter->connect(SceneStringName(gui_input), callable_mp(this, &VisualShaderEditor::_sbox_input));
  5792. node_filter->set_h_size_flags(SIZE_EXPAND_FILL);
  5793. node_filter->set_placeholder(TTR("Search"));
  5794. tools = memnew(MenuButton);
  5795. filter_hb->add_child(tools);
  5796. tools->set_tooltip_text(TTR("Options"));
  5797. tools->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_tools_menu_option));
  5798. tools->get_popup()->add_item(TTR("Expand All"), EXPAND_ALL);
  5799. tools->get_popup()->add_item(TTR("Collapse All"), COLLAPSE_ALL);
  5800. members = memnew(Tree);
  5801. members_vb->add_child(members);
  5802. SET_DRAG_FORWARDING_GCD(members, VisualShaderEditor);
  5803. members->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  5804. members->set_h_size_flags(SIZE_EXPAND_FILL);
  5805. members->set_v_size_flags(SIZE_EXPAND_FILL);
  5806. members->set_hide_root(true);
  5807. members->set_allow_reselect(true);
  5808. members->set_hide_folding(false);
  5809. members->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE));
  5810. members->connect("item_activated", callable_mp(this, &VisualShaderEditor::_member_create));
  5811. members->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_member_selected));
  5812. HBoxContainer *desc_hbox = memnew(HBoxContainer);
  5813. members_vb->add_child(desc_hbox);
  5814. Label *desc_label = memnew(Label);
  5815. desc_hbox->add_child(desc_label);
  5816. desc_label->set_text(TTR("Description:"));
  5817. desc_hbox->add_spacer();
  5818. highend_label = memnew(Label);
  5819. highend_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  5820. desc_hbox->add_child(highend_label);
  5821. highend_label->set_visible(false);
  5822. highend_label->set_text("Vulkan");
  5823. highend_label->set_mouse_filter(Control::MOUSE_FILTER_STOP);
  5824. highend_label->set_tooltip_text(TTR("High-end node"));
  5825. node_desc = memnew(RichTextLabel);
  5826. members_vb->add_child(node_desc);
  5827. node_desc->set_h_size_flags(SIZE_EXPAND_FILL);
  5828. node_desc->set_v_size_flags(SIZE_FILL);
  5829. node_desc->set_custom_minimum_size(Size2(0, 70 * EDSCALE));
  5830. members_dialog = memnew(ConfirmationDialog);
  5831. members_dialog->set_title(TTR("Create Shader Node"));
  5832. members_dialog->add_child(members_vb);
  5833. members_dialog->set_ok_button_text(TTR("Create"));
  5834. members_dialog->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_member_create));
  5835. members_dialog->get_ok_button()->set_disabled(true);
  5836. members_dialog->connect("canceled", callable_mp(this, &VisualShaderEditor::_member_cancel));
  5837. members_dialog->register_text_enter(node_filter);
  5838. add_child(members_dialog);
  5839. // add varyings dialog
  5840. {
  5841. add_varying_dialog = memnew(ConfirmationDialog);
  5842. add_varying_dialog->set_title(TTR("Create Shader Varying"));
  5843. add_varying_dialog->set_ok_button_text(TTR("Create"));
  5844. add_varying_dialog->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_varying_create));
  5845. add_varying_dialog->get_ok_button()->set_disabled(true);
  5846. add_child(add_varying_dialog);
  5847. VBoxContainer *vb = memnew(VBoxContainer);
  5848. add_varying_dialog->add_child(vb);
  5849. HBoxContainer *hb = memnew(HBoxContainer);
  5850. vb->add_child(hb);
  5851. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  5852. varying_type = memnew(OptionButton);
  5853. hb->add_child(varying_type);
  5854. varying_type->add_item("Float");
  5855. varying_type->add_item("Int");
  5856. varying_type->add_item("UInt");
  5857. varying_type->add_item("Vector2");
  5858. varying_type->add_item("Vector3");
  5859. varying_type->add_item("Vector4");
  5860. varying_type->add_item("Boolean");
  5861. varying_type->add_item("Transform");
  5862. varying_type->set_accessibility_name(TTRC("Varying Type"));
  5863. varying_type->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_type_changed));
  5864. varying_name = memnew(LineEdit);
  5865. hb->add_child(varying_name);
  5866. varying_name->set_custom_minimum_size(Size2(150 * EDSCALE, 0));
  5867. varying_name->set_h_size_flags(SIZE_EXPAND_FILL);
  5868. varying_name->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_varying_name_changed));
  5869. add_varying_dialog->register_text_enter(varying_name);
  5870. varying_mode = memnew(OptionButton);
  5871. hb->add_child(varying_mode);
  5872. varying_mode->add_item("Vertex -> [Fragment, Light]");
  5873. varying_mode->add_item("Fragment -> Light");
  5874. varying_mode->set_accessibility_name(TTRC("Varying Mode"));
  5875. varying_mode->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_mode_changed));
  5876. varying_error_label = memnew(Label);
  5877. varying_error_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  5878. vb->add_child(varying_error_label);
  5879. varying_error_label->set_h_size_flags(SIZE_EXPAND_FILL);
  5880. varying_error_label->hide();
  5881. }
  5882. // remove varying dialog
  5883. {
  5884. remove_varying_dialog = memnew(ConfirmationDialog);
  5885. remove_varying_dialog->set_title(TTR("Delete Shader Varying"));
  5886. remove_varying_dialog->set_ok_button_text(TTR("Delete"));
  5887. remove_varying_dialog->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_varying_deleted));
  5888. add_child(remove_varying_dialog);
  5889. VBoxContainer *vb = memnew(VBoxContainer);
  5890. remove_varying_dialog->add_child(vb);
  5891. varyings = memnew(Tree);
  5892. vb->add_child(varyings);
  5893. varyings->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  5894. varyings->set_h_size_flags(SIZE_EXPAND_FILL);
  5895. varyings->set_v_size_flags(SIZE_EXPAND_FILL);
  5896. varyings->set_hide_root(true);
  5897. varyings->set_allow_reselect(true);
  5898. varyings->set_hide_folding(false);
  5899. varyings->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE));
  5900. varyings->connect("item_activated", callable_mp(this, &VisualShaderEditor::_varying_deleted));
  5901. varyings->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_selected));
  5902. varyings->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_varying_unselected));
  5903. }
  5904. alert = memnew(AcceptDialog);
  5905. alert->get_label()->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  5906. alert->get_label()->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  5907. alert->get_label()->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  5908. alert->get_label()->set_custom_minimum_size(Size2(400, 60) * EDSCALE);
  5909. add_child(alert);
  5910. frame_title_change_popup = memnew(PopupPanel);
  5911. frame_title_change_edit = memnew(LineEdit);
  5912. frame_title_change_edit->set_expand_to_text_length_enabled(true);
  5913. frame_title_change_edit->set_select_all_on_focus(true);
  5914. frame_title_change_edit->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_frame_title_text_changed));
  5915. frame_title_change_edit->connect(SceneStringName(text_submitted), callable_mp(this, &VisualShaderEditor::_frame_title_text_submitted));
  5916. frame_title_change_popup->add_child(frame_title_change_edit);
  5917. frame_title_change_edit->reset_size();
  5918. frame_title_change_popup->reset_size();
  5919. frame_title_change_popup->connect(SceneStringName(focus_exited), callable_mp(this, &VisualShaderEditor::_frame_title_popup_focus_out));
  5920. frame_title_change_popup->connect("popup_hide", callable_mp(this, &VisualShaderEditor::_frame_title_popup_hide));
  5921. add_child(frame_title_change_popup);
  5922. frame_tint_color_pick_popup = memnew(PopupPanel);
  5923. VBoxContainer *frame_popup_item_tint_color_editor = memnew(VBoxContainer);
  5924. frame_tint_color_pick_popup->add_child(frame_popup_item_tint_color_editor);
  5925. frame_tint_color_picker = memnew(ColorPicker);
  5926. frame_popup_item_tint_color_editor->add_child(frame_tint_color_picker);
  5927. frame_tint_color_picker->reset_size();
  5928. frame_tint_color_picker->connect("color_changed", callable_mp(this, &VisualShaderEditor::_frame_color_changed));
  5929. Button *frame_tint_color_confirm_button = memnew(Button);
  5930. frame_tint_color_confirm_button->set_text(TTR("OK"));
  5931. frame_popup_item_tint_color_editor->add_child(frame_tint_color_confirm_button);
  5932. frame_tint_color_confirm_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_frame_color_confirm));
  5933. frame_tint_color_pick_popup->connect("popup_hide", callable_mp(this, &VisualShaderEditor::_frame_color_popup_hide));
  5934. add_child(frame_tint_color_pick_popup);
  5935. ///////////////////////////////////////
  5936. // SHADER NODES TREE OPTIONS
  5937. ///////////////////////////////////////
  5938. // COLOR
  5939. add_options.push_back(AddOption("ColorFunc", "Color/Common", "VisualShaderNodeColorFunc", TTR("Color function."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5940. add_options.push_back(AddOption("ColorOp", "Color/Common", "VisualShaderNodeColorOp", TTR("Color operator."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5941. add_options.push_back(AddOption("Grayscale", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Grayscale function."), { VisualShaderNodeColorFunc::FUNC_GRAYSCALE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5942. add_options.push_back(AddOption("HSV2RGB", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Converts HSV vector to RGB equivalent."), { VisualShaderNodeColorFunc::FUNC_HSV2RGB, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5943. add_options.push_back(AddOption("LinearToSRGB", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Converts color from linear to sRGB color space."), { VisualShaderNodeColorFunc::FUNC_LINEAR_TO_SRGB }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5944. add_options.push_back(AddOption("RGB2HSV", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Converts RGB vector to HSV equivalent."), { VisualShaderNodeColorFunc::FUNC_RGB2HSV, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5945. add_options.push_back(AddOption("Sepia", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Sepia function."), { VisualShaderNodeColorFunc::FUNC_SEPIA }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5946. add_options.push_back(AddOption("SRGBToLinear", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Converts color from sRGB to linear color space."), { VisualShaderNodeColorFunc::FUNC_SRGB_TO_LINEAR }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5947. add_options.push_back(AddOption("Burn", "Color/Operators", "VisualShaderNodeColorOp", TTR("Burn operator."), { VisualShaderNodeColorOp::OP_BURN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5948. add_options.push_back(AddOption("Darken", "Color/Operators", "VisualShaderNodeColorOp", TTR("Darken operator."), { VisualShaderNodeColorOp::OP_DARKEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5949. add_options.push_back(AddOption("Difference", "Color/Operators", "VisualShaderNodeColorOp", TTR("Difference operator."), { VisualShaderNodeColorOp::OP_DIFFERENCE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5950. add_options.push_back(AddOption("Dodge", "Color/Operators", "VisualShaderNodeColorOp", TTR("Dodge operator."), { VisualShaderNodeColorOp::OP_DODGE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5951. add_options.push_back(AddOption("HardLight", "Color/Operators", "VisualShaderNodeColorOp", TTR("HardLight operator."), { VisualShaderNodeColorOp::OP_HARD_LIGHT }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5952. add_options.push_back(AddOption("Lighten", "Color/Operators", "VisualShaderNodeColorOp", TTR("Lighten operator."), { VisualShaderNodeColorOp::OP_LIGHTEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5953. add_options.push_back(AddOption("Overlay", "Color/Operators", "VisualShaderNodeColorOp", TTR("Overlay operator."), { VisualShaderNodeColorOp::OP_OVERLAY }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5954. add_options.push_back(AddOption("Screen", "Color/Operators", "VisualShaderNodeColorOp", TTR("Screen operator."), { VisualShaderNodeColorOp::OP_SCREEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5955. add_options.push_back(AddOption("SoftLight", "Color/Operators", "VisualShaderNodeColorOp", TTR("SoftLight operator."), { VisualShaderNodeColorOp::OP_SOFT_LIGHT }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5956. add_options.push_back(AddOption("ColorConstant", "Color/Variables", "VisualShaderNodeColorConstant", TTR("Color constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  5957. add_options.push_back(AddOption("ColorParameter", "Color/Variables", "VisualShaderNodeColorParameter", TTR("Color parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  5958. // COMMON
  5959. add_options.push_back(AddOption("DerivativeFunc", "Common", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) Derivative function."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  5960. add_options.push_back(AddOption("DerivativeFunc", "Common", "VisualShaderNodeDerivativeFunc", TTR("Derivative function."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  5961. // CONDITIONAL
  5962. const String &compare_func_desc = TTR("Returns the boolean result of the %s comparison between two parameters.");
  5963. add_options.push_back(AddOption("Equal (==)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Equal (==)")), { VisualShaderNodeCompare::FUNC_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5964. add_options.push_back(AddOption("GreaterThan (>)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Greater Than (>)")), { VisualShaderNodeCompare::FUNC_GREATER_THAN }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5965. 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));
  5966. add_options.push_back(AddOption("If", "Conditional/Functions", "VisualShaderNodeIf", TTR("Returns an associated vector if the provided scalars are equal, greater or less."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5967. 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));
  5968. 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));
  5969. add_options.push_back(AddOption("LessThan (<)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than (<)")), { VisualShaderNodeCompare::FUNC_LESS_THAN }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5970. 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));
  5971. add_options.push_back(AddOption("NotEqual (!=)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Not Equal (!=)")), { VisualShaderNodeCompare::FUNC_NOT_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5972. add_options.push_back(AddOption("SwitchVector2D (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated 2D vector if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  5973. add_options.push_back(AddOption("SwitchVector3D (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated 3D vector if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5974. add_options.push_back(AddOption("SwitchVector4D (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated 4D vector if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  5975. add_options.push_back(AddOption("SwitchBool (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated boolean if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_BOOLEAN }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5976. add_options.push_back(AddOption("SwitchFloat (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated floating-point scalar if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_FLOAT }, VisualShaderNode::PORT_TYPE_SCALAR));
  5977. add_options.push_back(AddOption("SwitchInt (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated integer scalar if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_INT }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  5978. add_options.push_back(AddOption("SwitchTransform (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated transform if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_TRANSFORM }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  5979. add_options.push_back(AddOption("SwitchUInt (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated unsigned integer scalar if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_UINT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  5980. add_options.push_back(AddOption("Compare (==)", "Conditional/Common", "VisualShaderNodeCompare", TTR("Returns the boolean result of the comparison between two parameters."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5981. 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."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5982. add_options.push_back(AddOption("BooleanConstant", "Conditional/Variables", "VisualShaderNodeBooleanConstant", TTR("Boolean constant."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5983. add_options.push_back(AddOption("BooleanParameter", "Conditional/Variables", "VisualShaderNodeBooleanParameter", TTR("Boolean parameter."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5984. // INPUT
  5985. const String translation_gdsl = "\n\n" + TTR("Translated to '%s' in Godot Shading Language.");
  5986. const String input_param_shader_modes = TTR("'%s' input parameter for all shader modes.") + translation_gdsl;
  5987. // NODE3D-FOR-ALL
  5988. add_options.push_back(AddOption("ClipSpaceFar", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "clip_space_far", "CLIP_SPACE_FAR"), { "clip_space_far" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL));
  5989. add_options.push_back(AddOption("Exposure", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "exposure", "EXPOSURE"), { "exposure" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL));
  5990. add_options.push_back(AddOption("InvProjectionMatrix", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "inv_projection_matrix", "INV_PROJECTION_MATRIX"), { "inv_projection_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL));
  5991. add_options.push_back(AddOption("InvViewMatrix", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "inv_view_matrix", "INV_VIEW_MATRIX"), { "inv_view_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL));
  5992. add_options.push_back(AddOption("ModelMatrix", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "model_matrix", "MODEL_MATRIX"), { "model_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL));
  5993. add_options.push_back(AddOption("Normal", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "normal", "NORMAL"), { "normal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, -1, Shader::MODE_SPATIAL));
  5994. add_options.push_back(AddOption("OutputIsSRGB", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "output_is_srgb", "OUTPUT_IS_SRGB"), { "output_is_srgb" }, VisualShaderNode::PORT_TYPE_BOOLEAN, -1, Shader::MODE_SPATIAL));
  5995. add_options.push_back(AddOption("ProjectionMatrix", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "projection_matrix", "PROJECTION_MATRIX"), { "projection_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL));
  5996. add_options.push_back(AddOption("Time", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL));
  5997. add_options.push_back(AddOption("UV", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "uv", "UV"), { "uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, -1, Shader::MODE_SPATIAL));
  5998. add_options.push_back(AddOption("UV2", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "uv2", "UV2"), { "uv2" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, -1, Shader::MODE_SPATIAL));
  5999. add_options.push_back(AddOption("ViewMatrix", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "view_matrix", "VIEW_MATRIX"), { "view_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL));
  6000. add_options.push_back(AddOption("ViewportSize", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "viewport_size", "VIEWPORT_SIZE"), { "viewport_size" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, -1, Shader::MODE_SPATIAL));
  6001. // CANVASITEM-FOR-ALL
  6002. add_options.push_back(AddOption("Color", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "color", "COLOR"), { "color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, -1, Shader::MODE_CANVAS_ITEM));
  6003. add_options.push_back(AddOption("TexturePixelSize", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "texture_pixel_size", "TEXTURE_PIXEL_SIZE"), { "texture_pixel_size" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, -1, Shader::MODE_CANVAS_ITEM));
  6004. add_options.push_back(AddOption("Time", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_CANVAS_ITEM));
  6005. add_options.push_back(AddOption("UV", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "uv", "UV"), { "uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, -1, Shader::MODE_CANVAS_ITEM));
  6006. // PARTICLES-FOR-ALL
  6007. add_options.push_back(AddOption("Active", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "active", "ACTIVE"), { "active" }, VisualShaderNode::PORT_TYPE_BOOLEAN, -1, Shader::MODE_PARTICLES));
  6008. add_options.push_back(AddOption("AttractorForce", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "attractor_force", "ATTRACTOR_FORCE"), { "attractor_force" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, -1, Shader::MODE_PARTICLES));
  6009. add_options.push_back(AddOption("Color", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "color", "COLOR"), { "color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, -1, Shader::MODE_PARTICLES));
  6010. add_options.push_back(AddOption("Custom", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "custom", "CUSTOM"), { "custom" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, -1, Shader::MODE_PARTICLES));
  6011. add_options.push_back(AddOption("Delta", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "delta", "DELTA"), { "delta" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_PARTICLES));
  6012. add_options.push_back(AddOption("EmissionTransform", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "emission_transform", "EMISSION_TRANSFORM"), { "emission_transform" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_PARTICLES));
  6013. add_options.push_back(AddOption("Index", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "index", "INDEX"), { "index" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, -1, Shader::MODE_PARTICLES));
  6014. add_options.push_back(AddOption("LifeTime", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "lifetime", "LIFETIME"), { "lifetime" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_PARTICLES));
  6015. add_options.push_back(AddOption("Number", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "number", "NUMBER"), { "number" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, -1, Shader::MODE_PARTICLES));
  6016. add_options.push_back(AddOption("RandomSeed", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "random_seed", "RANDOM_SEED"), { "random_seed" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, -1, Shader::MODE_PARTICLES));
  6017. add_options.push_back(AddOption("Restart", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "restart", "RESTART"), { "restart" }, VisualShaderNode::PORT_TYPE_BOOLEAN, -1, Shader::MODE_PARTICLES));
  6018. add_options.push_back(AddOption("Time", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_PARTICLES));
  6019. add_options.push_back(AddOption("Transform", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "transform", "TRANSFORM"), { "transform" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_PARTICLES));
  6020. add_options.push_back(AddOption("Velocity", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "velocity", "VELOCITY"), { "velocity" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, -1, Shader::MODE_PARTICLES));
  6021. /////////////////
  6022. add_options.push_back(AddOption("Input", "Input/Common", "VisualShaderNodeInput", TTR("Input parameter.")));
  6023. const String input_param_for_vertex_and_fragment_shader_modes = TTR("'%s' input parameter for vertex and fragment shader modes.") + translation_gdsl;
  6024. const String input_param_for_fragment_and_light_shader_modes = TTR("'%s' input parameter for fragment and light shader modes.") + translation_gdsl;
  6025. const String input_param_for_fragment_shader_mode = TTR("'%s' input parameter for fragment shader mode.") + translation_gdsl;
  6026. const String input_param_for_sky_shader_mode = TTR("'%s' input parameter for sky shader mode.") + translation_gdsl;
  6027. const String input_param_for_fog_shader_mode = TTR("'%s' input parameter for fog shader mode.") + translation_gdsl;
  6028. const String input_param_for_light_shader_mode = TTR("'%s' input parameter for light shader mode.") + translation_gdsl;
  6029. const String input_param_for_vertex_shader_mode = TTR("'%s' input parameter for vertex shader mode.") + translation_gdsl;
  6030. const String input_param_for_start_shader_mode = TTR("'%s' input parameter for start shader mode.") + translation_gdsl;
  6031. const String input_param_for_process_shader_mode = TTR("'%s' input parameter for process shader mode.") + translation_gdsl;
  6032. const String input_param_for_collide_shader_mode = TTR("'%s' input parameter for collide shader mode." + translation_gdsl);
  6033. const String input_param_for_start_and_process_shader_mode = TTR("'%s' input parameter for start and process shader modes.") + translation_gdsl;
  6034. const String input_param_for_process_and_collide_shader_mode = TTR("'%s' input parameter for process and collide shader modes.") + translation_gdsl;
  6035. const String input_param_for_vertex_and_fragment_shader_mode = TTR("'%s' input parameter for vertex and fragment shader modes.") + translation_gdsl;
  6036. // NODE3D INPUTS
  6037. add_options.push_back(AddOption("Binormal", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "binormal", "BINORMAL"), { "binormal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6038. add_options.push_back(AddOption("CameraDirectionWorld", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_direction_world", "CAMERA_DIRECTION_WORLD"), { "camera_direction_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6039. add_options.push_back(AddOption("CameraPositionWorld", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_position_world", "CAMERA_POSITION_WORLD"), { "camera_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6040. add_options.push_back(AddOption("CameraVisibleLayers", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS"), { "camera_visible_layers" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6041. add_options.push_back(AddOption("Color", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "color", "COLOR"), { "color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6042. add_options.push_back(AddOption("Custom0", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom0", "CUSTOM0"), { "custom0" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6043. add_options.push_back(AddOption("Custom1", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom1", "CUSTOM1"), { "custom1" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6044. add_options.push_back(AddOption("Custom2", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom2", "CUSTOM2"), { "custom2" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6045. add_options.push_back(AddOption("Custom3", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom3", "CUSTOM3"), { "custom3" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6046. add_options.push_back(AddOption("EyeOffset", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "eye_offset", "EYE_OFFSET"), { "eye_offset" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6047. add_options.push_back(AddOption("InstanceCustom", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "instance_custom", "INSTANCE_CUSTOM"), { "instance_custom" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6048. add_options.push_back(AddOption("InstanceId", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "instance_id", "INSTANCE_ID"), { "instance_id" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6049. add_options.push_back(AddOption("ModelViewMatrix", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "modelview_matrix", "MODELVIEW_MATRIX"), { "modelview_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6050. add_options.push_back(AddOption("NodePositionView", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_view", "NODE_POSITION_VIEW"), { "node_position_view" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6051. add_options.push_back(AddOption("NodePositionWorld", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_world", "NODE_POSITION_WORLD"), { "node_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6052. add_options.push_back(AddOption("PointSize", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "point_size", "POINT_SIZE"), { "point_size" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6053. add_options.push_back(AddOption("Tangent", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_mode, "tangent", "TANGENT"), { "tangent" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6054. add_options.push_back(AddOption("Vertex", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "vertex", "VERTEX"), { "vertex" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6055. add_options.push_back(AddOption("VertexId", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "vertex_id", "VERTEX_ID"), { "vertex_id" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6056. add_options.push_back(AddOption("ViewIndex", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_index", "VIEW_INDEX"), { "view_index" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6057. add_options.push_back(AddOption("ViewMonoLeft", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_mono_left", "VIEW_MONO_LEFT"), { "view_mono_left" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6058. add_options.push_back(AddOption("ViewRight", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_right", "VIEW_RIGHT"), { "view_right" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6059. add_options.push_back(AddOption("Binormal", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "binormal", "BINORMAL"), { "binormal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6060. add_options.push_back(AddOption("CameraDirectionWorld", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_direction_world", "CAMERA_DIRECTION_WORLD"), { "camera_direction_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6061. add_options.push_back(AddOption("CameraPositionWorld", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_position_world", "CAMERA_POSITION_WORLD"), { "camera_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6062. add_options.push_back(AddOption("CameraVisibleLayers", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS"), { "camera_visible_layers" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6063. add_options.push_back(AddOption("Color", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "color", "COLOR"), { "color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6064. add_options.push_back(AddOption("EyeOffset", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "eye_offset", "EYE_OFFSET"), { "eye_offset" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6065. add_options.push_back(AddOption("FragCoord", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord", "FRAGCOORD"), { "fragcoord" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6066. add_options.push_back(AddOption("FrontFacing", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "front_facing", "FRONT_FACING"), { "front_facing" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6067. add_options.push_back(AddOption("NodePositionView", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_view", "NODE_POSITION_VIEW"), { "node_position_view" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6068. add_options.push_back(AddOption("NodePositionWorld", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_world", "NODE_POSITION_WORLD"), { "node_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6069. add_options.push_back(AddOption("PointCoord", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "point_coord", "POINT_COORD"), { "point_coord" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6070. add_options.push_back(AddOption("ScreenUV", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6071. add_options.push_back(AddOption("Tangent", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "tangent", "TANGENT"), { "tangent" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6072. add_options.push_back(AddOption("Vertex", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "vertex", "VERTEX"), { "vertex" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6073. add_options.push_back(AddOption("View", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "view", "VIEW"), { "view" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6074. add_options.push_back(AddOption("ViewIndex", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_index", "VIEW_INDEX"), { "view_index" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6075. add_options.push_back(AddOption("ViewMonoLeft", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_mono_left", "VIEW_MONO_LEFT"), { "view_mono_left" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6076. add_options.push_back(AddOption("ViewRight", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_right", "VIEW_RIGHT"), { "view_right" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6077. add_options.push_back(AddOption("Albedo", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "albedo", "ALBEDO"), { "albedo" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6078. add_options.push_back(AddOption("Attenuation", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "attenuation", "ATTENUATION"), { "attenuation" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6079. add_options.push_back(AddOption("Backlight", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "backlight", "BACKLIGHT"), { "backlight" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6080. add_options.push_back(AddOption("Diffuse", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "diffuse", "DIFFUSE_LIGHT"), { "diffuse" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6081. add_options.push_back(AddOption("FragCoord", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord", "FRAGCOORD"), { "fragcoord" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6082. add_options.push_back(AddOption("Light", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light", "LIGHT"), { "light" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6083. add_options.push_back(AddOption("LightColor", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_color", "LIGHT_COLOR"), { "light_color" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6084. add_options.push_back(AddOption("LightIsDirectional", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_is_directional", "LIGHT_IS_DIRECTIONAL"), { "light_is_directional" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6085. add_options.push_back(AddOption("Metallic", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "metallic", "METALLIC"), { "metallic" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6086. add_options.push_back(AddOption("Roughness", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "roughness", "ROUGHNESS"), { "roughness" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6087. add_options.push_back(AddOption("ScreenUV", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6088. add_options.push_back(AddOption("Specular", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "specular", "SPECULAR_LIGHT"), { "specular" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6089. add_options.push_back(AddOption("View", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "view", "VIEW"), { "view" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6090. // CANVASITEM INPUTS
  6091. add_options.push_back(AddOption("AtLightPass", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "at_light_pass", "AT_LIGHT_PASS"), { "at_light_pass" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6092. add_options.push_back(AddOption("CanvasMatrix", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "canvas_matrix", "CANVAS_MATRIX"), { "canvas_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6093. add_options.push_back(AddOption("Custom0", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom0", "CUSTOM0"), { "custom0" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6094. add_options.push_back(AddOption("Custom1", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom1", "CUSTOM1"), { "custom1" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6095. add_options.push_back(AddOption("InstanceCustom", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "instance_custom", "INSTANCE_CUSTOM"), { "instance_custom" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6096. add_options.push_back(AddOption("InstanceId", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "instance_id", "INSTANCE_ID"), { "instance_id" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6097. add_options.push_back(AddOption("ModelMatrix", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "model_matrix", "MODEL_MATRIX"), { "model_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6098. add_options.push_back(AddOption("PointSize", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "point_size", "POINT_SIZE"), { "point_size" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6099. add_options.push_back(AddOption("ScreenMatrix", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "screen_matrix", "SCREEN_MATRIX"), { "screen_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6100. add_options.push_back(AddOption("Vertex", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_mode, "vertex", "VERTEX"), { "vertex" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6101. add_options.push_back(AddOption("VertexId", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "vertex_id", "VERTEX_ID"), { "vertex_id" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM));
  6102. add_options.push_back(AddOption("AtLightPass", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "at_light_pass", "AT_LIGHT_PASS"), { "at_light_pass" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6103. add_options.push_back(AddOption("FragCoord", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord", "FRAGCOORD"), { "fragcoord" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6104. add_options.push_back(AddOption("NormalTexture", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "normal_texture", "NORMAL_TEXTURE"), { "normal_texture" }, VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6105. add_options.push_back(AddOption("PointCoord", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "point_coord", "POINT_COORD"), { "point_coord" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6106. add_options.push_back(AddOption("RegionRect", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "region_rect", "REGION_RECT"), { "region_rect" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6107. add_options.push_back(AddOption("ScreenPixelSize", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_pixel_size", "SCREEN_PIXEL_SIZE"), { "screen_pixel_size" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6108. add_options.push_back(AddOption("ScreenUV", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6109. add_options.push_back(AddOption("SpecularShininess", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "specular_shininess", "SPECULAR_SHININESS"), { "specular_shininess" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6110. add_options.push_back(AddOption("SpecularShininessTexture", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "specular_shininess_texture", "SPECULAR_SHININESS_TEXTURE"), { "specular_shininess_texture" }, VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6111. add_options.push_back(AddOption("Texture", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "texture", "TEXTURE"), { "texture" }, VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6112. add_options.push_back(AddOption("Vertex", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_mode, "vertex", "VERTEX"), { "vertex" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6113. add_options.push_back(AddOption("FragCoord", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord", "FRAGCOORD"), { "fragcoord" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6114. add_options.push_back(AddOption("Light", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light", "LIGHT"), { "light" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6115. add_options.push_back(AddOption("LightColor", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_color", "LIGHT_COLOR"), { "light_color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6116. add_options.push_back(AddOption("LightDirection", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_direction", "LIGHT_DIRECTION"), { "light_direction" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6117. add_options.push_back(AddOption("LightEnergy", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_energy", "LIGHT_ENERGY"), { "light_energy" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6118. add_options.push_back(AddOption("LightIsDirectional", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_is_directional", "LIGHT_IS_DIRECTIONAL"), { "light_is_directional" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6119. add_options.push_back(AddOption("LightPosition", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_position", "LIGHT_POSITION"), { "light_position" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6120. add_options.push_back(AddOption("LightVertex", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "light_vertex", "LIGHT_VERTEX"), { "light_vertex" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6121. add_options.push_back(AddOption("Normal", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "normal", "NORMAL"), { "normal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6122. add_options.push_back(AddOption("PointCoord", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "point_coord", "POINT_COORD"), { "point_coord" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6123. add_options.push_back(AddOption("ScreenUV", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6124. add_options.push_back(AddOption("Shadow", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "shadow", "SHADOW_MODULATE"), { "shadow" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6125. add_options.push_back(AddOption("SpecularShininess", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "specular_shininess", "SPECULAR_SHININESS"), { "specular_shininess" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6126. add_options.push_back(AddOption("Texture", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "texture", "TEXTURE"), { "texture" }, VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6127. // SKY INPUTS
  6128. add_options.push_back(AddOption("AtCubeMapPass", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "at_cubemap_pass", "AT_CUBEMAP_PASS"), { "at_cubemap_pass" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6129. add_options.push_back(AddOption("AtHalfResPass", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "at_half_res_pass", "AT_HALF_RES_PASS"), { "at_half_res_pass" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6130. add_options.push_back(AddOption("AtQuarterResPass", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "at_quarter_res_pass", "AT_QUARTER_RES_PASS"), { "at_quarter_res_pass" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6131. add_options.push_back(AddOption("EyeDir", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "eyedir", "EYEDIR"), { "eyedir" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6132. add_options.push_back(AddOption("FragCoord", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "fragcoord", "FRAGCOORD"), { "fragcoord" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6133. add_options.push_back(AddOption("HalfResColor", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "half_res_color", "HALF_RES_COLOR"), { "half_res_color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6134. add_options.push_back(AddOption("Light0Color", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light0_color", "LIGHT0_COLOR"), { "light0_color" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6135. add_options.push_back(AddOption("Light0Direction", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light0_direction", "LIGHT0_DIRECTION"), { "light0_direction" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6136. add_options.push_back(AddOption("Light0Enabled", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light0_enabled", "LIGHT0_ENABLED"), { "light0_enabled" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6137. add_options.push_back(AddOption("Light0Energy", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light0_energy", "LIGHT0_ENERGY"), { "light0_energy" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6138. add_options.push_back(AddOption("Light1Color", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light1_color", "LIGHT1_COLOR"), { "light1_color" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6139. add_options.push_back(AddOption("Light1Direction", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light1_direction", "LIGHT1_DIRECTION"), { "light1_direction" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6140. add_options.push_back(AddOption("Light1Enabled", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light1_enabled", "LIGHT1_ENABLED"), { "light1_enabled" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6141. add_options.push_back(AddOption("Light1Energy", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light1_energy", "LIGHT1_ENERGY"), { "light1_energy" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6142. add_options.push_back(AddOption("Light2Color", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light2_color", "LIGHT2_COLOR"), { "light2_color" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6143. add_options.push_back(AddOption("Light2Direction", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light2_direction", "LIGHT2_DIRECTION"), { "light2_direction" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6144. add_options.push_back(AddOption("Light2Enabled", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light2_enabled", "LIGHT2_ENABLED"), { "light2_enabled" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6145. add_options.push_back(AddOption("Light2Energy", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light2_energy", "LIGHT2_ENERGY"), { "light2_energy" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6146. add_options.push_back(AddOption("Light3Color", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light3_color", "LIGHT3_COLOR"), { "light3_color" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6147. add_options.push_back(AddOption("Light3Direction", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light3_direction", "LIGHT3_DIRECTION"), { "light3_direction" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6148. add_options.push_back(AddOption("Light3Enabled", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light3_enabled", "LIGHT3_ENABLED"), { "light3_enabled" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6149. add_options.push_back(AddOption("Light3Energy", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light3_energy", "LIGHT3_ENERGY"), { "light3_energy" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6150. add_options.push_back(AddOption("Position", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "position", "POSITION"), { "position" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6151. add_options.push_back(AddOption("QuarterResColor", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "quarter_res_color", "QUARTER_RES_COLOR"), { "quarter_res_color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6152. add_options.push_back(AddOption("Radiance", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "radiance", "RADIANCE"), { "radiance" }, VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6153. add_options.push_back(AddOption("ScreenUV", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6154. add_options.push_back(AddOption("SkyCoords", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "sky_coords", "SKY_COORDS"), { "sky_coords" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6155. add_options.push_back(AddOption("Time", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY));
  6156. // FOG INPUTS
  6157. add_options.push_back(AddOption("ObjectPosition", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "object_position", "OBJECT_POSITION"), { "object_position" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FOG, Shader::MODE_FOG));
  6158. add_options.push_back(AddOption("SDF", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "sdf", "SDF"), { "sdf" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FOG, Shader::MODE_FOG));
  6159. add_options.push_back(AddOption("Size", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "size", "SIZE"), { "size" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FOG, Shader::MODE_FOG));
  6160. add_options.push_back(AddOption("Time", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FOG, Shader::MODE_FOG));
  6161. add_options.push_back(AddOption("UVW", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "uvw", "UVW"), { "uvw" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FOG, Shader::MODE_FOG));
  6162. add_options.push_back(AddOption("WorldPosition", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "world_position", "WORLD_POSITION"), { "world_position" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FOG, Shader::MODE_FOG));
  6163. // PARTICLES INPUTS
  6164. add_options.push_back(AddOption("CollisionDepth", "Input/Collide", "VisualShaderNodeInput", vformat(input_param_for_collide_shader_mode, "collision_depth", "COLLISION_DEPTH"), { "collision_depth" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  6165. add_options.push_back(AddOption("CollisionNormal", "Input/Collide", "VisualShaderNodeInput", vformat(input_param_for_collide_shader_mode, "collision_normal", "COLLISION_NORMAL"), { "collision_normal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  6166. // PARTICLES
  6167. add_options.push_back(AddOption("EmitParticle", "Particles", "VisualShaderNodeParticleEmit", "", {}, -1, TYPE_FLAGS_PROCESS | TYPE_FLAGS_PROCESS_CUSTOM | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  6168. add_options.push_back(AddOption("ParticleAccelerator", "Particles", "VisualShaderNodeParticleAccelerator", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  6169. add_options.push_back(AddOption("ParticleRandomness", "Particles", "VisualShaderNodeParticleRandomness", "", {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT | TYPE_FLAGS_PROCESS | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  6170. add_options.push_back(AddOption("MultiplyByAxisAngle (*)", "Particles/Transform", "VisualShaderNodeParticleMultiplyByAxisAngle", TTR("A node for help to multiply a position input vector by rotation using specific axis. Intended to work with emitters."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT | TYPE_FLAGS_PROCESS | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  6171. add_options.push_back(AddOption("BoxEmitter", "Particles/Emitters", "VisualShaderNodeParticleBoxEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  6172. mesh_emitter_option_idx = add_options.size();
  6173. add_options.push_back(AddOption("MeshEmitter", "Particles/Emitters", "VisualShaderNodeParticleMeshEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  6174. add_options.push_back(AddOption("RingEmitter", "Particles/Emitters", "VisualShaderNodeParticleRingEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  6175. add_options.push_back(AddOption("SphereEmitter", "Particles/Emitters", "VisualShaderNodeParticleSphereEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  6176. add_options.push_back(AddOption("ConeVelocity", "Particles/Velocity", "VisualShaderNodeParticleConeVelocity", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  6177. // SCALAR
  6178. add_options.push_back(AddOption("FloatFunc", "Scalar/Common", "VisualShaderNodeFloatFunc", TTR("Float function."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6179. add_options.push_back(AddOption("FloatOp", "Scalar/Common", "VisualShaderNodeFloatOp", TTR("Float operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6180. add_options.push_back(AddOption("IntFunc", "Scalar/Common", "VisualShaderNodeIntFunc", TTR("Integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6181. add_options.push_back(AddOption("IntOp", "Scalar/Common", "VisualShaderNodeIntOp", TTR("Integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6182. add_options.push_back(AddOption("UIntFunc", "Scalar/Common", "VisualShaderNodeUIntFunc", TTR("Unsigned integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6183. add_options.push_back(AddOption("UIntOp", "Scalar/Common", "VisualShaderNodeUIntOp", TTR("Unsigned integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6184. // CONSTANTS
  6185. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  6186. add_options.push_back(AddOption(float_constant_defs[i].name, "Scalar/Constants", "VisualShaderNodeFloatConstant", TTRGET(float_constant_defs[i].desc_key), { float_constant_defs[i].value }, VisualShaderNode::PORT_TYPE_SCALAR));
  6187. }
  6188. // FUNCTIONS
  6189. add_options.push_back(AddOption("Abs", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ABS }, VisualShaderNode::PORT_TYPE_SCALAR));
  6190. 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));
  6191. add_options.push_back(AddOption("ACos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ACOS }, VisualShaderNode::PORT_TYPE_SCALAR));
  6192. 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));
  6193. add_options.push_back(AddOption("ASin", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ASIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6194. 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));
  6195. add_options.push_back(AddOption("ATan", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ATAN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6196. add_options.push_back(AddOption("ATan2", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeFloatOp::OP_ATAN2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  6197. 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));
  6198. add_options.push_back(AddOption("BitwiseNOT", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Returns the result of bitwise NOT (~a) operation on the integer."), { VisualShaderNodeIntFunc::FUNC_BITWISE_NOT }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6199. add_options.push_back(AddOption("BitwiseNOT", "Scalar/Functions", "VisualShaderNodeUIntFunc", TTR("Returns the result of bitwise NOT (~a) operation on the unsigned integer."), { VisualShaderNodeUIntFunc::FUNC_BITWISE_NOT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6200. 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));
  6201. add_options.push_back(AddOption("Clamp", "Scalar/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_FLOAT }, VisualShaderNode::PORT_TYPE_SCALAR));
  6202. add_options.push_back(AddOption("Clamp", "Scalar/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_INT }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6203. add_options.push_back(AddOption("Clamp", "Scalar/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_UINT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6204. add_options.push_back(AddOption("Cos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COS }, VisualShaderNode::PORT_TYPE_SCALAR));
  6205. add_options.push_back(AddOption("CosH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COSH }, VisualShaderNode::PORT_TYPE_SCALAR));
  6206. add_options.push_back(AddOption("Degrees", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeFloatFunc::FUNC_DEGREES }, VisualShaderNode::PORT_TYPE_SCALAR));
  6207. add_options.push_back(AddOption("DFdX", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Scalar) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6208. add_options.push_back(AddOption("DFdY", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Scalar) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6209. add_options.push_back(AddOption("DFdX", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Scalar) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6210. add_options.push_back(AddOption("DFdY", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Scalar) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6211. add_options.push_back(AddOption("Exp", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-e Exponential."), { VisualShaderNodeFloatFunc::FUNC_EXP }, VisualShaderNode::PORT_TYPE_SCALAR));
  6212. add_options.push_back(AddOption("Exp2", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 Exponential."), { VisualShaderNodeFloatFunc::FUNC_EXP2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  6213. 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));
  6214. add_options.push_back(AddOption("Fract", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeFloatFunc::FUNC_FRACT }, VisualShaderNode::PORT_TYPE_SCALAR));
  6215. 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));
  6216. add_options.push_back(AddOption("Log", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Natural logarithm."), { VisualShaderNodeFloatFunc::FUNC_LOG }, VisualShaderNode::PORT_TYPE_SCALAR));
  6217. add_options.push_back(AddOption("Log2", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 logarithm."), { VisualShaderNodeFloatFunc::FUNC_LOG2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  6218. add_options.push_back(AddOption("Max", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the greater of two values."), { VisualShaderNodeFloatOp::OP_MAX }, VisualShaderNode::PORT_TYPE_SCALAR));
  6219. add_options.push_back(AddOption("Min", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the lesser of two values."), { VisualShaderNodeFloatOp::OP_MIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6220. add_options.push_back(AddOption("Mix", "Scalar/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two scalars."), { VisualShaderNodeMix::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR));
  6221. add_options.push_back(AddOption("MultiplyAdd (a * b + c)", "Scalar/Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on scalars."), { VisualShaderNodeMultiplyAdd::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR));
  6222. add_options.push_back(AddOption("Negate (*-1)", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_NEGATE }, VisualShaderNode::PORT_TYPE_SCALAR));
  6223. add_options.push_back(AddOption("Negate (*-1)", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeIntFunc::FUNC_NEGATE }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6224. add_options.push_back(AddOption("Negate (*-1)", "Scalar/Functions", "VisualShaderNodeUIntFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeUIntFunc::FUNC_NEGATE }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6225. add_options.push_back(AddOption("OneMinus (1-)", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 - scalar"), { VisualShaderNodeFloatFunc::FUNC_ONEMINUS }, VisualShaderNode::PORT_TYPE_SCALAR));
  6226. 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));
  6227. add_options.push_back(AddOption("Radians", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeFloatFunc::FUNC_RADIANS }, VisualShaderNode::PORT_TYPE_SCALAR));
  6228. add_options.push_back(AddOption("Reciprocal", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 / scalar"), { VisualShaderNodeFloatFunc::FUNC_RECIPROCAL }, VisualShaderNode::PORT_TYPE_SCALAR));
  6229. add_options.push_back(AddOption("Remap", "Scalar/Functions", "VisualShaderNodeRemap", TTR("Remaps a value from the input range to the output range."), { VisualShaderNodeRemap::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR));
  6230. add_options.push_back(AddOption("Round", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeFloatFunc::FUNC_ROUND }, VisualShaderNode::PORT_TYPE_SCALAR));
  6231. 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));
  6232. 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));
  6233. add_options.push_back(AddOption("Sign", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SIGN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6234. add_options.push_back(AddOption("Sign", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeIntFunc::FUNC_SIGN }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6235. add_options.push_back(AddOption("Sin", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6236. add_options.push_back(AddOption("SinH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SINH }, VisualShaderNode::PORT_TYPE_SCALAR));
  6237. add_options.push_back(AddOption("Sqrt", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SQRT }, VisualShaderNode::PORT_TYPE_SCALAR));
  6238. add_options.push_back(AddOption("SmoothStep", "Scalar/Functions", "VisualShaderNodeSmoothStep", 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."), { VisualShaderNodeSmoothStep::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR));
  6239. add_options.push_back(AddOption("Step", "Scalar/Functions", "VisualShaderNodeStep", TTR("Step function( scalar(edge), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR));
  6240. add_options.push_back(AddOption("Sum", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Scalar) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6241. add_options.push_back(AddOption("Sum", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Scalar) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6242. add_options.push_back(AddOption("Tan", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TAN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6243. add_options.push_back(AddOption("TanH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TANH }, VisualShaderNode::PORT_TYPE_SCALAR));
  6244. add_options.push_back(AddOption("Trunc", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TRUNC }, VisualShaderNode::PORT_TYPE_SCALAR));
  6245. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Sums two floating-point scalars."), { VisualShaderNodeFloatOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR));
  6246. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Sums two integer scalars."), { VisualShaderNodeIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6247. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Sums two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6248. add_options.push_back(AddOption("BitwiseAND (&)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise AND (a & b) operation for two integers."), { VisualShaderNodeIntOp::OP_BITWISE_AND }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6249. add_options.push_back(AddOption("BitwiseAND (&)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise AND (a & b) operation for two unsigned integers."), { VisualShaderNodeUIntOp::OP_BITWISE_AND }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6250. add_options.push_back(AddOption("BitwiseLeftShift (<<)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise left shift (a << b) operation on the integer."), { VisualShaderNodeIntOp::OP_BITWISE_LEFT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6251. add_options.push_back(AddOption("BitwiseLeftShift (<<)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise left shift (a << b) operation on the unsigned integer."), { VisualShaderNodeUIntOp::OP_BITWISE_LEFT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6252. add_options.push_back(AddOption("BitwiseOR (|)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise OR (a | b) operation for two integers."), { VisualShaderNodeIntOp::OP_BITWISE_OR }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6253. add_options.push_back(AddOption("BitwiseOR (|)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise OR (a | b) operation for two unsigned integers."), { VisualShaderNodeUIntOp::OP_BITWISE_OR }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6254. add_options.push_back(AddOption("BitwiseRightShift (>>)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise right shift (a >> b) operation on the integer."), { VisualShaderNodeIntOp::OP_BITWISE_RIGHT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6255. add_options.push_back(AddOption("BitwiseRightShift (>>)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise right shift (a >> b) operation on the unsigned integer."), { VisualShaderNodeIntOp::OP_BITWISE_RIGHT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6256. add_options.push_back(AddOption("BitwiseXOR (^)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise XOR (a ^ b) operation on the integer."), { VisualShaderNodeIntOp::OP_BITWISE_XOR }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6257. add_options.push_back(AddOption("BitwiseXOR (^)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise XOR (a ^ b) operation on the unsigned integer."), { VisualShaderNodeUIntOp::OP_BITWISE_XOR }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6258. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Divides two floating-point scalars."), { VisualShaderNodeFloatOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR));
  6259. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Divides two integer scalars."), { VisualShaderNodeIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6260. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Divides two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6261. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Multiplies two floating-point scalars."), { VisualShaderNodeFloatOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR));
  6262. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Multiplies two integer scalars."), { VisualShaderNodeIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6263. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Multiplies two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6264. 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));
  6265. 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));
  6266. add_options.push_back(AddOption("Remainder (%)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the remainder of the two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_MOD }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6267. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Subtracts two floating-point scalars."), { VisualShaderNodeFloatOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR));
  6268. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Subtracts two integer scalars."), { VisualShaderNodeIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6269. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Subtracts two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6270. add_options.push_back(AddOption("FloatConstant", "Scalar/Variables", "VisualShaderNodeFloatConstant", TTR("Scalar floating-point constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6271. add_options.push_back(AddOption("IntConstant", "Scalar/Variables", "VisualShaderNodeIntConstant", TTR("Scalar integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6272. add_options.push_back(AddOption("UIntConstant", "Scalar/Variables", "VisualShaderNodeUIntConstant", TTR("Scalar unsigned integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6273. add_options.push_back(AddOption("FloatParameter", "Scalar/Variables", "VisualShaderNodeFloatParameter", TTR("Scalar floating-point parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6274. add_options.push_back(AddOption("IntParameter", "Scalar/Variables", "VisualShaderNodeIntParameter", TTR("Scalar integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6275. add_options.push_back(AddOption("UIntParameter", "Scalar/Variables", "VisualShaderNodeUIntParameter", TTR("Scalar unsigned integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6276. // SDF
  6277. {
  6278. add_options.push_back(AddOption("ScreenUVToSDF", "SDF", "VisualShaderNodeScreenUVToSDF", TTR("Converts screen UV to a SDF."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6279. add_options.push_back(AddOption("SDFRaymarch", "SDF", "VisualShaderNodeSDFRaymarch", TTR("Casts a ray against the screen SDF and returns the distance travelled."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6280. add_options.push_back(AddOption("SDFToScreenUV", "SDF", "VisualShaderNodeSDFToScreenUV", TTR("Converts a SDF to screen UV."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6281. add_options.push_back(AddOption("TextureSDF", "SDF", "VisualShaderNodeTextureSDF", TTR("Performs a SDF texture lookup."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6282. add_options.push_back(AddOption("TextureSDFNormal", "SDF", "VisualShaderNodeTextureSDFNormal", TTR("Performs a SDF normal texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6283. }
  6284. // TEXTURES
  6285. add_options.push_back(AddOption("UVFunc", "Textures/Common", "VisualShaderNodeUVFunc", TTR("Function to be applied on texture coordinates."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6286. add_options.push_back(AddOption("UVPolarCoord", "Textures/Common", "VisualShaderNodeUVPolarCoord", TTR("Polar coordinates conversion applied on texture coordinates."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6287. cubemap_node_option_idx = add_options.size();
  6288. add_options.push_back(AddOption("CubeMap", "Textures/Functions", "VisualShaderNodeCubemap", TTR("Perform the cubic texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6289. curve_node_option_idx = add_options.size();
  6290. add_options.push_back(AddOption("CurveTexture", "Textures/Functions", "VisualShaderNodeCurveTexture", TTR("Perform the curve texture lookup."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6291. curve_xyz_node_option_idx = add_options.size();
  6292. add_options.push_back(AddOption("CurveXYZTexture", "Textures/Functions", "VisualShaderNodeCurveXYZTexture", TTR("Perform the three components curve texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6293. add_options.push_back(AddOption("LinearSceneDepth", "Textures/Functions", "VisualShaderNodeLinearSceneDepth", TTR("Returns the depth value obtained from the depth prepass in a linear space."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6294. texture2d_node_option_idx = add_options.size();
  6295. add_options.push_back(AddOption("WorldPositionFromDepth", "Textures/Functions", "VisualShaderNodeWorldPositionFromDepth", TTR("Reconstructs the World Position of the Node from the depth texture."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6296. texture2d_node_option_idx = add_options.size();
  6297. add_options.push_back(AddOption("ScreenNormalWorldSpace", "Textures/Functions", "VisualShaderNodeScreenNormalWorldSpace", TTR("Unpacks the Screen Normal Texture in World Space"), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6298. texture2d_node_option_idx = add_options.size();
  6299. add_options.push_back(AddOption("Texture2D", "Textures/Functions", "VisualShaderNodeTexture", TTR("Perform the 2D texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6300. texture2d_array_node_option_idx = add_options.size();
  6301. add_options.push_back(AddOption("Texture2DArray", "Textures/Functions", "VisualShaderNodeTexture2DArray", TTR("Perform the 2D-array texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6302. texture3d_node_option_idx = add_options.size();
  6303. add_options.push_back(AddOption("Texture3D", "Textures/Functions", "VisualShaderNodeTexture3D", TTR("Perform the 3D texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6304. add_options.push_back(AddOption("UVPanning", "Textures/Functions", "VisualShaderNodeUVFunc", TTR("Apply panning function on texture coordinates."), { VisualShaderNodeUVFunc::FUNC_PANNING }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6305. add_options.push_back(AddOption("UVScaling", "Textures/Functions", "VisualShaderNodeUVFunc", TTR("Apply scaling function on texture coordinates."), { VisualShaderNodeUVFunc::FUNC_SCALING }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6306. add_options.push_back(AddOption("CubeMapParameter", "Textures/Variables", "VisualShaderNodeCubemapParameter", TTR("Cubic texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6307. add_options.push_back(AddOption("Texture2DParameter", "Textures/Variables", "VisualShaderNodeTexture2DParameter", TTR("2D texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6308. add_options.push_back(AddOption("TextureParameterTriplanar", "Textures/Variables", "VisualShaderNodeTextureParameterTriplanar", TTR("2D texture parameter lookup with triplanar."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6309. add_options.push_back(AddOption("Texture2DArrayParameter", "Textures/Variables", "VisualShaderNodeTexture2DArrayParameter", TTR("2D array of textures parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6310. add_options.push_back(AddOption("Texture3DParameter", "Textures/Variables", "VisualShaderNodeTexture3DParameter", TTR("3D texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6311. // TRANSFORM
  6312. add_options.push_back(AddOption("TransformFunc", "Transform/Common", "VisualShaderNodeTransformFunc", TTR("Transform function."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6313. add_options.push_back(AddOption("TransformOp", "Transform/Common", "VisualShaderNodeTransformOp", TTR("Transform operator."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6314. 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'."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6315. add_options.push_back(AddOption("TransformCompose", "Transform/Composition", "VisualShaderNodeTransformCompose", TTR("Composes transform from four vectors."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6316. add_options.push_back(AddOption("TransformDecompose", "Transform/Composition", "VisualShaderNodeTransformDecompose", TTR("Decomposes transform to four vectors.")));
  6317. add_options.push_back(AddOption("Determinant", "Transform/Functions", "VisualShaderNodeDeterminant", TTR("Calculates the determinant of a transform."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6318. add_options.push_back(AddOption("GetBillboardMatrix", "Transform/Functions", "VisualShaderNodeBillboard", TTR("Calculates how the object should face the camera to be applied on Model View Matrix output port for 3D objects."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
  6319. add_options.push_back(AddOption("Inverse", "Transform/Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the inverse of a transform."), { VisualShaderNodeTransformFunc::FUNC_INVERSE }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6320. add_options.push_back(AddOption("Transpose", "Transform/Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the transpose of a transform."), { VisualShaderNodeTransformFunc::FUNC_TRANSPOSE }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6321. add_options.push_back(AddOption("Add (+)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Sums two transforms."), { VisualShaderNodeTransformOp::OP_ADD }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6322. add_options.push_back(AddOption("Divide (/)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Divides two transforms."), { VisualShaderNodeTransformOp::OP_A_DIV_B }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6323. add_options.push_back(AddOption("Multiply (*)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Multiplies two transforms."), { VisualShaderNodeTransformOp::OP_AxB }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6324. add_options.push_back(AddOption("MultiplyComp (*)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Performs per-component multiplication of two transforms."), { VisualShaderNodeTransformOp::OP_AxB_COMP }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6325. add_options.push_back(AddOption("Subtract (-)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Subtracts two transforms."), { VisualShaderNodeTransformOp::OP_A_MINUS_B }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6326. add_options.push_back(AddOption("TransformVectorMult (*)", "Transform/Operators", "VisualShaderNodeTransformVecMult", TTR("Multiplies vector by transform."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6327. add_options.push_back(AddOption("TransformConstant", "Transform/Variables", "VisualShaderNodeTransformConstant", TTR("Transform constant."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6328. add_options.push_back(AddOption("TransformParameter", "Transform/Variables", "VisualShaderNodeTransformParameter", TTR("Transform parameter."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6329. // UTILITY
  6330. add_options.push_back(AddOption("DistanceFade", "Utility", "VisualShaderNodeDistanceFade", TTR("The distance fade effect fades out each pixel based on its distance to another object."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6331. add_options.push_back(AddOption("ProximityFade", "Utility", "VisualShaderNodeProximityFade", TTR("The proximity fade effect fades out each pixel based on its distance to another object."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6332. add_options.push_back(AddOption("RandomRange", "Utility", "VisualShaderNodeRandomRange", TTR("Returns a random value between the minimum and maximum input values."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6333. add_options.push_back(AddOption("RotationByAxis", "Utility", "VisualShaderNodeRotationByAxis", TTR("Builds a rotation matrix from the given axis and angle, multiply the input vector by it and returns both this vector and a matrix."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6334. // VECTOR
  6335. add_options.push_back(AddOption("VectorFunc", "Vector/Common", "VisualShaderNodeVectorFunc", TTR("Vector function."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6336. add_options.push_back(AddOption("VectorOp", "Vector/Common", "VisualShaderNodeVectorOp", TTR("Vector operator."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6337. add_options.push_back(AddOption("VectorCompose", "Vector/Common", "VisualShaderNodeVectorCompose", TTR("Composes vector from scalars.")));
  6338. add_options.push_back(AddOption("VectorDecompose", "Vector/Common", "VisualShaderNodeVectorDecompose", TTR("Decomposes vector to scalars.")));
  6339. add_options.push_back(AddOption("Vector2Compose", "Vector/Composition", "VisualShaderNodeVectorCompose", TTR("Composes 2D vector from two scalars."), { VisualShaderNodeVectorCompose::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6340. add_options.push_back(AddOption("Vector2Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 2D vector to two scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_2D }));
  6341. add_options.push_back(AddOption("Vector3Compose", "Vector/Composition", "VisualShaderNodeVectorCompose", TTR("Composes 3D vector from three scalars."), { VisualShaderNodeVectorCompose::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6342. add_options.push_back(AddOption("Vector3Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 3D vector to three scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_3D }));
  6343. add_options.push_back(AddOption("Vector4Compose", "Vector/Composition", "VisualShaderNodeVectorCompose", TTR("Composes 4D vector from four scalars."), { VisualShaderNodeVectorCompose::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6344. add_options.push_back(AddOption("Vector4Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 4D vector to four scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_4D }));
  6345. add_options.push_back(AddOption("Abs", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ABS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6346. add_options.push_back(AddOption("Abs", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ABS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6347. add_options.push_back(AddOption("Abs", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ABS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6348. add_options.push_back(AddOption("ACos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6349. add_options.push_back(AddOption("ACos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6350. add_options.push_back(AddOption("ACos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6351. add_options.push_back(AddOption("ACosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6352. add_options.push_back(AddOption("ACosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6353. add_options.push_back(AddOption("ACosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6354. add_options.push_back(AddOption("ASin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6355. add_options.push_back(AddOption("ASin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6356. add_options.push_back(AddOption("ASin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6357. add_options.push_back(AddOption("ASinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6358. add_options.push_back(AddOption("ASinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6359. add_options.push_back(AddOption("ASinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6360. add_options.push_back(AddOption("ATan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6361. add_options.push_back(AddOption("ATan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6362. add_options.push_back(AddOption("ATan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6363. add_options.push_back(AddOption("ATan2", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeVectorOp::OP_ATAN2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6364. add_options.push_back(AddOption("ATan2", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeVectorOp::OP_ATAN2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6365. add_options.push_back(AddOption("ATan2", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeVectorOp::OP_ATAN2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6366. add_options.push_back(AddOption("ATanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6367. add_options.push_back(AddOption("ATanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6368. add_options.push_back(AddOption("ATanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6369. 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, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6370. 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, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6371. 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, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6372. add_options.push_back(AddOption("Clamp", "Vector/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6373. add_options.push_back(AddOption("Clamp", "Vector/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6374. add_options.push_back(AddOption("Clamp", "Vector/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6375. add_options.push_back(AddOption("Cos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6376. add_options.push_back(AddOption("Cos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6377. add_options.push_back(AddOption("Cos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6378. add_options.push_back(AddOption("CosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6379. add_options.push_back(AddOption("CosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6380. add_options.push_back(AddOption("CosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6381. add_options.push_back(AddOption("Cross", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Calculates the cross product of two vectors."), { VisualShaderNodeVectorOp::OP_CROSS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6382. add_options.push_back(AddOption("Degrees", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeVectorFunc::FUNC_DEGREES, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6383. add_options.push_back(AddOption("Degrees", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeVectorFunc::FUNC_DEGREES, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6384. add_options.push_back(AddOption("Degrees", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeVectorFunc::FUNC_DEGREES, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6385. add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6386. add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6387. add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6388. add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6389. add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6390. add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6391. add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6392. add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6393. add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6394. add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6395. add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6396. add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6397. add_options.push_back(AddOption("Distance2D", "Vector/Functions", "VisualShaderNodeVectorDistance", TTR("Returns the distance between two points."), { VisualShaderNodeVectorDistance::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_SCALAR));
  6398. add_options.push_back(AddOption("Distance3D", "Vector/Functions", "VisualShaderNodeVectorDistance", TTR("Returns the distance between two points."), { VisualShaderNodeVectorDistance::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_SCALAR));
  6399. add_options.push_back(AddOption("Distance4D", "Vector/Functions", "VisualShaderNodeVectorDistance", TTR("Returns the distance between two points."), { VisualShaderNodeVectorDistance::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_SCALAR));
  6400. add_options.push_back(AddOption("Dot", "Vector/Functions", "VisualShaderNodeDotProduct", TTR("Calculates the dot product of two vectors."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6401. add_options.push_back(AddOption("Exp", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-e Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6402. add_options.push_back(AddOption("Exp", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-e Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6403. add_options.push_back(AddOption("Exp", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-e Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6404. add_options.push_back(AddOption("Exp2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6405. add_options.push_back(AddOption("Exp2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6406. add_options.push_back(AddOption("Exp2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6407. 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."), { VisualShaderNodeFaceForward::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6408. 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."), { VisualShaderNodeFaceForward::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6409. 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."), { VisualShaderNodeFaceForward::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6410. add_options.push_back(AddOption("Floor", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer less than or equal to the parameter."), { VisualShaderNodeVectorFunc::FUNC_FLOOR, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6411. add_options.push_back(AddOption("Floor", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer less than or equal to the parameter."), { VisualShaderNodeVectorFunc::FUNC_FLOOR, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6412. add_options.push_back(AddOption("Floor", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer less than or equal to the parameter."), { VisualShaderNodeVectorFunc::FUNC_FLOOR, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6413. add_options.push_back(AddOption("Fract", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeVectorFunc::FUNC_FRACT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6414. add_options.push_back(AddOption("Fract", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeVectorFunc::FUNC_FRACT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6415. add_options.push_back(AddOption("Fract", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeVectorFunc::FUNC_FRACT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6416. add_options.push_back(AddOption("Fresnel", "Vector/Functions", "VisualShaderNodeFresnel", TTR("Returns falloff based on the dot product of surface normal and view direction of camera (pass associated inputs to it)."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6417. add_options.push_back(AddOption("InverseSqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse of the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_INVERSE_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6418. add_options.push_back(AddOption("InverseSqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse of the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_INVERSE_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6419. add_options.push_back(AddOption("InverseSqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse of the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_INVERSE_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6420. add_options.push_back(AddOption("Length2D", "Vector/Functions", "VisualShaderNodeVectorLen", TTR("Calculates the length of a vector."), { VisualShaderNodeVectorLen::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_SCALAR));
  6421. add_options.push_back(AddOption("Length3D", "Vector/Functions", "VisualShaderNodeVectorLen", TTR("Calculates the length of a vector."), { VisualShaderNodeVectorLen::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_SCALAR));
  6422. add_options.push_back(AddOption("Length4D", "Vector/Functions", "VisualShaderNodeVectorLen", TTR("Calculates the length of a vector."), { VisualShaderNodeVectorLen::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_SCALAR));
  6423. add_options.push_back(AddOption("Log", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Natural logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6424. add_options.push_back(AddOption("Log", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Natural logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6425. add_options.push_back(AddOption("Log", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Natural logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6426. add_options.push_back(AddOption("Log2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6427. add_options.push_back(AddOption("Log2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6428. add_options.push_back(AddOption("Log2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6429. add_options.push_back(AddOption("Max", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), { VisualShaderNodeVectorOp::OP_MAX, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6430. add_options.push_back(AddOption("Max", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), { VisualShaderNodeVectorOp::OP_MAX, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6431. add_options.push_back(AddOption("Max", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), { VisualShaderNodeVectorOp::OP_MAX, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6432. add_options.push_back(AddOption("Min", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), { VisualShaderNodeVectorOp::OP_MIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6433. add_options.push_back(AddOption("Min", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), { VisualShaderNodeVectorOp::OP_MIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6434. add_options.push_back(AddOption("Min", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), { VisualShaderNodeVectorOp::OP_MIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6435. add_options.push_back(AddOption("Mix", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors."), { VisualShaderNodeMix::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6436. add_options.push_back(AddOption("Mix", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors."), { VisualShaderNodeMix::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6437. add_options.push_back(AddOption("Mix", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors."), { VisualShaderNodeMix::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6438. add_options.push_back(AddOption("MixS", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors using scalar."), { VisualShaderNodeMix::OP_TYPE_VECTOR_2D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6439. add_options.push_back(AddOption("MixS", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors using scalar."), { VisualShaderNodeMix::OP_TYPE_VECTOR_3D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6440. add_options.push_back(AddOption("MixS", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors using scalar."), { VisualShaderNodeMix::OP_TYPE_VECTOR_4D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6441. add_options.push_back(AddOption("MultiplyAdd (a * b + c)", "Vector/Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on vectors."), { VisualShaderNodeMultiplyAdd::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6442. add_options.push_back(AddOption("MultiplyAdd (a * b + c)", "Vector/Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on vectors."), { VisualShaderNodeMultiplyAdd::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6443. add_options.push_back(AddOption("MultiplyAdd (a * b + c)", "Vector/Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on vectors."), { VisualShaderNodeMultiplyAdd::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6444. add_options.push_back(AddOption("Negate (*-1)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6445. add_options.push_back(AddOption("Negate (*-1)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6446. add_options.push_back(AddOption("Negate (*-1)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6447. add_options.push_back(AddOption("Normalize", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), { VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6448. add_options.push_back(AddOption("Normalize", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), { VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6449. add_options.push_back(AddOption("Normalize", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), { VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6450. add_options.push_back(AddOption("OneMinus (1-)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 - vector"), { VisualShaderNodeVectorFunc::FUNC_ONEMINUS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6451. add_options.push_back(AddOption("OneMinus (1-)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 - vector"), { VisualShaderNodeVectorFunc::FUNC_ONEMINUS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6452. add_options.push_back(AddOption("OneMinus (1-)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 - vector"), { VisualShaderNodeVectorFunc::FUNC_ONEMINUS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6453. 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, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6454. 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, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6455. 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, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6456. add_options.push_back(AddOption("Radians", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeVectorFunc::FUNC_RADIANS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6457. add_options.push_back(AddOption("Radians", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeVectorFunc::FUNC_RADIANS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6458. add_options.push_back(AddOption("Radians", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeVectorFunc::FUNC_RADIANS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6459. add_options.push_back(AddOption("Reciprocal", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 / vector"), { VisualShaderNodeVectorFunc::FUNC_RECIPROCAL, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6460. add_options.push_back(AddOption("Reciprocal", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 / vector"), { VisualShaderNodeVectorFunc::FUNC_RECIPROCAL, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6461. add_options.push_back(AddOption("Reciprocal", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 / vector"), { VisualShaderNodeVectorFunc::FUNC_RECIPROCAL, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6462. 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, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6463. 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, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6464. 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, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6465. add_options.push_back(AddOption("Refract", "Vector/Functions", "VisualShaderNodeVectorRefract", TTR("Returns the vector that points in the direction of refraction."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6466. add_options.push_back(AddOption("Refract", "Vector/Functions", "VisualShaderNodeVectorRefract", TTR("Returns the vector that points in the direction of refraction."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6467. add_options.push_back(AddOption("Refract", "Vector/Functions", "VisualShaderNodeVectorRefract", TTR("Returns the vector that points in the direction of refraction."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6468. add_options.push_back(AddOption("Remap", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6469. add_options.push_back(AddOption("Remap", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6470. add_options.push_back(AddOption("Remap", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6471. add_options.push_back(AddOption("RemapS", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range. Ranges defined with scalars."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_2D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6472. add_options.push_back(AddOption("RemapS", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range. Ranges defined with scalars."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_3D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6473. add_options.push_back(AddOption("RemapS", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range. Ranges defined with scalars."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_4D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6474. add_options.push_back(AddOption("Round", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUND, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6475. add_options.push_back(AddOption("Round", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUND, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6476. add_options.push_back(AddOption("Round", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUND, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6477. add_options.push_back(AddOption("RoundEven", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest even integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUNDEVEN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6478. add_options.push_back(AddOption("RoundEven", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest even integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUNDEVEN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6479. add_options.push_back(AddOption("RoundEven", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest even integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUNDEVEN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6480. add_options.push_back(AddOption("Saturate", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Clamps the value between 0.0 and 1.0."), { VisualShaderNodeVectorFunc::FUNC_SATURATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6481. add_options.push_back(AddOption("Saturate", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Clamps the value between 0.0 and 1.0."), { VisualShaderNodeVectorFunc::FUNC_SATURATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6482. add_options.push_back(AddOption("Saturate", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Clamps the value between 0.0 and 1.0."), { VisualShaderNodeVectorFunc::FUNC_SATURATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6483. add_options.push_back(AddOption("Sign", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIGN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6484. add_options.push_back(AddOption("Sign", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIGN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6485. add_options.push_back(AddOption("Sign", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIGN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6486. add_options.push_back(AddOption("Sin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6487. add_options.push_back(AddOption("Sin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6488. add_options.push_back(AddOption("Sin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6489. add_options.push_back(AddOption("SinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6490. add_options.push_back(AddOption("SinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6491. add_options.push_back(AddOption("SinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6492. add_options.push_back(AddOption("Sqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6493. add_options.push_back(AddOption("Sqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6494. add_options.push_back(AddOption("Sqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6495. add_options.push_back(AddOption("SmoothStep", "Vector/Functions", "VisualShaderNodeSmoothStep", 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."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6496. add_options.push_back(AddOption("SmoothStep", "Vector/Functions", "VisualShaderNodeSmoothStep", 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."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6497. add_options.push_back(AddOption("SmoothStep", "Vector/Functions", "VisualShaderNodeSmoothStep", 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."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6498. add_options.push_back(AddOption("SmoothStepS", "Vector/Functions", "VisualShaderNodeSmoothStep", 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."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_2D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6499. add_options.push_back(AddOption("SmoothStepS", "Vector/Functions", "VisualShaderNodeSmoothStep", 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."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_3D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6500. add_options.push_back(AddOption("SmoothStepS", "Vector/Functions", "VisualShaderNodeSmoothStep", 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."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_4D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6501. add_options.push_back(AddOption("Step", "Vector/Functions", "VisualShaderNodeStep", TTR("Step function( vector(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6502. add_options.push_back(AddOption("Step", "Vector/Functions", "VisualShaderNodeStep", TTR("Step function( vector(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6503. add_options.push_back(AddOption("StepS", "Vector/Functions", "VisualShaderNodeStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_VECTOR_2D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6504. add_options.push_back(AddOption("StepS", "Vector/Functions", "VisualShaderNodeStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_VECTOR_3D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6505. add_options.push_back(AddOption("StepS", "Vector/Functions", "VisualShaderNodeStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_VECTOR_4D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6506. add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6507. add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6508. add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true));
  6509. add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6510. add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6511. add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  6512. add_options.push_back(AddOption("Tan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6513. add_options.push_back(AddOption("Tan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6514. add_options.push_back(AddOption("Tan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6515. add_options.push_back(AddOption("TanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6516. add_options.push_back(AddOption("TanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6517. add_options.push_back(AddOption("TanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6518. add_options.push_back(AddOption("Trunc", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6519. add_options.push_back(AddOption("Trunc", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6520. add_options.push_back(AddOption("Trunc", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6521. add_options.push_back(AddOption("Add (+)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Adds 2D vector to 2D vector."), { VisualShaderNodeVectorOp::OP_ADD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6522. add_options.push_back(AddOption("Add (+)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Adds 3D vector to 3D vector."), { VisualShaderNodeVectorOp::OP_ADD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6523. add_options.push_back(AddOption("Add (+)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Adds 4D vector to 4D vector."), { VisualShaderNodeVectorOp::OP_ADD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6524. add_options.push_back(AddOption("Divide (/)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Divides 2D vector by 2D vector."), { VisualShaderNodeVectorOp::OP_DIV, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6525. add_options.push_back(AddOption("Divide (/)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Divides 3D vector by 3D vector."), { VisualShaderNodeVectorOp::OP_DIV, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6526. add_options.push_back(AddOption("Divide (/)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Divides 4D vector by 4D vector."), { VisualShaderNodeVectorOp::OP_DIV, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6527. add_options.push_back(AddOption("Multiply (*)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Multiplies 2D vector by 2D vector."), { VisualShaderNodeVectorOp::OP_MUL, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6528. add_options.push_back(AddOption("Multiply (*)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Multiplies 3D vector by 3D vector."), { VisualShaderNodeVectorOp::OP_MUL, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6529. add_options.push_back(AddOption("Multiply (*)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Multiplies 4D vector by 4D vector."), { VisualShaderNodeVectorOp::OP_MUL, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6530. add_options.push_back(AddOption("Remainder (%)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Returns the remainder of the two 2D vectors."), { VisualShaderNodeVectorOp::OP_MOD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6531. add_options.push_back(AddOption("Remainder (%)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Returns the remainder of the two 3D vectors."), { VisualShaderNodeVectorOp::OP_MOD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6532. add_options.push_back(AddOption("Remainder (%)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Returns the remainder of the two 4D vectors."), { VisualShaderNodeVectorOp::OP_MOD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6533. add_options.push_back(AddOption("Subtract (-)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Subtracts 2D vector from 2D vector."), { VisualShaderNodeVectorOp::OP_SUB, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6534. add_options.push_back(AddOption("Subtract (-)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Subtracts 3D vector from 3D vector."), { VisualShaderNodeVectorOp::OP_SUB, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6535. add_options.push_back(AddOption("Subtract (-)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Subtracts 4D vector from 4D vector."), { VisualShaderNodeVectorOp::OP_SUB, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6536. add_options.push_back(AddOption("Vector2Constant", "Vector/Variables", "VisualShaderNodeVec2Constant", TTR("2D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6537. add_options.push_back(AddOption("Vector2Parameter", "Vector/Variables", "VisualShaderNodeVec2Parameter", TTR("2D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6538. add_options.push_back(AddOption("Vector3Constant", "Vector/Variables", "VisualShaderNodeVec3Constant", TTR("3D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6539. add_options.push_back(AddOption("Vector3Parameter", "Vector/Variables", "VisualShaderNodeVec3Parameter", TTR("3D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6540. add_options.push_back(AddOption("Vector4Constant", "Vector/Variables", "VisualShaderNodeVec4Constant", TTR("4D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6541. add_options.push_back(AddOption("Vector4Parameter", "Vector/Variables", "VisualShaderNodeVec4Parameter", TTR("4D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6542. // SPECIAL
  6543. add_options.push_back(AddOption("Frame", "Special", "VisualShaderNodeFrame", TTR("A rectangular area with a description string for better graph organization.")));
  6544. 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.")));
  6545. 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, parameters and constants.")));
  6546. add_options.push_back(AddOption("ParameterRef", "Special", "VisualShaderNodeParameterRef", TTR("A reference to an existing parameter.")));
  6547. add_options.push_back(AddOption("VaryingGetter", "Special", "VisualShaderNodeVaryingGetter", TTR("Get varying parameter."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6548. add_options.push_back(AddOption("VaryingSetter", "Special", "VisualShaderNodeVaryingSetter", TTR("Set varying parameter."), {}, -1, TYPE_FLAGS_VERTEX | TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6549. add_options.push_back(AddOption("VaryingGetter", "Special", "VisualShaderNodeVaryingGetter", TTR("Get varying parameter."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6550. add_options.push_back(AddOption("VaryingSetter", "Special", "VisualShaderNodeVaryingSetter", TTR("Set varying parameter."), {}, -1, TYPE_FLAGS_VERTEX | TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6551. add_options.push_back(AddOption("Reroute", "Special", "VisualShaderNodeReroute", TTR("Reroute connections freely, can be used to connect multiple input ports to single output port.")));
  6552. custom_node_option_idx = add_options.size();
  6553. /////////////////////////////////////////////////////////////////////
  6554. Ref<VisualShaderNodePluginDefault> default_plugin;
  6555. default_plugin.instantiate();
  6556. default_plugin->set_editor(this);
  6557. add_plugin(default_plugin);
  6558. graph_plugin.instantiate();
  6559. graph_plugin->set_editor(this);
  6560. property_editor_popup = memnew(PopupPanel);
  6561. property_editor_popup->set_min_size(Size2(360, 0) * EDSCALE);
  6562. add_child(property_editor_popup);
  6563. edited_property_holder.instantiate();
  6564. panning_debounce_timer = memnew(Timer);
  6565. panning_debounce_timer->set_one_shot(true);
  6566. panning_debounce_timer->set_wait_time(1.0);
  6567. panning_debounce_timer->connect("timeout", callable_mp(this, &VisualShaderEditor::save_editor_layout));
  6568. add_child(panning_debounce_timer);
  6569. }
  6570. VisualShaderEditor::~VisualShaderEditor() {
  6571. save_editor_layout();
  6572. }
  6573. class VisualShaderNodePluginInputEditor : public OptionButton {
  6574. GDCLASS(VisualShaderNodePluginInputEditor, OptionButton);
  6575. VisualShaderEditor *editor = nullptr;
  6576. Ref<VisualShaderNodeInput> input;
  6577. public:
  6578. void _notification(int p_what) {
  6579. switch (p_what) {
  6580. case NOTIFICATION_READY: {
  6581. connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginInputEditor::_item_selected));
  6582. } break;
  6583. }
  6584. }
  6585. void _item_selected(int p_item) {
  6586. editor->call_deferred(SNAME("_input_select_item"), input, get_item_metadata(p_item));
  6587. }
  6588. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeInput> &p_input) {
  6589. set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  6590. editor = p_editor;
  6591. input = p_input;
  6592. Ref<Texture2D> type_icon[] = {
  6593. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)),
  6594. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)),
  6595. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)),
  6596. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)),
  6597. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)),
  6598. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)),
  6599. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)),
  6600. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)),
  6601. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ImageTexture"), EditorStringName(EditorIcons)),
  6602. };
  6603. add_item(TTR("[None]"));
  6604. set_item_metadata(-1, "[None]");
  6605. int to_select = -1;
  6606. for (int i = 0; i < input->get_input_index_count(); i++) {
  6607. if (input->get_input_name() == input->get_input_index_name(i)) {
  6608. to_select = i + 1;
  6609. }
  6610. add_icon_item(type_icon[input->get_input_index_type(i)], input->get_input_index_name(i));
  6611. set_item_metadata(-1, input->get_input_index_name(i));
  6612. }
  6613. if (to_select >= 0) {
  6614. select(to_select);
  6615. }
  6616. }
  6617. };
  6618. ////////////////
  6619. class VisualShaderNodePluginVaryingEditor : public OptionButton {
  6620. GDCLASS(VisualShaderNodePluginVaryingEditor, OptionButton);
  6621. VisualShaderEditor *editor = nullptr;
  6622. Ref<VisualShaderNodeVarying> varying;
  6623. public:
  6624. void _notification(int p_what) {
  6625. if (p_what == NOTIFICATION_READY) {
  6626. connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginVaryingEditor::_item_selected));
  6627. }
  6628. }
  6629. void _item_selected(int p_item) {
  6630. editor->call_deferred(SNAME("_varying_select_item"), varying, get_item_metadata(p_item));
  6631. }
  6632. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeVarying> &p_varying, VisualShader::Type p_type) {
  6633. set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  6634. editor = p_editor;
  6635. varying = p_varying;
  6636. Ref<Texture2D> type_icon[] = {
  6637. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)),
  6638. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)),
  6639. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)),
  6640. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)),
  6641. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)),
  6642. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)),
  6643. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)),
  6644. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)),
  6645. };
  6646. bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid();
  6647. add_item(TTR("[None]"));
  6648. set_item_metadata(-1, "[None]");
  6649. int to_select = -1;
  6650. for (int i = 0, j = 0; i < varying->get_varyings_count(); i++) {
  6651. VisualShader::VaryingMode mode = varying->get_varying_mode_by_index(i);
  6652. if (is_getter) {
  6653. if (mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT) {
  6654. if (p_type != VisualShader::TYPE_LIGHT) {
  6655. j++;
  6656. continue;
  6657. }
  6658. } else {
  6659. if (p_type != VisualShader::TYPE_FRAGMENT && p_type != VisualShader::TYPE_LIGHT) {
  6660. j++;
  6661. continue;
  6662. }
  6663. }
  6664. } else {
  6665. if (mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT) {
  6666. if (p_type != VisualShader::TYPE_FRAGMENT) {
  6667. j++;
  6668. continue;
  6669. }
  6670. } else {
  6671. if (p_type != VisualShader::TYPE_VERTEX) {
  6672. j++;
  6673. continue;
  6674. }
  6675. }
  6676. }
  6677. if (varying->get_varying_name() == varying->get_varying_name_by_index(i)) {
  6678. to_select = i - j + 1;
  6679. }
  6680. add_icon_item(type_icon[varying->get_varying_type_by_index(i)], varying->get_varying_name_by_index(i));
  6681. set_item_metadata(-1, varying->get_varying_name_by_index(i));
  6682. }
  6683. if (to_select >= 0) {
  6684. select(to_select);
  6685. }
  6686. }
  6687. };
  6688. ////////////////
  6689. class VisualShaderNodePluginParameterRefEditor : public OptionButton {
  6690. GDCLASS(VisualShaderNodePluginParameterRefEditor, OptionButton);
  6691. VisualShaderEditor *editor = nullptr;
  6692. Ref<VisualShaderNodeParameterRef> parameter_ref;
  6693. public:
  6694. void _notification(int p_what) {
  6695. switch (p_what) {
  6696. case NOTIFICATION_READY: {
  6697. connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginParameterRefEditor::_item_selected));
  6698. } break;
  6699. }
  6700. }
  6701. void _item_selected(int p_item) {
  6702. editor->call_deferred(SNAME("_parameter_ref_select_item"), parameter_ref, get_item_metadata(p_item));
  6703. }
  6704. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeParameterRef> &p_parameter_ref) {
  6705. set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  6706. editor = p_editor;
  6707. parameter_ref = p_parameter_ref;
  6708. Ref<Texture2D> type_icon[] = {
  6709. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)),
  6710. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)),
  6711. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)),
  6712. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)),
  6713. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)),
  6714. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)),
  6715. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)),
  6716. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)),
  6717. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Color"), EditorStringName(EditorIcons)),
  6718. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ImageTexture"), EditorStringName(EditorIcons)),
  6719. };
  6720. add_item(TTR("[None]"));
  6721. set_item_metadata(-1, "[None]");
  6722. int to_select = -1;
  6723. for (int i = 0; i < p_parameter_ref->get_parameters_count(); i++) {
  6724. if (p_parameter_ref->get_parameter_name() == p_parameter_ref->get_parameter_name_by_index(i)) {
  6725. to_select = i + 1;
  6726. }
  6727. add_icon_item(type_icon[p_parameter_ref->get_parameter_type_by_index(i)], p_parameter_ref->get_parameter_name_by_index(i));
  6728. set_item_metadata(-1, p_parameter_ref->get_parameter_name_by_index(i));
  6729. }
  6730. if (to_select >= 0) {
  6731. select(to_select);
  6732. }
  6733. }
  6734. };
  6735. ////////////////
  6736. class VisualShaderNodePluginDefaultEditor : public VBoxContainer {
  6737. GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer);
  6738. VisualShaderEditor *editor = nullptr;
  6739. Ref<Resource> parent_resource;
  6740. int node_id = 0;
  6741. VisualShader::Type shader_type;
  6742. public:
  6743. void _property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false) {
  6744. if (p_changing) {
  6745. return;
  6746. }
  6747. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  6748. updating = true;
  6749. undo_redo->create_action(vformat(TTR("Edit Visual Property: %s"), p_property), UndoRedo::MERGE_ENDS);
  6750. undo_redo->add_do_property(node.ptr(), p_property, p_value);
  6751. undo_redo->add_undo_property(node.ptr(), p_property, node->get(p_property));
  6752. Ref<VisualShaderNode> vsnode = editor->get_visual_shader()->get_node(shader_type, node_id);
  6753. ERR_FAIL_COND(vsnode.is_null());
  6754. // Check for invalid connections due to removed ports.
  6755. // We need to know the new state of the node to generate the proper undo/redo instructions.
  6756. // Quite hacky but the best way I could come up with for now.
  6757. Ref<VisualShaderNode> vsnode_new = vsnode->duplicate();
  6758. vsnode_new->set(p_property, p_value);
  6759. const int input_port_count = vsnode_new->get_input_port_count();
  6760. const int output_port_count = vsnode_new->get_expanded_output_port_count();
  6761. List<VisualShader::Connection> conns;
  6762. editor->get_visual_shader()->get_node_connections(shader_type, &conns);
  6763. VisualShaderGraphPlugin *graph_plugin = editor->get_graph_plugin();
  6764. bool undo_node_already_updated = false;
  6765. for (const VisualShader::Connection &c : conns) {
  6766. if ((c.from_node == node_id && c.from_port >= output_port_count) || (c.to_node == node_id && c.to_port >= input_port_count)) {
  6767. undo_redo->add_do_method(editor->get_visual_shader().ptr(), "disconnect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port);
  6768. undo_redo->add_do_method(graph_plugin, "disconnect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port);
  6769. // We need to update the node before reconnecting to avoid accessing a non-existing port.
  6770. undo_redo->add_undo_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  6771. undo_node_already_updated = true;
  6772. undo_redo->add_undo_method(editor->get_visual_shader().ptr(), "connect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port);
  6773. undo_redo->add_undo_method(graph_plugin, "connect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port);
  6774. }
  6775. }
  6776. if (p_value.get_type() == Variant::OBJECT) {
  6777. Ref<Resource> prev_res = vsnode->get(p_property);
  6778. Ref<Resource> curr_res = p_value;
  6779. if (curr_res.is_null()) {
  6780. undo_redo->add_do_method(this, "_open_inspector", (Ref<Resource>)parent_resource.ptr());
  6781. } else {
  6782. undo_redo->add_do_method(this, "_open_inspector", (Ref<Resource>)curr_res.ptr());
  6783. }
  6784. if (prev_res.is_valid()) {
  6785. undo_redo->add_undo_method(this, "_open_inspector", (Ref<Resource>)prev_res.ptr());
  6786. } else {
  6787. undo_redo->add_undo_method(this, "_open_inspector", (Ref<Resource>)parent_resource.ptr());
  6788. }
  6789. }
  6790. if (p_property != "constant") {
  6791. if (graph_plugin) {
  6792. undo_redo->add_do_method(editor, "_update_next_previews", node_id);
  6793. undo_redo->add_undo_method(editor, "_update_next_previews", node_id);
  6794. undo_redo->add_do_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  6795. if (!undo_node_already_updated) {
  6796. undo_redo->add_undo_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  6797. }
  6798. }
  6799. }
  6800. undo_redo->commit_action();
  6801. updating = false;
  6802. }
  6803. void _node_changed() {
  6804. if (updating) {
  6805. return;
  6806. }
  6807. for (int i = 0; i < properties.size(); i++) {
  6808. properties[i]->update_property();
  6809. }
  6810. }
  6811. void _resource_selected(const String &p_path, Ref<Resource> p_resource) {
  6812. _open_inspector(p_resource);
  6813. }
  6814. void _open_inspector(Ref<Resource> p_resource) {
  6815. InspectorDock::get_inspector_singleton()->edit(p_resource.ptr());
  6816. }
  6817. bool updating = false;
  6818. Ref<VisualShaderNode> node;
  6819. Vector<EditorProperty *> properties;
  6820. Vector<Label *> prop_names;
  6821. void _show_prop_names(bool p_show) {
  6822. for (int i = 0; i < prop_names.size(); i++) {
  6823. prop_names[i]->set_visible(p_show);
  6824. }
  6825. }
  6826. void setup(VisualShaderEditor *p_editor, Ref<Resource> p_parent_resource, const Vector<EditorProperty *> &p_properties, const Vector<StringName> &p_names, const HashMap<StringName, String> &p_overrided_names, Ref<VisualShaderNode> p_node) {
  6827. editor = p_editor;
  6828. parent_resource = p_parent_resource;
  6829. updating = false;
  6830. node = p_node;
  6831. properties = p_properties;
  6832. node_id = (int)p_node->get_meta("id");
  6833. shader_type = VisualShader::Type((int)p_node->get_meta("shader_type"));
  6834. for (int i = 0; i < p_properties.size(); i++) {
  6835. HBoxContainer *hbox = memnew(HBoxContainer);
  6836. hbox->set_h_size_flags(SIZE_EXPAND_FILL);
  6837. add_child(hbox);
  6838. Label *prop_name = memnew(Label);
  6839. prop_name->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  6840. String prop_name_str = p_names[i];
  6841. if (p_overrided_names.has(p_names[i])) {
  6842. prop_name_str = p_overrided_names[p_names[i]] + ":";
  6843. } else {
  6844. prop_name_str = prop_name_str.capitalize() + ":";
  6845. }
  6846. prop_name->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  6847. prop_name->set_text(prop_name_str);
  6848. prop_name->set_visible(false);
  6849. hbox->add_child(prop_name);
  6850. prop_names.push_back(prop_name);
  6851. p_properties[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  6852. hbox->add_child(p_properties[i]);
  6853. bool res_prop = Object::cast_to<EditorPropertyResource>(p_properties[i]);
  6854. if (res_prop) {
  6855. p_properties[i]->connect("resource_selected", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_resource_selected));
  6856. }
  6857. properties[i]->connect("property_changed", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_property_changed));
  6858. properties[i]->set_object_and_property(node.ptr(), p_names[i]);
  6859. properties[i]->update_property();
  6860. properties[i]->set_name_split_ratio(0);
  6861. }
  6862. node->connect_changed(callable_mp(this, &VisualShaderNodePluginDefaultEditor::_node_changed));
  6863. }
  6864. static void _bind_methods() {
  6865. ClassDB::bind_method("_open_inspector", &VisualShaderNodePluginDefaultEditor::_open_inspector); // Used by UndoRedo.
  6866. ClassDB::bind_method("_show_prop_names", &VisualShaderNodePluginDefaultEditor::_show_prop_names); // Used with call_deferred.
  6867. }
  6868. };
  6869. Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) {
  6870. Ref<VisualShader> p_shader = Ref<VisualShader>(p_parent_resource.ptr());
  6871. if (p_shader.is_valid() && (p_node->is_class("VisualShaderNodeVaryingGetter") || p_node->is_class("VisualShaderNodeVaryingSetter"))) {
  6872. VisualShaderNodePluginVaryingEditor *editor = memnew(VisualShaderNodePluginVaryingEditor);
  6873. editor->setup(vseditor, p_node, vseditor->get_current_shader_type());
  6874. return editor;
  6875. }
  6876. if (p_node->is_class("VisualShaderNodeParameterRef")) {
  6877. VisualShaderNodePluginParameterRefEditor *editor = memnew(VisualShaderNodePluginParameterRefEditor);
  6878. editor->setup(vseditor, p_node);
  6879. return editor;
  6880. }
  6881. if (p_node->is_class("VisualShaderNodeInput")) {
  6882. VisualShaderNodePluginInputEditor *editor = memnew(VisualShaderNodePluginInputEditor);
  6883. editor->setup(vseditor, p_node);
  6884. return editor;
  6885. }
  6886. Vector<StringName> properties = p_node->get_editable_properties();
  6887. if (properties.is_empty()) {
  6888. return nullptr;
  6889. }
  6890. List<PropertyInfo> props;
  6891. p_node->get_property_list(&props);
  6892. Vector<PropertyInfo> pinfo;
  6893. for (const PropertyInfo &E : props) {
  6894. for (int i = 0; i < properties.size(); i++) {
  6895. if (E.name == String(properties[i])) {
  6896. pinfo.push_back(E);
  6897. }
  6898. }
  6899. }
  6900. if (pinfo.is_empty()) {
  6901. return nullptr;
  6902. }
  6903. properties.clear();
  6904. Ref<VisualShaderNode> node = p_node;
  6905. Vector<EditorProperty *> editors;
  6906. for (int i = 0; i < pinfo.size(); i++) {
  6907. EditorProperty *prop = EditorInspector::instantiate_property_editor(node.ptr(), pinfo[i].type, pinfo[i].name, pinfo[i].hint, pinfo[i].hint_string, pinfo[i].usage);
  6908. if (!prop) {
  6909. return nullptr;
  6910. }
  6911. if (Object::cast_to<EditorPropertyResource>(prop)) {
  6912. Object::cast_to<EditorPropertyResource>(prop)->set_use_sub_inspector(false);
  6913. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  6914. } else if (Object::cast_to<EditorPropertyTransform3D>(prop) || Object::cast_to<EditorPropertyVector3>(prop)) {
  6915. prop->set_custom_minimum_size(Size2(250 * EDSCALE, 0));
  6916. } else if (Object::cast_to<EditorPropertyVector4>(prop)) {
  6917. prop->set_custom_minimum_size(Size2(320 * EDSCALE, 0));
  6918. } else if (Object::cast_to<EditorPropertyFloat>(prop)) {
  6919. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  6920. } else if (Object::cast_to<EditorPropertyEnum>(prop)) {
  6921. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  6922. Object::cast_to<EditorPropertyEnum>(prop)->set_option_button_clip(false);
  6923. } else if (Object::cast_to<EditorPropertyColor>(prop)) {
  6924. Object::cast_to<EditorPropertyColor>(prop)->set_live_changes_enabled(false);
  6925. }
  6926. editors.push_back(prop);
  6927. properties.push_back(pinfo[i].name);
  6928. }
  6929. VisualShaderNodePluginDefaultEditor *editor = memnew(VisualShaderNodePluginDefaultEditor);
  6930. editor->setup(vseditor, p_parent_resource, editors, properties, p_node->get_editable_properties_names(), p_node);
  6931. return editor;
  6932. }
  6933. void EditorPropertyVisualShaderMode::_option_selected(int p_which) {
  6934. Ref<VisualShader> visual_shader(Object::cast_to<VisualShader>(get_edited_object()));
  6935. if (visual_shader->get_mode() == p_which) {
  6936. return;
  6937. }
  6938. ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_editor_data().get_editor_by_name("Shader"));
  6939. if (!shader_editor) {
  6940. return;
  6941. }
  6942. VisualShaderEditor *editor = Object::cast_to<VisualShaderEditor>(shader_editor->get_shader_editor(visual_shader));
  6943. if (!editor) {
  6944. return;
  6945. }
  6946. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  6947. undo_redo->create_action(TTR("Visual Shader Mode Changed"));
  6948. //do is easy
  6949. undo_redo->add_do_method(visual_shader.ptr(), "set_mode", p_which);
  6950. undo_redo->add_undo_method(visual_shader.ptr(), "set_mode", visual_shader->get_mode());
  6951. undo_redo->add_do_method(editor, "_set_mode", p_which);
  6952. undo_redo->add_undo_method(editor, "_set_mode", visual_shader->get_mode());
  6953. //now undo is hell
  6954. //1. restore connections to output
  6955. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  6956. VisualShader::Type type = VisualShader::Type(i);
  6957. List<VisualShader::Connection> conns;
  6958. visual_shader->get_node_connections(type, &conns);
  6959. for (const VisualShader::Connection &E : conns) {
  6960. if (E.to_node == VisualShader::NODE_ID_OUTPUT) {
  6961. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  6962. }
  6963. }
  6964. }
  6965. //2. restore input indices
  6966. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  6967. VisualShader::Type type = VisualShader::Type(i);
  6968. Vector<int> nodes = visual_shader->get_node_list(type);
  6969. for (int j = 0; j < nodes.size(); j++) {
  6970. Ref<VisualShaderNodeInput> input = visual_shader->get_node(type, nodes[j]);
  6971. if (input.is_null()) {
  6972. continue;
  6973. }
  6974. undo_redo->add_undo_method(input.ptr(), "set_input_name", input->get_input_name());
  6975. }
  6976. }
  6977. //3. restore enums and flags
  6978. List<PropertyInfo> props;
  6979. visual_shader->get_property_list(&props);
  6980. for (const PropertyInfo &E : props) {
  6981. if (E.name.begins_with("flags/") || E.name.begins_with("modes/")) {
  6982. undo_redo->add_undo_property(visual_shader.ptr(), E.name, visual_shader->get(E.name));
  6983. }
  6984. }
  6985. //4. delete varyings (if needed)
  6986. if (p_which == VisualShader::MODE_PARTICLES || p_which == VisualShader::MODE_SKY || p_which == VisualShader::MODE_FOG) {
  6987. int var_count = visual_shader->get_varyings_count();
  6988. if (var_count > 0) {
  6989. for (int i = 0; i < var_count; i++) {
  6990. const VisualShader::Varying *var = visual_shader->get_varying_by_index(i);
  6991. undo_redo->add_do_method(visual_shader.ptr(), "remove_varying", var->name);
  6992. undo_redo->add_undo_method(visual_shader.ptr(), "add_varying", var->name, var->mode, var->type);
  6993. }
  6994. undo_redo->add_do_method(editor, "_update_varyings");
  6995. undo_redo->add_undo_method(editor, "_update_varyings");
  6996. }
  6997. }
  6998. undo_redo->add_do_method(editor, "_update_nodes");
  6999. undo_redo->add_undo_method(editor, "_update_nodes");
  7000. undo_redo->add_do_method(editor, "_update_graph");
  7001. undo_redo->add_undo_method(editor, "_update_graph");
  7002. undo_redo->commit_action();
  7003. }
  7004. void EditorPropertyVisualShaderMode::update_property() {
  7005. int which = get_edited_property_value();
  7006. options->select(which);
  7007. }
  7008. void EditorPropertyVisualShaderMode::setup(const Vector<String> &p_options) {
  7009. for (int i = 0; i < p_options.size(); i++) {
  7010. options->add_item(p_options[i], i);
  7011. }
  7012. }
  7013. void EditorPropertyVisualShaderMode::set_option_button_clip(bool p_enable) {
  7014. options->set_clip_text(p_enable);
  7015. }
  7016. EditorPropertyVisualShaderMode::EditorPropertyVisualShaderMode() {
  7017. options = memnew(OptionButton);
  7018. options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  7019. options->set_clip_text(true);
  7020. add_child(options);
  7021. add_focusable(options);
  7022. options->connect(SceneStringName(item_selected), callable_mp(this, &EditorPropertyVisualShaderMode::_option_selected));
  7023. }
  7024. bool EditorInspectorVisualShaderModePlugin::can_handle(Object *p_object) {
  7025. return true; // Can handle everything.
  7026. }
  7027. bool EditorInspectorVisualShaderModePlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) {
  7028. if (p_path == "mode" && p_object->is_class("VisualShader") && p_type == Variant::INT) {
  7029. EditorPropertyVisualShaderMode *mode_editor = memnew(EditorPropertyVisualShaderMode);
  7030. Vector<String> options = p_hint_text.split(",");
  7031. mode_editor->setup(options);
  7032. add_property_editor(p_path, mode_editor);
  7033. return true;
  7034. }
  7035. return false;
  7036. }
  7037. //////////////////////////////////
  7038. void VisualShaderNodePortPreview::_shader_changed() {
  7039. if (!is_valid || shader.is_null()) {
  7040. return;
  7041. }
  7042. Vector<VisualShader::DefaultTextureParam> default_textures;
  7043. String shader_code = shader->generate_preview_shader(type, node, port, default_textures);
  7044. Ref<Shader> preview_shader;
  7045. preview_shader.instantiate();
  7046. preview_shader->set_code(shader_code);
  7047. for (int i = 0; i < default_textures.size(); i++) {
  7048. int j = 0;
  7049. for (List<Ref<Texture>>::ConstIterator itr = default_textures[i].params.begin(); itr != default_textures[i].params.end(); ++itr, ++j) {
  7050. preview_shader->set_default_texture_parameter(default_textures[i].name, *itr, j);
  7051. }
  7052. }
  7053. Ref<ShaderMaterial> mat;
  7054. mat.instantiate();
  7055. mat->set_shader(preview_shader);
  7056. if (preview_mat.is_valid() && preview_mat->get_shader().is_valid()) {
  7057. List<PropertyInfo> params;
  7058. preview_mat->get_shader()->get_shader_uniform_list(&params);
  7059. for (const PropertyInfo &E : params) {
  7060. mat->set_shader_parameter(E.name, preview_mat->get_shader_parameter(E.name));
  7061. }
  7062. }
  7063. set_material(mat);
  7064. }
  7065. void VisualShaderNodePortPreview::setup(const Ref<VisualShader> &p_shader, Ref<ShaderMaterial> &p_preview_material, VisualShader::Type p_type, bool p_has_transparency, int p_node, int p_port, bool p_is_valid) {
  7066. if (p_has_transparency) {
  7067. checkerboard = memnew(TextureRect);
  7068. checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE);
  7069. checkerboard->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  7070. checkerboard->set_draw_behind_parent(true);
  7071. add_child(checkerboard);
  7072. }
  7073. set_mouse_filter(MOUSE_FILTER_PASS);
  7074. shader = p_shader;
  7075. shader->connect_changed(callable_mp(this, &VisualShaderNodePortPreview::_shader_changed), CONNECT_DEFERRED);
  7076. preview_mat = p_preview_material;
  7077. type = p_type;
  7078. port = p_port;
  7079. node = p_node;
  7080. is_valid = p_is_valid;
  7081. queue_redraw();
  7082. _shader_changed();
  7083. }
  7084. Size2 VisualShaderNodePortPreview::get_minimum_size() const {
  7085. int port_preview_size = EDITOR_GET("editors/visual_editors/visual_shader/port_preview_size");
  7086. return Size2(port_preview_size, port_preview_size) * EDSCALE;
  7087. }
  7088. void VisualShaderNodePortPreview::_notification(int p_what) {
  7089. switch (p_what) {
  7090. case NOTIFICATION_THEME_CHANGED: {
  7091. if (checkerboard != nullptr) {
  7092. checkerboard->set_texture(get_theme_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons)));
  7093. }
  7094. } break;
  7095. case NOTIFICATION_DRAW: {
  7096. Vector<Vector2> points = {
  7097. Vector2(),
  7098. Vector2(get_size().width, 0),
  7099. get_size(),
  7100. Vector2(0, get_size().height)
  7101. };
  7102. Vector<Vector2> uvs = {
  7103. Vector2(0, 0),
  7104. Vector2(1, 0),
  7105. Vector2(1, 1),
  7106. Vector2(0, 1)
  7107. };
  7108. if (is_valid) {
  7109. Vector<Color> colors = {
  7110. Color(1, 1, 1, 1),
  7111. Color(1, 1, 1, 1),
  7112. Color(1, 1, 1, 1),
  7113. Color(1, 1, 1, 1)
  7114. };
  7115. draw_primitive(points, colors, uvs);
  7116. } else {
  7117. Vector<Color> colors = {
  7118. Color(0, 0, 0, 1),
  7119. Color(0, 0, 0, 1),
  7120. Color(0, 0, 0, 1),
  7121. Color(0, 0, 0, 1)
  7122. };
  7123. draw_primitive(points, colors, uvs);
  7124. }
  7125. } break;
  7126. }
  7127. }
  7128. //////////////////////////////////
  7129. String VisualShaderConversionPlugin::converts_to() const {
  7130. return "Shader";
  7131. }
  7132. bool VisualShaderConversionPlugin::handles(const Ref<Resource> &p_resource) const {
  7133. Ref<VisualShader> vshader = p_resource;
  7134. return vshader.is_valid();
  7135. }
  7136. Ref<Resource> VisualShaderConversionPlugin::convert(const Ref<Resource> &p_resource) const {
  7137. Ref<VisualShader> vshader = p_resource;
  7138. ERR_FAIL_COND_V(vshader.is_null(), Ref<Resource>());
  7139. int embed = vshader->has_node_embeds();
  7140. EditorToaster *toast = EditorToaster::get_singleton();
  7141. if (toast == nullptr) {
  7142. ERR_FAIL_COND_V_MSG(embed == 2, Ref<Resource>(), "Cannot convert VisualShader to GDShader because VisualShader has embedded subresources.");
  7143. if (embed == 1) {
  7144. WARN_PRINT("Visual Shader conversion cannot convert external dependencies. Resource references from Nodes will have to be rebound as ShaderParameters on a Material.");
  7145. }
  7146. } else if (embed == 2) {
  7147. toast->popup_str(TTR("Cannot convert VisualShader to GDShader because VisualShader has embedded subresources."), EditorToaster::SEVERITY_ERROR);
  7148. return Ref<Resource>();
  7149. } else if (embed == 1) {
  7150. toast->popup_str(TTR("Visual Shader conversion cannot convert external dependencies. Resource references from Nodes will have to be rebound as ShaderParameters on a Material."), EditorToaster::SEVERITY_WARNING);
  7151. }
  7152. Ref<Shader> shader;
  7153. shader.instantiate();
  7154. String code = vshader->get_code();
  7155. shader->set_code(code);
  7156. return shader;
  7157. }