visual_shader_editor_plugin.cpp 367 KB

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