visual_shader_editor_plugin.cpp 336 KB

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