visual_shader_editor_plugin.cpp 404 KB

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