visual_shader_editor_plugin.cpp 334 KB

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