visual_shader_editor_plugin.cpp 338 KB

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