visual_shader_editor_plugin.cpp 364 KB

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