visual_shader_editor_plugin.cpp 444 KB

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