visual_shader_editor_plugin.cpp 429 KB

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