visual_shader_editor_plugin.cpp 440 KB

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