visual_shader_editor_plugin.cpp 362 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705
  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/core_string_names.h"
  33. #include "core/io/resource_loader.h"
  34. #include "core/math/math_defs.h"
  35. #include "core/os/keyboard.h"
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_properties.h"
  38. #include "editor/editor_scale.h"
  39. #include "editor/editor_settings.h"
  40. #include "editor/editor_undo_redo_manager.h"
  41. #include "editor/filesystem_dock.h"
  42. #include "editor/inspector_dock.h"
  43. #include "editor/plugins/curve_editor_plugin.h"
  44. #include "editor/plugins/shader_editor_plugin.h"
  45. #include "scene/gui/button.h"
  46. #include "scene/gui/check_box.h"
  47. #include "scene/gui/code_edit.h"
  48. #include "scene/gui/graph_edit.h"
  49. #include "scene/gui/menu_button.h"
  50. #include "scene/gui/option_button.h"
  51. #include "scene/gui/popup.h"
  52. #include "scene/gui/rich_text_label.h"
  53. #include "scene/gui/separator.h"
  54. #include "scene/gui/tree.h"
  55. #include "scene/gui/view_panner.h"
  56. #include "scene/main/window.h"
  57. #include "scene/resources/visual_shader_nodes.h"
  58. #include "scene/resources/visual_shader_particle_nodes.h"
  59. #include "servers/display_server.h"
  60. #include "servers/rendering/shader_types.h"
  61. struct FloatConstantDef {
  62. String name;
  63. float value = 0;
  64. String desc;
  65. };
  66. static FloatConstantDef float_constant_defs[] = {
  67. { "E", Math_E, TTR("E constant (2.718282). Represents the base of the natural logarithm.") },
  68. { "Epsilon", CMP_EPSILON, TTR("Epsilon constant (0.00001). Smallest possible scalar number.") },
  69. { "Phi", 1.618034f, TTR("Phi constant (1.618034). Golden ratio.") },
  70. { "Pi/4", Math_PI / 4, TTR("Pi/4 constant (0.785398) or 45 degrees.") },
  71. { "Pi/2", Math_PI / 2, TTR("Pi/2 constant (1.570796) or 90 degrees.") },
  72. { "Pi", Math_PI, TTR("Pi constant (3.141593) or 180 degrees.") },
  73. { "Tau", Math_TAU, TTR("Tau constant (6.283185) or 360 degrees.") },
  74. { "Sqrt2", Math_SQRT2, TTR("Sqrt2 constant (1.414214). Square root of 2.") }
  75. };
  76. const int MAX_FLOAT_CONST_DEFS = sizeof(float_constant_defs) / sizeof(FloatConstantDef);
  77. ///////////////////
  78. void VisualShaderNodePlugin::set_editor(VisualShaderEditor *p_editor) {
  79. vseditor = p_editor;
  80. }
  81. Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) {
  82. Object *ret = nullptr;
  83. GDVIRTUAL_CALL(_create_editor, p_parent_resource, p_node, ret);
  84. return Object::cast_to<Control>(ret);
  85. }
  86. void VisualShaderNodePlugin::_bind_methods() {
  87. GDVIRTUAL_BIND(_create_editor, "parent_resource", "visual_shader_node");
  88. }
  89. ///////////////////
  90. VisualShaderGraphPlugin::VisualShaderGraphPlugin() {
  91. }
  92. void VisualShaderGraphPlugin::_bind_methods() {
  93. ClassDB::bind_method("add_node", &VisualShaderGraphPlugin::add_node);
  94. ClassDB::bind_method("remove_node", &VisualShaderGraphPlugin::remove_node);
  95. ClassDB::bind_method("connect_nodes", &VisualShaderGraphPlugin::connect_nodes);
  96. ClassDB::bind_method("disconnect_nodes", &VisualShaderGraphPlugin::disconnect_nodes);
  97. ClassDB::bind_method("set_node_position", &VisualShaderGraphPlugin::set_node_position);
  98. ClassDB::bind_method("update_node", &VisualShaderGraphPlugin::update_node);
  99. ClassDB::bind_method("update_node_deferred", &VisualShaderGraphPlugin::update_node_deferred);
  100. ClassDB::bind_method("set_input_port_default_value", &VisualShaderGraphPlugin::set_input_port_default_value);
  101. ClassDB::bind_method("set_parameter_name", &VisualShaderGraphPlugin::set_parameter_name);
  102. ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression);
  103. ClassDB::bind_method("update_curve", &VisualShaderGraphPlugin::update_curve);
  104. ClassDB::bind_method("update_curve_xyz", &VisualShaderGraphPlugin::update_curve_xyz);
  105. }
  106. void VisualShaderGraphPlugin::set_editor(VisualShaderEditor *p_editor) {
  107. editor = p_editor;
  108. }
  109. void VisualShaderGraphPlugin::register_shader(VisualShader *p_shader) {
  110. visual_shader = Ref<VisualShader>(p_shader);
  111. }
  112. void VisualShaderGraphPlugin::set_connections(const List<VisualShader::Connection> &p_connections) {
  113. connections = p_connections;
  114. }
  115. void VisualShaderGraphPlugin::show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id) {
  116. if (visual_shader->get_shader_type() == p_type && links.has(p_node_id) && links[p_node_id].output_ports.has(p_port_id)) {
  117. Link &link = links[p_node_id];
  118. for (const KeyValue<int, Port> &E : link.output_ports) {
  119. if (E.value.preview_button != nullptr) {
  120. E.value.preview_button->set_pressed(false);
  121. }
  122. }
  123. bool is_dirty = link.preview_pos < 0;
  124. if (!is_dirty && link.preview_visible && link.preview_box != nullptr) {
  125. link.graph_node->remove_child(link.preview_box);
  126. memdelete(link.preview_box);
  127. link.preview_box = nullptr;
  128. link.graph_node->reset_size();
  129. link.preview_visible = false;
  130. }
  131. if (p_port_id != -1 && link.output_ports[p_port_id].preview_button != nullptr) {
  132. if (is_dirty) {
  133. link.preview_pos = link.graph_node->get_child_count();
  134. }
  135. VBoxContainer *vbox = memnew(VBoxContainer);
  136. link.graph_node->add_child(vbox);
  137. link.graph_node->move_child(vbox, link.preview_pos);
  138. link.graph_node->set_slot_draw_stylebox(vbox->get_index(), false);
  139. Control *offset = memnew(Control);
  140. offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  141. vbox->add_child(offset);
  142. VisualShaderNodePortPreview *port_preview = memnew(VisualShaderNodePortPreview);
  143. port_preview->setup(visual_shader, visual_shader->get_shader_type(), p_node_id, p_port_id);
  144. port_preview->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
  145. vbox->add_child(port_preview);
  146. link.preview_visible = true;
  147. link.preview_box = vbox;
  148. link.output_ports[p_port_id].preview_button->set_pressed(true);
  149. }
  150. }
  151. }
  152. void VisualShaderGraphPlugin::update_node_deferred(VisualShader::Type p_type, int p_node_id) {
  153. call_deferred(SNAME("update_node"), p_type, p_node_id);
  154. }
  155. void VisualShaderGraphPlugin::update_node(VisualShader::Type p_type, int p_node_id) {
  156. if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id)) {
  157. return;
  158. }
  159. remove_node(p_type, p_node_id, true);
  160. add_node(p_type, p_node_id, true);
  161. }
  162. void VisualShaderGraphPlugin::set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, Variant p_value) {
  163. if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id)) {
  164. return;
  165. }
  166. Button *button = links[p_node_id].input_ports[p_port_id].default_input_button;
  167. switch (p_value.get_type()) {
  168. case Variant::COLOR: {
  169. button->set_custom_minimum_size(Size2(30, 0) * EDSCALE);
  170. Callable ce = callable_mp(editor, &VisualShaderEditor::_draw_color_over_button);
  171. if (!button->is_connected("draw", ce)) {
  172. button->connect("draw", ce.bind(button, p_value));
  173. }
  174. } break;
  175. case Variant::BOOL: {
  176. button->set_text(((bool)p_value) ? "true" : "false");
  177. } break;
  178. case Variant::INT:
  179. case Variant::FLOAT: {
  180. button->set_text(String::num(p_value, 4));
  181. } break;
  182. case Variant::VECTOR2: {
  183. Vector2 v = p_value;
  184. button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3));
  185. } break;
  186. case Variant::VECTOR3: {
  187. Vector3 v = p_value;
  188. button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3) + "," + String::num(v.z, 3));
  189. } break;
  190. case Variant::QUATERNION: {
  191. Quaternion v = p_value;
  192. button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3) + "," + String::num(v.z, 3) + "," + String::num(v.w, 3));
  193. } break;
  194. default: {
  195. }
  196. }
  197. }
  198. void VisualShaderGraphPlugin::set_parameter_name(VisualShader::Type p_type, int p_node_id, const String &p_name) {
  199. if (visual_shader->get_shader_type() == p_type && links.has(p_node_id) && links[p_node_id].parameter_name != nullptr) {
  200. links[p_node_id].parameter_name->set_text(p_name);
  201. }
  202. }
  203. void VisualShaderGraphPlugin::update_curve(int p_node_id) {
  204. if (links.has(p_node_id) && links[p_node_id].curve_editors[0]) {
  205. Ref<VisualShaderNodeCurveTexture> tex = Object::cast_to<VisualShaderNodeCurveTexture>(links[p_node_id].visual_node);
  206. ERR_FAIL_COND(!tex.is_valid());
  207. if (tex->get_texture().is_valid()) {
  208. links[p_node_id].curve_editors[0]->set_curve(tex->get_texture()->get_curve());
  209. }
  210. tex->emit_signal(CoreStringNames::get_singleton()->changed);
  211. }
  212. }
  213. void VisualShaderGraphPlugin::update_curve_xyz(int p_node_id) {
  214. 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]) {
  215. Ref<VisualShaderNodeCurveXYZTexture> tex = Object::cast_to<VisualShaderNodeCurveXYZTexture>(links[p_node_id].visual_node);
  216. ERR_FAIL_COND(!tex.is_valid());
  217. if (tex->get_texture().is_valid()) {
  218. links[p_node_id].curve_editors[0]->set_curve(tex->get_texture()->get_curve_x());
  219. links[p_node_id].curve_editors[1]->set_curve(tex->get_texture()->get_curve_y());
  220. links[p_node_id].curve_editors[2]->set_curve(tex->get_texture()->get_curve_z());
  221. }
  222. tex->emit_signal(CoreStringNames::get_singleton()->changed);
  223. }
  224. }
  225. int VisualShaderGraphPlugin::get_constant_index(float p_constant) const {
  226. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  227. if (Math::is_equal_approx(p_constant, float_constant_defs[i].value)) {
  228. return i + 1;
  229. }
  230. }
  231. return 0;
  232. }
  233. void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression) {
  234. if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].expression_edit) {
  235. return;
  236. }
  237. links[p_node_id].expression_edit->set_text(p_expression);
  238. }
  239. Ref<Script> VisualShaderGraphPlugin::get_node_script(int p_node_id) const {
  240. if (!links.has(p_node_id)) {
  241. return Ref<Script>();
  242. }
  243. Ref<VisualShaderNodeCustom> custom = Ref<VisualShaderNodeCustom>(links[p_node_id].visual_node);
  244. if (custom.is_valid()) {
  245. return custom->get_script();
  246. }
  247. return Ref<Script>();
  248. }
  249. void VisualShaderGraphPlugin::update_node_size(int p_node_id) {
  250. if (!links.has(p_node_id)) {
  251. return;
  252. }
  253. links[p_node_id].graph_node->reset_size();
  254. }
  255. void VisualShaderGraphPlugin::register_default_input_button(int p_node_id, int p_port_id, Button *p_button) {
  256. links[p_node_id].input_ports.insert(p_port_id, { p_button });
  257. }
  258. void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit *p_expression_edit) {
  259. links[p_node_id].expression_edit = p_expression_edit;
  260. }
  261. void VisualShaderGraphPlugin::register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor) {
  262. links[p_node_id].curve_editors[p_index] = p_curve_editor;
  263. }
  264. void VisualShaderGraphPlugin::update_parameter_refs() {
  265. for (KeyValue<int, Link> &E : links) {
  266. VisualShaderNodeParameterRef *ref = Object::cast_to<VisualShaderNodeParameterRef>(E.value.visual_node);
  267. if (ref) {
  268. remove_node(E.value.type, E.key, true);
  269. add_node(E.value.type, E.key, true);
  270. }
  271. }
  272. }
  273. VisualShader::Type VisualShaderGraphPlugin::get_shader_type() const {
  274. return visual_shader->get_shader_type();
  275. }
  276. void VisualShaderGraphPlugin::set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position) {
  277. if (visual_shader->get_shader_type() == p_type && links.has(p_id)) {
  278. links[p_id].graph_node->set_position_offset(p_position);
  279. }
  280. }
  281. bool VisualShaderGraphPlugin::is_preview_visible(int p_id) const {
  282. return links[p_id].preview_visible;
  283. }
  284. void VisualShaderGraphPlugin::clear_links() {
  285. links.clear();
  286. }
  287. void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) {
  288. links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, HashMap<int, InputPort>(), HashMap<int, Port>(), nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } });
  289. }
  290. void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) {
  291. links[p_node_id].output_ports.insert(p_port, { p_button });
  292. }
  293. void VisualShaderGraphPlugin::register_parameter_name(int p_node_id, LineEdit *p_parameter_name) {
  294. links[p_node_id].parameter_name = p_parameter_name;
  295. }
  296. void VisualShaderGraphPlugin::update_theme() {
  297. vector_expanded_color[0] = editor->get_theme_color(SNAME("axis_x_color"), SNAME("Editor")); // red
  298. vector_expanded_color[1] = editor->get_theme_color(SNAME("axis_y_color"), SNAME("Editor")); // green
  299. vector_expanded_color[2] = editor->get_theme_color(SNAME("axis_z_color"), SNAME("Editor")); // blue
  300. vector_expanded_color[3] = editor->get_theme_color(SNAME("axis_w_color"), SNAME("Editor")); // alpha
  301. }
  302. void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool p_just_update) {
  303. if (!visual_shader.is_valid() || p_type != visual_shader->get_shader_type()) {
  304. return;
  305. }
  306. GraphEdit *graph = editor->graph;
  307. if (!graph) {
  308. return;
  309. }
  310. VisualShaderGraphPlugin *graph_plugin = editor->get_graph_plugin();
  311. if (!graph_plugin) {
  312. return;
  313. }
  314. Shader::Mode mode = visual_shader->get_mode();
  315. Control *offset;
  316. static const Color type_color[] = {
  317. Color(0.38, 0.85, 0.96), // scalar (float)
  318. Color(0.49, 0.78, 0.94), // scalar (int)
  319. Color(0.20, 0.88, 0.67), // scalar (uint)
  320. Color(0.74, 0.57, 0.95), // vector2
  321. Color(0.84, 0.49, 0.93), // vector3
  322. Color(1.0, 0.125, 0.95), // vector4
  323. Color(0.55, 0.65, 0.94), // boolean
  324. Color(0.96, 0.66, 0.43), // transform
  325. Color(1.0, 1.0, 0.0), // sampler
  326. };
  327. static const String vector_expanded_name[4] = {
  328. "red",
  329. "green",
  330. "blue",
  331. "alpha"
  332. };
  333. // Visual shader specific theme for MSDF font.
  334. Ref<Theme> vstheme;
  335. vstheme.instantiate();
  336. Ref<Font> label_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_msdf", "EditorFonts");
  337. vstheme->set_font("font", "Label", label_font);
  338. vstheme->set_font("font", "LineEdit", label_font);
  339. vstheme->set_font("font", "Button", label_font);
  340. Ref<VisualShaderNode> vsnode = visual_shader->get_node(p_type, p_id);
  341. Ref<VisualShaderNodeResizableBase> resizable_node = Object::cast_to<VisualShaderNodeResizableBase>(vsnode.ptr());
  342. bool is_resizable = !resizable_node.is_null();
  343. Size2 size = Size2(0, 0);
  344. Ref<VisualShaderNodeGroupBase> group_node = Object::cast_to<VisualShaderNodeGroupBase>(vsnode.ptr());
  345. bool is_group = !group_node.is_null();
  346. bool is_comment = false;
  347. Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(group_node.ptr());
  348. bool is_expression = !expression_node.is_null();
  349. String expression = "";
  350. VisualShaderNodeCustom *custom_node = Object::cast_to<VisualShaderNodeCustom>(vsnode.ptr());
  351. if (custom_node) {
  352. custom_node->_set_initialized(true);
  353. }
  354. // Create graph node.
  355. GraphNode *node = memnew(GraphNode);
  356. graph->add_child(node);
  357. node->set_theme(vstheme);
  358. editor->_update_created_node(node);
  359. if (p_just_update) {
  360. Link &link = links[p_id];
  361. link.graph_node = node;
  362. link.preview_box = nullptr;
  363. link.preview_pos = -1;
  364. link.output_ports.clear();
  365. link.input_ports.clear();
  366. } else {
  367. register_link(p_type, p_id, vsnode.ptr(), node);
  368. }
  369. if (is_resizable) {
  370. size = resizable_node->get_size();
  371. node->set_resizable(true);
  372. node->connect("resize_request", callable_mp(editor, &VisualShaderEditor::_node_resized).bind((int)p_type, p_id));
  373. }
  374. if (is_expression) {
  375. expression = expression_node->get_expression();
  376. }
  377. node->set_position_offset(visual_shader->get_node_position(p_type, p_id));
  378. node->set_title(vsnode->get_caption());
  379. node->set_name(itos(p_id));
  380. if (p_id >= 2) {
  381. node->set_show_close_button(true);
  382. node->connect("close_request", callable_mp(editor, &VisualShaderEditor::_delete_node_request).bind(p_type, p_id), CONNECT_DEFERRED);
  383. }
  384. node->connect("dragged", callable_mp(editor, &VisualShaderEditor::_node_dragged).bind(p_id));
  385. Control *custom_editor = nullptr;
  386. int port_offset = 1;
  387. Control *content_offset = memnew(Control);
  388. content_offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  389. node->add_child(content_offset);
  390. if (is_group) {
  391. port_offset += 1;
  392. }
  393. if (is_resizable) {
  394. Ref<VisualShaderNodeComment> comment_node = Object::cast_to<VisualShaderNodeComment>(vsnode.ptr());
  395. if (comment_node.is_valid()) {
  396. is_comment = true;
  397. node->set_comment(true);
  398. Label *comment_label = memnew(Label);
  399. node->add_child(comment_label);
  400. comment_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  401. comment_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  402. comment_label->set_text(comment_node->get_description());
  403. }
  404. editor->call_deferred(SNAME("_set_node_size"), (int)p_type, p_id, size);
  405. }
  406. Ref<VisualShaderNodeParticleEmit> emit = vsnode;
  407. if (emit.is_valid()) {
  408. node->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
  409. }
  410. Ref<VisualShaderNodeParameterRef> parameter_ref = vsnode;
  411. if (parameter_ref.is_valid()) {
  412. parameter_ref->set_shader_rid(visual_shader->get_rid());
  413. parameter_ref->update_parameter_type();
  414. }
  415. Ref<VisualShaderNodeParameter> parameter = vsnode;
  416. HBoxContainer *hb = nullptr;
  417. if (parameter.is_valid()) {
  418. LineEdit *parameter_name = memnew(LineEdit);
  419. register_parameter_name(p_id, parameter_name);
  420. parameter_name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  421. parameter_name->set_text(parameter->get_parameter_name());
  422. parameter_name->connect("text_submitted", callable_mp(editor, &VisualShaderEditor::_parameter_line_edit_changed).bind(p_id));
  423. parameter_name->connect("focus_exited", callable_mp(editor, &VisualShaderEditor::_parameter_line_edit_focus_out).bind(parameter_name, p_id));
  424. if (vsnode->get_output_port_count() == 1 && vsnode->get_output_port_name(0) == "") {
  425. hb = memnew(HBoxContainer);
  426. hb->add_child(parameter_name);
  427. node->add_child(hb);
  428. } else {
  429. node->add_child(parameter_name);
  430. }
  431. port_offset++;
  432. }
  433. for (int i = 0; i < editor->plugins.size(); i++) {
  434. vsnode->set_meta("id", p_id);
  435. vsnode->set_meta("shader_type", (int)p_type);
  436. custom_editor = editor->plugins.write[i]->create_editor(visual_shader, vsnode);
  437. vsnode->remove_meta("id");
  438. vsnode->remove_meta("shader_type");
  439. if (custom_editor) {
  440. if (vsnode->is_show_prop_names()) {
  441. custom_editor->call_deferred(SNAME("_show_prop_names"), true);
  442. }
  443. break;
  444. }
  445. }
  446. Ref<VisualShaderNodeCurveTexture> curve = vsnode;
  447. Ref<VisualShaderNodeCurveXYZTexture> curve_xyz = vsnode;
  448. bool is_curve = curve.is_valid() || curve_xyz.is_valid();
  449. if (is_curve) {
  450. hb = memnew(HBoxContainer);
  451. node->add_child(hb);
  452. }
  453. if (curve.is_valid()) {
  454. custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  455. Callable ce = callable_mp(graph_plugin, &VisualShaderGraphPlugin::update_curve);
  456. if (curve->get_texture().is_valid() && !curve->get_texture()->is_connected("changed", ce)) {
  457. curve->get_texture()->connect("changed", ce.bind(p_id));
  458. }
  459. CurveEditor *curve_editor = memnew(CurveEditor);
  460. node->add_child(curve_editor);
  461. register_curve_editor(p_id, 0, curve_editor);
  462. curve_editor->set_custom_minimum_size(Size2(300, 0));
  463. curve_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  464. if (curve->get_texture().is_valid()) {
  465. curve_editor->set_curve(curve->get_texture()->get_curve());
  466. }
  467. }
  468. if (curve_xyz.is_valid()) {
  469. custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  470. Callable ce = callable_mp(graph_plugin, &VisualShaderGraphPlugin::update_curve_xyz);
  471. if (curve_xyz->get_texture().is_valid() && !curve_xyz->get_texture()->is_connected("changed", ce)) {
  472. curve_xyz->get_texture()->connect("changed", ce.bind(p_id));
  473. }
  474. CurveEditor *curve_editor_x = memnew(CurveEditor);
  475. node->add_child(curve_editor_x);
  476. register_curve_editor(p_id, 0, curve_editor_x);
  477. curve_editor_x->set_custom_minimum_size(Size2(300, 0));
  478. curve_editor_x->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  479. if (curve_xyz->get_texture().is_valid()) {
  480. curve_editor_x->set_curve(curve_xyz->get_texture()->get_curve_x());
  481. }
  482. CurveEditor *curve_editor_y = memnew(CurveEditor);
  483. node->add_child(curve_editor_y);
  484. register_curve_editor(p_id, 1, curve_editor_y);
  485. curve_editor_y->set_custom_minimum_size(Size2(300, 0));
  486. curve_editor_y->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  487. if (curve_xyz->get_texture().is_valid()) {
  488. curve_editor_y->set_curve(curve_xyz->get_texture()->get_curve_y());
  489. }
  490. CurveEditor *curve_editor_z = memnew(CurveEditor);
  491. node->add_child(curve_editor_z);
  492. register_curve_editor(p_id, 2, curve_editor_z);
  493. curve_editor_z->set_custom_minimum_size(Size2(300, 0));
  494. curve_editor_z->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  495. if (curve_xyz->get_texture().is_valid()) {
  496. curve_editor_z->set_curve(curve_xyz->get_texture()->get_curve_z());
  497. }
  498. }
  499. if (custom_editor) {
  500. 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) == ""))) {
  501. //will be embedded in first port
  502. } else {
  503. port_offset++;
  504. node->add_child(custom_editor);
  505. custom_editor = nullptr;
  506. }
  507. }
  508. if (is_group) {
  509. if (group_node->is_editable()) {
  510. HBoxContainer *hb2 = memnew(HBoxContainer);
  511. String input_port_name = "input" + itos(group_node->get_free_input_port_id());
  512. String output_port_name = "output" + itos(group_node->get_free_output_port_id());
  513. for (int i = 0; i < MAX(vsnode->get_input_port_count(), vsnode->get_output_port_count()); i++) {
  514. if (i < vsnode->get_input_port_count()) {
  515. if (input_port_name == vsnode->get_input_port_name(i)) {
  516. input_port_name = "_" + input_port_name;
  517. }
  518. }
  519. if (i < vsnode->get_output_port_count()) {
  520. if (output_port_name == vsnode->get_output_port_name(i)) {
  521. output_port_name = "_" + output_port_name;
  522. }
  523. }
  524. }
  525. Button *add_input_btn = memnew(Button);
  526. add_input_btn->set_text(TTR("Add Input"));
  527. add_input_btn->connect("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);
  528. hb2->add_child(add_input_btn);
  529. hb2->add_spacer();
  530. Button *add_output_btn = memnew(Button);
  531. add_output_btn->set_text(TTR("Add Output"));
  532. add_output_btn->connect("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);
  533. hb2->add_child(add_output_btn);
  534. node->add_child(hb2);
  535. }
  536. }
  537. int output_port_count = 0;
  538. for (int i = 0; i < vsnode->get_output_port_count(); i++) {
  539. if (vsnode->_is_output_port_expanded(i)) {
  540. switch (vsnode->get_output_port_type(i)) {
  541. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  542. output_port_count += 2;
  543. } break;
  544. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  545. output_port_count += 3;
  546. } break;
  547. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  548. output_port_count += 4;
  549. } break;
  550. default:
  551. break;
  552. }
  553. }
  554. output_port_count++;
  555. }
  556. int max_ports = MAX(vsnode->get_input_port_count(), output_port_count);
  557. VisualShaderNode::PortType expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  558. int expanded_port_counter = 0;
  559. for (int i = 0, j = 0; i < max_ports; i++, j++) {
  560. switch (expanded_type) {
  561. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  562. if (expanded_port_counter >= 2) {
  563. expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  564. expanded_port_counter = 0;
  565. i -= 2;
  566. }
  567. } break;
  568. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  569. if (expanded_port_counter >= 3) {
  570. expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  571. expanded_port_counter = 0;
  572. i -= 3;
  573. }
  574. } break;
  575. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  576. if (expanded_port_counter >= 4) {
  577. expanded_type = VisualShaderNode::PORT_TYPE_SCALAR;
  578. expanded_port_counter = 0;
  579. i -= 4;
  580. }
  581. } break;
  582. default:
  583. break;
  584. }
  585. if (vsnode->is_port_separator(i)) {
  586. node->add_child(memnew(HSeparator));
  587. port_offset++;
  588. }
  589. bool valid_left = j < vsnode->get_input_port_count();
  590. VisualShaderNode::PortType port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  591. bool port_left_used = false;
  592. String name_left;
  593. if (valid_left) {
  594. name_left = vsnode->get_input_port_name(i);
  595. port_left = vsnode->get_input_port_type(i);
  596. for (const VisualShader::Connection &E : connections) {
  597. if (E.to_node == p_id && E.to_port == j) {
  598. port_left_used = true;
  599. break;
  600. }
  601. }
  602. }
  603. bool valid_right = true;
  604. VisualShaderNode::PortType port_right = VisualShaderNode::PORT_TYPE_SCALAR;
  605. String name_right;
  606. if (expanded_type == VisualShaderNode::PORT_TYPE_SCALAR) {
  607. valid_right = i < vsnode->get_output_port_count();
  608. if (valid_right) {
  609. name_right = vsnode->get_output_port_name(i);
  610. port_right = vsnode->get_output_port_type(i);
  611. }
  612. } else {
  613. name_right = vector_expanded_name[expanded_port_counter++];
  614. }
  615. bool is_first_hbox = false;
  616. if (i == 0 && hb != nullptr) {
  617. is_first_hbox = true;
  618. } else {
  619. hb = memnew(HBoxContainer);
  620. }
  621. hb->add_theme_constant_override("separation", 7 * EDSCALE);
  622. Variant default_value;
  623. if (valid_left && !port_left_used) {
  624. default_value = vsnode->get_input_port_default_value(i);
  625. }
  626. Button *button = memnew(Button);
  627. hb->add_child(button);
  628. register_default_input_button(p_id, i, button);
  629. button->connect("pressed", callable_mp(editor, &VisualShaderEditor::_edit_port_default_input).bind(button, p_id, i));
  630. if (default_value.get_type() != Variant::NIL) { // only a label
  631. set_input_port_default_value(p_type, p_id, i, default_value);
  632. } else {
  633. button->hide();
  634. }
  635. if (i == 0 && custom_editor) {
  636. hb->add_child(custom_editor);
  637. custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  638. } else {
  639. if (valid_left) {
  640. if (is_group) {
  641. OptionButton *type_box = memnew(OptionButton);
  642. hb->add_child(type_box);
  643. type_box->add_item(TTR("Float"));
  644. type_box->add_item(TTR("Int"));
  645. type_box->add_item(TTR("UInt"));
  646. type_box->add_item(TTR("Vector2"));
  647. type_box->add_item(TTR("Vector3"));
  648. type_box->add_item(TTR("Vector4"));
  649. type_box->add_item(TTR("Boolean"));
  650. type_box->add_item(TTR("Transform"));
  651. type_box->add_item(TTR("Sampler"));
  652. type_box->select(group_node->get_input_port_type(i));
  653. type_box->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  654. type_box->connect("item_selected", callable_mp(editor, &VisualShaderEditor::_change_input_port_type).bind(p_id, i), CONNECT_DEFERRED);
  655. LineEdit *name_box = memnew(LineEdit);
  656. hb->add_child(name_box);
  657. name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0));
  658. name_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  659. name_box->set_text(name_left);
  660. name_box->connect("text_submitted", callable_mp(editor, &VisualShaderEditor::_change_input_port_name).bind(name_box, p_id, i), CONNECT_DEFERRED);
  661. name_box->connect("focus_exited", callable_mp(editor, &VisualShaderEditor::_port_name_focus_out).bind(name_box, p_id, i, false), CONNECT_DEFERRED);
  662. Button *remove_btn = memnew(Button);
  663. remove_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
  664. remove_btn->set_tooltip_text(TTR("Remove") + " " + name_left);
  665. remove_btn->connect("pressed", callable_mp(editor, &VisualShaderEditor::_remove_input_port).bind(p_id, i), CONNECT_DEFERRED);
  666. hb->add_child(remove_btn);
  667. } else {
  668. Label *label = memnew(Label);
  669. label->set_text(name_left);
  670. label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact
  671. hb->add_child(label);
  672. if (vsnode->is_input_port_default(i, mode) && !port_left_used) {
  673. Label *hint_label = memnew(Label);
  674. hint_label->set_text(TTR("[default]"));
  675. hint_label->add_theme_color_override("font_color", editor->get_theme_color(SNAME("font_readonly_color"), SNAME("TextEdit")));
  676. hint_label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor")));
  677. hb->add_child(hint_label);
  678. }
  679. }
  680. }
  681. if (!is_group && !is_first_hbox) {
  682. hb->add_spacer();
  683. }
  684. if (valid_right) {
  685. if (is_group) {
  686. Button *remove_btn = memnew(Button);
  687. remove_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
  688. remove_btn->set_tooltip_text(TTR("Remove") + " " + name_left);
  689. remove_btn->connect("pressed", callable_mp(editor, &VisualShaderEditor::_remove_output_port).bind(p_id, i), CONNECT_DEFERRED);
  690. hb->add_child(remove_btn);
  691. LineEdit *name_box = memnew(LineEdit);
  692. hb->add_child(name_box);
  693. name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0));
  694. name_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  695. name_box->set_text(name_right);
  696. name_box->connect("text_submitted", callable_mp(editor, &VisualShaderEditor::_change_output_port_name).bind(name_box, p_id, i), CONNECT_DEFERRED);
  697. name_box->connect("focus_exited", callable_mp(editor, &VisualShaderEditor::_port_name_focus_out).bind(name_box, p_id, i, true), CONNECT_DEFERRED);
  698. OptionButton *type_box = memnew(OptionButton);
  699. hb->add_child(type_box);
  700. type_box->add_item(TTR("Float"));
  701. type_box->add_item(TTR("Int"));
  702. type_box->add_item(TTR("UInt"));
  703. type_box->add_item(TTR("Vector2"));
  704. type_box->add_item(TTR("Vector3"));
  705. type_box->add_item(TTR("Vector4"));
  706. type_box->add_item(TTR("Boolean"));
  707. type_box->add_item(TTR("Transform"));
  708. type_box->select(group_node->get_output_port_type(i));
  709. type_box->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  710. type_box->connect("item_selected", callable_mp(editor, &VisualShaderEditor::_change_output_port_type).bind(p_id, i), CONNECT_DEFERRED);
  711. } else {
  712. Label *label = memnew(Label);
  713. label->set_text(name_right);
  714. label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact
  715. hb->add_child(label);
  716. }
  717. }
  718. }
  719. if (valid_right) {
  720. if (vsnode->is_output_port_expandable(i)) {
  721. TextureButton *expand = memnew(TextureButton);
  722. expand->set_toggle_mode(true);
  723. expand->set_texture_normal(editor->get_theme_icon(SNAME("GuiTreeArrowDown"), SNAME("EditorIcons")));
  724. expand->set_texture_pressed(editor->get_theme_icon(SNAME("GuiTreeArrowRight"), SNAME("EditorIcons")));
  725. expand->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  726. expand->set_pressed(vsnode->_is_output_port_expanded(i));
  727. expand->connect("pressed", callable_mp(editor, &VisualShaderEditor::_expand_output_port).bind(p_id, i, !vsnode->_is_output_port_expanded(i)), CONNECT_DEFERRED);
  728. hb->add_child(expand);
  729. }
  730. if (vsnode->has_output_port_preview(i) && port_right != VisualShaderNode::PORT_TYPE_TRANSFORM && port_right != VisualShaderNode::PORT_TYPE_SAMPLER) {
  731. TextureButton *preview = memnew(TextureButton);
  732. preview->set_toggle_mode(true);
  733. preview->set_texture_normal(editor->get_theme_icon(SNAME("GuiVisibilityHidden"), SNAME("EditorIcons")));
  734. preview->set_texture_pressed(editor->get_theme_icon(SNAME("GuiVisibilityVisible"), SNAME("EditorIcons")));
  735. preview->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  736. register_output_port(p_id, j, preview);
  737. preview->connect("pressed", callable_mp(editor, &VisualShaderEditor::_preview_select_port).bind(p_id, j), CONNECT_DEFERRED);
  738. hb->add_child(preview);
  739. }
  740. }
  741. if (is_group) {
  742. offset = memnew(Control);
  743. offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE));
  744. node->add_child(offset);
  745. port_offset++;
  746. }
  747. if (!is_first_hbox) {
  748. node->add_child(hb);
  749. }
  750. if (expanded_type != VisualShaderNode::PORT_TYPE_SCALAR) {
  751. continue;
  752. }
  753. int idx = 1;
  754. if (!is_first_hbox) {
  755. idx = i + port_offset;
  756. }
  757. node->set_slot(idx, valid_left, port_left, type_color[port_left], valid_right, port_right, type_color[port_right]);
  758. if (vsnode->_is_output_port_expanded(i)) {
  759. switch (vsnode->get_output_port_type(i)) {
  760. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  761. port_offset++;
  762. valid_left = (i + 1) < vsnode->get_input_port_count();
  763. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  764. if (valid_left) {
  765. port_left = vsnode->get_input_port_type(i + 1);
  766. }
  767. node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]);
  768. port_offset++;
  769. valid_left = (i + 2) < vsnode->get_input_port_count();
  770. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  771. if (valid_left) {
  772. port_left = vsnode->get_input_port_type(i + 2);
  773. }
  774. node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]);
  775. expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_2D;
  776. } break;
  777. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  778. port_offset++;
  779. valid_left = (i + 1) < vsnode->get_input_port_count();
  780. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  781. if (valid_left) {
  782. port_left = vsnode->get_input_port_type(i + 1);
  783. }
  784. node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]);
  785. port_offset++;
  786. valid_left = (i + 2) < vsnode->get_input_port_count();
  787. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  788. if (valid_left) {
  789. port_left = vsnode->get_input_port_type(i + 2);
  790. }
  791. node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]);
  792. port_offset++;
  793. valid_left = (i + 3) < vsnode->get_input_port_count();
  794. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  795. if (valid_left) {
  796. port_left = vsnode->get_input_port_type(i + 3);
  797. }
  798. node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]);
  799. expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_3D;
  800. } break;
  801. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  802. port_offset++;
  803. valid_left = (i + 1) < vsnode->get_input_port_count();
  804. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  805. if (valid_left) {
  806. port_left = vsnode->get_input_port_type(i + 1);
  807. }
  808. node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]);
  809. port_offset++;
  810. valid_left = (i + 2) < vsnode->get_input_port_count();
  811. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  812. if (valid_left) {
  813. port_left = vsnode->get_input_port_type(i + 2);
  814. }
  815. node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]);
  816. port_offset++;
  817. valid_left = (i + 3) < vsnode->get_input_port_count();
  818. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  819. if (valid_left) {
  820. port_left = vsnode->get_input_port_type(i + 3);
  821. }
  822. node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]);
  823. port_offset++;
  824. valid_left = (i + 4) < vsnode->get_input_port_count();
  825. port_left = VisualShaderNode::PORT_TYPE_SCALAR;
  826. if (valid_left) {
  827. port_left = vsnode->get_input_port_type(i + 4);
  828. }
  829. node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[3]);
  830. expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_4D;
  831. } break;
  832. default:
  833. break;
  834. }
  835. }
  836. }
  837. if (vsnode->get_output_port_for_preview() >= 0) {
  838. show_port_preview(p_type, p_id, vsnode->get_output_port_for_preview());
  839. } else {
  840. offset = memnew(Control);
  841. offset->set_custom_minimum_size(Size2(0, 4 * EDSCALE));
  842. node->add_child(offset);
  843. }
  844. String error = vsnode->get_warning(mode, p_type);
  845. if (!error.is_empty()) {
  846. Label *error_label = memnew(Label);
  847. error_label->add_theme_color_override("font_color", editor->get_theme_color(SNAME("error_color"), SNAME("Editor")));
  848. error_label->set_text(error);
  849. node->add_child(error_label);
  850. }
  851. if (is_expression) {
  852. CodeEdit *expression_box = memnew(CodeEdit);
  853. Ref<CodeHighlighter> expression_syntax_highlighter;
  854. expression_syntax_highlighter.instantiate();
  855. expression_node->set_ctrl_pressed(expression_box, 0);
  856. node->add_child(expression_box);
  857. register_expression_edit(p_id, expression_box);
  858. Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color");
  859. Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color");
  860. Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
  861. Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color");
  862. Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
  863. Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color");
  864. Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color");
  865. Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color");
  866. Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color");
  867. expression_box->set_syntax_highlighter(expression_syntax_highlighter);
  868. expression_box->add_theme_color_override("background_color", background_color);
  869. for (const String &E : editor->keyword_list) {
  870. if (ShaderLanguage::is_control_flow_keyword(E)) {
  871. expression_syntax_highlighter->add_keyword_color(E, control_flow_keyword_color);
  872. } else {
  873. expression_syntax_highlighter->add_keyword_color(E, keyword_color);
  874. }
  875. }
  876. expression_box->add_theme_font_override("font", editor->get_theme_font(SNAME("expression"), SNAME("EditorFonts")));
  877. expression_box->add_theme_font_size_override("font_size", editor->get_theme_font_size(SNAME("expression_size"), SNAME("EditorFonts")));
  878. expression_box->add_theme_color_override("font_color", text_color);
  879. expression_syntax_highlighter->set_number_color(number_color);
  880. expression_syntax_highlighter->set_symbol_color(symbol_color);
  881. expression_syntax_highlighter->set_function_color(function_color);
  882. expression_syntax_highlighter->set_member_variable_color(members_color);
  883. expression_syntax_highlighter->add_color_region("/*", "*/", comment_color, false);
  884. expression_syntax_highlighter->add_color_region("//", "", comment_color, true);
  885. expression_box->clear_comment_delimiters();
  886. expression_box->add_comment_delimiter("/*", "*/", false);
  887. expression_box->add_comment_delimiter("//", "", true);
  888. if (!expression_box->has_auto_brace_completion_open_key("/*")) {
  889. expression_box->add_auto_brace_completion_pair("/*", "*/");
  890. }
  891. expression_box->set_text(expression);
  892. expression_box->set_context_menu_enabled(false);
  893. expression_box->set_draw_line_numbers(true);
  894. expression_box->connect("focus_exited", callable_mp(editor, &VisualShaderEditor::_expression_focus_out).bind(expression_box, p_id));
  895. }
  896. if (is_comment) {
  897. graph->move_child(node, 0); // to prevents a bug where comment node overlaps its content
  898. }
  899. }
  900. void VisualShaderGraphPlugin::remove_node(VisualShader::Type p_type, int p_id, bool p_just_update) {
  901. if (visual_shader->get_shader_type() == p_type && links.has(p_id)) {
  902. links[p_id].graph_node->get_parent()->remove_child(links[p_id].graph_node);
  903. memdelete(links[p_id].graph_node);
  904. if (!p_just_update) {
  905. links.erase(p_id);
  906. }
  907. }
  908. }
  909. void VisualShaderGraphPlugin::connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
  910. GraphEdit *graph = editor->graph;
  911. if (!graph) {
  912. return;
  913. }
  914. if (visual_shader.is_valid() && visual_shader->get_shader_type() == p_type) {
  915. graph->connect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
  916. connections.push_back({ p_from_node, p_from_port, p_to_node, p_to_port });
  917. if (links[p_to_node].input_ports.has(p_to_port) && links[p_to_node].input_ports[p_to_port].default_input_button != nullptr) {
  918. links[p_to_node].input_ports[p_to_port].default_input_button->hide();
  919. }
  920. }
  921. }
  922. void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
  923. GraphEdit *graph = editor->graph;
  924. if (!graph) {
  925. return;
  926. }
  927. if (visual_shader.is_valid() && visual_shader->get_shader_type() == p_type) {
  928. graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
  929. for (const List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) {
  930. 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) {
  931. connections.erase(E);
  932. break;
  933. }
  934. }
  935. 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) {
  936. links[p_to_node].input_ports[p_to_port].default_input_button->show();
  937. 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));
  938. }
  939. }
  940. }
  941. VisualShaderGraphPlugin::~VisualShaderGraphPlugin() {
  942. }
  943. /////////////////
  944. void VisualShaderEditedProperty::_bind_methods() {
  945. ClassDB::bind_method(D_METHOD("set_edited_property", "value"), &VisualShaderEditedProperty::set_edited_property);
  946. ClassDB::bind_method(D_METHOD("get_edited_property"), &VisualShaderEditedProperty::get_edited_property);
  947. ADD_PROPERTY(PropertyInfo(Variant::NIL, "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_edited_property", "get_edited_property");
  948. }
  949. void VisualShaderEditedProperty::set_edited_property(Variant p_variant) {
  950. edited_property = p_variant;
  951. }
  952. Variant VisualShaderEditedProperty::get_edited_property() const {
  953. return edited_property;
  954. }
  955. /////////////////
  956. Vector2 VisualShaderEditor::selection_center;
  957. List<VisualShaderEditor::CopyItem> VisualShaderEditor::copy_items_buffer;
  958. List<VisualShader::Connection> VisualShaderEditor::copy_connections_buffer;
  959. void VisualShaderEditor::edit(VisualShader *p_visual_shader) {
  960. bool changed = false;
  961. if (p_visual_shader) {
  962. if (visual_shader.is_null()) {
  963. changed = true;
  964. } else {
  965. if (visual_shader.ptr() != p_visual_shader) {
  966. changed = true;
  967. }
  968. }
  969. visual_shader = Ref<VisualShader>(p_visual_shader);
  970. graph_plugin->register_shader(visual_shader.ptr());
  971. Callable ce = callable_mp(this, &VisualShaderEditor::_update_preview);
  972. if (!visual_shader->is_connected("changed", ce)) {
  973. visual_shader->connect("changed", ce);
  974. }
  975. visual_shader->set_graph_offset(graph->get_scroll_ofs() / EDSCALE);
  976. _set_mode(visual_shader->get_mode());
  977. _update_nodes();
  978. } else {
  979. if (visual_shader.is_valid()) {
  980. Callable ce = callable_mp(this, &VisualShaderEditor::_update_preview);
  981. if (visual_shader->is_connected("changed", ce)) {
  982. visual_shader->disconnect("changed", ce);
  983. }
  984. }
  985. visual_shader.unref();
  986. }
  987. if (visual_shader.is_null()) {
  988. hide();
  989. } else {
  990. if (changed) { // to avoid tree collapse
  991. _update_varying_tree();
  992. _update_options_menu();
  993. _update_preview();
  994. _update_graph();
  995. }
  996. }
  997. }
  998. void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
  999. if (plugins.has(p_plugin)) {
  1000. return;
  1001. }
  1002. plugins.push_back(p_plugin);
  1003. }
  1004. void VisualShaderEditor::remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
  1005. plugins.erase(p_plugin);
  1006. }
  1007. void VisualShaderEditor::clear_custom_types() {
  1008. for (int i = 0; i < add_options.size(); i++) {
  1009. if (add_options[i].is_custom) {
  1010. add_options.remove_at(i);
  1011. i--;
  1012. }
  1013. }
  1014. }
  1015. void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend) {
  1016. ERR_FAIL_COND(!p_name.is_valid_identifier());
  1017. ERR_FAIL_COND(!p_script.is_valid());
  1018. for (int i = 0; i < add_options.size(); i++) {
  1019. if (add_options[i].is_custom) {
  1020. if (add_options[i].script == p_script) {
  1021. return;
  1022. }
  1023. }
  1024. }
  1025. AddOption ao;
  1026. ao.name = p_name;
  1027. ao.script = p_script;
  1028. ao.return_type = p_return_icon_type;
  1029. ao.description = p_description;
  1030. ao.category = p_category;
  1031. ao.highend = p_highend;
  1032. ao.is_custom = true;
  1033. bool begin = false;
  1034. String root = p_category.split("/")[0];
  1035. for (int i = 0; i < add_options.size(); i++) {
  1036. if (add_options[i].is_custom) {
  1037. if (add_options[i].category == root) {
  1038. if (!begin) {
  1039. begin = true;
  1040. }
  1041. } else {
  1042. if (begin) {
  1043. add_options.insert(i, ao);
  1044. return;
  1045. }
  1046. }
  1047. }
  1048. }
  1049. add_options.push_back(ao);
  1050. }
  1051. Dictionary VisualShaderEditor::get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node) {
  1052. Dictionary dict;
  1053. dict["script"] = p_custom_node->get_script();
  1054. String name;
  1055. if (p_custom_node->has_method("_get_name")) {
  1056. name = (String)p_custom_node->call("_get_name");
  1057. } else {
  1058. name = "Unnamed";
  1059. }
  1060. dict["name"] = name;
  1061. String description = "";
  1062. if (p_custom_node->has_method("_get_description")) {
  1063. description = (String)p_custom_node->call("_get_description");
  1064. }
  1065. dict["description"] = description;
  1066. int return_icon_type = -1;
  1067. if (p_custom_node->has_method("_get_return_icon_type")) {
  1068. return_icon_type = (int)p_custom_node->call("_get_return_icon_type");
  1069. }
  1070. dict["return_icon_type"] = return_icon_type;
  1071. String category = "";
  1072. if (p_custom_node->has_method("_get_category")) {
  1073. category = (String)p_custom_node->call("_get_category");
  1074. }
  1075. category = category.rstrip("/");
  1076. category = category.lstrip("/");
  1077. category = "Addons/" + category;
  1078. String subcategory = "";
  1079. if (p_custom_node->has_method("_get_subcategory")) {
  1080. subcategory = (String)p_custom_node->call("_get_subcategory");
  1081. }
  1082. if (!subcategory.is_empty()) {
  1083. category += "/" + subcategory;
  1084. }
  1085. dict["category"] = category;
  1086. bool highend = false;
  1087. if (p_custom_node->has_method("_is_highend")) {
  1088. highend = (bool)p_custom_node->call("_is_highend");
  1089. }
  1090. dict["highend"] = highend;
  1091. return dict;
  1092. }
  1093. void VisualShaderEditor::_get_current_mode_limits(int &r_begin_type, int &r_end_type) const {
  1094. switch (visual_shader->get_mode()) {
  1095. case Shader::MODE_CANVAS_ITEM:
  1096. case Shader::MODE_SPATIAL: {
  1097. r_begin_type = 0;
  1098. r_end_type = 3;
  1099. } break;
  1100. case Shader::MODE_PARTICLES: {
  1101. r_begin_type = 3;
  1102. r_end_type = 5 + r_begin_type;
  1103. } break;
  1104. case Shader::MODE_SKY: {
  1105. r_begin_type = 8;
  1106. r_end_type = 1 + r_begin_type;
  1107. } break;
  1108. case Shader::MODE_FOG: {
  1109. r_begin_type = 9;
  1110. r_end_type = 1 + r_begin_type;
  1111. } break;
  1112. default: {
  1113. } break;
  1114. }
  1115. }
  1116. void VisualShaderEditor::_script_created(const Ref<Script> &p_script) {
  1117. if (p_script.is_null() || p_script->get_instance_base_type() != "VisualShaderNodeCustom") {
  1118. return;
  1119. }
  1120. Ref<VisualShaderNodeCustom> ref;
  1121. ref.instantiate();
  1122. ref->set_script(p_script);
  1123. Dictionary dict = get_custom_node_data(ref);
  1124. add_custom_type(dict["name"], dict["script"], dict["description"], dict["return_icon_type"], dict["category"], dict["highend"]);
  1125. _update_options_menu();
  1126. }
  1127. void VisualShaderEditor::_update_custom_script(const Ref<Script> &p_script) {
  1128. if (p_script.is_null() || p_script->get_instance_base_type() != "VisualShaderNodeCustom") {
  1129. return;
  1130. }
  1131. Ref<VisualShaderNodeCustom> ref;
  1132. ref.instantiate();
  1133. ref->set_script(p_script);
  1134. if (!ref->is_available(visual_shader->get_mode(), visual_shader->get_shader_type())) {
  1135. for (int i = 0; i < add_options.size(); i++) {
  1136. if (add_options[i].is_custom && add_options[i].script == p_script) {
  1137. add_options.remove_at(i);
  1138. _update_options_menu();
  1139. // TODO: Make indication for the existed custom nodes with that script on graph to be disabled.
  1140. break;
  1141. }
  1142. }
  1143. return;
  1144. }
  1145. Dictionary dict = get_custom_node_data(ref);
  1146. bool found_type = false;
  1147. bool need_rebuild = false;
  1148. for (int i = custom_node_option_idx; i < add_options.size(); i++) {
  1149. if (add_options[i].script == p_script) {
  1150. found_type = true;
  1151. add_options.write[i].name = dict["name"];
  1152. add_options.write[i].return_type = dict["return_icon_type"];
  1153. add_options.write[i].description = dict["description"];
  1154. add_options.write[i].category = dict["category"];
  1155. add_options.write[i].highend = dict["highend"];
  1156. int begin_type = 0;
  1157. int end_type = 0;
  1158. _get_current_mode_limits(begin_type, end_type);
  1159. for (int t = begin_type; t < end_type; t++) {
  1160. VisualShader::Type type = (VisualShader::Type)t;
  1161. Vector<int> nodes = visual_shader->get_node_list(type);
  1162. List<VisualShader::Connection> node_connections;
  1163. visual_shader->get_node_connections(type, &node_connections);
  1164. List<VisualShader::Connection> custom_node_input_connections;
  1165. List<VisualShader::Connection> custom_node_output_connections;
  1166. for (const VisualShader::Connection &E : node_connections) {
  1167. int from = E.from_node;
  1168. int from_port = E.from_port;
  1169. int to = E.to_node;
  1170. int to_port = E.to_port;
  1171. if (graph_plugin->get_node_script(from) == p_script) {
  1172. custom_node_output_connections.push_back({ from, from_port, to, to_port });
  1173. } else if (graph_plugin->get_node_script(to) == p_script) {
  1174. custom_node_input_connections.push_back({ from, from_port, to, to_port });
  1175. }
  1176. }
  1177. for (int node_id : nodes) {
  1178. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  1179. if (vsnode.is_null()) {
  1180. continue;
  1181. }
  1182. Ref<VisualShaderNodeCustom> custom_node = Ref<VisualShaderNodeCustom>(vsnode.ptr());
  1183. if (custom_node.is_null() || custom_node->get_script() != p_script) {
  1184. continue;
  1185. }
  1186. need_rebuild = true;
  1187. // Removes invalid connections.
  1188. {
  1189. int prev_input_port_count = custom_node->get_input_port_count();
  1190. int prev_output_port_count = custom_node->get_output_port_count();
  1191. custom_node->update_ports();
  1192. int input_port_count = custom_node->get_input_port_count();
  1193. int output_port_count = custom_node->get_output_port_count();
  1194. if (output_port_count != prev_output_port_count) {
  1195. for (const VisualShader::Connection &E : custom_node_output_connections) {
  1196. int from = E.from_node;
  1197. int from_idx = E.from_port;
  1198. int to = E.to_node;
  1199. int to_idx = E.to_port;
  1200. if (from_idx >= output_port_count) {
  1201. visual_shader->disconnect_nodes(type, from, from_idx, to, to_idx);
  1202. graph_plugin->disconnect_nodes(type, from, from_idx, to, to_idx);
  1203. }
  1204. }
  1205. }
  1206. if (input_port_count != prev_input_port_count) {
  1207. for (const VisualShader::Connection &E : custom_node_input_connections) {
  1208. int from = E.from_node;
  1209. int from_idx = E.from_port;
  1210. int to = E.to_node;
  1211. int to_idx = E.to_port;
  1212. if (to_idx >= input_port_count) {
  1213. visual_shader->disconnect_nodes(type, from, from_idx, to, to_idx);
  1214. graph_plugin->disconnect_nodes(type, from, from_idx, to, to_idx);
  1215. }
  1216. }
  1217. }
  1218. }
  1219. graph_plugin->update_node(type, node_id);
  1220. }
  1221. }
  1222. break;
  1223. }
  1224. }
  1225. if (!found_type) {
  1226. add_custom_type(dict["name"], dict["script"], dict["description"], dict["return_icon_type"], dict["category"], dict["highend"]);
  1227. }
  1228. // To prevent updating options multiple times when multiple scripts are saved.
  1229. if (!_block_update_options_menu) {
  1230. _block_update_options_menu = true;
  1231. call_deferred(SNAME("_update_options_menu_deferred"));
  1232. }
  1233. // To prevent rebuilding the shader multiple times when multiple scripts are saved.
  1234. if (need_rebuild && !_block_rebuild_shader) {
  1235. _block_rebuild_shader = true;
  1236. call_deferred(SNAME("_rebuild_shader_deferred"));
  1237. }
  1238. }
  1239. void VisualShaderEditor::_resource_saved(const Ref<Resource> &p_resource) {
  1240. _update_custom_script(Ref<Script>(p_resource.ptr()));
  1241. }
  1242. void VisualShaderEditor::_resources_removed() {
  1243. bool has_any_instance = false;
  1244. for (const Ref<Script> &scr : custom_scripts_to_delete) {
  1245. for (int i = custom_node_option_idx; i < add_options.size(); i++) {
  1246. if (add_options[i].script == scr) {
  1247. add_options.remove_at(i);
  1248. // Removes all node instances using that script from the graph.
  1249. {
  1250. int begin_type = 0;
  1251. int end_type = 0;
  1252. _get_current_mode_limits(begin_type, end_type);
  1253. for (int t = begin_type; t < end_type; t++) {
  1254. VisualShader::Type type = (VisualShader::Type)t;
  1255. List<VisualShader::Connection> node_connections;
  1256. visual_shader->get_node_connections(type, &node_connections);
  1257. for (const VisualShader::Connection &E : node_connections) {
  1258. int from = E.from_node;
  1259. int from_port = E.from_port;
  1260. int to = E.to_node;
  1261. int to_port = E.to_port;
  1262. if (graph_plugin->get_node_script(from) == scr || graph_plugin->get_node_script(to) == scr) {
  1263. visual_shader->disconnect_nodes(type, from, from_port, to, to_port);
  1264. graph_plugin->disconnect_nodes(type, from, from_port, to, to_port);
  1265. }
  1266. }
  1267. Vector<int> nodes = visual_shader->get_node_list(type);
  1268. for (int node_id : nodes) {
  1269. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  1270. if (vsnode.is_null()) {
  1271. continue;
  1272. }
  1273. Ref<VisualShaderNodeCustom> custom_node = Ref<VisualShaderNodeCustom>(vsnode.ptr());
  1274. if (custom_node.is_null() || custom_node->get_script() != scr) {
  1275. continue;
  1276. }
  1277. visual_shader->remove_node(type, node_id);
  1278. graph_plugin->remove_node(type, node_id, false);
  1279. has_any_instance = true;
  1280. }
  1281. }
  1282. }
  1283. break;
  1284. }
  1285. }
  1286. }
  1287. if (has_any_instance) {
  1288. 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).
  1289. ResourceSaver::save(visual_shader, visual_shader->get_path());
  1290. }
  1291. _update_options_menu();
  1292. custom_scripts_to_delete.clear();
  1293. pending_custom_scripts_to_delete = false;
  1294. }
  1295. void VisualShaderEditor::_resource_removed(const Ref<Resource> &p_resource) {
  1296. Ref<Script> scr = Ref<Script>(p_resource.ptr());
  1297. if (scr.is_null() || scr->get_instance_base_type() != "VisualShaderNodeCustom") {
  1298. return;
  1299. }
  1300. custom_scripts_to_delete.push_back(scr);
  1301. if (!pending_custom_scripts_to_delete) {
  1302. pending_custom_scripts_to_delete = true;
  1303. call_deferred("_resources_removed");
  1304. }
  1305. }
  1306. void VisualShaderEditor::_update_options_menu_deferred() {
  1307. _update_options_menu();
  1308. _block_update_options_menu = false;
  1309. }
  1310. void VisualShaderEditor::_rebuild_shader_deferred() {
  1311. if (visual_shader.is_valid()) {
  1312. visual_shader->rebuild();
  1313. }
  1314. _block_rebuild_shader = false;
  1315. }
  1316. bool VisualShaderEditor::_is_available(int p_mode) {
  1317. int current_mode = edit_type->get_selected();
  1318. if (p_mode != -1) {
  1319. switch (current_mode) {
  1320. case 0: // Vertex / Emit
  1321. current_mode = 1;
  1322. break;
  1323. case 1: // Fragment / Process
  1324. current_mode = 2;
  1325. break;
  1326. case 2: // Light / Collide
  1327. current_mode = 4;
  1328. break;
  1329. default:
  1330. break;
  1331. }
  1332. }
  1333. return (p_mode == -1 || (p_mode & current_mode) != 0);
  1334. }
  1335. void VisualShaderEditor::_update_nodes() {
  1336. clear_custom_types();
  1337. List<StringName> class_list;
  1338. ScriptServer::get_global_class_list(&class_list);
  1339. Dictionary added;
  1340. for (int i = 0; i < class_list.size(); i++) {
  1341. if (ScriptServer::get_global_class_native_base(class_list[i]) == "VisualShaderNodeCustom") {
  1342. String script_path = ScriptServer::get_global_class_path(class_list[i]);
  1343. Ref<Resource> res = ResourceLoader::load(script_path);
  1344. ERR_FAIL_COND(res.is_null());
  1345. ERR_FAIL_COND(!res->is_class("Script"));
  1346. Ref<Script> scr = Ref<Script>(res);
  1347. Ref<VisualShaderNodeCustom> ref;
  1348. ref.instantiate();
  1349. ref->set_script(scr);
  1350. if (!ref->is_available(visual_shader->get_mode(), visual_shader->get_shader_type())) {
  1351. continue;
  1352. }
  1353. Dictionary dict = get_custom_node_data(ref);
  1354. String key;
  1355. key = String(dict["category"]) + "/" + String(dict["name"]);
  1356. added[key] = dict;
  1357. }
  1358. }
  1359. // Disables not-supported copied items.
  1360. {
  1361. for (CopyItem &item : copy_items_buffer) {
  1362. Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(item.node.ptr());
  1363. if (custom.is_valid()) {
  1364. if (!custom->is_available(visual_shader->get_mode(), visual_shader->get_shader_type())) {
  1365. item.disabled = true;
  1366. } else {
  1367. item.disabled = false;
  1368. }
  1369. } else {
  1370. for (int i = 0; i < add_options.size(); i++) {
  1371. if (add_options[i].type == item.node->get_class_name()) {
  1372. if ((add_options[i].func != visual_shader->get_mode() && add_options[i].func != -1) || !_is_available(add_options[i].mode)) {
  1373. item.disabled = true;
  1374. } else {
  1375. item.disabled = false;
  1376. }
  1377. break;
  1378. }
  1379. }
  1380. }
  1381. }
  1382. }
  1383. Array keys = added.keys();
  1384. keys.sort();
  1385. for (int i = 0; i < keys.size(); i++) {
  1386. const Variant &key = keys.get(i);
  1387. const Dictionary &value = (Dictionary)added[key];
  1388. add_custom_type(value["name"], value["script"], value["description"], value["return_icon_type"], value["category"], value["highend"]);
  1389. }
  1390. _update_options_menu();
  1391. }
  1392. String VisualShaderEditor::_get_description(int p_idx) {
  1393. return add_options[p_idx].description;
  1394. }
  1395. void VisualShaderEditor::_update_options_menu() {
  1396. node_desc->set_text("");
  1397. members_dialog->get_ok_button()->set_disabled(true);
  1398. members->clear();
  1399. TreeItem *root = members->create_item();
  1400. String filter = node_filter->get_text().strip_edges();
  1401. bool use_filter = !filter.is_empty();
  1402. bool is_first_item = true;
  1403. Color unsupported_color = get_theme_color(SNAME("error_color"), SNAME("Editor"));
  1404. Color supported_color = get_theme_color(SNAME("warning_color"), SNAME("Editor"));
  1405. static bool low_driver = GLOBAL_GET("rendering/renderer/rendering_method") == "gl_compatibility";
  1406. HashMap<String, TreeItem *> folders;
  1407. int current_func = -1;
  1408. if (!visual_shader.is_null()) {
  1409. current_func = visual_shader->get_mode();
  1410. }
  1411. Vector<AddOption> custom_options;
  1412. Vector<AddOption> embedded_options;
  1413. static Vector<String> type_filter_exceptions;
  1414. if (type_filter_exceptions.is_empty()) {
  1415. type_filter_exceptions.append("VisualShaderNodeExpression");
  1416. }
  1417. for (int i = 0; i < add_options.size(); i++) {
  1418. if (!use_filter || add_options[i].name.findn(filter) != -1) {
  1419. // port type filtering
  1420. if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX || members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1421. Ref<VisualShaderNode> vsn;
  1422. int check_result = 0;
  1423. if (!add_options[i].is_custom) {
  1424. vsn = Ref<VisualShaderNode>(Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[i].type)));
  1425. if (!vsn.is_valid()) {
  1426. continue;
  1427. }
  1428. if (type_filter_exceptions.has(add_options[i].type)) {
  1429. check_result = 1;
  1430. }
  1431. Ref<VisualShaderNodeInput> input = Object::cast_to<VisualShaderNodeInput>(vsn.ptr());
  1432. if (input.is_valid()) {
  1433. input->set_shader_mode(visual_shader->get_mode());
  1434. input->set_shader_type(visual_shader->get_shader_type());
  1435. if (!add_options[i].ops.is_empty() && add_options[i].ops[0].get_type() == Variant::STRING) {
  1436. input->set_input_name((String)add_options[i].ops[0]);
  1437. }
  1438. }
  1439. Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(vsn.ptr());
  1440. if (expression.is_valid()) {
  1441. if (members_input_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) {
  1442. check_result = -1; // expressions creates a port with required type automatically (except for sampler output)
  1443. }
  1444. }
  1445. Ref<VisualShaderNodeParameterRef> parameter_ref = Object::cast_to<VisualShaderNodeParameterRef>(vsn.ptr());
  1446. if (parameter_ref.is_valid()) {
  1447. check_result = -1;
  1448. if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1449. for (int j = 0; j < parameter_ref->get_parameters_count(); j++) {
  1450. if (visual_shader->is_port_types_compatible(parameter_ref->get_port_type_by_index(j), members_input_port_type)) {
  1451. check_result = 1;
  1452. break;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. } else {
  1458. check_result = 1;
  1459. }
  1460. if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1461. if (check_result == 0) {
  1462. for (int j = 0; j < vsn->get_input_port_count(); j++) {
  1463. if (visual_shader->is_port_types_compatible(vsn->get_input_port_type(j), members_output_port_type)) {
  1464. check_result = 1;
  1465. break;
  1466. }
  1467. }
  1468. }
  1469. if (check_result != 1) {
  1470. continue;
  1471. }
  1472. }
  1473. if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1474. if (check_result == 0) {
  1475. for (int j = 0; j < vsn->get_output_port_count(); j++) {
  1476. if (visual_shader->is_port_types_compatible(vsn->get_output_port_type(j), members_input_port_type)) {
  1477. check_result = 1;
  1478. break;
  1479. }
  1480. }
  1481. }
  1482. if (check_result != 1) {
  1483. continue;
  1484. }
  1485. }
  1486. }
  1487. if ((add_options[i].func != current_func && add_options[i].func != -1) || !_is_available(add_options[i].mode)) {
  1488. continue;
  1489. }
  1490. const_cast<AddOption &>(add_options[i]).temp_idx = i; // save valid id
  1491. if (add_options[i].is_custom) {
  1492. custom_options.push_back(add_options[i]);
  1493. } else {
  1494. embedded_options.push_back(add_options[i]);
  1495. }
  1496. }
  1497. }
  1498. Vector<AddOption> options;
  1499. SortArray<AddOption, _OptionComparator> sorter;
  1500. sorter.sort(custom_options.ptrw(), custom_options.size());
  1501. options.append_array(custom_options);
  1502. options.append_array(embedded_options);
  1503. for (int i = 0; i < options.size(); i++) {
  1504. String path = options[i].category;
  1505. Vector<String> subfolders = path.split("/");
  1506. TreeItem *category = nullptr;
  1507. if (!folders.has(path)) {
  1508. category = root;
  1509. String path_temp = "";
  1510. for (int j = 0; j < subfolders.size(); j++) {
  1511. path_temp += subfolders[j];
  1512. if (!folders.has(path_temp)) {
  1513. category = members->create_item(category);
  1514. category->set_selectable(0, false);
  1515. category->set_collapsed(!use_filter);
  1516. category->set_text(0, subfolders[j]);
  1517. folders.insert(path_temp, category);
  1518. } else {
  1519. category = folders[path_temp];
  1520. }
  1521. }
  1522. } else {
  1523. category = folders[path];
  1524. }
  1525. TreeItem *item = members->create_item(category);
  1526. if (options[i].highend && low_driver) {
  1527. item->set_custom_color(0, unsupported_color);
  1528. } else if (options[i].highend) {
  1529. item->set_custom_color(0, supported_color);
  1530. }
  1531. item->set_text(0, options[i].name);
  1532. if (is_first_item && use_filter) {
  1533. item->select(0);
  1534. node_desc->set_text(options[i].description);
  1535. is_first_item = false;
  1536. }
  1537. switch (options[i].return_type) {
  1538. case VisualShaderNode::PORT_TYPE_SCALAR:
  1539. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("float"), SNAME("EditorIcons")));
  1540. break;
  1541. case VisualShaderNode::PORT_TYPE_SCALAR_INT:
  1542. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("int"), SNAME("EditorIcons")));
  1543. break;
  1544. case VisualShaderNode::PORT_TYPE_SCALAR_UINT:
  1545. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("uint"), SNAME("EditorIcons")));
  1546. break;
  1547. case VisualShaderNode::PORT_TYPE_VECTOR_2D:
  1548. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")));
  1549. break;
  1550. case VisualShaderNode::PORT_TYPE_VECTOR_3D:
  1551. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")));
  1552. break;
  1553. case VisualShaderNode::PORT_TYPE_VECTOR_4D:
  1554. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector4"), SNAME("EditorIcons")));
  1555. break;
  1556. case VisualShaderNode::PORT_TYPE_BOOLEAN:
  1557. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("bool"), SNAME("EditorIcons")));
  1558. break;
  1559. case VisualShaderNode::PORT_TYPE_TRANSFORM:
  1560. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")));
  1561. break;
  1562. case VisualShaderNode::PORT_TYPE_SAMPLER:
  1563. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons")));
  1564. break;
  1565. default:
  1566. break;
  1567. }
  1568. item->set_meta("id", options[i].temp_idx);
  1569. }
  1570. }
  1571. void VisualShaderEditor::_set_mode(int p_which) {
  1572. if (p_which == VisualShader::MODE_SKY) {
  1573. edit_type_standard->set_visible(false);
  1574. edit_type_particles->set_visible(false);
  1575. edit_type_sky->set_visible(true);
  1576. edit_type_fog->set_visible(false);
  1577. edit_type = edit_type_sky;
  1578. custom_mode_box->set_visible(false);
  1579. varying_button->hide();
  1580. mode = MODE_FLAGS_SKY;
  1581. } else if (p_which == VisualShader::MODE_FOG) {
  1582. edit_type_standard->set_visible(false);
  1583. edit_type_particles->set_visible(false);
  1584. edit_type_sky->set_visible(false);
  1585. edit_type_fog->set_visible(true);
  1586. edit_type = edit_type_fog;
  1587. custom_mode_box->set_visible(false);
  1588. varying_button->hide();
  1589. mode = MODE_FLAGS_FOG;
  1590. } else if (p_which == VisualShader::MODE_PARTICLES) {
  1591. edit_type_standard->set_visible(false);
  1592. edit_type_particles->set_visible(true);
  1593. edit_type_sky->set_visible(false);
  1594. edit_type_fog->set_visible(false);
  1595. edit_type = edit_type_particles;
  1596. if ((edit_type->get_selected() + 3) > VisualShader::TYPE_PROCESS) {
  1597. custom_mode_box->set_visible(false);
  1598. } else {
  1599. custom_mode_box->set_visible(true);
  1600. }
  1601. varying_button->hide();
  1602. mode = MODE_FLAGS_PARTICLES;
  1603. } else {
  1604. edit_type_particles->set_visible(false);
  1605. edit_type_standard->set_visible(true);
  1606. edit_type_sky->set_visible(false);
  1607. edit_type_fog->set_visible(false);
  1608. edit_type = edit_type_standard;
  1609. custom_mode_box->set_visible(false);
  1610. varying_button->show();
  1611. mode = MODE_FLAGS_SPATIAL_CANVASITEM;
  1612. }
  1613. visual_shader->set_shader_type(get_current_shader_type());
  1614. }
  1615. Size2 VisualShaderEditor::get_minimum_size() const {
  1616. return Size2(10, 200);
  1617. }
  1618. void VisualShaderEditor::_draw_color_over_button(Object *obj, Color p_color) {
  1619. Button *button = Object::cast_to<Button>(obj);
  1620. if (!button) {
  1621. return;
  1622. }
  1623. Ref<StyleBox> normal = get_theme_stylebox(SNAME("normal"), SNAME("Button"));
  1624. button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
  1625. }
  1626. void VisualShaderEditor::_update_created_node(GraphNode *node) {
  1627. const Ref<StyleBoxFlat> sb = node->get_theme_stylebox(SNAME("frame"), SNAME("GraphNode"));
  1628. Color c = sb->get_border_color();
  1629. const Color mono_color = ((c.r + c.g + c.b) / 3) < 0.7 ? Color(1.0, 1.0, 1.0, 0.85) : Color(0.0, 0.0, 0.0, 0.85);
  1630. c = mono_color;
  1631. node->add_theme_color_override("title_color", c);
  1632. c.a = 0.7;
  1633. node->add_theme_color_override("close_color", c);
  1634. node->add_theme_color_override("resizer_color", c);
  1635. }
  1636. void VisualShaderEditor::_update_parameters(bool p_update_refs) {
  1637. VisualShaderNodeParameterRef::clear_parameters(visual_shader->get_rid());
  1638. for (int t = 0; t < VisualShader::TYPE_MAX; t++) {
  1639. Vector<int> tnodes = visual_shader->get_node_list((VisualShader::Type)t);
  1640. for (int i = 0; i < tnodes.size(); i++) {
  1641. Ref<VisualShaderNode> vsnode = visual_shader->get_node((VisualShader::Type)t, tnodes[i]);
  1642. Ref<VisualShaderNodeParameter> parameter = vsnode;
  1643. if (parameter.is_valid()) {
  1644. Ref<VisualShaderNodeFloatParameter> float_parameter = vsnode;
  1645. Ref<VisualShaderNodeIntParameter> int_parameter = vsnode;
  1646. Ref<VisualShaderNodeUIntParameter> uint_parameter = vsnode;
  1647. Ref<VisualShaderNodeVec2Parameter> vec2_parameter = vsnode;
  1648. Ref<VisualShaderNodeVec3Parameter> vec3_parameter = vsnode;
  1649. Ref<VisualShaderNodeVec4Parameter> vec4_parameter = vsnode;
  1650. Ref<VisualShaderNodeColorParameter> color_parameter = vsnode;
  1651. Ref<VisualShaderNodeBooleanParameter> boolean_parameter = vsnode;
  1652. Ref<VisualShaderNodeTransformParameter> transform_parameter = vsnode;
  1653. VisualShaderNodeParameterRef::ParameterType parameter_type;
  1654. if (float_parameter.is_valid()) {
  1655. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_FLOAT;
  1656. } else if (int_parameter.is_valid()) {
  1657. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_INT;
  1658. } else if (uint_parameter.is_valid()) {
  1659. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_UINT;
  1660. } else if (boolean_parameter.is_valid()) {
  1661. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_BOOLEAN;
  1662. } else if (vec2_parameter.is_valid()) {
  1663. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR2;
  1664. } else if (vec3_parameter.is_valid()) {
  1665. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR3;
  1666. } else if (vec4_parameter.is_valid()) {
  1667. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR4;
  1668. } else if (transform_parameter.is_valid()) {
  1669. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_TRANSFORM;
  1670. } else if (color_parameter.is_valid()) {
  1671. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_COLOR;
  1672. } else {
  1673. parameter_type = VisualShaderNodeParameterRef::UNIFORM_TYPE_SAMPLER;
  1674. }
  1675. VisualShaderNodeParameterRef::add_parameter(visual_shader->get_rid(), parameter->get_parameter_name(), parameter_type);
  1676. }
  1677. }
  1678. }
  1679. if (p_update_refs) {
  1680. graph_plugin->update_parameter_refs();
  1681. }
  1682. }
  1683. void VisualShaderEditor::_update_parameter_refs(HashSet<String> &p_deleted_names) {
  1684. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1685. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  1686. VisualShader::Type type = VisualShader::Type(i);
  1687. Vector<int> nodes = visual_shader->get_node_list(type);
  1688. for (int j = 0; j < nodes.size(); j++) {
  1689. if (j > 0) {
  1690. Ref<VisualShaderNodeParameterRef> ref = visual_shader->get_node(type, nodes[j]);
  1691. if (ref.is_valid()) {
  1692. if (p_deleted_names.has(ref->get_parameter_name())) {
  1693. undo_redo->add_do_method(ref.ptr(), "set_parameter_name", "[None]");
  1694. undo_redo->add_undo_method(ref.ptr(), "set_parameter_name", ref->get_parameter_name());
  1695. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", VisualShader::Type(i), nodes[j]);
  1696. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", VisualShader::Type(i), nodes[j]);
  1697. }
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. void VisualShaderEditor::_update_graph() {
  1704. if (updating) {
  1705. return;
  1706. }
  1707. if (visual_shader.is_null()) {
  1708. return;
  1709. }
  1710. graph->set_scroll_ofs(visual_shader->get_graph_offset() * EDSCALE);
  1711. VisualShader::Type type = get_current_shader_type();
  1712. graph->clear_connections();
  1713. //erase all nodes
  1714. for (int i = 0; i < graph->get_child_count(); i++) {
  1715. if (Object::cast_to<GraphNode>(graph->get_child(i))) {
  1716. Node *node = graph->get_child(i);
  1717. graph->remove_child(node);
  1718. memdelete(node);
  1719. i--;
  1720. }
  1721. }
  1722. List<VisualShader::Connection> node_connections;
  1723. visual_shader->get_node_connections(type, &node_connections);
  1724. graph_plugin->set_connections(node_connections);
  1725. Vector<int> nodes = visual_shader->get_node_list(type);
  1726. _update_parameters(false);
  1727. _update_varyings();
  1728. graph_plugin->clear_links();
  1729. graph_plugin->update_theme();
  1730. for (int n_i = 0; n_i < nodes.size(); n_i++) {
  1731. graph_plugin->add_node(type, nodes[n_i], false);
  1732. }
  1733. for (const VisualShader::Connection &E : node_connections) {
  1734. int from = E.from_node;
  1735. int from_idx = E.from_port;
  1736. int to = E.to_node;
  1737. int to_idx = E.to_port;
  1738. graph->connect_node(itos(from), from_idx, itos(to), to_idx);
  1739. }
  1740. float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity");
  1741. graph->set_minimap_opacity(graph_minimap_opacity);
  1742. float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature");
  1743. graph->set_connection_lines_curvature(graph_lines_curvature);
  1744. }
  1745. VisualShader::Type VisualShaderEditor::get_current_shader_type() const {
  1746. VisualShader::Type type;
  1747. if (mode & MODE_FLAGS_PARTICLES) {
  1748. type = VisualShader::Type(edit_type->get_selected() + 3 + (custom_mode_enabled ? 3 : 0));
  1749. } else if (mode & MODE_FLAGS_SKY) {
  1750. type = VisualShader::Type(edit_type->get_selected() + 8);
  1751. } else if (mode & MODE_FLAGS_FOG) {
  1752. type = VisualShader::Type(edit_type->get_selected() + 9);
  1753. } else {
  1754. type = VisualShader::Type(edit_type->get_selected());
  1755. }
  1756. return type;
  1757. }
  1758. void VisualShaderEditor::_add_input_port(int p_node, int p_port, int p_port_type, const String &p_name) {
  1759. VisualShader::Type type = get_current_shader_type();
  1760. Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node);
  1761. if (node.is_null()) {
  1762. return;
  1763. }
  1764. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1765. undo_redo->create_action(TTR("Add Input Port"));
  1766. undo_redo->add_do_method(node.ptr(), "add_input_port", p_port, p_port_type, p_name);
  1767. undo_redo->add_undo_method(node.ptr(), "remove_input_port", p_port);
  1768. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  1769. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  1770. undo_redo->commit_action();
  1771. }
  1772. void VisualShaderEditor::_add_output_port(int p_node, int p_port, int p_port_type, const String &p_name) {
  1773. VisualShader::Type type = get_current_shader_type();
  1774. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  1775. if (node.is_null()) {
  1776. return;
  1777. }
  1778. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1779. undo_redo->create_action(TTR("Add Output Port"));
  1780. undo_redo->add_do_method(node.ptr(), "add_output_port", p_port, p_port_type, p_name);
  1781. undo_redo->add_undo_method(node.ptr(), "remove_output_port", p_port);
  1782. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  1783. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  1784. undo_redo->commit_action();
  1785. }
  1786. void VisualShaderEditor::_change_input_port_type(int p_type, int p_node, int p_port) {
  1787. VisualShader::Type type = get_current_shader_type();
  1788. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  1789. if (node.is_null()) {
  1790. return;
  1791. }
  1792. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1793. undo_redo->create_action(TTR("Change Input Port Type"));
  1794. undo_redo->add_do_method(node.ptr(), "set_input_port_type", p_port, p_type);
  1795. undo_redo->add_undo_method(node.ptr(), "set_input_port_type", p_port, node->get_input_port_type(p_port));
  1796. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  1797. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  1798. undo_redo->commit_action();
  1799. }
  1800. void VisualShaderEditor::_change_output_port_type(int p_type, int p_node, int p_port) {
  1801. VisualShader::Type type = get_current_shader_type();
  1802. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  1803. if (node.is_null()) {
  1804. return;
  1805. }
  1806. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1807. undo_redo->create_action(TTR("Change Output Port Type"));
  1808. undo_redo->add_do_method(node.ptr(), "set_output_port_type", p_port, p_type);
  1809. undo_redo->add_undo_method(node.ptr(), "set_output_port_type", p_port, node->get_output_port_type(p_port));
  1810. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  1811. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  1812. undo_redo->commit_action();
  1813. }
  1814. void VisualShaderEditor::_change_input_port_name(const String &p_text, Object *p_line_edit, int p_node_id, int p_port_id) {
  1815. VisualShader::Type type = get_current_shader_type();
  1816. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  1817. ERR_FAIL_COND(!node.is_valid());
  1818. String prev_name = node->get_input_port_name(p_port_id);
  1819. if (prev_name == p_text) {
  1820. return;
  1821. }
  1822. LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
  1823. ERR_FAIL_COND(!line_edit);
  1824. String validated_name = visual_shader->validate_port_name(p_text, node.ptr(), p_port_id, false);
  1825. if (validated_name.is_empty() || prev_name == validated_name) {
  1826. line_edit->set_text(node->get_input_port_name(p_port_id));
  1827. return;
  1828. }
  1829. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1830. undo_redo->create_action(TTR("Change Input Port Name"));
  1831. undo_redo->add_do_method(node.ptr(), "set_input_port_name", p_port_id, validated_name);
  1832. undo_redo->add_undo_method(node.ptr(), "set_input_port_name", p_port_id, node->get_input_port_name(p_port_id));
  1833. undo_redo->commit_action();
  1834. }
  1835. void VisualShaderEditor::_change_output_port_name(const String &p_text, Object *p_line_edit, int p_node_id, int p_port_id) {
  1836. VisualShader::Type type = get_current_shader_type();
  1837. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  1838. ERR_FAIL_COND(!node.is_valid());
  1839. String prev_name = node->get_output_port_name(p_port_id);
  1840. if (prev_name == p_text) {
  1841. return;
  1842. }
  1843. LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
  1844. ERR_FAIL_COND(!line_edit);
  1845. String validated_name = visual_shader->validate_port_name(p_text, node.ptr(), p_port_id, true);
  1846. if (validated_name.is_empty() || prev_name == validated_name) {
  1847. line_edit->set_text(node->get_output_port_name(p_port_id));
  1848. return;
  1849. }
  1850. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1851. undo_redo->create_action(TTR("Change Output Port Name"));
  1852. undo_redo->add_do_method(node.ptr(), "set_output_port_name", p_port_id, validated_name);
  1853. undo_redo->add_undo_method(node.ptr(), "set_output_port_name", p_port_id, prev_name);
  1854. undo_redo->commit_action();
  1855. }
  1856. void VisualShaderEditor::_expand_output_port(int p_node, int p_port, bool p_expand) {
  1857. VisualShader::Type type = get_current_shader_type();
  1858. Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
  1859. ERR_FAIL_COND(!node.is_valid());
  1860. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1861. if (p_expand) {
  1862. undo_redo->create_action(TTR("Expand Output Port"));
  1863. } else {
  1864. undo_redo->create_action(TTR("Shrink Output Port"));
  1865. }
  1866. undo_redo->add_do_method(node.ptr(), "_set_output_port_expanded", p_port, p_expand);
  1867. undo_redo->add_undo_method(node.ptr(), "_set_output_port_expanded", p_port, !p_expand);
  1868. int type_size = 0;
  1869. switch (node->get_output_port_type(p_port)) {
  1870. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  1871. type_size = 2;
  1872. } break;
  1873. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  1874. type_size = 3;
  1875. } break;
  1876. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  1877. type_size = 4;
  1878. } break;
  1879. default:
  1880. break;
  1881. }
  1882. List<VisualShader::Connection> conns;
  1883. visual_shader->get_node_connections(type, &conns);
  1884. for (const VisualShader::Connection &E : conns) {
  1885. int cn_from_node = E.from_node;
  1886. int cn_from_port = E.from_port;
  1887. int cn_to_node = E.to_node;
  1888. int cn_to_port = E.to_port;
  1889. if (cn_from_node == p_node) {
  1890. if (p_expand) {
  1891. if (cn_from_port > p_port) { // reconnect ports after expanded ports
  1892. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1893. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1894. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1895. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1896. 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);
  1897. 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);
  1898. 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);
  1899. 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);
  1900. }
  1901. } else {
  1902. if (cn_from_port > p_port + type_size) { // reconnect ports after expanded ports
  1903. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1904. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1905. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1906. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1907. 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);
  1908. 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);
  1909. 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);
  1910. 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);
  1911. } else if (cn_from_port > p_port) { // disconnect component ports
  1912. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1913. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1914. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1915. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1916. }
  1917. }
  1918. }
  1919. }
  1920. int preview_port = node->get_output_port_for_preview();
  1921. if (p_expand) {
  1922. if (preview_port > p_port) {
  1923. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port + type_size);
  1924. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  1925. }
  1926. } else {
  1927. if (preview_port > p_port + type_size) {
  1928. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - type_size);
  1929. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  1930. }
  1931. }
  1932. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  1933. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  1934. undo_redo->commit_action();
  1935. }
  1936. void VisualShaderEditor::_remove_input_port(int p_node, int p_port) {
  1937. VisualShader::Type type = get_current_shader_type();
  1938. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  1939. if (node.is_null()) {
  1940. return;
  1941. }
  1942. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1943. undo_redo->create_action(TTR("Remove Input Port"));
  1944. List<VisualShader::Connection> conns;
  1945. visual_shader->get_node_connections(type, &conns);
  1946. for (const VisualShader::Connection &E : conns) {
  1947. int cn_from_node = E.from_node;
  1948. int cn_from_port = E.from_port;
  1949. int cn_to_node = E.to_node;
  1950. int cn_to_port = E.to_port;
  1951. if (cn_to_node == p_node) {
  1952. if (cn_to_port == p_port) {
  1953. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1954. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1955. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1956. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1957. } else if (cn_to_port > p_port) {
  1958. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1959. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1960. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1961. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1962. 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);
  1963. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  1964. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  1965. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  1966. }
  1967. }
  1968. }
  1969. undo_redo->add_do_method(node.ptr(), "remove_input_port", p_port);
  1970. 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));
  1971. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  1972. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  1973. undo_redo->commit_action();
  1974. }
  1975. void VisualShaderEditor::_remove_output_port(int p_node, int p_port) {
  1976. VisualShader::Type type = get_current_shader_type();
  1977. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  1978. if (node.is_null()) {
  1979. return;
  1980. }
  1981. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1982. undo_redo->create_action(TTR("Remove Output Port"));
  1983. List<VisualShader::Connection> conns;
  1984. visual_shader->get_node_connections(type, &conns);
  1985. for (const VisualShader::Connection &E : conns) {
  1986. int cn_from_node = E.from_node;
  1987. int cn_from_port = E.from_port;
  1988. int cn_to_node = E.to_node;
  1989. int cn_to_port = E.to_port;
  1990. if (cn_from_node == p_node) {
  1991. if (cn_from_port == p_port) {
  1992. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1993. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1994. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1995. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1996. } else if (cn_from_port > p_port) {
  1997. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1998. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  1999. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2000. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2001. 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);
  2002. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2003. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2004. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2005. }
  2006. }
  2007. }
  2008. int preview_port = node->get_output_port_for_preview();
  2009. if (preview_port != -1) {
  2010. if (preview_port == p_port) {
  2011. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", -1);
  2012. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2013. } else if (preview_port > p_port) {
  2014. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - 1);
  2015. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2016. }
  2017. }
  2018. undo_redo->add_do_method(node.ptr(), "remove_output_port", p_port);
  2019. 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));
  2020. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2021. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2022. undo_redo->commit_action();
  2023. }
  2024. void VisualShaderEditor::_expression_focus_out(Object *code_edit, int p_node) {
  2025. VisualShader::Type type = get_current_shader_type();
  2026. Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node);
  2027. if (node.is_null()) {
  2028. return;
  2029. }
  2030. CodeEdit *expression_box = Object::cast_to<CodeEdit>(code_edit);
  2031. if (node->get_expression() == expression_box->get_text()) {
  2032. return;
  2033. }
  2034. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2035. undo_redo->create_action(TTR("Set VisualShader Expression"));
  2036. undo_redo->add_do_method(node.ptr(), "set_expression", expression_box->get_text());
  2037. undo_redo->add_undo_method(node.ptr(), "set_expression", node->get_expression());
  2038. undo_redo->add_do_method(graph_plugin.ptr(), "set_expression", type, p_node, expression_box->get_text());
  2039. undo_redo->add_undo_method(graph_plugin.ptr(), "set_expression", type, p_node, node->get_expression());
  2040. undo_redo->commit_action();
  2041. }
  2042. void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p_size) {
  2043. VisualShader::Type type = VisualShader::Type(p_type);
  2044. Ref<VisualShaderNodeResizableBase> node = visual_shader->get_node(type, p_node);
  2045. if (node.is_null()) {
  2046. return;
  2047. }
  2048. Size2 size = p_size;
  2049. if (!node->is_allow_v_resize()) {
  2050. size.y = 0;
  2051. }
  2052. node->set_size(size);
  2053. if (get_current_shader_type() == type) {
  2054. Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  2055. Control *text_box = nullptr;
  2056. if (!expression_node.is_null()) {
  2057. text_box = expression_node->is_ctrl_pressed(0);
  2058. if (text_box) {
  2059. text_box->set_custom_minimum_size(Size2(0, 0));
  2060. }
  2061. }
  2062. GraphNode *gn = nullptr;
  2063. Node *node2 = graph->get_node(itos(p_node));
  2064. gn = Object::cast_to<GraphNode>(node2);
  2065. if (!gn) {
  2066. return;
  2067. }
  2068. gn->set_custom_minimum_size(size);
  2069. gn->reset_size();
  2070. if (!expression_node.is_null() && text_box) {
  2071. Size2 box_size = size;
  2072. if (box_size.x < 150 * EDSCALE || box_size.y < 0) {
  2073. box_size.x = gn->get_size().x;
  2074. }
  2075. box_size.x -= text_box->get_offset(SIDE_LEFT);
  2076. box_size.x -= 28 * EDSCALE;
  2077. box_size.y -= text_box->get_offset(SIDE_TOP);
  2078. box_size.y -= 28 * EDSCALE;
  2079. text_box->set_custom_minimum_size(box_size);
  2080. text_box->reset_size();
  2081. }
  2082. }
  2083. }
  2084. void VisualShaderEditor::_node_resized(const Vector2 &p_new_size, int p_type, int p_node) {
  2085. Ref<VisualShaderNodeResizableBase> node = visual_shader->get_node(VisualShader::Type(p_type), p_node);
  2086. if (node.is_null()) {
  2087. return;
  2088. }
  2089. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2090. undo_redo->create_action(TTR("Resize VisualShader Node"), UndoRedo::MERGE_ENDS);
  2091. undo_redo->add_do_method(this, "_set_node_size", p_type, p_node, p_new_size);
  2092. undo_redo->add_undo_method(this, "_set_node_size", p_type, p_node, node->get_size());
  2093. undo_redo->commit_action();
  2094. }
  2095. void VisualShaderEditor::_preview_select_port(int p_node, int p_port) {
  2096. VisualShader::Type type = get_current_shader_type();
  2097. Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
  2098. if (node.is_null()) {
  2099. return;
  2100. }
  2101. int prev_port = node->get_output_port_for_preview();
  2102. if (node->get_output_port_for_preview() == p_port) {
  2103. p_port = -1; //toggle it
  2104. }
  2105. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2106. undo_redo->create_action(p_port == -1 ? TTR("Hide Port Preview") : TTR("Show Port Preview"));
  2107. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", p_port);
  2108. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", prev_port);
  2109. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, p_node);
  2110. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, p_node);
  2111. undo_redo->commit_action();
  2112. }
  2113. void VisualShaderEditor::_comment_title_popup_show(const Point2 &p_position, int p_node_id) {
  2114. VisualShader::Type type = get_current_shader_type();
  2115. Ref<VisualShaderNodeComment> node = visual_shader->get_node(type, p_node_id);
  2116. if (node.is_null()) {
  2117. return;
  2118. }
  2119. comment_title_change_edit->set_text(node->get_title());
  2120. comment_title_change_popup->set_meta("id", p_node_id);
  2121. comment_title_change_popup->popup();
  2122. comment_title_change_popup->set_position(p_position);
  2123. }
  2124. void VisualShaderEditor::_comment_title_text_changed(const String &p_new_text) {
  2125. comment_title_change_edit->reset_size();
  2126. comment_title_change_popup->reset_size();
  2127. }
  2128. void VisualShaderEditor::_comment_title_text_submitted(const String &p_new_text) {
  2129. comment_title_change_popup->hide();
  2130. }
  2131. void VisualShaderEditor::_comment_title_popup_focus_out() {
  2132. comment_title_change_popup->hide();
  2133. }
  2134. void VisualShaderEditor::_comment_title_popup_hide() {
  2135. ERR_FAIL_COND(!comment_title_change_popup->has_meta("id"));
  2136. int node_id = (int)comment_title_change_popup->get_meta("id");
  2137. VisualShader::Type type = get_current_shader_type();
  2138. Ref<VisualShaderNodeComment> node = visual_shader->get_node(type, node_id);
  2139. ERR_FAIL_COND(node.is_null());
  2140. if (node->get_title() == comment_title_change_edit->get_text()) {
  2141. return; // nothing changed - ignored
  2142. }
  2143. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2144. undo_redo->create_action(TTR("Set Comment Node Title"));
  2145. undo_redo->add_do_method(node.ptr(), "set_title", comment_title_change_edit->get_text());
  2146. undo_redo->add_undo_method(node.ptr(), "set_title", node->get_title());
  2147. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, node_id);
  2148. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, node_id);
  2149. undo_redo->commit_action();
  2150. }
  2151. void VisualShaderEditor::_comment_desc_popup_show(const Point2 &p_position, int p_node_id) {
  2152. VisualShader::Type type = get_current_shader_type();
  2153. Ref<VisualShaderNodeComment> node = visual_shader->get_node(type, p_node_id);
  2154. if (node.is_null()) {
  2155. return;
  2156. }
  2157. comment_desc_change_edit->set_text(node->get_description());
  2158. comment_desc_change_popup->set_meta("id", p_node_id);
  2159. comment_desc_change_popup->reset_size();
  2160. comment_desc_change_popup->popup();
  2161. comment_desc_change_popup->set_position(p_position);
  2162. }
  2163. void VisualShaderEditor::_comment_desc_text_changed() {
  2164. comment_desc_change_edit->reset_size();
  2165. comment_desc_change_popup->reset_size();
  2166. }
  2167. void VisualShaderEditor::_comment_desc_confirm() {
  2168. comment_desc_change_popup->hide();
  2169. }
  2170. void VisualShaderEditor::_comment_desc_popup_hide() {
  2171. ERR_FAIL_COND(!comment_desc_change_popup->has_meta("id"));
  2172. int node_id = (int)comment_desc_change_popup->get_meta("id");
  2173. VisualShader::Type type = get_current_shader_type();
  2174. Ref<VisualShaderNodeComment> node = visual_shader->get_node(type, node_id);
  2175. ERR_FAIL_COND(node.is_null());
  2176. if (node->get_description() == comment_desc_change_edit->get_text()) {
  2177. return; // nothing changed - ignored
  2178. }
  2179. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2180. undo_redo->create_action(TTR("Set Comment Node Description"));
  2181. undo_redo->add_do_method(node.ptr(), "set_description", comment_desc_change_edit->get_text());
  2182. undo_redo->add_undo_method(node.ptr(), "set_description", node->get_title());
  2183. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, node_id);
  2184. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, node_id);
  2185. undo_redo->commit_action();
  2186. }
  2187. void VisualShaderEditor::_parameter_line_edit_changed(const String &p_text, int p_node_id) {
  2188. VisualShader::Type type = get_current_shader_type();
  2189. Ref<VisualShaderNodeParameter> node = visual_shader->get_node(type, p_node_id);
  2190. ERR_FAIL_COND(!node.is_valid());
  2191. String validated_name = visual_shader->validate_parameter_name(p_text, node);
  2192. if (validated_name == node->get_parameter_name()) {
  2193. return;
  2194. }
  2195. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2196. undo_redo->create_action(TTR("Set Parameter Name"));
  2197. undo_redo->add_do_method(node.ptr(), "set_parameter_name", validated_name);
  2198. undo_redo->add_undo_method(node.ptr(), "set_parameter_name", node->get_parameter_name());
  2199. undo_redo->add_do_method(graph_plugin.ptr(), "set_parameter_name", type, p_node_id, validated_name);
  2200. undo_redo->add_undo_method(graph_plugin.ptr(), "set_parameter_name", type, p_node_id, node->get_parameter_name());
  2201. undo_redo->add_do_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id);
  2202. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id);
  2203. undo_redo->add_do_method(this, "_update_parameters", true);
  2204. undo_redo->add_undo_method(this, "_update_parameters", true);
  2205. HashSet<String> changed_names;
  2206. changed_names.insert(node->get_parameter_name());
  2207. _update_parameter_refs(changed_names);
  2208. undo_redo->commit_action();
  2209. }
  2210. void VisualShaderEditor::_parameter_line_edit_focus_out(Object *line_edit, int p_node_id) {
  2211. _parameter_line_edit_changed(Object::cast_to<LineEdit>(line_edit)->get_text(), p_node_id);
  2212. }
  2213. void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output) {
  2214. if (!p_output) {
  2215. _change_input_port_name(Object::cast_to<LineEdit>(line_edit)->get_text(), line_edit, p_node_id, p_port_id);
  2216. } else {
  2217. _change_output_port_name(Object::cast_to<LineEdit>(line_edit)->get_text(), line_edit, p_node_id, p_port_id);
  2218. }
  2219. }
  2220. void VisualShaderEditor::_port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
  2221. VisualShader::Type type = get_current_shader_type();
  2222. Ref<VisualShaderNode> vsn = visual_shader->get_node(type, editing_node);
  2223. ERR_FAIL_COND(!vsn.is_valid());
  2224. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2225. undo_redo->create_action(TTR("Set Input Default Port"));
  2226. Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(vsn.ptr());
  2227. if (custom.is_valid()) {
  2228. undo_redo->add_do_method(custom.ptr(), "_set_input_port_default_value", editing_port, p_value);
  2229. undo_redo->add_undo_method(custom.ptr(), "_set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
  2230. } else {
  2231. undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, p_value);
  2232. undo_redo->add_undo_method(vsn.ptr(), "set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
  2233. }
  2234. undo_redo->add_do_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, p_value);
  2235. 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));
  2236. undo_redo->commit_action();
  2237. }
  2238. void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, int p_port) {
  2239. VisualShader::Type type = get_current_shader_type();
  2240. Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, p_node);
  2241. Variant value = vs_node->get_input_port_default_value(p_port);
  2242. edited_property_holder->set_edited_property(value);
  2243. if (property_editor) {
  2244. property_editor->disconnect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
  2245. property_editor_popup->remove_child(property_editor);
  2246. }
  2247. // TODO: Define these properties with actual PropertyInfo and feed it to the property editor widget.
  2248. property_editor = EditorInspector::instantiate_property_editor(edited_property_holder.ptr(), value.get_type(), "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE);
  2249. if (property_editor) {
  2250. property_editor->set_object_and_property(edited_property_holder.ptr(), "edited_property");
  2251. property_editor->update_property();
  2252. property_editor->set_name_split_ratio(0);
  2253. property_editor_popup->add_child(property_editor);
  2254. property_editor->connect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
  2255. Button *button = Object::cast_to<Button>(p_button);
  2256. if (button) {
  2257. property_editor_popup->set_position(button->get_screen_position() + Vector2(0, button->get_size().height) * graph->get_zoom());
  2258. }
  2259. property_editor_popup->reset_size();
  2260. if (button) {
  2261. property_editor_popup->popup();
  2262. } else {
  2263. property_editor_popup->popup_centered_ratio();
  2264. }
  2265. }
  2266. editing_node = p_node;
  2267. editing_port = p_port;
  2268. }
  2269. void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops) {
  2270. // INPUT
  2271. {
  2272. VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(p_node);
  2273. if (input) {
  2274. ERR_FAIL_COND(p_ops[0].get_type() != Variant::STRING);
  2275. input->set_input_name((String)p_ops[0]);
  2276. return;
  2277. }
  2278. }
  2279. // FLOAT_CONST
  2280. {
  2281. VisualShaderNodeFloatConstant *float_const = Object::cast_to<VisualShaderNodeFloatConstant>(p_node);
  2282. if (float_const) {
  2283. ERR_FAIL_COND(p_ops[0].get_type() != Variant::FLOAT);
  2284. float_const->set_constant((float)p_ops[0]);
  2285. return;
  2286. }
  2287. }
  2288. // FLOAT_OP
  2289. {
  2290. VisualShaderNodeFloatOp *floatOp = Object::cast_to<VisualShaderNodeFloatOp>(p_node);
  2291. if (floatOp) {
  2292. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2293. floatOp->set_operator((VisualShaderNodeFloatOp::Operator)(int)p_ops[0]);
  2294. return;
  2295. }
  2296. }
  2297. // FLOAT_FUNC
  2298. {
  2299. VisualShaderNodeFloatFunc *floatFunc = Object::cast_to<VisualShaderNodeFloatFunc>(p_node);
  2300. if (floatFunc) {
  2301. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2302. floatFunc->set_function((VisualShaderNodeFloatFunc::Function)(int)p_ops[0]);
  2303. return;
  2304. }
  2305. }
  2306. // VECTOR_OP
  2307. {
  2308. VisualShaderNodeVectorOp *vecOp = Object::cast_to<VisualShaderNodeVectorOp>(p_node);
  2309. if (vecOp) {
  2310. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2311. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  2312. vecOp->set_operator((VisualShaderNodeVectorOp::Operator)(int)p_ops[0]);
  2313. vecOp->set_op_type((VisualShaderNodeVectorOp::OpType)(int)p_ops[1]);
  2314. return;
  2315. }
  2316. }
  2317. // VECTOR_FUNC
  2318. {
  2319. VisualShaderNodeVectorFunc *vecFunc = Object::cast_to<VisualShaderNodeVectorFunc>(p_node);
  2320. if (vecFunc) {
  2321. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2322. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  2323. vecFunc->set_function((VisualShaderNodeVectorFunc::Function)(int)p_ops[0]);
  2324. vecFunc->set_op_type((VisualShaderNodeVectorFunc::OpType)(int)p_ops[1]);
  2325. return;
  2326. }
  2327. }
  2328. // COLOR_OP
  2329. {
  2330. VisualShaderNodeColorOp *colorOp = Object::cast_to<VisualShaderNodeColorOp>(p_node);
  2331. if (colorOp) {
  2332. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2333. colorOp->set_operator((VisualShaderNodeColorOp::Operator)(int)p_ops[0]);
  2334. return;
  2335. }
  2336. }
  2337. // COLOR_FUNC
  2338. {
  2339. VisualShaderNodeColorFunc *colorFunc = Object::cast_to<VisualShaderNodeColorFunc>(p_node);
  2340. if (colorFunc) {
  2341. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2342. colorFunc->set_function((VisualShaderNodeColorFunc::Function)(int)p_ops[0]);
  2343. return;
  2344. }
  2345. }
  2346. // INT_OP
  2347. {
  2348. VisualShaderNodeIntOp *intOp = Object::cast_to<VisualShaderNodeIntOp>(p_node);
  2349. if (intOp) {
  2350. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2351. intOp->set_operator((VisualShaderNodeIntOp::Operator)(int)p_ops[0]);
  2352. return;
  2353. }
  2354. }
  2355. // INT_FUNC
  2356. {
  2357. VisualShaderNodeIntFunc *intFunc = Object::cast_to<VisualShaderNodeIntFunc>(p_node);
  2358. if (intFunc) {
  2359. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2360. intFunc->set_function((VisualShaderNodeIntFunc::Function)(int)p_ops[0]);
  2361. return;
  2362. }
  2363. }
  2364. // UINT_OP
  2365. {
  2366. VisualShaderNodeUIntOp *uintOp = Object::cast_to<VisualShaderNodeUIntOp>(p_node);
  2367. if (uintOp) {
  2368. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2369. uintOp->set_operator((VisualShaderNodeUIntOp::Operator)(int)p_ops[0]);
  2370. return;
  2371. }
  2372. }
  2373. // UINT_FUNC
  2374. {
  2375. VisualShaderNodeUIntFunc *uintFunc = Object::cast_to<VisualShaderNodeUIntFunc>(p_node);
  2376. if (uintFunc) {
  2377. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2378. uintFunc->set_function((VisualShaderNodeUIntFunc::Function)(int)p_ops[0]);
  2379. return;
  2380. }
  2381. }
  2382. // TRANSFORM_OP
  2383. {
  2384. VisualShaderNodeTransformOp *matOp = Object::cast_to<VisualShaderNodeTransformOp>(p_node);
  2385. if (matOp) {
  2386. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2387. matOp->set_operator((VisualShaderNodeTransformOp::Operator)(int)p_ops[0]);
  2388. return;
  2389. }
  2390. }
  2391. // TRANSFORM_FUNC
  2392. {
  2393. VisualShaderNodeTransformFunc *matFunc = Object::cast_to<VisualShaderNodeTransformFunc>(p_node);
  2394. if (matFunc) {
  2395. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2396. matFunc->set_function((VisualShaderNodeTransformFunc::Function)(int)p_ops[0]);
  2397. return;
  2398. }
  2399. }
  2400. // VECTOR_COMPOSE
  2401. {
  2402. VisualShaderNodeVectorCompose *vecCompose = Object::cast_to<VisualShaderNodeVectorCompose>(p_node);
  2403. if (vecCompose) {
  2404. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2405. vecCompose->set_op_type((VisualShaderNodeVectorCompose::OpType)(int)p_ops[0]);
  2406. return;
  2407. }
  2408. }
  2409. // VECTOR_DECOMPOSE
  2410. {
  2411. VisualShaderNodeVectorDecompose *vecDecompose = Object::cast_to<VisualShaderNodeVectorDecompose>(p_node);
  2412. if (vecDecompose) {
  2413. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2414. vecDecompose->set_op_type((VisualShaderNodeVectorDecompose::OpType)(int)p_ops[0]);
  2415. return;
  2416. }
  2417. }
  2418. // UV_FUNC
  2419. {
  2420. VisualShaderNodeUVFunc *uvFunc = Object::cast_to<VisualShaderNodeUVFunc>(p_node);
  2421. if (uvFunc) {
  2422. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2423. uvFunc->set_function((VisualShaderNodeUVFunc::Function)(int)p_ops[0]);
  2424. return;
  2425. }
  2426. }
  2427. // IS
  2428. {
  2429. VisualShaderNodeIs *is = Object::cast_to<VisualShaderNodeIs>(p_node);
  2430. if (is) {
  2431. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2432. is->set_function((VisualShaderNodeIs::Function)(int)p_ops[0]);
  2433. return;
  2434. }
  2435. }
  2436. // COMPARE
  2437. {
  2438. VisualShaderNodeCompare *cmp = Object::cast_to<VisualShaderNodeCompare>(p_node);
  2439. if (cmp) {
  2440. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2441. cmp->set_function((VisualShaderNodeCompare::Function)(int)p_ops[0]);
  2442. return;
  2443. }
  2444. }
  2445. // DISTANCE
  2446. {
  2447. VisualShaderNodeVectorDistance *dist = Object::cast_to<VisualShaderNodeVectorDistance>(p_node);
  2448. if (dist) {
  2449. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2450. dist->set_op_type((VisualShaderNodeVectorDistance::OpType)(int)p_ops[0]);
  2451. return;
  2452. }
  2453. }
  2454. // DERIVATIVE
  2455. {
  2456. VisualShaderNodeDerivativeFunc *derFunc = Object::cast_to<VisualShaderNodeDerivativeFunc>(p_node);
  2457. if (derFunc) {
  2458. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2459. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  2460. derFunc->set_function((VisualShaderNodeDerivativeFunc::Function)(int)p_ops[0]);
  2461. derFunc->set_op_type((VisualShaderNodeDerivativeFunc::OpType)(int)p_ops[1]);
  2462. return;
  2463. }
  2464. }
  2465. // MIX
  2466. {
  2467. VisualShaderNodeMix *mix = Object::cast_to<VisualShaderNodeMix>(p_node);
  2468. if (mix) {
  2469. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2470. mix->set_op_type((VisualShaderNodeMix::OpType)(int)p_ops[0]);
  2471. return;
  2472. }
  2473. }
  2474. // CLAMP
  2475. {
  2476. VisualShaderNodeClamp *clampFunc = Object::cast_to<VisualShaderNodeClamp>(p_node);
  2477. if (clampFunc) {
  2478. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2479. clampFunc->set_op_type((VisualShaderNodeClamp::OpType)(int)p_ops[0]);
  2480. return;
  2481. }
  2482. }
  2483. // SWITCH
  2484. {
  2485. VisualShaderNodeSwitch *switchFunc = Object::cast_to<VisualShaderNodeSwitch>(p_node);
  2486. if (switchFunc) {
  2487. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2488. switchFunc->set_op_type((VisualShaderNodeSwitch::OpType)(int)p_ops[0]);
  2489. return;
  2490. }
  2491. }
  2492. // FACEFORWARD
  2493. {
  2494. VisualShaderNodeFaceForward *faceForward = Object::cast_to<VisualShaderNodeFaceForward>(p_node);
  2495. if (faceForward) {
  2496. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2497. faceForward->set_op_type((VisualShaderNodeFaceForward::OpType)(int)p_ops[0]);
  2498. return;
  2499. }
  2500. }
  2501. // LENGTH
  2502. {
  2503. VisualShaderNodeVectorLen *length = Object::cast_to<VisualShaderNodeVectorLen>(p_node);
  2504. if (length) {
  2505. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2506. length->set_op_type((VisualShaderNodeVectorLen::OpType)(int)p_ops[0]);
  2507. return;
  2508. }
  2509. }
  2510. // SMOOTHSTEP
  2511. {
  2512. VisualShaderNodeSmoothStep *smoothStepFunc = Object::cast_to<VisualShaderNodeSmoothStep>(p_node);
  2513. if (smoothStepFunc) {
  2514. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2515. smoothStepFunc->set_op_type((VisualShaderNodeSmoothStep::OpType)(int)p_ops[0]);
  2516. return;
  2517. }
  2518. }
  2519. // STEP
  2520. {
  2521. VisualShaderNodeStep *stepFunc = Object::cast_to<VisualShaderNodeStep>(p_node);
  2522. if (stepFunc) {
  2523. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2524. stepFunc->set_op_type((VisualShaderNodeStep::OpType)(int)p_ops[0]);
  2525. return;
  2526. }
  2527. }
  2528. // MULTIPLY_ADD
  2529. {
  2530. VisualShaderNodeMultiplyAdd *fmaFunc = Object::cast_to<VisualShaderNodeMultiplyAdd>(p_node);
  2531. if (fmaFunc) {
  2532. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2533. fmaFunc->set_op_type((VisualShaderNodeMultiplyAdd::OpType)(int)p_ops[0]);
  2534. }
  2535. }
  2536. }
  2537. void VisualShaderEditor::_add_node(int p_idx, const Vector<Variant> &p_ops, String p_resource_path, int p_node_idx) {
  2538. ERR_FAIL_INDEX(p_idx, add_options.size());
  2539. VisualShader::Type type = get_current_shader_type();
  2540. Ref<VisualShaderNode> vsnode;
  2541. bool is_custom = add_options[p_idx].is_custom;
  2542. if (!is_custom && !add_options[p_idx].type.is_empty()) {
  2543. VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[p_idx].type));
  2544. ERR_FAIL_COND(!vsn);
  2545. if (!p_ops.is_empty()) {
  2546. _setup_node(vsn, p_ops);
  2547. }
  2548. VisualShaderNodeParameterRef *parameter_ref = Object::cast_to<VisualShaderNodeParameterRef>(vsn);
  2549. if (parameter_ref && to_node != -1 && to_slot != -1) {
  2550. VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot);
  2551. bool success = false;
  2552. for (int i = 0; i < parameter_ref->get_parameters_count(); i++) {
  2553. if (parameter_ref->get_port_type_by_index(i) == input_port_type) {
  2554. parameter_ref->set_parameter_name(parameter_ref->get_parameter_name_by_index(i));
  2555. success = true;
  2556. break;
  2557. }
  2558. }
  2559. if (!success) {
  2560. for (int i = 0; i < parameter_ref->get_parameters_count(); i++) {
  2561. if (visual_shader->is_port_types_compatible(parameter_ref->get_port_type_by_index(i), input_port_type)) {
  2562. parameter_ref->set_parameter_name(parameter_ref->get_parameter_name_by_index(i));
  2563. break;
  2564. }
  2565. }
  2566. }
  2567. }
  2568. vsnode = Ref<VisualShaderNode>(vsn);
  2569. } else {
  2570. ERR_FAIL_COND(add_options[p_idx].script.is_null());
  2571. StringName base_type = add_options[p_idx].script->get_instance_base_type();
  2572. VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(base_type));
  2573. ERR_FAIL_COND(!vsn);
  2574. vsnode = Ref<VisualShaderNode>(vsn);
  2575. vsnode->set_script(add_options[p_idx].script);
  2576. }
  2577. bool is_texture2d = (Object::cast_to<VisualShaderNodeTexture>(vsnode.ptr()) != nullptr);
  2578. bool is_texture3d = (Object::cast_to<VisualShaderNodeTexture3D>(vsnode.ptr()) != nullptr);
  2579. bool is_texture2d_array = (Object::cast_to<VisualShaderNodeTexture2DArray>(vsnode.ptr()) != nullptr);
  2580. bool is_cubemap = (Object::cast_to<VisualShaderNodeCubemap>(vsnode.ptr()) != nullptr);
  2581. bool is_curve = (Object::cast_to<VisualShaderNodeCurveTexture>(vsnode.ptr()) != nullptr);
  2582. bool is_curve_xyz = (Object::cast_to<VisualShaderNodeCurveXYZTexture>(vsnode.ptr()) != nullptr);
  2583. bool is_parameter = (Object::cast_to<VisualShaderNodeParameter>(vsnode.ptr()) != nullptr);
  2584. Point2 position = graph->get_scroll_ofs();
  2585. if (saved_node_pos_dirty) {
  2586. position += saved_node_pos;
  2587. } else {
  2588. position += graph->get_size() * 0.5;
  2589. position /= EDSCALE;
  2590. }
  2591. position /= graph->get_zoom();
  2592. saved_node_pos_dirty = false;
  2593. int id_to_use = visual_shader->get_valid_node_id(type);
  2594. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2595. if (p_resource_path.is_empty()) {
  2596. undo_redo->create_action(TTR("Add Node to Visual Shader"));
  2597. } else {
  2598. id_to_use += p_node_idx;
  2599. }
  2600. undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, vsnode, position, id_to_use);
  2601. undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_to_use);
  2602. undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_to_use, false);
  2603. undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_to_use, false);
  2604. VisualShaderNodeExpression *expr = Object::cast_to<VisualShaderNodeExpression>(vsnode.ptr());
  2605. if (expr) {
  2606. expr->set_size(Size2(250 * EDSCALE, 150 * EDSCALE));
  2607. }
  2608. bool created_expression_port = false;
  2609. if (to_node != -1 && to_slot != -1) {
  2610. VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot);
  2611. if (expr && expr->is_editable() && input_port_type != VisualShaderNode::PORT_TYPE_SAMPLER) {
  2612. expr->add_output_port(0, input_port_type, "output0");
  2613. String initial_expression_code;
  2614. switch (input_port_type) {
  2615. case VisualShaderNode::PORT_TYPE_SCALAR:
  2616. initial_expression_code = "output0 = 1.0;";
  2617. break;
  2618. case VisualShaderNode::PORT_TYPE_SCALAR_INT:
  2619. initial_expression_code = "output0 = 1;";
  2620. break;
  2621. case VisualShaderNode::PORT_TYPE_SCALAR_UINT:
  2622. initial_expression_code = "output0 = 1u;";
  2623. break;
  2624. case VisualShaderNode::PORT_TYPE_VECTOR_2D:
  2625. initial_expression_code = "output0 = vec2(1.0, 1.0);";
  2626. break;
  2627. case VisualShaderNode::PORT_TYPE_VECTOR_3D:
  2628. initial_expression_code = "output0 = vec3(1.0, 1.0, 1.0);";
  2629. break;
  2630. case VisualShaderNode::PORT_TYPE_VECTOR_4D:
  2631. initial_expression_code = "output0 = vec4(1.0, 1.0, 1.0, 1.0);";
  2632. break;
  2633. case VisualShaderNode::PORT_TYPE_BOOLEAN:
  2634. initial_expression_code = "output0 = true;";
  2635. break;
  2636. case VisualShaderNode::PORT_TYPE_TRANSFORM:
  2637. initial_expression_code = "output0 = mat4(1.0);";
  2638. break;
  2639. default:
  2640. break;
  2641. }
  2642. expr->set_expression(initial_expression_code);
  2643. expr->set_size(Size2(500 * EDSCALE, 200 * EDSCALE));
  2644. created_expression_port = true;
  2645. }
  2646. if (vsnode->get_output_port_count() > 0 || created_expression_port) {
  2647. int _from_node = id_to_use;
  2648. if (created_expression_port) {
  2649. int _from_slot = 0;
  2650. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  2651. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  2652. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  2653. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  2654. } else {
  2655. // Need to setting up Input node properly before committing since `is_port_types_compatible` (calling below) is using `mode` and `shader_type`.
  2656. VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(vsnode.ptr());
  2657. if (input) {
  2658. input->set_shader_mode(visual_shader->get_mode());
  2659. input->set_shader_type(visual_shader->get_shader_type());
  2660. }
  2661. // Attempting to connect to the first correct port.
  2662. for (int i = 0; i < vsnode->get_output_port_count(); i++) {
  2663. if (visual_shader->is_port_types_compatible(vsnode->get_output_port_type(i), input_port_type)) {
  2664. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot);
  2665. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot);
  2666. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot);
  2667. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot);
  2668. break;
  2669. }
  2670. }
  2671. }
  2672. }
  2673. } else if (from_node != -1 && from_slot != -1) {
  2674. VisualShaderNode::PortType output_port_type = visual_shader->get_node(type, from_node)->get_output_port_type(from_slot);
  2675. if (expr && expr->is_editable()) {
  2676. expr->add_input_port(0, output_port_type, "input0");
  2677. created_expression_port = true;
  2678. }
  2679. if (vsnode->get_input_port_count() > 0 || created_expression_port) {
  2680. int _to_node = id_to_use;
  2681. if (created_expression_port) {
  2682. int _to_slot = 0;
  2683. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  2684. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  2685. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  2686. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  2687. } else {
  2688. // Attempting to connect to the first correct port.
  2689. for (int i = 0; i < vsnode->get_input_port_count(); i++) {
  2690. if (visual_shader->is_port_types_compatible(output_port_type, vsnode->get_input_port_type(i))) {
  2691. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, i);
  2692. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, i);
  2693. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, i);
  2694. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, i);
  2695. break;
  2696. }
  2697. }
  2698. }
  2699. if (output_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) {
  2700. if (is_texture2d) {
  2701. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeTexture::SOURCE_PORT);
  2702. }
  2703. if (is_texture3d || is_texture2d_array) {
  2704. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeSample3D::SOURCE_PORT);
  2705. }
  2706. if (is_cubemap) {
  2707. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeCubemap::SOURCE_PORT);
  2708. }
  2709. }
  2710. }
  2711. }
  2712. _member_cancel();
  2713. if (is_parameter) {
  2714. undo_redo->add_do_method(this, "_update_parameters", true);
  2715. undo_redo->add_undo_method(this, "_update_parameters", true);
  2716. }
  2717. if (is_curve) {
  2718. graph_plugin->call_deferred(SNAME("update_curve"), id_to_use);
  2719. }
  2720. if (is_curve_xyz) {
  2721. graph_plugin->call_deferred(SNAME("update_curve_xyz"), id_to_use);
  2722. }
  2723. if (p_resource_path.is_empty()) {
  2724. undo_redo->commit_action();
  2725. } else {
  2726. //post-initialization
  2727. if (is_texture2d || is_texture3d || is_curve || is_curve_xyz) {
  2728. undo_redo->add_do_method(vsnode.ptr(), "set_texture", ResourceLoader::load(p_resource_path));
  2729. return;
  2730. }
  2731. if (is_cubemap) {
  2732. undo_redo->add_do_method(vsnode.ptr(), "set_cube_map", ResourceLoader::load(p_resource_path));
  2733. return;
  2734. }
  2735. if (is_texture2d_array) {
  2736. undo_redo->add_do_method(vsnode.ptr(), "set_texture_array", ResourceLoader::load(p_resource_path));
  2737. }
  2738. }
  2739. }
  2740. void VisualShaderEditor::_add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type) {
  2741. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2742. undo_redo->create_action(vformat(TTR("Add Varying to Visual Shader: %s"), p_name));
  2743. undo_redo->add_do_method(visual_shader.ptr(), "add_varying", p_name, p_mode, p_type);
  2744. undo_redo->add_undo_method(visual_shader.ptr(), "remove_varying", p_name);
  2745. undo_redo->add_do_method(this, "_update_varyings");
  2746. undo_redo->add_undo_method(this, "_update_varyings");
  2747. for (int i = 0; i <= VisualShader::TYPE_LIGHT; i++) {
  2748. if (p_mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT && i == 0) {
  2749. continue;
  2750. }
  2751. VisualShader::Type type = VisualShader::Type(i);
  2752. Vector<int> nodes = visual_shader->get_node_list(type);
  2753. for (int j = 0; j < nodes.size(); j++) {
  2754. int node_id = nodes[j];
  2755. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  2756. Ref<VisualShaderNodeVarying> var = vsnode;
  2757. if (var.is_valid()) {
  2758. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, node_id);
  2759. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, node_id);
  2760. }
  2761. }
  2762. }
  2763. undo_redo->add_do_method(this, "_update_varying_tree");
  2764. undo_redo->add_undo_method(this, "_update_varying_tree");
  2765. undo_redo->commit_action();
  2766. }
  2767. void VisualShaderEditor::_remove_varying(const String &p_name) {
  2768. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2769. undo_redo->create_action(vformat(TTR("Remove Varying from Visual Shader: %s"), p_name));
  2770. VisualShader::VaryingMode var_mode = visual_shader->get_varying_mode(p_name);
  2771. undo_redo->add_do_method(visual_shader.ptr(), "remove_varying", p_name);
  2772. undo_redo->add_undo_method(visual_shader.ptr(), "add_varying", p_name, var_mode, visual_shader->get_varying_type(p_name));
  2773. undo_redo->add_do_method(this, "_update_varyings");
  2774. undo_redo->add_undo_method(this, "_update_varyings");
  2775. for (int i = 0; i <= VisualShader::TYPE_LIGHT; i++) {
  2776. if (var_mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT && i == 0) {
  2777. continue;
  2778. }
  2779. VisualShader::Type type = VisualShader::Type(i);
  2780. Vector<int> nodes = visual_shader->get_node_list(type);
  2781. for (int j = 0; j < nodes.size(); j++) {
  2782. int node_id = nodes[j];
  2783. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  2784. Ref<VisualShaderNodeVarying> var = vsnode;
  2785. if (var.is_valid()) {
  2786. String var_name = var->get_varying_name();
  2787. if (var_name == p_name) {
  2788. undo_redo->add_do_method(var.ptr(), "set_varying_name", "[None]");
  2789. undo_redo->add_undo_method(var.ptr(), "set_varying_name", var_name);
  2790. undo_redo->add_do_method(var.ptr(), "set_varying_type", VisualShader::VARYING_TYPE_FLOAT);
  2791. undo_redo->add_undo_method(var.ptr(), "set_varying_type", var->get_varying_type());
  2792. }
  2793. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, node_id);
  2794. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, node_id);
  2795. }
  2796. }
  2797. List<VisualShader::Connection> node_connections;
  2798. visual_shader->get_node_connections(type, &node_connections);
  2799. for (VisualShader::Connection &E : node_connections) {
  2800. Ref<VisualShaderNodeVaryingGetter> var_getter = Object::cast_to<VisualShaderNodeVaryingGetter>(visual_shader->get_node(type, E.from_node).ptr());
  2801. if (var_getter.is_valid() && E.from_port > 0) {
  2802. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2803. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2804. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2805. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2806. }
  2807. Ref<VisualShaderNodeVaryingSetter> var_setter = Object::cast_to<VisualShaderNodeVaryingSetter>(visual_shader->get_node(type, E.to_node).ptr());
  2808. if (var_setter.is_valid() && E.to_port > 0) {
  2809. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2810. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2811. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2812. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2813. }
  2814. }
  2815. }
  2816. undo_redo->add_do_method(this, "_update_varying_tree");
  2817. undo_redo->add_undo_method(this, "_update_varying_tree");
  2818. undo_redo->commit_action();
  2819. }
  2820. void VisualShaderEditor::_update_varyings() {
  2821. VisualShaderNodeVarying::clear_varyings();
  2822. for (int i = 0; i < visual_shader->get_varyings_count(); i++) {
  2823. const VisualShader::Varying *var = visual_shader->get_varying_by_index(i);
  2824. if (var != nullptr) {
  2825. VisualShaderNodeVarying::add_varying(var->name, var->mode, var->type);
  2826. }
  2827. }
  2828. }
  2829. void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) {
  2830. VisualShader::Type type = get_current_shader_type();
  2831. drag_buffer.push_back({ type, p_node, p_from, p_to });
  2832. if (!drag_dirty) {
  2833. call_deferred(SNAME("_nodes_dragged"));
  2834. }
  2835. drag_dirty = true;
  2836. }
  2837. void VisualShaderEditor::_nodes_dragged() {
  2838. drag_dirty = false;
  2839. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2840. undo_redo->create_action(TTR("Node(s) Moved"));
  2841. for (const DragOp &E : drag_buffer) {
  2842. undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.to);
  2843. undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.from);
  2844. undo_redo->add_do_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.to);
  2845. undo_redo->add_undo_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.from);
  2846. }
  2847. drag_buffer.clear();
  2848. undo_redo->commit_action();
  2849. }
  2850. void VisualShaderEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  2851. VisualShader::Type type = get_current_shader_type();
  2852. int from = p_from.to_int();
  2853. int to = p_to.to_int();
  2854. if (!visual_shader->can_connect_nodes(type, from, p_from_index, to, p_to_index)) {
  2855. return;
  2856. }
  2857. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2858. undo_redo->create_action(TTR("Nodes Connected"));
  2859. List<VisualShader::Connection> conns;
  2860. visual_shader->get_node_connections(type, &conns);
  2861. for (const VisualShader::Connection &E : conns) {
  2862. if (E.to_node == to && E.to_port == p_to_index) {
  2863. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2864. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2865. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2866. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2867. }
  2868. }
  2869. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  2870. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  2871. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  2872. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  2873. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, to);
  2874. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, to);
  2875. undo_redo->commit_action();
  2876. }
  2877. void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  2878. graph->disconnect_node(p_from, p_from_index, p_to, p_to_index);
  2879. VisualShader::Type type = get_current_shader_type();
  2880. int from = p_from.to_int();
  2881. int to = p_to.to_int();
  2882. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2883. undo_redo->create_action(TTR("Nodes Disconnected"));
  2884. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  2885. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  2886. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  2887. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  2888. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, to);
  2889. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, to);
  2890. undo_redo->commit_action();
  2891. }
  2892. void VisualShaderEditor::_connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position) {
  2893. from_node = p_from.to_int();
  2894. from_slot = p_from_slot;
  2895. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  2896. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  2897. Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), from_node);
  2898. if (node.is_valid()) {
  2899. output_port_type = node->get_output_port_type(from_slot);
  2900. }
  2901. _show_members_dialog(true, input_port_type, output_port_type);
  2902. }
  2903. void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position) {
  2904. to_node = p_to.to_int();
  2905. to_slot = p_to_slot;
  2906. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  2907. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  2908. Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), to_node);
  2909. if (node.is_valid()) {
  2910. input_port_type = node->get_input_port_type(to_slot);
  2911. }
  2912. _show_members_dialog(true, input_port_type, output_port_type);
  2913. }
  2914. void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) {
  2915. VisualShader::Type type = VisualShader::Type(p_type);
  2916. List<VisualShader::Connection> conns;
  2917. visual_shader->get_node_connections(type, &conns);
  2918. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2919. for (const int &F : p_nodes) {
  2920. for (const VisualShader::Connection &E : conns) {
  2921. if (E.from_node == F || E.to_node == F) {
  2922. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2923. }
  2924. }
  2925. }
  2926. HashSet<String> parameter_names;
  2927. for (const int &F : p_nodes) {
  2928. Ref<VisualShaderNode> node = visual_shader->get_node(type, F);
  2929. undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F);
  2930. undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F), F);
  2931. undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F, false);
  2932. VisualShaderNodeParameter *parameter = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  2933. if (parameter) {
  2934. parameter_names.insert(parameter->get_parameter_name());
  2935. }
  2936. }
  2937. List<VisualShader::Connection> used_conns;
  2938. for (const int &F : p_nodes) {
  2939. for (const VisualShader::Connection &E : conns) {
  2940. if (E.from_node == F || E.to_node == F) {
  2941. bool cancel = false;
  2942. for (List<VisualShader::Connection>::Element *R = used_conns.front(); R; R = R->next()) {
  2943. if (R->get().from_node == E.from_node && R->get().from_port == E.from_port && R->get().to_node == E.to_node && R->get().to_port == E.to_port) {
  2944. cancel = true; // to avoid ERR_ALREADY_EXISTS warning
  2945. break;
  2946. }
  2947. }
  2948. if (!cancel) {
  2949. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2950. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  2951. used_conns.push_back(E);
  2952. }
  2953. }
  2954. }
  2955. }
  2956. // delete nodes from the graph
  2957. for (const int &F : p_nodes) {
  2958. undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, F, false);
  2959. }
  2960. // update parameter refs if any parameter has been deleted
  2961. if (parameter_names.size() > 0) {
  2962. undo_redo->add_do_method(this, "_update_parameters", true);
  2963. undo_redo->add_undo_method(this, "_update_parameters", true);
  2964. _update_parameter_refs(parameter_names);
  2965. }
  2966. }
  2967. void VisualShaderEditor::_replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to) {
  2968. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2969. undo_redo->add_do_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_to);
  2970. undo_redo->add_undo_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_from);
  2971. }
  2972. void VisualShaderEditor::_update_constant(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port) {
  2973. Ref<VisualShaderNode> node = visual_shader->get_node(p_type_id, p_node_id);
  2974. ERR_FAIL_COND(!node.is_valid());
  2975. ERR_FAIL_COND(!node->has_method("set_constant"));
  2976. node->call("set_constant", p_var);
  2977. if (p_preview_port != -1) {
  2978. node->set_output_port_for_preview(p_preview_port);
  2979. }
  2980. }
  2981. void VisualShaderEditor::_update_parameter(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port) {
  2982. Ref<VisualShaderNodeParameter> parameter = visual_shader->get_node(p_type_id, p_node_id);
  2983. ERR_FAIL_COND(!parameter.is_valid());
  2984. String valid_name = visual_shader->validate_parameter_name(parameter->get_parameter_name(), parameter);
  2985. parameter->set_parameter_name(valid_name);
  2986. graph_plugin->set_parameter_name(p_type_id, p_node_id, valid_name);
  2987. if (parameter->has_method("set_default_value_enabled")) {
  2988. parameter->call("set_default_value_enabled", true);
  2989. parameter->call("set_default_value", p_var);
  2990. }
  2991. if (p_preview_port != -1) {
  2992. parameter->set_output_port_for_preview(p_preview_port);
  2993. }
  2994. }
  2995. void VisualShaderEditor::_convert_constants_to_parameters(bool p_vice_versa) {
  2996. VisualShader::Type type_id = get_current_shader_type();
  2997. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2998. if (!p_vice_versa) {
  2999. undo_redo->create_action(TTR("Convert Constant Node(s) To Parameter(s)"));
  3000. } else {
  3001. undo_redo->create_action(TTR("Convert Parameter Node(s) To Constant(s)"));
  3002. }
  3003. const HashSet<int> &current_set = p_vice_versa ? selected_parameters : selected_constants;
  3004. HashSet<String> deleted_names;
  3005. for (const int &E : current_set) {
  3006. int node_id = E;
  3007. Ref<VisualShaderNode> node = visual_shader->get_node(type_id, node_id);
  3008. bool caught = false;
  3009. Variant var;
  3010. // float
  3011. if (!p_vice_versa) {
  3012. Ref<VisualShaderNodeFloatConstant> float_const = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
  3013. if (float_const.is_valid()) {
  3014. _replace_node(type_id, node_id, "VisualShaderNodeFloatConstant", "VisualShaderNodeFloatParameter");
  3015. var = float_const->get_constant();
  3016. caught = true;
  3017. }
  3018. } else {
  3019. Ref<VisualShaderNodeFloatParameter> float_parameter = Object::cast_to<VisualShaderNodeFloatParameter>(node.ptr());
  3020. if (float_parameter.is_valid()) {
  3021. _replace_node(type_id, node_id, "VisualShaderNodeFloatParameter", "VisualShaderNodeFloatConstant");
  3022. var = float_parameter->get_default_value();
  3023. caught = true;
  3024. }
  3025. }
  3026. // int
  3027. if (!caught) {
  3028. if (!p_vice_versa) {
  3029. Ref<VisualShaderNodeIntConstant> int_const = Object::cast_to<VisualShaderNodeIntConstant>(node.ptr());
  3030. if (int_const.is_valid()) {
  3031. _replace_node(type_id, node_id, "VisualShaderNodeIntConstant", "VisualShaderNodeIntParameter");
  3032. var = int_const->get_constant();
  3033. caught = true;
  3034. }
  3035. } else {
  3036. Ref<VisualShaderNodeIntParameter> int_parameter = Object::cast_to<VisualShaderNodeIntParameter>(node.ptr());
  3037. if (int_parameter.is_valid()) {
  3038. _replace_node(type_id, node_id, "VisualShaderNodeIntParameter", "VisualShaderNodeIntConstant");
  3039. var = int_parameter->get_default_value();
  3040. caught = true;
  3041. }
  3042. }
  3043. }
  3044. // boolean
  3045. if (!caught) {
  3046. if (!p_vice_versa) {
  3047. Ref<VisualShaderNodeBooleanConstant> boolean_const = Object::cast_to<VisualShaderNodeBooleanConstant>(node.ptr());
  3048. if (boolean_const.is_valid()) {
  3049. _replace_node(type_id, node_id, "VisualShaderNodeBooleanConstant", "VisualShaderNodeBooleanParameter");
  3050. var = boolean_const->get_constant();
  3051. caught = true;
  3052. }
  3053. } else {
  3054. Ref<VisualShaderNodeBooleanParameter> boolean_parameter = Object::cast_to<VisualShaderNodeBooleanParameter>(node.ptr());
  3055. if (boolean_parameter.is_valid()) {
  3056. _replace_node(type_id, node_id, "VisualShaderNodeBooleanParameter", "VisualShaderNodeBooleanConstant");
  3057. var = boolean_parameter->get_default_value();
  3058. caught = true;
  3059. }
  3060. }
  3061. }
  3062. // vec2
  3063. if (!caught) {
  3064. if (!p_vice_versa) {
  3065. Ref<VisualShaderNodeVec2Constant> vec2_const = Object::cast_to<VisualShaderNodeVec2Constant>(node.ptr());
  3066. if (vec2_const.is_valid()) {
  3067. _replace_node(type_id, node_id, "VisualShaderNodeVec2Constant", "VisualShaderNodeVec2Parameter");
  3068. var = vec2_const->get_constant();
  3069. caught = true;
  3070. }
  3071. } else {
  3072. Ref<VisualShaderNodeVec2Parameter> vec2_parameter = Object::cast_to<VisualShaderNodeVec2Parameter>(node.ptr());
  3073. if (vec2_parameter.is_valid()) {
  3074. _replace_node(type_id, node_id, "VisualShaderNodeVec2Parameter", "VisualShaderNodeVec2Constant");
  3075. var = vec2_parameter->get_default_value();
  3076. caught = true;
  3077. }
  3078. }
  3079. }
  3080. // vec3
  3081. if (!caught) {
  3082. if (!p_vice_versa) {
  3083. Ref<VisualShaderNodeVec3Constant> vec3_const = Object::cast_to<VisualShaderNodeVec3Constant>(node.ptr());
  3084. if (vec3_const.is_valid()) {
  3085. _replace_node(type_id, node_id, "VisualShaderNodeVec3Constant", "VisualShaderNodeVec3Parameter");
  3086. var = vec3_const->get_constant();
  3087. caught = true;
  3088. }
  3089. } else {
  3090. Ref<VisualShaderNodeVec3Parameter> vec3_parameter = Object::cast_to<VisualShaderNodeVec3Parameter>(node.ptr());
  3091. if (vec3_parameter.is_valid()) {
  3092. _replace_node(type_id, node_id, "VisualShaderNodeVec3Parameter", "VisualShaderNodeVec3Constant");
  3093. var = vec3_parameter->get_default_value();
  3094. caught = true;
  3095. }
  3096. }
  3097. }
  3098. // vec4
  3099. if (!caught) {
  3100. if (!p_vice_versa) {
  3101. Ref<VisualShaderNodeVec4Constant> vec4_const = Object::cast_to<VisualShaderNodeVec4Constant>(node.ptr());
  3102. if (vec4_const.is_valid()) {
  3103. _replace_node(type_id, node_id, "VisualShaderNodeVec4Constant", "VisualShaderNodeVec4Parameter");
  3104. var = vec4_const->get_constant();
  3105. caught = true;
  3106. }
  3107. } else {
  3108. Ref<VisualShaderNodeVec4Parameter> vec4_parameter = Object::cast_to<VisualShaderNodeVec4Parameter>(node.ptr());
  3109. if (vec4_parameter.is_valid()) {
  3110. _replace_node(type_id, node_id, "VisualShaderNodeVec4Parameter", "VisualShaderNodeVec4Constant");
  3111. var = vec4_parameter->get_default_value();
  3112. caught = true;
  3113. }
  3114. }
  3115. }
  3116. // color
  3117. if (!caught) {
  3118. if (!p_vice_versa) {
  3119. Ref<VisualShaderNodeColorConstant> color_const = Object::cast_to<VisualShaderNodeColorConstant>(node.ptr());
  3120. if (color_const.is_valid()) {
  3121. _replace_node(type_id, node_id, "VisualShaderNodeColorConstant", "VisualShaderNodeColorParameter");
  3122. var = color_const->get_constant();
  3123. caught = true;
  3124. }
  3125. } else {
  3126. Ref<VisualShaderNodeColorParameter> color_parameter = Object::cast_to<VisualShaderNodeColorParameter>(node.ptr());
  3127. if (color_parameter.is_valid()) {
  3128. _replace_node(type_id, node_id, "VisualShaderNodeColorParameter", "VisualShaderNodeColorConstant");
  3129. var = color_parameter->get_default_value();
  3130. caught = true;
  3131. }
  3132. }
  3133. }
  3134. // transform
  3135. if (!caught) {
  3136. if (!p_vice_versa) {
  3137. Ref<VisualShaderNodeTransformConstant> transform_const = Object::cast_to<VisualShaderNodeTransformConstant>(node.ptr());
  3138. if (transform_const.is_valid()) {
  3139. _replace_node(type_id, node_id, "VisualShaderNodeTransformConstant", "VisualShaderNodeTransformParameter");
  3140. var = transform_const->get_constant();
  3141. caught = true;
  3142. }
  3143. } else {
  3144. Ref<VisualShaderNodeTransformParameter> transform_parameter = Object::cast_to<VisualShaderNodeTransformParameter>(node.ptr());
  3145. if (transform_parameter.is_valid()) {
  3146. _replace_node(type_id, node_id, "VisualShaderNodeTransformParameter", "VisualShaderNodeTransformConstant");
  3147. var = transform_parameter->get_default_value();
  3148. caught = true;
  3149. }
  3150. }
  3151. }
  3152. ERR_CONTINUE(!caught);
  3153. int preview_port = node->get_output_port_for_preview();
  3154. if (!p_vice_versa) {
  3155. undo_redo->add_do_method(this, "_update_parameter", type_id, node_id, var, preview_port);
  3156. undo_redo->add_undo_method(this, "_update_constant", type_id, node_id, var, preview_port);
  3157. } else {
  3158. undo_redo->add_do_method(this, "_update_constant", type_id, node_id, var, preview_port);
  3159. undo_redo->add_undo_method(this, "_update_parameter", type_id, node_id, var, preview_port);
  3160. Ref<VisualShaderNodeParameter> parameter = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  3161. ERR_CONTINUE(!parameter.is_valid());
  3162. deleted_names.insert(parameter->get_parameter_name());
  3163. }
  3164. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type_id, node_id);
  3165. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type_id, node_id);
  3166. }
  3167. undo_redo->add_do_method(this, "_update_parameters", true);
  3168. undo_redo->add_undo_method(this, "_update_parameters", true);
  3169. if (deleted_names.size() > 0) {
  3170. _update_parameter_refs(deleted_names);
  3171. }
  3172. undo_redo->commit_action();
  3173. }
  3174. void VisualShaderEditor::_delete_node_request(int p_type, int p_node) {
  3175. List<int> to_erase;
  3176. to_erase.push_back(p_node);
  3177. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3178. undo_redo->create_action(TTR("Delete VisualShader Node"));
  3179. _delete_nodes(p_type, to_erase);
  3180. undo_redo->commit_action();
  3181. }
  3182. void VisualShaderEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) {
  3183. List<int> to_erase;
  3184. if (p_nodes.is_empty()) {
  3185. // Called from context menu.
  3186. for (int i = 0; i < graph->get_child_count(); i++) {
  3187. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  3188. if (gn) {
  3189. if (gn->is_selected() && gn->is_close_button_visible()) {
  3190. to_erase.push_back(gn->get_name().operator String().to_int());
  3191. }
  3192. }
  3193. }
  3194. } else {
  3195. for (int i = 0; i < p_nodes.size(); i++) {
  3196. to_erase.push_back(p_nodes[i].operator String().to_int());
  3197. }
  3198. }
  3199. if (to_erase.is_empty()) {
  3200. return;
  3201. }
  3202. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3203. undo_redo->create_action(TTR("Delete VisualShader Node(s)"));
  3204. _delete_nodes(get_current_shader_type(), to_erase);
  3205. undo_redo->commit_action();
  3206. }
  3207. void VisualShaderEditor::_node_selected(Object *p_node) {
  3208. VisualShader::Type type = get_current_shader_type();
  3209. GraphNode *gn = Object::cast_to<GraphNode>(p_node);
  3210. ERR_FAIL_COND(!gn);
  3211. int id = String(gn->get_name()).to_int();
  3212. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  3213. ERR_FAIL_COND(!vsnode.is_valid());
  3214. //do not rely on this, makes editor more complex
  3215. //EditorNode::get_singleton()->push_item(vsnode.ptr(), "", true);
  3216. }
  3217. void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
  3218. Ref<InputEventMouseButton> mb = p_event;
  3219. VisualShader::Type type = get_current_shader_type();
  3220. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {
  3221. selected_constants.clear();
  3222. selected_parameters.clear();
  3223. selected_comment = -1;
  3224. selected_float_constant = -1;
  3225. List<int> to_change;
  3226. for (int i = 0; i < graph->get_child_count(); i++) {
  3227. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  3228. if (gn) {
  3229. if (gn->is_selected() && gn->is_close_button_visible()) {
  3230. int id = gn->get_name().operator String().to_int();
  3231. to_change.push_back(id);
  3232. Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
  3233. VisualShaderNodeComment *comment_node = Object::cast_to<VisualShaderNodeComment>(node.ptr());
  3234. if (comment_node != nullptr) {
  3235. selected_comment = id;
  3236. }
  3237. VisualShaderNodeConstant *constant_node = Object::cast_to<VisualShaderNodeConstant>(node.ptr());
  3238. if (constant_node != nullptr) {
  3239. selected_constants.insert(id);
  3240. }
  3241. VisualShaderNodeFloatConstant *float_constant_node = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
  3242. if (float_constant_node != nullptr) {
  3243. selected_float_constant = id;
  3244. }
  3245. VisualShaderNodeParameter *parameter_node = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  3246. if (parameter_node != nullptr && parameter_node->is_convertible_to_constant()) {
  3247. selected_parameters.insert(id);
  3248. }
  3249. }
  3250. }
  3251. }
  3252. if (to_change.size() > 1) {
  3253. selected_comment = -1;
  3254. selected_float_constant = -1;
  3255. }
  3256. bool copy_buffer_empty = true;
  3257. for (const CopyItem &item : copy_items_buffer) {
  3258. if (!item.disabled) {
  3259. copy_buffer_empty = false;
  3260. break;
  3261. }
  3262. }
  3263. if (to_change.is_empty() && copy_buffer_empty) {
  3264. _show_members_dialog(true);
  3265. } else {
  3266. popup_menu->set_item_disabled(NodeMenuOptions::CUT, to_change.is_empty());
  3267. popup_menu->set_item_disabled(NodeMenuOptions::COPY, to_change.is_empty());
  3268. popup_menu->set_item_disabled(NodeMenuOptions::PASTE, copy_buffer_empty);
  3269. popup_menu->set_item_disabled(NodeMenuOptions::DELETE, to_change.is_empty());
  3270. popup_menu->set_item_disabled(NodeMenuOptions::DUPLICATE, to_change.is_empty());
  3271. popup_menu->set_item_disabled(NodeMenuOptions::CLEAR_COPY_BUFFER, copy_buffer_empty);
  3272. int temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR2);
  3273. if (temp != -1) {
  3274. popup_menu->remove_item(temp);
  3275. }
  3276. temp = popup_menu->get_item_index(NodeMenuOptions::FLOAT_CONSTANTS);
  3277. if (temp != -1) {
  3278. popup_menu->remove_item(temp);
  3279. }
  3280. temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS);
  3281. if (temp != -1) {
  3282. popup_menu->remove_item(temp);
  3283. }
  3284. temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS);
  3285. if (temp != -1) {
  3286. popup_menu->remove_item(temp);
  3287. }
  3288. temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR3);
  3289. if (temp != -1) {
  3290. popup_menu->remove_item(temp);
  3291. }
  3292. temp = popup_menu->get_item_index(NodeMenuOptions::SET_COMMENT_TITLE);
  3293. if (temp != -1) {
  3294. popup_menu->remove_item(temp);
  3295. }
  3296. temp = popup_menu->get_item_index(NodeMenuOptions::SET_COMMENT_DESCRIPTION);
  3297. if (temp != -1) {
  3298. popup_menu->remove_item(temp);
  3299. }
  3300. if (selected_constants.size() > 0 || selected_parameters.size() > 0) {
  3301. popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2);
  3302. if (selected_float_constant != -1) {
  3303. popup_menu->add_submenu_item(TTR("Float Constants"), "FloatConstants", int(NodeMenuOptions::FLOAT_CONSTANTS));
  3304. if (!constants_submenu) {
  3305. constants_submenu = memnew(PopupMenu);
  3306. constants_submenu->set_name("FloatConstants");
  3307. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  3308. constants_submenu->add_item(float_constant_defs[i].name, i);
  3309. }
  3310. popup_menu->add_child(constants_submenu);
  3311. constants_submenu->connect("index_pressed", callable_mp(this, &VisualShaderEditor::_float_constant_selected));
  3312. }
  3313. }
  3314. if (selected_constants.size() > 0) {
  3315. popup_menu->add_item(TTR("Convert Constant(s) to Parameter(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS);
  3316. }
  3317. if (selected_parameters.size() > 0) {
  3318. popup_menu->add_item(TTR("Convert Parameter(s) to Constant(s)"), NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS);
  3319. }
  3320. }
  3321. if (selected_comment != -1) {
  3322. popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3);
  3323. popup_menu->add_item(TTR("Set Comment Title"), NodeMenuOptions::SET_COMMENT_TITLE);
  3324. popup_menu->add_item(TTR("Set Comment Description"), NodeMenuOptions::SET_COMMENT_DESCRIPTION);
  3325. }
  3326. menu_point = graph->get_local_mouse_position();
  3327. Point2 gpos = get_screen_position() + get_local_mouse_position();
  3328. popup_menu->set_position(gpos);
  3329. popup_menu->reset_size();
  3330. popup_menu->popup();
  3331. }
  3332. }
  3333. }
  3334. void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type, VisualShaderNode::PortType p_output_port_type) {
  3335. if (members_input_port_type != p_input_port_type || members_output_port_type != p_output_port_type) {
  3336. members_input_port_type = p_input_port_type;
  3337. members_output_port_type = p_output_port_type;
  3338. _update_options_menu();
  3339. }
  3340. if (at_mouse_pos) {
  3341. saved_node_pos_dirty = true;
  3342. saved_node_pos = graph->get_local_mouse_position();
  3343. Point2 gpos = get_screen_position() + get_local_mouse_position();
  3344. members_dialog->set_position(gpos);
  3345. } else {
  3346. saved_node_pos_dirty = false;
  3347. members_dialog->set_position(graph->get_screen_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  3348. }
  3349. members_dialog->popup();
  3350. // Keep dialog within window bounds.
  3351. Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size());
  3352. Rect2 dialog_rect = Rect2(members_dialog->get_position(), members_dialog->get_size());
  3353. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).max(Vector2());
  3354. members_dialog->set_position(members_dialog->get_position() - difference);
  3355. node_filter->call_deferred(SNAME("grab_focus")); // Still not visible.
  3356. node_filter->select_all();
  3357. }
  3358. void VisualShaderEditor::_varying_menu_id_pressed(int p_idx) {
  3359. switch (VaryingMenuOptions(p_idx)) {
  3360. case VaryingMenuOptions::ADD: {
  3361. _show_add_varying_dialog();
  3362. } break;
  3363. case VaryingMenuOptions::REMOVE: {
  3364. _show_remove_varying_dialog();
  3365. } break;
  3366. default:
  3367. break;
  3368. }
  3369. }
  3370. void VisualShaderEditor::_show_add_varying_dialog() {
  3371. _varying_name_changed(varying_name->get_text());
  3372. add_varying_dialog->set_position(graph->get_screen_position() + varying_button->get_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  3373. add_varying_dialog->popup();
  3374. // Keep dialog within window bounds.
  3375. Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size());
  3376. Rect2 dialog_rect = Rect2(add_varying_dialog->get_position(), add_varying_dialog->get_size());
  3377. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).max(Vector2());
  3378. add_varying_dialog->set_position(add_varying_dialog->get_position() - difference);
  3379. }
  3380. void VisualShaderEditor::_show_remove_varying_dialog() {
  3381. remove_varying_dialog->set_position(graph->get_screen_position() + varying_button->get_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  3382. remove_varying_dialog->popup();
  3383. // Keep dialog within window bounds.
  3384. Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size());
  3385. Rect2 dialog_rect = Rect2(remove_varying_dialog->get_position(), remove_varying_dialog->get_size());
  3386. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).max(Vector2());
  3387. remove_varying_dialog->set_position(remove_varying_dialog->get_position() - difference);
  3388. }
  3389. void VisualShaderEditor::_sbox_input(const Ref<InputEvent> &p_ie) {
  3390. Ref<InputEventKey> ie = p_ie;
  3391. if (ie.is_valid() && (ie->get_keycode() == Key::UP || ie->get_keycode() == Key::DOWN || ie->get_keycode() == Key::ENTER || ie->get_keycode() == Key::KP_ENTER)) {
  3392. members->gui_input(ie);
  3393. node_filter->accept_event();
  3394. }
  3395. }
  3396. void VisualShaderEditor::_notification(int p_what) {
  3397. switch (p_what) {
  3398. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  3399. 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")));
  3400. graph->set_warped_panning(bool(EDITOR_GET("editors/panning/warped_mouse_panning")));
  3401. graph->set_minimap_opacity(EDITOR_GET("editors/visual_editors/minimap_opacity"));
  3402. graph->set_connection_lines_curvature(EDITOR_GET("editors/visual_editors/lines_curvature"));
  3403. _update_graph();
  3404. } break;
  3405. case NOTIFICATION_ENTER_TREE: {
  3406. node_filter->set_clear_button_enabled(true);
  3407. // collapse tree by default
  3408. TreeItem *category = members->get_root()->get_first_child();
  3409. while (category) {
  3410. category->set_collapsed(true);
  3411. TreeItem *sub_category = category->get_first_child();
  3412. while (sub_category) {
  3413. sub_category->set_collapsed(true);
  3414. sub_category = sub_category->get_next();
  3415. }
  3416. category = category->get_next();
  3417. }
  3418. 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")));
  3419. graph->set_warped_panning(bool(EDITOR_GET("editors/panning/warped_mouse_panning")));
  3420. [[fallthrough]];
  3421. }
  3422. case NOTIFICATION_THEME_CHANGED: {
  3423. highend_label->set_modulate(get_theme_color(SNAME("highend_color"), SNAME("Editor")));
  3424. node_filter->set_right_icon(Control::get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
  3425. preview_shader->set_icon(Control::get_theme_icon(SNAME("Shader"), SNAME("EditorIcons")));
  3426. {
  3427. Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color");
  3428. Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color");
  3429. Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
  3430. Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color");
  3431. Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
  3432. Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color");
  3433. Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color");
  3434. Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color");
  3435. Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color");
  3436. Color error_color = get_theme_color(SNAME("error_color"), SNAME("Editor"));
  3437. preview_text->add_theme_color_override("background_color", background_color);
  3438. varying_error_label->add_theme_color_override("font_color", error_color);
  3439. for (const String &E : keyword_list) {
  3440. if (ShaderLanguage::is_control_flow_keyword(E)) {
  3441. syntax_highlighter->add_keyword_color(E, control_flow_keyword_color);
  3442. } else {
  3443. syntax_highlighter->add_keyword_color(E, keyword_color);
  3444. }
  3445. }
  3446. preview_text->add_theme_font_override("font", get_theme_font(SNAME("expression"), SNAME("EditorFonts")));
  3447. preview_text->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("expression_size"), SNAME("EditorFonts")));
  3448. preview_text->add_theme_color_override("font_color", text_color);
  3449. syntax_highlighter->set_number_color(number_color);
  3450. syntax_highlighter->set_symbol_color(symbol_color);
  3451. syntax_highlighter->set_function_color(function_color);
  3452. syntax_highlighter->set_member_variable_color(members_color);
  3453. syntax_highlighter->clear_color_regions();
  3454. syntax_highlighter->add_color_region("/*", "*/", comment_color, false);
  3455. syntax_highlighter->add_color_region("//", "", comment_color, true);
  3456. preview_text->clear_comment_delimiters();
  3457. preview_text->add_comment_delimiter("/*", "*/", false);
  3458. preview_text->add_comment_delimiter("//", "", true);
  3459. error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Panel")));
  3460. error_label->add_theme_font_override("font", get_theme_font(SNAME("status_source"), SNAME("EditorFonts")));
  3461. error_label->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts")));
  3462. error_label->add_theme_color_override("font_color", error_color);
  3463. }
  3464. tools->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Tools"), SNAME("EditorIcons")));
  3465. if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) {
  3466. _update_graph();
  3467. }
  3468. } break;
  3469. case NOTIFICATION_DRAG_BEGIN: {
  3470. Dictionary dd = get_viewport()->gui_get_drag_data();
  3471. if (members->is_visible_in_tree() && dd.has("id")) {
  3472. members->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
  3473. }
  3474. } break;
  3475. case NOTIFICATION_DRAG_END: {
  3476. members->set_drop_mode_flags(0);
  3477. } break;
  3478. }
  3479. }
  3480. void VisualShaderEditor::_scroll_changed(const Vector2 &p_scroll) {
  3481. if (updating) {
  3482. return;
  3483. }
  3484. updating = true;
  3485. visual_shader->set_graph_offset(p_scroll / EDSCALE);
  3486. updating = false;
  3487. }
  3488. void VisualShaderEditor::_node_changed(int p_id) {
  3489. if (updating) {
  3490. return;
  3491. }
  3492. if (is_visible_in_tree()) {
  3493. _update_graph();
  3494. }
  3495. }
  3496. void VisualShaderEditor::_dup_copy_nodes(int p_type, List<CopyItem> &r_items, List<VisualShader::Connection> &r_connections) {
  3497. VisualShader::Type type = (VisualShader::Type)p_type;
  3498. selection_center.x = 0.0f;
  3499. selection_center.y = 0.0f;
  3500. HashSet<int> nodes;
  3501. for (int i = 0; i < graph->get_child_count(); i++) {
  3502. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  3503. if (gn) {
  3504. int id = String(gn->get_name()).to_int();
  3505. Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
  3506. Ref<VisualShaderNodeOutput> output = node;
  3507. if (output.is_valid()) { // can't duplicate output
  3508. continue;
  3509. }
  3510. if (node.is_valid() && gn->is_selected()) {
  3511. Vector2 pos = visual_shader->get_node_position(type, id);
  3512. selection_center += pos;
  3513. CopyItem item;
  3514. item.id = id;
  3515. item.node = visual_shader->get_node(type, id)->duplicate();
  3516. item.position = visual_shader->get_node_position(type, id);
  3517. Ref<VisualShaderNodeResizableBase> resizable_base = node;
  3518. if (resizable_base.is_valid()) {
  3519. item.size = resizable_base->get_size();
  3520. }
  3521. Ref<VisualShaderNodeGroupBase> group = node;
  3522. if (group.is_valid()) {
  3523. item.group_inputs = group->get_inputs();
  3524. item.group_outputs = group->get_outputs();
  3525. }
  3526. Ref<VisualShaderNodeExpression> expression = node;
  3527. if (expression.is_valid()) {
  3528. item.expression = expression->get_expression();
  3529. }
  3530. r_items.push_back(item);
  3531. nodes.insert(id);
  3532. }
  3533. }
  3534. }
  3535. List<VisualShader::Connection> node_connections;
  3536. visual_shader->get_node_connections(type, &node_connections);
  3537. for (const VisualShader::Connection &E : node_connections) {
  3538. if (nodes.has(E.from_node) && nodes.has(E.to_node)) {
  3539. r_connections.push_back(E);
  3540. }
  3541. }
  3542. selection_center /= (float)r_items.size();
  3543. }
  3544. 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) {
  3545. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3546. if (p_duplicate) {
  3547. undo_redo->create_action(TTR("Duplicate VisualShader Node(s)"));
  3548. } else {
  3549. bool copy_buffer_empty = true;
  3550. for (const CopyItem &item : copy_items_buffer) {
  3551. if (!item.disabled) {
  3552. copy_buffer_empty = false;
  3553. break;
  3554. }
  3555. }
  3556. if (copy_buffer_empty) {
  3557. return;
  3558. }
  3559. undo_redo->create_action(TTR("Paste VisualShader Node(s)"));
  3560. }
  3561. VisualShader::Type type = (VisualShader::Type)p_type;
  3562. int base_id = visual_shader->get_valid_node_id(type);
  3563. int id_from = base_id;
  3564. HashMap<int, int> connection_remap;
  3565. HashSet<int> unsupported_set;
  3566. HashSet<int> added_set;
  3567. for (CopyItem &item : r_items) {
  3568. if (item.disabled) {
  3569. unsupported_set.insert(item.id);
  3570. continue;
  3571. }
  3572. connection_remap[item.id] = id_from;
  3573. Ref<VisualShaderNode> node = item.node->duplicate();
  3574. Ref<VisualShaderNodeResizableBase> resizable_base = Object::cast_to<VisualShaderNodeResizableBase>(node.ptr());
  3575. if (resizable_base.is_valid()) {
  3576. undo_redo->add_do_method(node.ptr(), "set_size", item.size);
  3577. }
  3578. Ref<VisualShaderNodeGroupBase> group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
  3579. if (group.is_valid()) {
  3580. undo_redo->add_do_method(node.ptr(), "set_inputs", item.group_inputs);
  3581. undo_redo->add_do_method(node.ptr(), "set_outputs", item.group_outputs);
  3582. }
  3583. Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  3584. if (expression.is_valid()) {
  3585. undo_redo->add_do_method(node.ptr(), "set_expression", item.expression);
  3586. }
  3587. undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, node, item.position + p_offset, id_from);
  3588. undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_from, false);
  3589. added_set.insert(id_from);
  3590. id_from++;
  3591. }
  3592. for (const VisualShader::Connection &E : p_connections) {
  3593. if (unsupported_set.has(E.from_node) || unsupported_set.has(E.to_node)) {
  3594. continue;
  3595. }
  3596. 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);
  3597. 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);
  3598. 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);
  3599. }
  3600. id_from = base_id;
  3601. for (const CopyItem &item : r_items) {
  3602. if (item.disabled) {
  3603. continue;
  3604. }
  3605. undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_from);
  3606. undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_from, false);
  3607. id_from++;
  3608. }
  3609. undo_redo->commit_action();
  3610. // reselect nodes by excluding the other ones
  3611. for (int i = 0; i < graph->get_child_count(); i++) {
  3612. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  3613. if (gn) {
  3614. int id = String(gn->get_name()).to_int();
  3615. if (added_set.has(id)) {
  3616. gn->set_selected(true);
  3617. } else {
  3618. gn->set_selected(false);
  3619. }
  3620. }
  3621. }
  3622. }
  3623. void VisualShaderEditor::_clear_copy_buffer() {
  3624. copy_items_buffer.clear();
  3625. copy_connections_buffer.clear();
  3626. }
  3627. void VisualShaderEditor::_duplicate_nodes() {
  3628. int type = get_current_shader_type();
  3629. List<CopyItem> items;
  3630. List<VisualShader::Connection> node_connections;
  3631. _dup_copy_nodes(type, items, node_connections);
  3632. if (items.is_empty()) {
  3633. return;
  3634. }
  3635. _dup_paste_nodes(type, items, node_connections, Vector2(10, 10) * EDSCALE, true);
  3636. }
  3637. void VisualShaderEditor::_copy_nodes(bool p_cut) {
  3638. _clear_copy_buffer();
  3639. _dup_copy_nodes(get_current_shader_type(), copy_items_buffer, copy_connections_buffer);
  3640. if (p_cut) {
  3641. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3642. undo_redo->create_action(TTR("Cut VisualShader Node(s)"));
  3643. List<int> ids;
  3644. for (const CopyItem &E : copy_items_buffer) {
  3645. ids.push_back(E.id);
  3646. }
  3647. _delete_nodes(get_current_shader_type(), ids);
  3648. undo_redo->commit_action();
  3649. }
  3650. }
  3651. void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2 &p_custom_position) {
  3652. if (copy_items_buffer.is_empty()) {
  3653. return;
  3654. }
  3655. int type = get_current_shader_type();
  3656. float scale = graph->get_zoom();
  3657. Vector2 mpos;
  3658. if (p_use_custom_position) {
  3659. mpos = p_custom_position;
  3660. } else {
  3661. mpos = graph->get_local_mouse_position();
  3662. }
  3663. _dup_paste_nodes(type, copy_items_buffer, copy_connections_buffer, graph->get_scroll_ofs() / scale + mpos / scale - selection_center, false);
  3664. }
  3665. void VisualShaderEditor::_mode_selected(int p_id) {
  3666. int offset = 0;
  3667. if (mode & MODE_FLAGS_PARTICLES) {
  3668. offset = 3;
  3669. if (p_id + offset > VisualShader::TYPE_PROCESS) {
  3670. custom_mode_box->set_visible(false);
  3671. custom_mode_enabled = false;
  3672. } else {
  3673. custom_mode_box->set_visible(true);
  3674. if (custom_mode_box->is_pressed()) {
  3675. custom_mode_enabled = true;
  3676. offset += 3;
  3677. }
  3678. }
  3679. } else if (mode & MODE_FLAGS_SKY) {
  3680. offset = 8;
  3681. } else if (mode & MODE_FLAGS_FOG) {
  3682. offset = 9;
  3683. }
  3684. visual_shader->set_shader_type(VisualShader::Type(p_id + offset));
  3685. _update_nodes();
  3686. _update_graph();
  3687. graph->grab_focus();
  3688. }
  3689. void VisualShaderEditor::_custom_mode_toggled(bool p_enabled) {
  3690. if (!(mode & MODE_FLAGS_PARTICLES)) {
  3691. return;
  3692. }
  3693. custom_mode_enabled = p_enabled;
  3694. int id = edit_type->get_selected() + 3;
  3695. if (p_enabled) {
  3696. visual_shader->set_shader_type(VisualShader::Type(id + 3));
  3697. } else {
  3698. visual_shader->set_shader_type(VisualShader::Type(id));
  3699. }
  3700. _update_options_menu();
  3701. _update_graph();
  3702. }
  3703. void VisualShaderEditor::_input_select_item(Ref<VisualShaderNodeInput> p_input, String p_name) {
  3704. String prev_name = p_input->get_input_name();
  3705. if (p_name == prev_name) {
  3706. return;
  3707. }
  3708. VisualShaderNode::PortType next_input_type = p_input->get_input_type_by_name(p_name);
  3709. VisualShaderNode::PortType prev_input_type = p_input->get_input_type_by_name(prev_name);
  3710. bool type_changed = next_input_type != prev_input_type;
  3711. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  3712. undo_redo_man->create_action(TTR("Visual Shader Input Type Changed"));
  3713. undo_redo_man->add_do_method(p_input.ptr(), "set_input_name", p_name);
  3714. undo_redo_man->add_undo_method(p_input.ptr(), "set_input_name", prev_name);
  3715. if (type_changed) {
  3716. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  3717. VisualShader::Type type = VisualShader::Type(type_id);
  3718. int id = visual_shader->find_node_id(type, p_input);
  3719. if (id != VisualShader::NODE_ID_INVALID) {
  3720. bool is_expanded = p_input->is_output_port_expandable(0) && p_input->_is_output_port_expanded(0);
  3721. int type_size = 0;
  3722. if (is_expanded) {
  3723. switch (next_input_type) {
  3724. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  3725. type_size = 2;
  3726. } break;
  3727. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  3728. type_size = 3;
  3729. } break;
  3730. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  3731. type_size = 4;
  3732. } break;
  3733. default:
  3734. break;
  3735. }
  3736. }
  3737. List<VisualShader::Connection> conns;
  3738. visual_shader->get_node_connections(type, &conns);
  3739. for (const VisualShader::Connection &E : conns) {
  3740. int cn_from_node = E.from_node;
  3741. int cn_from_port = E.from_port;
  3742. int cn_to_node = E.to_node;
  3743. int cn_to_port = E.to_port;
  3744. if (cn_from_node == id) {
  3745. 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));
  3746. if (is_incompatible_types || cn_from_port > type_size) {
  3747. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  3748. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  3749. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  3750. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  3751. }
  3752. }
  3753. }
  3754. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  3755. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  3756. }
  3757. }
  3758. }
  3759. undo_redo_man->commit_action();
  3760. }
  3761. void VisualShaderEditor::_parameter_ref_select_item(Ref<VisualShaderNodeParameterRef> p_parameter_ref, String p_name) {
  3762. String prev_name = p_parameter_ref->get_parameter_name();
  3763. if (p_name == prev_name) {
  3764. return;
  3765. }
  3766. bool type_changed = p_parameter_ref->get_parameter_type_by_name(p_name) != p_parameter_ref->get_parameter_type_by_name(prev_name);
  3767. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  3768. undo_redo_man->create_action(TTR("ParameterRef Name Changed"));
  3769. undo_redo_man->add_do_method(p_parameter_ref.ptr(), "set_parameter_name", p_name);
  3770. undo_redo_man->add_undo_method(p_parameter_ref.ptr(), "set_parameter_name", prev_name);
  3771. // update output port
  3772. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  3773. VisualShader::Type type = VisualShader::Type(type_id);
  3774. int id = visual_shader->find_node_id(type, p_parameter_ref);
  3775. if (id != VisualShader::NODE_ID_INVALID) {
  3776. if (type_changed) {
  3777. List<VisualShader::Connection> conns;
  3778. visual_shader->get_node_connections(type, &conns);
  3779. for (const VisualShader::Connection &E : conns) {
  3780. if (E.from_node == id) {
  3781. 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))) {
  3782. continue;
  3783. }
  3784. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3785. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3786. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3787. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3788. }
  3789. }
  3790. }
  3791. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  3792. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  3793. break;
  3794. }
  3795. }
  3796. undo_redo_man->commit_action();
  3797. }
  3798. void VisualShaderEditor::_varying_select_item(Ref<VisualShaderNodeVarying> p_varying, String p_name) {
  3799. String prev_name = p_varying->get_varying_name();
  3800. if (p_name == prev_name) {
  3801. return;
  3802. }
  3803. bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid();
  3804. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  3805. undo_redo_man->create_action(TTR("Varying Name Changed"));
  3806. undo_redo_man->add_do_method(p_varying.ptr(), "set_varying_name", p_name);
  3807. undo_redo_man->add_undo_method(p_varying.ptr(), "set_varying_name", prev_name);
  3808. VisualShader::VaryingType vtype = p_varying->get_varying_type_by_name(p_name);
  3809. VisualShader::VaryingType prev_vtype = p_varying->get_varying_type_by_name(prev_name);
  3810. bool type_changed = vtype != prev_vtype;
  3811. if (type_changed) {
  3812. undo_redo_man->add_do_method(p_varying.ptr(), "set_varying_type", vtype);
  3813. undo_redo_man->add_undo_method(p_varying.ptr(), "set_varying_type", prev_vtype);
  3814. }
  3815. // update ports
  3816. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  3817. VisualShader::Type type = VisualShader::Type(type_id);
  3818. int id = visual_shader->find_node_id(type, p_varying);
  3819. if (id != VisualShader::NODE_ID_INVALID) {
  3820. if (type_changed) {
  3821. List<VisualShader::Connection> conns;
  3822. visual_shader->get_node_connections(type, &conns);
  3823. for (const VisualShader::Connection &E : conns) {
  3824. if (is_getter) {
  3825. if (E.from_node == id) {
  3826. 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))) {
  3827. continue;
  3828. }
  3829. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3830. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3831. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3832. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3833. }
  3834. } else {
  3835. if (E.to_node == id) {
  3836. 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))) {
  3837. continue;
  3838. }
  3839. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3840. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3841. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3842. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3843. }
  3844. }
  3845. }
  3846. }
  3847. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  3848. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  3849. break;
  3850. }
  3851. }
  3852. undo_redo_man->commit_action();
  3853. }
  3854. void VisualShaderEditor::_float_constant_selected(int p_which) {
  3855. ERR_FAIL_INDEX(p_which, MAX_FLOAT_CONST_DEFS);
  3856. VisualShader::Type type = get_current_shader_type();
  3857. Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, selected_float_constant);
  3858. ERR_FAIL_COND(!node.is_valid());
  3859. if (Math::is_equal_approx(node->get_constant(), float_constant_defs[p_which].value)) {
  3860. return; // same
  3861. }
  3862. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3863. undo_redo->create_action(vformat(TTR("Set Constant: %s"), float_constant_defs[p_which].name));
  3864. undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_which].value);
  3865. undo_redo->add_undo_method(node.ptr(), "set_constant", node->get_constant());
  3866. undo_redo->commit_action();
  3867. }
  3868. void VisualShaderEditor::_member_filter_changed(const String &p_text) {
  3869. _update_options_menu();
  3870. }
  3871. void VisualShaderEditor::_member_selected() {
  3872. TreeItem *item = members->get_selected();
  3873. if (item != nullptr && item->has_meta("id")) {
  3874. members_dialog->get_ok_button()->set_disabled(false);
  3875. highend_label->set_visible(add_options[item->get_meta("id")].highend);
  3876. node_desc->set_text(_get_description(item->get_meta("id")));
  3877. } else {
  3878. highend_label->set_visible(false);
  3879. members_dialog->get_ok_button()->set_disabled(true);
  3880. node_desc->set_text("");
  3881. }
  3882. }
  3883. void VisualShaderEditor::_member_unselected() {
  3884. }
  3885. void VisualShaderEditor::_member_create() {
  3886. TreeItem *item = members->get_selected();
  3887. if (item != nullptr && item->has_meta("id")) {
  3888. int idx = members->get_selected()->get_meta("id");
  3889. _add_node(idx, add_options[idx].ops);
  3890. members_dialog->hide();
  3891. }
  3892. }
  3893. void VisualShaderEditor::_member_cancel() {
  3894. to_node = -1;
  3895. to_slot = -1;
  3896. from_node = -1;
  3897. from_slot = -1;
  3898. }
  3899. void VisualShaderEditor::_update_varying_tree() {
  3900. varyings->clear();
  3901. TreeItem *root = varyings->create_item();
  3902. int count = visual_shader->get_varyings_count();
  3903. for (int i = 0; i < count; i++) {
  3904. const VisualShader::Varying *varying = visual_shader->get_varying_by_index(i);
  3905. if (varying) {
  3906. TreeItem *item = varyings->create_item(root);
  3907. item->set_text(0, varying->name);
  3908. if (i == 0) {
  3909. item->select(0);
  3910. }
  3911. switch (varying->type) {
  3912. case VisualShader::VARYING_TYPE_FLOAT:
  3913. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("float"), SNAME("EditorIcons")));
  3914. break;
  3915. case VisualShader::VARYING_TYPE_INT:
  3916. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("int"), SNAME("EditorIcons")));
  3917. break;
  3918. case VisualShader::VARYING_TYPE_UINT:
  3919. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("uint"), SNAME("EditorIcons")));
  3920. break;
  3921. case VisualShader::VARYING_TYPE_VECTOR_2D:
  3922. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")));
  3923. break;
  3924. case VisualShader::VARYING_TYPE_VECTOR_3D:
  3925. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")));
  3926. break;
  3927. case VisualShader::VARYING_TYPE_VECTOR_4D:
  3928. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector4"), SNAME("EditorIcons")));
  3929. break;
  3930. case VisualShader::VARYING_TYPE_BOOLEAN:
  3931. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("bool"), SNAME("EditorIcons")));
  3932. break;
  3933. case VisualShader::VARYING_TYPE_TRANSFORM:
  3934. item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")));
  3935. break;
  3936. default:
  3937. break;
  3938. }
  3939. }
  3940. }
  3941. varying_button->get_popup()->set_item_disabled(int(VaryingMenuOptions::REMOVE), count == 0);
  3942. }
  3943. void VisualShaderEditor::_varying_create() {
  3944. _add_varying(varying_name->get_text(), (VisualShader::VaryingMode)varying_mode->get_selected(), (VisualShader::VaryingType)varying_type->get_selected());
  3945. add_varying_dialog->hide();
  3946. }
  3947. void VisualShaderEditor::_varying_name_changed(const String &p_text) {
  3948. String name = p_text;
  3949. if (!name.is_valid_identifier()) {
  3950. varying_error_label->show();
  3951. varying_error_label->set_text(TTR("Invalid name for varying."));
  3952. add_varying_dialog->get_ok_button()->set_disabled(true);
  3953. return;
  3954. }
  3955. if (visual_shader->has_varying(name)) {
  3956. varying_error_label->show();
  3957. varying_error_label->set_text(TTR("Varying with that name is already exist."));
  3958. add_varying_dialog->get_ok_button()->set_disabled(true);
  3959. return;
  3960. }
  3961. if (varying_error_label->is_visible()) {
  3962. varying_error_label->hide();
  3963. add_varying_dialog->set_size(Size2(add_varying_dialog->get_size().x, 0));
  3964. }
  3965. add_varying_dialog->get_ok_button()->set_disabled(false);
  3966. }
  3967. void VisualShaderEditor::_varying_deleted() {
  3968. TreeItem *item = varyings->get_selected();
  3969. if (item != nullptr) {
  3970. _remove_varying(item->get_text(0));
  3971. remove_varying_dialog->hide();
  3972. }
  3973. }
  3974. void VisualShaderEditor::_varying_selected() {
  3975. add_varying_dialog->get_ok_button()->set_disabled(false);
  3976. }
  3977. void VisualShaderEditor::_varying_unselected() {
  3978. add_varying_dialog->get_ok_button()->set_disabled(true);
  3979. }
  3980. void VisualShaderEditor::_tools_menu_option(int p_idx) {
  3981. TreeItem *category = members->get_root()->get_first_child();
  3982. switch (p_idx) {
  3983. case EXPAND_ALL:
  3984. while (category) {
  3985. category->set_collapsed(false);
  3986. TreeItem *sub_category = category->get_first_child();
  3987. while (sub_category) {
  3988. sub_category->set_collapsed(false);
  3989. sub_category = sub_category->get_next();
  3990. }
  3991. category = category->get_next();
  3992. }
  3993. break;
  3994. case COLLAPSE_ALL:
  3995. while (category) {
  3996. category->set_collapsed(true);
  3997. TreeItem *sub_category = category->get_first_child();
  3998. while (sub_category) {
  3999. sub_category->set_collapsed(true);
  4000. sub_category = sub_category->get_next();
  4001. }
  4002. category = category->get_next();
  4003. }
  4004. break;
  4005. default:
  4006. break;
  4007. }
  4008. }
  4009. void VisualShaderEditor::_node_menu_id_pressed(int p_idx) {
  4010. switch (p_idx) {
  4011. case NodeMenuOptions::ADD:
  4012. _show_members_dialog(true);
  4013. break;
  4014. case NodeMenuOptions::CUT:
  4015. _copy_nodes(true);
  4016. break;
  4017. case NodeMenuOptions::COPY:
  4018. _copy_nodes(false);
  4019. break;
  4020. case NodeMenuOptions::PASTE:
  4021. _paste_nodes(true, menu_point);
  4022. break;
  4023. case NodeMenuOptions::DELETE:
  4024. _delete_nodes_request(TypedArray<StringName>());
  4025. break;
  4026. case NodeMenuOptions::DUPLICATE:
  4027. _duplicate_nodes();
  4028. break;
  4029. case NodeMenuOptions::CLEAR_COPY_BUFFER:
  4030. _clear_copy_buffer();
  4031. break;
  4032. case NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS:
  4033. _convert_constants_to_parameters(false);
  4034. break;
  4035. case NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS:
  4036. _convert_constants_to_parameters(true);
  4037. break;
  4038. case NodeMenuOptions::SET_COMMENT_TITLE:
  4039. _comment_title_popup_show(get_screen_position() + get_local_mouse_position(), selected_comment);
  4040. break;
  4041. case NodeMenuOptions::SET_COMMENT_DESCRIPTION:
  4042. _comment_desc_popup_show(get_screen_position() + get_local_mouse_position(), selected_comment);
  4043. break;
  4044. default:
  4045. break;
  4046. }
  4047. }
  4048. Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  4049. if (p_from == members) {
  4050. TreeItem *it = members->get_item_at_position(p_point);
  4051. if (!it) {
  4052. return Variant();
  4053. }
  4054. if (!it->has_meta("id")) {
  4055. return Variant();
  4056. }
  4057. int id = it->get_meta("id");
  4058. AddOption op = add_options[id];
  4059. Dictionary d;
  4060. d["id"] = id;
  4061. Label *label = memnew(Label);
  4062. label->set_text(it->get_text(0));
  4063. set_drag_preview(label);
  4064. return d;
  4065. }
  4066. return Variant();
  4067. }
  4068. bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  4069. if (p_from == graph) {
  4070. Dictionary d = p_data;
  4071. if (d.has("id")) {
  4072. return true;
  4073. }
  4074. if (d.has("files")) {
  4075. return true;
  4076. }
  4077. }
  4078. return false;
  4079. }
  4080. void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  4081. if (p_from == graph) {
  4082. Dictionary d = p_data;
  4083. if (d.has("id")) {
  4084. int idx = d["id"];
  4085. saved_node_pos = p_point;
  4086. saved_node_pos_dirty = true;
  4087. _add_node(idx, add_options[idx].ops);
  4088. } else if (d.has("files")) {
  4089. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4090. undo_redo->create_action(TTR("Add Node(s) to Visual Shader"));
  4091. if (d["files"].get_type() == Variant::PACKED_STRING_ARRAY) {
  4092. PackedStringArray arr = d["files"];
  4093. for (int i = 0; i < arr.size(); i++) {
  4094. String type = ResourceLoader::get_resource_type(arr[i]);
  4095. if (type == "GDScript") {
  4096. Ref<Script> scr = ResourceLoader::load(arr[i]);
  4097. if (scr->get_instance_base_type() == "VisualShaderNodeCustom") {
  4098. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  4099. saved_node_pos_dirty = true;
  4100. int idx = -1;
  4101. for (int j = custom_node_option_idx; j < add_options.size(); j++) {
  4102. if (add_options[j].script.is_valid()) {
  4103. if (add_options[j].script->get_path() == arr[i]) {
  4104. idx = j;
  4105. break;
  4106. }
  4107. }
  4108. }
  4109. if (idx != -1) {
  4110. _add_node(idx, {}, arr[i], i);
  4111. }
  4112. }
  4113. } else if (type == "CurveTexture") {
  4114. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  4115. saved_node_pos_dirty = true;
  4116. _add_node(curve_node_option_idx, {}, arr[i], i);
  4117. } else if (type == "CurveXYZTexture") {
  4118. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  4119. saved_node_pos_dirty = true;
  4120. _add_node(curve_xyz_node_option_idx, {}, arr[i], i);
  4121. } else if (ClassDB::get_parent_class(type) == "Texture2D") {
  4122. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  4123. saved_node_pos_dirty = true;
  4124. _add_node(texture2d_node_option_idx, {}, arr[i], i);
  4125. } else if (type == "Texture2DArray") {
  4126. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  4127. saved_node_pos_dirty = true;
  4128. _add_node(texture2d_array_node_option_idx, {}, arr[i], i);
  4129. } else if (ClassDB::get_parent_class(type) == "Texture3D") {
  4130. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  4131. saved_node_pos_dirty = true;
  4132. _add_node(texture3d_node_option_idx, {}, arr[i], i);
  4133. } else if (type == "Cubemap") {
  4134. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  4135. saved_node_pos_dirty = true;
  4136. _add_node(cubemap_node_option_idx, {}, arr[i], i);
  4137. }
  4138. }
  4139. }
  4140. undo_redo->commit_action();
  4141. }
  4142. }
  4143. }
  4144. void VisualShaderEditor::_show_preview_text() {
  4145. preview_showed = !preview_showed;
  4146. if (preview_showed) {
  4147. if (preview_first) {
  4148. preview_window->set_size(Size2(400 * EDSCALE, 600 * EDSCALE));
  4149. preview_window->popup_centered();
  4150. preview_first = false;
  4151. } else {
  4152. preview_window->popup();
  4153. }
  4154. _preview_size_changed();
  4155. if (pending_update_preview) {
  4156. _update_preview();
  4157. pending_update_preview = false;
  4158. }
  4159. } else {
  4160. preview_window->hide();
  4161. }
  4162. }
  4163. void VisualShaderEditor::_preview_close_requested() {
  4164. preview_showed = false;
  4165. preview_window->hide();
  4166. preview_shader->set_pressed(false);
  4167. }
  4168. void VisualShaderEditor::_preview_size_changed() {
  4169. preview_vbox->set_custom_minimum_size(preview_window->get_size());
  4170. }
  4171. static ShaderLanguage::DataType _get_global_shader_uniform_type(const StringName &p_variable) {
  4172. RS::GlobalShaderParameterType gvt = RS::get_singleton()->global_shader_parameter_get_type(p_variable);
  4173. return (ShaderLanguage::DataType)RS::global_shader_uniform_type_get_shader_datatype(gvt);
  4174. }
  4175. void VisualShaderEditor::_update_preview() {
  4176. if (!preview_showed) {
  4177. pending_update_preview = true;
  4178. return;
  4179. }
  4180. String code = visual_shader->get_code();
  4181. preview_text->set_text(code);
  4182. ShaderLanguage::ShaderCompileInfo info;
  4183. info.functions = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(visual_shader->get_mode()));
  4184. info.render_modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(visual_shader->get_mode()));
  4185. info.shader_types = ShaderTypes::get_singleton()->get_types();
  4186. info.global_shader_uniform_type_func = _get_global_shader_uniform_type;
  4187. ShaderLanguage sl;
  4188. Error err = sl.compile(code, info);
  4189. for (int i = 0; i < preview_text->get_line_count(); i++) {
  4190. preview_text->set_line_background_color(i, Color(0, 0, 0, 0));
  4191. }
  4192. if (err != OK) {
  4193. Color error_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color");
  4194. preview_text->set_line_background_color(sl.get_error_line() - 1, error_line_color);
  4195. error_panel->show();
  4196. String text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text();
  4197. error_label->set_text(text);
  4198. shader_error = true;
  4199. } else {
  4200. error_panel->hide();
  4201. shader_error = false;
  4202. }
  4203. }
  4204. void VisualShaderEditor::_visibility_changed() {
  4205. if (!is_visible()) {
  4206. if (preview_window->is_visible()) {
  4207. preview_shader->set_pressed(false);
  4208. preview_window->hide();
  4209. preview_showed = false;
  4210. }
  4211. }
  4212. }
  4213. void VisualShaderEditor::_bind_methods() {
  4214. ClassDB::bind_method("_update_nodes", &VisualShaderEditor::_update_nodes);
  4215. ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph);
  4216. ClassDB::bind_method("_add_node", &VisualShaderEditor::_add_node);
  4217. ClassDB::bind_method("_node_changed", &VisualShaderEditor::_node_changed);
  4218. ClassDB::bind_method("_input_select_item", &VisualShaderEditor::_input_select_item);
  4219. ClassDB::bind_method("_parameter_ref_select_item", &VisualShaderEditor::_parameter_ref_select_item);
  4220. ClassDB::bind_method("_varying_select_item", &VisualShaderEditor::_varying_select_item);
  4221. ClassDB::bind_method("_set_node_size", &VisualShaderEditor::_set_node_size);
  4222. ClassDB::bind_method("_clear_copy_buffer", &VisualShaderEditor::_clear_copy_buffer);
  4223. ClassDB::bind_method("_update_parameters", &VisualShaderEditor::_update_parameters);
  4224. ClassDB::bind_method("_update_varyings", &VisualShaderEditor::_update_varyings);
  4225. ClassDB::bind_method("_update_varying_tree", &VisualShaderEditor::_update_varying_tree);
  4226. ClassDB::bind_method("_set_mode", &VisualShaderEditor::_set_mode);
  4227. ClassDB::bind_method("_nodes_dragged", &VisualShaderEditor::_nodes_dragged);
  4228. ClassDB::bind_method("_float_constant_selected", &VisualShaderEditor::_float_constant_selected);
  4229. ClassDB::bind_method("_update_constant", &VisualShaderEditor::_update_constant);
  4230. ClassDB::bind_method("_update_parameter", &VisualShaderEditor::_update_parameter);
  4231. ClassDB::bind_method("_expand_output_port", &VisualShaderEditor::_expand_output_port);
  4232. ClassDB::bind_method("_update_options_menu_deferred", &VisualShaderEditor::_update_options_menu_deferred);
  4233. ClassDB::bind_method("_rebuild_shader_deferred", &VisualShaderEditor::_rebuild_shader_deferred);
  4234. ClassDB::bind_method("_resources_removed", &VisualShaderEditor::_resources_removed);
  4235. ClassDB::bind_method("_is_available", &VisualShaderEditor::_is_available);
  4236. }
  4237. VisualShaderEditor::VisualShaderEditor() {
  4238. ShaderLanguage::get_keyword_list(&keyword_list);
  4239. EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &VisualShaderEditor::_resource_saved));
  4240. FileSystemDock::get_singleton()->get_script_create_dialog()->connect("script_created", callable_mp(this, &VisualShaderEditor::_script_created));
  4241. FileSystemDock::get_singleton()->connect("resource_removed", callable_mp(this, &VisualShaderEditor::_resource_removed));
  4242. graph = memnew(GraphEdit);
  4243. graph->get_zoom_hbox()->set_h_size_flags(SIZE_EXPAND_FILL);
  4244. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  4245. graph->set_h_size_flags(SIZE_EXPAND_FILL);
  4246. graph->set_show_zoom_label(true);
  4247. add_child(graph);
  4248. SET_DRAG_FORWARDING_GCD(graph, VisualShaderEditor);
  4249. float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity");
  4250. graph->set_minimap_opacity(graph_minimap_opacity);
  4251. float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature");
  4252. graph->set_connection_lines_curvature(graph_lines_curvature);
  4253. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR);
  4254. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_INT);
  4255. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  4256. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN);
  4257. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_2D);
  4258. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_3D);
  4259. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_4D);
  4260. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_TRANSFORM);
  4261. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SAMPLER);
  4262. //graph->add_valid_left_disconnect_type(0);
  4263. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  4264. graph->connect("connection_request", callable_mp(this, &VisualShaderEditor::_connection_request), CONNECT_DEFERRED);
  4265. graph->connect("disconnection_request", callable_mp(this, &VisualShaderEditor::_disconnection_request), CONNECT_DEFERRED);
  4266. graph->connect("node_selected", callable_mp(this, &VisualShaderEditor::_node_selected));
  4267. graph->connect("scroll_offset_changed", callable_mp(this, &VisualShaderEditor::_scroll_changed));
  4268. graph->connect("duplicate_nodes_request", callable_mp(this, &VisualShaderEditor::_duplicate_nodes));
  4269. graph->connect("copy_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes).bind(false));
  4270. graph->connect("paste_nodes_request", callable_mp(this, &VisualShaderEditor::_paste_nodes).bind(false, Point2()));
  4271. graph->connect("delete_nodes_request", callable_mp(this, &VisualShaderEditor::_delete_nodes_request));
  4272. graph->connect("gui_input", callable_mp(this, &VisualShaderEditor::_graph_gui_input));
  4273. graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty));
  4274. graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty));
  4275. graph->connect("visibility_changed", callable_mp(this, &VisualShaderEditor::_visibility_changed));
  4276. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR);
  4277. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  4278. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  4279. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  4280. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  4281. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  4282. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_BOOLEAN);
  4283. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR);
  4284. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  4285. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  4286. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  4287. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  4288. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  4289. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_BOOLEAN);
  4290. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR);
  4291. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  4292. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  4293. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  4294. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  4295. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  4296. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_BOOLEAN);
  4297. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR);
  4298. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  4299. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  4300. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  4301. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  4302. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  4303. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  4304. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR);
  4305. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  4306. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  4307. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  4308. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  4309. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  4310. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  4311. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR);
  4312. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  4313. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  4314. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  4315. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  4316. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  4317. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  4318. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR);
  4319. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  4320. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  4321. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  4322. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  4323. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  4324. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_BOOLEAN);
  4325. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShaderNode::PORT_TYPE_TRANSFORM);
  4326. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SAMPLER, VisualShaderNode::PORT_TYPE_SAMPLER);
  4327. VSeparator *vs = memnew(VSeparator);
  4328. graph->get_zoom_hbox()->add_child(vs);
  4329. graph->get_zoom_hbox()->move_child(vs, 0);
  4330. custom_mode_box = memnew(CheckBox);
  4331. custom_mode_box->set_text(TTR("Custom"));
  4332. custom_mode_box->set_pressed(false);
  4333. custom_mode_box->set_visible(false);
  4334. custom_mode_box->connect("toggled", callable_mp(this, &VisualShaderEditor::_custom_mode_toggled));
  4335. edit_type_standard = memnew(OptionButton);
  4336. edit_type_standard->add_item(TTR("Vertex"));
  4337. edit_type_standard->add_item(TTR("Fragment"));
  4338. edit_type_standard->add_item(TTR("Light"));
  4339. edit_type_standard->select(1);
  4340. edit_type_standard->connect("item_selected", callable_mp(this, &VisualShaderEditor::_mode_selected));
  4341. edit_type_particles = memnew(OptionButton);
  4342. edit_type_particles->add_item(TTR("Start"));
  4343. edit_type_particles->add_item(TTR("Process"));
  4344. edit_type_particles->add_item(TTR("Collide"));
  4345. edit_type_particles->select(0);
  4346. edit_type_particles->connect("item_selected", callable_mp(this, &VisualShaderEditor::_mode_selected));
  4347. edit_type_sky = memnew(OptionButton);
  4348. edit_type_sky->add_item(TTR("Sky"));
  4349. edit_type_sky->select(0);
  4350. edit_type_sky->connect("item_selected", callable_mp(this, &VisualShaderEditor::_mode_selected));
  4351. edit_type_fog = memnew(OptionButton);
  4352. edit_type_fog->add_item(TTR("Fog"));
  4353. edit_type_fog->select(0);
  4354. edit_type_fog->connect("item_selected", callable_mp(this, &VisualShaderEditor::_mode_selected));
  4355. edit_type = edit_type_standard;
  4356. graph->get_zoom_hbox()->add_child(custom_mode_box);
  4357. graph->get_zoom_hbox()->move_child(custom_mode_box, 0);
  4358. graph->get_zoom_hbox()->add_child(edit_type_standard);
  4359. graph->get_zoom_hbox()->move_child(edit_type_standard, 0);
  4360. graph->get_zoom_hbox()->add_child(edit_type_particles);
  4361. graph->get_zoom_hbox()->move_child(edit_type_particles, 0);
  4362. graph->get_zoom_hbox()->add_child(edit_type_sky);
  4363. graph->get_zoom_hbox()->move_child(edit_type_sky, 0);
  4364. graph->get_zoom_hbox()->add_child(edit_type_fog);
  4365. graph->get_zoom_hbox()->move_child(edit_type_fog, 0);
  4366. add_node = memnew(Button);
  4367. add_node->set_flat(true);
  4368. add_node->set_text(TTR("Add Node..."));
  4369. graph->get_zoom_hbox()->add_child(add_node);
  4370. graph->get_zoom_hbox()->move_child(add_node, 0);
  4371. add_node->connect("pressed", callable_mp(this, &VisualShaderEditor::_show_members_dialog).bind(false, VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PORT_TYPE_MAX));
  4372. varying_button = memnew(MenuButton);
  4373. varying_button->set_text(TTR("Manage Varyings"));
  4374. varying_button->set_switch_on_hover(true);
  4375. graph->get_zoom_hbox()->add_child(varying_button);
  4376. PopupMenu *varying_menu = varying_button->get_popup();
  4377. varying_menu->add_item(TTR("Add Varying"), int(VaryingMenuOptions::ADD));
  4378. varying_menu->add_item(TTR("Remove Varying"), int(VaryingMenuOptions::REMOVE));
  4379. varying_menu->connect("id_pressed", callable_mp(this, &VisualShaderEditor::_varying_menu_id_pressed));
  4380. preview_shader = memnew(Button);
  4381. preview_shader->set_flat(true);
  4382. preview_shader->set_toggle_mode(true);
  4383. preview_shader->set_tooltip_text(TTR("Show generated shader code."));
  4384. graph->get_zoom_hbox()->add_child(preview_shader);
  4385. preview_shader->connect("pressed", callable_mp(this, &VisualShaderEditor::_show_preview_text));
  4386. ///////////////////////////////////////
  4387. // PREVIEW WINDOW
  4388. ///////////////////////////////////////
  4389. preview_window = memnew(Window);
  4390. preview_window->set_title(TTR("Generated Shader Code"));
  4391. preview_window->set_visible(preview_showed);
  4392. preview_window->connect("close_requested", callable_mp(this, &VisualShaderEditor::_preview_close_requested));
  4393. preview_window->connect("size_changed", callable_mp(this, &VisualShaderEditor::_preview_size_changed));
  4394. add_child(preview_window);
  4395. preview_vbox = memnew(VBoxContainer);
  4396. preview_window->add_child(preview_vbox);
  4397. preview_vbox->add_theme_constant_override("separation", 0);
  4398. preview_text = memnew(CodeEdit);
  4399. syntax_highlighter.instantiate();
  4400. preview_vbox->add_child(preview_text);
  4401. preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  4402. preview_text->set_syntax_highlighter(syntax_highlighter);
  4403. preview_text->set_draw_line_numbers(true);
  4404. preview_text->set_editable(false);
  4405. error_panel = memnew(PanelContainer);
  4406. preview_vbox->add_child(error_panel);
  4407. error_panel->set_visible(false);
  4408. error_label = memnew(Label);
  4409. error_panel->add_child(error_label);
  4410. error_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  4411. ///////////////////////////////////////
  4412. // POPUP MENU
  4413. ///////////////////////////////////////
  4414. popup_menu = memnew(PopupMenu);
  4415. add_child(popup_menu);
  4416. popup_menu->add_item(TTR("Add Node"), NodeMenuOptions::ADD);
  4417. popup_menu->add_separator();
  4418. popup_menu->add_item(TTR("Cut"), NodeMenuOptions::CUT);
  4419. popup_menu->add_item(TTR("Copy"), NodeMenuOptions::COPY);
  4420. popup_menu->add_item(TTR("Paste"), NodeMenuOptions::PASTE);
  4421. popup_menu->add_item(TTR("Delete"), NodeMenuOptions::DELETE);
  4422. popup_menu->add_item(TTR("Duplicate"), NodeMenuOptions::DUPLICATE);
  4423. popup_menu->add_item(TTR("Clear Copy Buffer"), NodeMenuOptions::CLEAR_COPY_BUFFER);
  4424. popup_menu->connect("id_pressed", callable_mp(this, &VisualShaderEditor::_node_menu_id_pressed));
  4425. ///////////////////////////////////////
  4426. // SHADER NODES TREE
  4427. ///////////////////////////////////////
  4428. VBoxContainer *members_vb = memnew(VBoxContainer);
  4429. members_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  4430. HBoxContainer *filter_hb = memnew(HBoxContainer);
  4431. members_vb->add_child(filter_hb);
  4432. node_filter = memnew(LineEdit);
  4433. filter_hb->add_child(node_filter);
  4434. node_filter->connect("text_changed", callable_mp(this, &VisualShaderEditor::_member_filter_changed));
  4435. node_filter->connect("gui_input", callable_mp(this, &VisualShaderEditor::_sbox_input));
  4436. node_filter->set_h_size_flags(SIZE_EXPAND_FILL);
  4437. node_filter->set_placeholder(TTR("Search"));
  4438. tools = memnew(MenuButton);
  4439. filter_hb->add_child(tools);
  4440. tools->set_tooltip_text(TTR("Options"));
  4441. tools->get_popup()->connect("id_pressed", callable_mp(this, &VisualShaderEditor::_tools_menu_option));
  4442. tools->get_popup()->add_item(TTR("Expand All"), EXPAND_ALL);
  4443. tools->get_popup()->add_item(TTR("Collapse All"), COLLAPSE_ALL);
  4444. members = memnew(Tree);
  4445. members_vb->add_child(members);
  4446. SET_DRAG_FORWARDING_GCD(members, VisualShaderEditor);
  4447. members->set_h_size_flags(SIZE_EXPAND_FILL);
  4448. members->set_v_size_flags(SIZE_EXPAND_FILL);
  4449. members->set_hide_root(true);
  4450. members->set_allow_reselect(true);
  4451. members->set_hide_folding(false);
  4452. members->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE));
  4453. members->connect("item_activated", callable_mp(this, &VisualShaderEditor::_member_create));
  4454. members->connect("item_selected", callable_mp(this, &VisualShaderEditor::_member_selected));
  4455. members->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_member_unselected));
  4456. HBoxContainer *desc_hbox = memnew(HBoxContainer);
  4457. members_vb->add_child(desc_hbox);
  4458. Label *desc_label = memnew(Label);
  4459. desc_hbox->add_child(desc_label);
  4460. desc_label->set_text(TTR("Description:"));
  4461. desc_hbox->add_spacer();
  4462. highend_label = memnew(Label);
  4463. desc_hbox->add_child(highend_label);
  4464. highend_label->set_visible(false);
  4465. highend_label->set_text("Vulkan");
  4466. highend_label->set_mouse_filter(Control::MOUSE_FILTER_STOP);
  4467. highend_label->set_tooltip_text(TTR("High-end node"));
  4468. node_desc = memnew(RichTextLabel);
  4469. members_vb->add_child(node_desc);
  4470. node_desc->set_h_size_flags(SIZE_EXPAND_FILL);
  4471. node_desc->set_v_size_flags(SIZE_FILL);
  4472. node_desc->set_custom_minimum_size(Size2(0, 70 * EDSCALE));
  4473. members_dialog = memnew(ConfirmationDialog);
  4474. members_dialog->set_title(TTR("Create Shader Node"));
  4475. members_dialog->set_exclusive(false);
  4476. members_dialog->add_child(members_vb);
  4477. members_dialog->set_ok_button_text(TTR("Create"));
  4478. members_dialog->get_ok_button()->connect("pressed", callable_mp(this, &VisualShaderEditor::_member_create));
  4479. members_dialog->get_ok_button()->set_disabled(true);
  4480. members_dialog->connect("canceled", callable_mp(this, &VisualShaderEditor::_member_cancel));
  4481. add_child(members_dialog);
  4482. // add varyings dialog
  4483. {
  4484. add_varying_dialog = memnew(ConfirmationDialog);
  4485. add_varying_dialog->set_title(TTR("Create Shader Varying"));
  4486. add_varying_dialog->set_exclusive(false);
  4487. add_varying_dialog->set_ok_button_text(TTR("Create"));
  4488. add_varying_dialog->get_ok_button()->connect("pressed", callable_mp(this, &VisualShaderEditor::_varying_create));
  4489. add_varying_dialog->get_ok_button()->set_disabled(true);
  4490. add_child(add_varying_dialog);
  4491. VBoxContainer *vb = memnew(VBoxContainer);
  4492. add_varying_dialog->add_child(vb);
  4493. HBoxContainer *hb = memnew(HBoxContainer);
  4494. vb->add_child(hb);
  4495. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  4496. varying_type = memnew(OptionButton);
  4497. hb->add_child(varying_type);
  4498. varying_type->add_item("Float");
  4499. varying_type->add_item("Int");
  4500. varying_type->add_item("UInt");
  4501. varying_type->add_item("Vector2");
  4502. varying_type->add_item("Vector3");
  4503. varying_type->add_item("Vector4");
  4504. varying_type->add_item("Boolean");
  4505. varying_type->add_item("Transform");
  4506. varying_name = memnew(LineEdit);
  4507. hb->add_child(varying_name);
  4508. varying_name->set_custom_minimum_size(Size2(150 * EDSCALE, 0));
  4509. varying_name->set_h_size_flags(SIZE_EXPAND_FILL);
  4510. varying_name->connect("text_changed", callable_mp(this, &VisualShaderEditor::_varying_name_changed));
  4511. varying_mode = memnew(OptionButton);
  4512. hb->add_child(varying_mode);
  4513. varying_mode->add_item("Vertex -> [Fragment, Light]");
  4514. varying_mode->add_item("Fragment -> Light");
  4515. varying_error_label = memnew(Label);
  4516. vb->add_child(varying_error_label);
  4517. varying_error_label->set_h_size_flags(SIZE_EXPAND_FILL);
  4518. varying_error_label->hide();
  4519. }
  4520. // remove varying dialog
  4521. {
  4522. remove_varying_dialog = memnew(ConfirmationDialog);
  4523. remove_varying_dialog->set_title(TTR("Delete Shader Varying"));
  4524. remove_varying_dialog->set_exclusive(false);
  4525. remove_varying_dialog->set_ok_button_text(TTR("Delete"));
  4526. remove_varying_dialog->get_ok_button()->connect("pressed", callable_mp(this, &VisualShaderEditor::_varying_deleted));
  4527. add_child(remove_varying_dialog);
  4528. VBoxContainer *vb = memnew(VBoxContainer);
  4529. remove_varying_dialog->add_child(vb);
  4530. varyings = memnew(Tree);
  4531. vb->add_child(varyings);
  4532. varyings->set_h_size_flags(SIZE_EXPAND_FILL);
  4533. varyings->set_v_size_flags(SIZE_EXPAND_FILL);
  4534. varyings->set_hide_root(true);
  4535. varyings->set_allow_reselect(true);
  4536. varyings->set_hide_folding(false);
  4537. varyings->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE));
  4538. varyings->connect("item_activated", callable_mp(this, &VisualShaderEditor::_varying_deleted));
  4539. varyings->connect("item_selected", callable_mp(this, &VisualShaderEditor::_varying_selected));
  4540. varyings->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_varying_unselected));
  4541. }
  4542. alert = memnew(AcceptDialog);
  4543. alert->get_label()->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  4544. alert->get_label()->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  4545. alert->get_label()->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  4546. alert->get_label()->set_custom_minimum_size(Size2(400, 60) * EDSCALE);
  4547. add_child(alert);
  4548. comment_title_change_popup = memnew(PopupPanel);
  4549. comment_title_change_edit = memnew(LineEdit);
  4550. comment_title_change_edit->set_expand_to_text_length_enabled(true);
  4551. comment_title_change_edit->connect("text_changed", callable_mp(this, &VisualShaderEditor::_comment_title_text_changed));
  4552. comment_title_change_edit->connect("text_submitted", callable_mp(this, &VisualShaderEditor::_comment_title_text_submitted));
  4553. comment_title_change_popup->add_child(comment_title_change_edit);
  4554. comment_title_change_edit->reset_size();
  4555. comment_title_change_popup->reset_size();
  4556. comment_title_change_popup->connect("focus_exited", callable_mp(this, &VisualShaderEditor::_comment_title_popup_focus_out));
  4557. comment_title_change_popup->connect("popup_hide", callable_mp(this, &VisualShaderEditor::_comment_title_popup_hide));
  4558. add_child(comment_title_change_popup);
  4559. comment_desc_change_popup = memnew(PopupPanel);
  4560. VBoxContainer *comment_desc_vbox = memnew(VBoxContainer);
  4561. comment_desc_change_popup->add_child(comment_desc_vbox);
  4562. comment_desc_change_edit = memnew(TextEdit);
  4563. comment_desc_change_edit->connect("text_changed", callable_mp(this, &VisualShaderEditor::_comment_desc_text_changed));
  4564. comment_desc_vbox->add_child(comment_desc_change_edit);
  4565. comment_desc_change_edit->set_custom_minimum_size(Size2(300 * EDSCALE, 150 * EDSCALE));
  4566. comment_desc_change_edit->reset_size();
  4567. comment_desc_change_popup->reset_size();
  4568. comment_desc_change_popup->connect("focus_exited", callable_mp(this, &VisualShaderEditor::_comment_desc_confirm));
  4569. comment_desc_change_popup->connect("popup_hide", callable_mp(this, &VisualShaderEditor::_comment_desc_popup_hide));
  4570. Button *comment_desc_confirm_button = memnew(Button);
  4571. comment_desc_confirm_button->set_text(TTR("OK"));
  4572. comment_desc_vbox->add_child(comment_desc_confirm_button);
  4573. comment_desc_confirm_button->connect("pressed", callable_mp(this, &VisualShaderEditor::_comment_desc_confirm));
  4574. add_child(comment_desc_change_popup);
  4575. ///////////////////////////////////////
  4576. // SHADER NODES TREE OPTIONS
  4577. ///////////////////////////////////////
  4578. // COLOR
  4579. add_options.push_back(AddOption("ColorFunc", "Color/Common", "VisualShaderNodeColorFunc", TTR("Color function."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4580. add_options.push_back(AddOption("ColorOp", "Color/Common", "VisualShaderNodeColorOp", TTR("Color operator."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4581. add_options.push_back(AddOption("Grayscale", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Grayscale function."), { VisualShaderNodeColorFunc::FUNC_GRAYSCALE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4582. 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));
  4583. 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));
  4584. add_options.push_back(AddOption("Sepia", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Sepia function."), { VisualShaderNodeColorFunc::FUNC_SEPIA }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4585. add_options.push_back(AddOption("Burn", "Color/Operators", "VisualShaderNodeColorOp", TTR("Burn operator."), { VisualShaderNodeColorOp::OP_BURN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4586. add_options.push_back(AddOption("Darken", "Color/Operators", "VisualShaderNodeColorOp", TTR("Darken operator."), { VisualShaderNodeColorOp::OP_DARKEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4587. add_options.push_back(AddOption("Difference", "Color/Operators", "VisualShaderNodeColorOp", TTR("Difference operator."), { VisualShaderNodeColorOp::OP_DIFFERENCE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4588. add_options.push_back(AddOption("Dodge", "Color/Operators", "VisualShaderNodeColorOp", TTR("Dodge operator."), { VisualShaderNodeColorOp::OP_DODGE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4589. add_options.push_back(AddOption("HardLight", "Color/Operators", "VisualShaderNodeColorOp", TTR("HardLight operator."), { VisualShaderNodeColorOp::OP_HARD_LIGHT }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4590. add_options.push_back(AddOption("Lighten", "Color/Operators", "VisualShaderNodeColorOp", TTR("Lighten operator."), { VisualShaderNodeColorOp::OP_LIGHTEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4591. add_options.push_back(AddOption("Overlay", "Color/Operators", "VisualShaderNodeColorOp", TTR("Overlay operator."), { VisualShaderNodeColorOp::OP_OVERLAY }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4592. add_options.push_back(AddOption("Screen", "Color/Operators", "VisualShaderNodeColorOp", TTR("Screen operator."), { VisualShaderNodeColorOp::OP_SCREEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4593. add_options.push_back(AddOption("SoftLight", "Color/Operators", "VisualShaderNodeColorOp", TTR("SoftLight operator."), { VisualShaderNodeColorOp::OP_SOFT_LIGHT }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4594. add_options.push_back(AddOption("ColorConstant", "Color/Variables", "VisualShaderNodeColorConstant", TTR("Color constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  4595. add_options.push_back(AddOption("ColorParameter", "Color/Variables", "VisualShaderNodeColorParameter", TTR("Color parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  4596. // COMMON
  4597. 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));
  4598. // CONDITIONAL
  4599. const String &compare_func_desc = TTR("Returns the boolean result of the %s comparison between two parameters.");
  4600. add_options.push_back(AddOption("Equal (==)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Equal (==)")), { VisualShaderNodeCompare::FUNC_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  4601. add_options.push_back(AddOption("GreaterThan (>)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Greater Than (>)")), { VisualShaderNodeCompare::FUNC_GREATER_THAN }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  4602. 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));
  4603. 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));
  4604. 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));
  4605. 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));
  4606. add_options.push_back(AddOption("LessThan (<)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than (<)")), { VisualShaderNodeCompare::FUNC_LESS_THAN }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  4607. 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));
  4608. add_options.push_back(AddOption("NotEqual (!=)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Not Equal (!=)")), { VisualShaderNodeCompare::FUNC_NOT_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  4609. add_options.push_back(AddOption("Switch (==)", "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));
  4610. add_options.push_back(AddOption("Switch2D (==)", "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));
  4611. 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));
  4612. 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));
  4613. 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));
  4614. 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));
  4615. 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));
  4616. add_options.push_back(AddOption("Compare (==)", "Conditional/Common", "VisualShaderNodeCompare", TTR("Returns the boolean result of the comparison between two parameters."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  4617. 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));
  4618. add_options.push_back(AddOption("BooleanConstant", "Conditional/Variables", "VisualShaderNodeBooleanConstant", TTR("Boolean constant."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  4619. add_options.push_back(AddOption("BooleanParameter", "Conditional/Variables", "VisualShaderNodeBooleanParameter", TTR("Boolean parameter."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  4620. // INPUT
  4621. const String translation_gdsl = "\n\n" + TTR("Translated to '%s' in Godot Shading Language.");
  4622. const String input_param_shader_modes = TTR("'%s' input parameter for all shader modes.") + translation_gdsl;
  4623. // NODE3D-FOR-ALL
  4624. 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));
  4625. 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));
  4626. 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));
  4627. 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));
  4628. 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));
  4629. 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));
  4630. 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));
  4631. 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));
  4632. 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));
  4633. 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));
  4634. 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));
  4635. // CANVASITEM-FOR-ALL
  4636. 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));
  4637. 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));
  4638. 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));
  4639. 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));
  4640. // PARTICLES-FOR-ALL
  4641. 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));
  4642. 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));
  4643. 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));
  4644. 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));
  4645. 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));
  4646. 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));
  4647. 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));
  4648. 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));
  4649. 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));
  4650. 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));
  4651. 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));
  4652. 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));
  4653. 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));
  4654. 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));
  4655. /////////////////
  4656. add_options.push_back(AddOption("Input", "Input/Common", "VisualShaderNodeInput", TTR("Input parameter.")));
  4657. const String input_param_for_vertex_and_fragment_shader_modes = TTR("'%s' input parameter for vertex and fragment shader modes.") + translation_gdsl;
  4658. const String input_param_for_fragment_and_light_shader_modes = TTR("'%s' input parameter for fragment and light shader modes.") + translation_gdsl;
  4659. const String input_param_for_fragment_shader_mode = TTR("'%s' input parameter for fragment shader mode.") + translation_gdsl;
  4660. const String input_param_for_sky_shader_mode = TTR("'%s' input parameter for sky shader mode.") + translation_gdsl;
  4661. const String input_param_for_fog_shader_mode = TTR("'%s' input parameter for fog shader mode.") + translation_gdsl;
  4662. const String input_param_for_light_shader_mode = TTR("'%s' input parameter for light shader mode.") + translation_gdsl;
  4663. const String input_param_for_vertex_shader_mode = TTR("'%s' input parameter for vertex shader mode.") + translation_gdsl;
  4664. const String input_param_for_start_shader_mode = TTR("'%s' input parameter for start shader mode.") + translation_gdsl;
  4665. const String input_param_for_process_shader_mode = TTR("'%s' input parameter for process shader mode.") + translation_gdsl;
  4666. const String input_param_for_collide_shader_mode = TTR("'%s' input parameter for collide shader mode." + translation_gdsl);
  4667. const String input_param_for_start_and_process_shader_mode = TTR("'%s' input parameter for start and process shader modes.") + translation_gdsl;
  4668. const String input_param_for_process_and_collide_shader_mode = TTR("'%s' input parameter for process and collide shader modes.") + translation_gdsl;
  4669. const String input_param_for_vertex_and_fragment_shader_mode = TTR("'%s' input parameter for vertex and fragment shader modes.") + translation_gdsl;
  4670. // NODE3D INPUTS
  4671. 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));
  4672. 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));
  4673. 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));
  4674. 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));
  4675. 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));
  4676. 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));
  4677. 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));
  4678. 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));
  4679. 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));
  4680. 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));
  4681. 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));
  4682. 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));
  4683. 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));
  4684. 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));
  4685. 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));
  4686. 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));
  4687. 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));
  4688. 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));
  4689. 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));
  4690. 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));
  4691. 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));
  4692. 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));
  4693. 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));
  4694. 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));
  4695. 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));
  4696. 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));
  4697. 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));
  4698. add_options.push_back(AddOption("ScreenUV", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  4699. 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));
  4700. 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));
  4701. 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));
  4702. 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));
  4703. 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));
  4704. 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));
  4705. 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));
  4706. 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));
  4707. 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));
  4708. 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));
  4709. 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));
  4710. 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));
  4711. 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));
  4712. 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));
  4713. 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));
  4714. 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));
  4715. 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));
  4716. 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));
  4717. 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));
  4718. 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));
  4719. 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));
  4720. 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));
  4721. 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));
  4722. // CANVASITEM INPUTS
  4723. 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));
  4724. 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));
  4725. 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));
  4726. 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));
  4727. 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));
  4728. 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));
  4729. 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));
  4730. 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));
  4731. 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));
  4732. 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));
  4733. 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));
  4734. 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));
  4735. 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));
  4736. 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));
  4737. 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));
  4738. 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));
  4739. 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));
  4740. 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));
  4741. 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));
  4742. 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));
  4743. 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));
  4744. 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));
  4745. 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));
  4746. 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));
  4747. 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));
  4748. 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));
  4749. 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));
  4750. 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));
  4751. 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));
  4752. 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));
  4753. 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));
  4754. 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));
  4755. 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));
  4756. // SKY INPUTS
  4757. 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));
  4758. 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));
  4759. 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));
  4760. 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));
  4761. 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));
  4762. 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));
  4763. 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));
  4764. 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));
  4765. 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));
  4766. 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));
  4767. 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));
  4768. 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));
  4769. 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));
  4770. 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));
  4771. 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));
  4772. 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));
  4773. 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));
  4774. 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));
  4775. 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));
  4776. 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));
  4777. 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));
  4778. 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));
  4779. 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));
  4780. 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));
  4781. 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));
  4782. 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));
  4783. 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));
  4784. 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));
  4785. // FOG INPUTS
  4786. 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));
  4787. 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));
  4788. 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));
  4789. 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));
  4790. 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));
  4791. 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));
  4792. // PARTICLES INPUTS
  4793. 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));
  4794. 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));
  4795. // PARTICLES
  4796. add_options.push_back(AddOption("EmitParticle", "Particles", "VisualShaderNodeParticleEmit", "", {}, -1, TYPE_FLAGS_PROCESS | TYPE_FLAGS_PROCESS_CUSTOM | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  4797. add_options.push_back(AddOption("ParticleAccelerator", "Particles", "VisualShaderNodeParticleAccelerator", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  4798. add_options.push_back(AddOption("ParticleRandomness", "Particles", "VisualShaderNodeParticleRandomness", "", {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT | TYPE_FLAGS_PROCESS | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  4799. 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));
  4800. add_options.push_back(AddOption("BoxEmitter", "Particles/Emitters", "VisualShaderNodeParticleBoxEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  4801. add_options.push_back(AddOption("MeshEmitter", "Particles/Emitters", "VisualShaderNodeParticleMeshEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  4802. add_options.push_back(AddOption("RingEmitter", "Particles/Emitters", "VisualShaderNodeParticleRingEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  4803. add_options.push_back(AddOption("SphereEmitter", "Particles/Emitters", "VisualShaderNodeParticleSphereEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  4804. add_options.push_back(AddOption("ConeVelocity", "Particles/Velocity", "VisualShaderNodeParticleConeVelocity", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  4805. // SCALAR
  4806. add_options.push_back(AddOption("FloatFunc", "Scalar/Common", "VisualShaderNodeFloatFunc", TTR("Float function."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  4807. add_options.push_back(AddOption("FloatOp", "Scalar/Common", "VisualShaderNodeFloatOp", TTR("Float operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  4808. add_options.push_back(AddOption("IntFunc", "Scalar/Common", "VisualShaderNodeIntFunc", TTR("Integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  4809. add_options.push_back(AddOption("IntOp", "Scalar/Common", "VisualShaderNodeIntOp", TTR("Integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  4810. add_options.push_back(AddOption("UIntFunc", "Scalar/Common", "VisualShaderNodeUIntFunc", TTR("Unsigned integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  4811. add_options.push_back(AddOption("UIntOp", "Scalar/Common", "VisualShaderNodeUIntOp", TTR("Unsigned integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  4812. // CONSTANTS
  4813. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  4814. add_options.push_back(AddOption(float_constant_defs[i].name, "Scalar/Constants", "VisualShaderNodeFloatConstant", float_constant_defs[i].desc, { float_constant_defs[i].value }, VisualShaderNode::PORT_TYPE_SCALAR));
  4815. }
  4816. // FUNCTIONS
  4817. add_options.push_back(AddOption("Abs", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ABS }, VisualShaderNode::PORT_TYPE_SCALAR));
  4818. 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));
  4819. add_options.push_back(AddOption("ACos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ACOS }, VisualShaderNode::PORT_TYPE_SCALAR));
  4820. 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));
  4821. add_options.push_back(AddOption("ASin", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ASIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  4822. 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));
  4823. add_options.push_back(AddOption("ATan", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ATAN }, VisualShaderNode::PORT_TYPE_SCALAR));
  4824. add_options.push_back(AddOption("ATan2", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeFloatOp::OP_ATAN2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  4825. 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));
  4826. 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));
  4827. 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));
  4828. 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));
  4829. 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));
  4830. 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));
  4831. 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));
  4832. add_options.push_back(AddOption("Cos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COS }, VisualShaderNode::PORT_TYPE_SCALAR));
  4833. add_options.push_back(AddOption("CosH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COSH }, VisualShaderNode::PORT_TYPE_SCALAR));
  4834. add_options.push_back(AddOption("Degrees", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeFloatFunc::FUNC_DEGREES }, VisualShaderNode::PORT_TYPE_SCALAR));
  4835. 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));
  4836. 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));
  4837. add_options.push_back(AddOption("Exp", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-e Exponential."), { VisualShaderNodeFloatFunc::FUNC_EXP }, VisualShaderNode::PORT_TYPE_SCALAR));
  4838. add_options.push_back(AddOption("Exp2", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 Exponential."), { VisualShaderNodeFloatFunc::FUNC_EXP2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  4839. 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));
  4840. add_options.push_back(AddOption("Fract", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeFloatFunc::FUNC_FRACT }, VisualShaderNode::PORT_TYPE_SCALAR));
  4841. 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));
  4842. add_options.push_back(AddOption("Log", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Natural logarithm."), { VisualShaderNodeFloatFunc::FUNC_LOG }, VisualShaderNode::PORT_TYPE_SCALAR));
  4843. add_options.push_back(AddOption("Log2", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 logarithm."), { VisualShaderNodeFloatFunc::FUNC_LOG2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  4844. add_options.push_back(AddOption("Max", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the greater of two values."), { VisualShaderNodeFloatOp::OP_MAX }, VisualShaderNode::PORT_TYPE_SCALAR));
  4845. add_options.push_back(AddOption("Min", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the lesser of two values."), { VisualShaderNodeFloatOp::OP_MIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  4846. add_options.push_back(AddOption("Mix", "Scalar/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two scalars."), { VisualShaderNodeMix::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR));
  4847. 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));
  4848. 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));
  4849. 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));
  4850. 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));
  4851. add_options.push_back(AddOption("OneMinus (1-)", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 - scalar"), { VisualShaderNodeFloatFunc::FUNC_ONEMINUS }, VisualShaderNode::PORT_TYPE_SCALAR));
  4852. 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));
  4853. add_options.push_back(AddOption("Radians", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeFloatFunc::FUNC_RADIANS }, VisualShaderNode::PORT_TYPE_SCALAR));
  4854. add_options.push_back(AddOption("Reciprocal", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 / scalar"), { VisualShaderNodeFloatFunc::FUNC_RECIPROCAL }, VisualShaderNode::PORT_TYPE_SCALAR));
  4855. add_options.push_back(AddOption("Round", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeFloatFunc::FUNC_ROUND }, VisualShaderNode::PORT_TYPE_SCALAR));
  4856. 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));
  4857. 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));
  4858. add_options.push_back(AddOption("Sign", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SIGN }, VisualShaderNode::PORT_TYPE_SCALAR));
  4859. add_options.push_back(AddOption("Sign", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeIntFunc::FUNC_SIGN }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  4860. add_options.push_back(AddOption("Sin", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  4861. add_options.push_back(AddOption("SinH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SINH }, VisualShaderNode::PORT_TYPE_SCALAR));
  4862. add_options.push_back(AddOption("Sqrt", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SQRT }, VisualShaderNode::PORT_TYPE_SCALAR));
  4863. 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));
  4864. 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));
  4865. 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));
  4866. add_options.push_back(AddOption("Tan", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TAN }, VisualShaderNode::PORT_TYPE_SCALAR));
  4867. add_options.push_back(AddOption("TanH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TANH }, VisualShaderNode::PORT_TYPE_SCALAR));
  4868. add_options.push_back(AddOption("Trunc", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TRUNC }, VisualShaderNode::PORT_TYPE_SCALAR));
  4869. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Sums two floating-point scalars."), { VisualShaderNodeFloatOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR));
  4870. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Sums two integer scalars."), { VisualShaderNodeIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  4871. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Sums two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  4872. 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));
  4873. 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));
  4874. 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));
  4875. 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));
  4876. 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));
  4877. 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));
  4878. 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));
  4879. 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));
  4880. 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));
  4881. 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));
  4882. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Divides two floating-point scalars."), { VisualShaderNodeFloatOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR));
  4883. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Divides two integer scalars."), { VisualShaderNodeIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  4884. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Divides two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  4885. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Multiplies two floating-point scalars."), { VisualShaderNodeFloatOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR));
  4886. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Multiplies two integer scalars."), { VisualShaderNodeIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  4887. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Multiplies two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  4888. 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));
  4889. 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));
  4890. 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));
  4891. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Subtracts two floating-point scalars."), { VisualShaderNodeFloatOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR));
  4892. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Subtracts two integer scalars."), { VisualShaderNodeIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  4893. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Subtracts two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  4894. add_options.push_back(AddOption("FloatConstant", "Scalar/Variables", "VisualShaderNodeFloatConstant", TTR("Scalar floating-point constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  4895. add_options.push_back(AddOption("IntConstant", "Scalar/Variables", "VisualShaderNodeIntConstant", TTR("Scalar integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  4896. add_options.push_back(AddOption("UIntConstant", "Scalar/Variables", "VisualShaderNodeUIntConstant", TTR("Scalar unsigned integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  4897. add_options.push_back(AddOption("FloatParameter", "Scalar/Variables", "VisualShaderNodeFloatParameter", TTR("Scalar floating-point parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  4898. add_options.push_back(AddOption("IntParameter", "Scalar/Variables", "VisualShaderNodeIntParameter", TTR("Scalar integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  4899. add_options.push_back(AddOption("UIntParameter", "Scalar/Variables", "VisualShaderNodeUIntParameter", TTR("Scalar unsigned integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  4900. // SDF
  4901. {
  4902. 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));
  4903. 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));
  4904. 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));
  4905. 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));
  4906. 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));
  4907. }
  4908. // TEXTURES
  4909. add_options.push_back(AddOption("UVFunc", "Textures/Common", "VisualShaderNodeUVFunc", TTR("Function to be applied on texture coordinates."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  4910. add_options.push_back(AddOption("UVPolarCoord", "Textures/Common", "VisualShaderNodeUVPolarCoord", TTR("Polar coordinates conversion applied on texture coordinates."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  4911. cubemap_node_option_idx = add_options.size();
  4912. add_options.push_back(AddOption("CubeMap", "Textures/Functions", "VisualShaderNodeCubemap", TTR("Perform the cubic texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  4913. curve_node_option_idx = add_options.size();
  4914. add_options.push_back(AddOption("CurveTexture", "Textures/Functions", "VisualShaderNodeCurveTexture", TTR("Perform the curve texture lookup."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  4915. curve_xyz_node_option_idx = add_options.size();
  4916. add_options.push_back(AddOption("CurveXYZTexture", "Textures/Functions", "VisualShaderNodeCurveXYZTexture", TTR("Perform the three components curve texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4917. 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));
  4918. texture2d_node_option_idx = add_options.size();
  4919. add_options.push_back(AddOption("Texture2D", "Textures/Functions", "VisualShaderNodeTexture", TTR("Perform the 2D texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  4920. texture2d_array_node_option_idx = add_options.size();
  4921. add_options.push_back(AddOption("Texture2DArray", "Textures/Functions", "VisualShaderNodeTexture2DArray", TTR("Perform the 2D-array texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  4922. texture3d_node_option_idx = add_options.size();
  4923. add_options.push_back(AddOption("Texture3D", "Textures/Functions", "VisualShaderNodeTexture3D", TTR("Perform the 3D texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  4924. add_options.push_back(AddOption("UVPanning", "Textures/Functions", "VisualShaderNodeUVFunc", TTR("Apply panning function on texture coordinates."), { VisualShaderNodeUVFunc::FUNC_PANNING }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  4925. add_options.push_back(AddOption("UVScaling", "Textures/Functions", "VisualShaderNodeUVFunc", TTR("Apply scaling function on texture coordinates."), { VisualShaderNodeUVFunc::FUNC_SCALING }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  4926. add_options.push_back(AddOption("CubeMapParameter", "Textures/Variables", "VisualShaderNodeCubemapParameter", TTR("Cubic texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  4927. add_options.push_back(AddOption("Texture2DParameter", "Textures/Variables", "VisualShaderNodeTexture2DParameter", TTR("2D texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  4928. 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));
  4929. add_options.push_back(AddOption("Texture2DArrayParameter", "Textures/Variables", "VisualShaderNodeTexture2DArrayParameter", TTR("2D array of textures parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  4930. add_options.push_back(AddOption("Texture3DParameter", "Textures/Variables", "VisualShaderNodeTexture3DParameter", TTR("3D texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  4931. // TRANSFORM
  4932. add_options.push_back(AddOption("TransformFunc", "Transform/Common", "VisualShaderNodeTransformFunc", TTR("Transform function."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4933. add_options.push_back(AddOption("TransformOp", "Transform/Common", "VisualShaderNodeTransformOp", TTR("Transform operator."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4934. 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));
  4935. add_options.push_back(AddOption("TransformCompose", "Transform/Composition", "VisualShaderNodeTransformCompose", TTR("Composes transform from four vectors."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4936. add_options.push_back(AddOption("TransformDecompose", "Transform/Composition", "VisualShaderNodeTransformDecompose", TTR("Decomposes transform to four vectors.")));
  4937. add_options.push_back(AddOption("Determinant", "Transform/Functions", "VisualShaderNodeDeterminant", TTR("Calculates the determinant of a transform."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  4938. 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));
  4939. add_options.push_back(AddOption("Inverse", "Transform/Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the inverse of a transform."), { VisualShaderNodeTransformFunc::FUNC_INVERSE }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4940. add_options.push_back(AddOption("Transpose", "Transform/Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the transpose of a transform."), { VisualShaderNodeTransformFunc::FUNC_TRANSPOSE }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4941. add_options.push_back(AddOption("Add (+)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Sums two transforms."), { VisualShaderNodeTransformOp::OP_ADD }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4942. add_options.push_back(AddOption("Divide (/)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Divides two transforms."), { VisualShaderNodeTransformOp::OP_A_DIV_B }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4943. add_options.push_back(AddOption("Multiply (*)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Multiplies two transforms."), { VisualShaderNodeTransformOp::OP_AxB }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4944. 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));
  4945. add_options.push_back(AddOption("Subtract (-)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Subtracts two transforms."), { VisualShaderNodeTransformOp::OP_A_MINUS_B }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4946. add_options.push_back(AddOption("TransformVectorMult (*)", "Transform/Operators", "VisualShaderNodeTransformVecMult", TTR("Multiplies vector by transform."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4947. add_options.push_back(AddOption("TransformConstant", "Transform/Variables", "VisualShaderNodeTransformConstant", TTR("Transform constant."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4948. add_options.push_back(AddOption("TransformParameter", "Transform/Variables", "VisualShaderNodeTransformParameter", TTR("Transform parameter."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  4949. // UTILITY
  4950. 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));
  4951. 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));
  4952. add_options.push_back(AddOption("RandomRange", "Utility", "VisualShaderNodeRandomRange", TTR("Returns a random value between the minimum and maximum input values."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  4953. add_options.push_back(AddOption("Remap", "Utility", "VisualShaderNodeRemap", TTR("Remaps a given input from the input range to the output range."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  4954. // VECTOR
  4955. add_options.push_back(AddOption("VectorFunc", "Vector/Common", "VisualShaderNodeVectorFunc", TTR("Vector function."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4956. add_options.push_back(AddOption("VectorOp", "Vector/Common", "VisualShaderNodeVectorOp", TTR("Vector operator."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  4957. add_options.push_back(AddOption("VectorCompose", "Vector/Common", "VisualShaderNodeVectorCompose", TTR("Composes vector from scalars.")));
  4958. add_options.push_back(AddOption("VectorDecompose", "Vector/Common", "VisualShaderNodeVectorDecompose", TTR("Decomposes vector to scalars.")));
  4959. 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));
  4960. add_options.push_back(AddOption("Vector2Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 2D vector to two scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_2D }));
  4961. 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));
  4962. add_options.push_back(AddOption("Vector3Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 3D vector to three scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_3D }));
  4963. 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));
  4964. add_options.push_back(AddOption("Vector4Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 4D vector to four scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_4D }));
  4965. 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));
  4966. 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));
  4967. 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));
  4968. 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));
  4969. 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));
  4970. 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));
  4971. 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));
  4972. 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));
  4973. 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));
  4974. 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));
  4975. 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));
  4976. 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));
  4977. 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));
  4978. 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));
  4979. 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));
  4980. 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));
  4981. 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));
  4982. 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));
  4983. 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));
  4984. 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));
  4985. 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));
  4986. 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));
  4987. 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));
  4988. 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));
  4989. add_options.push_back(AddOption("Ceil", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer that is greater than or equal to the parameter."), { VisualShaderNodeVectorFunc::FUNC_CEIL }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  4990. 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));
  4991. 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));
  4992. 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));
  4993. 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));
  4994. 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));
  4995. 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));
  4996. 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));
  4997. 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));
  4998. 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));
  4999. 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));
  5000. 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));
  5001. 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));
  5002. 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));
  5003. 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));
  5004. 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));
  5005. 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));
  5006. 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));
  5007. 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));
  5008. 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));
  5009. 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));
  5010. 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));
  5011. 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));
  5012. 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));
  5013. 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));
  5014. add_options.push_back(AddOption("Dot", "Vector/Functions", "VisualShaderNodeDotProduct", TTR("Calculates the dot product of two vectors."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  5015. 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));
  5016. 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));
  5017. 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));
  5018. 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));
  5019. 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));
  5020. 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));
  5021. 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));
  5022. 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));
  5023. 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));
  5024. 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));
  5025. 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));
  5026. 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));
  5027. 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));
  5028. 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));
  5029. 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));
  5030. 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));
  5031. 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));
  5032. 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));
  5033. 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));
  5034. 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));
  5035. 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));
  5036. 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));
  5037. 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));
  5038. 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));
  5039. 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));
  5040. 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));
  5041. 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));
  5042. 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));
  5043. 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));
  5044. 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));
  5045. 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));
  5046. 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));
  5047. 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));
  5048. 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));
  5049. 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));
  5050. 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));
  5051. 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));
  5052. 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));
  5053. 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));
  5054. 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));
  5055. 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));
  5056. 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));
  5057. 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));
  5058. 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));
  5059. 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));
  5060. 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));
  5061. 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));
  5062. 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));
  5063. 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));
  5064. 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));
  5065. 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));
  5066. 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));
  5067. 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));
  5068. 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));
  5069. 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));
  5070. 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));
  5071. 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));
  5072. 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));
  5073. 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));
  5074. 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));
  5075. 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));
  5076. 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));
  5077. 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));
  5078. 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));
  5079. 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));
  5080. 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));
  5081. 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));
  5082. 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));
  5083. 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));
  5084. 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));
  5085. 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));
  5086. 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));
  5087. 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));
  5088. 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));
  5089. 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));
  5090. 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));
  5091. 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));
  5092. 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));
  5093. 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));
  5094. 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));
  5095. 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));
  5096. 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));
  5097. 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));
  5098. 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));
  5099. 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));
  5100. 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));
  5101. 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));
  5102. 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));
  5103. 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));
  5104. 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));
  5105. 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));
  5106. 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));
  5107. 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));
  5108. 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));
  5109. 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));
  5110. 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));
  5111. 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));
  5112. 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));
  5113. 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));
  5114. 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));
  5115. 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));
  5116. 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));
  5117. 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));
  5118. 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));
  5119. 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));
  5120. 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));
  5121. 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));
  5122. 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));
  5123. 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));
  5124. 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));
  5125. 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));
  5126. 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));
  5127. 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));
  5128. 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));
  5129. 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));
  5130. 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));
  5131. 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));
  5132. 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));
  5133. 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));
  5134. 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));
  5135. 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));
  5136. 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));
  5137. 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));
  5138. 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));
  5139. 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));
  5140. 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));
  5141. add_options.push_back(AddOption("Vector2Constant", "Vector/Variables", "VisualShaderNodeVec2Constant", TTR("2D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  5142. add_options.push_back(AddOption("Vector2Parameter", "Vector/Variables", "VisualShaderNodeVec2Parameter", TTR("2D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  5143. add_options.push_back(AddOption("Vector3Constant", "Vector/Variables", "VisualShaderNodeVec3Constant", TTR("3D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5144. add_options.push_back(AddOption("Vector3Parameter", "Vector/Variables", "VisualShaderNodeVec3Parameter", TTR("3D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5145. add_options.push_back(AddOption("Vector4Constant", "Vector/Variables", "VisualShaderNodeVec4Constant", TTR("4D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  5146. add_options.push_back(AddOption("Vector4Parameter", "Vector/Variables", "VisualShaderNodeVec4Parameter", TTR("4D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  5147. // SPECIAL
  5148. add_options.push_back(AddOption("Comment", "Special", "VisualShaderNodeComment", TTR("A rectangular area with a description string for better graph organization.")));
  5149. 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.")));
  5150. 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.")));
  5151. add_options.push_back(AddOption("ParameterRef", "Special", "VisualShaderNodeParameterRef", TTR("A reference to an existing parameter.")));
  5152. add_options.push_back(AddOption("VaryingGetter", "Special", "VisualShaderNodeVaryingGetter", TTR("Get varying parameter."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  5153. add_options.push_back(AddOption("VaryingSetter", "Special", "VisualShaderNodeVaryingSetter", TTR("Set varying parameter."), {}, -1, TYPE_FLAGS_VERTEX | TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  5154. add_options.push_back(AddOption("VaryingGetter", "Special", "VisualShaderNodeVaryingGetter", TTR("Get varying parameter."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  5155. add_options.push_back(AddOption("VaryingSetter", "Special", "VisualShaderNodeVaryingSetter", TTR("Set varying parameter."), {}, -1, TYPE_FLAGS_VERTEX | TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  5156. custom_node_option_idx = add_options.size();
  5157. /////////////////////////////////////////////////////////////////////
  5158. _update_options_menu();
  5159. Ref<VisualShaderNodePluginDefault> default_plugin;
  5160. default_plugin.instantiate();
  5161. default_plugin->set_editor(this);
  5162. add_plugin(default_plugin);
  5163. graph_plugin.instantiate();
  5164. graph_plugin->set_editor(this);
  5165. property_editor_popup = memnew(PopupPanel);
  5166. property_editor_popup->set_min_size(Size2(180, 0) * EDSCALE);
  5167. add_child(property_editor_popup);
  5168. edited_property_holder.instantiate();
  5169. }
  5170. class VisualShaderNodePluginInputEditor : public OptionButton {
  5171. GDCLASS(VisualShaderNodePluginInputEditor, OptionButton);
  5172. VisualShaderEditor *editor = nullptr;
  5173. Ref<VisualShaderNodeInput> input;
  5174. public:
  5175. void _notification(int p_what) {
  5176. switch (p_what) {
  5177. case NOTIFICATION_READY: {
  5178. connect("item_selected", callable_mp(this, &VisualShaderNodePluginInputEditor::_item_selected));
  5179. } break;
  5180. }
  5181. }
  5182. void _item_selected(int p_item) {
  5183. editor->call_deferred(SNAME("_input_select_item"), input, get_item_text(p_item));
  5184. }
  5185. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeInput> &p_input) {
  5186. editor = p_editor;
  5187. input = p_input;
  5188. Ref<Texture2D> type_icon[] = {
  5189. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("float"), SNAME("EditorIcons")),
  5190. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("int"), SNAME("EditorIcons")),
  5191. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("uint"), SNAME("EditorIcons")),
  5192. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")),
  5193. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")),
  5194. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector4"), SNAME("EditorIcons")),
  5195. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("bool"), SNAME("EditorIcons")),
  5196. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")),
  5197. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons")),
  5198. };
  5199. add_item("[None]");
  5200. int to_select = -1;
  5201. for (int i = 0; i < input->get_input_index_count(); i++) {
  5202. if (input->get_input_name() == input->get_input_index_name(i)) {
  5203. to_select = i + 1;
  5204. }
  5205. add_icon_item(type_icon[input->get_input_index_type(i)], input->get_input_index_name(i));
  5206. }
  5207. if (to_select >= 0) {
  5208. select(to_select);
  5209. }
  5210. }
  5211. };
  5212. ////////////////
  5213. class VisualShaderNodePluginVaryingEditor : public OptionButton {
  5214. GDCLASS(VisualShaderNodePluginVaryingEditor, OptionButton);
  5215. VisualShaderEditor *editor = nullptr;
  5216. Ref<VisualShaderNodeVarying> varying;
  5217. public:
  5218. void _notification(int p_what) {
  5219. if (p_what == NOTIFICATION_READY) {
  5220. connect("item_selected", callable_mp(this, &VisualShaderNodePluginVaryingEditor::_item_selected));
  5221. }
  5222. }
  5223. void _item_selected(int p_item) {
  5224. editor->call_deferred(SNAME("_varying_select_item"), varying, get_item_text(p_item));
  5225. }
  5226. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeVarying> &p_varying, VisualShader::Type p_type) {
  5227. editor = p_editor;
  5228. varying = p_varying;
  5229. Ref<Texture2D> type_icon[] = {
  5230. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("float"), SNAME("EditorIcons")),
  5231. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("int"), SNAME("EditorIcons")),
  5232. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("uint"), SNAME("EditorIcons")),
  5233. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")),
  5234. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")),
  5235. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector4"), SNAME("EditorIcons")),
  5236. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("bool"), SNAME("EditorIcons")),
  5237. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")),
  5238. };
  5239. bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid();
  5240. add_item("[None]");
  5241. int to_select = -1;
  5242. for (int i = 0, j = 0; i < varying->get_varyings_count(); i++) {
  5243. VisualShader::VaryingMode mode = varying->get_varying_mode_by_index(i);
  5244. if (is_getter) {
  5245. if (mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT) {
  5246. if (p_type != VisualShader::TYPE_LIGHT) {
  5247. j++;
  5248. continue;
  5249. }
  5250. } else {
  5251. if (p_type != VisualShader::TYPE_FRAGMENT && p_type != VisualShader::TYPE_LIGHT) {
  5252. j++;
  5253. continue;
  5254. }
  5255. }
  5256. } else {
  5257. if (mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT) {
  5258. if (p_type != VisualShader::TYPE_FRAGMENT) {
  5259. j++;
  5260. continue;
  5261. }
  5262. } else {
  5263. if (p_type != VisualShader::TYPE_VERTEX) {
  5264. j++;
  5265. continue;
  5266. }
  5267. }
  5268. }
  5269. if (varying->get_varying_name() == varying->get_varying_name_by_index(i)) {
  5270. to_select = i - j + 1;
  5271. }
  5272. add_icon_item(type_icon[varying->get_varying_type_by_index(i)], varying->get_varying_name_by_index(i));
  5273. }
  5274. if (to_select >= 0) {
  5275. select(to_select);
  5276. }
  5277. }
  5278. };
  5279. ////////////////
  5280. class VisualShaderNodePluginParameterRefEditor : public OptionButton {
  5281. GDCLASS(VisualShaderNodePluginParameterRefEditor, OptionButton);
  5282. VisualShaderEditor *editor = nullptr;
  5283. Ref<VisualShaderNodeParameterRef> parameter_ref;
  5284. public:
  5285. void _notification(int p_what) {
  5286. switch (p_what) {
  5287. case NOTIFICATION_READY: {
  5288. connect("item_selected", callable_mp(this, &VisualShaderNodePluginParameterRefEditor::_item_selected));
  5289. } break;
  5290. }
  5291. }
  5292. void _item_selected(int p_item) {
  5293. editor->call_deferred(SNAME("_parameter_ref_select_item"), parameter_ref, get_item_text(p_item));
  5294. }
  5295. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeParameterRef> &p_parameter_ref) {
  5296. editor = p_editor;
  5297. parameter_ref = p_parameter_ref;
  5298. Ref<Texture2D> type_icon[] = {
  5299. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("float"), SNAME("EditorIcons")),
  5300. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("int"), SNAME("EditorIcons")),
  5301. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("uint"), SNAME("EditorIcons")),
  5302. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("bool"), SNAME("EditorIcons")),
  5303. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")),
  5304. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")),
  5305. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector4"), SNAME("EditorIcons")),
  5306. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")),
  5307. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Color"), SNAME("EditorIcons")),
  5308. EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons")),
  5309. };
  5310. add_item("[None]");
  5311. int to_select = -1;
  5312. for (int i = 0; i < p_parameter_ref->get_parameters_count(); i++) {
  5313. if (p_parameter_ref->get_parameter_name() == p_parameter_ref->get_parameter_name_by_index(i)) {
  5314. to_select = i + 1;
  5315. }
  5316. add_icon_item(type_icon[p_parameter_ref->get_parameter_type_by_index(i)], p_parameter_ref->get_parameter_name_by_index(i));
  5317. }
  5318. if (to_select >= 0) {
  5319. select(to_select);
  5320. }
  5321. }
  5322. };
  5323. ////////////////
  5324. class VisualShaderNodePluginDefaultEditor : public VBoxContainer {
  5325. GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer);
  5326. VisualShaderEditor *editor = nullptr;
  5327. Ref<Resource> parent_resource;
  5328. int node_id = 0;
  5329. VisualShader::Type shader_type;
  5330. public:
  5331. void _property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false) {
  5332. if (p_changing) {
  5333. return;
  5334. }
  5335. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  5336. updating = true;
  5337. undo_redo->create_action(TTR("Edit Visual Property:") + " " + p_property, UndoRedo::MERGE_ENDS);
  5338. undo_redo->add_do_property(node.ptr(), p_property, p_value);
  5339. undo_redo->add_undo_property(node.ptr(), p_property, node->get(p_property));
  5340. if (p_value.get_type() == Variant::OBJECT) {
  5341. Ref<Resource> prev_res = node->get(p_property);
  5342. Ref<Resource> curr_res = p_value;
  5343. if (curr_res.is_null()) {
  5344. undo_redo->add_do_method(this, "_open_inspector", (Ref<Resource>)parent_resource.ptr());
  5345. } else {
  5346. undo_redo->add_do_method(this, "_open_inspector", (Ref<Resource>)curr_res.ptr());
  5347. }
  5348. if (!prev_res.is_null()) {
  5349. undo_redo->add_undo_method(this, "_open_inspector", (Ref<Resource>)prev_res.ptr());
  5350. } else {
  5351. undo_redo->add_undo_method(this, "_open_inspector", (Ref<Resource>)parent_resource.ptr());
  5352. }
  5353. }
  5354. if (p_property != "constant") {
  5355. VisualShaderGraphPlugin *graph_plugin = editor->get_graph_plugin();
  5356. if (graph_plugin) {
  5357. undo_redo->add_do_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  5358. undo_redo->add_undo_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  5359. }
  5360. }
  5361. undo_redo->commit_action();
  5362. updating = false;
  5363. }
  5364. void _node_changed() {
  5365. if (updating) {
  5366. return;
  5367. }
  5368. for (int i = 0; i < properties.size(); i++) {
  5369. properties[i]->update_property();
  5370. }
  5371. }
  5372. void _resource_selected(const String &p_path, Ref<Resource> p_resource) {
  5373. _open_inspector(p_resource);
  5374. }
  5375. void _open_inspector(Ref<Resource> p_resource) {
  5376. InspectorDock::get_inspector_singleton()->edit(p_resource.ptr());
  5377. }
  5378. bool updating = false;
  5379. Ref<VisualShaderNode> node;
  5380. Vector<EditorProperty *> properties;
  5381. Vector<Label *> prop_names;
  5382. void _show_prop_names(bool p_show) {
  5383. for (int i = 0; i < prop_names.size(); i++) {
  5384. prop_names[i]->set_visible(p_show);
  5385. }
  5386. }
  5387. void setup(VisualShaderEditor *p_editor, Ref<Resource> p_parent_resource, Vector<EditorProperty *> p_properties, const Vector<StringName> &p_names, const HashMap<StringName, String> &p_overrided_names, Ref<VisualShaderNode> p_node) {
  5388. editor = p_editor;
  5389. parent_resource = p_parent_resource;
  5390. updating = false;
  5391. node = p_node;
  5392. properties = p_properties;
  5393. node_id = (int)p_node->get_meta("id");
  5394. shader_type = VisualShader::Type((int)p_node->get_meta("shader_type"));
  5395. for (int i = 0; i < p_properties.size(); i++) {
  5396. HBoxContainer *hbox = memnew(HBoxContainer);
  5397. hbox->set_h_size_flags(SIZE_EXPAND_FILL);
  5398. add_child(hbox);
  5399. Label *prop_name = memnew(Label);
  5400. String prop_name_str = p_names[i];
  5401. if (p_overrided_names.has(p_names[i])) {
  5402. prop_name_str = p_overrided_names[p_names[i]] + ":";
  5403. } else {
  5404. prop_name_str = prop_name_str.capitalize() + ":";
  5405. }
  5406. prop_name->set_text(prop_name_str);
  5407. prop_name->set_visible(false);
  5408. hbox->add_child(prop_name);
  5409. prop_names.push_back(prop_name);
  5410. p_properties[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  5411. hbox->add_child(p_properties[i]);
  5412. bool res_prop = Object::cast_to<EditorPropertyResource>(p_properties[i]);
  5413. if (res_prop) {
  5414. p_properties[i]->connect("resource_selected", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_resource_selected));
  5415. }
  5416. properties[i]->connect("property_changed", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_property_changed));
  5417. properties[i]->set_object_and_property(node.ptr(), p_names[i]);
  5418. properties[i]->update_property();
  5419. properties[i]->set_name_split_ratio(0);
  5420. }
  5421. node->connect("changed", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_node_changed));
  5422. }
  5423. static void _bind_methods() {
  5424. ClassDB::bind_method("_open_inspector", &VisualShaderNodePluginDefaultEditor::_open_inspector); // Used by UndoRedo.
  5425. ClassDB::bind_method("_show_prop_names", &VisualShaderNodePluginDefaultEditor::_show_prop_names); // Used with call_deferred.
  5426. }
  5427. };
  5428. Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) {
  5429. Ref<VisualShader> p_shader = Ref<VisualShader>(p_parent_resource.ptr());
  5430. if (p_shader.is_valid() && (p_node->is_class("VisualShaderNodeVaryingGetter") || p_node->is_class("VisualShaderNodeVaryingSetter"))) {
  5431. VisualShaderNodePluginVaryingEditor *editor = memnew(VisualShaderNodePluginVaryingEditor);
  5432. editor->setup(vseditor, p_node, p_shader->get_shader_type());
  5433. return editor;
  5434. }
  5435. if (p_node->is_class("VisualShaderNodeParameterRef")) {
  5436. VisualShaderNodePluginParameterRefEditor *editor = memnew(VisualShaderNodePluginParameterRefEditor);
  5437. editor->setup(vseditor, p_node);
  5438. return editor;
  5439. }
  5440. if (p_node->is_class("VisualShaderNodeInput")) {
  5441. VisualShaderNodePluginInputEditor *editor = memnew(VisualShaderNodePluginInputEditor);
  5442. editor->setup(vseditor, p_node);
  5443. return editor;
  5444. }
  5445. Vector<StringName> properties = p_node->get_editable_properties();
  5446. if (properties.size() == 0) {
  5447. return nullptr;
  5448. }
  5449. List<PropertyInfo> props;
  5450. p_node->get_property_list(&props);
  5451. Vector<PropertyInfo> pinfo;
  5452. for (const PropertyInfo &E : props) {
  5453. for (int i = 0; i < properties.size(); i++) {
  5454. if (E.name == String(properties[i])) {
  5455. pinfo.push_back(E);
  5456. }
  5457. }
  5458. }
  5459. if (pinfo.size() == 0) {
  5460. return nullptr;
  5461. }
  5462. properties.clear();
  5463. Ref<VisualShaderNode> node = p_node;
  5464. Vector<EditorProperty *> editors;
  5465. for (int i = 0; i < pinfo.size(); i++) {
  5466. EditorProperty *prop = EditorInspector::instantiate_property_editor(node.ptr(), pinfo[i].type, pinfo[i].name, pinfo[i].hint, pinfo[i].hint_string, pinfo[i].usage);
  5467. if (!prop) {
  5468. return nullptr;
  5469. }
  5470. if (Object::cast_to<EditorPropertyResource>(prop)) {
  5471. Object::cast_to<EditorPropertyResource>(prop)->set_use_sub_inspector(false);
  5472. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  5473. } else if (Object::cast_to<EditorPropertyTransform3D>(prop) || Object::cast_to<EditorPropertyVector3>(prop)) {
  5474. prop->set_custom_minimum_size(Size2(250 * EDSCALE, 0));
  5475. } else if (Object::cast_to<EditorPropertyQuaternion>(prop)) {
  5476. prop->set_custom_minimum_size(Size2(320 * EDSCALE, 0));
  5477. } else if (Object::cast_to<EditorPropertyFloat>(prop)) {
  5478. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  5479. } else if (Object::cast_to<EditorPropertyEnum>(prop)) {
  5480. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  5481. Object::cast_to<EditorPropertyEnum>(prop)->set_option_button_clip(false);
  5482. }
  5483. editors.push_back(prop);
  5484. properties.push_back(pinfo[i].name);
  5485. }
  5486. VisualShaderNodePluginDefaultEditor *editor = memnew(VisualShaderNodePluginDefaultEditor);
  5487. editor->setup(vseditor, p_parent_resource, editors, properties, p_node->get_editable_properties_names(), p_node);
  5488. return editor;
  5489. }
  5490. void EditorPropertyVisualShaderMode::_option_selected(int p_which) {
  5491. Ref<VisualShader> visual_shader(Object::cast_to<VisualShader>(get_edited_object()));
  5492. if (visual_shader->get_mode() == p_which) {
  5493. return;
  5494. }
  5495. ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader"));
  5496. if (!shader_editor) {
  5497. return;
  5498. }
  5499. VisualShaderEditor *editor = shader_editor->get_visual_shader_editor(visual_shader);
  5500. if (!editor) {
  5501. return;
  5502. }
  5503. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  5504. undo_redo->create_action(TTR("Visual Shader Mode Changed"));
  5505. //do is easy
  5506. undo_redo->add_do_method(visual_shader.ptr(), "set_mode", p_which);
  5507. undo_redo->add_undo_method(visual_shader.ptr(), "set_mode", visual_shader->get_mode());
  5508. undo_redo->add_do_method(editor, "_set_mode", p_which);
  5509. undo_redo->add_undo_method(editor, "_set_mode", visual_shader->get_mode());
  5510. //now undo is hell
  5511. //1. restore connections to output
  5512. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  5513. VisualShader::Type type = VisualShader::Type(i);
  5514. List<VisualShader::Connection> conns;
  5515. visual_shader->get_node_connections(type, &conns);
  5516. for (const VisualShader::Connection &E : conns) {
  5517. if (E.to_node == VisualShader::NODE_ID_OUTPUT) {
  5518. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  5519. }
  5520. }
  5521. }
  5522. //2. restore input indices
  5523. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  5524. VisualShader::Type type = VisualShader::Type(i);
  5525. Vector<int> nodes = visual_shader->get_node_list(type);
  5526. for (int j = 0; j < nodes.size(); j++) {
  5527. Ref<VisualShaderNodeInput> input = visual_shader->get_node(type, nodes[j]);
  5528. if (!input.is_valid()) {
  5529. continue;
  5530. }
  5531. undo_redo->add_undo_method(input.ptr(), "set_input_name", input->get_input_name());
  5532. }
  5533. }
  5534. //3. restore enums and flags
  5535. List<PropertyInfo> props;
  5536. visual_shader->get_property_list(&props);
  5537. for (const PropertyInfo &E : props) {
  5538. if (E.name.begins_with("flags/") || E.name.begins_with("modes/")) {
  5539. undo_redo->add_undo_property(visual_shader.ptr(), E.name, visual_shader->get(E.name));
  5540. }
  5541. }
  5542. //4. delete varyings (if needed)
  5543. if (p_which == VisualShader::MODE_PARTICLES || p_which == VisualShader::MODE_SKY || p_which == VisualShader::MODE_FOG) {
  5544. int var_count = visual_shader->get_varyings_count();
  5545. if (var_count > 0) {
  5546. for (int i = 0; i < var_count; i++) {
  5547. const VisualShader::Varying *var = visual_shader->get_varying_by_index(i);
  5548. undo_redo->add_do_method(visual_shader.ptr(), "remove_varying", var->name);
  5549. undo_redo->add_undo_method(visual_shader.ptr(), "add_varying", var->name, var->mode, var->type);
  5550. }
  5551. undo_redo->add_do_method(editor, "_update_varyings");
  5552. undo_redo->add_undo_method(editor, "_update_varyings");
  5553. }
  5554. }
  5555. undo_redo->add_do_method(editor, "_update_nodes");
  5556. undo_redo->add_undo_method(editor, "_update_nodes");
  5557. undo_redo->add_do_method(editor, "_update_graph");
  5558. undo_redo->add_undo_method(editor, "_update_graph");
  5559. undo_redo->commit_action();
  5560. }
  5561. void EditorPropertyVisualShaderMode::update_property() {
  5562. int which = get_edited_object()->get(get_edited_property());
  5563. options->select(which);
  5564. }
  5565. void EditorPropertyVisualShaderMode::setup(const Vector<String> &p_options) {
  5566. for (int i = 0; i < p_options.size(); i++) {
  5567. options->add_item(p_options[i], i);
  5568. }
  5569. }
  5570. void EditorPropertyVisualShaderMode::set_option_button_clip(bool p_enable) {
  5571. options->set_clip_text(p_enable);
  5572. }
  5573. void EditorPropertyVisualShaderMode::_bind_methods() {
  5574. }
  5575. EditorPropertyVisualShaderMode::EditorPropertyVisualShaderMode() {
  5576. options = memnew(OptionButton);
  5577. options->set_clip_text(true);
  5578. add_child(options);
  5579. add_focusable(options);
  5580. options->connect("item_selected", callable_mp(this, &EditorPropertyVisualShaderMode::_option_selected));
  5581. }
  5582. bool EditorInspectorVisualShaderModePlugin::can_handle(Object *p_object) {
  5583. return true; // Can handle everything.
  5584. }
  5585. 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) {
  5586. if (p_path == "mode" && p_object->is_class("VisualShader") && p_type == Variant::INT) {
  5587. EditorPropertyVisualShaderMode *mode_editor = memnew(EditorPropertyVisualShaderMode);
  5588. Vector<String> options = p_hint_text.split(",");
  5589. mode_editor->setup(options);
  5590. add_property_editor(p_path, mode_editor);
  5591. return true;
  5592. }
  5593. return false;
  5594. }
  5595. //////////////////////////////////
  5596. void VisualShaderNodePortPreview::_shader_changed() {
  5597. if (shader.is_null()) {
  5598. return;
  5599. }
  5600. Vector<VisualShader::DefaultTextureParam> default_textures;
  5601. String shader_code = shader->generate_preview_shader(type, node, port, default_textures);
  5602. Ref<Shader> preview_shader;
  5603. preview_shader.instantiate();
  5604. preview_shader->set_code(shader_code);
  5605. for (int i = 0; i < default_textures.size(); i++) {
  5606. for (int j = 0; j < default_textures[i].params.size(); j++) {
  5607. preview_shader->set_default_texture_parameter(default_textures[i].name, default_textures[i].params[j], j);
  5608. }
  5609. }
  5610. Ref<ShaderMaterial> mat;
  5611. mat.instantiate();
  5612. mat->set_shader(preview_shader);
  5613. //find if a material is also being edited and copy parameters to this one
  5614. for (int i = EditorNode::get_singleton()->get_editor_selection_history()->get_path_size() - 1; i >= 0; i--) {
  5615. Object *object = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_selection_history()->get_path_object(i));
  5616. ShaderMaterial *src_mat;
  5617. if (!object) {
  5618. continue;
  5619. }
  5620. if (object->has_method("get_material_override")) { // trying getting material from MeshInstance
  5621. src_mat = Object::cast_to<ShaderMaterial>(object->call("get_material_override"));
  5622. } else if (object->has_method("get_material")) { // from CanvasItem/Node2D
  5623. src_mat = Object::cast_to<ShaderMaterial>(object->call("get_material"));
  5624. } else {
  5625. src_mat = Object::cast_to<ShaderMaterial>(object);
  5626. }
  5627. if (src_mat && src_mat->get_shader().is_valid()) {
  5628. List<PropertyInfo> params;
  5629. src_mat->get_shader()->get_shader_uniform_list(&params);
  5630. for (const PropertyInfo &E : params) {
  5631. mat->set(E.name, src_mat->get(E.name));
  5632. }
  5633. }
  5634. }
  5635. set_material(mat);
  5636. }
  5637. void VisualShaderNodePortPreview::setup(const Ref<VisualShader> &p_shader, VisualShader::Type p_type, int p_node, int p_port) {
  5638. shader = p_shader;
  5639. shader->connect("changed", callable_mp(this, &VisualShaderNodePortPreview::_shader_changed));
  5640. type = p_type;
  5641. port = p_port;
  5642. node = p_node;
  5643. queue_redraw();
  5644. _shader_changed();
  5645. }
  5646. Size2 VisualShaderNodePortPreview::get_minimum_size() const {
  5647. int port_preview_size = EDITOR_GET("editors/visual_editors/visual_shader/port_preview_size");
  5648. return Size2(port_preview_size, port_preview_size) * EDSCALE;
  5649. }
  5650. void VisualShaderNodePortPreview::_notification(int p_what) {
  5651. switch (p_what) {
  5652. case NOTIFICATION_DRAW: {
  5653. Vector<Vector2> points = {
  5654. Vector2(),
  5655. Vector2(get_size().width, 0),
  5656. get_size(),
  5657. Vector2(0, get_size().height)
  5658. };
  5659. Vector<Vector2> uvs = {
  5660. Vector2(0, 0),
  5661. Vector2(1, 0),
  5662. Vector2(1, 1),
  5663. Vector2(0, 1)
  5664. };
  5665. Vector<Color> colors = {
  5666. Color(1, 1, 1, 1),
  5667. Color(1, 1, 1, 1),
  5668. Color(1, 1, 1, 1),
  5669. Color(1, 1, 1, 1)
  5670. };
  5671. draw_primitive(points, colors, uvs);
  5672. } break;
  5673. }
  5674. }
  5675. void VisualShaderNodePortPreview::_bind_methods() {
  5676. }
  5677. //////////////////////////////////
  5678. String VisualShaderConversionPlugin::converts_to() const {
  5679. return "Shader";
  5680. }
  5681. bool VisualShaderConversionPlugin::handles(const Ref<Resource> &p_resource) const {
  5682. Ref<VisualShader> vshader = p_resource;
  5683. return vshader.is_valid();
  5684. }
  5685. Ref<Resource> VisualShaderConversionPlugin::convert(const Ref<Resource> &p_resource) const {
  5686. Ref<VisualShader> vshader = p_resource;
  5687. ERR_FAIL_COND_V(!vshader.is_valid(), Ref<Resource>());
  5688. Ref<Shader> shader;
  5689. shader.instantiate();
  5690. String code = vshader->get_code();
  5691. shader->set_code(code);
  5692. return shader;
  5693. }