visual_shader_editor_plugin.cpp 441 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448
  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/inspector/editor_properties.h"
  43. #include "editor/inspector/editor_properties_vector.h"
  44. #include "editor/scene/curve_editor_plugin.h"
  45. #include "editor/scene/material_editor_plugin.h"
  46. #include "editor/settings/editor_settings.h"
  47. #include "editor/shader/shader_editor_plugin.h"
  48. #include "editor/themes/editor_scale.h"
  49. #include "editor/themes/editor_theme_manager.h"
  50. #include "scene/animation/tween.h"
  51. #include "scene/gui/button.h"
  52. #include "scene/gui/check_box.h"
  53. #include "scene/gui/code_edit.h"
  54. #include "scene/gui/color_picker.h"
  55. #include "scene/gui/flow_container.h"
  56. #include "scene/gui/graph_edit.h"
  57. #include "scene/gui/menu_button.h"
  58. #include "scene/gui/option_button.h"
  59. #include "scene/gui/popup.h"
  60. #include "scene/gui/rich_text_label.h"
  61. #include "scene/gui/separator.h"
  62. #include "scene/gui/split_container.h"
  63. #include "scene/gui/texture_rect.h"
  64. #include "scene/gui/tree.h"
  65. #include "scene/gui/view_panner.h"
  66. #include "scene/main/window.h"
  67. #include "scene/resources/curve_texture.h"
  68. #include "scene/resources/style_box_flat.h"
  69. #include "scene/resources/visual_shader_nodes.h"
  70. #include "scene/resources/visual_shader_particle_nodes.h"
  71. #include "servers/display_server.h"
  72. #include "servers/rendering/shader_preprocessor.h"
  73. #include "servers/rendering/shader_types.h"
  74. struct FloatConstantDef {
  75. String name;
  76. float value = 0;
  77. const char *desc_key;
  78. };
  79. static FloatConstantDef float_constant_defs[] = {
  80. { "E", Math::E, TTRC("E constant (2.718282). Represents the base of the natural logarithm.") },
  81. { "Epsilon", CMP_EPSILON, TTRC("Epsilon constant (0.00001). Smallest possible scalar number.") },
  82. { "Phi", 1.618034f, TTRC("Phi constant (1.618034). Golden ratio.") },
  83. { "Pi/4", Math::PI / 4, TTRC("Pi/4 constant (0.785398) or 45 degrees.") },
  84. { "Pi/2", Math::PI / 2, TTRC("Pi/2 constant (1.570796) or 90 degrees.") },
  85. { "Pi", Math::PI, TTRC("Pi constant (3.141593) or 180 degrees.") },
  86. { "Tau", Math::TAU, TTRC("Tau constant (6.283185) or 360 degrees.") },
  87. { "Sqrt2", Math::SQRT2, TTRC("Sqrt2 constant (1.414214). Square root of 2.") }
  88. };
  89. constexpr int MAX_FLOAT_CONST_DEFS = std::size(float_constant_defs);
  90. ///////////////////
  91. void VisualShaderNodePlugin::set_editor(VisualShaderEditor *p_editor) {
  92. vseditor = p_editor;
  93. }
  94. Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) {
  95. Object *ret = nullptr;
  96. GDVIRTUAL_CALL(_create_editor, p_parent_resource, p_node, ret);
  97. return Object::cast_to<Control>(ret);
  98. }
  99. void VisualShaderNodePlugin::_bind_methods() {
  100. GDVIRTUAL_BIND(_create_editor, "parent_resource", "visual_shader_node");
  101. }
  102. ///////////////////
  103. void VSGraphNode::_draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color, const Color &p_rim_color) {
  104. Ref<Texture2D> port_icon = p_left ? get_slot_custom_icon_left(p_slot_index) : get_slot_custom_icon_right(p_slot_index);
  105. Point2 icon_offset;
  106. if (port_icon.is_null()) {
  107. port_icon = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
  108. }
  109. icon_offset = -port_icon->get_size() * 0.5;
  110. // Draw "shadow"/outline in the connection rim color.
  111. 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);
  112. draw_texture_rect(port_icon, Rect2(p_pos + icon_offset * EDSCALE, port_icon->get_size() * EDSCALE), false, p_color);
  113. }
  114. void VSGraphNode::draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) {
  115. Color rim_color = get_theme_color(SNAME("connection_rim_color"), SNAME("GraphEdit"));
  116. _draw_port(p_slot_index, p_pos, p_left, p_color, rim_color);
  117. }
  118. ///////////////////
  119. void VSRerouteNode::_notification(int p_what) {
  120. switch (p_what) {
  121. case NOTIFICATION_READY: {
  122. connect(SceneStringName(mouse_entered), callable_mp(this, &VSRerouteNode::_on_mouse_entered));
  123. connect(SceneStringName(mouse_exited), callable_mp(this, &VSRerouteNode::_on_mouse_exited));
  124. } break;
  125. case NOTIFICATION_DRAW: {
  126. Vector2 offset = Vector2(0, -16 * EDSCALE);
  127. Color drag_bg_color = get_theme_color(SNAME("drag_background"), SNAME("VSRerouteNode"));
  128. draw_circle(get_size() * 0.5 + offset, 16 * EDSCALE, Color(drag_bg_color, selected ? 1 : icon_opacity), true, -1, true);
  129. Ref<Texture2D> icon = get_editor_theme_icon(SNAME("ToolMove"));
  130. Point2 icon_offset = -icon->get_size() * 0.5 + get_size() * 0.5 + offset;
  131. draw_texture(icon, icon_offset, Color(1, 1, 1, selected ? 1 : icon_opacity));
  132. } break;
  133. }
  134. }
  135. void VSRerouteNode::draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) {
  136. Color rim_color = selected ? get_theme_color("selected_rim_color", "VSRerouteNode") : get_theme_color("connection_rim_color", "GraphEdit");
  137. _draw_port(p_slot_index, p_pos, p_left, p_color, rim_color);
  138. }
  139. VSRerouteNode::VSRerouteNode() {
  140. Label *title_lbl = Object::cast_to<Label>(get_titlebar_hbox()->get_child(0));
  141. title_lbl->hide();
  142. const Size2 size = Size2(32, 32) * EDSCALE;
  143. Control *slot_area = memnew(Control);
  144. slot_area->set_custom_minimum_size(size);
  145. slot_area->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
  146. add_child(slot_area);
  147. // Lay the input and output ports on top of each other to create the illusion of a single port.
  148. add_theme_constant_override("port_h_offset", size.width / 2);
  149. }
  150. void VSRerouteNode::set_icon_opacity(float p_opacity) {
  151. icon_opacity = p_opacity;
  152. queue_redraw();
  153. }
  154. void VSRerouteNode::_on_mouse_entered() {
  155. Ref<Tween> tween = create_tween();
  156. tween->tween_method(callable_mp(this, &VSRerouteNode::set_icon_opacity), 0.0, 1.0, FADE_ANIMATION_LENGTH_SEC);
  157. }
  158. void VSRerouteNode::_on_mouse_exited() {
  159. Ref<Tween> tween = create_tween();
  160. tween->tween_method(callable_mp(this, &VSRerouteNode::set_icon_opacity), 1.0, 0.0, FADE_ANIMATION_LENGTH_SEC);
  161. }
  162. ///////////////////
  163. VisualShaderGraphPlugin::VisualShaderGraphPlugin() {
  164. vs_msdf_fonts_theme.instantiate();
  165. }
  166. void VisualShaderGraphPlugin::_bind_methods() {
  167. ClassDB::bind_method("add_node", &VisualShaderGraphPlugin::add_node);
  168. ClassDB::bind_method("remove_node", &VisualShaderGraphPlugin::remove_node);
  169. ClassDB::bind_method("connect_nodes", &VisualShaderGraphPlugin::connect_nodes);
  170. ClassDB::bind_method("disconnect_nodes", &VisualShaderGraphPlugin::disconnect_nodes);
  171. ClassDB::bind_method("set_node_position", &VisualShaderGraphPlugin::set_node_position);
  172. ClassDB::bind_method("update_node", &VisualShaderGraphPlugin::update_node);
  173. ClassDB::bind_method("update_node_deferred", &VisualShaderGraphPlugin::update_node_deferred);
  174. ClassDB::bind_method("set_input_port_default_value", &VisualShaderGraphPlugin::set_input_port_default_value);
  175. ClassDB::bind_method("set_parameter_name", &VisualShaderGraphPlugin::set_parameter_name);
  176. ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression);
  177. ClassDB::bind_method("update_curve", &VisualShaderGraphPlugin::update_curve);
  178. ClassDB::bind_method("update_curve_xyz", &VisualShaderGraphPlugin::update_curve_xyz);
  179. ClassDB::bind_method(D_METHOD("attach_node_to_frame", "type", "id", "frame"), &VisualShaderGraphPlugin::attach_node_to_frame);
  180. ClassDB::bind_method(D_METHOD("detach_node_from_frame", "type", "id"), &VisualShaderGraphPlugin::detach_node_from_frame);
  181. ClassDB::bind_method(D_METHOD("set_frame_color_enabled", "type", "id", "enabled"), &VisualShaderGraphPlugin::set_frame_color_enabled);
  182. ClassDB::bind_method(D_METHOD("set_frame_color", "type", "id", "color"), &VisualShaderGraphPlugin::set_frame_color);
  183. ClassDB::bind_method(D_METHOD("set_frame_autoshrink_enabled", "type", "id", "enabled"), &VisualShaderGraphPlugin::set_frame_autoshrink_enabled);
  184. }
  185. void VisualShaderGraphPlugin::set_editor(VisualShaderEditor *p_editor) {
  186. editor = p_editor;
  187. }
  188. void VisualShaderGraphPlugin::register_shader(VisualShader *p_shader) {
  189. visual_shader = Ref<VisualShader>(p_shader);
  190. }
  191. void VisualShaderGraphPlugin::set_connections(const List<VisualShader::Connection> &p_connections) {
  192. connections = p_connections;
  193. }
  194. void VisualShaderGraphPlugin::show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id, bool p_is_valid) {
  195. if (editor->get_current_shader_type() == p_type && links.has(p_node_id) && links[p_node_id].output_ports.has(p_port_id)) {
  196. Link &link = links[p_node_id];
  197. for (const KeyValue<int, Port> &E : link.output_ports) {
  198. if (E.value.preview_button != nullptr) {
  199. E.value.preview_button->set_pressed(false);
  200. }
  201. }
  202. bool is_dirty = link.preview_pos < 0;
  203. if (!is_dirty && link.preview_visible && link.preview_box != nullptr) {
  204. link.graph_element->remove_child(link.preview_box);
  205. memdelete(link.preview_box);
  206. link.preview_box = nullptr;
  207. link.graph_element->reset_size();
  208. link.preview_visible = false;
  209. }
  210. if (p_port_id != -1 && link.output_ports[p_port_id].preview_button != nullptr) {
  211. if (is_dirty) {
  212. link.preview_pos = link.graph_element->get_child_count();
  213. }
  214. VBoxContainer *vbox = memnew(VBoxContainer);
  215. link.graph_element->add_child(vbox);
  216. link.graph_element->move_child(vbox, link.preview_pos);
  217. GraphNode *graph_node = Object::cast_to<GraphNode>(link.graph_element);
  218. if (graph_node) {
  219. graph_node->set_slot_draw_stylebox(vbox->get_index(false), false);
  220. }
  221. Control *offset = memnew(Control);
  222. offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  223. vbox->add_child(offset);
  224. VisualShaderNodePortPreview *port_preview = memnew(VisualShaderNodePortPreview);
  225. 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);
  226. port_preview->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
  227. vbox->add_child(port_preview);
  228. link.preview_visible = true;
  229. link.preview_box = vbox;
  230. link.output_ports[p_port_id].preview_button->set_pressed(true);
  231. }
  232. }
  233. }
  234. void VisualShaderGraphPlugin::update_node_deferred(VisualShader::Type p_type, int p_node_id) {
  235. callable_mp(this, &VisualShaderGraphPlugin::update_node).call_deferred(p_type, p_node_id);
  236. }
  237. void VisualShaderGraphPlugin::update_node(VisualShader::Type p_type, int p_node_id) {
  238. if (p_type != editor->get_current_shader_type() || !links.has(p_node_id)) {
  239. return;
  240. }
  241. remove_node(p_type, p_node_id, true);
  242. add_node(p_type, p_node_id, true, true);
  243. // TODO: Restore focus here?
  244. }
  245. void VisualShaderGraphPlugin::set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, const Variant &p_value) {
  246. if (p_type != editor->get_current_shader_type() || !links.has(p_node_id)) {
  247. return;
  248. }
  249. Button *button = links[p_node_id].input_ports[p_port_id].default_input_button;
  250. switch (p_value.get_type()) {
  251. case Variant::COLOR: {
  252. button->set_custom_minimum_size(Size2(30, 0) * EDSCALE);
  253. Callable ce = callable_mp(editor, &VisualShaderEditor::_draw_color_over_button);
  254. if (!button->is_connected(SceneStringName(draw), ce)) {
  255. button->connect(SceneStringName(draw), ce.bind(button, p_value));
  256. }
  257. } break;
  258. case Variant::BOOL: {
  259. button->set_text(((bool)p_value) ? "true" : "false");
  260. } break;
  261. case Variant::INT:
  262. case Variant::FLOAT: {
  263. button->set_text(String::num(p_value, 4));
  264. } break;
  265. case Variant::VECTOR2: {
  266. Vector2 v = p_value;
  267. button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3));
  268. } break;
  269. case Variant::VECTOR3: {
  270. Vector3 v = p_value;
  271. button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3) + "," + String::num(v.z, 3));
  272. } break;
  273. case Variant::VECTOR4: {
  274. Vector4 v = p_value;
  275. button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3) + "," + String::num(v.z, 3) + "," + String::num(v.w, 3));
  276. } break;
  277. default: {
  278. }
  279. }
  280. }
  281. void VisualShaderGraphPlugin::set_parameter_name(VisualShader::Type p_type, int p_node_id, const String &p_name) {
  282. if (editor->get_current_shader_type() == p_type && links.has(p_node_id) && links[p_node_id].parameter_name != nullptr) {
  283. links[p_node_id].parameter_name->set_text(p_name);
  284. }
  285. }
  286. void VisualShaderGraphPlugin::update_curve(int p_node_id) {
  287. if (links.has(p_node_id) && links[p_node_id].curve_editors[0]) {
  288. Ref<VisualShaderNodeCurveTexture> tex = Object::cast_to<VisualShaderNodeCurveTexture>(links[p_node_id].visual_node);
  289. ERR_FAIL_COND(tex.is_null());
  290. if (tex->get_texture().is_valid()) {
  291. links[p_node_id].curve_editors[0]->set_curve(tex->get_texture()->get_curve());
  292. }
  293. tex->emit_changed();
  294. }
  295. }
  296. void VisualShaderGraphPlugin::update_curve_xyz(int p_node_id) {
  297. 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]) {
  298. Ref<VisualShaderNodeCurveXYZTexture> tex = Object::cast_to<VisualShaderNodeCurveXYZTexture>(links[p_node_id].visual_node);
  299. ERR_FAIL_COND(tex.is_null());
  300. if (tex->get_texture().is_valid()) {
  301. links[p_node_id].curve_editors[0]->set_curve(tex->get_texture()->get_curve_x());
  302. links[p_node_id].curve_editors[1]->set_curve(tex->get_texture()->get_curve_y());
  303. links[p_node_id].curve_editors[2]->set_curve(tex->get_texture()->get_curve_z());
  304. }
  305. tex->emit_changed();
  306. }
  307. }
  308. int VisualShaderGraphPlugin::get_constant_index(float p_constant) const {
  309. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  310. if (Math::is_equal_approx(p_constant, float_constant_defs[i].value)) {
  311. return i + 1;
  312. }
  313. }
  314. return 0;
  315. }
  316. void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression) {
  317. if (p_type != editor->get_current_shader_type() || !links.has(p_node_id) || !links[p_node_id].expression_edit) {
  318. return;
  319. }
  320. links[p_node_id].expression_edit->set_text(p_expression);
  321. }
  322. void VisualShaderGraphPlugin::attach_node_to_frame(VisualShader::Type p_type, int p_node_id, int p_frame_id) {
  323. if (p_type != editor->get_current_shader_type() || !links.has(p_node_id) || !links.has(p_frame_id)) {
  324. return;
  325. }
  326. GraphEdit *graph = editor->graph;
  327. if (!graph) {
  328. return;
  329. }
  330. // Get the hint label and hide it before attaching the node to prevent resizing issues with the frame.
  331. GraphFrame *frame = Object::cast_to<GraphFrame>(links[p_frame_id].graph_element);
  332. ERR_FAIL_COND_MSG(!frame, "VisualShader node to attach to is not a frame node.");
  333. Label *frame_hint_label = Object::cast_to<Label>(frame->get_child(0, false));
  334. if (frame_hint_label) {
  335. frame_hint_label->hide();
  336. }
  337. graph->attach_graph_element_to_frame(itos(p_node_id), itos(p_frame_id));
  338. }
  339. void VisualShaderGraphPlugin::detach_node_from_frame(VisualShader::Type p_type, int p_node_id) {
  340. GraphEdit *graph = editor->graph;
  341. if (!graph) {
  342. return;
  343. }
  344. const StringName node_name = itos(p_node_id);
  345. GraphFrame *frame = graph->get_element_frame(node_name);
  346. if (!frame) {
  347. return;
  348. }
  349. graph->detach_graph_element_from_frame(node_name);
  350. bool no_more_frames_attached = graph->get_attached_nodes_of_frame(frame->get_name()).is_empty();
  351. if (no_more_frames_attached) {
  352. // Get the hint label and show it.
  353. Label *frame_hint_label = Object::cast_to<Label>(frame->get_child(0, false));
  354. ERR_FAIL_COND_MSG(!frame_hint_label, "Frame node does not have a hint label.");
  355. frame_hint_label->show();
  356. }
  357. }
  358. void VisualShaderGraphPlugin::set_frame_color_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable) {
  359. GraphEdit *graph = editor->graph;
  360. ERR_FAIL_COND(!graph);
  361. const NodePath node_name = itos(p_node_id);
  362. GraphFrame *frame = Object::cast_to<GraphFrame>(graph->get_node_or_null(node_name));
  363. if (!frame) {
  364. return;
  365. }
  366. frame->set_tint_color_enabled(p_enable);
  367. }
  368. void VisualShaderGraphPlugin::set_frame_color(VisualShader::Type p_type, int p_node_id, const Color &p_color) {
  369. GraphEdit *graph = editor->graph;
  370. ERR_FAIL_COND(!graph);
  371. const NodePath node_name = itos(p_node_id);
  372. GraphFrame *frame = Object::cast_to<GraphFrame>(graph->get_node_or_null(node_name));
  373. if (!frame) {
  374. return;
  375. }
  376. frame->set_tint_color(p_color);
  377. }
  378. void VisualShaderGraphPlugin::set_frame_autoshrink_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable) {
  379. GraphEdit *graph = editor->graph;
  380. ERR_FAIL_COND(!graph);
  381. const NodePath node_name = itos(p_node_id);
  382. GraphFrame *frame = Object::cast_to<GraphFrame>(graph->get_node_or_null(node_name));
  383. if (!frame) {
  384. return;
  385. }
  386. frame->set_autoshrink_enabled(p_enable);
  387. }
  388. void VisualShaderGraphPlugin::update_reroute_nodes() {
  389. for (const KeyValue<int, Link> &E : links) {
  390. Ref<VisualShaderNodeReroute> reroute_node = Object::cast_to<VisualShaderNodeReroute>(E.value.visual_node);
  391. if (reroute_node.is_valid()) {
  392. update_node(editor->get_current_shader_type(), E.key);
  393. }
  394. }
  395. }
  396. Ref<Script> VisualShaderGraphPlugin::get_node_script(int p_node_id) const {
  397. if (!links.has(p_node_id)) {
  398. return Ref<Script>();
  399. }
  400. Ref<VisualShaderNodeCustom> custom = Ref<VisualShaderNodeCustom>(links[p_node_id].visual_node);
  401. if (custom.is_valid()) {
  402. return custom->get_script();
  403. }
  404. return Ref<Script>();
  405. }
  406. void VisualShaderGraphPlugin::register_default_input_button(int p_node_id, int p_port_id, Button *p_button) {
  407. links[p_node_id].input_ports.insert(p_port_id, { p_button });
  408. }
  409. void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit *p_expression_edit) {
  410. links[p_node_id].expression_edit = p_expression_edit;
  411. }
  412. void VisualShaderGraphPlugin::register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor) {
  413. links[p_node_id].curve_editors[p_index] = p_curve_editor;
  414. }
  415. void VisualShaderGraphPlugin::update_parameter_refs() {
  416. for (KeyValue<int, Link> &E : links) {
  417. VisualShaderNodeParameterRef *ref = Object::cast_to<VisualShaderNodeParameterRef>(E.value.visual_node);
  418. if (ref) {
  419. remove_node(E.value.type, E.key, true);
  420. add_node(E.value.type, E.key, true, true);
  421. }
  422. }
  423. }
  424. // Only updates the linked frames of the given node, not the node itself (in case it's a frame node).
  425. void VisualShaderGraphPlugin::update_frames(VisualShader::Type p_type, int p_node) {
  426. GraphEdit *graph = editor->graph;
  427. if (!graph) {
  428. return;
  429. }
  430. Ref<VisualShaderNode> vsnode = visual_shader->get_node(p_type, p_node);
  431. if (vsnode.is_null()) {
  432. WARN_PRINT("Update linked frames: Node not found.");
  433. return;
  434. }
  435. int frame_vsnode_id = vsnode->get_frame();
  436. if (frame_vsnode_id == -1) {
  437. return;
  438. }
  439. Ref<VisualShaderNodeFrame> frame_node = visual_shader->get_node(p_type, frame_vsnode_id);
  440. if (frame_node.is_null() || !links.has(frame_vsnode_id)) {
  441. return;
  442. }
  443. GraphFrame *frame = Object::cast_to<GraphFrame>(links[frame_vsnode_id].graph_element);
  444. if (!frame) {
  445. return;
  446. }
  447. // Update the frame node recursively.
  448. editor->graph->_update_graph_frame(frame);
  449. }
  450. void VisualShaderGraphPlugin::set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position) {
  451. if (editor->get_current_shader_type() == p_type && links.has(p_id)) {
  452. links[p_id].graph_element->set_position_offset(p_position);
  453. }
  454. }
  455. bool VisualShaderGraphPlugin::is_preview_visible(int p_id) const {
  456. return links[p_id].preview_visible;
  457. }
  458. void VisualShaderGraphPlugin::clear_links() {
  459. links.clear();
  460. }
  461. void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphElement *p_graph_element) {
  462. 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 } });
  463. }
  464. void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, VisualShaderNode::PortType p_port_type, TextureButton *p_button) {
  465. links[p_node_id].output_ports.insert(p_port, { p_port_type, p_button });
  466. }
  467. void VisualShaderGraphPlugin::register_parameter_name(int p_node_id, LineEdit *p_parameter_name) {
  468. links[p_node_id].parameter_name = p_parameter_name;
  469. }
  470. void VisualShaderGraphPlugin::update_theme() {
  471. vector_expanded_color[0] = editor->get_theme_color(SNAME("axis_x_color"), EditorStringName(Editor)); // red
  472. vector_expanded_color[1] = editor->get_theme_color(SNAME("axis_y_color"), EditorStringName(Editor)); // green
  473. vector_expanded_color[2] = editor->get_theme_color(SNAME("axis_z_color"), EditorStringName(Editor)); // blue
  474. vector_expanded_color[3] = editor->get_theme_color(SNAME("axis_w_color"), EditorStringName(Editor)); // alpha
  475. Ref<Font> label_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_msdf", EditorStringName(EditorFonts));
  476. Ref<Font> label_bold_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_bold_msdf", EditorStringName(EditorFonts));
  477. vs_msdf_fonts_theme->set_font(SceneStringName(font), "Label", label_font);
  478. vs_msdf_fonts_theme->set_font(SceneStringName(font), "GraphNodeTitleLabel", label_bold_font);
  479. if (!EditorThemeManager::is_dark_theme()) {
  480. // Override the color to white for light themes.
  481. vs_msdf_fonts_theme->set_color(SceneStringName(font_color), "GraphNodeTitleLabel", Color(1, 1, 1));
  482. }
  483. vs_msdf_fonts_theme->set_font(SceneStringName(font), "LineEdit", label_font);
  484. vs_msdf_fonts_theme->set_font(SceneStringName(font), "Button", label_font);
  485. }
  486. bool VisualShaderGraphPlugin::is_node_has_parameter_instances_relatively(VisualShader::Type p_type, int p_node) const {
  487. bool result = false;
  488. Ref<VisualShaderNodeParameter> parameter_node = Object::cast_to<VisualShaderNodeParameter>(visual_shader->get_node_unchecked(p_type, p_node).ptr());
  489. if (parameter_node.is_valid()) {
  490. if (parameter_node->get_qualifier() == VisualShaderNodeParameter::QUAL_INSTANCE) {
  491. return true;
  492. }
  493. }
  494. const LocalVector<int> &prev_connected_nodes = visual_shader->get_prev_connected_nodes(p_type, p_node);
  495. for (const int &E : prev_connected_nodes) {
  496. result = is_node_has_parameter_instances_relatively(p_type, E);
  497. if (result) {
  498. break;
  499. }
  500. }
  501. return result;
  502. }
  503. void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool p_just_update, bool p_update_frames) {
  504. if (visual_shader.is_null() || p_type != editor->get_current_shader_type()) {
  505. return;
  506. }
  507. GraphEdit *graph = editor->graph;
  508. if (!graph) {
  509. return;
  510. }
  511. VisualShaderGraphPlugin *graph_plugin = editor->get_graph_plugin();
  512. if (!graph_plugin) {
  513. return;
  514. }
  515. Shader::Mode mode = visual_shader->get_mode();
  516. Control *offset;
  517. const Color type_color[] = {
  518. EDITOR_GET("editors/visual_editors/connection_colors/scalar_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/vector2_color"),
  522. EDITOR_GET("editors/visual_editors/connection_colors/vector3_color"),
  523. EDITOR_GET("editors/visual_editors/connection_colors/vector4_color"),
  524. EDITOR_GET("editors/visual_editors/connection_colors/boolean_color"),
  525. EDITOR_GET("editors/visual_editors/connection_colors/transform_color"),
  526. EDITOR_GET("editors/visual_editors/connection_colors/sampler_color"),
  527. };
  528. // Keep in sync with VisualShaderNode::Category.
  529. const Color category_color[VisualShaderNode::Category::CATEGORY_MAX] = {
  530. Color(0.0, 0.0, 0.0), // None (default, not used)
  531. EDITOR_GET("editors/visual_editors/category_colors/output_color"),
  532. EDITOR_GET("editors/visual_editors/category_colors/color_color"),
  533. EDITOR_GET("editors/visual_editors/category_colors/conditional_color"),
  534. EDITOR_GET("editors/visual_editors/category_colors/input_color"),
  535. EDITOR_GET("editors/visual_editors/category_colors/scalar_color"),
  536. EDITOR_GET("editors/visual_editors/category_colors/textures_color"),
  537. EDITOR_GET("editors/visual_editors/category_colors/transform_color"),
  538. EDITOR_GET("editors/visual_editors/category_colors/utility_color"),
  539. EDITOR_GET("editors/visual_editors/category_colors/vector_color"),
  540. EDITOR_GET("editors/visual_editors/category_colors/special_color"),
  541. EDITOR_GET("editors/visual_editors/category_colors/particle_color"),
  542. };
  543. static const String vector_expanded_name[4] = { "red", "green", "blue", "alpha" };
  544. Ref<VisualShaderNode> vsnode = visual_shader->get_node(p_type, p_id);
  545. ERR_FAIL_COND(vsnode.is_null());
  546. Ref<VisualShaderNodeResizableBase> resizable_node = vsnode;
  547. bool is_resizable = resizable_node.is_valid();
  548. Size2 size = Size2(0, 0);
  549. Ref<VisualShaderNodeGroupBase> group_node = vsnode;
  550. bool is_group = group_node.is_valid();
  551. Ref<VisualShaderNodeFrame> frame_node = vsnode;
  552. bool is_frame = frame_node.is_valid();
  553. Ref<VisualShaderNodeExpression> expression_node = group_node;
  554. bool is_expression = expression_node.is_valid();
  555. String expression = "";
  556. Ref<VisualShaderNodeReroute> reroute_node = vsnode;
  557. bool is_reroute = reroute_node.is_valid();
  558. Ref<VisualShaderNodeCustom> custom_node = vsnode;
  559. if (custom_node.is_valid()) {
  560. custom_node->_set_initialized(true);
  561. }
  562. GraphElement *node;
  563. if (is_frame) {
  564. GraphFrame *frame = memnew(GraphFrame);
  565. frame->set_title(vsnode->get_caption());
  566. node = frame;
  567. } else if (is_reroute) {
  568. VSRerouteNode *reroute_gnode = memnew(VSRerouteNode);
  569. reroute_gnode->set_ignore_invalid_connection_type(true);
  570. node = reroute_gnode;
  571. } else {
  572. VSGraphNode *gnode = memnew(VSGraphNode);
  573. gnode->set_title(vsnode->get_caption());
  574. node = gnode;
  575. }
  576. node->set_name(itos(p_id));
  577. // All nodes are closable except the output node.
  578. if (p_id >= 2) {
  579. vsnode->set_deletable(true);
  580. node->connect("delete_request", callable_mp(editor, &VisualShaderEditor::_delete_node_request).bind(p_type, p_id), CONNECT_DEFERRED);
  581. }
  582. graph->add_child(node);
  583. node->set_theme(vs_msdf_fonts_theme);
  584. // Set the node's titlebar color based on its category.
  585. if (vsnode->get_category() != VisualShaderNode::CATEGORY_NONE && !is_frame && !is_reroute) {
  586. Ref<StyleBoxFlat> sb_colored = editor->get_theme_stylebox("titlebar", "GraphNode")->duplicate();
  587. sb_colored->set_bg_color(category_color[vsnode->get_category()]);
  588. node->add_theme_style_override("titlebar", sb_colored);
  589. Ref<StyleBoxFlat> sb_colored_selected = editor->get_theme_stylebox("titlebar_selected", "GraphNode")->duplicate();
  590. sb_colored_selected->set_bg_color(category_color[vsnode->get_category()].lightened(0.2));
  591. node->add_theme_style_override("titlebar_selected", sb_colored_selected);
  592. }
  593. if (p_just_update) {
  594. Link &link = links[p_id];
  595. link.visual_node = vsnode.ptr();
  596. link.graph_element = node;
  597. link.preview_box = nullptr;
  598. link.preview_pos = -1;
  599. link.output_ports.clear();
  600. link.input_ports.clear();
  601. } else {
  602. register_link(p_type, p_id, vsnode.ptr(), node);
  603. }
  604. if (is_resizable) {
  605. size = resizable_node->get_size();
  606. node->set_resizable(true);
  607. node->connect("resize_end", callable_mp(editor, &VisualShaderEditor::_node_resized).bind((int)p_type, p_id));
  608. node->set_size(size);
  609. // node->call_deferred(SNAME("set_size"), size);
  610. // editor->call_deferred(SNAME("_set_node_size"), (int)p_type, p_id, size);
  611. }
  612. if (is_expression) {
  613. expression = expression_node->get_expression();
  614. }
  615. node->set_position_offset(visual_shader->get_node_position(p_type, p_id));
  616. node->connect("dragged", callable_mp(editor, &VisualShaderEditor::_node_dragged).bind(p_id));
  617. Control *custom_editor = nullptr;
  618. int port_offset = 1;
  619. if (p_update_frames) {
  620. if (vsnode->get_frame() > -1) {
  621. graph->attach_graph_element_to_frame(itos(p_id), itos(vsnode->get_frame()));
  622. } else {
  623. graph->detach_graph_element_from_frame(itos(p_id));
  624. }
  625. }
  626. if (is_frame) {
  627. GraphFrame *graph_frame = Object::cast_to<GraphFrame>(node);
  628. ERR_FAIL_NULL(graph_frame);
  629. graph_frame->set_tint_color_enabled(frame_node->is_tint_color_enabled());
  630. graph_frame->set_tint_color(frame_node->get_tint_color());
  631. // Add hint label.
  632. Label *frame_hint_label = memnew(Label);
  633. frame_hint_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  634. node->add_child(frame_hint_label);
  635. frame_hint_label->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER);
  636. frame_hint_label->set_vertical_alignment(VerticalAlignment::VERTICAL_ALIGNMENT_CENTER);
  637. frame_hint_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  638. frame_hint_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  639. frame_hint_label->set_text(TTR("Drag and drop nodes here to attach them."));
  640. frame_hint_label->set_modulate(Color(1.0, 1.0, 1.0, 0.3));
  641. graph_frame->set_autoshrink_enabled(frame_node->is_autoshrink_enabled());
  642. if (frame_node->get_attached_nodes().is_empty()) {
  643. frame_hint_label->show();
  644. } else {
  645. frame_hint_label->hide();
  646. }
  647. // Attach all nodes.
  648. if (p_update_frames && frame_node->get_attached_nodes().size() > 0) {
  649. for (const int &id : frame_node->get_attached_nodes()) {
  650. graph->attach_graph_element_to_frame(itos(id), node->get_name());
  651. }
  652. }
  653. // We should be done here.
  654. return;
  655. }
  656. if (!is_reroute) {
  657. Control *content_offset = memnew(Control);
  658. content_offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  659. node->add_child(content_offset);
  660. }
  661. if (is_group) {
  662. port_offset += 1;
  663. }
  664. // Set the minimum width of a node based on the preview size to avoid a resize when toggling the preview.
  665. Ref<StyleBoxFlat> graph_node_stylebox = graph->get_theme_stylebox(SceneStringName(panel), "GraphNode");
  666. int port_preview_size = EDITOR_GET("editors/visual_editors/visual_shader/port_preview_size");
  667. if (!is_frame && !is_reroute) {
  668. node->set_custom_minimum_size(Size2((Math::ceil(graph_node_stylebox->get_minimum_size().width) + port_preview_size) * EDSCALE, 0));
  669. }
  670. Ref<VisualShaderNodeParticleEmit> emit = vsnode;
  671. if (emit.is_valid()) {
  672. node->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
  673. }
  674. Ref<VisualShaderNodeParameterRef> parameter_ref = vsnode;
  675. if (parameter_ref.is_valid()) {
  676. parameter_ref->set_shader_rid(visual_shader->get_rid());
  677. parameter_ref->update_parameter_type();
  678. }
  679. Ref<VisualShaderNodeVarying> varying = vsnode;
  680. if (varying.is_valid()) {
  681. varying->set_shader_rid(visual_shader->get_rid());
  682. }
  683. Ref<VisualShaderNodeParameter> parameter = vsnode;
  684. HBoxContainer *hb = nullptr;
  685. if (parameter.is_valid()) {
  686. LineEdit *parameter_name = memnew(LineEdit);
  687. register_parameter_name(p_id, parameter_name);
  688. parameter_name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  689. parameter_name->set_text(parameter->get_parameter_name());
  690. parameter_name->connect(SceneStringName(text_submitted), callable_mp(editor, &VisualShaderEditor::_parameter_line_edit_changed).bind(p_id));
  691. parameter_name->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_parameter_line_edit_focus_out).bind(parameter_name, p_id));
  692. if (vsnode->get_output_port_count() == 1 && vsnode->get_output_port_name(0) == "") {
  693. hb = memnew(HBoxContainer);
  694. hb->add_child(parameter_name);
  695. node->add_child(hb);
  696. } else {
  697. node->add_child(parameter_name);
  698. }
  699. port_offset++;
  700. }
  701. for (int i = 0; i < editor->plugins.size(); i++) {
  702. vsnode->set_meta("id", p_id);
  703. vsnode->set_meta("shader_type", (int)p_type);
  704. custom_editor = editor->plugins.write[i]->create_editor(visual_shader, vsnode);
  705. vsnode->remove_meta("id");
  706. vsnode->remove_meta("shader_type");
  707. if (custom_editor) {
  708. if (vsnode->is_show_prop_names()) {
  709. custom_editor->call_deferred(SNAME("_show_prop_names"), true);
  710. }
  711. break;
  712. }
  713. }
  714. if (custom_node.is_valid()) {
  715. bool first = true;
  716. VBoxContainer *vbox = nullptr;
  717. int i = 0;
  718. for (List<VisualShaderNodeCustom::DropDownListProperty>::ConstIterator itr = custom_node->dp_props.begin(); itr != custom_node->dp_props.end(); ++itr, ++i) {
  719. const VisualShaderNodeCustom::DropDownListProperty &dp = *itr;
  720. if (first) {
  721. first = false;
  722. vbox = memnew(VBoxContainer);
  723. node->add_child(vbox);
  724. port_offset++;
  725. }
  726. HBoxContainer *hbox = memnew(HBoxContainer);
  727. vbox->add_child(hbox);
  728. hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  729. String prop_name = dp.name.strip_edges();
  730. if (!prop_name.is_empty()) {
  731. Label *label = memnew(Label);
  732. label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  733. label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  734. label->set_text(prop_name + ":");
  735. hbox->add_child(label);
  736. }
  737. OptionButton *op = memnew(OptionButton);
  738. hbox->add_child(op);
  739. op->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  740. op->connect(SceneStringName(item_selected), callable_mp(editor, &VisualShaderEditor::_set_custom_node_option).bind(p_id, i), CONNECT_DEFERRED);
  741. for (const String &s : dp.options) {
  742. op->add_item(s);
  743. }
  744. if (custom_node->dp_selected_cache.has(i)) {
  745. op->select(custom_node->dp_selected_cache[i]);
  746. } else {
  747. op->select(0);
  748. }
  749. }
  750. }
  751. Ref<VisualShaderNodeCurveTexture> curve = vsnode;
  752. Ref<VisualShaderNodeCurveXYZTexture> curve_xyz = vsnode;
  753. bool is_curve = curve.is_valid() || curve_xyz.is_valid();
  754. if (is_curve) {
  755. hb = memnew(HBoxContainer);
  756. node->add_child(hb);
  757. }
  758. if (curve.is_valid()) {
  759. custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  760. if (curve->get_texture().is_valid()) {
  761. curve->get_texture()->connect_changed(callable_mp(graph_plugin, &VisualShaderGraphPlugin::update_curve).bind(p_id));
  762. }
  763. CurveEditor *curve_editor = memnew(CurveEditor);
  764. node->add_child(curve_editor);
  765. register_curve_editor(p_id, 0, curve_editor);
  766. curve_editor->set_custom_minimum_size(Size2(300, 0));
  767. curve_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  768. if (curve->get_texture().is_valid()) {
  769. curve_editor->set_curve(curve->get_texture()->get_curve());
  770. }
  771. }
  772. if (curve_xyz.is_valid()) {
  773. custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  774. if (curve_xyz->get_texture().is_valid()) {
  775. curve_xyz->get_texture()->connect_changed(callable_mp(graph_plugin, &VisualShaderGraphPlugin::update_curve_xyz).bind(p_id));
  776. }
  777. CurveEditor *curve_editor_x = memnew(CurveEditor);
  778. node->add_child(curve_editor_x);
  779. register_curve_editor(p_id, 0, curve_editor_x);
  780. curve_editor_x->set_custom_minimum_size(Size2(300, 0));
  781. curve_editor_x->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  782. if (curve_xyz->get_texture().is_valid()) {
  783. curve_editor_x->set_curve(curve_xyz->get_texture()->get_curve_x());
  784. }
  785. CurveEditor *curve_editor_y = memnew(CurveEditor);
  786. node->add_child(curve_editor_y);
  787. register_curve_editor(p_id, 1, curve_editor_y);
  788. curve_editor_y->set_custom_minimum_size(Size2(300, 0));
  789. curve_editor_y->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  790. if (curve_xyz->get_texture().is_valid()) {
  791. curve_editor_y->set_curve(curve_xyz->get_texture()->get_curve_y());
  792. }
  793. CurveEditor *curve_editor_z = memnew(CurveEditor);
  794. node->add_child(curve_editor_z);
  795. register_curve_editor(p_id, 2, curve_editor_z);
  796. curve_editor_z->set_custom_minimum_size(Size2(300, 0));
  797. curve_editor_z->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  798. if (curve_xyz->get_texture().is_valid()) {
  799. curve_editor_z->set_curve(curve_xyz->get_texture()->get_curve_z());
  800. }
  801. }
  802. if (custom_editor) {
  803. 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) == ""))) {
  804. // Will be embedded in first port.
  805. } else {
  806. port_offset++;
  807. node->add_child(custom_editor);
  808. custom_editor = nullptr;
  809. }
  810. }
  811. if (is_group) {
  812. if (group_node->is_editable()) {
  813. HBoxContainer *hb2 = memnew(HBoxContainer);
  814. String input_port_name = "input" + itos(group_node->get_free_input_port_id());
  815. String output_port_name = "output" + itos(group_node->get_free_output_port_id());
  816. for (int i = 0; i < MAX(vsnode->get_input_port_count(), vsnode->get_output_port_count()); i++) {
  817. if (i < vsnode->get_input_port_count()) {
  818. if (input_port_name == vsnode->get_input_port_name(i)) {
  819. input_port_name = "_" + input_port_name;
  820. }
  821. }
  822. if (i < vsnode->get_output_port_count()) {
  823. if (output_port_name == vsnode->get_output_port_name(i)) {
  824. output_port_name = "_" + output_port_name;
  825. }
  826. }
  827. }
  828. Button *add_input_btn = memnew(Button);
  829. add_input_btn->set_text(TTR("Add Input"));
  830. 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);
  831. hb2->add_child(add_input_btn);
  832. hb2->add_spacer();
  833. Button *add_output_btn = memnew(Button);
  834. add_output_btn->set_text(TTR("Add Output"));
  835. 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);
  836. hb2->add_child(add_output_btn);
  837. node->add_child(hb2);
  838. }
  839. }
  840. int output_port_count = 0;
  841. for (int i = 0; i < vsnode->get_output_port_count(); i++) {
  842. if (vsnode->_is_output_port_expanded(i)) {
  843. switch (vsnode->get_output_port_type(i)) {
  844. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  845. output_port_count += 2;
  846. } break;
  847. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  848. output_port_count += 3;
  849. } break;
  850. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  851. output_port_count += 4;
  852. } break;
  853. default:
  854. break;
  855. }
  856. }
  857. output_port_count++;
  858. }
  859. int max_ports = MAX(vsnode->get_input_port_count(), output_port_count);
  860. VisualShaderNode::PortType expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  861. int expanded_port_counter = 0;
  862. for (int i = 0, j = 0; i < max_ports; i++, j++) {
  863. switch (expanded_type) {
  864. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  865. if (expanded_port_counter >= 2) {
  866. expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  867. expanded_port_counter = 0;
  868. i -= 2;
  869. }
  870. } break;
  871. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  872. if (expanded_port_counter >= 3) {
  873. expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  874. expanded_port_counter = 0;
  875. i -= 3;
  876. }
  877. } break;
  878. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  879. if (expanded_port_counter >= 4) {
  880. expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  881. expanded_port_counter = 0;
  882. i -= 4;
  883. }
  884. } break;
  885. default:
  886. break;
  887. }
  888. if (vsnode->is_port_separator(i)) {
  889. node->add_child(memnew(HSeparator));
  890. port_offset++;
  891. }
  892. bool valid_left = j < vsnode->get_input_port_count();
  893. VisualShaderNode::PortType port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  894. bool port_left_used = false;
  895. String name_left;
  896. if (valid_left) {
  897. name_left = vsnode->get_input_port_name(j);
  898. port_left = vsnode->get_input_port_type(j);
  899. for (const VisualShader::Connection &E : connections) {
  900. if (E.to_node == p_id && E.to_port == j) {
  901. port_left_used = true;
  902. break;
  903. }
  904. }
  905. }
  906. bool valid_right = true;
  907. VisualShaderNode::PortType port_right = VisualShaderNode::PORT_TYPE_SCALAR;
  908. String name_right;
  909. if (expanded_type == VisualShaderNode::PORT_TYPE_SCALAR) {
  910. valid_right = i < vsnode->get_output_port_count();
  911. if (valid_right) {
  912. name_right = vsnode->get_output_port_name(i);
  913. port_right = vsnode->get_output_port_type(i);
  914. }
  915. } else {
  916. name_right = vector_expanded_name[expanded_port_counter++];
  917. }
  918. bool is_first_hbox = false;
  919. if (i == 0 && hb != nullptr) {
  920. is_first_hbox = true;
  921. } else {
  922. hb = memnew(HBoxContainer);
  923. }
  924. hb->add_theme_constant_override("separation", 7 * EDSCALE);
  925. // Default value button/property editor.
  926. Variant default_value;
  927. if (valid_left && !port_left_used) {
  928. default_value = vsnode->get_input_port_default_value(j);
  929. }
  930. Button *default_input_btn = memnew(Button);
  931. hb->add_child(default_input_btn);
  932. register_default_input_button(p_id, j, default_input_btn);
  933. default_input_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_edit_port_default_input).bind(default_input_btn, p_id, j));
  934. if (default_value.get_type() != Variant::NIL) { // only a label
  935. set_input_port_default_value(p_type, p_id, j, default_value);
  936. } else {
  937. default_input_btn->hide();
  938. }
  939. if (j == 0 && custom_editor) {
  940. hb->add_child(custom_editor);
  941. custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  942. } else {
  943. if (valid_left) {
  944. if (is_group) {
  945. OptionButton *type_box = memnew(OptionButton);
  946. hb->add_child(type_box);
  947. type_box->add_item(TTR("Float"));
  948. type_box->add_item(TTR("Int"));
  949. type_box->add_item(TTR("UInt"));
  950. type_box->add_item(TTR("Vector2"));
  951. type_box->add_item(TTR("Vector3"));
  952. type_box->add_item(TTR("Vector4"));
  953. type_box->add_item(TTR("Boolean"));
  954. type_box->add_item(TTR("Transform"));
  955. type_box->add_item(TTR("Sampler"));
  956. type_box->select(group_node->get_input_port_type(j));
  957. type_box->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  958. type_box->connect(SceneStringName(item_selected), callable_mp(editor, &VisualShaderEditor::_change_input_port_type).bind(p_id, j), CONNECT_DEFERRED);
  959. LineEdit *name_box = memnew(LineEdit);
  960. hb->add_child(name_box);
  961. name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0));
  962. name_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  963. name_box->set_text(name_left);
  964. name_box->connect(SceneStringName(text_submitted), callable_mp(editor, &VisualShaderEditor::_change_input_port_name).bind(name_box, p_id, j), CONNECT_DEFERRED);
  965. name_box->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_port_name_focus_out).bind(name_box, p_id, j, false), CONNECT_DEFERRED);
  966. Button *remove_btn = memnew(Button);
  967. remove_btn->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Remove"), EditorStringName(EditorIcons)));
  968. remove_btn->set_tooltip_text(TTR("Remove") + " " + name_left);
  969. remove_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_remove_input_port).bind(p_id, j), CONNECT_DEFERRED);
  970. hb->add_child(remove_btn);
  971. } else {
  972. Label *label = memnew(Label);
  973. label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  974. label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  975. label->set_text(name_left);
  976. label->add_theme_style_override(CoreStringName(normal), editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor")));
  977. hb->add_child(label);
  978. if (vsnode->is_input_port_default(j, mode) && !port_left_used) {
  979. Label *hint_label = memnew(Label);
  980. hint_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  981. hint_label->set_text(TTR("[default]"));
  982. hint_label->add_theme_color_override(SceneStringName(font_color), editor->get_theme_color(SNAME("font_readonly_color"), SNAME("TextEdit")));
  983. hint_label->add_theme_style_override(CoreStringName(normal), editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor")));
  984. hb->add_child(hint_label);
  985. }
  986. }
  987. }
  988. if (!is_group && !is_first_hbox) {
  989. hb->add_spacer();
  990. }
  991. if (valid_right) {
  992. if (is_group) {
  993. Button *remove_btn = memnew(Button);
  994. remove_btn->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Remove"), EditorStringName(EditorIcons)));
  995. remove_btn->set_tooltip_text(TTR("Remove") + " " + name_left);
  996. remove_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_remove_output_port).bind(p_id, i), CONNECT_DEFERRED);
  997. hb->add_child(remove_btn);
  998. LineEdit *name_box = memnew(LineEdit);
  999. hb->add_child(name_box);
  1000. name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0));
  1001. name_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1002. name_box->set_text(name_right);
  1003. name_box->connect(SceneStringName(text_submitted), callable_mp(editor, &VisualShaderEditor::_change_output_port_name).bind(name_box, p_id, i), CONNECT_DEFERRED);
  1004. name_box->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_port_name_focus_out).bind(name_box, p_id, i, true), CONNECT_DEFERRED);
  1005. OptionButton *type_box = memnew(OptionButton);
  1006. hb->add_child(type_box);
  1007. type_box->add_item(TTR("Float"));
  1008. type_box->add_item(TTR("Int"));
  1009. type_box->add_item(TTR("UInt"));
  1010. type_box->add_item(TTR("Vector2"));
  1011. type_box->add_item(TTR("Vector3"));
  1012. type_box->add_item(TTR("Vector4"));
  1013. type_box->add_item(TTR("Boolean"));
  1014. type_box->add_item(TTR("Transform"));
  1015. type_box->select(group_node->get_output_port_type(i));
  1016. type_box->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  1017. type_box->connect(SceneStringName(item_selected), callable_mp(editor, &VisualShaderEditor::_change_output_port_type).bind(p_id, i), CONNECT_DEFERRED);
  1018. } else {
  1019. Label *label = memnew(Label);
  1020. label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  1021. label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  1022. label->set_text(name_right);
  1023. label->add_theme_style_override(CoreStringName(normal), editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact
  1024. hb->add_child(label);
  1025. }
  1026. }
  1027. }
  1028. if (valid_right) {
  1029. if (expanded_port_counter == 0 && vsnode->is_output_port_expandable(i)) {
  1030. TextureButton *expand = memnew(TextureButton);
  1031. expand->set_accessibility_name(TTRC("Expand output port"));
  1032. expand->set_toggle_mode(true);
  1033. expand->set_texture_normal(editor->get_editor_theme_icon(SNAME("GuiTreeArrowRight")));
  1034. expand->set_texture_pressed(editor->get_editor_theme_icon(SNAME("GuiTreeArrowDown")));
  1035. expand->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  1036. expand->set_pressed(vsnode->_is_output_port_expanded(i));
  1037. expand->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_expand_output_port).bind(p_id, i, !vsnode->_is_output_port_expanded(i)), CONNECT_DEFERRED);
  1038. hb->add_child(expand);
  1039. }
  1040. if (vsnode->has_output_port_preview(i) && port_right != VisualShaderNode::PORT_TYPE_TRANSFORM && port_right != VisualShaderNode::PORT_TYPE_SAMPLER) {
  1041. TextureButton *preview = memnew(TextureButton);
  1042. preview->set_accessibility_name(TTRC("Select preview port"));
  1043. preview->set_toggle_mode(true);
  1044. preview->set_texture_normal(editor->get_editor_theme_icon(SNAME("GuiVisibilityHidden")));
  1045. preview->set_texture_pressed(editor->get_editor_theme_icon(SNAME("GuiVisibilityVisible")));
  1046. preview->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  1047. register_output_port(p_id, j, port_right, preview);
  1048. preview->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_preview_select_port).bind(p_id, j), CONNECT_DEFERRED);
  1049. hb->add_child(preview);
  1050. }
  1051. }
  1052. if (is_group) {
  1053. offset = memnew(Control);
  1054. offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  1055. node->add_child(offset);
  1056. port_offset++;
  1057. }
  1058. if (!is_first_hbox && !is_reroute) {
  1059. node->add_child(hb);
  1060. if (curve_xyz.is_valid()) {
  1061. node->move_child(hb, 1 + expanded_port_counter);
  1062. }
  1063. }
  1064. if (expanded_type != VisualShaderNode::PORT_TYPE_SCALAR) {
  1065. continue;
  1066. }
  1067. int idx = is_first_hbox ? 1 : i + port_offset;
  1068. if (is_reroute) {
  1069. idx = 0;
  1070. }
  1071. if (!is_frame) {
  1072. GraphNode *graph_node = Object::cast_to<GraphNode>(node);
  1073. graph_node->set_slot(idx, valid_left, port_left, type_color[port_left], valid_right, port_right, type_color[port_right]);
  1074. if (vsnode->_is_output_port_expanded(i)) {
  1075. switch (vsnode->get_output_port_type(i)) {
  1076. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  1077. port_offset++;
  1078. valid_left = (i + 1) < vsnode->get_input_port_count();
  1079. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1080. if (valid_left) {
  1081. port_left = vsnode->get_input_port_type(i + 1);
  1082. }
  1083. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]);
  1084. port_offset++;
  1085. valid_left = (i + 2) < vsnode->get_input_port_count();
  1086. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1087. if (valid_left) {
  1088. port_left = vsnode->get_input_port_type(i + 2);
  1089. }
  1090. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]);
  1091. expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_2D;
  1092. } break;
  1093. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  1094. port_offset++;
  1095. valid_left = (i + 1) < vsnode->get_input_port_count();
  1096. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1097. if (valid_left) {
  1098. port_left = vsnode->get_input_port_type(i + 1);
  1099. }
  1100. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]);
  1101. port_offset++;
  1102. valid_left = (i + 2) < vsnode->get_input_port_count();
  1103. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1104. if (valid_left) {
  1105. port_left = vsnode->get_input_port_type(i + 2);
  1106. }
  1107. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]);
  1108. port_offset++;
  1109. valid_left = (i + 3) < vsnode->get_input_port_count();
  1110. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1111. if (valid_left) {
  1112. port_left = vsnode->get_input_port_type(i + 3);
  1113. }
  1114. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]);
  1115. expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_3D;
  1116. } break;
  1117. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  1118. port_offset++;
  1119. valid_left = (i + 1) < vsnode->get_input_port_count();
  1120. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1121. if (valid_left) {
  1122. port_left = vsnode->get_input_port_type(i + 1);
  1123. }
  1124. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]);
  1125. port_offset++;
  1126. valid_left = (i + 2) < vsnode->get_input_port_count();
  1127. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1128. if (valid_left) {
  1129. port_left = vsnode->get_input_port_type(i + 2);
  1130. }
  1131. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]);
  1132. port_offset++;
  1133. valid_left = (i + 3) < vsnode->get_input_port_count();
  1134. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1135. if (valid_left) {
  1136. port_left = vsnode->get_input_port_type(i + 3);
  1137. }
  1138. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]);
  1139. port_offset++;
  1140. valid_left = (i + 4) < vsnode->get_input_port_count();
  1141. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  1142. if (valid_left) {
  1143. port_left = vsnode->get_input_port_type(i + 4);
  1144. }
  1145. graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[3]);
  1146. expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_4D;
  1147. } break;
  1148. default:
  1149. break;
  1150. }
  1151. }
  1152. }
  1153. }
  1154. bool has_relative_parameter_instances = false;
  1155. if (vsnode->get_output_port_for_preview() >= 0) {
  1156. has_relative_parameter_instances = is_node_has_parameter_instances_relatively(p_type, p_id);
  1157. show_port_preview(p_type, p_id, vsnode->get_output_port_for_preview(), !has_relative_parameter_instances);
  1158. } else if (!is_reroute) {
  1159. offset = memnew(Control);
  1160. offset->set_custom_minimum_size(Size2(0, 4 * EDSCALE));
  1161. node->add_child(offset);
  1162. }
  1163. String error = vsnode->get_warning(mode, p_type);
  1164. if (has_relative_parameter_instances) {
  1165. error += "\n" + TTR("The 2D preview cannot correctly show the result retrieved from instance parameter.");
  1166. }
  1167. if (!error.is_empty()) {
  1168. Label *error_label = memnew(Label);
  1169. error_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  1170. error_label->add_theme_color_override(SceneStringName(font_color), editor->get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
  1171. error_label->set_text(error);
  1172. error_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  1173. node->add_child(error_label);
  1174. }
  1175. if (is_expression) {
  1176. CodeEdit *expression_box = memnew(CodeEdit);
  1177. Ref<CodeHighlighter> expression_syntax_highlighter;
  1178. expression_syntax_highlighter.instantiate();
  1179. expression_node->set_ctrl_pressed(expression_box, 0);
  1180. expression_box->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1181. node->add_child(expression_box);
  1182. register_expression_edit(p_id, expression_box);
  1183. Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color");
  1184. Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color");
  1185. Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
  1186. Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color");
  1187. Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
  1188. Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color");
  1189. Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color");
  1190. Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color");
  1191. Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color");
  1192. expression_box->set_syntax_highlighter(expression_syntax_highlighter);
  1193. expression_box->add_theme_color_override("background_color", background_color);
  1194. for (const String &E : editor->keyword_list) {
  1195. if (ShaderLanguage::is_control_flow_keyword(E)) {
  1196. expression_syntax_highlighter->add_keyword_color(E, control_flow_keyword_color);
  1197. } else {
  1198. expression_syntax_highlighter->add_keyword_color(E, keyword_color);
  1199. }
  1200. }
  1201. expression_box->begin_bulk_theme_override();
  1202. expression_box->add_theme_font_override(SceneStringName(font), editor->get_theme_font(SNAME("expression"), EditorStringName(EditorFonts)));
  1203. expression_box->add_theme_font_size_override(SceneStringName(font_size), editor->get_theme_font_size(SNAME("expression_size"), EditorStringName(EditorFonts)));
  1204. expression_box->add_theme_color_override(SceneStringName(font_color), text_color);
  1205. expression_box->end_bulk_theme_override();
  1206. expression_syntax_highlighter->set_number_color(number_color);
  1207. expression_syntax_highlighter->set_symbol_color(symbol_color);
  1208. expression_syntax_highlighter->set_function_color(function_color);
  1209. expression_syntax_highlighter->set_member_variable_color(members_color);
  1210. expression_syntax_highlighter->add_color_region("/*", "*/", comment_color, false);
  1211. expression_syntax_highlighter->add_color_region("//", "", comment_color, true);
  1212. expression_box->clear_comment_delimiters();
  1213. expression_box->add_comment_delimiter("/*", "*/", false);
  1214. expression_box->add_comment_delimiter("//", "", true);
  1215. if (!expression_box->has_auto_brace_completion_open_key("/*")) {
  1216. expression_box->add_auto_brace_completion_pair("/*", "*/");
  1217. }
  1218. expression_box->set_text(expression);
  1219. expression_box->set_context_menu_enabled(false);
  1220. expression_box->set_draw_line_numbers(true);
  1221. expression_box->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_expression_focus_out).bind(expression_box, p_id));
  1222. }
  1223. }
  1224. void VisualShaderGraphPlugin::remove_node(VisualShader::Type p_type, int p_id, bool p_just_update) {
  1225. if (editor->get_current_shader_type() == p_type && links.has(p_id)) {
  1226. GraphEdit *graph_edit = editor->graph;
  1227. if (!graph_edit) {
  1228. return;
  1229. }
  1230. graph_edit->remove_child(links[p_id].graph_element);
  1231. memdelete(links[p_id].graph_element);
  1232. if (!p_just_update) {
  1233. links.erase(p_id);
  1234. }
  1235. }
  1236. }
  1237. void VisualShaderGraphPlugin::connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
  1238. GraphEdit *graph = editor->graph;
  1239. if (!graph) {
  1240. return;
  1241. }
  1242. if (visual_shader.is_valid() && editor->get_current_shader_type() == p_type) {
  1243. // Update reroute nodes since their port type might have changed.
  1244. Ref<VisualShaderNodeReroute> reroute_to = visual_shader->get_node(p_type, p_to_node);
  1245. Ref<VisualShaderNodeReroute> reroute_from = visual_shader->get_node(p_type, p_from_node);
  1246. if (reroute_to.is_valid() || reroute_from.is_valid()) {
  1247. update_reroute_nodes();
  1248. }
  1249. graph->connect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
  1250. connections.push_back({ p_from_node, p_from_port, p_to_node, p_to_port });
  1251. if (links[p_to_node].input_ports.has(p_to_port) && links[p_to_node].input_ports[p_to_port].default_input_button != nullptr) {
  1252. links[p_to_node].input_ports[p_to_port].default_input_button->hide();
  1253. }
  1254. }
  1255. }
  1256. void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
  1257. GraphEdit *graph = editor->graph;
  1258. if (!graph) {
  1259. return;
  1260. }
  1261. if (visual_shader.is_valid() && editor->get_current_shader_type() == p_type) {
  1262. graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
  1263. for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) {
  1264. 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) {
  1265. connections.erase(E);
  1266. break;
  1267. }
  1268. }
  1269. 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) {
  1270. links[p_to_node].input_ports[p_to_port].default_input_button->show();
  1271. 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));
  1272. }
  1273. }
  1274. }
  1275. /////////////////
  1276. void VisualShaderEditedProperty::_bind_methods() {
  1277. ClassDB::bind_method(D_METHOD("set_edited_property", "value"), &VisualShaderEditedProperty::set_edited_property);
  1278. ClassDB::bind_method(D_METHOD("get_edited_property"), &VisualShaderEditedProperty::get_edited_property);
  1279. ADD_PROPERTY(PropertyInfo(Variant::NIL, "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_edited_property", "get_edited_property");
  1280. }
  1281. void VisualShaderEditedProperty::set_edited_property(const Variant &p_variant) {
  1282. edited_property = p_variant;
  1283. }
  1284. Variant VisualShaderEditedProperty::get_edited_property() const {
  1285. return edited_property;
  1286. }
  1287. /////////////////
  1288. Vector2 VisualShaderEditor::selection_center;
  1289. List<VisualShaderEditor::CopyItem> VisualShaderEditor::copy_items_buffer;
  1290. List<VisualShader::Connection> VisualShaderEditor::copy_connections_buffer;
  1291. void VisualShaderEditor::edit_shader(const Ref<Shader> &p_shader) {
  1292. shader_fully_loaded = false;
  1293. bool changed = false;
  1294. VisualShader *visual_shader_ptr = Object::cast_to<VisualShader>(p_shader.ptr());
  1295. if (visual_shader_ptr) {
  1296. if (visual_shader.is_null()) {
  1297. changed = true;
  1298. } else {
  1299. if (visual_shader.ptr() != visual_shader_ptr) {
  1300. changed = true;
  1301. }
  1302. }
  1303. visual_shader = p_shader;
  1304. graph_plugin->register_shader(visual_shader.ptr());
  1305. visual_shader->connect_changed(callable_mp(this, &VisualShaderEditor::_update_preview));
  1306. _set_mode(visual_shader->get_mode());
  1307. preview_material->set_shader(visual_shader);
  1308. _update_nodes();
  1309. } else {
  1310. if (visual_shader.is_valid()) {
  1311. visual_shader->disconnect_changed(callable_mp(this, &VisualShaderEditor::_update_preview));
  1312. }
  1313. visual_shader.unref();
  1314. }
  1315. if (visual_shader.is_null()) {
  1316. hide();
  1317. } else {
  1318. if (changed) { // to avoid tree collapse
  1319. _update_varying_tree();
  1320. _update_options_menu();
  1321. _update_preview();
  1322. _update_graph();
  1323. callable_mp(this, &VisualShaderEditor::_restore_editor_state).call_deferred();
  1324. }
  1325. }
  1326. }
  1327. void VisualShaderEditor::apply_shaders() {
  1328. // Stub. TODO: Implement apply_shaders in visual shaders for parity with text shaders.
  1329. }
  1330. bool VisualShaderEditor::is_unsaved() const {
  1331. // Stub. TODO: Implement is_unsaved in visual shaders for parity with text shaders.
  1332. return false;
  1333. }
  1334. void VisualShaderEditor::save_external_data(const String &p_str) {
  1335. ResourceSaver::save(visual_shader, visual_shader->get_path());
  1336. }
  1337. void VisualShaderEditor::validate_script() {
  1338. if (visual_shader.is_valid()) {
  1339. _update_nodes();
  1340. }
  1341. }
  1342. void VisualShaderEditor::save_editor_layout() {
  1343. const String id_string = _get_cache_id_string();
  1344. const String offset_cache_key = _get_cache_key("offset");
  1345. const String zoom_cache_key = _get_cache_key("zoom");
  1346. vs_editor_cache->set_value(id_string, offset_cache_key, graph->get_scroll_offset() / EDSCALE);
  1347. vs_editor_cache->set_value(id_string, zoom_cache_key, graph->get_zoom());
  1348. vs_editor_cache->save(EditorPaths::get_singleton()->get_project_settings_dir().path_join("vs_editor_cache.cfg"));
  1349. }
  1350. void VisualShaderEditor::set_current_shader_type(VisualShader::Type p_type) {
  1351. current_type = p_type;
  1352. const String id_string = _get_cache_id_string();
  1353. vs_editor_cache->set_value(id_string, "edited_type", p_type);
  1354. vs_editor_cache->save(EditorPaths::get_singleton()->get_project_settings_dir().path_join("vs_editor_cache.cfg"));
  1355. const String offset_cache_key = _get_cache_key("offset");
  1356. const String zoom_cache_key = _get_cache_key("zoom");
  1357. const Vector2 saved_scroll_offset = vs_editor_cache->get_value(id_string, offset_cache_key, Vector2());
  1358. const real_t saved_zoom = vs_editor_cache->get_value(id_string, zoom_cache_key, 1.0);
  1359. graph->set_scroll_offset(saved_scroll_offset);
  1360. graph->set_zoom(saved_zoom);
  1361. }
  1362. VisualShader::Type VisualShaderEditor::get_current_shader_type() const {
  1363. return current_type;
  1364. }
  1365. Control *VisualShaderEditor::get_top_bar() {
  1366. return toolbar;
  1367. }
  1368. void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
  1369. if (plugins.has(p_plugin)) {
  1370. return;
  1371. }
  1372. plugins.push_back(p_plugin);
  1373. }
  1374. void VisualShaderEditor::remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
  1375. plugins.erase(p_plugin);
  1376. }
  1377. void VisualShaderEditor::clear_custom_types() {
  1378. for (int i = 0; i < add_options.size(); i++) {
  1379. if (add_options[i].is_custom) {
  1380. add_options.remove_at(i);
  1381. i--;
  1382. }
  1383. }
  1384. }
  1385. 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) {
  1386. ERR_FAIL_COND(!p_name.is_valid_ascii_identifier());
  1387. ERR_FAIL_COND(p_type.is_empty() && p_script.is_null());
  1388. for (int i = 0; i < add_options.size(); i++) {
  1389. const AddOption &op = add_options[i];
  1390. if (op.is_custom) {
  1391. if (!p_type.is_empty()) {
  1392. if (op.type == p_type) {
  1393. return;
  1394. }
  1395. } else if (op.script == p_script) {
  1396. return;
  1397. }
  1398. }
  1399. }
  1400. AddOption ao;
  1401. ao.name = p_name;
  1402. ao.type = p_type;
  1403. ao.script = p_script;
  1404. ao.return_type = p_return_icon_type;
  1405. ao.description = p_description;
  1406. ao.category = p_category;
  1407. ao.highend = p_highend;
  1408. ao.is_custom = true;
  1409. ao.is_native = !p_type.is_empty();
  1410. bool begin = false;
  1411. String root = p_category.split("/")[0];
  1412. for (int i = 0; i < add_options.size(); i++) {
  1413. if (add_options[i].is_custom) {
  1414. if (add_options[i].category == root) {
  1415. if (!begin) {
  1416. begin = true;
  1417. }
  1418. } else {
  1419. if (begin) {
  1420. add_options.insert(i, ao);
  1421. return;
  1422. }
  1423. }
  1424. }
  1425. }
  1426. add_options.push_back(ao);
  1427. }
  1428. Dictionary VisualShaderEditor::get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node) {
  1429. Dictionary dict;
  1430. dict["script"] = p_custom_node->get_script();
  1431. dict["name"] = p_custom_node->_get_name();
  1432. dict["description"] = p_custom_node->_get_description();
  1433. dict["return_icon_type"] = p_custom_node->_get_return_icon_type();
  1434. dict["highend"] = p_custom_node->_is_highend();
  1435. String category = p_custom_node->_get_category();
  1436. category = category.rstrip("/");
  1437. category = category.lstrip("/");
  1438. category = "Addons/" + category;
  1439. if (p_custom_node->has_method("_get_subcategory")) {
  1440. String subcategory = (String)p_custom_node->call("_get_subcategory");
  1441. if (!subcategory.is_empty()) {
  1442. category += "/" + subcategory;
  1443. }
  1444. }
  1445. dict["category"] = category;
  1446. return dict;
  1447. }
  1448. void VisualShaderEditor::_get_current_mode_limits(int &r_begin_type, int &r_end_type) const {
  1449. switch (visual_shader->get_mode()) {
  1450. case Shader::MODE_CANVAS_ITEM:
  1451. case Shader::MODE_SPATIAL: {
  1452. r_begin_type = VisualShader::TYPE_VERTEX;
  1453. r_end_type = VisualShader::TYPE_START;
  1454. } break;
  1455. case Shader::MODE_PARTICLES: {
  1456. r_begin_type = VisualShader::TYPE_START;
  1457. r_end_type = VisualShader::TYPE_SKY;
  1458. } break;
  1459. case Shader::MODE_SKY: {
  1460. r_begin_type = VisualShader::TYPE_SKY;
  1461. r_end_type = VisualShader::TYPE_FOG;
  1462. } break;
  1463. case Shader::MODE_FOG: {
  1464. r_begin_type = VisualShader::TYPE_FOG;
  1465. r_end_type = VisualShader::TYPE_MAX;
  1466. } break;
  1467. default: {
  1468. } break;
  1469. }
  1470. }
  1471. void VisualShaderEditor::_script_created(const Ref<Script> &p_script) {
  1472. if (p_script.is_null() || p_script->get_instance_base_type() != "VisualShaderNodeCustom") {
  1473. return;
  1474. }
  1475. Ref<VisualShaderNodeCustom> ref;
  1476. ref.instantiate();
  1477. ref->set_script(p_script);
  1478. Dictionary dict = get_custom_node_data(ref);
  1479. add_custom_type(dict["name"], String(), dict["script"], dict["description"], dict["return_icon_type"], dict["category"], dict["highend"]);
  1480. _update_options_menu();
  1481. }
  1482. void VisualShaderEditor::_update_custom_script(const Ref<Script> &p_script) {
  1483. if (p_script.is_null() || p_script->get_instance_base_type() != "VisualShaderNodeCustom") {
  1484. return;
  1485. }
  1486. Ref<VisualShaderNodeCustom> ref;
  1487. ref.instantiate();
  1488. ref->set_script(p_script);
  1489. if (!ref->is_available(visual_shader->get_mode(), get_current_shader_type())) {
  1490. for (int i = 0; i < add_options.size(); i++) {
  1491. if (add_options[i].is_custom && add_options[i].script == p_script) {
  1492. add_options.remove_at(i);
  1493. _update_options_menu();
  1494. // TODO: Make indication for the existed custom nodes with that script on graph to be disabled.
  1495. break;
  1496. }
  1497. }
  1498. return;
  1499. }
  1500. Dictionary dict = get_custom_node_data(ref);
  1501. bool found_type = false;
  1502. bool need_rebuild = false;
  1503. for (int i = custom_node_option_idx; i < add_options.size(); i++) {
  1504. if (add_options[i].script == p_script) {
  1505. found_type = true;
  1506. add_options.write[i].name = dict["name"];
  1507. add_options.write[i].return_type = dict["return_icon_type"];
  1508. add_options.write[i].description = dict["description"];
  1509. add_options.write[i].category = dict["category"];
  1510. add_options.write[i].highend = dict["highend"];
  1511. int begin_type = 0;
  1512. int end_type = 0;
  1513. _get_current_mode_limits(begin_type, end_type);
  1514. for (int t = begin_type; t < end_type; t++) {
  1515. VisualShader::Type type = (VisualShader::Type)t;
  1516. Vector<int> nodes = visual_shader->get_node_list(type);
  1517. List<VisualShader::Connection> node_connections;
  1518. visual_shader->get_node_connections(type, &node_connections);
  1519. List<VisualShader::Connection> custom_node_input_connections;
  1520. List<VisualShader::Connection> custom_node_output_connections;
  1521. for (const VisualShader::Connection &E : node_connections) {
  1522. int from = E.from_node;
  1523. int from_port = E.from_port;
  1524. int to = E.to_node;
  1525. int to_port = E.to_port;
  1526. if (graph_plugin->get_node_script(from) == p_script) {
  1527. custom_node_output_connections.push_back({ from, from_port, to, to_port });
  1528. } else if (graph_plugin->get_node_script(to) == p_script) {
  1529. custom_node_input_connections.push_back({ from, from_port, to, to_port });
  1530. }
  1531. }
  1532. for (int node_id : nodes) {
  1533. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  1534. if (vsnode.is_null()) {
  1535. continue;
  1536. }
  1537. Ref<VisualShaderNodeCustom> custom_node = vsnode;
  1538. if (custom_node.is_null() || custom_node->get_script() != p_script) {
  1539. continue;
  1540. }
  1541. need_rebuild = true;
  1542. // Removes invalid connections.
  1543. {
  1544. int prev_input_port_count = custom_node->get_input_port_count();
  1545. int prev_output_port_count = custom_node->get_output_port_count();
  1546. custom_node->update_ports();
  1547. int input_port_count = custom_node->get_input_port_count();
  1548. int output_port_count = custom_node->get_output_port_count();
  1549. if (output_port_count != prev_output_port_count) {
  1550. for (const VisualShader::Connection &E : custom_node_output_connections) {
  1551. int from = E.from_node;
  1552. int from_idx = E.from_port;
  1553. int to = E.to_node;
  1554. int to_idx = E.to_port;
  1555. if (from_idx >= output_port_count) {
  1556. visual_shader->disconnect_nodes(type, from, from_idx, to, to_idx);
  1557. graph_plugin->disconnect_nodes(type, from, from_idx, to, to_idx);
  1558. }
  1559. }
  1560. }
  1561. if (input_port_count != prev_input_port_count) {
  1562. for (const VisualShader::Connection &E : custom_node_input_connections) {
  1563. int from = E.from_node;
  1564. int from_idx = E.from_port;
  1565. int to = E.to_node;
  1566. int to_idx = E.to_port;
  1567. if (to_idx >= input_port_count) {
  1568. visual_shader->disconnect_nodes(type, from, from_idx, to, to_idx);
  1569. graph_plugin->disconnect_nodes(type, from, from_idx, to, to_idx);
  1570. }
  1571. }
  1572. }
  1573. }
  1574. graph_plugin->update_node(type, node_id);
  1575. }
  1576. }
  1577. break;
  1578. }
  1579. }
  1580. if (!found_type) {
  1581. add_custom_type(dict["name"], String(), dict["script"], dict["description"], dict["return_icon_type"], dict["category"], dict["highend"]);
  1582. }
  1583. // To prevent updating options multiple times when multiple scripts are saved.
  1584. if (!_block_update_options_menu) {
  1585. _block_update_options_menu = true;
  1586. callable_mp(this, &VisualShaderEditor::_update_options_menu_deferred);
  1587. }
  1588. // To prevent rebuilding the shader multiple times when multiple scripts are saved.
  1589. if (need_rebuild && !_block_rebuild_shader) {
  1590. _block_rebuild_shader = true;
  1591. callable_mp(this, &VisualShaderEditor::_rebuild_shader_deferred);
  1592. }
  1593. }
  1594. void VisualShaderEditor::_resource_saved(const Ref<Resource> &p_resource) {
  1595. _update_custom_script(Ref<Script>(p_resource.ptr()));
  1596. }
  1597. void VisualShaderEditor::_resources_removed() {
  1598. bool has_any_instance = false;
  1599. for (const Ref<Script> &scr : custom_scripts_to_delete) {
  1600. for (int i = custom_node_option_idx; i < add_options.size(); i++) {
  1601. if (add_options[i].script == scr) {
  1602. add_options.remove_at(i);
  1603. // Removes all node instances using that script from the graph.
  1604. {
  1605. int begin_type = 0;
  1606. int end_type = 0;
  1607. _get_current_mode_limits(begin_type, end_type);
  1608. for (int t = begin_type; t < end_type; t++) {
  1609. VisualShader::Type type = (VisualShader::Type)t;
  1610. List<VisualShader::Connection> node_connections;
  1611. visual_shader->get_node_connections(type, &node_connections);
  1612. for (const VisualShader::Connection &E : node_connections) {
  1613. int from = E.from_node;
  1614. int from_port = E.from_port;
  1615. int to = E.to_node;
  1616. int to_port = E.to_port;
  1617. if (graph_plugin->get_node_script(from) == scr || graph_plugin->get_node_script(to) == scr) {
  1618. visual_shader->disconnect_nodes(type, from, from_port, to, to_port);
  1619. graph_plugin->disconnect_nodes(type, from, from_port, to, to_port);
  1620. }
  1621. }
  1622. Vector<int> nodes = visual_shader->get_node_list(type);
  1623. for (int node_id : nodes) {
  1624. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  1625. if (vsnode.is_null()) {
  1626. continue;
  1627. }
  1628. Ref<VisualShaderNodeCustom> custom_node = vsnode;
  1629. if (custom_node.is_null() || custom_node->get_script() != scr) {
  1630. continue;
  1631. }
  1632. visual_shader->remove_node(type, node_id);
  1633. graph_plugin->remove_node(type, node_id, false);
  1634. has_any_instance = true;
  1635. }
  1636. }
  1637. }
  1638. break;
  1639. }
  1640. }
  1641. }
  1642. if (has_any_instance) {
  1643. 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).
  1644. ResourceSaver::save(visual_shader, visual_shader->get_path());
  1645. }
  1646. _update_options_menu();
  1647. custom_scripts_to_delete.clear();
  1648. pending_custom_scripts_to_delete = false;
  1649. }
  1650. void VisualShaderEditor::_resource_removed(const Ref<Resource> &p_resource) {
  1651. Ref<Script> scr = Ref<Script>(p_resource.ptr());
  1652. if (scr.is_null() || scr->get_instance_base_type() != "VisualShaderNodeCustom") {
  1653. return;
  1654. }
  1655. custom_scripts_to_delete.push_back(scr);
  1656. if (!pending_custom_scripts_to_delete) {
  1657. pending_custom_scripts_to_delete = true;
  1658. callable_mp(this, &VisualShaderEditor::_resources_removed).call_deferred();
  1659. }
  1660. }
  1661. void VisualShaderEditor::_update_options_menu_deferred() {
  1662. _update_options_menu();
  1663. _block_update_options_menu = false;
  1664. }
  1665. void VisualShaderEditor::_rebuild_shader_deferred() {
  1666. if (visual_shader.is_valid()) {
  1667. visual_shader->rebuild();
  1668. }
  1669. _block_rebuild_shader = false;
  1670. }
  1671. bool VisualShaderEditor::_is_available(int p_mode) {
  1672. int current_mode = edit_type->get_selected();
  1673. if (p_mode != -1) {
  1674. switch (current_mode) {
  1675. case 0: // Vertex / Emit
  1676. current_mode = 1;
  1677. break;
  1678. case 1: // Fragment / Process
  1679. current_mode = 2;
  1680. break;
  1681. case 2: // Light / Collide
  1682. current_mode = 4;
  1683. break;
  1684. default:
  1685. break;
  1686. }
  1687. }
  1688. return (p_mode == -1 || (p_mode & current_mode) != 0);
  1689. }
  1690. bool VisualShaderEditor::_update_preview_parameter_tree() {
  1691. bool found = false;
  1692. bool use_filter = !param_filter_name.is_empty();
  1693. parameters->clear();
  1694. TreeItem *root = parameters->create_item();
  1695. for (const KeyValue<String, PropertyInfo> &prop : parameter_props) {
  1696. String param_name = prop.value.name;
  1697. if (use_filter && !param_name.containsn(param_filter_name)) {
  1698. continue;
  1699. }
  1700. TreeItem *item = parameters->create_item(root);
  1701. item->set_text(0, param_name);
  1702. item->set_meta("id", param_name);
  1703. if (param_name == selected_param_id) {
  1704. parameters->set_selected(item);
  1705. found = true;
  1706. }
  1707. if (prop.value.type == Variant::OBJECT) {
  1708. item->set_icon(0, get_editor_theme_icon(SNAME("ImageTexture")));
  1709. } else {
  1710. item->set_icon(0, get_editor_theme_icon(Variant::get_type_name(prop.value.type)));
  1711. }
  1712. }
  1713. return found;
  1714. }
  1715. void VisualShaderEditor::_preview_tools_menu_option(int p_idx) {
  1716. ShaderMaterial *src_mat = nullptr;
  1717. if (p_idx == COPY_PARAMS_FROM_MATERIAL || p_idx == PASTE_PARAMS_TO_MATERIAL) {
  1718. for (int i = EditorNode::get_singleton()->get_editor_selection_history()->get_path_size() - 1; i >= 0; i--) {
  1719. Object *object = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_selection_history()->get_path_object(i));
  1720. ShaderMaterial *src_mat2;
  1721. if (!object) {
  1722. continue;
  1723. }
  1724. if (object->has_method("get_material_override")) { // Trying to get material from MeshInstance.
  1725. src_mat2 = Object::cast_to<ShaderMaterial>(object->call("get_material_override"));
  1726. } else if (object->has_method("get_material")) { // From CanvasItem/Node2D.
  1727. src_mat2 = Object::cast_to<ShaderMaterial>(object->call("get_material"));
  1728. } else {
  1729. src_mat2 = Object::cast_to<ShaderMaterial>(object);
  1730. }
  1731. if (src_mat2 && src_mat2->get_shader().is_valid() && src_mat2->get_shader() == visual_shader) {
  1732. src_mat = src_mat2;
  1733. break;
  1734. }
  1735. }
  1736. }
  1737. switch (p_idx) {
  1738. case COPY_PARAMS_FROM_MATERIAL:
  1739. if (src_mat) {
  1740. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1741. undo_redo->create_action(TTR("Copy Preview Shader Parameters From Material"));
  1742. List<PropertyInfo> params;
  1743. preview_material->get_shader()->get_shader_uniform_list(&params);
  1744. for (const PropertyInfo &E : params) {
  1745. undo_redo->add_do_method(visual_shader.ptr(), "_set_preview_shader_parameter", E.name, src_mat->get_shader_parameter(E.name));
  1746. undo_redo->add_undo_method(visual_shader.ptr(), "_set_preview_shader_parameter", E.name, preview_material->get_shader_parameter(E.name));
  1747. }
  1748. undo_redo->commit_action();
  1749. }
  1750. break;
  1751. case PASTE_PARAMS_TO_MATERIAL:
  1752. if (src_mat) {
  1753. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1754. undo_redo->create_action(TTR("Paste Preview Shader Parameters To Material"));
  1755. List<PropertyInfo> params;
  1756. preview_material->get_shader()->get_shader_uniform_list(&params);
  1757. for (const PropertyInfo &E : params) {
  1758. undo_redo->add_do_method(src_mat, "set_shader_parameter", E.name, preview_material->get_shader_parameter(E.name));
  1759. undo_redo->add_undo_method(src_mat, "set_shader_parameter", E.name, src_mat->get_shader_parameter(E.name));
  1760. }
  1761. undo_redo->commit_action();
  1762. }
  1763. break;
  1764. default:
  1765. break;
  1766. }
  1767. }
  1768. void VisualShaderEditor::_clear_preview_param() {
  1769. selected_param_id = "";
  1770. current_prop = nullptr;
  1771. if (param_vbox2->get_child_count() > 0) {
  1772. param_vbox2->remove_child(param_vbox2->get_child(0));
  1773. }
  1774. param_vbox->hide();
  1775. }
  1776. void VisualShaderEditor::_update_preview_parameter_list() {
  1777. material_editor->edit(preview_material.ptr(), env);
  1778. List<PropertyInfo> properties;
  1779. RenderingServer::get_singleton()->get_shader_parameter_list(visual_shader->get_rid(), &properties);
  1780. HashSet<String> params_to_remove;
  1781. for (const KeyValue<String, PropertyInfo> &E : parameter_props) {
  1782. params_to_remove.insert(E.key);
  1783. }
  1784. parameter_props.clear();
  1785. for (const PropertyInfo &prop : properties) {
  1786. String param_name = prop.name;
  1787. if (visual_shader->_has_preview_shader_parameter(param_name)) {
  1788. preview_material->set_shader_parameter(param_name, visual_shader->_get_preview_shader_parameter(param_name));
  1789. } else {
  1790. preview_material->set_shader_parameter(param_name, RenderingServer::get_singleton()->shader_get_parameter_default(visual_shader->get_rid(), param_name));
  1791. }
  1792. parameter_props.insert(param_name, prop);
  1793. params_to_remove.erase(param_name);
  1794. if (param_name == selected_param_id) {
  1795. current_prop->update_property();
  1796. current_prop->update_editor_property_status();
  1797. current_prop->update_cache();
  1798. }
  1799. }
  1800. _update_preview_parameter_tree();
  1801. // Removes invalid parameters.
  1802. for (const String &param_name : params_to_remove) {
  1803. preview_material->set_shader_parameter(param_name, Variant());
  1804. if (visual_shader->_has_preview_shader_parameter(param_name)) {
  1805. visual_shader->_set_preview_shader_parameter(param_name, Variant());
  1806. }
  1807. if (param_name == selected_param_id) {
  1808. _clear_preview_param();
  1809. }
  1810. }
  1811. }
  1812. void VisualShaderEditor::_update_nodes() {
  1813. clear_custom_types();
  1814. Dictionary added;
  1815. // Add GDScript classes.
  1816. {
  1817. List<StringName> class_list;
  1818. ScriptServer::get_global_class_list(&class_list);
  1819. for (const StringName &E : class_list) {
  1820. if (ScriptServer::get_global_class_native_base(E) == "VisualShaderNodeCustom") {
  1821. String script_path = ScriptServer::get_global_class_path(E);
  1822. Ref<Resource> res = ResourceLoader::load(script_path);
  1823. ERR_CONTINUE(res.is_null());
  1824. ERR_CONTINUE(!res->is_class("Script"));
  1825. Ref<Script> scr = Ref<Script>(res);
  1826. Ref<VisualShaderNodeCustom> ref;
  1827. ref.instantiate();
  1828. ref->set_script(scr);
  1829. if (!ref->is_available(visual_shader->get_mode(), get_current_shader_type())) {
  1830. continue;
  1831. }
  1832. Dictionary dict = get_custom_node_data(ref);
  1833. dict["type"] = String();
  1834. String key;
  1835. key = String(dict["category"]) + "/" + String(dict["name"]);
  1836. added[key] = dict;
  1837. }
  1838. }
  1839. }
  1840. // Add GDExtension classes.
  1841. {
  1842. List<StringName> class_list;
  1843. ClassDB::get_class_list(&class_list);
  1844. for (const StringName &E : class_list) {
  1845. if (ClassDB::get_parent_class(E) == "VisualShaderNodeCustom") {
  1846. Object *instance = ClassDB::instantiate(E);
  1847. Ref<VisualShaderNodeCustom> ref = Object::cast_to<VisualShaderNodeCustom>(instance);
  1848. ERR_CONTINUE(ref.is_null());
  1849. if (!ref->is_available(visual_shader->get_mode(), get_current_shader_type())) {
  1850. continue;
  1851. }
  1852. Dictionary dict = get_custom_node_data(ref);
  1853. dict["type"] = E;
  1854. dict["script"] = Ref<Script>();
  1855. String key;
  1856. key = String(dict["category"]) + "/" + String(dict["name"]);
  1857. added[key] = dict;
  1858. }
  1859. }
  1860. }
  1861. // Disables not-supported copied items.
  1862. {
  1863. for (CopyItem &item : copy_items_buffer) {
  1864. Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(item.node.ptr());
  1865. if (custom.is_valid()) {
  1866. if (!custom->is_available(visual_shader->get_mode(), get_current_shader_type())) {
  1867. item.disabled = true;
  1868. } else {
  1869. item.disabled = false;
  1870. }
  1871. } else {
  1872. for (int i = 0; i < add_options.size(); i++) {
  1873. if (add_options[i].type == item.node->get_class_name()) {
  1874. if ((add_options[i].func != visual_shader->get_mode() && add_options[i].func != -1) || !_is_available(add_options[i].mode)) {
  1875. item.disabled = true;
  1876. } else {
  1877. item.disabled = false;
  1878. }
  1879. break;
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. LocalVector<Variant> keys = added.get_key_list();
  1886. keys.sort_custom<StringLikeVariantOrder>();
  1887. for (const Variant &key : keys) {
  1888. const Dictionary &value = (Dictionary)added[key];
  1889. add_custom_type(value["name"], value["type"], value["script"], value["description"], value["return_icon_type"], value["category"], value["highend"]);
  1890. }
  1891. _update_options_menu();
  1892. }
  1893. String VisualShaderEditor::_get_description(int p_idx) {
  1894. return add_options[p_idx].description;
  1895. }
  1896. void VisualShaderEditor::_update_options_menu() {
  1897. node_desc->set_text("");
  1898. highend_label->set_visible(false);
  1899. members_dialog->get_ok_button()->set_disabled(true);
  1900. members->clear();
  1901. TreeItem *root = members->create_item();
  1902. String filter = node_filter->get_text().strip_edges();
  1903. bool use_filter = !filter.is_empty();
  1904. bool is_first_item = true;
  1905. Color unsupported_color = get_theme_color(SNAME("error_color"), EditorStringName(Editor));
  1906. Color supported_color = get_theme_color(SNAME("warning_color"), EditorStringName(Editor));
  1907. static bool low_driver = GLOBAL_GET("rendering/renderer/rendering_method") == "gl_compatibility";
  1908. HashMap<String, TreeItem *> folders;
  1909. int current_func = -1;
  1910. if (visual_shader.is_valid()) {
  1911. current_func = visual_shader->get_mode();
  1912. }
  1913. Vector<AddOption> custom_options;
  1914. Vector<AddOption> embedded_options;
  1915. static Vector<String> type_filter_exceptions;
  1916. if (type_filter_exceptions.is_empty()) {
  1917. type_filter_exceptions.append("VisualShaderNodeExpression");
  1918. type_filter_exceptions.append("VisualShaderNodeReroute");
  1919. }
  1920. for (int i = 0; i < add_options.size(); i++) {
  1921. if (!use_filter || add_options[i].name.containsn(filter)) {
  1922. // port type filtering
  1923. if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX || members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1924. Ref<VisualShaderNode> vsn;
  1925. int check_result = 0;
  1926. if (!add_options[i].is_custom) {
  1927. vsn = Ref<VisualShaderNode>(Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[i].type)));
  1928. if (vsn.is_null()) {
  1929. continue;
  1930. }
  1931. if (type_filter_exceptions.has(add_options[i].type)) {
  1932. check_result = 1;
  1933. }
  1934. Ref<VisualShaderNodeInput> input = Object::cast_to<VisualShaderNodeInput>(vsn.ptr());
  1935. if (input.is_valid()) {
  1936. input->set_shader_mode(visual_shader->get_mode());
  1937. input->set_shader_type(get_current_shader_type());
  1938. if (!add_options[i].ops.is_empty() && add_options[i].ops[0].is_string()) {
  1939. input->set_input_name((String)add_options[i].ops[0]);
  1940. }
  1941. }
  1942. Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(vsn.ptr());
  1943. if (expression.is_valid()) {
  1944. if (members_input_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) {
  1945. check_result = -1; // expressions creates a port with required type automatically (except for sampler output)
  1946. }
  1947. }
  1948. Ref<VisualShaderNodeParameterRef> parameter_ref = Object::cast_to<VisualShaderNodeParameterRef>(vsn.ptr());
  1949. if (parameter_ref.is_valid() && parameter_ref->is_shader_valid()) {
  1950. check_result = -1;
  1951. if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1952. for (int j = 0; j < parameter_ref->get_parameters_count(); j++) {
  1953. if (visual_shader->is_port_types_compatible(parameter_ref->get_port_type_by_index(j), members_input_port_type)) {
  1954. check_result = 1;
  1955. break;
  1956. }
  1957. }
  1958. }
  1959. }
  1960. } else {
  1961. check_result = 1;
  1962. }
  1963. if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1964. if (check_result == 0) {
  1965. for (int j = 0; j < vsn->get_input_port_count(); j++) {
  1966. if (visual_shader->is_port_types_compatible(vsn->get_input_port_type(j), members_output_port_type)) {
  1967. check_result = 1;
  1968. break;
  1969. }
  1970. }
  1971. }
  1972. if (check_result != 1) {
  1973. continue;
  1974. }
  1975. }
  1976. if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1977. if (check_result == 0) {
  1978. for (int j = 0; j < vsn->get_output_port_count(); j++) {
  1979. if (visual_shader->is_port_types_compatible(vsn->get_output_port_type(j), members_input_port_type)) {
  1980. check_result = 1;
  1981. break;
  1982. }
  1983. }
  1984. }
  1985. if (check_result != 1) {
  1986. continue;
  1987. }
  1988. }
  1989. }
  1990. if ((add_options[i].func != current_func && add_options[i].func != -1) || !_is_available(add_options[i].mode)) {
  1991. continue;
  1992. }
  1993. add_options[i].temp_idx = i; // save valid id
  1994. if (add_options[i].is_custom) {
  1995. custom_options.push_back(add_options[i]);
  1996. } else {
  1997. embedded_options.push_back(add_options[i]);
  1998. }
  1999. }
  2000. }
  2001. Vector<AddOption> options;
  2002. SortArray<AddOption, _OptionComparator> sorter;
  2003. sorter.sort(custom_options.ptrw(), custom_options.size());
  2004. options.append_array(custom_options);
  2005. options.append_array(embedded_options);
  2006. for (int i = 0; i < options.size(); i++) {
  2007. String path = options[i].category;
  2008. Vector<String> subfolders = path.split("/");
  2009. TreeItem *category = nullptr;
  2010. if (!folders.has(path)) {
  2011. category = root;
  2012. String path_temp = "";
  2013. for (int j = 0; j < subfolders.size(); j++) {
  2014. path_temp += subfolders[j];
  2015. if (!folders.has(path_temp)) {
  2016. category = members->create_item(category);
  2017. category->set_selectable(0, false);
  2018. category->set_collapsed(!use_filter);
  2019. category->set_text(0, subfolders[j]);
  2020. folders.insert(path_temp, category);
  2021. } else {
  2022. category = folders[path_temp];
  2023. }
  2024. }
  2025. } else {
  2026. category = folders[path];
  2027. }
  2028. TreeItem *item = members->create_item(category);
  2029. if (options[i].highend && low_driver) {
  2030. item->set_custom_color(0, unsupported_color);
  2031. } else if (options[i].highend) {
  2032. item->set_custom_color(0, supported_color);
  2033. }
  2034. item->set_text(0, options[i].name);
  2035. if (is_first_item && use_filter) {
  2036. item->select(0);
  2037. node_desc->set_text(options[i].description);
  2038. is_first_item = false;
  2039. members_dialog->get_ok_button()->set_disabled(false);
  2040. }
  2041. switch (options[i].return_type) {
  2042. case VisualShaderNode::PORT_TYPE_SCALAR:
  2043. item->set_icon(0, get_editor_theme_icon(SNAME("float")));
  2044. break;
  2045. case VisualShaderNode::PORT_TYPE_SCALAR_INT:
  2046. item->set_icon(0, get_editor_theme_icon(SNAME("int")));
  2047. break;
  2048. case VisualShaderNode::PORT_TYPE_SCALAR_UINT:
  2049. item->set_icon(0, get_editor_theme_icon(SNAME("uint")));
  2050. break;
  2051. case VisualShaderNode::PORT_TYPE_VECTOR_2D:
  2052. item->set_icon(0, get_editor_theme_icon(SNAME("Vector2")));
  2053. break;
  2054. case VisualShaderNode::PORT_TYPE_VECTOR_3D:
  2055. item->set_icon(0, get_editor_theme_icon(SNAME("Vector3")));
  2056. break;
  2057. case VisualShaderNode::PORT_TYPE_VECTOR_4D:
  2058. item->set_icon(0, get_editor_theme_icon(SNAME("Vector4")));
  2059. break;
  2060. case VisualShaderNode::PORT_TYPE_BOOLEAN:
  2061. item->set_icon(0, get_editor_theme_icon(SNAME("bool")));
  2062. break;
  2063. case VisualShaderNode::PORT_TYPE_TRANSFORM:
  2064. item->set_icon(0, get_editor_theme_icon(SNAME("Transform3D")));
  2065. break;
  2066. case VisualShaderNode::PORT_TYPE_SAMPLER:
  2067. item->set_icon(0, get_editor_theme_icon(SNAME("ImageTexture")));
  2068. break;
  2069. default:
  2070. break;
  2071. }
  2072. item->set_meta("id", options[i].temp_idx);
  2073. }
  2074. }
  2075. void VisualShaderEditor::_set_mode(int p_which) {
  2076. if (p_which == VisualShader::MODE_SKY) {
  2077. edit_type_standard->set_visible(false);
  2078. edit_type_particles->set_visible(false);
  2079. edit_type_sky->set_visible(true);
  2080. edit_type_fog->set_visible(false);
  2081. edit_type = edit_type_sky;
  2082. custom_mode_box->set_visible(false);
  2083. varying_button->hide();
  2084. mode = MODE_FLAGS_SKY;
  2085. } else if (p_which == VisualShader::MODE_FOG) {
  2086. edit_type_standard->set_visible(false);
  2087. edit_type_particles->set_visible(false);
  2088. edit_type_sky->set_visible(false);
  2089. edit_type_fog->set_visible(true);
  2090. edit_type = edit_type_fog;
  2091. custom_mode_box->set_visible(false);
  2092. varying_button->hide();
  2093. mode = MODE_FLAGS_FOG;
  2094. } else if (p_which == VisualShader::MODE_PARTICLES) {
  2095. edit_type_standard->set_visible(false);
  2096. edit_type_particles->set_visible(true);
  2097. edit_type_sky->set_visible(false);
  2098. edit_type_fog->set_visible(false);
  2099. edit_type = edit_type_particles;
  2100. if ((edit_type->get_selected() + 3) > VisualShader::TYPE_PROCESS) {
  2101. custom_mode_box->set_visible(false);
  2102. } else {
  2103. custom_mode_box->set_visible(true);
  2104. }
  2105. varying_button->hide();
  2106. mode = MODE_FLAGS_PARTICLES;
  2107. } else {
  2108. edit_type_particles->set_visible(false);
  2109. edit_type_standard->set_visible(true);
  2110. edit_type_sky->set_visible(false);
  2111. edit_type_fog->set_visible(false);
  2112. edit_type = edit_type_standard;
  2113. custom_mode_box->set_visible(false);
  2114. varying_button->show();
  2115. mode = MODE_FLAGS_SPATIAL_CANVASITEM;
  2116. }
  2117. const String id_string = _get_cache_id_string();
  2118. int default_type = VisualShader::TYPE_VERTEX;
  2119. int upper_type = VisualShader::TYPE_START;
  2120. if (mode & MODE_FLAGS_PARTICLES) {
  2121. default_type = VisualShader::TYPE_START;
  2122. upper_type = VisualShader::TYPE_SKY;
  2123. } else if (mode & MODE_FLAGS_SKY) {
  2124. default_type = VisualShader::TYPE_SKY;
  2125. upper_type = VisualShader::TYPE_FOG;
  2126. } else if (mode & MODE_FLAGS_FOG) {
  2127. default_type = VisualShader::TYPE_FOG;
  2128. upper_type = VisualShader::TYPE_MAX;
  2129. }
  2130. int saved_type = vs_editor_cache->get_value(id_string, "edited_type", default_type);
  2131. if (saved_type >= upper_type || saved_type < default_type) {
  2132. saved_type = default_type;
  2133. }
  2134. if (mode & MODE_FLAGS_PARTICLES && saved_type - default_type >= 3) {
  2135. edit_type->select(saved_type - default_type - 3);
  2136. custom_mode_box->set_pressed(true);
  2137. } else {
  2138. edit_type->select(saved_type - default_type);
  2139. }
  2140. set_current_shader_type((VisualShader::Type)saved_type);
  2141. }
  2142. Size2 VisualShaderEditor::get_minimum_size() const {
  2143. return Size2(10, 200);
  2144. }
  2145. void VisualShaderEditor::update_toggle_files_button() {
  2146. ERR_FAIL_NULL(toggle_files_list);
  2147. bool forward = toggle_files_list->is_visible() == is_layout_rtl();
  2148. toggle_files_button->set_button_icon(get_editor_theme_icon(forward ? SNAME("Forward") : SNAME("Back")));
  2149. toggle_files_button->set_tooltip_text(vformat("%s (%s)", TTR("Toggle Files Panel"), ED_GET_SHORTCUT("script_editor/toggle_files_panel")->get_as_text()));
  2150. }
  2151. void VisualShaderEditor::_draw_color_over_button(Object *p_obj, Color p_color) {
  2152. Button *button = Object::cast_to<Button>(p_obj);
  2153. if (!button) {
  2154. return;
  2155. }
  2156. Ref<StyleBox> normal = get_theme_stylebox(CoreStringName(normal), SNAME("Button"));
  2157. button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
  2158. }
  2159. void VisualShaderEditor::_update_parameters(bool p_update_refs) {
  2160. VisualShaderNodeParameterRef::clear_parameters(visual_shader->get_rid());
  2161. for (int t = 0; t < VisualShader::TYPE_MAX; t++) {
  2162. Vector<int> tnodes = visual_shader->get_node_list((VisualShader::Type)t);
  2163. for (int i = 0; i < tnodes.size(); i++) {
  2164. Ref<VisualShaderNode> vsnode = visual_shader->get_node((VisualShader::Type)t, tnodes[i]);
  2165. Ref<VisualShaderNodeParameter> parameter = vsnode;
  2166. if (parameter.is_valid()) {
  2167. Ref<VisualShaderNodeFloatParameter> float_parameter = vsnode;
  2168. Ref<VisualShaderNodeIntParameter> int_parameter = vsnode;
  2169. Ref<VisualShaderNodeUIntParameter> uint_parameter = vsnode;
  2170. Ref<VisualShaderNodeVec2Parameter> vec2_parameter = vsnode;
  2171. Ref<VisualShaderNodeVec3Parameter> vec3_parameter = vsnode;
  2172. Ref<VisualShaderNodeVec4Parameter> vec4_parameter = vsnode;
  2173. Ref<VisualShaderNodeColorParameter> color_parameter = vsnode;
  2174. Ref<VisualShaderNodeBooleanParameter> boolean_parameter = vsnode;
  2175. Ref<VisualShaderNodeTransformParameter> transform_parameter = vsnode;
  2176. VisualShaderNodeParameterRef::ParameterType parameter_type;
  2177. if (float_parameter.is_valid()) {
  2178. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_FLOAT;
  2179. } else if (int_parameter.is_valid()) {
  2180. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_INT;
  2181. } else if (uint_parameter.is_valid()) {
  2182. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_UINT;
  2183. } else if (boolean_parameter.is_valid()) {
  2184. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_BOOLEAN;
  2185. } else if (vec2_parameter.is_valid()) {
  2186. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR2;
  2187. } else if (vec3_parameter.is_valid()) {
  2188. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR3;
  2189. } else if (vec4_parameter.is_valid()) {
  2190. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR4;
  2191. } else if (transform_parameter.is_valid()) {
  2192. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_TRANSFORM;
  2193. } else if (color_parameter.is_valid()) {
  2194. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_COLOR;
  2195. } else {
  2196. parameter_type = VisualShaderNodeParameterRef::UNIFORM_TYPE_SAMPLER;
  2197. }
  2198. VisualShaderNodeParameterRef::add_parameter(visual_shader->get_rid(), parameter->get_parameter_name(), parameter_type);
  2199. }
  2200. }
  2201. }
  2202. if (p_update_refs) {
  2203. graph_plugin->update_parameter_refs();
  2204. }
  2205. }
  2206. void VisualShaderEditor::_update_parameter_refs(HashSet<String> &p_deleted_names) {
  2207. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2208. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  2209. VisualShader::Type type = VisualShader::Type(i);
  2210. Vector<int> nodes = visual_shader->get_node_list(type);
  2211. for (int j = 0; j < nodes.size(); j++) {
  2212. if (j > 0) {
  2213. Ref<VisualShaderNodeParameterRef> ref = visual_shader->get_node(type, nodes[j]);
  2214. if (ref.is_valid()) {
  2215. if (p_deleted_names.has(ref->get_parameter_name())) {
  2216. undo_redo->add_do_method(ref.ptr(), "set_parameter_name", "[None]");
  2217. undo_redo->add_undo_method(ref.ptr(), "set_parameter_name", ref->get_parameter_name());
  2218. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", VisualShader::Type(i), nodes[j]);
  2219. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", VisualShader::Type(i), nodes[j]);
  2220. }
  2221. }
  2222. }
  2223. }
  2224. }
  2225. }
  2226. void VisualShaderEditor::_update_graph() {
  2227. if (visual_shader.is_null()) {
  2228. return;
  2229. }
  2230. VisualShader::Type type = get_current_shader_type();
  2231. graph->clear_connections();
  2232. // Remove all nodes.
  2233. for (int i = 0; i < graph->get_child_count(); i++) {
  2234. if (Object::cast_to<GraphElement>(graph->get_child(i))) {
  2235. Node *node = graph->get_child(i);
  2236. graph->remove_child(node);
  2237. memdelete(node);
  2238. i--;
  2239. }
  2240. }
  2241. List<VisualShader::Connection> node_connections;
  2242. visual_shader->get_node_connections(type, &node_connections);
  2243. graph_plugin->set_connections(node_connections);
  2244. Vector<int> nodes = visual_shader->get_node_list(type);
  2245. _update_parameters(false);
  2246. _update_varyings();
  2247. graph_plugin->clear_links();
  2248. graph_plugin->update_theme();
  2249. for (int n_i = 0; n_i < nodes.size(); n_i++) {
  2250. // Update frame related stuff later since we need to have all nodes in the graph.
  2251. graph_plugin->add_node(type, nodes[n_i], false, false);
  2252. }
  2253. for (const VisualShader::Connection &E : node_connections) {
  2254. int from = E.from_node;
  2255. int from_idx = E.from_port;
  2256. int to = E.to_node;
  2257. int to_idx = E.to_port;
  2258. graph->connect_node(itos(from), from_idx, itos(to), to_idx);
  2259. }
  2260. // Attach nodes to frames.
  2261. for (int node_id : nodes) {
  2262. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  2263. ERR_CONTINUE_MSG(vsnode.is_null(), "Node is null.");
  2264. if (vsnode->get_frame() != -1) {
  2265. int frame_name = vsnode->get_frame();
  2266. graph->attach_graph_element_to_frame(itos(node_id), itos(frame_name));
  2267. }
  2268. }
  2269. float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity");
  2270. graph->set_minimap_opacity(graph_minimap_opacity);
  2271. float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature");
  2272. graph->set_connection_lines_curvature(graph_lines_curvature);
  2273. }
  2274. void VisualShaderEditor::_restore_editor_state() {
  2275. const String id_string = _get_cache_id_string();
  2276. const String offset_cache_key = _get_cache_key("offset");
  2277. const String zoom_cache_key = _get_cache_key("zoom");
  2278. const Vector2 saved_scroll_offset = vs_editor_cache->get_value(id_string, offset_cache_key, Vector2());
  2279. const real_t saved_zoom = vs_editor_cache->get_value(id_string, zoom_cache_key, 1.0);
  2280. // Setting the scroll offset needs to be further deferred because it requires min/max scroll offset to be final (as it gets clamped).
  2281. callable_mp(graph, &GraphEdit::set_zoom).call_deferred(saved_zoom);
  2282. callable_mp(graph, &GraphEdit::set_scroll_offset).call_deferred(saved_scroll_offset);
  2283. shader_fully_loaded = true;
  2284. }
  2285. String VisualShaderEditor::_get_cache_id_string() const {
  2286. String id_string = visual_shader->get_path();
  2287. const ResourceUID::ID uid = EditorFileSystem::get_singleton()->get_file_uid(id_string);
  2288. if (uid != ResourceUID::INVALID_ID) {
  2289. id_string = ResourceUID::get_singleton()->id_to_text(uid);
  2290. }
  2291. return id_string;
  2292. }
  2293. String VisualShaderEditor::_get_cache_key(const String &p_prop_name) const {
  2294. const int type = get_current_shader_type();
  2295. return "type" + itos(type) + ":" + p_prop_name;
  2296. }
  2297. void VisualShaderEditor::_add_input_port(int p_node, int p_port, int p_port_type, const String &p_name) {
  2298. VisualShader::Type type = get_current_shader_type();
  2299. Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node);
  2300. if (node.is_null()) {
  2301. return;
  2302. }
  2303. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2304. undo_redo->create_action(TTR("Add Input Port"));
  2305. undo_redo->add_do_method(node.ptr(), "add_input_port", p_port, p_port_type, p_name);
  2306. undo_redo->add_undo_method(node.ptr(), "remove_input_port", p_port);
  2307. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2308. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2309. undo_redo->commit_action();
  2310. }
  2311. void VisualShaderEditor::_add_output_port(int p_node, int p_port, int p_port_type, const String &p_name) {
  2312. VisualShader::Type type = get_current_shader_type();
  2313. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2314. if (node.is_null()) {
  2315. return;
  2316. }
  2317. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2318. undo_redo->create_action(TTR("Add Output Port"));
  2319. undo_redo->add_do_method(node.ptr(), "add_output_port", p_port, p_port_type, p_name);
  2320. undo_redo->add_undo_method(node.ptr(), "remove_output_port", p_port);
  2321. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2322. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2323. undo_redo->commit_action();
  2324. }
  2325. void VisualShaderEditor::_change_input_port_type(int p_type, int p_node, int p_port) {
  2326. VisualShader::Type type = get_current_shader_type();
  2327. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2328. if (node.is_null()) {
  2329. return;
  2330. }
  2331. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2332. undo_redo->create_action(TTR("Change Input Port Type"));
  2333. undo_redo->add_do_method(node.ptr(), "set_input_port_type", p_port, p_type);
  2334. undo_redo->add_undo_method(node.ptr(), "set_input_port_type", p_port, node->get_input_port_type(p_port));
  2335. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2336. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2337. undo_redo->commit_action();
  2338. }
  2339. void VisualShaderEditor::_change_output_port_type(int p_type, int p_node, int p_port) {
  2340. VisualShader::Type type = get_current_shader_type();
  2341. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2342. if (node.is_null()) {
  2343. return;
  2344. }
  2345. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2346. undo_redo->create_action(TTR("Change Output Port Type"));
  2347. undo_redo->add_do_method(node.ptr(), "set_output_port_type", p_port, p_type);
  2348. undo_redo->add_undo_method(node.ptr(), "set_output_port_type", p_port, node->get_output_port_type(p_port));
  2349. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2350. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2351. undo_redo->commit_action();
  2352. }
  2353. void VisualShaderEditor::_change_input_port_name(const String &p_text, Object *p_line_edit, int p_node_id, int p_port_id) {
  2354. VisualShader::Type type = get_current_shader_type();
  2355. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  2356. ERR_FAIL_COND(node.is_null());
  2357. String prev_name = node->get_input_port_name(p_port_id);
  2358. if (prev_name == p_text) {
  2359. return;
  2360. }
  2361. LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
  2362. ERR_FAIL_NULL(line_edit);
  2363. String validated_name = visual_shader->validate_port_name(p_text, node.ptr(), p_port_id, false);
  2364. if (validated_name.is_empty() || prev_name == validated_name) {
  2365. line_edit->set_text(node->get_input_port_name(p_port_id));
  2366. return;
  2367. }
  2368. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2369. undo_redo->create_action(TTR("Change Input Port Name"));
  2370. undo_redo->add_do_method(node.ptr(), "set_input_port_name", p_port_id, validated_name);
  2371. undo_redo->add_undo_method(node.ptr(), "set_input_port_name", p_port_id, node->get_input_port_name(p_port_id));
  2372. undo_redo->commit_action();
  2373. }
  2374. void VisualShaderEditor::_change_output_port_name(const String &p_text, Object *p_line_edit, int p_node_id, int p_port_id) {
  2375. VisualShader::Type type = get_current_shader_type();
  2376. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  2377. ERR_FAIL_COND(node.is_null());
  2378. String prev_name = node->get_output_port_name(p_port_id);
  2379. if (prev_name == p_text) {
  2380. return;
  2381. }
  2382. LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
  2383. ERR_FAIL_NULL(line_edit);
  2384. String validated_name = visual_shader->validate_port_name(p_text, node.ptr(), p_port_id, true);
  2385. if (validated_name.is_empty() || prev_name == validated_name) {
  2386. line_edit->set_text(node->get_output_port_name(p_port_id));
  2387. return;
  2388. }
  2389. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2390. undo_redo->create_action(TTR("Change Output Port Name"));
  2391. undo_redo->add_do_method(node.ptr(), "set_output_port_name", p_port_id, validated_name);
  2392. undo_redo->add_undo_method(node.ptr(), "set_output_port_name", p_port_id, prev_name);
  2393. undo_redo->commit_action();
  2394. }
  2395. void VisualShaderEditor::_expand_output_port(int p_node, int p_port, bool p_expand) {
  2396. VisualShader::Type type = get_current_shader_type();
  2397. Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
  2398. ERR_FAIL_COND(node.is_null());
  2399. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2400. if (p_expand) {
  2401. undo_redo->create_action(TTR("Expand Output Port"));
  2402. } else {
  2403. undo_redo->create_action(TTR("Shrink Output Port"));
  2404. }
  2405. undo_redo->add_do_method(node.ptr(), "_set_output_port_expanded", p_port, p_expand);
  2406. undo_redo->add_undo_method(node.ptr(), "_set_output_port_expanded", p_port, !p_expand);
  2407. int type_size = 0;
  2408. switch (node->get_output_port_type(p_port)) {
  2409. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  2410. type_size = 2;
  2411. } break;
  2412. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  2413. type_size = 3;
  2414. } break;
  2415. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  2416. type_size = 4;
  2417. } break;
  2418. default:
  2419. break;
  2420. }
  2421. List<VisualShader::Connection> conns;
  2422. visual_shader->get_node_connections(type, &conns);
  2423. for (const VisualShader::Connection &E : conns) {
  2424. int cn_from_node = E.from_node;
  2425. int cn_from_port = E.from_port;
  2426. int cn_to_node = E.to_node;
  2427. int cn_to_port = E.to_port;
  2428. if (cn_from_node == p_node) {
  2429. if (p_expand) {
  2430. if (cn_from_port > p_port) { // reconnect ports after expanded ports
  2431. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2432. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2433. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2434. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2435. 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);
  2436. 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);
  2437. 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);
  2438. 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);
  2439. }
  2440. } else {
  2441. if (cn_from_port > p_port + type_size) { // reconnect ports after expanded ports
  2442. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2443. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2444. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2445. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2446. 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);
  2447. 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);
  2448. 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);
  2449. 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);
  2450. } else if (cn_from_port > p_port) { // disconnect component ports
  2451. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2452. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2453. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2454. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2455. }
  2456. }
  2457. }
  2458. }
  2459. int preview_port = node->get_output_port_for_preview();
  2460. if (p_expand) {
  2461. if (preview_port > p_port) {
  2462. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port + type_size);
  2463. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2464. }
  2465. } else {
  2466. if (preview_port > p_port + type_size) {
  2467. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - type_size);
  2468. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2469. }
  2470. }
  2471. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2472. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2473. undo_redo->commit_action();
  2474. }
  2475. void VisualShaderEditor::_remove_input_port(int p_node, int p_port) {
  2476. VisualShader::Type type = get_current_shader_type();
  2477. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2478. if (node.is_null()) {
  2479. return;
  2480. }
  2481. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2482. undo_redo->create_action(TTR("Remove Input Port"));
  2483. List<VisualShader::Connection> conns;
  2484. visual_shader->get_node_connections(type, &conns);
  2485. for (const VisualShader::Connection &E : conns) {
  2486. int cn_from_node = E.from_node;
  2487. int cn_from_port = E.from_port;
  2488. int cn_to_node = E.to_node;
  2489. int cn_to_port = E.to_port;
  2490. if (cn_to_node == p_node) {
  2491. if (cn_to_port == p_port) {
  2492. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2493. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2494. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2495. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2496. } else if (cn_to_port > p_port) {
  2497. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2498. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2499. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2500. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2501. 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);
  2502. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2503. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2504. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2505. }
  2506. }
  2507. }
  2508. undo_redo->add_do_method(node.ptr(), "remove_input_port", p_port);
  2509. 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));
  2510. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2511. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2512. undo_redo->commit_action();
  2513. }
  2514. void VisualShaderEditor::_remove_output_port(int p_node, int p_port) {
  2515. VisualShader::Type type = get_current_shader_type();
  2516. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2517. if (node.is_null()) {
  2518. return;
  2519. }
  2520. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2521. undo_redo->create_action(TTR("Remove Output Port"));
  2522. List<VisualShader::Connection> conns;
  2523. visual_shader->get_node_connections(type, &conns);
  2524. for (const VisualShader::Connection &E : conns) {
  2525. int cn_from_node = E.from_node;
  2526. int cn_from_port = E.from_port;
  2527. int cn_to_node = E.to_node;
  2528. int cn_to_port = E.to_port;
  2529. if (cn_from_node == p_node) {
  2530. if (cn_from_port == p_port) {
  2531. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2532. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2533. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2534. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2535. } else if (cn_from_port > p_port) {
  2536. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2537. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2538. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2539. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2540. 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);
  2541. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2542. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2543. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2544. }
  2545. }
  2546. }
  2547. int preview_port = node->get_output_port_for_preview();
  2548. if (preview_port != -1) {
  2549. if (preview_port == p_port) {
  2550. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", -1);
  2551. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2552. } else if (preview_port > p_port) {
  2553. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - 1);
  2554. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2555. }
  2556. }
  2557. undo_redo->add_do_method(node.ptr(), "remove_output_port", p_port);
  2558. 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));
  2559. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2560. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2561. undo_redo->commit_action();
  2562. }
  2563. void VisualShaderEditor::_expression_focus_out(Object *p_code_edit, int p_node) {
  2564. VisualShader::Type type = get_current_shader_type();
  2565. Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node);
  2566. if (node.is_null()) {
  2567. return;
  2568. }
  2569. CodeEdit *expression_box = Object::cast_to<CodeEdit>(p_code_edit);
  2570. if (node->get_expression() == expression_box->get_text()) {
  2571. return;
  2572. }
  2573. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2574. undo_redo->create_action(TTR("Set VisualShader Expression"));
  2575. undo_redo->add_do_method(node.ptr(), "set_expression", expression_box->get_text());
  2576. undo_redo->add_undo_method(node.ptr(), "set_expression", node->get_expression());
  2577. undo_redo->add_do_method(graph_plugin.ptr(), "set_expression", type, p_node, expression_box->get_text());
  2578. undo_redo->add_undo_method(graph_plugin.ptr(), "set_expression", type, p_node, node->get_expression());
  2579. undo_redo->commit_action();
  2580. }
  2581. void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p_size) {
  2582. VisualShader::Type type = VisualShader::Type(p_type);
  2583. Ref<VisualShaderNodeResizableBase> node = visual_shader->get_node(type, p_node);
  2584. if (node.is_null()) {
  2585. return;
  2586. }
  2587. Size2 size = p_size;
  2588. if (!node->is_allow_v_resize()) {
  2589. size.y = 0;
  2590. }
  2591. node->set_size(size);
  2592. if (get_current_shader_type() == type) {
  2593. Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  2594. Control *text_box = nullptr;
  2595. if (expression_node.is_valid()) {
  2596. text_box = expression_node->is_ctrl_pressed(0);
  2597. if (text_box) {
  2598. text_box->set_custom_minimum_size(Size2(0, 0));
  2599. }
  2600. }
  2601. GraphElement *graph_element = nullptr;
  2602. Node *node2 = graph->get_node(itos(p_node));
  2603. graph_element = Object::cast_to<GraphElement>(node2);
  2604. if (!graph_element) {
  2605. return;
  2606. }
  2607. graph_element->set_size(size);
  2608. }
  2609. // Update all parent frames.
  2610. graph_plugin->update_frames(type, p_node);
  2611. }
  2612. // Called once after the node was resized.
  2613. void VisualShaderEditor::_node_resized(const Vector2 &p_new_size, int p_type, int p_node) {
  2614. Ref<VisualShaderNodeResizableBase> node = visual_shader->get_node(VisualShader::Type(p_type), p_node);
  2615. if (node.is_null()) {
  2616. return;
  2617. }
  2618. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_node(itos(p_node)));
  2619. if (!graph_element) {
  2620. return;
  2621. }
  2622. Size2 size = graph_element->get_size();
  2623. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2624. undo_redo->create_action(TTR("Resize VisualShader Node"));
  2625. undo_redo->add_do_method(this, "_set_node_size", p_type, p_node, size);
  2626. undo_redo->add_undo_method(this, "_set_node_size", p_type, p_node, node->get_size());
  2627. undo_redo->commit_action();
  2628. }
  2629. void VisualShaderEditor::_preview_select_port(int p_node, int p_port) {
  2630. VisualShader::Type type = get_current_shader_type();
  2631. Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
  2632. if (node.is_null()) {
  2633. return;
  2634. }
  2635. int prev_port = node->get_output_port_for_preview();
  2636. if (node->get_output_port_for_preview() == p_port) {
  2637. p_port = -1; //toggle it
  2638. }
  2639. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2640. undo_redo->create_action(p_port == -1 ? TTR("Hide Port Preview") : TTR("Show Port Preview"));
  2641. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", p_port);
  2642. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", prev_port);
  2643. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, p_node);
  2644. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, p_node);
  2645. undo_redo->commit_action();
  2646. }
  2647. void VisualShaderEditor::_frame_title_popup_show(const Point2 &p_position, int p_node_id) {
  2648. VisualShader::Type type = get_current_shader_type();
  2649. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2650. if (node.is_null()) {
  2651. return;
  2652. }
  2653. frame_title_change_edit->set_text(node->get_title());
  2654. frame_title_change_popup->set_meta("id", p_node_id);
  2655. frame_title_change_popup->set_position(p_position);
  2656. frame_title_change_popup->popup();
  2657. // Select current text.
  2658. frame_title_change_edit->grab_focus();
  2659. }
  2660. void VisualShaderEditor::_frame_title_text_changed(const String &p_new_text) {
  2661. frame_title_change_edit->reset_size();
  2662. frame_title_change_popup->reset_size();
  2663. }
  2664. void VisualShaderEditor::_frame_title_text_submitted(const String &p_new_text) {
  2665. frame_title_change_popup->hide();
  2666. }
  2667. void VisualShaderEditor::_frame_title_popup_focus_out() {
  2668. frame_title_change_popup->hide();
  2669. }
  2670. void VisualShaderEditor::_frame_title_popup_hide() {
  2671. int node_id = (int)frame_title_change_popup->get_meta("id", -1);
  2672. ERR_FAIL_COND(node_id == -1);
  2673. VisualShader::Type type = get_current_shader_type();
  2674. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id);
  2675. ERR_FAIL_COND(node.is_null());
  2676. if (node->get_title() == frame_title_change_edit->get_text()) {
  2677. return; // nothing changed - ignored
  2678. }
  2679. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2680. undo_redo->create_action(TTR("Set Frame Title"));
  2681. undo_redo->add_do_method(node.ptr(), "set_title", frame_title_change_edit->get_text());
  2682. undo_redo->add_undo_method(node.ptr(), "set_title", node->get_title());
  2683. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, node_id);
  2684. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, node_id);
  2685. undo_redo->commit_action();
  2686. }
  2687. void VisualShaderEditor::_frame_color_enabled_changed(int p_node_id) {
  2688. int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR);
  2689. // The new state.
  2690. bool tint_color_enabled = !popup_menu->is_item_checked(item_index);
  2691. popup_menu->set_item_checked(item_index, tint_color_enabled);
  2692. int frame_color_item_idx = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_COLOR);
  2693. if (tint_color_enabled && frame_color_item_idx == -1) {
  2694. popup_menu->add_item(TTR("Set Tint Color"), NodeMenuOptions::SET_FRAME_COLOR);
  2695. } else if (!tint_color_enabled && frame_color_item_idx != -1) {
  2696. popup_menu->remove_item(frame_color_item_idx);
  2697. }
  2698. VisualShader::Type type = get_current_shader_type();
  2699. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2700. ERR_FAIL_COND(node.is_null());
  2701. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2702. undo_redo->create_action(TTR("Toggle Frame Color"));
  2703. undo_redo->add_do_method(node.ptr(), "set_tint_color_enabled", tint_color_enabled);
  2704. undo_redo->add_undo_method(node.ptr(), "set_tint_color_enabled", node->is_tint_color_enabled());
  2705. undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_color_enabled", (int)type, p_node_id, tint_color_enabled);
  2706. undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_color_enabled", (int)type, p_node_id, node->is_tint_color_enabled());
  2707. undo_redo->commit_action();
  2708. }
  2709. void VisualShaderEditor::_frame_color_popup_show(const Point2 &p_position, int p_node_id) {
  2710. VisualShader::Type type = get_current_shader_type();
  2711. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2712. if (node.is_null()) {
  2713. return;
  2714. }
  2715. frame_tint_color_picker->set_pick_color(node->get_tint_color());
  2716. frame_tint_color_pick_popup->set_meta("id", p_node_id);
  2717. frame_tint_color_pick_popup->set_position(p_position);
  2718. frame_tint_color_pick_popup->popup();
  2719. }
  2720. void VisualShaderEditor::_frame_color_confirm() {
  2721. frame_tint_color_pick_popup->hide();
  2722. }
  2723. void VisualShaderEditor::_frame_color_changed(const Color &p_color) {
  2724. ERR_FAIL_COND(!frame_tint_color_pick_popup->has_meta("id"));
  2725. int node_id = (int)frame_tint_color_pick_popup->get_meta("id");
  2726. VisualShader::Type type = get_current_shader_type();
  2727. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id);
  2728. ERR_FAIL_COND(node.is_null());
  2729. node->set_tint_color(p_color);
  2730. graph_plugin->set_frame_color(type, node_id, p_color);
  2731. }
  2732. void VisualShaderEditor::_frame_color_popup_hide() {
  2733. ERR_FAIL_COND(!frame_tint_color_pick_popup->has_meta("id"));
  2734. int node_id = (int)frame_tint_color_pick_popup->get_meta("id");
  2735. VisualShader::Type type = get_current_shader_type();
  2736. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id);
  2737. ERR_FAIL_COND(node.is_null());
  2738. if (node->get_tint_color() == frame_tint_color_picker->get_pick_color()) {
  2739. return;
  2740. }
  2741. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2742. undo_redo->create_action(TTR("Set Frame Color"));
  2743. undo_redo->add_do_method(node.ptr(), "set_tint_color", frame_tint_color_picker->get_pick_color());
  2744. undo_redo->add_undo_method(node.ptr(), "set_tint_color", node->get_tint_color());
  2745. undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_color", (int)type, node_id, frame_tint_color_picker->get_pick_color());
  2746. undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_color", (int)type, node_id, node->get_tint_color());
  2747. undo_redo->commit_action();
  2748. }
  2749. void VisualShaderEditor::_frame_autoshrink_enabled_changed(int p_node_id) {
  2750. int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  2751. bool autoshrink_enabled = popup_menu->is_item_checked(item_index);
  2752. popup_menu->set_item_checked(item_index, !autoshrink_enabled);
  2753. VisualShader::Type type = get_current_shader_type();
  2754. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2755. ERR_FAIL_COND(node.is_null());
  2756. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2757. undo_redo->create_action(TTR("Toggle Auto Shrink"));
  2758. undo_redo->add_do_method(node.ptr(), "set_autoshrink_enabled", !autoshrink_enabled);
  2759. undo_redo->add_undo_method(node.ptr(), "set_autoshrink_enabled", autoshrink_enabled);
  2760. undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_autoshrink_enabled", (int)type, p_node_id, !autoshrink_enabled);
  2761. undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_autoshrink_enabled", (int)type, p_node_id, autoshrink_enabled);
  2762. undo_redo->commit_action();
  2763. popup_menu->hide();
  2764. }
  2765. void VisualShaderEditor::_parameter_line_edit_changed(const String &p_text, int p_node_id) {
  2766. VisualShader::Type type = get_current_shader_type();
  2767. Ref<VisualShaderNodeParameter> node = visual_shader->get_node(type, p_node_id);
  2768. ERR_FAIL_COND(node.is_null());
  2769. String validated_name = visual_shader->validate_parameter_name(p_text, node);
  2770. if (validated_name == node->get_parameter_name()) {
  2771. return;
  2772. }
  2773. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2774. undo_redo->create_action(TTR("Set Parameter Name"));
  2775. undo_redo->add_do_method(node.ptr(), "set_parameter_name", validated_name);
  2776. undo_redo->add_undo_method(node.ptr(), "set_parameter_name", node->get_parameter_name());
  2777. undo_redo->add_do_method(graph_plugin.ptr(), "set_parameter_name", type, p_node_id, validated_name);
  2778. undo_redo->add_undo_method(graph_plugin.ptr(), "set_parameter_name", type, p_node_id, node->get_parameter_name());
  2779. undo_redo->add_do_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id);
  2780. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id);
  2781. undo_redo->add_do_method(this, "_update_parameters", true);
  2782. undo_redo->add_undo_method(this, "_update_parameters", true);
  2783. HashSet<String> changed_names;
  2784. changed_names.insert(node->get_parameter_name());
  2785. _update_parameter_refs(changed_names);
  2786. undo_redo->commit_action();
  2787. }
  2788. void VisualShaderEditor::_parameter_line_edit_focus_out(Object *line_edit, int p_node_id) {
  2789. _parameter_line_edit_changed(Object::cast_to<LineEdit>(line_edit)->get_text(), p_node_id);
  2790. }
  2791. void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output) {
  2792. if (!p_output) {
  2793. _change_input_port_name(Object::cast_to<LineEdit>(line_edit)->get_text(), line_edit, p_node_id, p_port_id);
  2794. } else {
  2795. _change_output_port_name(Object::cast_to<LineEdit>(line_edit)->get_text(), line_edit, p_node_id, p_port_id);
  2796. }
  2797. }
  2798. void VisualShaderEditor::_port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
  2799. VisualShader::Type type = get_current_shader_type();
  2800. Ref<VisualShaderNode> vsn = visual_shader->get_node(type, editing_node);
  2801. ERR_FAIL_COND(vsn.is_null());
  2802. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2803. undo_redo->create_action(TTR("Set Input Default Port"));
  2804. Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(vsn.ptr());
  2805. if (custom.is_valid()) {
  2806. undo_redo->add_do_method(custom.ptr(), "_set_input_port_default_value", editing_port, p_value);
  2807. undo_redo->add_undo_method(custom.ptr(), "_set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
  2808. } else {
  2809. undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, p_value);
  2810. undo_redo->add_undo_method(vsn.ptr(), "set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
  2811. }
  2812. undo_redo->add_do_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, p_value);
  2813. 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));
  2814. undo_redo->commit_action();
  2815. }
  2816. void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, int p_port) {
  2817. VisualShader::Type type = get_current_shader_type();
  2818. Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, p_node);
  2819. Variant value = vs_node->get_input_port_default_value(p_port);
  2820. edited_property_holder->set_edited_property(value);
  2821. editing_node = p_node;
  2822. editing_port = p_port;
  2823. if (property_editor) {
  2824. property_editor->disconnect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
  2825. property_editor_popup->remove_child(property_editor);
  2826. }
  2827. // TODO: Define these properties with actual PropertyInfo and feed it to the property editor widget.
  2828. property_editor = EditorInspector::instantiate_property_editor(edited_property_holder.ptr(), value.get_type(), "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE, true);
  2829. ERR_FAIL_NULL_MSG(property_editor, "Failed to create property editor for type: " + Variant::get_type_name(value.get_type()));
  2830. // Determine the best size for the popup based on the property type.
  2831. // 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.
  2832. Size2 popup_pref_size;
  2833. switch (value.get_type()) {
  2834. case Variant::VECTOR3:
  2835. case Variant::BASIS:
  2836. popup_pref_size.width = 320;
  2837. break;
  2838. case Variant::VECTOR4:
  2839. case Variant::PLANE:
  2840. case Variant::TRANSFORM2D:
  2841. case Variant::TRANSFORM3D:
  2842. case Variant::PROJECTION:
  2843. popup_pref_size.width = 480;
  2844. break;
  2845. default:
  2846. popup_pref_size.width = 180;
  2847. break;
  2848. }
  2849. property_editor_popup->set_min_size(popup_pref_size * EDSCALE);
  2850. property_editor->set_object_and_property(edited_property_holder.ptr(), "edited_property");
  2851. property_editor->update_property();
  2852. property_editor->set_name_split_ratio(0);
  2853. property_editor_popup->add_child(property_editor);
  2854. property_editor->connect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
  2855. Button *button = Object::cast_to<Button>(p_button);
  2856. if (button) {
  2857. property_editor_popup->set_position(button->get_screen_position() + Vector2(0, button->get_size().height) * graph->get_zoom());
  2858. }
  2859. property_editor_popup->reset_size();
  2860. if (button) {
  2861. property_editor_popup->popup();
  2862. } else {
  2863. property_editor_popup->popup_centered_ratio();
  2864. }
  2865. property_editor->select(0); // Focus the first focusable control.
  2866. }
  2867. void VisualShaderEditor::_set_custom_node_option(int p_index, int p_node, int p_op) {
  2868. VisualShader::Type type = get_current_shader_type();
  2869. Ref<VisualShaderNodeCustom> node = visual_shader->get_node(type, p_node);
  2870. if (node.is_null()) {
  2871. return;
  2872. }
  2873. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2874. undo_redo->create_action(TTR("Set Custom Node Option"));
  2875. undo_redo->add_do_method(node.ptr(), "_set_option_index", p_op, p_index);
  2876. undo_redo->add_undo_method(node.ptr(), "_set_option_index", p_op, node->get_option_index(p_op));
  2877. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2878. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2879. undo_redo->commit_action();
  2880. }
  2881. void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops) {
  2882. // INPUT
  2883. {
  2884. VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(p_node);
  2885. if (input) {
  2886. ERR_FAIL_COND(!p_ops[0].is_string());
  2887. input->set_input_name((String)p_ops[0]);
  2888. return;
  2889. }
  2890. }
  2891. // FLOAT_CONST
  2892. {
  2893. VisualShaderNodeFloatConstant *float_const = Object::cast_to<VisualShaderNodeFloatConstant>(p_node);
  2894. if (float_const) {
  2895. ERR_FAIL_COND(p_ops[0].get_type() != Variant::FLOAT);
  2896. float_const->set_constant((float)p_ops[0]);
  2897. return;
  2898. }
  2899. }
  2900. // FLOAT_OP
  2901. {
  2902. VisualShaderNodeFloatOp *float_op = Object::cast_to<VisualShaderNodeFloatOp>(p_node);
  2903. if (float_op) {
  2904. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2905. float_op->set_operator((VisualShaderNodeFloatOp::Operator)(int)p_ops[0]);
  2906. return;
  2907. }
  2908. }
  2909. // FLOAT_FUNC
  2910. {
  2911. VisualShaderNodeFloatFunc *float_func = Object::cast_to<VisualShaderNodeFloatFunc>(p_node);
  2912. if (float_func) {
  2913. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2914. float_func->set_function((VisualShaderNodeFloatFunc::Function)(int)p_ops[0]);
  2915. return;
  2916. }
  2917. }
  2918. // VECTOR_OP
  2919. {
  2920. VisualShaderNodeVectorOp *vec_op = Object::cast_to<VisualShaderNodeVectorOp>(p_node);
  2921. if (vec_op) {
  2922. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2923. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  2924. vec_op->set_operator((VisualShaderNodeVectorOp::Operator)(int)p_ops[0]);
  2925. vec_op->set_op_type((VisualShaderNodeVectorOp::OpType)(int)p_ops[1]);
  2926. return;
  2927. }
  2928. }
  2929. // VECTOR_FUNC
  2930. {
  2931. VisualShaderNodeVectorFunc *vec_func = Object::cast_to<VisualShaderNodeVectorFunc>(p_node);
  2932. if (vec_func) {
  2933. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2934. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  2935. vec_func->set_function((VisualShaderNodeVectorFunc::Function)(int)p_ops[0]);
  2936. vec_func->set_op_type((VisualShaderNodeVectorFunc::OpType)(int)p_ops[1]);
  2937. return;
  2938. }
  2939. }
  2940. // COLOR_OP
  2941. {
  2942. VisualShaderNodeColorOp *color_op = Object::cast_to<VisualShaderNodeColorOp>(p_node);
  2943. if (color_op) {
  2944. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2945. color_op->set_operator((VisualShaderNodeColorOp::Operator)(int)p_ops[0]);
  2946. return;
  2947. }
  2948. }
  2949. // COLOR_FUNC
  2950. {
  2951. VisualShaderNodeColorFunc *color_func = Object::cast_to<VisualShaderNodeColorFunc>(p_node);
  2952. if (color_func) {
  2953. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2954. color_func->set_function((VisualShaderNodeColorFunc::Function)(int)p_ops[0]);
  2955. return;
  2956. }
  2957. }
  2958. // INT_OP
  2959. {
  2960. VisualShaderNodeIntOp *int_op = Object::cast_to<VisualShaderNodeIntOp>(p_node);
  2961. if (int_op) {
  2962. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2963. int_op->set_operator((VisualShaderNodeIntOp::Operator)(int)p_ops[0]);
  2964. return;
  2965. }
  2966. }
  2967. // INT_FUNC
  2968. {
  2969. VisualShaderNodeIntFunc *int_func = Object::cast_to<VisualShaderNodeIntFunc>(p_node);
  2970. if (int_func) {
  2971. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2972. int_func->set_function((VisualShaderNodeIntFunc::Function)(int)p_ops[0]);
  2973. return;
  2974. }
  2975. }
  2976. // UINT_OP
  2977. {
  2978. VisualShaderNodeUIntOp *uint_op = Object::cast_to<VisualShaderNodeUIntOp>(p_node);
  2979. if (uint_op) {
  2980. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2981. uint_op->set_operator((VisualShaderNodeUIntOp::Operator)(int)p_ops[0]);
  2982. return;
  2983. }
  2984. }
  2985. // UINT_FUNC
  2986. {
  2987. VisualShaderNodeUIntFunc *uint_func = Object::cast_to<VisualShaderNodeUIntFunc>(p_node);
  2988. if (uint_func) {
  2989. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2990. uint_func->set_function((VisualShaderNodeUIntFunc::Function)(int)p_ops[0]);
  2991. return;
  2992. }
  2993. }
  2994. // TRANSFORM_OP
  2995. {
  2996. VisualShaderNodeTransformOp *mat_op = Object::cast_to<VisualShaderNodeTransformOp>(p_node);
  2997. if (mat_op) {
  2998. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2999. mat_op->set_operator((VisualShaderNodeTransformOp::Operator)(int)p_ops[0]);
  3000. return;
  3001. }
  3002. }
  3003. // TRANSFORM_FUNC
  3004. {
  3005. VisualShaderNodeTransformFunc *mat_func = Object::cast_to<VisualShaderNodeTransformFunc>(p_node);
  3006. if (mat_func) {
  3007. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3008. mat_func->set_function((VisualShaderNodeTransformFunc::Function)(int)p_ops[0]);
  3009. return;
  3010. }
  3011. }
  3012. // VECTOR_COMPOSE
  3013. {
  3014. VisualShaderNodeVectorCompose *vec_compose = Object::cast_to<VisualShaderNodeVectorCompose>(p_node);
  3015. if (vec_compose) {
  3016. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3017. vec_compose->set_op_type((VisualShaderNodeVectorCompose::OpType)(int)p_ops[0]);
  3018. return;
  3019. }
  3020. }
  3021. // VECTOR_DECOMPOSE
  3022. {
  3023. VisualShaderNodeVectorDecompose *vec_decompose = Object::cast_to<VisualShaderNodeVectorDecompose>(p_node);
  3024. if (vec_decompose) {
  3025. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3026. vec_decompose->set_op_type((VisualShaderNodeVectorDecompose::OpType)(int)p_ops[0]);
  3027. return;
  3028. }
  3029. }
  3030. // UV_FUNC
  3031. {
  3032. VisualShaderNodeUVFunc *uv_func = Object::cast_to<VisualShaderNodeUVFunc>(p_node);
  3033. if (uv_func) {
  3034. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3035. uv_func->set_function((VisualShaderNodeUVFunc::Function)(int)p_ops[0]);
  3036. return;
  3037. }
  3038. }
  3039. // IS
  3040. {
  3041. VisualShaderNodeIs *is = Object::cast_to<VisualShaderNodeIs>(p_node);
  3042. if (is) {
  3043. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3044. is->set_function((VisualShaderNodeIs::Function)(int)p_ops[0]);
  3045. return;
  3046. }
  3047. }
  3048. // COMPARE
  3049. {
  3050. VisualShaderNodeCompare *cmp = Object::cast_to<VisualShaderNodeCompare>(p_node);
  3051. if (cmp) {
  3052. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3053. cmp->set_function((VisualShaderNodeCompare::Function)(int)p_ops[0]);
  3054. return;
  3055. }
  3056. }
  3057. // DISTANCE
  3058. {
  3059. VisualShaderNodeVectorDistance *dist = Object::cast_to<VisualShaderNodeVectorDistance>(p_node);
  3060. if (dist) {
  3061. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3062. dist->set_op_type((VisualShaderNodeVectorDistance::OpType)(int)p_ops[0]);
  3063. return;
  3064. }
  3065. }
  3066. // DERIVATIVE
  3067. {
  3068. VisualShaderNodeDerivativeFunc *der_func = Object::cast_to<VisualShaderNodeDerivativeFunc>(p_node);
  3069. if (der_func) {
  3070. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3071. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  3072. der_func->set_function((VisualShaderNodeDerivativeFunc::Function)(int)p_ops[0]);
  3073. der_func->set_op_type((VisualShaderNodeDerivativeFunc::OpType)(int)p_ops[1]);
  3074. return;
  3075. }
  3076. }
  3077. // MIX
  3078. {
  3079. VisualShaderNodeMix *mix = Object::cast_to<VisualShaderNodeMix>(p_node);
  3080. if (mix) {
  3081. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3082. mix->set_op_type((VisualShaderNodeMix::OpType)(int)p_ops[0]);
  3083. return;
  3084. }
  3085. }
  3086. // CLAMP
  3087. {
  3088. VisualShaderNodeClamp *clamp_func = Object::cast_to<VisualShaderNodeClamp>(p_node);
  3089. if (clamp_func) {
  3090. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3091. clamp_func->set_op_type((VisualShaderNodeClamp::OpType)(int)p_ops[0]);
  3092. return;
  3093. }
  3094. }
  3095. // SWITCH
  3096. {
  3097. VisualShaderNodeSwitch *switch_func = Object::cast_to<VisualShaderNodeSwitch>(p_node);
  3098. if (switch_func) {
  3099. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3100. switch_func->set_op_type((VisualShaderNodeSwitch::OpType)(int)p_ops[0]);
  3101. return;
  3102. }
  3103. }
  3104. // FACEFORWARD
  3105. {
  3106. VisualShaderNodeFaceForward *face_forward = Object::cast_to<VisualShaderNodeFaceForward>(p_node);
  3107. if (face_forward) {
  3108. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3109. face_forward->set_op_type((VisualShaderNodeFaceForward::OpType)(int)p_ops[0]);
  3110. return;
  3111. }
  3112. }
  3113. // LENGTH
  3114. {
  3115. VisualShaderNodeVectorLen *length = Object::cast_to<VisualShaderNodeVectorLen>(p_node);
  3116. if (length) {
  3117. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3118. length->set_op_type((VisualShaderNodeVectorLen::OpType)(int)p_ops[0]);
  3119. return;
  3120. }
  3121. }
  3122. // SMOOTHSTEP
  3123. {
  3124. VisualShaderNodeSmoothStep *smooth_step_func = Object::cast_to<VisualShaderNodeSmoothStep>(p_node);
  3125. if (smooth_step_func) {
  3126. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3127. smooth_step_func->set_op_type((VisualShaderNodeSmoothStep::OpType)(int)p_ops[0]);
  3128. return;
  3129. }
  3130. }
  3131. // STEP
  3132. {
  3133. VisualShaderNodeStep *step_func = Object::cast_to<VisualShaderNodeStep>(p_node);
  3134. if (step_func) {
  3135. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3136. step_func->set_op_type((VisualShaderNodeStep::OpType)(int)p_ops[0]);
  3137. return;
  3138. }
  3139. }
  3140. // MULTIPLY_ADD
  3141. {
  3142. VisualShaderNodeMultiplyAdd *fma_func = Object::cast_to<VisualShaderNodeMultiplyAdd>(p_node);
  3143. if (fma_func) {
  3144. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3145. fma_func->set_op_type((VisualShaderNodeMultiplyAdd::OpType)(int)p_ops[0]);
  3146. }
  3147. }
  3148. // REMAP
  3149. {
  3150. VisualShaderNodeRemap *remap_func = Object::cast_to<VisualShaderNodeRemap>(p_node);
  3151. if (remap_func) {
  3152. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3153. remap_func->set_op_type((VisualShaderNodeRemap::OpType)(int)p_ops[0]);
  3154. }
  3155. }
  3156. }
  3157. void VisualShaderEditor::_add_node(int p_idx, const Vector<Variant> &p_ops, const String &p_resource_path, int p_node_idx) {
  3158. ERR_FAIL_INDEX(p_idx, add_options.size());
  3159. VisualShader::Type type = get_current_shader_type();
  3160. Ref<VisualShaderNode> vsnode;
  3161. bool is_custom = add_options[p_idx].is_custom;
  3162. if (!is_custom && !add_options[p_idx].type.is_empty()) {
  3163. VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[p_idx].type));
  3164. ERR_FAIL_NULL(vsn);
  3165. if (!p_ops.is_empty()) {
  3166. _setup_node(vsn, p_ops);
  3167. }
  3168. VisualShaderNodeParameterRef *parameter_ref = Object::cast_to<VisualShaderNodeParameterRef>(vsn);
  3169. if (parameter_ref && to_node != -1 && to_slot != -1) {
  3170. VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot);
  3171. bool success = false;
  3172. for (int i = 0; i < parameter_ref->get_parameters_count(); i++) {
  3173. if (parameter_ref->get_port_type_by_index(i) == input_port_type) {
  3174. parameter_ref->set_parameter_name(parameter_ref->get_parameter_name_by_index(i));
  3175. success = true;
  3176. break;
  3177. }
  3178. }
  3179. if (!success) {
  3180. for (int i = 0; i < parameter_ref->get_parameters_count(); i++) {
  3181. if (visual_shader->is_port_types_compatible(parameter_ref->get_port_type_by_index(i), input_port_type)) {
  3182. parameter_ref->set_parameter_name(parameter_ref->get_parameter_name_by_index(i));
  3183. break;
  3184. }
  3185. }
  3186. }
  3187. }
  3188. vsnode = Ref<VisualShaderNode>(vsn);
  3189. } else {
  3190. StringName base_type;
  3191. bool is_native = add_options[p_idx].is_native;
  3192. if (is_native) {
  3193. base_type = add_options[p_idx].type;
  3194. } else {
  3195. ERR_FAIL_COND(add_options[p_idx].script.is_null());
  3196. base_type = add_options[p_idx].script->get_instance_base_type();
  3197. }
  3198. VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(base_type));
  3199. ERR_FAIL_NULL(vsn);
  3200. vsnode = Ref<VisualShaderNode>(vsn);
  3201. if (!is_native) {
  3202. vsnode->set_script(add_options[p_idx].script);
  3203. }
  3204. VisualShaderNodeCustom *custom_node = Object::cast_to<VisualShaderNodeCustom>(vsn);
  3205. ERR_FAIL_NULL(custom_node);
  3206. custom_node->update_property_default_values();
  3207. custom_node->update_input_port_default_values();
  3208. custom_node->update_properties();
  3209. }
  3210. bool is_texture2d = (Object::cast_to<VisualShaderNodeTexture>(vsnode.ptr()) != nullptr);
  3211. bool is_texture3d = (Object::cast_to<VisualShaderNodeTexture3D>(vsnode.ptr()) != nullptr);
  3212. bool is_texture2d_array = (Object::cast_to<VisualShaderNodeTexture2DArray>(vsnode.ptr()) != nullptr);
  3213. bool is_cubemap = (Object::cast_to<VisualShaderNodeCubemap>(vsnode.ptr()) != nullptr);
  3214. bool is_curve = (Object::cast_to<VisualShaderNodeCurveTexture>(vsnode.ptr()) != nullptr);
  3215. bool is_curve_xyz = (Object::cast_to<VisualShaderNodeCurveXYZTexture>(vsnode.ptr()) != nullptr);
  3216. bool is_parameter = (Object::cast_to<VisualShaderNodeParameter>(vsnode.ptr()) != nullptr);
  3217. bool is_mesh_emitter = (Object::cast_to<VisualShaderNodeParticleMeshEmitter>(vsnode.ptr()) != nullptr);
  3218. Point2 position = graph->get_scroll_offset();
  3219. if (saved_node_pos_dirty) {
  3220. position += saved_node_pos;
  3221. } else {
  3222. position += graph->get_size() * 0.5;
  3223. position /= EDSCALE;
  3224. }
  3225. position /= graph->get_zoom();
  3226. saved_node_pos_dirty = false;
  3227. int id_to_use = visual_shader->get_valid_node_id(type);
  3228. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3229. if (p_resource_path.is_empty()) {
  3230. undo_redo->create_action(TTR("Add Node to Visual Shader"));
  3231. } else {
  3232. id_to_use += p_node_idx;
  3233. }
  3234. undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, vsnode, position, id_to_use);
  3235. undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_to_use);
  3236. undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_to_use, false, true);
  3237. undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_to_use, false);
  3238. VisualShaderNodeExpression *expr = Object::cast_to<VisualShaderNodeExpression>(vsnode.ptr());
  3239. if (expr) {
  3240. expr->set_size(Size2(250 * EDSCALE, 150 * EDSCALE));
  3241. }
  3242. Ref<VisualShaderNodeFrame> frame = vsnode;
  3243. if (frame.is_valid()) {
  3244. frame->set_size(Size2(320 * EDSCALE, 180 * EDSCALE));
  3245. }
  3246. Ref<VisualShaderNodeReroute> reroute = vsnode;
  3247. bool created_expression_port = false;
  3248. // A node is inserted in an already present connection.
  3249. if (from_node != -1 && from_slot != -1 && to_node != -1 && to_slot != -1) {
  3250. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, to_node, to_slot);
  3251. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, to_node, to_slot);
  3252. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, to_node, to_slot);
  3253. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, to_node, to_slot);
  3254. }
  3255. // Create a connection from the output port of an existing node to the new one.
  3256. if (from_node != -1 && from_slot != -1) {
  3257. VisualShaderNode::PortType output_port_type = visual_shader->get_node(type, from_node)->get_output_port_type(from_slot);
  3258. if (expr && expr->is_editable()) {
  3259. expr->add_input_port(0, output_port_type, "input0");
  3260. created_expression_port = true;
  3261. }
  3262. if (vsnode->get_input_port_count() > 0 || created_expression_port) {
  3263. int _to_node = id_to_use;
  3264. if (created_expression_port) {
  3265. int _to_slot = 0;
  3266. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3267. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3268. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3269. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3270. } else {
  3271. int _to_slot = -1;
  3272. // Attempting to connect to the default input port or to the first correct port (if it's not found).
  3273. for (int i = 0; i < vsnode->get_input_port_count(); i++) {
  3274. if (visual_shader->is_port_types_compatible(output_port_type, vsnode->get_input_port_type(i)) || reroute.is_valid()) {
  3275. if (i == vsnode->get_default_input_port(output_port_type)) {
  3276. _to_slot = i;
  3277. break;
  3278. } else if (_to_slot == -1) {
  3279. _to_slot = i;
  3280. }
  3281. }
  3282. }
  3283. if (_to_slot >= 0) {
  3284. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3285. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3286. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3287. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3288. }
  3289. }
  3290. if (output_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) {
  3291. if (is_texture2d) {
  3292. undo_redo->force_fixed_history(); // vsnode is freshly created and has no path, so history can't be correctly determined.
  3293. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeTexture::SOURCE_PORT);
  3294. }
  3295. if (is_texture3d || is_texture2d_array) {
  3296. undo_redo->force_fixed_history();
  3297. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeSample3D::SOURCE_PORT);
  3298. }
  3299. if (is_cubemap) {
  3300. undo_redo->force_fixed_history();
  3301. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeCubemap::SOURCE_PORT);
  3302. }
  3303. }
  3304. }
  3305. }
  3306. // Create a connection from the new node to an input port of an existing one.
  3307. if (to_node != -1 && to_slot != -1) {
  3308. VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot);
  3309. if (expr && expr->is_editable() && input_port_type != VisualShaderNode::PORT_TYPE_SAMPLER) {
  3310. expr->add_output_port(0, input_port_type, "output0");
  3311. String initial_expression_code;
  3312. switch (input_port_type) {
  3313. case VisualShaderNode::PORT_TYPE_SCALAR:
  3314. initial_expression_code = "output0 = 1.0;";
  3315. break;
  3316. case VisualShaderNode::PORT_TYPE_SCALAR_INT:
  3317. initial_expression_code = "output0 = 1;";
  3318. break;
  3319. case VisualShaderNode::PORT_TYPE_SCALAR_UINT:
  3320. initial_expression_code = "output0 = 1u;";
  3321. break;
  3322. case VisualShaderNode::PORT_TYPE_VECTOR_2D:
  3323. initial_expression_code = "output0 = vec2(1.0, 1.0);";
  3324. break;
  3325. case VisualShaderNode::PORT_TYPE_VECTOR_3D:
  3326. initial_expression_code = "output0 = vec3(1.0, 1.0, 1.0);";
  3327. break;
  3328. case VisualShaderNode::PORT_TYPE_VECTOR_4D:
  3329. initial_expression_code = "output0 = vec4(1.0, 1.0, 1.0, 1.0);";
  3330. break;
  3331. case VisualShaderNode::PORT_TYPE_BOOLEAN:
  3332. initial_expression_code = "output0 = true;";
  3333. break;
  3334. case VisualShaderNode::PORT_TYPE_TRANSFORM:
  3335. initial_expression_code = "output0 = mat4(1.0);";
  3336. break;
  3337. default:
  3338. break;
  3339. }
  3340. expr->set_expression(initial_expression_code);
  3341. expr->set_size(Size2(500 * EDSCALE, 200 * EDSCALE));
  3342. created_expression_port = true;
  3343. }
  3344. if (vsnode->get_output_port_count() > 0 || created_expression_port) {
  3345. int _from_node = id_to_use;
  3346. if (created_expression_port) {
  3347. int _from_slot = 0;
  3348. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  3349. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  3350. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  3351. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  3352. } else {
  3353. // Need to setting up Input node properly before committing since `is_port_types_compatible` (calling below) is using `mode` and `shader_type`.
  3354. VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(vsnode.ptr());
  3355. if (input) {
  3356. input->set_shader_mode(visual_shader->get_mode());
  3357. input->set_shader_type(get_current_shader_type());
  3358. }
  3359. // Attempting to connect to the first correct port.
  3360. for (int i = 0; i < vsnode->get_output_port_count(); i++) {
  3361. if (visual_shader->is_port_types_compatible(vsnode->get_output_port_type(i), input_port_type) || reroute.is_valid()) {
  3362. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot);
  3363. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot);
  3364. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot);
  3365. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot);
  3366. break;
  3367. }
  3368. }
  3369. }
  3370. }
  3371. }
  3372. _member_cancel();
  3373. if (is_parameter) {
  3374. undo_redo->add_do_method(this, "_update_parameters", true);
  3375. undo_redo->add_undo_method(this, "_update_parameters", true);
  3376. }
  3377. if (is_curve) {
  3378. callable_mp(graph_plugin.ptr(), &VisualShaderGraphPlugin::update_curve).call_deferred(id_to_use);
  3379. }
  3380. if (is_curve_xyz) {
  3381. callable_mp(graph_plugin.ptr(), &VisualShaderGraphPlugin::update_curve_xyz).call_deferred(id_to_use);
  3382. }
  3383. if (p_resource_path.is_empty()) {
  3384. undo_redo->commit_action();
  3385. } else {
  3386. //post-initialization
  3387. if (is_texture2d || is_texture3d || is_curve || is_curve_xyz) {
  3388. undo_redo->force_fixed_history();
  3389. undo_redo->add_do_method(vsnode.ptr(), "set_texture", ResourceLoader::load(p_resource_path));
  3390. return;
  3391. }
  3392. if (is_cubemap) {
  3393. undo_redo->force_fixed_history();
  3394. undo_redo->add_do_method(vsnode.ptr(), "set_cube_map", ResourceLoader::load(p_resource_path));
  3395. return;
  3396. }
  3397. if (is_texture2d_array) {
  3398. undo_redo->force_fixed_history();
  3399. undo_redo->add_do_method(vsnode.ptr(), "set_texture_array", ResourceLoader::load(p_resource_path));
  3400. return;
  3401. }
  3402. if (is_mesh_emitter) {
  3403. undo_redo->add_do_method(vsnode.ptr(), "set_mesh", ResourceLoader::load(p_resource_path));
  3404. return;
  3405. }
  3406. }
  3407. }
  3408. void VisualShaderEditor::_add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type) {
  3409. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3410. undo_redo->create_action(vformat(TTR("Add Varying to Visual Shader: %s"), p_name));
  3411. undo_redo->add_do_method(visual_shader.ptr(), "add_varying", p_name, p_mode, p_type);
  3412. undo_redo->add_undo_method(visual_shader.ptr(), "remove_varying", p_name);
  3413. undo_redo->add_do_method(this, "_update_varyings");
  3414. undo_redo->add_undo_method(this, "_update_varyings");
  3415. for (int i = 0; i <= VisualShader::TYPE_LIGHT; i++) {
  3416. if (p_mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT && i == 0) {
  3417. continue;
  3418. }
  3419. VisualShader::Type type = VisualShader::Type(i);
  3420. Vector<int> nodes = visual_shader->get_node_list(type);
  3421. for (int j = 0; j < nodes.size(); j++) {
  3422. int node_id = nodes[j];
  3423. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  3424. Ref<VisualShaderNodeVarying> var = vsnode;
  3425. if (var.is_valid()) {
  3426. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, node_id);
  3427. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, node_id);
  3428. }
  3429. }
  3430. }
  3431. undo_redo->add_do_method(this, "_update_varying_tree");
  3432. undo_redo->add_undo_method(this, "_update_varying_tree");
  3433. undo_redo->commit_action();
  3434. }
  3435. void VisualShaderEditor::_remove_varying(const String &p_name) {
  3436. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3437. undo_redo->create_action(vformat(TTR("Remove Varying from Visual Shader: %s"), p_name));
  3438. VisualShader::VaryingMode var_mode = visual_shader->get_varying_mode(p_name);
  3439. undo_redo->add_do_method(visual_shader.ptr(), "remove_varying", p_name);
  3440. undo_redo->add_undo_method(visual_shader.ptr(), "add_varying", p_name, var_mode, visual_shader->get_varying_type(p_name));
  3441. undo_redo->add_do_method(this, "_update_varyings");
  3442. undo_redo->add_undo_method(this, "_update_varyings");
  3443. for (int i = 0; i <= VisualShader::TYPE_LIGHT; i++) {
  3444. if (var_mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT && i == 0) {
  3445. continue;
  3446. }
  3447. VisualShader::Type type = VisualShader::Type(i);
  3448. Vector<int> nodes = visual_shader->get_node_list(type);
  3449. for (int j = 0; j < nodes.size(); j++) {
  3450. int node_id = nodes[j];
  3451. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  3452. Ref<VisualShaderNodeVarying> var = vsnode;
  3453. if (var.is_valid()) {
  3454. String var_name = var->get_varying_name();
  3455. if (var_name == p_name) {
  3456. undo_redo->add_do_method(var.ptr(), "set_varying_name", "[None]");
  3457. undo_redo->add_undo_method(var.ptr(), "set_varying_name", var_name);
  3458. undo_redo->add_do_method(var.ptr(), "set_varying_type", VisualShader::VARYING_TYPE_FLOAT);
  3459. undo_redo->add_undo_method(var.ptr(), "set_varying_type", var->get_varying_type());
  3460. }
  3461. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, node_id);
  3462. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, node_id);
  3463. }
  3464. }
  3465. List<VisualShader::Connection> node_connections;
  3466. visual_shader->get_node_connections(type, &node_connections);
  3467. for (VisualShader::Connection &E : node_connections) {
  3468. Ref<VisualShaderNodeVaryingGetter> var_getter = Object::cast_to<VisualShaderNodeVaryingGetter>(visual_shader->get_node(type, E.from_node).ptr());
  3469. if (var_getter.is_valid() && E.from_port > 0) {
  3470. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3471. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3472. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3473. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3474. }
  3475. Ref<VisualShaderNodeVaryingSetter> var_setter = Object::cast_to<VisualShaderNodeVaryingSetter>(visual_shader->get_node(type, E.to_node).ptr());
  3476. if (var_setter.is_valid() && E.to_port > 0) {
  3477. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3478. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3479. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3480. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3481. }
  3482. }
  3483. }
  3484. undo_redo->add_do_method(this, "_update_varying_tree");
  3485. undo_redo->add_undo_method(this, "_update_varying_tree");
  3486. undo_redo->commit_action();
  3487. }
  3488. void VisualShaderEditor::_update_varyings() {
  3489. VisualShaderNodeVarying::clear_varyings(visual_shader->get_rid());
  3490. for (int i = 0; i < visual_shader->get_varyings_count(); i++) {
  3491. const VisualShader::Varying *var = visual_shader->get_varying_by_index(i);
  3492. if (var != nullptr) {
  3493. VisualShaderNodeVarying::add_varying(visual_shader->get_rid(), var->name, var->mode, var->type);
  3494. }
  3495. }
  3496. }
  3497. void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) {
  3498. VisualShader::Type type = get_current_shader_type();
  3499. drag_buffer.push_back({ type, p_node, p_from, p_to });
  3500. if (!drag_dirty) {
  3501. callable_mp(this, &VisualShaderEditor::_nodes_dragged).call_deferred();
  3502. }
  3503. drag_dirty = true;
  3504. }
  3505. void VisualShaderEditor::_nodes_dragged() {
  3506. drag_dirty = false;
  3507. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3508. if (frame_node_id_to_link_to == -1) {
  3509. undo_redo->create_action(TTR("Move VisualShader Node(s)"));
  3510. } else {
  3511. undo_redo->create_action(TTR("Move and Attach VisualShader Node(s) to parent frame"));
  3512. }
  3513. for (const DragOp &E : drag_buffer) {
  3514. undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.to);
  3515. undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.from);
  3516. undo_redo->add_do_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.to);
  3517. undo_redo->add_undo_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.from);
  3518. }
  3519. for (const int node_id : nodes_link_to_frame_buffer) {
  3520. VisualShader::Type type = get_current_shader_type();
  3521. Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, node_id);
  3522. undo_redo->add_do_method(visual_shader.ptr(), "attach_node_to_frame", type, node_id, frame_node_id_to_link_to);
  3523. undo_redo->add_do_method(graph_plugin.ptr(), "attach_node_to_frame", type, node_id, frame_node_id_to_link_to);
  3524. undo_redo->add_undo_method(graph_plugin.ptr(), "detach_node_from_frame", type, node_id);
  3525. undo_redo->add_undo_method(visual_shader.ptr(), "detach_node_from_frame", type, node_id);
  3526. }
  3527. undo_redo->commit_action();
  3528. _handle_node_drop_on_connection();
  3529. drag_buffer.clear();
  3530. nodes_link_to_frame_buffer.clear();
  3531. frame_node_id_to_link_to = -1;
  3532. }
  3533. void VisualShaderEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  3534. VisualShader::Type type = get_current_shader_type();
  3535. int from = p_from.to_int();
  3536. int to = p_to.to_int();
  3537. bool swap = last_to_node != -1 && Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL);
  3538. if (!visual_shader->can_connect_nodes(type, from, p_from_index, to, p_to_index)) {
  3539. return;
  3540. }
  3541. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3542. undo_redo->create_action(TTR("Nodes Connected"));
  3543. List<VisualShader::Connection> conns;
  3544. visual_shader->get_node_connections(type, &conns);
  3545. for (const VisualShader::Connection &E : conns) {
  3546. if (E.to_node == to && E.to_port == p_to_index) {
  3547. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3548. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3549. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3550. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3551. if (swap) {
  3552. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port);
  3553. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port);
  3554. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port);
  3555. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port);
  3556. }
  3557. break;
  3558. }
  3559. }
  3560. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3561. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3562. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3563. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3564. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, from);
  3565. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, from);
  3566. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3567. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3568. undo_redo->commit_action();
  3569. last_to_node = -1;
  3570. last_to_port = -1;
  3571. }
  3572. void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  3573. graph->disconnect_node(p_from, p_from_index, p_to, p_to_index);
  3574. VisualShader::Type type = get_current_shader_type();
  3575. int from = p_from.to_int();
  3576. int to = p_to.to_int();
  3577. last_to_node = to;
  3578. last_to_port = p_to_index;
  3579. info_label->show();
  3580. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3581. undo_redo->create_action(TTR("Nodes Disconnected"));
  3582. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3583. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3584. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3585. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3586. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3587. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3588. undo_redo->commit_action();
  3589. }
  3590. void VisualShaderEditor::_connection_drag_ended() {
  3591. info_label->hide();
  3592. }
  3593. void VisualShaderEditor::_connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position) {
  3594. from_node = p_from.to_int();
  3595. from_slot = p_from_slot;
  3596. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3597. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3598. Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), from_node);
  3599. if (node.is_valid()) {
  3600. output_port_type = node->get_output_port_type(from_slot);
  3601. }
  3602. _show_members_dialog(true, input_port_type, output_port_type);
  3603. }
  3604. void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position) {
  3605. to_node = p_to.to_int();
  3606. to_slot = p_to_slot;
  3607. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3608. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3609. Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), to_node);
  3610. if (node.is_valid()) {
  3611. input_port_type = node->get_input_port_type(to_slot);
  3612. }
  3613. _show_members_dialog(true, input_port_type, output_port_type);
  3614. }
  3615. 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) {
  3616. VisualShader::Type shader_type = get_current_shader_type();
  3617. // Get selected graph node.
  3618. Ref<VisualShaderNode> selected_vsnode;
  3619. int selected_node_id = -1;
  3620. int selected_node_count = 0;
  3621. Rect2 selected_node_rect;
  3622. for (int i = 0; i < graph->get_child_count(); i++) {
  3623. GraphNode *graph_node = Object::cast_to<GraphNode>(graph->get_child(i));
  3624. if (graph_node && graph_node->is_selected()) {
  3625. selected_node_id = String(graph_node->get_name()).to_int();
  3626. Ref<VisualShaderNode> vsnode = visual_shader->get_node(shader_type, selected_node_id);
  3627. if (!vsnode->is_deletable()) {
  3628. continue;
  3629. }
  3630. selected_node_count += 1;
  3631. Ref<VisualShaderNode> node = visual_shader->get_node(shader_type, selected_node_id);
  3632. selected_vsnode = node;
  3633. selected_node_rect = graph_node->get_rect();
  3634. }
  3635. }
  3636. // Only a single node - which has both input and output ports but is not connected yet - can be inserted.
  3637. if (selected_node_count != 1 || selected_vsnode.is_null()) {
  3638. return false;
  3639. }
  3640. // Check whether the dragged node was dropped over a connection.
  3641. List<Ref<GraphEdit::Connection>> intersecting_connections = graph->get_connections_intersecting_with_rect(selected_node_rect);
  3642. if (intersecting_connections.is_empty()) {
  3643. return false;
  3644. }
  3645. Ref<GraphEdit::Connection> intersecting_connection = intersecting_connections.front()->get();
  3646. if (selected_vsnode->is_any_port_connected() || selected_vsnode->get_input_port_count() == 0 || selected_vsnode->get_output_port_count() == 0) {
  3647. return false;
  3648. }
  3649. 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);
  3650. 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);
  3651. Ref<VisualShaderNodeReroute> reroute_node = selected_vsnode;
  3652. // Searching for the default port or the first compatible input port of the node to insert.
  3653. int _to_port = -1;
  3654. for (int i = 0; i < selected_vsnode->get_input_port_count(); i++) {
  3655. if (visual_shader->is_port_types_compatible(original_port_type_from, selected_vsnode->get_input_port_type(i)) || reroute_node.is_valid()) {
  3656. if (i == selected_vsnode->get_default_input_port(original_port_type_from)) {
  3657. _to_port = i;
  3658. break;
  3659. } else if (_to_port == -1) {
  3660. _to_port = i;
  3661. }
  3662. }
  3663. }
  3664. // Searching for the first compatible output port of the node to insert.
  3665. int _from_port = -1;
  3666. for (int i = 0; i < selected_vsnode->get_output_port_count(); i++) {
  3667. if (visual_shader->is_port_types_compatible(selected_vsnode->get_output_port_type(i), original_port_type_to) || reroute_node.is_valid()) {
  3668. _from_port = i;
  3669. break;
  3670. }
  3671. }
  3672. if (_to_port == -1 || _from_port == -1) {
  3673. return false;
  3674. }
  3675. if (r_closest_connection != nullptr) {
  3676. *r_closest_connection = intersecting_connection;
  3677. }
  3678. if (r_from_port != nullptr) {
  3679. *r_from_port = _from_port;
  3680. }
  3681. if (r_to_port != nullptr) {
  3682. *r_to_port = _to_port;
  3683. }
  3684. return true;
  3685. }
  3686. void VisualShaderEditor::_handle_node_drop_on_connection() {
  3687. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3688. undo_redo->create_action(TTR("Insert node"));
  3689. // Check whether the dragged node was dropped over a connection.
  3690. Ref<GraphEdit::Connection> closest_connection;
  3691. int _from_port = -1;
  3692. int _to_port = -1;
  3693. if (!_check_node_drop_on_connection(graph->get_local_mouse_position(), &closest_connection, &_from_port, &_to_port)) {
  3694. return;
  3695. }
  3696. int selected_node_id = drag_buffer.front()->get().node;
  3697. VisualShader::Type shader_type = get_current_shader_type();
  3698. Ref<VisualShaderNode> selected_vsnode = visual_shader->get_node(shader_type, selected_node_id);
  3699. // Delete the old connection.
  3700. 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);
  3701. 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);
  3702. 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);
  3703. 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);
  3704. // Add the connection to the dropped node.
  3705. 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);
  3706. 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);
  3707. 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);
  3708. 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);
  3709. // Add the connection from the dropped node.
  3710. 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);
  3711. 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);
  3712. 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);
  3713. 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);
  3714. undo_redo->commit_action();
  3715. call_deferred(SNAME("_update_graph"));
  3716. }
  3717. void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) {
  3718. VisualShader::Type type = VisualShader::Type(p_type);
  3719. List<VisualShader::Connection> conns;
  3720. visual_shader->get_node_connections(type, &conns);
  3721. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3722. for (const int &F : p_nodes) {
  3723. for (const VisualShader::Connection &E : conns) {
  3724. if (E.from_node == F || E.to_node == F) {
  3725. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3726. }
  3727. }
  3728. }
  3729. // The VS nodes need to be added before attaching them to frames.
  3730. for (const int &F : p_nodes) {
  3731. Ref<VisualShaderNode> node = visual_shader->get_node(type, F);
  3732. undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F), F);
  3733. undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F, false, false);
  3734. }
  3735. // Update frame references.
  3736. for (const int &node_id : p_nodes) {
  3737. Ref<VisualShaderNodeFrame> frame = visual_shader->get_node(type, node_id);
  3738. if (frame.is_valid()) {
  3739. for (const int &attached_node_id : frame->get_attached_nodes()) {
  3740. undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", type, attached_node_id);
  3741. undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", type, attached_node_id);
  3742. undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", type, attached_node_id, node_id);
  3743. undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", type, attached_node_id, node_id);
  3744. }
  3745. }
  3746. Ref<VisualShaderNode> node = visual_shader->get_node(type, node_id);
  3747. if (node->get_frame() == -1) {
  3748. continue;
  3749. }
  3750. undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", type, node_id);
  3751. undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", type, node_id);
  3752. undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", type, node_id, node->get_frame());
  3753. undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", type, node_id, node->get_frame());
  3754. }
  3755. // Restore size of the frame nodes.
  3756. for (const int &F : p_nodes) {
  3757. Ref<VisualShaderNodeFrame> frame = visual_shader->get_node(type, F);
  3758. if (frame.is_valid()) {
  3759. undo_redo->add_undo_method(this, "_set_node_size", type, F, frame->get_size());
  3760. }
  3761. }
  3762. HashSet<String> parameter_names;
  3763. for (const int &F : p_nodes) {
  3764. Ref<VisualShaderNode> node = visual_shader->get_node(type, F);
  3765. undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F);
  3766. VisualShaderNodeParameter *parameter = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  3767. if (parameter) {
  3768. parameter_names.insert(parameter->get_parameter_name());
  3769. }
  3770. }
  3771. List<VisualShader::Connection> used_conns;
  3772. for (const int &F : p_nodes) {
  3773. for (const VisualShader::Connection &E : conns) {
  3774. if (E.from_node == F || E.to_node == F) {
  3775. bool cancel = false;
  3776. for (const VisualShader::Connection &R : used_conns) {
  3777. 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) {
  3778. cancel = true; // to avoid ERR_ALREADY_EXISTS warning
  3779. break;
  3780. }
  3781. }
  3782. if (!cancel) {
  3783. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3784. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3785. used_conns.push_back(E);
  3786. }
  3787. }
  3788. }
  3789. }
  3790. // Delete nodes from the graph.
  3791. for (const int &F : p_nodes) {
  3792. undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, F, false);
  3793. }
  3794. // Update parameter refs if any parameter has been deleted.
  3795. if (parameter_names.size() > 0) {
  3796. undo_redo->add_do_method(this, "_update_parameters", true);
  3797. undo_redo->add_undo_method(this, "_update_parameters", true);
  3798. _update_parameter_refs(parameter_names);
  3799. }
  3800. }
  3801. void VisualShaderEditor::_replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to) {
  3802. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3803. undo_redo->add_do_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_to);
  3804. undo_redo->add_undo_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_from);
  3805. }
  3806. void VisualShaderEditor::_update_constant(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port) {
  3807. Ref<VisualShaderNode> node = visual_shader->get_node(p_type_id, p_node_id);
  3808. ERR_FAIL_COND(node.is_null());
  3809. ERR_FAIL_COND(!node->has_method("set_constant"));
  3810. node->call("set_constant", p_var);
  3811. if (p_preview_port != -1) {
  3812. node->set_output_port_for_preview(p_preview_port);
  3813. }
  3814. }
  3815. void VisualShaderEditor::_update_parameter(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port) {
  3816. Ref<VisualShaderNodeParameter> parameter = visual_shader->get_node(p_type_id, p_node_id);
  3817. ERR_FAIL_COND(parameter.is_null());
  3818. String valid_name = visual_shader->validate_parameter_name(parameter->get_parameter_name(), parameter);
  3819. parameter->set_parameter_name(valid_name);
  3820. graph_plugin->set_parameter_name(p_type_id, p_node_id, valid_name);
  3821. if (parameter->has_method("set_default_value_enabled")) {
  3822. parameter->call("set_default_value_enabled", true);
  3823. parameter->call("set_default_value", p_var);
  3824. }
  3825. if (p_preview_port != -1) {
  3826. parameter->set_output_port_for_preview(p_preview_port);
  3827. }
  3828. }
  3829. void VisualShaderEditor::_convert_constants_to_parameters(bool p_vice_versa) {
  3830. VisualShader::Type type_id = get_current_shader_type();
  3831. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3832. if (!p_vice_versa) {
  3833. undo_redo->create_action(TTR("Convert Constant Node(s) To Parameter(s)"));
  3834. } else {
  3835. undo_redo->create_action(TTR("Convert Parameter Node(s) To Constant(s)"));
  3836. }
  3837. const HashSet<int> &current_set = p_vice_versa ? selected_parameters : selected_constants;
  3838. HashSet<String> deleted_names;
  3839. for (const int &E : current_set) {
  3840. int node_id = E;
  3841. Ref<VisualShaderNode> node = visual_shader->get_node(type_id, node_id);
  3842. bool caught = false;
  3843. Variant var;
  3844. // float
  3845. if (!p_vice_versa) {
  3846. Ref<VisualShaderNodeFloatConstant> float_const = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
  3847. if (float_const.is_valid()) {
  3848. _replace_node(type_id, node_id, "VisualShaderNodeFloatConstant", "VisualShaderNodeFloatParameter");
  3849. var = float_const->get_constant();
  3850. caught = true;
  3851. }
  3852. } else {
  3853. Ref<VisualShaderNodeFloatParameter> float_parameter = Object::cast_to<VisualShaderNodeFloatParameter>(node.ptr());
  3854. if (float_parameter.is_valid()) {
  3855. _replace_node(type_id, node_id, "VisualShaderNodeFloatParameter", "VisualShaderNodeFloatConstant");
  3856. var = float_parameter->get_default_value();
  3857. caught = true;
  3858. }
  3859. }
  3860. // int
  3861. if (!caught) {
  3862. if (!p_vice_versa) {
  3863. Ref<VisualShaderNodeIntConstant> int_const = Object::cast_to<VisualShaderNodeIntConstant>(node.ptr());
  3864. if (int_const.is_valid()) {
  3865. _replace_node(type_id, node_id, "VisualShaderNodeIntConstant", "VisualShaderNodeIntParameter");
  3866. var = int_const->get_constant();
  3867. caught = true;
  3868. }
  3869. } else {
  3870. Ref<VisualShaderNodeIntParameter> int_parameter = Object::cast_to<VisualShaderNodeIntParameter>(node.ptr());
  3871. if (int_parameter.is_valid()) {
  3872. _replace_node(type_id, node_id, "VisualShaderNodeIntParameter", "VisualShaderNodeIntConstant");
  3873. var = int_parameter->get_default_value();
  3874. caught = true;
  3875. }
  3876. }
  3877. }
  3878. // boolean
  3879. if (!caught) {
  3880. if (!p_vice_versa) {
  3881. Ref<VisualShaderNodeBooleanConstant> boolean_const = Object::cast_to<VisualShaderNodeBooleanConstant>(node.ptr());
  3882. if (boolean_const.is_valid()) {
  3883. _replace_node(type_id, node_id, "VisualShaderNodeBooleanConstant", "VisualShaderNodeBooleanParameter");
  3884. var = boolean_const->get_constant();
  3885. caught = true;
  3886. }
  3887. } else {
  3888. Ref<VisualShaderNodeBooleanParameter> boolean_parameter = Object::cast_to<VisualShaderNodeBooleanParameter>(node.ptr());
  3889. if (boolean_parameter.is_valid()) {
  3890. _replace_node(type_id, node_id, "VisualShaderNodeBooleanParameter", "VisualShaderNodeBooleanConstant");
  3891. var = boolean_parameter->get_default_value();
  3892. caught = true;
  3893. }
  3894. }
  3895. }
  3896. // vec2
  3897. if (!caught) {
  3898. if (!p_vice_versa) {
  3899. Ref<VisualShaderNodeVec2Constant> vec2_const = Object::cast_to<VisualShaderNodeVec2Constant>(node.ptr());
  3900. if (vec2_const.is_valid()) {
  3901. _replace_node(type_id, node_id, "VisualShaderNodeVec2Constant", "VisualShaderNodeVec2Parameter");
  3902. var = vec2_const->get_constant();
  3903. caught = true;
  3904. }
  3905. } else {
  3906. Ref<VisualShaderNodeVec2Parameter> vec2_parameter = Object::cast_to<VisualShaderNodeVec2Parameter>(node.ptr());
  3907. if (vec2_parameter.is_valid()) {
  3908. _replace_node(type_id, node_id, "VisualShaderNodeVec2Parameter", "VisualShaderNodeVec2Constant");
  3909. var = vec2_parameter->get_default_value();
  3910. caught = true;
  3911. }
  3912. }
  3913. }
  3914. // vec3
  3915. if (!caught) {
  3916. if (!p_vice_versa) {
  3917. Ref<VisualShaderNodeVec3Constant> vec3_const = Object::cast_to<VisualShaderNodeVec3Constant>(node.ptr());
  3918. if (vec3_const.is_valid()) {
  3919. _replace_node(type_id, node_id, "VisualShaderNodeVec3Constant", "VisualShaderNodeVec3Parameter");
  3920. var = vec3_const->get_constant();
  3921. caught = true;
  3922. }
  3923. } else {
  3924. Ref<VisualShaderNodeVec3Parameter> vec3_parameter = Object::cast_to<VisualShaderNodeVec3Parameter>(node.ptr());
  3925. if (vec3_parameter.is_valid()) {
  3926. _replace_node(type_id, node_id, "VisualShaderNodeVec3Parameter", "VisualShaderNodeVec3Constant");
  3927. var = vec3_parameter->get_default_value();
  3928. caught = true;
  3929. }
  3930. }
  3931. }
  3932. // vec4
  3933. if (!caught) {
  3934. if (!p_vice_versa) {
  3935. Ref<VisualShaderNodeVec4Constant> vec4_const = Object::cast_to<VisualShaderNodeVec4Constant>(node.ptr());
  3936. if (vec4_const.is_valid()) {
  3937. _replace_node(type_id, node_id, "VisualShaderNodeVec4Constant", "VisualShaderNodeVec4Parameter");
  3938. var = vec4_const->get_constant();
  3939. caught = true;
  3940. }
  3941. } else {
  3942. Ref<VisualShaderNodeVec4Parameter> vec4_parameter = Object::cast_to<VisualShaderNodeVec4Parameter>(node.ptr());
  3943. if (vec4_parameter.is_valid()) {
  3944. _replace_node(type_id, node_id, "VisualShaderNodeVec4Parameter", "VisualShaderNodeVec4Constant");
  3945. var = vec4_parameter->get_default_value();
  3946. caught = true;
  3947. }
  3948. }
  3949. }
  3950. // color
  3951. if (!caught) {
  3952. if (!p_vice_versa) {
  3953. Ref<VisualShaderNodeColorConstant> color_const = Object::cast_to<VisualShaderNodeColorConstant>(node.ptr());
  3954. if (color_const.is_valid()) {
  3955. _replace_node(type_id, node_id, "VisualShaderNodeColorConstant", "VisualShaderNodeColorParameter");
  3956. var = color_const->get_constant();
  3957. caught = true;
  3958. }
  3959. } else {
  3960. Ref<VisualShaderNodeColorParameter> color_parameter = Object::cast_to<VisualShaderNodeColorParameter>(node.ptr());
  3961. if (color_parameter.is_valid()) {
  3962. _replace_node(type_id, node_id, "VisualShaderNodeColorParameter", "VisualShaderNodeColorConstant");
  3963. var = color_parameter->get_default_value();
  3964. caught = true;
  3965. }
  3966. }
  3967. }
  3968. // transform
  3969. if (!caught) {
  3970. if (!p_vice_versa) {
  3971. Ref<VisualShaderNodeTransformConstant> transform_const = Object::cast_to<VisualShaderNodeTransformConstant>(node.ptr());
  3972. if (transform_const.is_valid()) {
  3973. _replace_node(type_id, node_id, "VisualShaderNodeTransformConstant", "VisualShaderNodeTransformParameter");
  3974. var = transform_const->get_constant();
  3975. caught = true;
  3976. }
  3977. } else {
  3978. Ref<VisualShaderNodeTransformParameter> transform_parameter = Object::cast_to<VisualShaderNodeTransformParameter>(node.ptr());
  3979. if (transform_parameter.is_valid()) {
  3980. _replace_node(type_id, node_id, "VisualShaderNodeTransformParameter", "VisualShaderNodeTransformConstant");
  3981. var = transform_parameter->get_default_value();
  3982. caught = true;
  3983. }
  3984. }
  3985. }
  3986. ERR_CONTINUE(!caught);
  3987. int preview_port = node->get_output_port_for_preview();
  3988. if (!p_vice_versa) {
  3989. undo_redo->add_do_method(this, "_update_parameter", type_id, node_id, var, preview_port);
  3990. undo_redo->add_undo_method(this, "_update_constant", type_id, node_id, var, preview_port);
  3991. } else {
  3992. undo_redo->add_do_method(this, "_update_constant", type_id, node_id, var, preview_port);
  3993. undo_redo->add_undo_method(this, "_update_parameter", type_id, node_id, var, preview_port);
  3994. Ref<VisualShaderNodeParameter> parameter = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  3995. ERR_CONTINUE(parameter.is_null());
  3996. deleted_names.insert(parameter->get_parameter_name());
  3997. }
  3998. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type_id, node_id);
  3999. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type_id, node_id);
  4000. }
  4001. undo_redo->add_do_method(this, "_update_parameters", true);
  4002. undo_redo->add_undo_method(this, "_update_parameters", true);
  4003. if (deleted_names.size() > 0) {
  4004. _update_parameter_refs(deleted_names);
  4005. }
  4006. undo_redo->commit_action();
  4007. }
  4008. void VisualShaderEditor::_detach_nodes_from_frame(int p_type, const List<int> &p_nodes) {
  4009. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4010. for (int node_id : p_nodes) {
  4011. Ref<VisualShaderNode> node = visual_shader->get_node((VisualShader::Type)p_type, node_id);
  4012. if (node.is_null()) {
  4013. continue;
  4014. }
  4015. int frame_id = node->get_frame();
  4016. if (frame_id != -1) {
  4017. undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", p_type, node_id);
  4018. undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", p_type, node_id);
  4019. undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", p_type, node_id, frame_id);
  4020. undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", p_type, node_id, frame_id);
  4021. }
  4022. }
  4023. }
  4024. void VisualShaderEditor::_detach_nodes_from_frame_request() {
  4025. // Called from context menu.
  4026. List<int> to_detach_node_ids;
  4027. for (int i = 0; i < graph->get_child_count(); i++) {
  4028. GraphElement *gn = Object::cast_to<GraphElement>(graph->get_child(i));
  4029. if (gn) {
  4030. int id = String(gn->get_name()).to_int();
  4031. if (gn->is_selected()) {
  4032. to_detach_node_ids.push_back(id);
  4033. }
  4034. }
  4035. }
  4036. if (to_detach_node_ids.is_empty()) {
  4037. return;
  4038. }
  4039. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4040. undo_redo->create_action(TTR("Detach VisualShader Node(s) from Frame"));
  4041. _detach_nodes_from_frame(get_current_shader_type(), to_detach_node_ids);
  4042. undo_redo->commit_action();
  4043. }
  4044. void VisualShaderEditor::_delete_node_request(int p_type, int p_node) {
  4045. Ref<VisualShaderNode> node = visual_shader->get_node((VisualShader::Type)p_type, p_node);
  4046. if (!node->is_deletable()) {
  4047. return;
  4048. }
  4049. List<int> to_erase;
  4050. to_erase.push_back(p_node);
  4051. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4052. undo_redo->create_action(TTR("Delete VisualShader Node"));
  4053. _delete_nodes(p_type, to_erase);
  4054. undo_redo->commit_action();
  4055. }
  4056. void VisualShaderEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) {
  4057. List<int> to_erase;
  4058. if (p_nodes.is_empty()) {
  4059. // Called from context menu.
  4060. for (int i = 0; i < graph->get_child_count(); i++) {
  4061. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  4062. if (!graph_element) {
  4063. continue;
  4064. }
  4065. VisualShader::Type type = get_current_shader_type();
  4066. int id = String(graph_element->get_name()).to_int();
  4067. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  4068. if (vsnode->is_deletable() && graph_element->is_selected()) {
  4069. to_erase.push_back(graph_element->get_name().operator String().to_int());
  4070. }
  4071. }
  4072. } else {
  4073. VisualShader::Type type = get_current_shader_type();
  4074. for (int i = 0; i < p_nodes.size(); i++) {
  4075. int id = p_nodes[i].operator String().to_int();
  4076. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  4077. if (vsnode->is_deletable()) {
  4078. to_erase.push_back(id);
  4079. }
  4080. }
  4081. }
  4082. if (to_erase.is_empty()) {
  4083. return;
  4084. }
  4085. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4086. undo_redo->create_action(TTR("Delete VisualShader Node(s)"));
  4087. _delete_nodes(get_current_shader_type(), to_erase);
  4088. undo_redo->commit_action();
  4089. }
  4090. void VisualShaderEditor::_node_selected(Object *p_node) {
  4091. VisualShader::Type type = get_current_shader_type();
  4092. GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
  4093. ERR_FAIL_NULL(graph_element);
  4094. int id = String(graph_element->get_name()).to_int();
  4095. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  4096. ERR_FAIL_COND(vsnode.is_null());
  4097. }
  4098. void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
  4099. Ref<InputEventMouseMotion> mm = p_event;
  4100. Ref<InputEventMouseButton> mb = p_event;
  4101. VisualShader::Type type = get_current_shader_type();
  4102. // Highlight valid connection on which a node can be dropped.
  4103. if (mm.is_valid() && mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) {
  4104. Ref<GraphEdit::Connection> closest_connection;
  4105. graph->reset_all_connection_activity();
  4106. if (_check_node_drop_on_connection(graph->get_local_mouse_position(), &closest_connection)) {
  4107. graph->set_connection_activity(closest_connection->from_node, closest_connection->from_port, closest_connection->to_node, closest_connection->to_port, 1.0);
  4108. }
  4109. }
  4110. Ref<VisualShaderNode> selected_vsnode;
  4111. // Right click actions.
  4112. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {
  4113. selected_constants.clear();
  4114. selected_parameters.clear();
  4115. selected_frame = -1;
  4116. selected_float_constant = -1;
  4117. List<int> selected_deletable_graph_elements;
  4118. List<GraphElement *> selected_graph_elements;
  4119. for (int i = 0; i < graph->get_child_count(); i++) {
  4120. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  4121. if (!graph_element) {
  4122. continue;
  4123. }
  4124. int id = String(graph_element->get_name()).to_int();
  4125. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  4126. if (!graph_element->is_selected()) {
  4127. continue;
  4128. }
  4129. selected_graph_elements.push_back(graph_element);
  4130. if (!vsnode->is_deletable()) {
  4131. continue;
  4132. }
  4133. selected_deletable_graph_elements.push_back(id);
  4134. Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
  4135. selected_vsnode = node;
  4136. VisualShaderNodeFrame *frame_node = Object::cast_to<VisualShaderNodeFrame>(node.ptr());
  4137. if (frame_node != nullptr) {
  4138. selected_frame = id;
  4139. }
  4140. VisualShaderNodeConstant *constant_node = Object::cast_to<VisualShaderNodeConstant>(node.ptr());
  4141. if (constant_node != nullptr) {
  4142. selected_constants.insert(id);
  4143. }
  4144. VisualShaderNodeFloatConstant *float_constant_node = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
  4145. if (float_constant_node != nullptr) {
  4146. selected_float_constant = id;
  4147. }
  4148. VisualShaderNodeParameter *parameter_node = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  4149. if (parameter_node != nullptr && parameter_node->is_convertible_to_constant()) {
  4150. selected_parameters.insert(id);
  4151. }
  4152. }
  4153. if (selected_deletable_graph_elements.size() > 1) {
  4154. selected_frame = -1;
  4155. selected_float_constant = -1;
  4156. }
  4157. bool copy_buffer_empty = true;
  4158. for (const CopyItem &item : copy_items_buffer) {
  4159. if (!item.disabled) {
  4160. copy_buffer_empty = false;
  4161. break;
  4162. }
  4163. }
  4164. menu_point = graph->get_local_mouse_position();
  4165. Point2 gpos = get_screen_position() + get_local_mouse_position();
  4166. Ref<GraphEdit::Connection> closest_connection = graph->get_closest_connection_at_point(menu_point);
  4167. if (closest_connection.is_valid()) {
  4168. clicked_connection = closest_connection;
  4169. saved_node_pos = graph->get_local_mouse_position();
  4170. saved_node_pos_dirty = true;
  4171. connection_popup_menu->set_position(gpos);
  4172. connection_popup_menu->reset_size();
  4173. connection_popup_menu->popup();
  4174. } else if (selected_graph_elements.is_empty() && copy_buffer_empty) {
  4175. _show_members_dialog(true);
  4176. } else {
  4177. popup_menu->set_item_disabled(NodeMenuOptions::CUT, selected_deletable_graph_elements.is_empty());
  4178. popup_menu->set_item_disabled(NodeMenuOptions::COPY, selected_deletable_graph_elements.is_empty());
  4179. popup_menu->set_item_disabled(NodeMenuOptions::PASTE, copy_buffer_empty);
  4180. popup_menu->set_item_disabled(NodeMenuOptions::DELETE_, selected_deletable_graph_elements.is_empty());
  4181. popup_menu->set_item_disabled(NodeMenuOptions::DUPLICATE, selected_deletable_graph_elements.is_empty());
  4182. popup_menu->set_item_disabled(NodeMenuOptions::CLEAR_COPY_BUFFER, copy_buffer_empty);
  4183. int temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR2);
  4184. if (temp != -1) {
  4185. popup_menu->remove_item(temp);
  4186. }
  4187. temp = popup_menu->get_item_index(NodeMenuOptions::FLOAT_CONSTANTS);
  4188. if (temp != -1) {
  4189. popup_menu->remove_item(temp);
  4190. }
  4191. temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS);
  4192. if (temp != -1) {
  4193. popup_menu->remove_item(temp);
  4194. }
  4195. temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS);
  4196. if (temp != -1) {
  4197. popup_menu->remove_item(temp);
  4198. }
  4199. temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR3);
  4200. if (temp != -1) {
  4201. popup_menu->remove_item(temp);
  4202. }
  4203. temp = popup_menu->get_item_index(NodeMenuOptions::UNLINK_FROM_PARENT_FRAME);
  4204. if (temp != -1) {
  4205. popup_menu->remove_item(temp);
  4206. }
  4207. temp = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_TITLE);
  4208. if (temp != -1) {
  4209. popup_menu->remove_item(temp);
  4210. }
  4211. temp = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR);
  4212. if (temp != -1) {
  4213. popup_menu->remove_item(temp);
  4214. }
  4215. temp = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_COLOR);
  4216. if (temp != -1) {
  4217. popup_menu->remove_item(temp);
  4218. }
  4219. temp = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  4220. if (temp != -1) {
  4221. popup_menu->remove_item(temp);
  4222. }
  4223. if (selected_constants.size() > 0 || selected_parameters.size() > 0) {
  4224. popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2);
  4225. if (selected_float_constant != -1) {
  4226. if (!constants_submenu) {
  4227. constants_submenu = memnew(PopupMenu);
  4228. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  4229. constants_submenu->add_item(float_constant_defs[i].name, i);
  4230. }
  4231. constants_submenu->connect("index_pressed", callable_mp(this, &VisualShaderEditor::_float_constant_selected));
  4232. }
  4233. popup_menu->add_submenu_node_item(TTR("Float Constants"), constants_submenu, int(NodeMenuOptions::FLOAT_CONSTANTS));
  4234. }
  4235. if (selected_constants.size() > 0) {
  4236. popup_menu->add_item(TTR("Convert Constant(s) to Parameter(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS);
  4237. }
  4238. if (selected_parameters.size() > 0) {
  4239. popup_menu->add_item(TTR("Convert Parameter(s) to Constant(s)"), NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS);
  4240. }
  4241. }
  4242. // Check if any selected node is attached to a frame.
  4243. bool is_attached_to_frame = false;
  4244. for (GraphElement *graph_element : selected_graph_elements) {
  4245. if (graph->get_element_frame(graph_element->get_name())) {
  4246. is_attached_to_frame = true;
  4247. break;
  4248. }
  4249. }
  4250. if (is_attached_to_frame) {
  4251. popup_menu->add_item(TTR("Detach from Parent Frame"), NodeMenuOptions::UNLINK_FROM_PARENT_FRAME);
  4252. }
  4253. if (selected_frame != -1) {
  4254. popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3);
  4255. popup_menu->add_item(TTR("Set Frame Title"), NodeMenuOptions::SET_FRAME_TITLE);
  4256. popup_menu->add_check_item(TTR("Enable Auto Shrink"), NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  4257. popup_menu->add_check_item(TTR("Enable Tint Color"), NodeMenuOptions::ENABLE_FRAME_COLOR);
  4258. VisualShaderNodeFrame *frame_ref = Object::cast_to<VisualShaderNodeFrame>(selected_vsnode.ptr());
  4259. if (frame_ref) {
  4260. int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR);
  4261. popup_menu->set_item_checked(item_index, frame_ref->is_tint_color_enabled());
  4262. if (frame_ref->is_tint_color_enabled()) {
  4263. popup_menu->add_item(TTR("Set Tint Color"), NodeMenuOptions::SET_FRAME_COLOR);
  4264. }
  4265. item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  4266. popup_menu->set_item_checked(item_index, frame_ref->is_autoshrink_enabled());
  4267. }
  4268. }
  4269. popup_menu->set_position(gpos);
  4270. popup_menu->reset_size();
  4271. popup_menu->popup();
  4272. }
  4273. }
  4274. }
  4275. void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type, VisualShaderNode::PortType p_output_port_type) {
  4276. if (members_input_port_type != p_input_port_type || members_output_port_type != p_output_port_type) {
  4277. members_input_port_type = p_input_port_type;
  4278. members_output_port_type = p_output_port_type;
  4279. _update_options_menu();
  4280. }
  4281. if (at_mouse_pos) {
  4282. saved_node_pos_dirty = true;
  4283. saved_node_pos = graph->get_local_mouse_position();
  4284. Point2 gpos = get_screen_position() + get_local_mouse_position();
  4285. members_dialog->set_position(gpos);
  4286. } else {
  4287. saved_node_pos_dirty = false;
  4288. members_dialog->set_position(graph->get_screen_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  4289. }
  4290. if (members_dialog->is_visible()) {
  4291. members_dialog->grab_focus();
  4292. return;
  4293. }
  4294. members_dialog->popup();
  4295. // Keep dialog within window bounds.
  4296. Rect2 window_rect = Rect2(get_window()->get_position(), get_window()->get_size());
  4297. Rect2 dialog_rect = Rect2(members_dialog->get_position(), members_dialog->get_size());
  4298. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0);
  4299. members_dialog->set_position(members_dialog->get_position() - difference);
  4300. node_filter->grab_focus();
  4301. node_filter->select_all();
  4302. }
  4303. void VisualShaderEditor::_varying_menu_id_pressed(int p_idx) {
  4304. switch (VaryingMenuOptions(p_idx)) {
  4305. case VaryingMenuOptions::ADD: {
  4306. _show_add_varying_dialog();
  4307. } break;
  4308. case VaryingMenuOptions::REMOVE: {
  4309. _show_remove_varying_dialog();
  4310. } break;
  4311. default:
  4312. break;
  4313. }
  4314. }
  4315. void VisualShaderEditor::_show_add_varying_dialog() {
  4316. _varying_name_changed(varying_name->get_text());
  4317. add_varying_dialog->set_position(graph->get_screen_position() + varying_button->get_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  4318. add_varying_dialog->popup();
  4319. varying_name->grab_focus();
  4320. // Keep dialog within window bounds.
  4321. Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size());
  4322. Rect2 dialog_rect = Rect2(add_varying_dialog->get_position(), add_varying_dialog->get_size());
  4323. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0);
  4324. add_varying_dialog->set_position(add_varying_dialog->get_position() - difference);
  4325. }
  4326. void VisualShaderEditor::_show_remove_varying_dialog() {
  4327. remove_varying_dialog->set_position(graph->get_screen_position() + varying_button->get_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  4328. remove_varying_dialog->popup();
  4329. varyings->grab_focus();
  4330. // Keep dialog within window bounds.
  4331. Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size());
  4332. Rect2 dialog_rect = Rect2(remove_varying_dialog->get_position(), remove_varying_dialog->get_size());
  4333. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0);
  4334. remove_varying_dialog->set_position(remove_varying_dialog->get_position() - difference);
  4335. }
  4336. void VisualShaderEditor::_sbox_input(const Ref<InputEvent> &p_event) {
  4337. // Redirect navigational key events to the tree.
  4338. Ref<InputEventKey> key = p_event;
  4339. if (key.is_valid()) {
  4340. 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")) {
  4341. members->gui_input(key);
  4342. node_filter->accept_event();
  4343. }
  4344. }
  4345. }
  4346. void VisualShaderEditor::_param_filter_changed(const String &p_text) {
  4347. param_filter_name = p_text;
  4348. if (!_update_preview_parameter_tree()) {
  4349. _clear_preview_param();
  4350. }
  4351. }
  4352. void VisualShaderEditor::_param_property_changed(const String &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
  4353. if (p_changing) {
  4354. return;
  4355. }
  4356. String raw_prop_name = p_property.trim_prefix("shader_parameter/");
  4357. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4358. undo_redo->create_action(vformat(TTR("Edit Preview Parameter: %s"), p_property));
  4359. undo_redo->add_do_method(visual_shader.ptr(), "_set_preview_shader_parameter", raw_prop_name, p_value);
  4360. undo_redo->add_undo_method(visual_shader.ptr(), "_set_preview_shader_parameter", raw_prop_name, preview_material->get(p_property));
  4361. undo_redo->add_do_method(this, "_update_current_param");
  4362. undo_redo->add_undo_method(this, "_update_current_param");
  4363. undo_redo->commit_action();
  4364. }
  4365. void VisualShaderEditor::_update_current_param() {
  4366. if (current_prop != nullptr) {
  4367. String name = current_prop->get_meta("id");
  4368. if (visual_shader->_has_preview_shader_parameter(name)) {
  4369. preview_material->set("shader_parameter/" + name, visual_shader->_get_preview_shader_parameter(name));
  4370. } else {
  4371. preview_material->set("shader_parameter/" + name, Variant());
  4372. }
  4373. current_prop->update_property();
  4374. current_prop->update_editor_property_status();
  4375. current_prop->update_cache();
  4376. }
  4377. }
  4378. void VisualShaderEditor::_param_selected() {
  4379. _clear_preview_param();
  4380. TreeItem *item = parameters->get_selected();
  4381. selected_param_id = item->get_meta("id");
  4382. PropertyInfo pi = parameter_props.get(selected_param_id);
  4383. EditorProperty *prop = EditorInspector::instantiate_property_editor(preview_material.ptr(), pi.type, pi.name, pi.hint, pi.hint_string, pi.usage);
  4384. if (!prop) {
  4385. return;
  4386. }
  4387. prop->connect("property_changed", callable_mp(this, &VisualShaderEditor::_param_property_changed));
  4388. prop->set_h_size_flags(SIZE_EXPAND_FILL);
  4389. prop->set_object_and_property(preview_material.ptr(), "shader_parameter/" + pi.name);
  4390. prop->set_label(TTR("Value:"));
  4391. prop->update_property();
  4392. prop->update_editor_property_status();
  4393. prop->update_cache();
  4394. current_prop = prop;
  4395. current_prop->set_meta("id", selected_param_id);
  4396. param_vbox2->add_child(prop);
  4397. param_vbox->show();
  4398. }
  4399. void VisualShaderEditor::_param_unselected() {
  4400. parameters->deselect_all();
  4401. _clear_preview_param();
  4402. }
  4403. void VisualShaderEditor::_help_open() {
  4404. OS::get_singleton()->shell_open(vformat("%s/tutorials/shaders/visual_shaders.html", GODOT_VERSION_DOCS_URL));
  4405. }
  4406. void VisualShaderEditor::_notification(int p_what) {
  4407. switch (p_what) {
  4408. case NOTIFICATION_POSTINITIALIZE: {
  4409. _update_options_menu();
  4410. } break;
  4411. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  4412. if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/panning")) {
  4413. 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")));
  4414. graph->set_warped_panning(EDITOR_GET("editors/panning/warped_mouse_panning"));
  4415. }
  4416. if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/visual_editors")) {
  4417. graph->set_minimap_opacity(EDITOR_GET("editors/visual_editors/minimap_opacity"));
  4418. graph->set_grid_pattern((GraphEdit::GridPattern) int(EDITOR_GET("editors/visual_editors/grid_pattern")));
  4419. graph->set_connection_lines_curvature(EDITOR_GET("editors/visual_editors/lines_curvature"));
  4420. _update_graph();
  4421. }
  4422. } break;
  4423. case NOTIFICATION_ENTER_TREE: {
  4424. node_filter->set_clear_button_enabled(true);
  4425. // collapse tree by default
  4426. TreeItem *category = members->get_root()->get_first_child();
  4427. while (category) {
  4428. category->set_collapsed(true);
  4429. TreeItem *sub_category = category->get_first_child();
  4430. while (sub_category) {
  4431. sub_category->set_collapsed(true);
  4432. sub_category = sub_category->get_next();
  4433. }
  4434. category = category->get_next();
  4435. }
  4436. 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")));
  4437. graph->set_warped_panning(EDITOR_GET("editors/panning/warped_mouse_panning"));
  4438. } break;
  4439. case NOTIFICATION_THEME_CHANGED: {
  4440. site_search->set_button_icon(get_editor_theme_icon(SNAME("ExternalLink")));
  4441. highend_label->set_modulate(get_theme_color(SNAME("highend_color"), EditorStringName(Editor)));
  4442. param_filter->set_right_icon(Control::get_editor_theme_icon(SNAME("Search")));
  4443. node_filter->set_right_icon(Control::get_editor_theme_icon(SNAME("Search")));
  4444. code_preview_button->set_button_icon(Control::get_editor_theme_icon(SNAME("Shader")));
  4445. shader_preview_button->set_button_icon(Control::get_editor_theme_icon(SNAME("SubViewport")));
  4446. {
  4447. Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color");
  4448. Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color");
  4449. Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
  4450. Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color");
  4451. Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
  4452. Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color");
  4453. Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color");
  4454. Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color");
  4455. Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color");
  4456. Color error_color = get_theme_color(SNAME("error_color"), EditorStringName(Editor));
  4457. preview_text->add_theme_color_override("background_color", background_color);
  4458. varying_error_label->add_theme_color_override(SceneStringName(font_color), error_color);
  4459. for (const String &E : keyword_list) {
  4460. if (ShaderLanguage::is_control_flow_keyword(E)) {
  4461. syntax_highlighter->add_keyword_color(E, control_flow_keyword_color);
  4462. } else {
  4463. syntax_highlighter->add_keyword_color(E, keyword_color);
  4464. }
  4465. }
  4466. preview_text->begin_bulk_theme_override();
  4467. preview_text->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("expression"), EditorStringName(EditorFonts)));
  4468. preview_text->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("expression_size"), EditorStringName(EditorFonts)));
  4469. preview_text->add_theme_color_override(SceneStringName(font_color), text_color);
  4470. preview_text->end_bulk_theme_override();
  4471. syntax_highlighter->set_number_color(number_color);
  4472. syntax_highlighter->set_symbol_color(symbol_color);
  4473. syntax_highlighter->set_function_color(function_color);
  4474. syntax_highlighter->set_member_variable_color(members_color);
  4475. syntax_highlighter->clear_color_regions();
  4476. syntax_highlighter->add_color_region("/*", "*/", comment_color, false);
  4477. syntax_highlighter->add_color_region("//", "", comment_color, true);
  4478. preview_text->clear_comment_delimiters();
  4479. preview_text->add_comment_delimiter("/*", "*/", false);
  4480. preview_text->add_comment_delimiter("//", "", true);
  4481. error_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Panel")));
  4482. error_label->begin_bulk_theme_override();
  4483. error_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));
  4484. error_label->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));
  4485. error_label->add_theme_color_override(SceneStringName(font_color), error_color);
  4486. error_label->end_bulk_theme_override();
  4487. }
  4488. tools->set_button_icon(get_editor_theme_icon(SNAME("Tools")));
  4489. preview_tools->set_button_icon(get_editor_theme_icon(SNAME("Tools")));
  4490. if (is_visible_in_tree()) {
  4491. _update_graph();
  4492. }
  4493. update_toggle_files_button();
  4494. } break;
  4495. case NOTIFICATION_VISIBILITY_CHANGED: {
  4496. update_toggle_files_button();
  4497. } break;
  4498. case NOTIFICATION_DRAG_BEGIN: {
  4499. Dictionary dd = get_viewport()->gui_get_drag_data();
  4500. if (members->is_visible_in_tree() && dd.has("id")) {
  4501. members->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
  4502. }
  4503. } break;
  4504. case NOTIFICATION_DRAG_END: {
  4505. members->set_drop_mode_flags(0);
  4506. } break;
  4507. }
  4508. }
  4509. void VisualShaderEditor::_scroll_offset_changed(const Vector2 &p_scroll) {
  4510. if (!shader_fully_loaded) {
  4511. return;
  4512. }
  4513. panning_debounce_timer->start();
  4514. }
  4515. void VisualShaderEditor::_node_changed(int p_id) {
  4516. if (is_visible_in_tree()) {
  4517. _update_graph();
  4518. }
  4519. }
  4520. void VisualShaderEditor::_nodes_linked_to_frame_request(const TypedArray<StringName> &p_nodes, const StringName &p_frame) {
  4521. Vector<int> node_ids;
  4522. for (int i = 0; i < p_nodes.size(); i++) {
  4523. node_ids.push_back(p_nodes[i].operator String().to_int());
  4524. }
  4525. frame_node_id_to_link_to = p_frame.operator String().to_int();
  4526. nodes_link_to_frame_buffer = node_ids;
  4527. }
  4528. void VisualShaderEditor::_frame_rect_changed(const GraphFrame *p_frame, const Rect2 &p_new_rect) {
  4529. if (p_frame == nullptr) {
  4530. return;
  4531. }
  4532. int node_id = String(p_frame->get_name()).to_int();
  4533. Ref<VisualShaderNodeResizableBase> vsnode = visual_shader->get_node(get_current_shader_type(), node_id);
  4534. if (vsnode.is_null()) {
  4535. return;
  4536. }
  4537. vsnode->set_size(p_new_rect.size / graph->get_zoom());
  4538. }
  4539. void VisualShaderEditor::_dup_copy_nodes(int p_type, List<CopyItem> &r_items, List<VisualShader::Connection> &r_connections) {
  4540. VisualShader::Type type = (VisualShader::Type)p_type;
  4541. selection_center.x = 0.0f;
  4542. selection_center.y = 0.0f;
  4543. HashSet<int> nodes;
  4544. for (int i = 0; i < graph->get_child_count(); i++) {
  4545. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  4546. if (graph_element) {
  4547. int id = String(graph_element->get_name()).to_int();
  4548. Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
  4549. Ref<VisualShaderNodeOutput> output = node;
  4550. if (output.is_valid()) { // can't duplicate output
  4551. continue;
  4552. }
  4553. if (node.is_valid() && graph_element->is_selected()) {
  4554. Vector2 pos = visual_shader->get_node_position(type, id);
  4555. selection_center += pos;
  4556. CopyItem item;
  4557. item.id = id;
  4558. item.node = visual_shader->get_node(type, id)->duplicate();
  4559. item.position = visual_shader->get_node_position(type, id);
  4560. Ref<VisualShaderNodeResizableBase> resizable_base = node;
  4561. if (resizable_base.is_valid()) {
  4562. item.size = resizable_base->get_size();
  4563. }
  4564. Ref<VisualShaderNodeGroupBase> group = node;
  4565. if (group.is_valid()) {
  4566. item.group_inputs = group->get_inputs();
  4567. item.group_outputs = group->get_outputs();
  4568. }
  4569. Ref<VisualShaderNodeExpression> expression = node;
  4570. if (expression.is_valid()) {
  4571. item.expression = expression->get_expression();
  4572. }
  4573. r_items.push_back(item);
  4574. nodes.insert(id);
  4575. }
  4576. }
  4577. }
  4578. List<VisualShader::Connection> node_connections;
  4579. visual_shader->get_node_connections(type, &node_connections);
  4580. for (const VisualShader::Connection &E : node_connections) {
  4581. if (nodes.has(E.from_node) && nodes.has(E.to_node)) {
  4582. r_connections.push_back(E);
  4583. }
  4584. }
  4585. selection_center /= (float)r_items.size();
  4586. }
  4587. 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) {
  4588. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4589. if (p_duplicate) {
  4590. undo_redo->create_action(TTR("Duplicate VisualShader Node(s)"));
  4591. } else {
  4592. bool copy_buffer_empty = true;
  4593. for (const CopyItem &item : copy_items_buffer) {
  4594. if (!item.disabled) {
  4595. copy_buffer_empty = false;
  4596. break;
  4597. }
  4598. }
  4599. if (copy_buffer_empty) {
  4600. return;
  4601. }
  4602. undo_redo->create_action(TTR("Paste VisualShader Node(s)"));
  4603. }
  4604. VisualShader::Type type = (VisualShader::Type)p_type;
  4605. int base_id = visual_shader->get_valid_node_id(type);
  4606. int id_from = base_id;
  4607. HashMap<int, int> connection_remap; // Used for connections and frame attachments.
  4608. HashSet<int> unsupported_set;
  4609. HashSet<int> added_set;
  4610. for (CopyItem &item : r_items) {
  4611. if (item.disabled) {
  4612. unsupported_set.insert(item.id);
  4613. continue;
  4614. }
  4615. connection_remap[item.id] = id_from;
  4616. Ref<VisualShaderNode> node = item.node->duplicate();
  4617. node->set_frame(-1); // Do not reattach nodes to frame (for now).
  4618. Ref<VisualShaderNodeResizableBase> resizable_base = Object::cast_to<VisualShaderNodeResizableBase>(node.ptr());
  4619. if (resizable_base.is_valid()) {
  4620. undo_redo->add_do_method(node.ptr(), "set_size", item.size);
  4621. }
  4622. Ref<VisualShaderNodeFrame> frame = Object::cast_to<VisualShaderNodeFrame>(node.ptr());
  4623. if (frame.is_valid()) {
  4624. // Do not reattach nodes to frame (for now).
  4625. undo_redo->add_do_method(node.ptr(), "set_attached_nodes", PackedInt32Array());
  4626. }
  4627. Ref<VisualShaderNodeGroupBase> group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
  4628. if (group.is_valid()) {
  4629. undo_redo->add_do_method(node.ptr(), "set_inputs", item.group_inputs);
  4630. undo_redo->add_do_method(node.ptr(), "set_outputs", item.group_outputs);
  4631. }
  4632. Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  4633. if (expression.is_valid()) {
  4634. undo_redo->add_do_method(node.ptr(), "set_expression", item.expression);
  4635. }
  4636. undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, node, item.position + p_offset, id_from);
  4637. undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_from, false, false);
  4638. added_set.insert(id_from);
  4639. id_from++;
  4640. }
  4641. // Attach nodes to frame.
  4642. for (const CopyItem &item : r_items) {
  4643. Ref<VisualShaderNode> node = item.node;
  4644. if (node->get_frame() == -1) {
  4645. continue;
  4646. }
  4647. int new_node_id = connection_remap[item.id];
  4648. int new_frame_id = node->get_frame();
  4649. undo_redo->add_do_method(visual_shader.ptr(), "attach_node_to_frame", type, new_node_id, new_frame_id);
  4650. undo_redo->add_do_method(graph_plugin.ptr(), "attach_node_to_frame", type, new_node_id, new_frame_id);
  4651. }
  4652. // Connect nodes.
  4653. for (const VisualShader::Connection &E : p_connections) {
  4654. if (unsupported_set.has(E.from_node) || unsupported_set.has(E.to_node)) {
  4655. continue;
  4656. }
  4657. 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);
  4658. 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);
  4659. 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);
  4660. }
  4661. id_from = base_id;
  4662. for (const CopyItem &item : r_items) {
  4663. if (item.disabled) {
  4664. continue;
  4665. }
  4666. undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_from);
  4667. undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_from, false);
  4668. id_from++;
  4669. }
  4670. undo_redo->commit_action();
  4671. // Reselect nodes by excluding the other ones.
  4672. for (int i = 0; i < graph->get_child_count(); i++) {
  4673. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  4674. if (graph_element) {
  4675. int id = String(graph_element->get_name()).to_int();
  4676. if (added_set.has(id)) {
  4677. graph_element->set_selected(true);
  4678. } else {
  4679. graph_element->set_selected(false);
  4680. }
  4681. }
  4682. }
  4683. }
  4684. void VisualShaderEditor::_clear_copy_buffer() {
  4685. copy_items_buffer.clear();
  4686. copy_connections_buffer.clear();
  4687. }
  4688. void VisualShaderEditor::_duplicate_nodes() {
  4689. int type = get_current_shader_type();
  4690. List<CopyItem> items;
  4691. List<VisualShader::Connection> node_connections;
  4692. _dup_copy_nodes(type, items, node_connections);
  4693. if (items.is_empty()) {
  4694. return;
  4695. }
  4696. _dup_paste_nodes(type, items, node_connections, Vector2(10, 10) * EDSCALE, true);
  4697. }
  4698. void VisualShaderEditor::_copy_nodes(bool p_cut) {
  4699. _clear_copy_buffer();
  4700. _dup_copy_nodes(get_current_shader_type(), copy_items_buffer, copy_connections_buffer);
  4701. if (p_cut) {
  4702. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4703. undo_redo->create_action(TTR("Cut VisualShader Node(s)"));
  4704. List<int> ids;
  4705. for (const CopyItem &E : copy_items_buffer) {
  4706. ids.push_back(E.id);
  4707. }
  4708. _delete_nodes(get_current_shader_type(), ids);
  4709. undo_redo->commit_action();
  4710. }
  4711. }
  4712. void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2 &p_custom_position) {
  4713. if (copy_items_buffer.is_empty()) {
  4714. return;
  4715. }
  4716. int type = get_current_shader_type();
  4717. float scale = graph->get_zoom();
  4718. Vector2 mpos;
  4719. if (p_use_custom_position) {
  4720. mpos = p_custom_position;
  4721. } else {
  4722. mpos = graph->get_local_mouse_position();
  4723. }
  4724. _dup_paste_nodes(type, copy_items_buffer, copy_connections_buffer, graph->get_scroll_offset() / scale + mpos / scale - selection_center, false);
  4725. }
  4726. void VisualShaderEditor::_type_selected(int p_id) {
  4727. int offset = VisualShader::TYPE_VERTEX;
  4728. if (mode & MODE_FLAGS_PARTICLES) {
  4729. offset = VisualShader::TYPE_START;
  4730. if (p_id + offset > VisualShader::TYPE_PROCESS) {
  4731. custom_mode_box->set_visible(false);
  4732. custom_mode_enabled = false;
  4733. } else {
  4734. custom_mode_box->set_visible(true);
  4735. if (custom_mode_box->is_pressed()) {
  4736. custom_mode_enabled = true;
  4737. offset += 3;
  4738. }
  4739. }
  4740. } else if (mode & MODE_FLAGS_SKY) {
  4741. offset = VisualShader::TYPE_SKY;
  4742. } else if (mode & MODE_FLAGS_FOG) {
  4743. offset = VisualShader::TYPE_FOG;
  4744. }
  4745. set_current_shader_type(VisualShader::Type(p_id + offset));
  4746. _update_nodes();
  4747. _update_graph();
  4748. graph->grab_focus();
  4749. }
  4750. void VisualShaderEditor::_custom_mode_toggled(bool p_enabled) {
  4751. if (!(mode & MODE_FLAGS_PARTICLES)) {
  4752. return;
  4753. }
  4754. custom_mode_enabled = p_enabled;
  4755. int id = edit_type->get_selected() + 3;
  4756. if (p_enabled) {
  4757. set_current_shader_type(VisualShader::Type(id + 3));
  4758. } else {
  4759. set_current_shader_type(VisualShader::Type(id));
  4760. }
  4761. _update_options_menu();
  4762. _update_graph();
  4763. }
  4764. void VisualShaderEditor::_input_select_item(Ref<VisualShaderNodeInput> p_input, const String &p_name) {
  4765. String prev_name = p_input->get_input_name();
  4766. if (p_name == prev_name) {
  4767. return;
  4768. }
  4769. VisualShaderNode::PortType next_input_type = p_input->get_input_type_by_name(p_name);
  4770. VisualShaderNode::PortType prev_input_type = p_input->get_input_type_by_name(prev_name);
  4771. bool type_changed = next_input_type != prev_input_type;
  4772. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  4773. undo_redo_man->create_action(TTR("Visual Shader Input Type Changed"));
  4774. undo_redo_man->add_do_method(p_input.ptr(), "set_input_name", p_name);
  4775. undo_redo_man->add_undo_method(p_input.ptr(), "set_input_name", prev_name);
  4776. if (type_changed) {
  4777. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  4778. VisualShader::Type type = VisualShader::Type(type_id);
  4779. int id = visual_shader->find_node_id(type, p_input);
  4780. if (id != VisualShader::NODE_ID_INVALID) {
  4781. bool is_expanded = p_input->is_output_port_expandable(0) && p_input->_is_output_port_expanded(0);
  4782. int type_size = 0;
  4783. if (is_expanded) {
  4784. switch (next_input_type) {
  4785. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  4786. type_size = 2;
  4787. } break;
  4788. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  4789. type_size = 3;
  4790. } break;
  4791. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  4792. type_size = 4;
  4793. } break;
  4794. default:
  4795. break;
  4796. }
  4797. }
  4798. List<VisualShader::Connection> conns;
  4799. visual_shader->get_node_connections(type, &conns);
  4800. for (const VisualShader::Connection &E : conns) {
  4801. int cn_from_node = E.from_node;
  4802. int cn_from_port = E.from_port;
  4803. int cn_to_node = E.to_node;
  4804. int cn_to_port = E.to_port;
  4805. if (cn_from_node == id) {
  4806. 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));
  4807. if (is_incompatible_types || cn_from_port > type_size) {
  4808. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4809. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4810. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4811. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4812. }
  4813. }
  4814. }
  4815. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  4816. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  4817. }
  4818. }
  4819. }
  4820. undo_redo_man->commit_action();
  4821. }
  4822. void VisualShaderEditor::_parameter_ref_select_item(Ref<VisualShaderNodeParameterRef> p_parameter_ref, const String &p_name) {
  4823. String prev_name = p_parameter_ref->get_parameter_name();
  4824. if (p_name == prev_name) {
  4825. return;
  4826. }
  4827. bool type_changed = p_parameter_ref->get_parameter_type_by_name(p_name) != p_parameter_ref->get_parameter_type_by_name(prev_name);
  4828. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  4829. undo_redo_man->create_action(TTR("ParameterRef Name Changed"));
  4830. undo_redo_man->add_do_method(p_parameter_ref.ptr(), "set_parameter_name", p_name);
  4831. undo_redo_man->add_undo_method(p_parameter_ref.ptr(), "set_parameter_name", prev_name);
  4832. // update output port
  4833. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  4834. VisualShader::Type type = VisualShader::Type(type_id);
  4835. int id = visual_shader->find_node_id(type, p_parameter_ref);
  4836. if (id != VisualShader::NODE_ID_INVALID) {
  4837. if (type_changed) {
  4838. List<VisualShader::Connection> conns;
  4839. visual_shader->get_node_connections(type, &conns);
  4840. for (const VisualShader::Connection &E : conns) {
  4841. if (E.from_node == id) {
  4842. 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))) {
  4843. continue;
  4844. }
  4845. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4846. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4847. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4848. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4849. }
  4850. }
  4851. }
  4852. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  4853. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  4854. break;
  4855. }
  4856. }
  4857. undo_redo_man->commit_action();
  4858. }
  4859. void VisualShaderEditor::_varying_select_item(Ref<VisualShaderNodeVarying> p_varying, const String &p_name) {
  4860. String prev_name = p_varying->get_varying_name();
  4861. if (p_name == prev_name) {
  4862. return;
  4863. }
  4864. bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid();
  4865. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  4866. undo_redo_man->create_action(TTR("Varying Name Changed"));
  4867. undo_redo_man->add_do_method(p_varying.ptr(), "set_varying_name", p_name);
  4868. undo_redo_man->add_undo_method(p_varying.ptr(), "set_varying_name", prev_name);
  4869. VisualShader::VaryingType vtype = p_varying->get_varying_type_by_name(p_name);
  4870. VisualShader::VaryingType prev_vtype = p_varying->get_varying_type_by_name(prev_name);
  4871. bool type_changed = vtype != prev_vtype;
  4872. if (type_changed) {
  4873. undo_redo_man->add_do_method(p_varying.ptr(), "set_varying_type", vtype);
  4874. undo_redo_man->add_undo_method(p_varying.ptr(), "set_varying_type", prev_vtype);
  4875. }
  4876. // update ports
  4877. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  4878. VisualShader::Type type = VisualShader::Type(type_id);
  4879. int id = visual_shader->find_node_id(type, p_varying);
  4880. if (id != VisualShader::NODE_ID_INVALID) {
  4881. if (type_changed) {
  4882. List<VisualShader::Connection> conns;
  4883. visual_shader->get_node_connections(type, &conns);
  4884. for (const VisualShader::Connection &E : conns) {
  4885. if (is_getter) {
  4886. if (E.from_node == id) {
  4887. 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))) {
  4888. continue;
  4889. }
  4890. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4891. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4892. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4893. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4894. }
  4895. } else {
  4896. if (E.to_node == id) {
  4897. 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))) {
  4898. continue;
  4899. }
  4900. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4901. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4902. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4903. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4904. }
  4905. }
  4906. }
  4907. }
  4908. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  4909. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  4910. break;
  4911. }
  4912. }
  4913. undo_redo_man->commit_action();
  4914. }
  4915. void VisualShaderEditor::_float_constant_selected(int p_which) {
  4916. ERR_FAIL_INDEX(p_which, MAX_FLOAT_CONST_DEFS);
  4917. VisualShader::Type type = get_current_shader_type();
  4918. Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, selected_float_constant);
  4919. ERR_FAIL_COND(node.is_null());
  4920. if (Math::is_equal_approx(node->get_constant(), float_constant_defs[p_which].value)) {
  4921. return; // same
  4922. }
  4923. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4924. undo_redo->create_action(vformat(TTR("Set Constant: %s"), float_constant_defs[p_which].name));
  4925. undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_which].value);
  4926. undo_redo->add_undo_method(node.ptr(), "set_constant", node->get_constant());
  4927. undo_redo->commit_action();
  4928. }
  4929. void VisualShaderEditor::_member_filter_changed(const String &p_text) {
  4930. _update_options_menu();
  4931. }
  4932. void VisualShaderEditor::_member_selected() {
  4933. TreeItem *item = members->get_selected();
  4934. if (item != nullptr && item->has_meta("id")) {
  4935. members_dialog->get_ok_button()->set_disabled(false);
  4936. highend_label->set_visible(add_options[item->get_meta("id")].highend);
  4937. node_desc->set_text(_get_description(item->get_meta("id")));
  4938. } else {
  4939. highend_label->set_visible(false);
  4940. members_dialog->get_ok_button()->set_disabled(true);
  4941. node_desc->set_text("");
  4942. }
  4943. }
  4944. void VisualShaderEditor::_member_create() {
  4945. TreeItem *item = members->get_selected();
  4946. if (item != nullptr && item->has_meta("id")) {
  4947. int idx = members->get_selected()->get_meta("id");
  4948. if (connection_node_insert_requested) {
  4949. from_node = String(clicked_connection->from_node).to_int();
  4950. from_slot = clicked_connection->from_port;
  4951. to_node = String(clicked_connection->to_node).to_int();
  4952. to_slot = clicked_connection->to_port;
  4953. connection_node_insert_requested = false;
  4954. saved_node_pos_dirty = true;
  4955. // Find both graph nodes and get their positions.
  4956. GraphNode *from_graph_element = Object::cast_to<GraphNode>(graph->get_node(itos(from_node)));
  4957. GraphNode *to_graph_element = Object::cast_to<GraphNode>(graph->get_node(itos(to_node)));
  4958. ERR_FAIL_NULL(from_graph_element);
  4959. ERR_FAIL_NULL(to_graph_element);
  4960. // Since the size of the node to add is not known yet, it's not possible to center it exactly.
  4961. float zoom = graph->get_zoom();
  4962. 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));
  4963. }
  4964. _add_node(idx, add_options[idx].ops);
  4965. members_dialog->hide();
  4966. }
  4967. }
  4968. void VisualShaderEditor::_member_cancel() {
  4969. to_node = -1;
  4970. to_slot = -1;
  4971. from_node = -1;
  4972. from_slot = -1;
  4973. connection_node_insert_requested = false;
  4974. }
  4975. void VisualShaderEditor::_update_varying_tree() {
  4976. varyings->clear();
  4977. TreeItem *root = varyings->create_item();
  4978. int count = visual_shader->get_varyings_count();
  4979. for (int i = 0; i < count; i++) {
  4980. const VisualShader::Varying *varying = visual_shader->get_varying_by_index(i);
  4981. if (varying) {
  4982. TreeItem *item = varyings->create_item(root);
  4983. item->set_text(0, varying->name);
  4984. if (i == 0) {
  4985. item->select(0);
  4986. }
  4987. switch (varying->type) {
  4988. case VisualShader::VARYING_TYPE_FLOAT:
  4989. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)));
  4990. break;
  4991. case VisualShader::VARYING_TYPE_INT:
  4992. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)));
  4993. break;
  4994. case VisualShader::VARYING_TYPE_UINT:
  4995. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)));
  4996. break;
  4997. case VisualShader::VARYING_TYPE_VECTOR_2D:
  4998. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)));
  4999. break;
  5000. case VisualShader::VARYING_TYPE_VECTOR_3D:
  5001. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)));
  5002. break;
  5003. case VisualShader::VARYING_TYPE_VECTOR_4D:
  5004. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)));
  5005. break;
  5006. case VisualShader::VARYING_TYPE_BOOLEAN:
  5007. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)));
  5008. break;
  5009. case VisualShader::VARYING_TYPE_TRANSFORM:
  5010. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)));
  5011. break;
  5012. default:
  5013. break;
  5014. }
  5015. }
  5016. }
  5017. varying_button->get_popup()->set_item_disabled(int(VaryingMenuOptions::REMOVE), count == 0);
  5018. }
  5019. void VisualShaderEditor::_varying_create() {
  5020. _add_varying(varying_name->get_text(), (VisualShader::VaryingMode)varying_mode->get_selected(), (VisualShader::VaryingType)varying_type->get_selected());
  5021. add_varying_dialog->hide();
  5022. }
  5023. void VisualShaderEditor::_varying_validate() {
  5024. bool has_error = false;
  5025. String error;
  5026. String varname = varying_name->get_text();
  5027. if (!varname.is_valid_ascii_identifier()) {
  5028. error += TTR("Invalid name for varying.");
  5029. has_error = true;
  5030. } else if (visual_shader->has_varying(varname)) {
  5031. error += TTR("Varying with that name is already exist.");
  5032. has_error = true;
  5033. }
  5034. if (varying_type->get_selected() == 6 && varying_mode->get_selected() == VisualShader::VaryingMode::VARYING_MODE_VERTEX_TO_FRAG_LIGHT) {
  5035. if (has_error) {
  5036. error += "\n";
  5037. }
  5038. error += vformat(TTR("Boolean type cannot be used with `%s` varying mode."), "Vertex -> [Fragment, Light]");
  5039. has_error = true;
  5040. }
  5041. if (has_error) {
  5042. varying_error_label->show();
  5043. varying_error_label->set_text(error);
  5044. add_varying_dialog->get_ok_button()->set_disabled(true);
  5045. } else {
  5046. varying_error_label->hide();
  5047. varying_error_label->set_text("");
  5048. add_varying_dialog->get_ok_button()->set_disabled(false);
  5049. }
  5050. add_varying_dialog->reset_size();
  5051. }
  5052. void VisualShaderEditor::_varying_type_changed(int p_index) {
  5053. _varying_validate();
  5054. }
  5055. void VisualShaderEditor::_varying_mode_changed(int p_index) {
  5056. _varying_validate();
  5057. }
  5058. void VisualShaderEditor::_varying_name_changed(const String &p_name) {
  5059. _varying_validate();
  5060. }
  5061. void VisualShaderEditor::_varying_deleted() {
  5062. TreeItem *item = varyings->get_selected();
  5063. if (item != nullptr) {
  5064. _remove_varying(item->get_text(0));
  5065. remove_varying_dialog->hide();
  5066. }
  5067. }
  5068. void VisualShaderEditor::_varying_selected() {
  5069. add_varying_dialog->get_ok_button()->set_disabled(false);
  5070. }
  5071. void VisualShaderEditor::_varying_unselected() {
  5072. add_varying_dialog->get_ok_button()->set_disabled(true);
  5073. }
  5074. void VisualShaderEditor::_tools_menu_option(int p_idx) {
  5075. TreeItem *category = members->get_root()->get_first_child();
  5076. switch (p_idx) {
  5077. case EXPAND_ALL:
  5078. while (category) {
  5079. category->set_collapsed(false);
  5080. TreeItem *sub_category = category->get_first_child();
  5081. while (sub_category) {
  5082. sub_category->set_collapsed(false);
  5083. sub_category = sub_category->get_next();
  5084. }
  5085. category = category->get_next();
  5086. }
  5087. break;
  5088. case COLLAPSE_ALL:
  5089. while (category) {
  5090. category->set_collapsed(true);
  5091. TreeItem *sub_category = category->get_first_child();
  5092. while (sub_category) {
  5093. sub_category->set_collapsed(true);
  5094. sub_category = sub_category->get_next();
  5095. }
  5096. category = category->get_next();
  5097. }
  5098. break;
  5099. default:
  5100. break;
  5101. }
  5102. }
  5103. void VisualShaderEditor::_node_menu_id_pressed(int p_idx) {
  5104. switch (p_idx) {
  5105. case NodeMenuOptions::ADD:
  5106. _show_members_dialog(true);
  5107. break;
  5108. case NodeMenuOptions::CUT:
  5109. _copy_nodes(true);
  5110. break;
  5111. case NodeMenuOptions::COPY:
  5112. _copy_nodes(false);
  5113. break;
  5114. case NodeMenuOptions::PASTE:
  5115. _paste_nodes(true, menu_point);
  5116. break;
  5117. case NodeMenuOptions::DELETE_:
  5118. _delete_nodes_request(TypedArray<StringName>());
  5119. break;
  5120. case NodeMenuOptions::DUPLICATE:
  5121. _duplicate_nodes();
  5122. break;
  5123. case NodeMenuOptions::CLEAR_COPY_BUFFER:
  5124. _clear_copy_buffer();
  5125. break;
  5126. case NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS:
  5127. _convert_constants_to_parameters(false);
  5128. break;
  5129. case NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS:
  5130. _convert_constants_to_parameters(true);
  5131. break;
  5132. case NodeMenuOptions::UNLINK_FROM_PARENT_FRAME:
  5133. _detach_nodes_from_frame_request();
  5134. break;
  5135. case NodeMenuOptions::SET_FRAME_TITLE:
  5136. _frame_title_popup_show(get_screen_position() + get_local_mouse_position(), selected_frame);
  5137. break;
  5138. case NodeMenuOptions::ENABLE_FRAME_COLOR:
  5139. _frame_color_enabled_changed(selected_frame);
  5140. break;
  5141. case NodeMenuOptions::SET_FRAME_COLOR:
  5142. _frame_color_popup_show(get_screen_position() + get_local_mouse_position(), selected_frame);
  5143. break;
  5144. case NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK:
  5145. _frame_autoshrink_enabled_changed(selected_frame);
  5146. break;
  5147. default:
  5148. break;
  5149. }
  5150. }
  5151. void VisualShaderEditor::_connection_menu_id_pressed(int p_idx) {
  5152. switch (p_idx) {
  5153. case ConnectionMenuOptions::DISCONNECT: {
  5154. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  5155. undo_redo->create_action(TTR("Disconnect"));
  5156. 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);
  5157. 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);
  5158. 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);
  5159. 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);
  5160. undo_redo->commit_action();
  5161. } break;
  5162. case ConnectionMenuOptions::INSERT_NEW_NODE: {
  5163. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  5164. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  5165. Ref<VisualShaderNode> node1 = visual_shader->get_node(get_current_shader_type(), String(clicked_connection->from_node).to_int());
  5166. if (node1.is_valid()) {
  5167. output_port_type = node1->get_output_port_type(from_slot);
  5168. }
  5169. Ref<VisualShaderNode> node2 = visual_shader->get_node(get_current_shader_type(), String(clicked_connection->to_node).to_int());
  5170. if (node2.is_valid()) {
  5171. input_port_type = node2->get_input_port_type(to_slot);
  5172. }
  5173. connection_node_insert_requested = true;
  5174. _show_members_dialog(true, input_port_type, output_port_type);
  5175. } break;
  5176. case ConnectionMenuOptions::INSERT_NEW_REROUTE: {
  5177. from_node = String(clicked_connection->from_node).to_int();
  5178. from_slot = clicked_connection->from_port;
  5179. to_node = String(clicked_connection->to_node).to_int();
  5180. to_slot = clicked_connection->to_port;
  5181. // Manual offset to place the port exactly at the mouse position.
  5182. saved_node_pos -= Vector2(11 * EDSCALE * graph->get_zoom(), 50 * EDSCALE * graph->get_zoom());
  5183. // Find reroute addoptions.
  5184. int idx = -1;
  5185. for (int i = 0; i < add_options.size(); i++) {
  5186. if (add_options[i].name == "Reroute") {
  5187. idx = i;
  5188. break;
  5189. }
  5190. }
  5191. _add_node(idx, add_options[idx].ops);
  5192. } break;
  5193. default:
  5194. break;
  5195. }
  5196. }
  5197. Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  5198. if (p_point == Vector2(Math::INF, Math::INF)) {
  5199. return Variant();
  5200. }
  5201. if (p_from == members) {
  5202. TreeItem *it = members->get_item_at_position(p_point);
  5203. if (!it) {
  5204. return Variant();
  5205. }
  5206. if (!it->has_meta("id")) {
  5207. return Variant();
  5208. }
  5209. int id = it->get_meta("id");
  5210. AddOption op = add_options[id];
  5211. Dictionary d;
  5212. d["id"] = id;
  5213. Label *label = memnew(Label);
  5214. label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  5215. label->set_text(it->get_text(0));
  5216. label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  5217. set_drag_preview(label);
  5218. return d;
  5219. }
  5220. return Variant();
  5221. }
  5222. bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  5223. if (p_point == Vector2(Math::INF, Math::INF)) {
  5224. return false;
  5225. }
  5226. if (p_from == graph) {
  5227. Dictionary d = p_data;
  5228. if (d.has("id")) {
  5229. return true;
  5230. }
  5231. if (d.has("files")) {
  5232. return true;
  5233. }
  5234. }
  5235. return false;
  5236. }
  5237. void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  5238. if (p_point == Vector2(Math::INF, Math::INF)) {
  5239. return;
  5240. }
  5241. if (p_from == graph) {
  5242. Dictionary d = p_data;
  5243. if (d.has("id")) {
  5244. int idx = d["id"];
  5245. saved_node_pos = p_point;
  5246. saved_node_pos_dirty = true;
  5247. _add_node(idx, add_options[idx].ops);
  5248. } else if (d.has("files")) {
  5249. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  5250. undo_redo->create_action(TTR("Add Node(s) to Visual Shader"));
  5251. if (d["files"].get_type() == Variant::PACKED_STRING_ARRAY) {
  5252. PackedStringArray arr = d["files"];
  5253. for (int i = 0; i < arr.size(); i++) {
  5254. String type = ResourceLoader::get_resource_type(arr[i]);
  5255. if (type == "GDScript") {
  5256. Ref<Script> scr = ResourceLoader::load(arr[i]);
  5257. if (scr->get_instance_base_type() == "VisualShaderNodeCustom") {
  5258. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5259. saved_node_pos_dirty = true;
  5260. int idx = -1;
  5261. for (int j = custom_node_option_idx; j < add_options.size(); j++) {
  5262. if (add_options[j].script.is_valid()) {
  5263. if (add_options[j].script->get_path() == arr[i]) {
  5264. idx = j;
  5265. break;
  5266. }
  5267. }
  5268. }
  5269. if (idx != -1) {
  5270. _add_node(idx, {}, arr[i], i);
  5271. }
  5272. }
  5273. } else if (type == "CurveTexture") {
  5274. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5275. saved_node_pos_dirty = true;
  5276. _add_node(curve_node_option_idx, {}, arr[i], i);
  5277. } else if (type == "CurveXYZTexture") {
  5278. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5279. saved_node_pos_dirty = true;
  5280. _add_node(curve_xyz_node_option_idx, {}, arr[i], i);
  5281. } else if (ClassDB::get_parent_class(type) == "Texture2D") {
  5282. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5283. saved_node_pos_dirty = true;
  5284. _add_node(texture2d_node_option_idx, {}, arr[i], i);
  5285. } else if (type == "Texture2DArray") {
  5286. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5287. saved_node_pos_dirty = true;
  5288. _add_node(texture2d_array_node_option_idx, {}, arr[i], i);
  5289. } else if (ClassDB::get_parent_class(type) == "Texture3D") {
  5290. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5291. saved_node_pos_dirty = true;
  5292. _add_node(texture3d_node_option_idx, {}, arr[i], i);
  5293. } else if (type == "Cubemap") {
  5294. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5295. saved_node_pos_dirty = true;
  5296. _add_node(cubemap_node_option_idx, {}, arr[i], i);
  5297. } else if (type == "Mesh" && visual_shader->get_mode() == Shader::MODE_PARTICLES &&
  5298. (get_current_shader_type() == VisualShader::TYPE_START || get_current_shader_type() == VisualShader::TYPE_START_CUSTOM)) {
  5299. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5300. saved_node_pos_dirty = true;
  5301. _add_node(mesh_emitter_option_idx, {}, arr[i], i);
  5302. }
  5303. }
  5304. }
  5305. undo_redo->commit_action();
  5306. }
  5307. }
  5308. }
  5309. void VisualShaderEditor::_show_preview_text() {
  5310. code_preview_showed = !code_preview_showed;
  5311. if (code_preview_showed) {
  5312. if (code_preview_first) {
  5313. code_preview_window->set_size(Size2(400 * EDSCALE, 600 * EDSCALE));
  5314. code_preview_window->popup_centered();
  5315. code_preview_first = false;
  5316. } else {
  5317. code_preview_window->popup();
  5318. }
  5319. if (pending_update_preview) {
  5320. _update_preview();
  5321. pending_update_preview = false;
  5322. }
  5323. } else {
  5324. code_preview_window->hide();
  5325. }
  5326. }
  5327. void VisualShaderEditor::_preview_close_requested() {
  5328. code_preview_showed = false;
  5329. code_preview_button->set_pressed(false);
  5330. }
  5331. static ShaderLanguage::DataType _visual_shader_editor_get_global_shader_uniform_type(const StringName &p_variable) {
  5332. RS::GlobalShaderParameterType gvt = RS::get_singleton()->global_shader_parameter_get_type(p_variable);
  5333. return (ShaderLanguage::DataType)RS::global_shader_uniform_type_get_shader_datatype(gvt);
  5334. }
  5335. void VisualShaderEditor::_update_preview() {
  5336. if (!code_preview_showed) {
  5337. pending_update_preview = true;
  5338. return;
  5339. }
  5340. String code = visual_shader->get_code();
  5341. preview_text->set_text(code);
  5342. ShaderLanguage::ShaderCompileInfo info;
  5343. info.functions = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(visual_shader->get_mode()));
  5344. info.render_modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(visual_shader->get_mode()));
  5345. info.stencil_modes = ShaderTypes::get_singleton()->get_stencil_modes(RenderingServer::ShaderMode(visual_shader->get_mode()));
  5346. info.shader_types = ShaderTypes::get_singleton()->get_types();
  5347. info.global_shader_uniform_type_func = _visual_shader_editor_get_global_shader_uniform_type;
  5348. for (int i = 0; i < preview_text->get_line_count(); i++) {
  5349. preview_text->set_line_background_color(i, Color(0, 0, 0, 0));
  5350. }
  5351. String preprocessed_code;
  5352. {
  5353. String path = visual_shader->get_path();
  5354. String error_pp;
  5355. List<ShaderPreprocessor::FilePosition> err_positions;
  5356. ShaderPreprocessor preprocessor;
  5357. Error err = preprocessor.preprocess(code, path, preprocessed_code, &error_pp, &err_positions);
  5358. if (err != OK) {
  5359. ERR_FAIL_COND(err_positions.is_empty());
  5360. String file = err_positions.front()->get().file;
  5361. int err_line = err_positions.front()->get().line;
  5362. Color error_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color");
  5363. preview_text->set_line_background_color(err_line - 1, error_line_color);
  5364. error_panel->show();
  5365. error_label->set_text("error(" + file + ":" + itos(err_line) + "): " + error_pp);
  5366. shader_error = true;
  5367. return;
  5368. }
  5369. }
  5370. ShaderLanguage sl;
  5371. Error err = sl.compile(preprocessed_code, info);
  5372. if (err != OK) {
  5373. int err_line;
  5374. String err_text;
  5375. Vector<ShaderLanguage::FilePosition> include_positions = sl.get_include_positions();
  5376. if (include_positions.size() > 1) {
  5377. // Error is in an include.
  5378. err_line = include_positions[0].line;
  5379. 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();
  5380. } else {
  5381. err_line = sl.get_error_line();
  5382. err_text = "error(" + itos(err_line) + "): " + sl.get_error_text();
  5383. }
  5384. Color error_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color");
  5385. preview_text->set_line_background_color(err_line - 1, error_line_color);
  5386. error_panel->show();
  5387. error_label->set_text(err_text);
  5388. shader_error = true;
  5389. } else {
  5390. error_panel->hide();
  5391. shader_error = false;
  5392. }
  5393. }
  5394. void VisualShaderEditor::_update_next_previews(int p_node_id) {
  5395. VisualShader::Type type = get_current_shader_type();
  5396. LocalVector<int> nodes;
  5397. _get_next_nodes_recursively(type, p_node_id, nodes);
  5398. for (int node_id : nodes) {
  5399. if (graph_plugin->is_preview_visible(node_id)) {
  5400. graph_plugin->update_node_deferred(type, node_id);
  5401. }
  5402. }
  5403. }
  5404. void VisualShaderEditor::_get_next_nodes_recursively(VisualShader::Type p_type, int p_node_id, LocalVector<int> &r_nodes) const {
  5405. const LocalVector<int> &next_connections = visual_shader->get_next_connected_nodes(p_type, p_node_id);
  5406. for (int node_id : next_connections) {
  5407. r_nodes.push_back(node_id);
  5408. _get_next_nodes_recursively(p_type, node_id, r_nodes);
  5409. }
  5410. }
  5411. void VisualShaderEditor::_visibility_changed() {
  5412. if (!is_visible()) {
  5413. if (code_preview_window->is_visible()) {
  5414. code_preview_button->set_pressed(false);
  5415. code_preview_window->hide();
  5416. code_preview_showed = false;
  5417. }
  5418. }
  5419. }
  5420. void VisualShaderEditor::_show_shader_preview() {
  5421. shader_preview_showed = !shader_preview_showed;
  5422. if (shader_preview_showed) {
  5423. shader_preview_vbox->show();
  5424. } else {
  5425. shader_preview_vbox->hide();
  5426. _param_unselected();
  5427. }
  5428. }
  5429. void VisualShaderEditor::set_toggle_list_control(Control *p_control) {
  5430. toggle_files_list = p_control;
  5431. }
  5432. void VisualShaderEditor::_toggle_files_pressed() {
  5433. ERR_FAIL_NULL(toggle_files_list);
  5434. toggle_files_list->set_visible(!toggle_files_list->is_visible());
  5435. update_toggle_files_button();
  5436. }
  5437. void VisualShaderEditor::_bind_methods() {
  5438. ClassDB::bind_method("_update_nodes", &VisualShaderEditor::_update_nodes);
  5439. ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph);
  5440. ClassDB::bind_method("_input_select_item", &VisualShaderEditor::_input_select_item);
  5441. ClassDB::bind_method("_parameter_ref_select_item", &VisualShaderEditor::_parameter_ref_select_item);
  5442. ClassDB::bind_method("_varying_select_item", &VisualShaderEditor::_varying_select_item);
  5443. ClassDB::bind_method("_set_node_size", &VisualShaderEditor::_set_node_size);
  5444. ClassDB::bind_method("_update_parameters", &VisualShaderEditor::_update_parameters);
  5445. ClassDB::bind_method("_update_varyings", &VisualShaderEditor::_update_varyings);
  5446. ClassDB::bind_method("_update_varying_tree", &VisualShaderEditor::_update_varying_tree);
  5447. ClassDB::bind_method("_set_mode", &VisualShaderEditor::_set_mode);
  5448. ClassDB::bind_method("_update_constant", &VisualShaderEditor::_update_constant);
  5449. ClassDB::bind_method("_update_parameter", &VisualShaderEditor::_update_parameter);
  5450. ClassDB::bind_method("_update_next_previews", &VisualShaderEditor::_update_next_previews);
  5451. ClassDB::bind_method("_update_current_param", &VisualShaderEditor::_update_current_param);
  5452. }
  5453. VisualShaderEditor::VisualShaderEditor() {
  5454. vs_editor_cache.instantiate();
  5455. vs_editor_cache->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join("vs_editor_cache.cfg"));
  5456. ShaderLanguage::get_keyword_list(&keyword_list);
  5457. EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &VisualShaderEditor::_resource_saved));
  5458. FileSystemDock::get_singleton()->get_script_create_dialog()->connect("script_created", callable_mp(this, &VisualShaderEditor::_script_created));
  5459. FileSystemDock::get_singleton()->connect("resource_removed", callable_mp(this, &VisualShaderEditor::_resource_removed));
  5460. HSplitContainer *main_box = memnew(HSplitContainer);
  5461. main_box->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  5462. add_child(main_box);
  5463. graph = memnew(GraphEdit);
  5464. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  5465. graph->set_h_size_flags(SIZE_EXPAND_FILL);
  5466. graph->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
  5467. graph->set_grid_pattern(GraphEdit::GridPattern::GRID_PATTERN_DOTS);
  5468. int grid_pattern = EDITOR_GET("editors/visual_editors/grid_pattern");
  5469. graph->set_grid_pattern((GraphEdit::GridPattern)grid_pattern);
  5470. graph->set_show_zoom_label(true);
  5471. main_box->add_child(graph);
  5472. SET_DRAG_FORWARDING_GCD(graph, VisualShaderEditor);
  5473. float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity");
  5474. graph->set_minimap_opacity(graph_minimap_opacity);
  5475. float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature");
  5476. graph->set_connection_lines_curvature(graph_lines_curvature);
  5477. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR);
  5478. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5479. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5480. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN);
  5481. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5482. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5483. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5484. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_TRANSFORM);
  5485. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SAMPLER);
  5486. //graph->add_valid_left_disconnect_type(0);
  5487. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  5488. graph->connect("connection_request", callable_mp(this, &VisualShaderEditor::_connection_request), CONNECT_DEFERRED);
  5489. graph->connect("disconnection_request", callable_mp(this, &VisualShaderEditor::_disconnection_request), CONNECT_DEFERRED);
  5490. graph->connect("node_selected", callable_mp(this, &VisualShaderEditor::_node_selected));
  5491. graph->connect("scroll_offset_changed", callable_mp(this, &VisualShaderEditor::_scroll_offset_changed));
  5492. graph->connect("duplicate_nodes_request", callable_mp(this, &VisualShaderEditor::_duplicate_nodes));
  5493. graph->connect("copy_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes).bind(false));
  5494. graph->connect("cut_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes).bind(true));
  5495. graph->connect("paste_nodes_request", callable_mp(this, &VisualShaderEditor::_paste_nodes).bind(false, Point2()));
  5496. graph->connect("delete_nodes_request", callable_mp(this, &VisualShaderEditor::_delete_nodes_request));
  5497. graph->connect(SceneStringName(gui_input), callable_mp(this, &VisualShaderEditor::_graph_gui_input));
  5498. graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty));
  5499. graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty));
  5500. graph->connect("connection_drag_ended", callable_mp(this, &VisualShaderEditor::_connection_drag_ended));
  5501. graph->connect(SceneStringName(visibility_changed), callable_mp(this, &VisualShaderEditor::_visibility_changed));
  5502. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR);
  5503. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5504. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5505. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5506. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5507. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5508. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5509. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR);
  5510. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5511. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5512. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5513. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5514. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5515. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5516. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR);
  5517. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5518. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5519. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5520. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5521. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5522. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5523. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR);
  5524. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5525. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5526. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5527. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5528. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5529. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5530. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR);
  5531. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5532. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5533. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5534. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5535. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5536. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5537. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR);
  5538. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5539. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5540. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5541. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5542. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5543. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5544. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR);
  5545. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5546. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5547. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5548. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5549. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5550. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5551. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShaderNode::PORT_TYPE_TRANSFORM);
  5552. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SAMPLER, VisualShaderNode::PORT_TYPE_SAMPLER);
  5553. info_label = memnew(Label);
  5554. info_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  5555. info_label->set_text(vformat(TTR("Hold %s Key To Swap Connections"), keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL)));
  5556. info_label->set_anchors_and_offsets_preset(Control::PRESET_BOTTOM_WIDE, PRESET_MODE_MINSIZE, 20);
  5557. info_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  5558. info_label->hide();
  5559. graph->get_top_layer()->add_child(info_label);
  5560. PanelContainer *toolbar_panel = static_cast<PanelContainer *>(graph->get_menu_hbox()->get_parent());
  5561. toolbar_panel->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE, PRESET_MODE_MINSIZE, 10);
  5562. toolbar_panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
  5563. toolbar = memnew(HFlowContainer);
  5564. {
  5565. LocalVector<Node *> nodes;
  5566. for (int i = 0; i < graph->get_menu_hbox()->get_child_count(); i++) {
  5567. Node *child = graph->get_menu_hbox()->get_child(i);
  5568. nodes.push_back(child);
  5569. }
  5570. for (Node *node : nodes) {
  5571. graph->get_menu_hbox()->remove_child(node);
  5572. toolbar->add_child(node);
  5573. }
  5574. graph->get_menu_hbox()->hide();
  5575. toolbar_panel->add_child(toolbar);
  5576. }
  5577. VSeparator *vs = memnew(VSeparator);
  5578. toolbar->add_child(vs);
  5579. toolbar->move_child(vs, 0);
  5580. custom_mode_box = memnew(CheckBox);
  5581. custom_mode_box->set_text(TTR("Custom"));
  5582. custom_mode_box->set_pressed(false);
  5583. custom_mode_box->set_visible(false);
  5584. custom_mode_box->connect(SceneStringName(toggled), callable_mp(this, &VisualShaderEditor::_custom_mode_toggled));
  5585. edit_type_standard = memnew(OptionButton);
  5586. edit_type_standard->add_item(TTR("Vertex"));
  5587. edit_type_standard->add_item(TTR("Fragment"));
  5588. edit_type_standard->add_item(TTR("Light"));
  5589. edit_type_standard->select(1);
  5590. edit_type_standard->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected));
  5591. edit_type_particles = memnew(OptionButton);
  5592. edit_type_particles->add_item(TTR("Start"));
  5593. edit_type_particles->add_item(TTR("Process"));
  5594. edit_type_particles->add_item(TTR("Collide"));
  5595. edit_type_particles->select(0);
  5596. edit_type_particles->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected));
  5597. edit_type_sky = memnew(OptionButton);
  5598. edit_type_sky->add_item(TTR("Sky"));
  5599. edit_type_sky->select(0);
  5600. edit_type_sky->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected));
  5601. edit_type_fog = memnew(OptionButton);
  5602. edit_type_fog->add_item(TTR("Fog"));
  5603. edit_type_fog->select(0);
  5604. edit_type_fog->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected));
  5605. edit_type = edit_type_standard;
  5606. toolbar->add_child(custom_mode_box);
  5607. toolbar->move_child(custom_mode_box, 0);
  5608. toolbar->add_child(edit_type_standard);
  5609. toolbar->move_child(edit_type_standard, 0);
  5610. toolbar->add_child(edit_type_particles);
  5611. toolbar->move_child(edit_type_particles, 0);
  5612. toolbar->add_child(edit_type_sky);
  5613. toolbar->move_child(edit_type_sky, 0);
  5614. toolbar->add_child(edit_type_fog);
  5615. toolbar->move_child(edit_type_fog, 0);
  5616. add_node = memnew(Button);
  5617. add_node->set_flat(true);
  5618. add_node->set_text(TTR("Add Node..."));
  5619. toolbar->add_child(add_node);
  5620. toolbar->move_child(add_node, 0);
  5621. add_node->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_members_dialog).bind(false, VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PORT_TYPE_MAX));
  5622. graph->connect("graph_elements_linked_to_frame_request", callable_mp(this, &VisualShaderEditor::_nodes_linked_to_frame_request));
  5623. graph->connect("frame_rect_changed", callable_mp(this, &VisualShaderEditor::_frame_rect_changed));
  5624. varying_button = memnew(MenuButton);
  5625. varying_button->set_text(TTR("Manage Varyings"));
  5626. varying_button->set_switch_on_hover(true);
  5627. toolbar->add_child(varying_button);
  5628. PopupMenu *varying_menu = varying_button->get_popup();
  5629. varying_menu->add_item(TTR("Add Varying"), int(VaryingMenuOptions::ADD));
  5630. varying_menu->add_item(TTR("Remove Varying"), int(VaryingMenuOptions::REMOVE));
  5631. varying_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_varying_menu_id_pressed));
  5632. code_preview_button = memnew(Button);
  5633. code_preview_button->set_theme_type_variation(SceneStringName(FlatButton));
  5634. code_preview_button->set_toggle_mode(true);
  5635. code_preview_button->set_tooltip_text(TTR("Show generated shader code."));
  5636. toolbar->add_child(code_preview_button);
  5637. code_preview_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_preview_text));
  5638. shader_preview_button = memnew(Button);
  5639. shader_preview_button->set_theme_type_variation(SceneStringName(FlatButton));
  5640. shader_preview_button->set_toggle_mode(true);
  5641. shader_preview_button->set_tooltip_text(TTR("Toggle shader preview."));
  5642. shader_preview_button->set_pressed(true);
  5643. toolbar->add_child(shader_preview_button);
  5644. shader_preview_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_shader_preview));
  5645. Control *spacer = memnew(Control);
  5646. spacer->set_h_size_flags(Control::SIZE_EXPAND);
  5647. toolbar->add_child(spacer);
  5648. site_search = memnew(Button);
  5649. site_search->set_flat(true);
  5650. site_search->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_help_open));
  5651. site_search->set_text(TTR("Online Docs"));
  5652. site_search->set_tooltip_text(TTR("Open Godot online documentation."));
  5653. toolbar->add_child(site_search);
  5654. toolbar->add_child(memnew(VSeparator));
  5655. VSeparator *separator = memnew(VSeparator);
  5656. toolbar->add_child(separator);
  5657. toolbar->move_child(separator, 0);
  5658. separator = memnew(VSeparator);
  5659. toolbar->add_child(separator);
  5660. toolbar->move_child(separator, 0);
  5661. toggle_files_button = memnew(Button);
  5662. toggle_files_button->set_flat(true);
  5663. toggle_files_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_toggle_files_pressed));
  5664. toolbar->add_child(toggle_files_button);
  5665. toolbar->move_child(toggle_files_button, 0);
  5666. ///////////////////////////////////////
  5667. // CODE PREVIEW
  5668. ///////////////////////////////////////
  5669. code_preview_window = memnew(AcceptDialog);
  5670. code_preview_window->set_title(TTR("Generated Shader Code"));
  5671. code_preview_window->set_visible(code_preview_showed);
  5672. code_preview_window->set_ok_button_text(TTR("Close"));
  5673. code_preview_window->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_preview_close_requested));
  5674. code_preview_window->connect("canceled", callable_mp(this, &VisualShaderEditor::_preview_close_requested));
  5675. add_child(code_preview_window);
  5676. code_preview_vbox = memnew(VBoxContainer);
  5677. code_preview_window->add_child(code_preview_vbox);
  5678. code_preview_vbox->add_theme_constant_override("separation", 0);
  5679. preview_text = memnew(CodeEdit);
  5680. syntax_highlighter.instantiate();
  5681. code_preview_vbox->add_child(preview_text);
  5682. preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  5683. preview_text->set_syntax_highlighter(syntax_highlighter);
  5684. preview_text->set_draw_line_numbers(true);
  5685. preview_text->set_editable(false);
  5686. error_panel = memnew(PanelContainer);
  5687. code_preview_vbox->add_child(error_panel);
  5688. error_panel->set_visible(false);
  5689. error_label = memnew(Label);
  5690. error_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  5691. error_panel->add_child(error_label);
  5692. error_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  5693. ///////////////////////////////////////
  5694. // POPUP MENU
  5695. ///////////////////////////////////////
  5696. popup_menu = memnew(PopupMenu);
  5697. add_child(popup_menu);
  5698. popup_menu->set_hide_on_checkable_item_selection(false);
  5699. popup_menu->add_item(TTR("Add Node"), NodeMenuOptions::ADD);
  5700. popup_menu->add_separator();
  5701. popup_menu->add_item(TTR("Cut"), NodeMenuOptions::CUT);
  5702. popup_menu->add_item(TTR("Copy"), NodeMenuOptions::COPY);
  5703. popup_menu->add_item(TTR("Paste"), NodeMenuOptions::PASTE);
  5704. popup_menu->add_item(TTR("Delete"), NodeMenuOptions::DELETE_);
  5705. popup_menu->add_item(TTR("Duplicate"), NodeMenuOptions::DUPLICATE);
  5706. popup_menu->add_item(TTR("Clear Copy Buffer"), NodeMenuOptions::CLEAR_COPY_BUFFER);
  5707. popup_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_node_menu_id_pressed));
  5708. connection_popup_menu = memnew(PopupMenu);
  5709. add_child(connection_popup_menu);
  5710. connection_popup_menu->add_item(TTR("Disconnect"), ConnectionMenuOptions::DISCONNECT);
  5711. connection_popup_menu->add_item(TTR("Insert New Node"), ConnectionMenuOptions::INSERT_NEW_NODE);
  5712. connection_popup_menu->add_item(TTR("Insert New Reroute"), ConnectionMenuOptions::INSERT_NEW_REROUTE);
  5713. connection_popup_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_connection_menu_id_pressed));
  5714. ///////////////////////////////////////
  5715. // SHADER PREVIEW
  5716. ///////////////////////////////////////
  5717. shader_preview_vbox = memnew(VBoxContainer);
  5718. shader_preview_vbox->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
  5719. main_box->add_child(shader_preview_vbox);
  5720. VSplitContainer *preview_split = memnew(VSplitContainer);
  5721. preview_split->set_v_size_flags(SIZE_EXPAND_FILL);
  5722. shader_preview_vbox->add_child(preview_split);
  5723. // Initialize material editor.
  5724. {
  5725. env.instantiate();
  5726. Ref<Sky> sky = memnew(Sky());
  5727. env->set_sky(sky);
  5728. env->set_background(Environment::BG_COLOR);
  5729. env->set_ambient_source(Environment::AMBIENT_SOURCE_SKY);
  5730. env->set_reflection_source(Environment::REFLECTION_SOURCE_SKY);
  5731. preview_material.instantiate();
  5732. preview_material->connect(CoreStringName(property_list_changed), callable_mp(this, &VisualShaderEditor::_update_preview_parameter_list));
  5733. material_editor = memnew(MaterialEditor);
  5734. preview_split->add_child(material_editor);
  5735. }
  5736. VBoxContainer *params_vbox = memnew(VBoxContainer);
  5737. preview_split->add_child(params_vbox);
  5738. HBoxContainer *filter_hbox = memnew(HBoxContainer);
  5739. params_vbox->add_child(filter_hbox);
  5740. param_filter = memnew(LineEdit);
  5741. filter_hbox->add_child(param_filter);
  5742. param_filter->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_param_filter_changed));
  5743. param_filter->set_h_size_flags(SIZE_EXPAND_FILL);
  5744. param_filter->set_placeholder(TTR("Filter Parameters"));
  5745. preview_tools = memnew(MenuButton);
  5746. filter_hbox->add_child(preview_tools);
  5747. preview_tools->set_tooltip_text(TTR("Options"));
  5748. preview_tools->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_preview_tools_menu_option));
  5749. preview_tools->get_popup()->add_item(TTR("Copy Parameters From Material"), COPY_PARAMS_FROM_MATERIAL);
  5750. preview_tools->get_popup()->add_item(TTR("Paste Parameters To Material"), PASTE_PARAMS_TO_MATERIAL);
  5751. ScrollContainer *sc = memnew(ScrollContainer);
  5752. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  5753. params_vbox->add_child(sc);
  5754. parameters = memnew(Tree);
  5755. parameters->set_hide_root(true);
  5756. parameters->set_allow_reselect(true);
  5757. parameters->set_hide_folding(false);
  5758. parameters->set_h_size_flags(SIZE_EXPAND_FILL);
  5759. parameters->set_v_size_flags(SIZE_EXPAND_FILL);
  5760. parameters->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  5761. parameters->set_theme_type_variation("TreeSecondary");
  5762. parameters->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_param_selected));
  5763. parameters->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_param_unselected));
  5764. sc->add_child(parameters);
  5765. param_vbox = memnew(VBoxContainer);
  5766. param_vbox->set_v_size_flags(SIZE_EXPAND_FILL);
  5767. param_vbox->hide();
  5768. params_vbox->add_child(param_vbox);
  5769. ScrollContainer *sc2 = memnew(ScrollContainer);
  5770. sc2->set_v_size_flags(SIZE_EXPAND_FILL);
  5771. param_vbox->add_child(sc2);
  5772. param_vbox2 = memnew(VBoxContainer);
  5773. param_vbox2->set_h_size_flags(SIZE_EXPAND_FILL);
  5774. sc2->add_child(param_vbox2);
  5775. ///////////////////////////////////////
  5776. // SHADER NODES TREE
  5777. ///////////////////////////////////////
  5778. VBoxContainer *members_vb = memnew(VBoxContainer);
  5779. members_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  5780. HBoxContainer *filter_hb = memnew(HBoxContainer);
  5781. members_vb->add_child(filter_hb);
  5782. node_filter = memnew(LineEdit);
  5783. filter_hb->add_child(node_filter);
  5784. node_filter->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_member_filter_changed));
  5785. node_filter->connect(SceneStringName(gui_input), callable_mp(this, &VisualShaderEditor::_sbox_input));
  5786. node_filter->set_h_size_flags(SIZE_EXPAND_FILL);
  5787. node_filter->set_placeholder(TTR("Search"));
  5788. tools = memnew(MenuButton);
  5789. filter_hb->add_child(tools);
  5790. tools->set_tooltip_text(TTR("Options"));
  5791. tools->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_tools_menu_option));
  5792. tools->get_popup()->add_item(TTR("Expand All"), EXPAND_ALL);
  5793. tools->get_popup()->add_item(TTR("Collapse All"), COLLAPSE_ALL);
  5794. members = memnew(Tree);
  5795. members_vb->add_child(members);
  5796. SET_DRAG_FORWARDING_GCD(members, VisualShaderEditor);
  5797. members->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  5798. members->set_h_size_flags(SIZE_EXPAND_FILL);
  5799. members->set_v_size_flags(SIZE_EXPAND_FILL);
  5800. members->set_hide_root(true);
  5801. members->set_allow_reselect(true);
  5802. members->set_hide_folding(false);
  5803. members->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE));
  5804. members->connect("item_activated", callable_mp(this, &VisualShaderEditor::_member_create));
  5805. members->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_member_selected));
  5806. HBoxContainer *desc_hbox = memnew(HBoxContainer);
  5807. members_vb->add_child(desc_hbox);
  5808. Label *desc_label = memnew(Label);
  5809. desc_hbox->add_child(desc_label);
  5810. desc_label->set_text(TTR("Description:"));
  5811. desc_hbox->add_spacer();
  5812. highend_label = memnew(Label);
  5813. highend_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  5814. desc_hbox->add_child(highend_label);
  5815. highend_label->set_visible(false);
  5816. highend_label->set_text("Vulkan");
  5817. highend_label->set_mouse_filter(Control::MOUSE_FILTER_STOP);
  5818. highend_label->set_tooltip_text(TTR("High-end node"));
  5819. node_desc = memnew(RichTextLabel);
  5820. members_vb->add_child(node_desc);
  5821. node_desc->set_h_size_flags(SIZE_EXPAND_FILL);
  5822. node_desc->set_v_size_flags(SIZE_FILL);
  5823. node_desc->set_custom_minimum_size(Size2(0, 70 * EDSCALE));
  5824. members_dialog = memnew(ConfirmationDialog);
  5825. members_dialog->set_title(TTR("Create Shader Node"));
  5826. members_dialog->add_child(members_vb);
  5827. members_dialog->set_ok_button_text(TTR("Create"));
  5828. members_dialog->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_member_create));
  5829. members_dialog->get_ok_button()->set_disabled(true);
  5830. members_dialog->connect("canceled", callable_mp(this, &VisualShaderEditor::_member_cancel));
  5831. members_dialog->register_text_enter(node_filter);
  5832. add_child(members_dialog);
  5833. // add varyings dialog
  5834. {
  5835. add_varying_dialog = memnew(ConfirmationDialog);
  5836. add_varying_dialog->set_title(TTR("Create Shader Varying"));
  5837. add_varying_dialog->set_ok_button_text(TTR("Create"));
  5838. add_varying_dialog->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_varying_create));
  5839. add_varying_dialog->get_ok_button()->set_disabled(true);
  5840. add_child(add_varying_dialog);
  5841. VBoxContainer *vb = memnew(VBoxContainer);
  5842. add_varying_dialog->add_child(vb);
  5843. HBoxContainer *hb = memnew(HBoxContainer);
  5844. vb->add_child(hb);
  5845. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  5846. varying_type = memnew(OptionButton);
  5847. hb->add_child(varying_type);
  5848. varying_type->add_item("Float");
  5849. varying_type->add_item("Int");
  5850. varying_type->add_item("UInt");
  5851. varying_type->add_item("Vector2");
  5852. varying_type->add_item("Vector3");
  5853. varying_type->add_item("Vector4");
  5854. varying_type->add_item("Boolean");
  5855. varying_type->add_item("Transform");
  5856. varying_type->set_accessibility_name(TTRC("Varying Type"));
  5857. varying_type->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_type_changed));
  5858. varying_name = memnew(LineEdit);
  5859. hb->add_child(varying_name);
  5860. varying_name->set_custom_minimum_size(Size2(150 * EDSCALE, 0));
  5861. varying_name->set_h_size_flags(SIZE_EXPAND_FILL);
  5862. varying_name->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_varying_name_changed));
  5863. add_varying_dialog->register_text_enter(varying_name);
  5864. varying_mode = memnew(OptionButton);
  5865. hb->add_child(varying_mode);
  5866. varying_mode->add_item("Vertex -> [Fragment, Light]");
  5867. varying_mode->add_item("Fragment -> Light");
  5868. varying_mode->set_accessibility_name(TTRC("Varying Mode"));
  5869. varying_mode->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_mode_changed));
  5870. varying_error_label = memnew(Label);
  5871. varying_error_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  5872. vb->add_child(varying_error_label);
  5873. varying_error_label->set_h_size_flags(SIZE_EXPAND_FILL);
  5874. varying_error_label->hide();
  5875. }
  5876. // remove varying dialog
  5877. {
  5878. remove_varying_dialog = memnew(ConfirmationDialog);
  5879. remove_varying_dialog->set_title(TTR("Delete Shader Varying"));
  5880. remove_varying_dialog->set_ok_button_text(TTR("Delete"));
  5881. remove_varying_dialog->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_varying_deleted));
  5882. add_child(remove_varying_dialog);
  5883. VBoxContainer *vb = memnew(VBoxContainer);
  5884. remove_varying_dialog->add_child(vb);
  5885. varyings = memnew(Tree);
  5886. vb->add_child(varyings);
  5887. varyings->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  5888. varyings->set_h_size_flags(SIZE_EXPAND_FILL);
  5889. varyings->set_v_size_flags(SIZE_EXPAND_FILL);
  5890. varyings->set_hide_root(true);
  5891. varyings->set_allow_reselect(true);
  5892. varyings->set_hide_folding(false);
  5893. varyings->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE));
  5894. varyings->connect("item_activated", callable_mp(this, &VisualShaderEditor::_varying_deleted));
  5895. varyings->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_selected));
  5896. varyings->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_varying_unselected));
  5897. }
  5898. alert = memnew(AcceptDialog);
  5899. alert->get_label()->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  5900. alert->get_label()->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  5901. alert->get_label()->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  5902. alert->get_label()->set_custom_minimum_size(Size2(400, 60) * EDSCALE);
  5903. add_child(alert);
  5904. frame_title_change_popup = memnew(PopupPanel);
  5905. frame_title_change_edit = memnew(LineEdit);
  5906. frame_title_change_edit->set_expand_to_text_length_enabled(true);
  5907. frame_title_change_edit->set_select_all_on_focus(true);
  5908. frame_title_change_edit->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_frame_title_text_changed));
  5909. frame_title_change_edit->connect(SceneStringName(text_submitted), callable_mp(this, &VisualShaderEditor::_frame_title_text_submitted));
  5910. frame_title_change_popup->add_child(frame_title_change_edit);
  5911. frame_title_change_edit->reset_size();
  5912. frame_title_change_popup->reset_size();
  5913. frame_title_change_popup->connect(SceneStringName(focus_exited), callable_mp(this, &VisualShaderEditor::_frame_title_popup_focus_out));
  5914. frame_title_change_popup->connect("popup_hide", callable_mp(this, &VisualShaderEditor::_frame_title_popup_hide));
  5915. add_child(frame_title_change_popup);
  5916. frame_tint_color_pick_popup = memnew(PopupPanel);
  5917. VBoxContainer *frame_popup_item_tint_color_editor = memnew(VBoxContainer);
  5918. frame_tint_color_pick_popup->add_child(frame_popup_item_tint_color_editor);
  5919. frame_tint_color_picker = memnew(ColorPicker);
  5920. frame_popup_item_tint_color_editor->add_child(frame_tint_color_picker);
  5921. frame_tint_color_picker->reset_size();
  5922. frame_tint_color_picker->connect("color_changed", callable_mp(this, &VisualShaderEditor::_frame_color_changed));
  5923. Button *frame_tint_color_confirm_button = memnew(Button);
  5924. frame_tint_color_confirm_button->set_text(TTR("OK"));
  5925. frame_popup_item_tint_color_editor->add_child(frame_tint_color_confirm_button);
  5926. frame_tint_color_confirm_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_frame_color_confirm));
  5927. frame_tint_color_pick_popup->connect("popup_hide", callable_mp(this, &VisualShaderEditor::_frame_color_popup_hide));
  5928. add_child(frame_tint_color_pick_popup);
  5929. ///////////////////////////////////////
  5930. // SHADER NODES TREE OPTIONS
  5931. ///////////////////////////////////////
  5932. // COLOR
  5933. add_options.push_back(AddOption("ColorFunc", "Color/Common", "VisualShaderNodeColorFunc", TTR("Color function."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5934. add_options.push_back(AddOption("ColorOp", "Color/Common", "VisualShaderNodeColorOp", TTR("Color operator."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5935. add_options.push_back(AddOption("Grayscale", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Grayscale function."), { VisualShaderNodeColorFunc::FUNC_GRAYSCALE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5936. 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));
  5937. 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));
  5938. 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));
  5939. add_options.push_back(AddOption("Sepia", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Sepia function."), { VisualShaderNodeColorFunc::FUNC_SEPIA }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5940. 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));
  5941. add_options.push_back(AddOption("Burn", "Color/Operators", "VisualShaderNodeColorOp", TTR("Burn operator."), { VisualShaderNodeColorOp::OP_BURN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5942. add_options.push_back(AddOption("Darken", "Color/Operators", "VisualShaderNodeColorOp", TTR("Darken operator."), { VisualShaderNodeColorOp::OP_DARKEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5943. add_options.push_back(AddOption("Difference", "Color/Operators", "VisualShaderNodeColorOp", TTR("Difference operator."), { VisualShaderNodeColorOp::OP_DIFFERENCE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5944. add_options.push_back(AddOption("Dodge", "Color/Operators", "VisualShaderNodeColorOp", TTR("Dodge operator."), { VisualShaderNodeColorOp::OP_DODGE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5945. add_options.push_back(AddOption("HardLight", "Color/Operators", "VisualShaderNodeColorOp", TTR("HardLight operator."), { VisualShaderNodeColorOp::OP_HARD_LIGHT }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5946. add_options.push_back(AddOption("Lighten", "Color/Operators", "VisualShaderNodeColorOp", TTR("Lighten operator."), { VisualShaderNodeColorOp::OP_LIGHTEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5947. add_options.push_back(AddOption("Overlay", "Color/Operators", "VisualShaderNodeColorOp", TTR("Overlay operator."), { VisualShaderNodeColorOp::OP_OVERLAY }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5948. add_options.push_back(AddOption("Screen", "Color/Operators", "VisualShaderNodeColorOp", TTR("Screen operator."), { VisualShaderNodeColorOp::OP_SCREEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5949. add_options.push_back(AddOption("SoftLight", "Color/Operators", "VisualShaderNodeColorOp", TTR("SoftLight operator."), { VisualShaderNodeColorOp::OP_SOFT_LIGHT }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5950. add_options.push_back(AddOption("ColorConstant", "Color/Variables", "VisualShaderNodeColorConstant", TTR("Color constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  5951. add_options.push_back(AddOption("ColorParameter", "Color/Variables", "VisualShaderNodeColorParameter", TTR("Color parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  5952. // COMMON
  5953. 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));
  5954. add_options.push_back(AddOption("DerivativeFunc", "Common", "VisualShaderNodeDerivativeFunc", TTR("Derivative function."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY, true));
  5955. // CONDITIONAL
  5956. const String &compare_func_desc = TTR("Returns the boolean result of the %s comparison between two parameters.");
  5957. add_options.push_back(AddOption("Equal (==)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Equal (==)")), { VisualShaderNodeCompare::FUNC_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5958. add_options.push_back(AddOption("GreaterThan (>)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Greater Than (>)")), { VisualShaderNodeCompare::FUNC_GREATER_THAN }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5959. 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));
  5960. 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));
  5961. 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));
  5962. 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));
  5963. add_options.push_back(AddOption("LessThan (<)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than (<)")), { VisualShaderNodeCompare::FUNC_LESS_THAN }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5964. 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));
  5965. add_options.push_back(AddOption("NotEqual (!=)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Not Equal (!=)")), { VisualShaderNodeCompare::FUNC_NOT_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5966. 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));
  5967. 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));
  5968. 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));
  5969. 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));
  5970. 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));
  5971. 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));
  5972. 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));
  5973. 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));
  5974. add_options.push_back(AddOption("Compare (==)", "Conditional/Common", "VisualShaderNodeCompare", TTR("Returns the boolean result of the comparison between two parameters."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5975. 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));
  5976. add_options.push_back(AddOption("BooleanConstant", "Conditional/Variables", "VisualShaderNodeBooleanConstant", TTR("Boolean constant."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5977. add_options.push_back(AddOption("BooleanParameter", "Conditional/Variables", "VisualShaderNodeBooleanParameter", TTR("Boolean parameter."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5978. // INPUT
  5979. const String translation_gdsl = "\n\n" + TTR("Translated to '%s' in Godot Shading Language.");
  5980. const String input_param_shader_modes = TTR("'%s' input parameter for all shader modes.") + translation_gdsl;
  5981. // NODE3D-FOR-ALL
  5982. 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));
  5983. 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));
  5984. 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));
  5985. 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));
  5986. 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));
  5987. 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));
  5988. 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));
  5989. 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));
  5990. 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));
  5991. 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));
  5992. 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));
  5993. 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));
  5994. 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));
  5995. // CANVASITEM-FOR-ALL
  5996. 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));
  5997. 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));
  5998. 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));
  5999. 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));
  6000. // PARTICLES-FOR-ALL
  6001. 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));
  6002. 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));
  6003. 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));
  6004. 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));
  6005. 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));
  6006. 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));
  6007. 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));
  6008. 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));
  6009. 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));
  6010. 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));
  6011. 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));
  6012. 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));
  6013. 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));
  6014. 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));
  6015. /////////////////
  6016. add_options.push_back(AddOption("Input", "Input/Common", "VisualShaderNodeInput", TTR("Input parameter.")));
  6017. const String input_param_for_vertex_and_fragment_shader_modes = TTR("'%s' input parameter for vertex and fragment shader modes.") + translation_gdsl;
  6018. const String input_param_for_fragment_and_light_shader_modes = TTR("'%s' input parameter for fragment and light shader modes.") + translation_gdsl;
  6019. const String input_param_for_fragment_shader_mode = TTR("'%s' input parameter for fragment shader mode.") + translation_gdsl;
  6020. const String input_param_for_sky_shader_mode = TTR("'%s' input parameter for sky shader mode.") + translation_gdsl;
  6021. const String input_param_for_fog_shader_mode = TTR("'%s' input parameter for fog shader mode.") + translation_gdsl;
  6022. const String input_param_for_light_shader_mode = TTR("'%s' input parameter for light shader mode.") + translation_gdsl;
  6023. const String input_param_for_vertex_shader_mode = TTR("'%s' input parameter for vertex shader mode.") + translation_gdsl;
  6024. const String input_param_for_start_shader_mode = TTR("'%s' input parameter for start shader mode.") + translation_gdsl;
  6025. const String input_param_for_process_shader_mode = TTR("'%s' input parameter for process shader mode.") + translation_gdsl;
  6026. const String input_param_for_collide_shader_mode = TTR("'%s' input parameter for collide shader mode." + translation_gdsl);
  6027. const String input_param_for_start_and_process_shader_mode = TTR("'%s' input parameter for start and process shader modes.") + translation_gdsl;
  6028. const String input_param_for_process_and_collide_shader_mode = TTR("'%s' input parameter for process and collide shader modes.") + translation_gdsl;
  6029. const String input_param_for_vertex_and_fragment_shader_mode = TTR("'%s' input parameter for vertex and fragment shader modes.") + translation_gdsl;
  6030. // NODE3D INPUTS
  6031. 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));
  6032. 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));
  6033. 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));
  6034. 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));
  6035. 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));
  6036. 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));
  6037. 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));
  6038. 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));
  6039. 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));
  6040. 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));
  6041. 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));
  6042. 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));
  6043. 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));
  6044. 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));
  6045. 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));
  6046. 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));
  6047. 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));
  6048. 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));
  6049. 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));
  6050. 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));
  6051. 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));
  6052. 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));
  6053. 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));
  6054. 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));
  6055. 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));
  6056. 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));
  6057. 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));
  6058. 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));
  6059. 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));
  6060. 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));
  6061. 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));
  6062. 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));
  6063. 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));
  6064. 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));
  6065. 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));
  6066. 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));
  6067. 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));
  6068. 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));
  6069. 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));
  6070. 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));
  6071. 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));
  6072. 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));
  6073. 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));
  6074. 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));
  6075. 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));
  6076. 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));
  6077. 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));
  6078. 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));
  6079. 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));
  6080. 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));
  6081. 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));
  6082. 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));
  6083. 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));
  6084. // CANVASITEM INPUTS
  6085. 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));
  6086. 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));
  6087. 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));
  6088. 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));
  6089. 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));
  6090. 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));
  6091. 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));
  6092. 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));
  6093. 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));
  6094. 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));
  6095. 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));
  6096. 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));
  6097. 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));
  6098. 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));
  6099. 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));
  6100. 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));
  6101. 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));
  6102. 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));
  6103. 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));
  6104. 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));
  6105. 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));
  6106. 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));
  6107. 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));
  6108. 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));
  6109. 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));
  6110. 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));
  6111. 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));
  6112. 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));
  6113. 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));
  6114. 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));
  6115. 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));
  6116. 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));
  6117. 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));
  6118. 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));
  6119. 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));
  6120. 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));
  6121. // SKY INPUTS
  6122. 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));
  6123. 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));
  6124. 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));
  6125. 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));
  6126. 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));
  6127. 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));
  6128. 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));
  6129. 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));
  6130. 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));
  6131. 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));
  6132. 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));
  6133. 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));
  6134. 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));
  6135. 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));
  6136. 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));
  6137. 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));
  6138. 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));
  6139. 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));
  6140. 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));
  6141. 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));
  6142. 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));
  6143. 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));
  6144. 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));
  6145. 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));
  6146. 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));
  6147. 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));
  6148. 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));
  6149. 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));
  6150. // FOG INPUTS
  6151. 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));
  6152. 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));
  6153. 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));
  6154. 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));
  6155. 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));
  6156. 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));
  6157. // PARTICLES INPUTS
  6158. 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));
  6159. 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));
  6160. // PARTICLES
  6161. add_options.push_back(AddOption("EmitParticle", "Particles", "VisualShaderNodeParticleEmit", "", {}, -1, TYPE_FLAGS_PROCESS | TYPE_FLAGS_PROCESS_CUSTOM | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  6162. add_options.push_back(AddOption("ParticleAccelerator", "Particles", "VisualShaderNodeParticleAccelerator", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  6163. add_options.push_back(AddOption("ParticleRandomness", "Particles", "VisualShaderNodeParticleRandomness", "", {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT | TYPE_FLAGS_PROCESS | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  6164. 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));
  6165. add_options.push_back(AddOption("BoxEmitter", "Particles/Emitters", "VisualShaderNodeParticleBoxEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  6166. mesh_emitter_option_idx = add_options.size();
  6167. add_options.push_back(AddOption("MeshEmitter", "Particles/Emitters", "VisualShaderNodeParticleMeshEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  6168. add_options.push_back(AddOption("RingEmitter", "Particles/Emitters", "VisualShaderNodeParticleRingEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  6169. add_options.push_back(AddOption("SphereEmitter", "Particles/Emitters", "VisualShaderNodeParticleSphereEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  6170. add_options.push_back(AddOption("ConeVelocity", "Particles/Velocity", "VisualShaderNodeParticleConeVelocity", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  6171. // SCALAR
  6172. add_options.push_back(AddOption("FloatFunc", "Scalar/Common", "VisualShaderNodeFloatFunc", TTR("Float function."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6173. add_options.push_back(AddOption("FloatOp", "Scalar/Common", "VisualShaderNodeFloatOp", TTR("Float operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6174. add_options.push_back(AddOption("IntFunc", "Scalar/Common", "VisualShaderNodeIntFunc", TTR("Integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6175. add_options.push_back(AddOption("IntOp", "Scalar/Common", "VisualShaderNodeIntOp", TTR("Integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6176. add_options.push_back(AddOption("UIntFunc", "Scalar/Common", "VisualShaderNodeUIntFunc", TTR("Unsigned integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6177. add_options.push_back(AddOption("UIntOp", "Scalar/Common", "VisualShaderNodeUIntOp", TTR("Unsigned integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6178. // CONSTANTS
  6179. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  6180. 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));
  6181. }
  6182. // FUNCTIONS
  6183. add_options.push_back(AddOption("Abs", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ABS }, VisualShaderNode::PORT_TYPE_SCALAR));
  6184. 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));
  6185. add_options.push_back(AddOption("ACos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ACOS }, VisualShaderNode::PORT_TYPE_SCALAR));
  6186. 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));
  6187. add_options.push_back(AddOption("ASin", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ASIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6188. 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));
  6189. add_options.push_back(AddOption("ATan", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ATAN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6190. add_options.push_back(AddOption("ATan2", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeFloatOp::OP_ATAN2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  6191. 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));
  6192. 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));
  6193. 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));
  6194. 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));
  6195. 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));
  6196. 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));
  6197. 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));
  6198. add_options.push_back(AddOption("Cos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COS }, VisualShaderNode::PORT_TYPE_SCALAR));
  6199. add_options.push_back(AddOption("CosH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COSH }, VisualShaderNode::PORT_TYPE_SCALAR));
  6200. add_options.push_back(AddOption("Degrees", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeFloatFunc::FUNC_DEGREES }, VisualShaderNode::PORT_TYPE_SCALAR));
  6201. 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));
  6202. 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));
  6203. 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));
  6204. 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));
  6205. add_options.push_back(AddOption("Exp", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-e Exponential."), { VisualShaderNodeFloatFunc::FUNC_EXP }, VisualShaderNode::PORT_TYPE_SCALAR));
  6206. add_options.push_back(AddOption("Exp2", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 Exponential."), { VisualShaderNodeFloatFunc::FUNC_EXP2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  6207. 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));
  6208. add_options.push_back(AddOption("Fract", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeFloatFunc::FUNC_FRACT }, VisualShaderNode::PORT_TYPE_SCALAR));
  6209. 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));
  6210. add_options.push_back(AddOption("Log", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Natural logarithm."), { VisualShaderNodeFloatFunc::FUNC_LOG }, VisualShaderNode::PORT_TYPE_SCALAR));
  6211. add_options.push_back(AddOption("Log2", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 logarithm."), { VisualShaderNodeFloatFunc::FUNC_LOG2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  6212. add_options.push_back(AddOption("Max", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the greater of two values."), { VisualShaderNodeFloatOp::OP_MAX }, VisualShaderNode::PORT_TYPE_SCALAR));
  6213. add_options.push_back(AddOption("Min", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the lesser of two values."), { VisualShaderNodeFloatOp::OP_MIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6214. add_options.push_back(AddOption("Mix", "Scalar/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two scalars."), { VisualShaderNodeMix::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR));
  6215. 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));
  6216. 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));
  6217. 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));
  6218. 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));
  6219. add_options.push_back(AddOption("OneMinus (1-)", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 - scalar"), { VisualShaderNodeFloatFunc::FUNC_ONEMINUS }, VisualShaderNode::PORT_TYPE_SCALAR));
  6220. 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));
  6221. add_options.push_back(AddOption("Radians", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeFloatFunc::FUNC_RADIANS }, VisualShaderNode::PORT_TYPE_SCALAR));
  6222. add_options.push_back(AddOption("Reciprocal", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 / scalar"), { VisualShaderNodeFloatFunc::FUNC_RECIPROCAL }, VisualShaderNode::PORT_TYPE_SCALAR));
  6223. 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));
  6224. add_options.push_back(AddOption("Round", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeFloatFunc::FUNC_ROUND }, VisualShaderNode::PORT_TYPE_SCALAR));
  6225. 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));
  6226. 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));
  6227. add_options.push_back(AddOption("Sign", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SIGN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6228. add_options.push_back(AddOption("Sign", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeIntFunc::FUNC_SIGN }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6229. add_options.push_back(AddOption("Sin", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6230. add_options.push_back(AddOption("SinH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SINH }, VisualShaderNode::PORT_TYPE_SCALAR));
  6231. add_options.push_back(AddOption("Sqrt", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SQRT }, VisualShaderNode::PORT_TYPE_SCALAR));
  6232. 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));
  6233. 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));
  6234. 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));
  6235. 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));
  6236. add_options.push_back(AddOption("Tan", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TAN }, VisualShaderNode::PORT_TYPE_SCALAR));
  6237. add_options.push_back(AddOption("TanH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TANH }, VisualShaderNode::PORT_TYPE_SCALAR));
  6238. add_options.push_back(AddOption("Trunc", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TRUNC }, VisualShaderNode::PORT_TYPE_SCALAR));
  6239. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Sums two floating-point scalars."), { VisualShaderNodeFloatOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR));
  6240. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Sums two integer scalars."), { VisualShaderNodeIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6241. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Sums two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6242. 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));
  6243. 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));
  6244. 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));
  6245. 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));
  6246. 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));
  6247. 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));
  6248. 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));
  6249. 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));
  6250. 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));
  6251. 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));
  6252. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Divides two floating-point scalars."), { VisualShaderNodeFloatOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR));
  6253. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Divides two integer scalars."), { VisualShaderNodeIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6254. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Divides two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6255. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Multiplies two floating-point scalars."), { VisualShaderNodeFloatOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR));
  6256. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Multiplies two integer scalars."), { VisualShaderNodeIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6257. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Multiplies two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6258. 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));
  6259. 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));
  6260. 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));
  6261. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Subtracts two floating-point scalars."), { VisualShaderNodeFloatOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR));
  6262. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Subtracts two integer scalars."), { VisualShaderNodeIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6263. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Subtracts two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6264. add_options.push_back(AddOption("FloatConstant", "Scalar/Variables", "VisualShaderNodeFloatConstant", TTR("Scalar floating-point constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6265. add_options.push_back(AddOption("IntConstant", "Scalar/Variables", "VisualShaderNodeIntConstant", TTR("Scalar integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6266. add_options.push_back(AddOption("UIntConstant", "Scalar/Variables", "VisualShaderNodeUIntConstant", TTR("Scalar unsigned integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6267. add_options.push_back(AddOption("FloatParameter", "Scalar/Variables", "VisualShaderNodeFloatParameter", TTR("Scalar floating-point parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6268. add_options.push_back(AddOption("IntParameter", "Scalar/Variables", "VisualShaderNodeIntParameter", TTR("Scalar integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6269. add_options.push_back(AddOption("UIntParameter", "Scalar/Variables", "VisualShaderNodeUIntParameter", TTR("Scalar unsigned integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6270. // SDF
  6271. {
  6272. 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));
  6273. 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));
  6274. 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));
  6275. 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));
  6276. 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));
  6277. }
  6278. // TEXTURES
  6279. add_options.push_back(AddOption("UVFunc", "Textures/Common", "VisualShaderNodeUVFunc", TTR("Function to be applied on texture coordinates."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6280. add_options.push_back(AddOption("UVPolarCoord", "Textures/Common", "VisualShaderNodeUVPolarCoord", TTR("Polar coordinates conversion applied on texture coordinates."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6281. cubemap_node_option_idx = add_options.size();
  6282. add_options.push_back(AddOption("CubeMap", "Textures/Functions", "VisualShaderNodeCubemap", TTR("Perform the cubic texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6283. curve_node_option_idx = add_options.size();
  6284. add_options.push_back(AddOption("CurveTexture", "Textures/Functions", "VisualShaderNodeCurveTexture", TTR("Perform the curve texture lookup."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6285. curve_xyz_node_option_idx = add_options.size();
  6286. add_options.push_back(AddOption("CurveXYZTexture", "Textures/Functions", "VisualShaderNodeCurveXYZTexture", TTR("Perform the three components curve texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6287. 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));
  6288. texture2d_node_option_idx = add_options.size();
  6289. 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));
  6290. texture2d_node_option_idx = add_options.size();
  6291. 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));
  6292. texture2d_node_option_idx = add_options.size();
  6293. add_options.push_back(AddOption("Texture2D", "Textures/Functions", "VisualShaderNodeTexture", TTR("Perform the 2D texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6294. texture2d_array_node_option_idx = add_options.size();
  6295. add_options.push_back(AddOption("Texture2DArray", "Textures/Functions", "VisualShaderNodeTexture2DArray", TTR("Perform the 2D-array texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6296. texture3d_node_option_idx = add_options.size();
  6297. add_options.push_back(AddOption("Texture3D", "Textures/Functions", "VisualShaderNodeTexture3D", TTR("Perform the 3D texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6298. add_options.push_back(AddOption("UVPanning", "Textures/Functions", "VisualShaderNodeUVFunc", TTR("Apply panning function on texture coordinates."), { VisualShaderNodeUVFunc::FUNC_PANNING }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6299. add_options.push_back(AddOption("UVScaling", "Textures/Functions", "VisualShaderNodeUVFunc", TTR("Apply scaling function on texture coordinates."), { VisualShaderNodeUVFunc::FUNC_SCALING }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6300. add_options.push_back(AddOption("CubeMapParameter", "Textures/Variables", "VisualShaderNodeCubemapParameter", TTR("Cubic texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6301. add_options.push_back(AddOption("Texture2DParameter", "Textures/Variables", "VisualShaderNodeTexture2DParameter", TTR("2D texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6302. 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));
  6303. add_options.push_back(AddOption("Texture2DArrayParameter", "Textures/Variables", "VisualShaderNodeTexture2DArrayParameter", TTR("2D array of textures parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6304. add_options.push_back(AddOption("Texture3DParameter", "Textures/Variables", "VisualShaderNodeTexture3DParameter", TTR("3D texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6305. // TRANSFORM
  6306. add_options.push_back(AddOption("TransformFunc", "Transform/Common", "VisualShaderNodeTransformFunc", TTR("Transform function."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6307. add_options.push_back(AddOption("TransformOp", "Transform/Common", "VisualShaderNodeTransformOp", TTR("Transform operator."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6308. 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));
  6309. add_options.push_back(AddOption("TransformCompose", "Transform/Composition", "VisualShaderNodeTransformCompose", TTR("Composes transform from four vectors."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6310. add_options.push_back(AddOption("TransformDecompose", "Transform/Composition", "VisualShaderNodeTransformDecompose", TTR("Decomposes transform to four vectors.")));
  6311. add_options.push_back(AddOption("Determinant", "Transform/Functions", "VisualShaderNodeDeterminant", TTR("Calculates the determinant of a transform."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6312. 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));
  6313. add_options.push_back(AddOption("Inverse", "Transform/Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the inverse of a transform."), { VisualShaderNodeTransformFunc::FUNC_INVERSE }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6314. add_options.push_back(AddOption("Transpose", "Transform/Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the transpose of a transform."), { VisualShaderNodeTransformFunc::FUNC_TRANSPOSE }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6315. add_options.push_back(AddOption("Add (+)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Sums two transforms."), { VisualShaderNodeTransformOp::OP_ADD }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6316. add_options.push_back(AddOption("Divide (/)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Divides two transforms."), { VisualShaderNodeTransformOp::OP_A_DIV_B }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6317. add_options.push_back(AddOption("Multiply (*)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Multiplies two transforms."), { VisualShaderNodeTransformOp::OP_AxB }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6318. 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));
  6319. add_options.push_back(AddOption("Subtract (-)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Subtracts two transforms."), { VisualShaderNodeTransformOp::OP_A_MINUS_B }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6320. add_options.push_back(AddOption("TransformVectorMult (*)", "Transform/Operators", "VisualShaderNodeTransformVecMult", TTR("Multiplies vector by transform."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6321. add_options.push_back(AddOption("TransformConstant", "Transform/Variables", "VisualShaderNodeTransformConstant", TTR("Transform constant."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6322. add_options.push_back(AddOption("TransformParameter", "Transform/Variables", "VisualShaderNodeTransformParameter", TTR("Transform parameter."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6323. // UTILITY
  6324. 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));
  6325. 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));
  6326. add_options.push_back(AddOption("RandomRange", "Utility", "VisualShaderNodeRandomRange", TTR("Returns a random value between the minimum and maximum input values."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6327. 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));
  6328. // VECTOR
  6329. add_options.push_back(AddOption("VectorFunc", "Vector/Common", "VisualShaderNodeVectorFunc", TTR("Vector function."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6330. add_options.push_back(AddOption("VectorOp", "Vector/Common", "VisualShaderNodeVectorOp", TTR("Vector operator."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6331. add_options.push_back(AddOption("VectorCompose", "Vector/Common", "VisualShaderNodeVectorCompose", TTR("Composes vector from scalars.")));
  6332. add_options.push_back(AddOption("VectorDecompose", "Vector/Common", "VisualShaderNodeVectorDecompose", TTR("Decomposes vector to scalars.")));
  6333. 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));
  6334. add_options.push_back(AddOption("Vector2Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 2D vector to two scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_2D }));
  6335. 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));
  6336. add_options.push_back(AddOption("Vector3Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 3D vector to three scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_3D }));
  6337. 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));
  6338. add_options.push_back(AddOption("Vector4Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 4D vector to four scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_4D }));
  6339. 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));
  6340. 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));
  6341. 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));
  6342. 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));
  6343. 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));
  6344. 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));
  6345. 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));
  6346. 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));
  6347. 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));
  6348. 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));
  6349. 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));
  6350. 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));
  6351. 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));
  6352. 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));
  6353. 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));
  6354. 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));
  6355. 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));
  6356. 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));
  6357. 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));
  6358. 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));
  6359. 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));
  6360. 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));
  6361. 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));
  6362. 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));
  6363. 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));
  6364. 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));
  6365. 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));
  6366. 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));
  6367. 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));
  6368. 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));
  6369. 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));
  6370. 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));
  6371. 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));
  6372. 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));
  6373. 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));
  6374. 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));
  6375. 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));
  6376. 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));
  6377. 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));
  6378. 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));
  6379. 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));
  6380. 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));
  6381. 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));
  6382. 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));
  6383. 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));
  6384. 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));
  6385. 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));
  6386. 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));
  6387. 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));
  6388. 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));
  6389. 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));
  6390. 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));
  6391. 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));
  6392. 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));
  6393. 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));
  6394. add_options.push_back(AddOption("Dot", "Vector/Functions", "VisualShaderNodeDotProduct", TTR("Calculates the dot product of two vectors."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6395. 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));
  6396. 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));
  6397. 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));
  6398. 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));
  6399. 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));
  6400. 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));
  6401. 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));
  6402. 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));
  6403. 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));
  6404. 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));
  6405. 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));
  6406. 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));
  6407. 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));
  6408. 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));
  6409. 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));
  6410. 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));
  6411. 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));
  6412. 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));
  6413. 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));
  6414. 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));
  6415. 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));
  6416. 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));
  6417. 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));
  6418. 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));
  6419. 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));
  6420. 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));
  6421. 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));
  6422. 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));
  6423. 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));
  6424. 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));
  6425. 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));
  6426. 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));
  6427. 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));
  6428. 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));
  6429. 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));
  6430. 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));
  6431. 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));
  6432. 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));
  6433. 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));
  6434. 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));
  6435. 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));
  6436. 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));
  6437. 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));
  6438. 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));
  6439. 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));
  6440. 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));
  6441. 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));
  6442. 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));
  6443. 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));
  6444. 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));
  6445. 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));
  6446. 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));
  6447. 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));
  6448. 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));
  6449. 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));
  6450. 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));
  6451. 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));
  6452. 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));
  6453. 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));
  6454. 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));
  6455. 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));
  6456. 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));
  6457. 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));
  6458. 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));
  6459. 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));
  6460. 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));
  6461. 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));
  6462. 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));
  6463. 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));
  6464. 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));
  6465. 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));
  6466. 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));
  6467. 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));
  6468. 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));
  6469. 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));
  6470. 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));
  6471. 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));
  6472. 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));
  6473. 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));
  6474. 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));
  6475. 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));
  6476. 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));
  6477. 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));
  6478. 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));
  6479. 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));
  6480. 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));
  6481. 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));
  6482. 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));
  6483. 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));
  6484. 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));
  6485. 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));
  6486. 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));
  6487. 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));
  6488. 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));
  6489. 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));
  6490. 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));
  6491. 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));
  6492. 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));
  6493. 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));
  6494. 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));
  6495. 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));
  6496. 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));
  6497. 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));
  6498. 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));
  6499. 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));
  6500. 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));
  6501. 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));
  6502. 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));
  6503. 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));
  6504. 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));
  6505. 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));
  6506. 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));
  6507. 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));
  6508. 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));
  6509. 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));
  6510. 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));
  6511. 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));
  6512. 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));
  6513. 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));
  6514. 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));
  6515. 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));
  6516. 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));
  6517. 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));
  6518. 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));
  6519. 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));
  6520. 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));
  6521. 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));
  6522. 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));
  6523. 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));
  6524. 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));
  6525. 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));
  6526. 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));
  6527. 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));
  6528. 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));
  6529. 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));
  6530. add_options.push_back(AddOption("Vector2Constant", "Vector/Variables", "VisualShaderNodeVec2Constant", TTR("2D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6531. add_options.push_back(AddOption("Vector2Parameter", "Vector/Variables", "VisualShaderNodeVec2Parameter", TTR("2D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6532. add_options.push_back(AddOption("Vector3Constant", "Vector/Variables", "VisualShaderNodeVec3Constant", TTR("3D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6533. add_options.push_back(AddOption("Vector3Parameter", "Vector/Variables", "VisualShaderNodeVec3Parameter", TTR("3D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6534. add_options.push_back(AddOption("Vector4Constant", "Vector/Variables", "VisualShaderNodeVec4Constant", TTR("4D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6535. add_options.push_back(AddOption("Vector4Parameter", "Vector/Variables", "VisualShaderNodeVec4Parameter", TTR("4D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6536. // SPECIAL
  6537. add_options.push_back(AddOption("Frame", "Special", "VisualShaderNodeFrame", TTR("A rectangular area with a description string for better graph organization.")));
  6538. 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.")));
  6539. 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.")));
  6540. add_options.push_back(AddOption("ParameterRef", "Special", "VisualShaderNodeParameterRef", TTR("A reference to an existing parameter.")));
  6541. add_options.push_back(AddOption("VaryingGetter", "Special", "VisualShaderNodeVaryingGetter", TTR("Get varying parameter."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6542. add_options.push_back(AddOption("VaryingSetter", "Special", "VisualShaderNodeVaryingSetter", TTR("Set varying parameter."), {}, -1, TYPE_FLAGS_VERTEX | TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6543. add_options.push_back(AddOption("VaryingGetter", "Special", "VisualShaderNodeVaryingGetter", TTR("Get varying parameter."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6544. add_options.push_back(AddOption("VaryingSetter", "Special", "VisualShaderNodeVaryingSetter", TTR("Set varying parameter."), {}, -1, TYPE_FLAGS_VERTEX | TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6545. add_options.push_back(AddOption("Reroute", "Special", "VisualShaderNodeReroute", TTR("Reroute connections freely, can be used to connect multiple input ports to single output port.")));
  6546. custom_node_option_idx = add_options.size();
  6547. /////////////////////////////////////////////////////////////////////
  6548. Ref<VisualShaderNodePluginDefault> default_plugin;
  6549. default_plugin.instantiate();
  6550. default_plugin->set_editor(this);
  6551. add_plugin(default_plugin);
  6552. graph_plugin.instantiate();
  6553. graph_plugin->set_editor(this);
  6554. property_editor_popup = memnew(PopupPanel);
  6555. property_editor_popup->set_min_size(Size2(360, 0) * EDSCALE);
  6556. add_child(property_editor_popup);
  6557. edited_property_holder.instantiate();
  6558. panning_debounce_timer = memnew(Timer);
  6559. panning_debounce_timer->set_one_shot(true);
  6560. panning_debounce_timer->set_wait_time(1.0);
  6561. panning_debounce_timer->connect("timeout", callable_mp(this, &VisualShaderEditor::save_editor_layout));
  6562. add_child(panning_debounce_timer);
  6563. }
  6564. class VisualShaderNodePluginInputEditor : public OptionButton {
  6565. GDCLASS(VisualShaderNodePluginInputEditor, OptionButton);
  6566. VisualShaderEditor *editor = nullptr;
  6567. Ref<VisualShaderNodeInput> input;
  6568. public:
  6569. void _notification(int p_what) {
  6570. switch (p_what) {
  6571. case NOTIFICATION_READY: {
  6572. connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginInputEditor::_item_selected));
  6573. } break;
  6574. }
  6575. }
  6576. void _item_selected(int p_item) {
  6577. editor->call_deferred(SNAME("_input_select_item"), input, get_item_metadata(p_item));
  6578. }
  6579. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeInput> &p_input) {
  6580. set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  6581. editor = p_editor;
  6582. input = p_input;
  6583. Ref<Texture2D> type_icon[] = {
  6584. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)),
  6585. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)),
  6586. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)),
  6587. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)),
  6588. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)),
  6589. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)),
  6590. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)),
  6591. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)),
  6592. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ImageTexture"), EditorStringName(EditorIcons)),
  6593. };
  6594. add_item(TTR("[None]"));
  6595. set_item_metadata(-1, "[None]");
  6596. int to_select = -1;
  6597. for (int i = 0; i < input->get_input_index_count(); i++) {
  6598. if (input->get_input_name() == input->get_input_index_name(i)) {
  6599. to_select = i + 1;
  6600. }
  6601. add_icon_item(type_icon[input->get_input_index_type(i)], input->get_input_index_name(i));
  6602. set_item_metadata(-1, input->get_input_index_name(i));
  6603. }
  6604. if (to_select >= 0) {
  6605. select(to_select);
  6606. }
  6607. }
  6608. };
  6609. ////////////////
  6610. class VisualShaderNodePluginVaryingEditor : public OptionButton {
  6611. GDCLASS(VisualShaderNodePluginVaryingEditor, OptionButton);
  6612. VisualShaderEditor *editor = nullptr;
  6613. Ref<VisualShaderNodeVarying> varying;
  6614. public:
  6615. void _notification(int p_what) {
  6616. if (p_what == NOTIFICATION_READY) {
  6617. connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginVaryingEditor::_item_selected));
  6618. }
  6619. }
  6620. void _item_selected(int p_item) {
  6621. editor->call_deferred(SNAME("_varying_select_item"), varying, get_item_metadata(p_item));
  6622. }
  6623. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeVarying> &p_varying, VisualShader::Type p_type) {
  6624. set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  6625. editor = p_editor;
  6626. varying = p_varying;
  6627. Ref<Texture2D> type_icon[] = {
  6628. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)),
  6629. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)),
  6630. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)),
  6631. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)),
  6632. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)),
  6633. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)),
  6634. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)),
  6635. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)),
  6636. };
  6637. bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid();
  6638. add_item(TTR("[None]"));
  6639. set_item_metadata(-1, "[None]");
  6640. int to_select = -1;
  6641. for (int i = 0, j = 0; i < varying->get_varyings_count(); i++) {
  6642. VisualShader::VaryingMode mode = varying->get_varying_mode_by_index(i);
  6643. if (is_getter) {
  6644. if (mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT) {
  6645. if (p_type != VisualShader::TYPE_LIGHT) {
  6646. j++;
  6647. continue;
  6648. }
  6649. } else {
  6650. if (p_type != VisualShader::TYPE_FRAGMENT && p_type != VisualShader::TYPE_LIGHT) {
  6651. j++;
  6652. continue;
  6653. }
  6654. }
  6655. } else {
  6656. if (mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT) {
  6657. if (p_type != VisualShader::TYPE_FRAGMENT) {
  6658. j++;
  6659. continue;
  6660. }
  6661. } else {
  6662. if (p_type != VisualShader::TYPE_VERTEX) {
  6663. j++;
  6664. continue;
  6665. }
  6666. }
  6667. }
  6668. if (varying->get_varying_name() == varying->get_varying_name_by_index(i)) {
  6669. to_select = i - j + 1;
  6670. }
  6671. add_icon_item(type_icon[varying->get_varying_type_by_index(i)], varying->get_varying_name_by_index(i));
  6672. set_item_metadata(-1, varying->get_varying_name_by_index(i));
  6673. }
  6674. if (to_select >= 0) {
  6675. select(to_select);
  6676. }
  6677. }
  6678. };
  6679. ////////////////
  6680. class VisualShaderNodePluginParameterRefEditor : public OptionButton {
  6681. GDCLASS(VisualShaderNodePluginParameterRefEditor, OptionButton);
  6682. VisualShaderEditor *editor = nullptr;
  6683. Ref<VisualShaderNodeParameterRef> parameter_ref;
  6684. public:
  6685. void _notification(int p_what) {
  6686. switch (p_what) {
  6687. case NOTIFICATION_READY: {
  6688. connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginParameterRefEditor::_item_selected));
  6689. } break;
  6690. }
  6691. }
  6692. void _item_selected(int p_item) {
  6693. editor->call_deferred(SNAME("_parameter_ref_select_item"), parameter_ref, get_item_metadata(p_item));
  6694. }
  6695. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeParameterRef> &p_parameter_ref) {
  6696. set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  6697. editor = p_editor;
  6698. parameter_ref = p_parameter_ref;
  6699. Ref<Texture2D> type_icon[] = {
  6700. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)),
  6701. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)),
  6702. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)),
  6703. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)),
  6704. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)),
  6705. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)),
  6706. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)),
  6707. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)),
  6708. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Color"), EditorStringName(EditorIcons)),
  6709. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ImageTexture"), EditorStringName(EditorIcons)),
  6710. };
  6711. add_item(TTR("[None]"));
  6712. set_item_metadata(-1, "[None]");
  6713. int to_select = -1;
  6714. for (int i = 0; i < p_parameter_ref->get_parameters_count(); i++) {
  6715. if (p_parameter_ref->get_parameter_name() == p_parameter_ref->get_parameter_name_by_index(i)) {
  6716. to_select = i + 1;
  6717. }
  6718. add_icon_item(type_icon[p_parameter_ref->get_parameter_type_by_index(i)], p_parameter_ref->get_parameter_name_by_index(i));
  6719. set_item_metadata(-1, p_parameter_ref->get_parameter_name_by_index(i));
  6720. }
  6721. if (to_select >= 0) {
  6722. select(to_select);
  6723. }
  6724. }
  6725. };
  6726. ////////////////
  6727. class VisualShaderNodePluginDefaultEditor : public VBoxContainer {
  6728. GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer);
  6729. VisualShaderEditor *editor = nullptr;
  6730. Ref<Resource> parent_resource;
  6731. int node_id = 0;
  6732. VisualShader::Type shader_type;
  6733. public:
  6734. void _property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false) {
  6735. if (p_changing) {
  6736. return;
  6737. }
  6738. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  6739. updating = true;
  6740. undo_redo->create_action(vformat(TTR("Edit Visual Property: %s"), p_property), UndoRedo::MERGE_ENDS);
  6741. undo_redo->add_do_property(node.ptr(), p_property, p_value);
  6742. undo_redo->add_undo_property(node.ptr(), p_property, node->get(p_property));
  6743. Ref<VisualShaderNode> vsnode = editor->get_visual_shader()->get_node(shader_type, node_id);
  6744. ERR_FAIL_COND(vsnode.is_null());
  6745. // Check for invalid connections due to removed ports.
  6746. // We need to know the new state of the node to generate the proper undo/redo instructions.
  6747. // Quite hacky but the best way I could come up with for now.
  6748. Ref<VisualShaderNode> vsnode_new = vsnode->duplicate();
  6749. vsnode_new->set(p_property, p_value);
  6750. const int input_port_count = vsnode_new->get_input_port_count();
  6751. const int output_port_count = vsnode_new->get_expanded_output_port_count();
  6752. List<VisualShader::Connection> conns;
  6753. editor->get_visual_shader()->get_node_connections(shader_type, &conns);
  6754. VisualShaderGraphPlugin *graph_plugin = editor->get_graph_plugin();
  6755. bool undo_node_already_updated = false;
  6756. for (const VisualShader::Connection &c : conns) {
  6757. if ((c.from_node == node_id && c.from_port >= output_port_count) || (c.to_node == node_id && c.to_port >= input_port_count)) {
  6758. 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);
  6759. undo_redo->add_do_method(graph_plugin, "disconnect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port);
  6760. // We need to update the node before reconnecting to avoid accessing a non-existing port.
  6761. undo_redo->add_undo_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  6762. undo_node_already_updated = true;
  6763. 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);
  6764. undo_redo->add_undo_method(graph_plugin, "connect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port);
  6765. }
  6766. }
  6767. if (p_value.get_type() == Variant::OBJECT) {
  6768. Ref<Resource> prev_res = vsnode->get(p_property);
  6769. Ref<Resource> curr_res = p_value;
  6770. if (curr_res.is_null()) {
  6771. undo_redo->add_do_method(this, "_open_inspector", (Ref<Resource>)parent_resource.ptr());
  6772. } else {
  6773. undo_redo->add_do_method(this, "_open_inspector", (Ref<Resource>)curr_res.ptr());
  6774. }
  6775. if (prev_res.is_valid()) {
  6776. undo_redo->add_undo_method(this, "_open_inspector", (Ref<Resource>)prev_res.ptr());
  6777. } else {
  6778. undo_redo->add_undo_method(this, "_open_inspector", (Ref<Resource>)parent_resource.ptr());
  6779. }
  6780. }
  6781. if (p_property != "constant") {
  6782. if (graph_plugin) {
  6783. undo_redo->add_do_method(editor, "_update_next_previews", node_id);
  6784. undo_redo->add_undo_method(editor, "_update_next_previews", node_id);
  6785. undo_redo->add_do_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  6786. if (!undo_node_already_updated) {
  6787. undo_redo->add_undo_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  6788. }
  6789. }
  6790. }
  6791. undo_redo->commit_action();
  6792. updating = false;
  6793. }
  6794. void _node_changed() {
  6795. if (updating) {
  6796. return;
  6797. }
  6798. for (int i = 0; i < properties.size(); i++) {
  6799. properties[i]->update_property();
  6800. }
  6801. }
  6802. void _resource_selected(const String &p_path, Ref<Resource> p_resource) {
  6803. _open_inspector(p_resource);
  6804. }
  6805. void _open_inspector(Ref<Resource> p_resource) {
  6806. InspectorDock::get_inspector_singleton()->edit(p_resource.ptr());
  6807. }
  6808. bool updating = false;
  6809. Ref<VisualShaderNode> node;
  6810. Vector<EditorProperty *> properties;
  6811. Vector<Label *> prop_names;
  6812. void _show_prop_names(bool p_show) {
  6813. for (int i = 0; i < prop_names.size(); i++) {
  6814. prop_names[i]->set_visible(p_show);
  6815. }
  6816. }
  6817. 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) {
  6818. editor = p_editor;
  6819. parent_resource = p_parent_resource;
  6820. updating = false;
  6821. node = p_node;
  6822. properties = p_properties;
  6823. node_id = (int)p_node->get_meta("id");
  6824. shader_type = VisualShader::Type((int)p_node->get_meta("shader_type"));
  6825. for (int i = 0; i < p_properties.size(); i++) {
  6826. HBoxContainer *hbox = memnew(HBoxContainer);
  6827. hbox->set_h_size_flags(SIZE_EXPAND_FILL);
  6828. add_child(hbox);
  6829. Label *prop_name = memnew(Label);
  6830. prop_name->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  6831. String prop_name_str = p_names[i];
  6832. if (p_overrided_names.has(p_names[i])) {
  6833. prop_name_str = p_overrided_names[p_names[i]] + ":";
  6834. } else {
  6835. prop_name_str = prop_name_str.capitalize() + ":";
  6836. }
  6837. prop_name->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  6838. prop_name->set_text(prop_name_str);
  6839. prop_name->set_visible(false);
  6840. hbox->add_child(prop_name);
  6841. prop_names.push_back(prop_name);
  6842. p_properties[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  6843. hbox->add_child(p_properties[i]);
  6844. bool res_prop = Object::cast_to<EditorPropertyResource>(p_properties[i]);
  6845. if (res_prop) {
  6846. p_properties[i]->connect("resource_selected", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_resource_selected));
  6847. }
  6848. properties[i]->connect("property_changed", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_property_changed));
  6849. properties[i]->set_object_and_property(node.ptr(), p_names[i]);
  6850. properties[i]->update_property();
  6851. properties[i]->set_name_split_ratio(0);
  6852. }
  6853. node->connect_changed(callable_mp(this, &VisualShaderNodePluginDefaultEditor::_node_changed));
  6854. }
  6855. static void _bind_methods() {
  6856. ClassDB::bind_method("_open_inspector", &VisualShaderNodePluginDefaultEditor::_open_inspector); // Used by UndoRedo.
  6857. ClassDB::bind_method("_show_prop_names", &VisualShaderNodePluginDefaultEditor::_show_prop_names); // Used with call_deferred.
  6858. }
  6859. };
  6860. Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) {
  6861. Ref<VisualShader> p_shader = Ref<VisualShader>(p_parent_resource.ptr());
  6862. if (p_shader.is_valid() && (p_node->is_class("VisualShaderNodeVaryingGetter") || p_node->is_class("VisualShaderNodeVaryingSetter"))) {
  6863. VisualShaderNodePluginVaryingEditor *editor = memnew(VisualShaderNodePluginVaryingEditor);
  6864. editor->setup(vseditor, p_node, vseditor->get_current_shader_type());
  6865. return editor;
  6866. }
  6867. if (p_node->is_class("VisualShaderNodeParameterRef")) {
  6868. VisualShaderNodePluginParameterRefEditor *editor = memnew(VisualShaderNodePluginParameterRefEditor);
  6869. editor->setup(vseditor, p_node);
  6870. return editor;
  6871. }
  6872. if (p_node->is_class("VisualShaderNodeInput")) {
  6873. VisualShaderNodePluginInputEditor *editor = memnew(VisualShaderNodePluginInputEditor);
  6874. editor->setup(vseditor, p_node);
  6875. return editor;
  6876. }
  6877. Vector<StringName> properties = p_node->get_editable_properties();
  6878. if (properties.is_empty()) {
  6879. return nullptr;
  6880. }
  6881. List<PropertyInfo> props;
  6882. p_node->get_property_list(&props);
  6883. Vector<PropertyInfo> pinfo;
  6884. for (const PropertyInfo &E : props) {
  6885. for (int i = 0; i < properties.size(); i++) {
  6886. if (E.name == String(properties[i])) {
  6887. pinfo.push_back(E);
  6888. }
  6889. }
  6890. }
  6891. if (pinfo.is_empty()) {
  6892. return nullptr;
  6893. }
  6894. properties.clear();
  6895. Ref<VisualShaderNode> node = p_node;
  6896. Vector<EditorProperty *> editors;
  6897. for (int i = 0; i < pinfo.size(); i++) {
  6898. EditorProperty *prop = EditorInspector::instantiate_property_editor(node.ptr(), pinfo[i].type, pinfo[i].name, pinfo[i].hint, pinfo[i].hint_string, pinfo[i].usage);
  6899. if (!prop) {
  6900. return nullptr;
  6901. }
  6902. if (Object::cast_to<EditorPropertyResource>(prop)) {
  6903. Object::cast_to<EditorPropertyResource>(prop)->set_use_sub_inspector(false);
  6904. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  6905. } else if (Object::cast_to<EditorPropertyTransform3D>(prop) || Object::cast_to<EditorPropertyVector3>(prop)) {
  6906. prop->set_custom_minimum_size(Size2(250 * EDSCALE, 0));
  6907. } else if (Object::cast_to<EditorPropertyVector4>(prop)) {
  6908. prop->set_custom_minimum_size(Size2(320 * EDSCALE, 0));
  6909. } else if (Object::cast_to<EditorPropertyFloat>(prop)) {
  6910. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  6911. } else if (Object::cast_to<EditorPropertyEnum>(prop)) {
  6912. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  6913. Object::cast_to<EditorPropertyEnum>(prop)->set_option_button_clip(false);
  6914. } else if (Object::cast_to<EditorPropertyColor>(prop)) {
  6915. Object::cast_to<EditorPropertyColor>(prop)->set_live_changes_enabled(false);
  6916. }
  6917. editors.push_back(prop);
  6918. properties.push_back(pinfo[i].name);
  6919. }
  6920. VisualShaderNodePluginDefaultEditor *editor = memnew(VisualShaderNodePluginDefaultEditor);
  6921. editor->setup(vseditor, p_parent_resource, editors, properties, p_node->get_editable_properties_names(), p_node);
  6922. return editor;
  6923. }
  6924. void EditorPropertyVisualShaderMode::_option_selected(int p_which) {
  6925. Ref<VisualShader> visual_shader(Object::cast_to<VisualShader>(get_edited_object()));
  6926. if (visual_shader->get_mode() == p_which) {
  6927. return;
  6928. }
  6929. ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_editor_data().get_editor_by_name("Shader"));
  6930. if (!shader_editor) {
  6931. return;
  6932. }
  6933. VisualShaderEditor *editor = Object::cast_to<VisualShaderEditor>(shader_editor->get_shader_editor(visual_shader));
  6934. if (!editor) {
  6935. return;
  6936. }
  6937. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  6938. undo_redo->create_action(TTR("Visual Shader Mode Changed"));
  6939. //do is easy
  6940. undo_redo->add_do_method(visual_shader.ptr(), "set_mode", p_which);
  6941. undo_redo->add_undo_method(visual_shader.ptr(), "set_mode", visual_shader->get_mode());
  6942. undo_redo->add_do_method(editor, "_set_mode", p_which);
  6943. undo_redo->add_undo_method(editor, "_set_mode", visual_shader->get_mode());
  6944. //now undo is hell
  6945. //1. restore connections to output
  6946. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  6947. VisualShader::Type type = VisualShader::Type(i);
  6948. List<VisualShader::Connection> conns;
  6949. visual_shader->get_node_connections(type, &conns);
  6950. for (const VisualShader::Connection &E : conns) {
  6951. if (E.to_node == VisualShader::NODE_ID_OUTPUT) {
  6952. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  6953. }
  6954. }
  6955. }
  6956. //2. restore input indices
  6957. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  6958. VisualShader::Type type = VisualShader::Type(i);
  6959. Vector<int> nodes = visual_shader->get_node_list(type);
  6960. for (int j = 0; j < nodes.size(); j++) {
  6961. Ref<VisualShaderNodeInput> input = visual_shader->get_node(type, nodes[j]);
  6962. if (input.is_null()) {
  6963. continue;
  6964. }
  6965. undo_redo->add_undo_method(input.ptr(), "set_input_name", input->get_input_name());
  6966. }
  6967. }
  6968. //3. restore enums and flags
  6969. List<PropertyInfo> props;
  6970. visual_shader->get_property_list(&props);
  6971. for (const PropertyInfo &E : props) {
  6972. if (E.name.begins_with("flags/") || E.name.begins_with("modes/")) {
  6973. undo_redo->add_undo_property(visual_shader.ptr(), E.name, visual_shader->get(E.name));
  6974. }
  6975. }
  6976. //4. delete varyings (if needed)
  6977. if (p_which == VisualShader::MODE_PARTICLES || p_which == VisualShader::MODE_SKY || p_which == VisualShader::MODE_FOG) {
  6978. int var_count = visual_shader->get_varyings_count();
  6979. if (var_count > 0) {
  6980. for (int i = 0; i < var_count; i++) {
  6981. const VisualShader::Varying *var = visual_shader->get_varying_by_index(i);
  6982. undo_redo->add_do_method(visual_shader.ptr(), "remove_varying", var->name);
  6983. undo_redo->add_undo_method(visual_shader.ptr(), "add_varying", var->name, var->mode, var->type);
  6984. }
  6985. undo_redo->add_do_method(editor, "_update_varyings");
  6986. undo_redo->add_undo_method(editor, "_update_varyings");
  6987. }
  6988. }
  6989. undo_redo->add_do_method(editor, "_update_nodes");
  6990. undo_redo->add_undo_method(editor, "_update_nodes");
  6991. undo_redo->add_do_method(editor, "_update_graph");
  6992. undo_redo->add_undo_method(editor, "_update_graph");
  6993. undo_redo->commit_action();
  6994. }
  6995. void EditorPropertyVisualShaderMode::update_property() {
  6996. int which = get_edited_property_value();
  6997. options->select(which);
  6998. }
  6999. void EditorPropertyVisualShaderMode::setup(const Vector<String> &p_options) {
  7000. for (int i = 0; i < p_options.size(); i++) {
  7001. options->add_item(p_options[i], i);
  7002. }
  7003. }
  7004. void EditorPropertyVisualShaderMode::set_option_button_clip(bool p_enable) {
  7005. options->set_clip_text(p_enable);
  7006. }
  7007. EditorPropertyVisualShaderMode::EditorPropertyVisualShaderMode() {
  7008. options = memnew(OptionButton);
  7009. options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  7010. options->set_clip_text(true);
  7011. add_child(options);
  7012. add_focusable(options);
  7013. options->connect(SceneStringName(item_selected), callable_mp(this, &EditorPropertyVisualShaderMode::_option_selected));
  7014. }
  7015. bool EditorInspectorVisualShaderModePlugin::can_handle(Object *p_object) {
  7016. return true; // Can handle everything.
  7017. }
  7018. 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) {
  7019. if (p_path == "mode" && p_object->is_class("VisualShader") && p_type == Variant::INT) {
  7020. EditorPropertyVisualShaderMode *mode_editor = memnew(EditorPropertyVisualShaderMode);
  7021. Vector<String> options = p_hint_text.split(",");
  7022. mode_editor->setup(options);
  7023. add_property_editor(p_path, mode_editor);
  7024. return true;
  7025. }
  7026. return false;
  7027. }
  7028. //////////////////////////////////
  7029. void VisualShaderNodePortPreview::_shader_changed() {
  7030. if (!is_valid || shader.is_null()) {
  7031. return;
  7032. }
  7033. Vector<VisualShader::DefaultTextureParam> default_textures;
  7034. String shader_code = shader->generate_preview_shader(type, node, port, default_textures);
  7035. Ref<Shader> preview_shader;
  7036. preview_shader.instantiate();
  7037. preview_shader->set_code(shader_code);
  7038. for (int i = 0; i < default_textures.size(); i++) {
  7039. int j = 0;
  7040. for (List<Ref<Texture>>::ConstIterator itr = default_textures[i].params.begin(); itr != default_textures[i].params.end(); ++itr, ++j) {
  7041. preview_shader->set_default_texture_parameter(default_textures[i].name, *itr, j);
  7042. }
  7043. }
  7044. Ref<ShaderMaterial> mat;
  7045. mat.instantiate();
  7046. mat->set_shader(preview_shader);
  7047. if (preview_mat.is_valid() && preview_mat->get_shader().is_valid()) {
  7048. List<PropertyInfo> params;
  7049. preview_mat->get_shader()->get_shader_uniform_list(&params);
  7050. for (const PropertyInfo &E : params) {
  7051. mat->set_shader_parameter(E.name, preview_mat->get_shader_parameter(E.name));
  7052. }
  7053. }
  7054. set_material(mat);
  7055. }
  7056. 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) {
  7057. if (p_has_transparency) {
  7058. checkerboard = memnew(TextureRect);
  7059. checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE);
  7060. checkerboard->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  7061. checkerboard->set_draw_behind_parent(true);
  7062. add_child(checkerboard);
  7063. }
  7064. set_mouse_filter(MOUSE_FILTER_PASS);
  7065. shader = p_shader;
  7066. shader->connect_changed(callable_mp(this, &VisualShaderNodePortPreview::_shader_changed), CONNECT_DEFERRED);
  7067. preview_mat = p_preview_material;
  7068. type = p_type;
  7069. port = p_port;
  7070. node = p_node;
  7071. is_valid = p_is_valid;
  7072. queue_redraw();
  7073. _shader_changed();
  7074. }
  7075. Size2 VisualShaderNodePortPreview::get_minimum_size() const {
  7076. int port_preview_size = EDITOR_GET("editors/visual_editors/visual_shader/port_preview_size");
  7077. return Size2(port_preview_size, port_preview_size) * EDSCALE;
  7078. }
  7079. void VisualShaderNodePortPreview::_notification(int p_what) {
  7080. switch (p_what) {
  7081. case NOTIFICATION_THEME_CHANGED: {
  7082. if (checkerboard != nullptr) {
  7083. checkerboard->set_texture(get_theme_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons)));
  7084. }
  7085. } break;
  7086. case NOTIFICATION_DRAW: {
  7087. Vector<Vector2> points = {
  7088. Vector2(),
  7089. Vector2(get_size().width, 0),
  7090. get_size(),
  7091. Vector2(0, get_size().height)
  7092. };
  7093. Vector<Vector2> uvs = {
  7094. Vector2(0, 0),
  7095. Vector2(1, 0),
  7096. Vector2(1, 1),
  7097. Vector2(0, 1)
  7098. };
  7099. if (is_valid) {
  7100. Vector<Color> colors = {
  7101. Color(1, 1, 1, 1),
  7102. Color(1, 1, 1, 1),
  7103. Color(1, 1, 1, 1),
  7104. Color(1, 1, 1, 1)
  7105. };
  7106. draw_primitive(points, colors, uvs);
  7107. } else {
  7108. Vector<Color> colors = {
  7109. Color(0, 0, 0, 1),
  7110. Color(0, 0, 0, 1),
  7111. Color(0, 0, 0, 1),
  7112. Color(0, 0, 0, 1)
  7113. };
  7114. draw_primitive(points, colors, uvs);
  7115. }
  7116. } break;
  7117. }
  7118. }
  7119. //////////////////////////////////
  7120. String VisualShaderConversionPlugin::converts_to() const {
  7121. return "Shader";
  7122. }
  7123. bool VisualShaderConversionPlugin::handles(const Ref<Resource> &p_resource) const {
  7124. Ref<VisualShader> vshader = p_resource;
  7125. return vshader.is_valid();
  7126. }
  7127. Ref<Resource> VisualShaderConversionPlugin::convert(const Ref<Resource> &p_resource) const {
  7128. Ref<VisualShader> vshader = p_resource;
  7129. ERR_FAIL_COND_V(vshader.is_null(), Ref<Resource>());
  7130. Ref<Shader> shader;
  7131. shader.instantiate();
  7132. String code = vshader->get_code();
  7133. shader->set_code(code);
  7134. return shader;
  7135. }