visual_shader_editor_plugin.cpp 421 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095
  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(), 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, TextureButton *p_button) {
  464. links[p_node_id].output_ports.insert(p_port, { 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_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_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, 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 (const 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::_clear_preview_param() {
  1678. selected_param_id = "";
  1679. current_prop = nullptr;
  1680. if (param_vbox2->get_child_count() > 0) {
  1681. param_vbox2->remove_child(param_vbox2->get_child(0));
  1682. }
  1683. param_vbox->hide();
  1684. }
  1685. void VisualShaderEditor::_update_preview_parameter_list() {
  1686. material_editor->edit(preview_material.ptr(), env);
  1687. List<PropertyInfo> properties;
  1688. RenderingServer::get_singleton()->get_shader_parameter_list(visual_shader->get_rid(), &properties);
  1689. HashSet<String> params_to_remove;
  1690. for (const KeyValue<String, PropertyInfo> &E : parameter_props) {
  1691. params_to_remove.insert(E.key);
  1692. }
  1693. parameter_props.clear();
  1694. for (const PropertyInfo &prop : properties) {
  1695. String param_name = prop.name;
  1696. if (visual_shader->_has_preview_shader_parameter(param_name)) {
  1697. preview_material->set_shader_parameter(param_name, visual_shader->_get_preview_shader_parameter(param_name));
  1698. } else {
  1699. preview_material->set_shader_parameter(param_name, RenderingServer::get_singleton()->shader_get_parameter_default(visual_shader->get_rid(), param_name));
  1700. }
  1701. parameter_props.insert(param_name, prop);
  1702. params_to_remove.erase(param_name);
  1703. if (param_name == selected_param_id) {
  1704. current_prop->update_property();
  1705. current_prop->update_editor_property_status();
  1706. current_prop->update_cache();
  1707. }
  1708. }
  1709. _update_preview_parameter_tree();
  1710. // Removes invalid parameters.
  1711. for (const String &param_name : params_to_remove) {
  1712. preview_material->set_shader_parameter(param_name, Variant());
  1713. if (visual_shader->_has_preview_shader_parameter(param_name)) {
  1714. visual_shader->_set_preview_shader_parameter(param_name, Variant());
  1715. }
  1716. if (param_name == selected_param_id) {
  1717. _clear_preview_param();
  1718. }
  1719. }
  1720. }
  1721. void VisualShaderEditor::_update_nodes() {
  1722. clear_custom_types();
  1723. Dictionary added;
  1724. // Add GDScript classes.
  1725. {
  1726. List<StringName> class_list;
  1727. ScriptServer::get_global_class_list(&class_list);
  1728. for (const StringName &E : class_list) {
  1729. if (ScriptServer::get_global_class_native_base(E) == "VisualShaderNodeCustom") {
  1730. String script_path = ScriptServer::get_global_class_path(E);
  1731. Ref<Resource> res = ResourceLoader::load(script_path);
  1732. ERR_CONTINUE(res.is_null());
  1733. ERR_CONTINUE(!res->is_class("Script"));
  1734. Ref<Script> scr = Ref<Script>(res);
  1735. Ref<VisualShaderNodeCustom> ref;
  1736. ref.instantiate();
  1737. ref->set_script(scr);
  1738. if (!ref->is_available(visual_shader->get_mode(), visual_shader->get_shader_type())) {
  1739. continue;
  1740. }
  1741. Dictionary dict = get_custom_node_data(ref);
  1742. dict["type"] = String();
  1743. String key;
  1744. key = String(dict["category"]) + "/" + String(dict["name"]);
  1745. added[key] = dict;
  1746. }
  1747. }
  1748. }
  1749. // Add GDExtension classes.
  1750. {
  1751. List<StringName> class_list;
  1752. ClassDB::get_class_list(&class_list);
  1753. for (const StringName &E : class_list) {
  1754. if (ClassDB::get_parent_class(E) == "VisualShaderNodeCustom") {
  1755. Object *instance = ClassDB::instantiate(E);
  1756. Ref<VisualShaderNodeCustom> ref = Object::cast_to<VisualShaderNodeCustom>(instance);
  1757. ERR_CONTINUE(ref.is_null());
  1758. if (!ref->is_available(visual_shader->get_mode(), visual_shader->get_shader_type())) {
  1759. continue;
  1760. }
  1761. Dictionary dict = get_custom_node_data(ref);
  1762. dict["type"] = E;
  1763. dict["script"] = Ref<Script>();
  1764. String key;
  1765. key = String(dict["category"]) + "/" + String(dict["name"]);
  1766. added[key] = dict;
  1767. }
  1768. }
  1769. }
  1770. // Disables not-supported copied items.
  1771. {
  1772. for (CopyItem &item : copy_items_buffer) {
  1773. Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(item.node.ptr());
  1774. if (custom.is_valid()) {
  1775. if (!custom->is_available(visual_shader->get_mode(), visual_shader->get_shader_type())) {
  1776. item.disabled = true;
  1777. } else {
  1778. item.disabled = false;
  1779. }
  1780. } else {
  1781. for (int i = 0; i < add_options.size(); i++) {
  1782. if (add_options[i].type == item.node->get_class_name()) {
  1783. if ((add_options[i].func != visual_shader->get_mode() && add_options[i].func != -1) || !_is_available(add_options[i].mode)) {
  1784. item.disabled = true;
  1785. } else {
  1786. item.disabled = false;
  1787. }
  1788. break;
  1789. }
  1790. }
  1791. }
  1792. }
  1793. }
  1794. Array keys = added.keys();
  1795. keys.sort();
  1796. for (int i = 0; i < keys.size(); i++) {
  1797. const Variant &key = keys.get(i);
  1798. const Dictionary &value = (Dictionary)added[key];
  1799. add_custom_type(value["name"], value["type"], value["script"], value["description"], value["return_icon_type"], value["category"], value["highend"]);
  1800. }
  1801. _update_options_menu();
  1802. }
  1803. String VisualShaderEditor::_get_description(int p_idx) {
  1804. return add_options[p_idx].description;
  1805. }
  1806. void VisualShaderEditor::_update_options_menu() {
  1807. node_desc->set_text("");
  1808. members_dialog->get_ok_button()->set_disabled(true);
  1809. members->clear();
  1810. TreeItem *root = members->create_item();
  1811. String filter = node_filter->get_text().strip_edges();
  1812. bool use_filter = !filter.is_empty();
  1813. bool is_first_item = true;
  1814. Color unsupported_color = get_theme_color(SNAME("error_color"), EditorStringName(Editor));
  1815. Color supported_color = get_theme_color(SNAME("warning_color"), EditorStringName(Editor));
  1816. static bool low_driver = GLOBAL_GET("rendering/renderer/rendering_method") == "gl_compatibility";
  1817. HashMap<String, TreeItem *> folders;
  1818. int current_func = -1;
  1819. if (!visual_shader.is_null()) {
  1820. current_func = visual_shader->get_mode();
  1821. }
  1822. Vector<AddOption> custom_options;
  1823. Vector<AddOption> embedded_options;
  1824. static Vector<String> type_filter_exceptions;
  1825. if (type_filter_exceptions.is_empty()) {
  1826. type_filter_exceptions.append("VisualShaderNodeExpression");
  1827. type_filter_exceptions.append("VisualShaderNodeReroute");
  1828. }
  1829. for (int i = 0; i < add_options.size(); i++) {
  1830. if (!use_filter || add_options[i].name.containsn(filter)) {
  1831. // port type filtering
  1832. if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX || members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1833. Ref<VisualShaderNode> vsn;
  1834. int check_result = 0;
  1835. if (!add_options[i].is_custom) {
  1836. vsn = Ref<VisualShaderNode>(Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[i].type)));
  1837. if (!vsn.is_valid()) {
  1838. continue;
  1839. }
  1840. if (type_filter_exceptions.has(add_options[i].type)) {
  1841. check_result = 1;
  1842. }
  1843. Ref<VisualShaderNodeInput> input = Object::cast_to<VisualShaderNodeInput>(vsn.ptr());
  1844. if (input.is_valid()) {
  1845. input->set_shader_mode(visual_shader->get_mode());
  1846. input->set_shader_type(visual_shader->get_shader_type());
  1847. if (!add_options[i].ops.is_empty() && add_options[i].ops[0].is_string()) {
  1848. input->set_input_name((String)add_options[i].ops[0]);
  1849. }
  1850. }
  1851. Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(vsn.ptr());
  1852. if (expression.is_valid()) {
  1853. if (members_input_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) {
  1854. check_result = -1; // expressions creates a port with required type automatically (except for sampler output)
  1855. }
  1856. }
  1857. Ref<VisualShaderNodeParameterRef> parameter_ref = Object::cast_to<VisualShaderNodeParameterRef>(vsn.ptr());
  1858. if (parameter_ref.is_valid() && parameter_ref->is_shader_valid()) {
  1859. check_result = -1;
  1860. if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1861. for (int j = 0; j < parameter_ref->get_parameters_count(); j++) {
  1862. if (visual_shader->is_port_types_compatible(parameter_ref->get_port_type_by_index(j), members_input_port_type)) {
  1863. check_result = 1;
  1864. break;
  1865. }
  1866. }
  1867. }
  1868. }
  1869. } else {
  1870. check_result = 1;
  1871. }
  1872. if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1873. if (check_result == 0) {
  1874. for (int j = 0; j < vsn->get_input_port_count(); j++) {
  1875. if (visual_shader->is_port_types_compatible(vsn->get_input_port_type(j), members_output_port_type)) {
  1876. check_result = 1;
  1877. break;
  1878. }
  1879. }
  1880. }
  1881. if (check_result != 1) {
  1882. continue;
  1883. }
  1884. }
  1885. if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) {
  1886. if (check_result == 0) {
  1887. for (int j = 0; j < vsn->get_output_port_count(); j++) {
  1888. if (visual_shader->is_port_types_compatible(vsn->get_output_port_type(j), members_input_port_type)) {
  1889. check_result = 1;
  1890. break;
  1891. }
  1892. }
  1893. }
  1894. if (check_result != 1) {
  1895. continue;
  1896. }
  1897. }
  1898. }
  1899. if ((add_options[i].func != current_func && add_options[i].func != -1) || !_is_available(add_options[i].mode)) {
  1900. continue;
  1901. }
  1902. const_cast<AddOption &>(add_options[i]).temp_idx = i; // save valid id
  1903. if (add_options[i].is_custom) {
  1904. custom_options.push_back(add_options[i]);
  1905. } else {
  1906. embedded_options.push_back(add_options[i]);
  1907. }
  1908. }
  1909. }
  1910. Vector<AddOption> options;
  1911. SortArray<AddOption, _OptionComparator> sorter;
  1912. sorter.sort(custom_options.ptrw(), custom_options.size());
  1913. options.append_array(custom_options);
  1914. options.append_array(embedded_options);
  1915. for (int i = 0; i < options.size(); i++) {
  1916. String path = options[i].category;
  1917. Vector<String> subfolders = path.split("/");
  1918. TreeItem *category = nullptr;
  1919. if (!folders.has(path)) {
  1920. category = root;
  1921. String path_temp = "";
  1922. for (int j = 0; j < subfolders.size(); j++) {
  1923. path_temp += subfolders[j];
  1924. if (!folders.has(path_temp)) {
  1925. category = members->create_item(category);
  1926. category->set_selectable(0, false);
  1927. category->set_collapsed(!use_filter);
  1928. category->set_text(0, subfolders[j]);
  1929. folders.insert(path_temp, category);
  1930. } else {
  1931. category = folders[path_temp];
  1932. }
  1933. }
  1934. } else {
  1935. category = folders[path];
  1936. }
  1937. TreeItem *item = members->create_item(category);
  1938. if (options[i].highend && low_driver) {
  1939. item->set_custom_color(0, unsupported_color);
  1940. } else if (options[i].highend) {
  1941. item->set_custom_color(0, supported_color);
  1942. }
  1943. item->set_text(0, options[i].name);
  1944. if (is_first_item && use_filter) {
  1945. item->select(0);
  1946. node_desc->set_text(options[i].description);
  1947. is_first_item = false;
  1948. }
  1949. switch (options[i].return_type) {
  1950. case VisualShaderNode::PORT_TYPE_SCALAR:
  1951. item->set_icon(0, get_editor_theme_icon(SNAME("float")));
  1952. break;
  1953. case VisualShaderNode::PORT_TYPE_SCALAR_INT:
  1954. item->set_icon(0, get_editor_theme_icon(SNAME("int")));
  1955. break;
  1956. case VisualShaderNode::PORT_TYPE_SCALAR_UINT:
  1957. item->set_icon(0, get_editor_theme_icon(SNAME("uint")));
  1958. break;
  1959. case VisualShaderNode::PORT_TYPE_VECTOR_2D:
  1960. item->set_icon(0, get_editor_theme_icon(SNAME("Vector2")));
  1961. break;
  1962. case VisualShaderNode::PORT_TYPE_VECTOR_3D:
  1963. item->set_icon(0, get_editor_theme_icon(SNAME("Vector3")));
  1964. break;
  1965. case VisualShaderNode::PORT_TYPE_VECTOR_4D:
  1966. item->set_icon(0, get_editor_theme_icon(SNAME("Vector4")));
  1967. break;
  1968. case VisualShaderNode::PORT_TYPE_BOOLEAN:
  1969. item->set_icon(0, get_editor_theme_icon(SNAME("bool")));
  1970. break;
  1971. case VisualShaderNode::PORT_TYPE_TRANSFORM:
  1972. item->set_icon(0, get_editor_theme_icon(SNAME("Transform3D")));
  1973. break;
  1974. case VisualShaderNode::PORT_TYPE_SAMPLER:
  1975. item->set_icon(0, get_editor_theme_icon(SNAME("ImageTexture")));
  1976. break;
  1977. default:
  1978. break;
  1979. }
  1980. item->set_meta("id", options[i].temp_idx);
  1981. }
  1982. }
  1983. void VisualShaderEditor::_set_mode(int p_which) {
  1984. if (p_which == VisualShader::MODE_SKY) {
  1985. edit_type_standard->set_visible(false);
  1986. edit_type_particles->set_visible(false);
  1987. edit_type_sky->set_visible(true);
  1988. edit_type_fog->set_visible(false);
  1989. edit_type = edit_type_sky;
  1990. custom_mode_box->set_visible(false);
  1991. varying_button->hide();
  1992. mode = MODE_FLAGS_SKY;
  1993. } else if (p_which == VisualShader::MODE_FOG) {
  1994. edit_type_standard->set_visible(false);
  1995. edit_type_particles->set_visible(false);
  1996. edit_type_sky->set_visible(false);
  1997. edit_type_fog->set_visible(true);
  1998. edit_type = edit_type_fog;
  1999. custom_mode_box->set_visible(false);
  2000. varying_button->hide();
  2001. mode = MODE_FLAGS_FOG;
  2002. } else if (p_which == VisualShader::MODE_PARTICLES) {
  2003. edit_type_standard->set_visible(false);
  2004. edit_type_particles->set_visible(true);
  2005. edit_type_sky->set_visible(false);
  2006. edit_type_fog->set_visible(false);
  2007. edit_type = edit_type_particles;
  2008. if ((edit_type->get_selected() + 3) > VisualShader::TYPE_PROCESS) {
  2009. custom_mode_box->set_visible(false);
  2010. } else {
  2011. custom_mode_box->set_visible(true);
  2012. }
  2013. varying_button->hide();
  2014. mode = MODE_FLAGS_PARTICLES;
  2015. } else {
  2016. edit_type_particles->set_visible(false);
  2017. edit_type_standard->set_visible(true);
  2018. edit_type_sky->set_visible(false);
  2019. edit_type_fog->set_visible(false);
  2020. edit_type = edit_type_standard;
  2021. custom_mode_box->set_visible(false);
  2022. varying_button->show();
  2023. mode = MODE_FLAGS_SPATIAL_CANVASITEM;
  2024. }
  2025. visual_shader->set_shader_type(get_current_shader_type());
  2026. }
  2027. Size2 VisualShaderEditor::get_minimum_size() const {
  2028. return Size2(10, 200);
  2029. }
  2030. void VisualShaderEditor::_draw_color_over_button(Object *p_obj, Color p_color) {
  2031. Button *button = Object::cast_to<Button>(p_obj);
  2032. if (!button) {
  2033. return;
  2034. }
  2035. Ref<StyleBox> normal = get_theme_stylebox(CoreStringName(normal), SNAME("Button"));
  2036. button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
  2037. }
  2038. void VisualShaderEditor::_update_parameters(bool p_update_refs) {
  2039. VisualShaderNodeParameterRef::clear_parameters(visual_shader->get_rid());
  2040. for (int t = 0; t < VisualShader::TYPE_MAX; t++) {
  2041. Vector<int> tnodes = visual_shader->get_node_list((VisualShader::Type)t);
  2042. for (int i = 0; i < tnodes.size(); i++) {
  2043. Ref<VisualShaderNode> vsnode = visual_shader->get_node((VisualShader::Type)t, tnodes[i]);
  2044. Ref<VisualShaderNodeParameter> parameter = vsnode;
  2045. if (parameter.is_valid()) {
  2046. Ref<VisualShaderNodeFloatParameter> float_parameter = vsnode;
  2047. Ref<VisualShaderNodeIntParameter> int_parameter = vsnode;
  2048. Ref<VisualShaderNodeUIntParameter> uint_parameter = vsnode;
  2049. Ref<VisualShaderNodeVec2Parameter> vec2_parameter = vsnode;
  2050. Ref<VisualShaderNodeVec3Parameter> vec3_parameter = vsnode;
  2051. Ref<VisualShaderNodeVec4Parameter> vec4_parameter = vsnode;
  2052. Ref<VisualShaderNodeColorParameter> color_parameter = vsnode;
  2053. Ref<VisualShaderNodeBooleanParameter> boolean_parameter = vsnode;
  2054. Ref<VisualShaderNodeTransformParameter> transform_parameter = vsnode;
  2055. VisualShaderNodeParameterRef::ParameterType parameter_type;
  2056. if (float_parameter.is_valid()) {
  2057. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_FLOAT;
  2058. } else if (int_parameter.is_valid()) {
  2059. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_INT;
  2060. } else if (uint_parameter.is_valid()) {
  2061. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_UINT;
  2062. } else if (boolean_parameter.is_valid()) {
  2063. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_BOOLEAN;
  2064. } else if (vec2_parameter.is_valid()) {
  2065. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR2;
  2066. } else if (vec3_parameter.is_valid()) {
  2067. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR3;
  2068. } else if (vec4_parameter.is_valid()) {
  2069. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR4;
  2070. } else if (transform_parameter.is_valid()) {
  2071. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_TRANSFORM;
  2072. } else if (color_parameter.is_valid()) {
  2073. parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_COLOR;
  2074. } else {
  2075. parameter_type = VisualShaderNodeParameterRef::UNIFORM_TYPE_SAMPLER;
  2076. }
  2077. VisualShaderNodeParameterRef::add_parameter(visual_shader->get_rid(), parameter->get_parameter_name(), parameter_type);
  2078. }
  2079. }
  2080. }
  2081. if (p_update_refs) {
  2082. graph_plugin->update_parameter_refs();
  2083. }
  2084. }
  2085. void VisualShaderEditor::_update_parameter_refs(HashSet<String> &p_deleted_names) {
  2086. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2087. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  2088. VisualShader::Type type = VisualShader::Type(i);
  2089. Vector<int> nodes = visual_shader->get_node_list(type);
  2090. for (int j = 0; j < nodes.size(); j++) {
  2091. if (j > 0) {
  2092. Ref<VisualShaderNodeParameterRef> ref = visual_shader->get_node(type, nodes[j]);
  2093. if (ref.is_valid()) {
  2094. if (p_deleted_names.has(ref->get_parameter_name())) {
  2095. undo_redo->add_do_method(ref.ptr(), "set_parameter_name", "[None]");
  2096. undo_redo->add_undo_method(ref.ptr(), "set_parameter_name", ref->get_parameter_name());
  2097. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", VisualShader::Type(i), nodes[j]);
  2098. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", VisualShader::Type(i), nodes[j]);
  2099. }
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. void VisualShaderEditor::_update_graph() {
  2106. if (updating) {
  2107. return;
  2108. }
  2109. if (visual_shader.is_null()) {
  2110. return;
  2111. }
  2112. graph->set_scroll_offset(visual_shader->get_graph_offset() * EDSCALE);
  2113. VisualShader::Type type = get_current_shader_type();
  2114. graph->clear_connections();
  2115. // Remove all nodes.
  2116. for (int i = 0; i < graph->get_child_count(); i++) {
  2117. if (Object::cast_to<GraphElement>(graph->get_child(i))) {
  2118. Node *node = graph->get_child(i);
  2119. graph->remove_child(node);
  2120. memdelete(node);
  2121. i--;
  2122. }
  2123. }
  2124. List<VisualShader::Connection> node_connections;
  2125. visual_shader->get_node_connections(type, &node_connections);
  2126. graph_plugin->set_connections(node_connections);
  2127. Vector<int> nodes = visual_shader->get_node_list(type);
  2128. _update_parameters(false);
  2129. _update_varyings();
  2130. graph_plugin->clear_links();
  2131. graph_plugin->update_theme();
  2132. for (int n_i = 0; n_i < nodes.size(); n_i++) {
  2133. // Update frame related stuff later since we need to have all nodes in the graph.
  2134. graph_plugin->add_node(type, nodes[n_i], false, false);
  2135. }
  2136. for (const VisualShader::Connection &E : node_connections) {
  2137. int from = E.from_node;
  2138. int from_idx = E.from_port;
  2139. int to = E.to_node;
  2140. int to_idx = E.to_port;
  2141. graph->connect_node(itos(from), from_idx, itos(to), to_idx);
  2142. }
  2143. // Attach nodes to frames.
  2144. for (int node_id : nodes) {
  2145. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  2146. ERR_CONTINUE_MSG(vsnode.is_null(), "Node is null.");
  2147. if (vsnode->get_frame() != -1) {
  2148. int frame_name = vsnode->get_frame();
  2149. graph->attach_graph_element_to_frame(itos(node_id), itos(frame_name));
  2150. }
  2151. }
  2152. float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity");
  2153. graph->set_minimap_opacity(graph_minimap_opacity);
  2154. float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature");
  2155. graph->set_connection_lines_curvature(graph_lines_curvature);
  2156. }
  2157. VisualShader::Type VisualShaderEditor::get_current_shader_type() const {
  2158. VisualShader::Type type;
  2159. if (mode & MODE_FLAGS_PARTICLES) {
  2160. type = VisualShader::Type(edit_type->get_selected() + 3 + (custom_mode_enabled ? 3 : 0));
  2161. } else if (mode & MODE_FLAGS_SKY) {
  2162. type = VisualShader::Type(edit_type->get_selected() + 8);
  2163. } else if (mode & MODE_FLAGS_FOG) {
  2164. type = VisualShader::Type(edit_type->get_selected() + 9);
  2165. } else {
  2166. type = VisualShader::Type(edit_type->get_selected());
  2167. }
  2168. return type;
  2169. }
  2170. void VisualShaderEditor::_add_input_port(int p_node, int p_port, int p_port_type, const String &p_name) {
  2171. VisualShader::Type type = get_current_shader_type();
  2172. Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node);
  2173. if (node.is_null()) {
  2174. return;
  2175. }
  2176. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2177. undo_redo->create_action(TTR("Add Input Port"));
  2178. undo_redo->add_do_method(node.ptr(), "add_input_port", p_port, p_port_type, p_name);
  2179. undo_redo->add_undo_method(node.ptr(), "remove_input_port", p_port);
  2180. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2181. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2182. undo_redo->commit_action();
  2183. }
  2184. void VisualShaderEditor::_add_output_port(int p_node, int p_port, int p_port_type, const String &p_name) {
  2185. VisualShader::Type type = get_current_shader_type();
  2186. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2187. if (node.is_null()) {
  2188. return;
  2189. }
  2190. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2191. undo_redo->create_action(TTR("Add Output Port"));
  2192. undo_redo->add_do_method(node.ptr(), "add_output_port", p_port, p_port_type, p_name);
  2193. undo_redo->add_undo_method(node.ptr(), "remove_output_port", p_port);
  2194. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2195. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2196. undo_redo->commit_action();
  2197. }
  2198. void VisualShaderEditor::_change_input_port_type(int p_type, int p_node, int p_port) {
  2199. VisualShader::Type type = get_current_shader_type();
  2200. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2201. if (node.is_null()) {
  2202. return;
  2203. }
  2204. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2205. undo_redo->create_action(TTR("Change Input Port Type"));
  2206. undo_redo->add_do_method(node.ptr(), "set_input_port_type", p_port, p_type);
  2207. undo_redo->add_undo_method(node.ptr(), "set_input_port_type", p_port, node->get_input_port_type(p_port));
  2208. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2209. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2210. undo_redo->commit_action();
  2211. }
  2212. void VisualShaderEditor::_change_output_port_type(int p_type, int p_node, int p_port) {
  2213. VisualShader::Type type = get_current_shader_type();
  2214. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2215. if (node.is_null()) {
  2216. return;
  2217. }
  2218. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2219. undo_redo->create_action(TTR("Change Output Port Type"));
  2220. undo_redo->add_do_method(node.ptr(), "set_output_port_type", p_port, p_type);
  2221. undo_redo->add_undo_method(node.ptr(), "set_output_port_type", p_port, node->get_output_port_type(p_port));
  2222. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2223. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2224. undo_redo->commit_action();
  2225. }
  2226. void VisualShaderEditor::_change_input_port_name(const String &p_text, Object *p_line_edit, int p_node_id, int p_port_id) {
  2227. VisualShader::Type type = get_current_shader_type();
  2228. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  2229. ERR_FAIL_COND(!node.is_valid());
  2230. String prev_name = node->get_input_port_name(p_port_id);
  2231. if (prev_name == p_text) {
  2232. return;
  2233. }
  2234. LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
  2235. ERR_FAIL_NULL(line_edit);
  2236. String validated_name = visual_shader->validate_port_name(p_text, node.ptr(), p_port_id, false);
  2237. if (validated_name.is_empty() || prev_name == validated_name) {
  2238. line_edit->set_text(node->get_input_port_name(p_port_id));
  2239. return;
  2240. }
  2241. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2242. undo_redo->create_action(TTR("Change Input Port Name"));
  2243. undo_redo->add_do_method(node.ptr(), "set_input_port_name", p_port_id, validated_name);
  2244. undo_redo->add_undo_method(node.ptr(), "set_input_port_name", p_port_id, node->get_input_port_name(p_port_id));
  2245. undo_redo->commit_action();
  2246. }
  2247. void VisualShaderEditor::_change_output_port_name(const String &p_text, Object *p_line_edit, int p_node_id, int p_port_id) {
  2248. VisualShader::Type type = get_current_shader_type();
  2249. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
  2250. ERR_FAIL_COND(!node.is_valid());
  2251. String prev_name = node->get_output_port_name(p_port_id);
  2252. if (prev_name == p_text) {
  2253. return;
  2254. }
  2255. LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
  2256. ERR_FAIL_NULL(line_edit);
  2257. String validated_name = visual_shader->validate_port_name(p_text, node.ptr(), p_port_id, true);
  2258. if (validated_name.is_empty() || prev_name == validated_name) {
  2259. line_edit->set_text(node->get_output_port_name(p_port_id));
  2260. return;
  2261. }
  2262. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2263. undo_redo->create_action(TTR("Change Output Port Name"));
  2264. undo_redo->add_do_method(node.ptr(), "set_output_port_name", p_port_id, validated_name);
  2265. undo_redo->add_undo_method(node.ptr(), "set_output_port_name", p_port_id, prev_name);
  2266. undo_redo->commit_action();
  2267. }
  2268. void VisualShaderEditor::_expand_output_port(int p_node, int p_port, bool p_expand) {
  2269. VisualShader::Type type = get_current_shader_type();
  2270. Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
  2271. ERR_FAIL_COND(!node.is_valid());
  2272. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2273. if (p_expand) {
  2274. undo_redo->create_action(TTR("Expand Output Port"));
  2275. } else {
  2276. undo_redo->create_action(TTR("Shrink Output Port"));
  2277. }
  2278. undo_redo->add_do_method(node.ptr(), "_set_output_port_expanded", p_port, p_expand);
  2279. undo_redo->add_undo_method(node.ptr(), "_set_output_port_expanded", p_port, !p_expand);
  2280. int type_size = 0;
  2281. switch (node->get_output_port_type(p_port)) {
  2282. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  2283. type_size = 2;
  2284. } break;
  2285. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  2286. type_size = 3;
  2287. } break;
  2288. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  2289. type_size = 4;
  2290. } break;
  2291. default:
  2292. break;
  2293. }
  2294. List<VisualShader::Connection> conns;
  2295. visual_shader->get_node_connections(type, &conns);
  2296. for (const VisualShader::Connection &E : conns) {
  2297. int cn_from_node = E.from_node;
  2298. int cn_from_port = E.from_port;
  2299. int cn_to_node = E.to_node;
  2300. int cn_to_port = E.to_port;
  2301. if (cn_from_node == p_node) {
  2302. if (p_expand) {
  2303. if (cn_from_port > p_port) { // reconnect ports after expanded ports
  2304. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2305. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2306. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2307. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2308. 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);
  2309. 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);
  2310. 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);
  2311. 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);
  2312. }
  2313. } else {
  2314. if (cn_from_port > p_port + type_size) { // reconnect ports after expanded ports
  2315. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2316. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2317. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2318. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2319. 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);
  2320. 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);
  2321. 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);
  2322. 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);
  2323. } else if (cn_from_port > p_port) { // disconnect component ports
  2324. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2325. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2326. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2327. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2328. }
  2329. }
  2330. }
  2331. }
  2332. int preview_port = node->get_output_port_for_preview();
  2333. if (p_expand) {
  2334. if (preview_port > p_port) {
  2335. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port + type_size);
  2336. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2337. }
  2338. } else {
  2339. if (preview_port > p_port + type_size) {
  2340. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - type_size);
  2341. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2342. }
  2343. }
  2344. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2345. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2346. undo_redo->commit_action();
  2347. }
  2348. void VisualShaderEditor::_remove_input_port(int p_node, int p_port) {
  2349. VisualShader::Type type = get_current_shader_type();
  2350. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2351. if (node.is_null()) {
  2352. return;
  2353. }
  2354. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2355. undo_redo->create_action(TTR("Remove Input Port"));
  2356. List<VisualShader::Connection> conns;
  2357. visual_shader->get_node_connections(type, &conns);
  2358. for (const VisualShader::Connection &E : conns) {
  2359. int cn_from_node = E.from_node;
  2360. int cn_from_port = E.from_port;
  2361. int cn_to_node = E.to_node;
  2362. int cn_to_port = E.to_port;
  2363. if (cn_to_node == p_node) {
  2364. if (cn_to_port == p_port) {
  2365. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2366. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2367. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2368. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2369. } else if (cn_to_port > p_port) {
  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_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2375. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2376. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2377. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1);
  2378. }
  2379. }
  2380. }
  2381. undo_redo->add_do_method(node.ptr(), "remove_input_port", p_port);
  2382. 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));
  2383. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2384. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2385. undo_redo->commit_action();
  2386. }
  2387. void VisualShaderEditor::_remove_output_port(int p_node, int p_port) {
  2388. VisualShader::Type type = get_current_shader_type();
  2389. Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
  2390. if (node.is_null()) {
  2391. return;
  2392. }
  2393. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2394. undo_redo->create_action(TTR("Remove Output Port"));
  2395. List<VisualShader::Connection> conns;
  2396. visual_shader->get_node_connections(type, &conns);
  2397. for (const VisualShader::Connection &E : conns) {
  2398. int cn_from_node = E.from_node;
  2399. int cn_from_port = E.from_port;
  2400. int cn_to_node = E.to_node;
  2401. int cn_to_port = E.to_port;
  2402. if (cn_from_node == p_node) {
  2403. if (cn_from_port == p_port) {
  2404. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2405. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2406. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2407. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2408. } else if (cn_from_port > p_port) {
  2409. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2410. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2411. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2412. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  2413. 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);
  2414. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2415. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2416. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port);
  2417. }
  2418. }
  2419. }
  2420. int preview_port = node->get_output_port_for_preview();
  2421. if (preview_port != -1) {
  2422. if (preview_port == p_port) {
  2423. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", -1);
  2424. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2425. } else if (preview_port > p_port) {
  2426. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - 1);
  2427. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
  2428. }
  2429. }
  2430. undo_redo->add_do_method(node.ptr(), "remove_output_port", p_port);
  2431. 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));
  2432. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2433. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2434. undo_redo->commit_action();
  2435. }
  2436. void VisualShaderEditor::_expression_focus_out(Object *p_code_edit, int p_node) {
  2437. VisualShader::Type type = get_current_shader_type();
  2438. Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node);
  2439. if (node.is_null()) {
  2440. return;
  2441. }
  2442. CodeEdit *expression_box = Object::cast_to<CodeEdit>(p_code_edit);
  2443. if (node->get_expression() == expression_box->get_text()) {
  2444. return;
  2445. }
  2446. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2447. undo_redo->create_action(TTR("Set VisualShader Expression"));
  2448. undo_redo->add_do_method(node.ptr(), "set_expression", expression_box->get_text());
  2449. undo_redo->add_undo_method(node.ptr(), "set_expression", node->get_expression());
  2450. undo_redo->add_do_method(graph_plugin.ptr(), "set_expression", type, p_node, expression_box->get_text());
  2451. undo_redo->add_undo_method(graph_plugin.ptr(), "set_expression", type, p_node, node->get_expression());
  2452. undo_redo->commit_action();
  2453. }
  2454. void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p_size) {
  2455. VisualShader::Type type = VisualShader::Type(p_type);
  2456. Ref<VisualShaderNodeResizableBase> node = visual_shader->get_node(type, p_node);
  2457. if (node.is_null()) {
  2458. return;
  2459. }
  2460. Size2 size = p_size;
  2461. if (!node->is_allow_v_resize()) {
  2462. size.y = 0;
  2463. }
  2464. node->set_size(size);
  2465. if (get_current_shader_type() == type) {
  2466. Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  2467. Control *text_box = nullptr;
  2468. if (!expression_node.is_null()) {
  2469. text_box = expression_node->is_ctrl_pressed(0);
  2470. if (text_box) {
  2471. text_box->set_custom_minimum_size(Size2(0, 0));
  2472. }
  2473. }
  2474. GraphElement *graph_element = nullptr;
  2475. Node *node2 = graph->get_node(itos(p_node));
  2476. graph_element = Object::cast_to<GraphElement>(node2);
  2477. if (!graph_element) {
  2478. return;
  2479. }
  2480. graph_element->set_size(size);
  2481. }
  2482. // Update all parent frames.
  2483. graph_plugin->update_frames(type, p_node);
  2484. }
  2485. // Called once after the node was resized.
  2486. void VisualShaderEditor::_node_resized(const Vector2 &p_new_size, int p_type, int p_node) {
  2487. Ref<VisualShaderNodeResizableBase> node = visual_shader->get_node(VisualShader::Type(p_type), p_node);
  2488. if (node.is_null()) {
  2489. return;
  2490. }
  2491. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_node(itos(p_node)));
  2492. if (!graph_element) {
  2493. return;
  2494. }
  2495. Size2 size = graph_element->get_size();
  2496. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2497. undo_redo->create_action(TTR("Resize VisualShader Node"));
  2498. undo_redo->add_do_method(this, "_set_node_size", p_type, p_node, size);
  2499. undo_redo->add_undo_method(this, "_set_node_size", p_type, p_node, node->get_size());
  2500. undo_redo->commit_action();
  2501. }
  2502. void VisualShaderEditor::_preview_select_port(int p_node, int p_port) {
  2503. VisualShader::Type type = get_current_shader_type();
  2504. Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
  2505. if (node.is_null()) {
  2506. return;
  2507. }
  2508. int prev_port = node->get_output_port_for_preview();
  2509. if (node->get_output_port_for_preview() == p_port) {
  2510. p_port = -1; //toggle it
  2511. }
  2512. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2513. undo_redo->create_action(p_port == -1 ? TTR("Hide Port Preview") : TTR("Show Port Preview"));
  2514. undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", p_port);
  2515. undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", prev_port);
  2516. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, p_node);
  2517. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, p_node);
  2518. undo_redo->commit_action();
  2519. }
  2520. void VisualShaderEditor::_frame_title_popup_show(const Point2 &p_position, int p_node_id) {
  2521. VisualShader::Type type = get_current_shader_type();
  2522. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2523. if (node.is_null()) {
  2524. return;
  2525. }
  2526. frame_title_change_edit->set_text(node->get_title());
  2527. frame_title_change_popup->set_meta("id", p_node_id);
  2528. frame_title_change_popup->popup();
  2529. frame_title_change_popup->set_position(p_position);
  2530. // Select current text.
  2531. frame_title_change_edit->grab_focus();
  2532. }
  2533. void VisualShaderEditor::_frame_title_text_changed(const String &p_new_text) {
  2534. frame_title_change_edit->reset_size();
  2535. frame_title_change_popup->reset_size();
  2536. }
  2537. void VisualShaderEditor::_frame_title_text_submitted(const String &p_new_text) {
  2538. frame_title_change_popup->hide();
  2539. }
  2540. void VisualShaderEditor::_frame_title_popup_focus_out() {
  2541. frame_title_change_popup->hide();
  2542. }
  2543. void VisualShaderEditor::_frame_title_popup_hide() {
  2544. int node_id = (int)frame_title_change_popup->get_meta("id", -1);
  2545. ERR_FAIL_COND(node_id == -1);
  2546. VisualShader::Type type = get_current_shader_type();
  2547. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id);
  2548. ERR_FAIL_COND(node.is_null());
  2549. if (node->get_title() == frame_title_change_edit->get_text()) {
  2550. return; // nothing changed - ignored
  2551. }
  2552. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2553. undo_redo->create_action(TTR("Set Frame Title"));
  2554. undo_redo->add_do_method(node.ptr(), "set_title", frame_title_change_edit->get_text());
  2555. undo_redo->add_undo_method(node.ptr(), "set_title", node->get_title());
  2556. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, node_id);
  2557. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, node_id);
  2558. undo_redo->commit_action();
  2559. }
  2560. void VisualShaderEditor::_frame_color_enabled_changed(int p_node_id) {
  2561. int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR);
  2562. // The new state.
  2563. bool tint_color_enabled = !popup_menu->is_item_checked(item_index);
  2564. popup_menu->set_item_checked(item_index, tint_color_enabled);
  2565. int frame_color_item_idx = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_COLOR);
  2566. if (tint_color_enabled && frame_color_item_idx == -1) {
  2567. popup_menu->add_item(TTR("Set Tint Color"), NodeMenuOptions::SET_FRAME_COLOR);
  2568. } else if (!tint_color_enabled && frame_color_item_idx != -1) {
  2569. popup_menu->remove_item(frame_color_item_idx);
  2570. }
  2571. VisualShader::Type type = get_current_shader_type();
  2572. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2573. ERR_FAIL_COND(node.is_null());
  2574. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2575. undo_redo->create_action(TTR("Toggle Frame Color"));
  2576. undo_redo->add_do_method(node.ptr(), "set_tint_color_enabled", tint_color_enabled);
  2577. undo_redo->add_undo_method(node.ptr(), "set_tint_color_enabled", node->is_tint_color_enabled());
  2578. undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_color_enabled", (int)type, p_node_id, tint_color_enabled);
  2579. undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_color_enabled", (int)type, p_node_id, node->is_tint_color_enabled());
  2580. undo_redo->commit_action();
  2581. }
  2582. void VisualShaderEditor::_frame_color_popup_show(const Point2 &p_position, int p_node_id) {
  2583. VisualShader::Type type = get_current_shader_type();
  2584. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id);
  2585. if (node.is_null()) {
  2586. return;
  2587. }
  2588. frame_tint_color_picker->set_pick_color(node->get_tint_color());
  2589. frame_tint_color_pick_popup->set_meta("id", p_node_id);
  2590. frame_tint_color_pick_popup->set_position(p_position);
  2591. frame_tint_color_pick_popup->popup();
  2592. }
  2593. void VisualShaderEditor::_frame_color_confirm() {
  2594. frame_tint_color_pick_popup->hide();
  2595. }
  2596. void VisualShaderEditor::_frame_color_changed(const Color &p_color) {
  2597. ERR_FAIL_COND(!frame_tint_color_pick_popup->has_meta("id"));
  2598. int node_id = (int)frame_tint_color_pick_popup->get_meta("id");
  2599. VisualShader::Type type = get_current_shader_type();
  2600. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id);
  2601. ERR_FAIL_COND(node.is_null());
  2602. node->set_tint_color(p_color);
  2603. graph_plugin->set_frame_color(type, node_id, p_color);
  2604. }
  2605. void VisualShaderEditor::_frame_color_popup_hide() {
  2606. ERR_FAIL_COND(!frame_tint_color_pick_popup->has_meta("id"));
  2607. int node_id = (int)frame_tint_color_pick_popup->get_meta("id");
  2608. VisualShader::Type type = get_current_shader_type();
  2609. Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id);
  2610. ERR_FAIL_COND(node.is_null());
  2611. if (node->get_tint_color() == frame_tint_color_picker->get_pick_color()) {
  2612. return;
  2613. }
  2614. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2615. undo_redo->create_action(TTR("Set Frame Color"));
  2616. undo_redo->add_do_method(node.ptr(), "set_tint_color", frame_tint_color_picker->get_pick_color());
  2617. undo_redo->add_undo_method(node.ptr(), "set_tint_color", node->get_tint_color());
  2618. undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_color", (int)type, node_id, frame_tint_color_picker->get_pick_color());
  2619. undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_color", (int)type, node_id, node->get_tint_color());
  2620. undo_redo->commit_action();
  2621. }
  2622. void VisualShaderEditor::_frame_autoshrink_enabled_changed(int p_node_id) {
  2623. int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  2624. bool autoshrink_enabled = popup_menu->is_item_checked(item_index);
  2625. popup_menu->set_item_checked(item_index, !autoshrink_enabled);
  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 Auto Shrink"));
  2631. undo_redo->add_do_method(node.ptr(), "set_autoshrink_enabled", !autoshrink_enabled);
  2632. undo_redo->add_undo_method(node.ptr(), "set_autoshrink_enabled", autoshrink_enabled);
  2633. undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_autoshrink_enabled", (int)type, p_node_id, !autoshrink_enabled);
  2634. undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_autoshrink_enabled", (int)type, p_node_id, autoshrink_enabled);
  2635. undo_redo->commit_action();
  2636. popup_menu->hide();
  2637. }
  2638. void VisualShaderEditor::_parameter_line_edit_changed(const String &p_text, int p_node_id) {
  2639. VisualShader::Type type = get_current_shader_type();
  2640. Ref<VisualShaderNodeParameter> node = visual_shader->get_node(type, p_node_id);
  2641. ERR_FAIL_COND(!node.is_valid());
  2642. String validated_name = visual_shader->validate_parameter_name(p_text, node);
  2643. if (validated_name == node->get_parameter_name()) {
  2644. return;
  2645. }
  2646. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2647. undo_redo->create_action(TTR("Set Parameter Name"));
  2648. undo_redo->add_do_method(node.ptr(), "set_parameter_name", validated_name);
  2649. undo_redo->add_undo_method(node.ptr(), "set_parameter_name", node->get_parameter_name());
  2650. undo_redo->add_do_method(graph_plugin.ptr(), "set_parameter_name", type, p_node_id, validated_name);
  2651. undo_redo->add_undo_method(graph_plugin.ptr(), "set_parameter_name", type, p_node_id, node->get_parameter_name());
  2652. undo_redo->add_do_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id);
  2653. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id);
  2654. undo_redo->add_do_method(this, "_update_parameters", true);
  2655. undo_redo->add_undo_method(this, "_update_parameters", true);
  2656. HashSet<String> changed_names;
  2657. changed_names.insert(node->get_parameter_name());
  2658. _update_parameter_refs(changed_names);
  2659. undo_redo->commit_action();
  2660. }
  2661. void VisualShaderEditor::_parameter_line_edit_focus_out(Object *line_edit, int p_node_id) {
  2662. _parameter_line_edit_changed(Object::cast_to<LineEdit>(line_edit)->get_text(), p_node_id);
  2663. }
  2664. void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output) {
  2665. if (!p_output) {
  2666. _change_input_port_name(Object::cast_to<LineEdit>(line_edit)->get_text(), line_edit, p_node_id, p_port_id);
  2667. } else {
  2668. _change_output_port_name(Object::cast_to<LineEdit>(line_edit)->get_text(), line_edit, p_node_id, p_port_id);
  2669. }
  2670. }
  2671. void VisualShaderEditor::_port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
  2672. VisualShader::Type type = get_current_shader_type();
  2673. Ref<VisualShaderNode> vsn = visual_shader->get_node(type, editing_node);
  2674. ERR_FAIL_COND(!vsn.is_valid());
  2675. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2676. undo_redo->create_action(TTR("Set Input Default Port"));
  2677. Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(vsn.ptr());
  2678. if (custom.is_valid()) {
  2679. undo_redo->add_do_method(custom.ptr(), "_set_input_port_default_value", editing_port, p_value);
  2680. undo_redo->add_undo_method(custom.ptr(), "_set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
  2681. } else {
  2682. undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, p_value);
  2683. undo_redo->add_undo_method(vsn.ptr(), "set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
  2684. }
  2685. undo_redo->add_do_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, p_value);
  2686. 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));
  2687. undo_redo->commit_action();
  2688. }
  2689. void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, int p_port) {
  2690. VisualShader::Type type = get_current_shader_type();
  2691. Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, p_node);
  2692. Variant value = vs_node->get_input_port_default_value(p_port);
  2693. edited_property_holder->set_edited_property(value);
  2694. editing_node = p_node;
  2695. editing_port = p_port;
  2696. if (property_editor) {
  2697. property_editor->disconnect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
  2698. property_editor_popup->remove_child(property_editor);
  2699. }
  2700. // TODO: Define these properties with actual PropertyInfo and feed it to the property editor widget.
  2701. property_editor = EditorInspector::instantiate_property_editor(edited_property_holder.ptr(), value.get_type(), "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE, true);
  2702. ERR_FAIL_NULL_MSG(property_editor, "Failed to create property editor for type: " + Variant::get_type_name(value.get_type()));
  2703. // Determine the best size for the popup based on the property type.
  2704. // 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.
  2705. Size2 popup_pref_size;
  2706. switch (value.get_type()) {
  2707. case Variant::VECTOR3:
  2708. case Variant::BASIS:
  2709. popup_pref_size.width = 320;
  2710. break;
  2711. case Variant::VECTOR4:
  2712. case Variant::QUATERNION:
  2713. case Variant::PLANE:
  2714. case Variant::TRANSFORM2D:
  2715. case Variant::TRANSFORM3D:
  2716. case Variant::PROJECTION:
  2717. popup_pref_size.width = 480;
  2718. break;
  2719. default:
  2720. popup_pref_size.width = 180;
  2721. break;
  2722. }
  2723. property_editor_popup->set_min_size(popup_pref_size);
  2724. property_editor->set_object_and_property(edited_property_holder.ptr(), "edited_property");
  2725. property_editor->update_property();
  2726. property_editor->set_name_split_ratio(0);
  2727. property_editor_popup->add_child(property_editor);
  2728. property_editor->connect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
  2729. Button *button = Object::cast_to<Button>(p_button);
  2730. if (button) {
  2731. property_editor_popup->set_position(button->get_screen_position() + Vector2(0, button->get_size().height) * graph->get_zoom());
  2732. }
  2733. property_editor_popup->reset_size();
  2734. if (button) {
  2735. property_editor_popup->popup();
  2736. } else {
  2737. property_editor_popup->popup_centered_ratio();
  2738. }
  2739. property_editor->select(0); // Focus the first focusable control.
  2740. }
  2741. void VisualShaderEditor::_set_custom_node_option(int p_index, int p_node, int p_op) {
  2742. VisualShader::Type type = get_current_shader_type();
  2743. Ref<VisualShaderNodeCustom> node = visual_shader->get_node(type, p_node);
  2744. if (node.is_null()) {
  2745. return;
  2746. }
  2747. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  2748. undo_redo->create_action(TTR("Set Custom Node Option"));
  2749. undo_redo->add_do_method(node.ptr(), "_set_option_index", p_op, p_index);
  2750. undo_redo->add_undo_method(node.ptr(), "_set_option_index", p_op, node->get_option_index(p_op));
  2751. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
  2752. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node);
  2753. undo_redo->commit_action();
  2754. }
  2755. void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops) {
  2756. // INPUT
  2757. {
  2758. VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(p_node);
  2759. if (input) {
  2760. ERR_FAIL_COND(!p_ops[0].is_string());
  2761. input->set_input_name((String)p_ops[0]);
  2762. return;
  2763. }
  2764. }
  2765. // FLOAT_CONST
  2766. {
  2767. VisualShaderNodeFloatConstant *float_const = Object::cast_to<VisualShaderNodeFloatConstant>(p_node);
  2768. if (float_const) {
  2769. ERR_FAIL_COND(p_ops[0].get_type() != Variant::FLOAT);
  2770. float_const->set_constant((float)p_ops[0]);
  2771. return;
  2772. }
  2773. }
  2774. // FLOAT_OP
  2775. {
  2776. VisualShaderNodeFloatOp *floatOp = Object::cast_to<VisualShaderNodeFloatOp>(p_node);
  2777. if (floatOp) {
  2778. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2779. floatOp->set_operator((VisualShaderNodeFloatOp::Operator)(int)p_ops[0]);
  2780. return;
  2781. }
  2782. }
  2783. // FLOAT_FUNC
  2784. {
  2785. VisualShaderNodeFloatFunc *floatFunc = Object::cast_to<VisualShaderNodeFloatFunc>(p_node);
  2786. if (floatFunc) {
  2787. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2788. floatFunc->set_function((VisualShaderNodeFloatFunc::Function)(int)p_ops[0]);
  2789. return;
  2790. }
  2791. }
  2792. // VECTOR_OP
  2793. {
  2794. VisualShaderNodeVectorOp *vecOp = Object::cast_to<VisualShaderNodeVectorOp>(p_node);
  2795. if (vecOp) {
  2796. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2797. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  2798. vecOp->set_operator((VisualShaderNodeVectorOp::Operator)(int)p_ops[0]);
  2799. vecOp->set_op_type((VisualShaderNodeVectorOp::OpType)(int)p_ops[1]);
  2800. return;
  2801. }
  2802. }
  2803. // VECTOR_FUNC
  2804. {
  2805. VisualShaderNodeVectorFunc *vecFunc = Object::cast_to<VisualShaderNodeVectorFunc>(p_node);
  2806. if (vecFunc) {
  2807. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2808. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  2809. vecFunc->set_function((VisualShaderNodeVectorFunc::Function)(int)p_ops[0]);
  2810. vecFunc->set_op_type((VisualShaderNodeVectorFunc::OpType)(int)p_ops[1]);
  2811. return;
  2812. }
  2813. }
  2814. // COLOR_OP
  2815. {
  2816. VisualShaderNodeColorOp *colorOp = Object::cast_to<VisualShaderNodeColorOp>(p_node);
  2817. if (colorOp) {
  2818. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2819. colorOp->set_operator((VisualShaderNodeColorOp::Operator)(int)p_ops[0]);
  2820. return;
  2821. }
  2822. }
  2823. // COLOR_FUNC
  2824. {
  2825. VisualShaderNodeColorFunc *colorFunc = Object::cast_to<VisualShaderNodeColorFunc>(p_node);
  2826. if (colorFunc) {
  2827. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2828. colorFunc->set_function((VisualShaderNodeColorFunc::Function)(int)p_ops[0]);
  2829. return;
  2830. }
  2831. }
  2832. // INT_OP
  2833. {
  2834. VisualShaderNodeIntOp *intOp = Object::cast_to<VisualShaderNodeIntOp>(p_node);
  2835. if (intOp) {
  2836. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2837. intOp->set_operator((VisualShaderNodeIntOp::Operator)(int)p_ops[0]);
  2838. return;
  2839. }
  2840. }
  2841. // INT_FUNC
  2842. {
  2843. VisualShaderNodeIntFunc *intFunc = Object::cast_to<VisualShaderNodeIntFunc>(p_node);
  2844. if (intFunc) {
  2845. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2846. intFunc->set_function((VisualShaderNodeIntFunc::Function)(int)p_ops[0]);
  2847. return;
  2848. }
  2849. }
  2850. // UINT_OP
  2851. {
  2852. VisualShaderNodeUIntOp *uintOp = Object::cast_to<VisualShaderNodeUIntOp>(p_node);
  2853. if (uintOp) {
  2854. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2855. uintOp->set_operator((VisualShaderNodeUIntOp::Operator)(int)p_ops[0]);
  2856. return;
  2857. }
  2858. }
  2859. // UINT_FUNC
  2860. {
  2861. VisualShaderNodeUIntFunc *uintFunc = Object::cast_to<VisualShaderNodeUIntFunc>(p_node);
  2862. if (uintFunc) {
  2863. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2864. uintFunc->set_function((VisualShaderNodeUIntFunc::Function)(int)p_ops[0]);
  2865. return;
  2866. }
  2867. }
  2868. // TRANSFORM_OP
  2869. {
  2870. VisualShaderNodeTransformOp *matOp = Object::cast_to<VisualShaderNodeTransformOp>(p_node);
  2871. if (matOp) {
  2872. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2873. matOp->set_operator((VisualShaderNodeTransformOp::Operator)(int)p_ops[0]);
  2874. return;
  2875. }
  2876. }
  2877. // TRANSFORM_FUNC
  2878. {
  2879. VisualShaderNodeTransformFunc *matFunc = Object::cast_to<VisualShaderNodeTransformFunc>(p_node);
  2880. if (matFunc) {
  2881. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2882. matFunc->set_function((VisualShaderNodeTransformFunc::Function)(int)p_ops[0]);
  2883. return;
  2884. }
  2885. }
  2886. // VECTOR_COMPOSE
  2887. {
  2888. VisualShaderNodeVectorCompose *vecCompose = Object::cast_to<VisualShaderNodeVectorCompose>(p_node);
  2889. if (vecCompose) {
  2890. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2891. vecCompose->set_op_type((VisualShaderNodeVectorCompose::OpType)(int)p_ops[0]);
  2892. return;
  2893. }
  2894. }
  2895. // VECTOR_DECOMPOSE
  2896. {
  2897. VisualShaderNodeVectorDecompose *vecDecompose = Object::cast_to<VisualShaderNodeVectorDecompose>(p_node);
  2898. if (vecDecompose) {
  2899. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2900. vecDecompose->set_op_type((VisualShaderNodeVectorDecompose::OpType)(int)p_ops[0]);
  2901. return;
  2902. }
  2903. }
  2904. // UV_FUNC
  2905. {
  2906. VisualShaderNodeUVFunc *uvFunc = Object::cast_to<VisualShaderNodeUVFunc>(p_node);
  2907. if (uvFunc) {
  2908. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2909. uvFunc->set_function((VisualShaderNodeUVFunc::Function)(int)p_ops[0]);
  2910. return;
  2911. }
  2912. }
  2913. // IS
  2914. {
  2915. VisualShaderNodeIs *is = Object::cast_to<VisualShaderNodeIs>(p_node);
  2916. if (is) {
  2917. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2918. is->set_function((VisualShaderNodeIs::Function)(int)p_ops[0]);
  2919. return;
  2920. }
  2921. }
  2922. // COMPARE
  2923. {
  2924. VisualShaderNodeCompare *cmp = Object::cast_to<VisualShaderNodeCompare>(p_node);
  2925. if (cmp) {
  2926. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2927. cmp->set_function((VisualShaderNodeCompare::Function)(int)p_ops[0]);
  2928. return;
  2929. }
  2930. }
  2931. // DISTANCE
  2932. {
  2933. VisualShaderNodeVectorDistance *dist = Object::cast_to<VisualShaderNodeVectorDistance>(p_node);
  2934. if (dist) {
  2935. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2936. dist->set_op_type((VisualShaderNodeVectorDistance::OpType)(int)p_ops[0]);
  2937. return;
  2938. }
  2939. }
  2940. // DERIVATIVE
  2941. {
  2942. VisualShaderNodeDerivativeFunc *derFunc = Object::cast_to<VisualShaderNodeDerivativeFunc>(p_node);
  2943. if (derFunc) {
  2944. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2945. ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT);
  2946. derFunc->set_function((VisualShaderNodeDerivativeFunc::Function)(int)p_ops[0]);
  2947. derFunc->set_op_type((VisualShaderNodeDerivativeFunc::OpType)(int)p_ops[1]);
  2948. return;
  2949. }
  2950. }
  2951. // MIX
  2952. {
  2953. VisualShaderNodeMix *mix = Object::cast_to<VisualShaderNodeMix>(p_node);
  2954. if (mix) {
  2955. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2956. mix->set_op_type((VisualShaderNodeMix::OpType)(int)p_ops[0]);
  2957. return;
  2958. }
  2959. }
  2960. // CLAMP
  2961. {
  2962. VisualShaderNodeClamp *clampFunc = Object::cast_to<VisualShaderNodeClamp>(p_node);
  2963. if (clampFunc) {
  2964. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2965. clampFunc->set_op_type((VisualShaderNodeClamp::OpType)(int)p_ops[0]);
  2966. return;
  2967. }
  2968. }
  2969. // SWITCH
  2970. {
  2971. VisualShaderNodeSwitch *switchFunc = Object::cast_to<VisualShaderNodeSwitch>(p_node);
  2972. if (switchFunc) {
  2973. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2974. switchFunc->set_op_type((VisualShaderNodeSwitch::OpType)(int)p_ops[0]);
  2975. return;
  2976. }
  2977. }
  2978. // FACEFORWARD
  2979. {
  2980. VisualShaderNodeFaceForward *faceForward = Object::cast_to<VisualShaderNodeFaceForward>(p_node);
  2981. if (faceForward) {
  2982. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2983. faceForward->set_op_type((VisualShaderNodeFaceForward::OpType)(int)p_ops[0]);
  2984. return;
  2985. }
  2986. }
  2987. // LENGTH
  2988. {
  2989. VisualShaderNodeVectorLen *length = Object::cast_to<VisualShaderNodeVectorLen>(p_node);
  2990. if (length) {
  2991. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  2992. length->set_op_type((VisualShaderNodeVectorLen::OpType)(int)p_ops[0]);
  2993. return;
  2994. }
  2995. }
  2996. // SMOOTHSTEP
  2997. {
  2998. VisualShaderNodeSmoothStep *smoothStepFunc = Object::cast_to<VisualShaderNodeSmoothStep>(p_node);
  2999. if (smoothStepFunc) {
  3000. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3001. smoothStepFunc->set_op_type((VisualShaderNodeSmoothStep::OpType)(int)p_ops[0]);
  3002. return;
  3003. }
  3004. }
  3005. // STEP
  3006. {
  3007. VisualShaderNodeStep *stepFunc = Object::cast_to<VisualShaderNodeStep>(p_node);
  3008. if (stepFunc) {
  3009. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3010. stepFunc->set_op_type((VisualShaderNodeStep::OpType)(int)p_ops[0]);
  3011. return;
  3012. }
  3013. }
  3014. // MULTIPLY_ADD
  3015. {
  3016. VisualShaderNodeMultiplyAdd *fmaFunc = Object::cast_to<VisualShaderNodeMultiplyAdd>(p_node);
  3017. if (fmaFunc) {
  3018. ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT);
  3019. fmaFunc->set_op_type((VisualShaderNodeMultiplyAdd::OpType)(int)p_ops[0]);
  3020. }
  3021. }
  3022. }
  3023. void VisualShaderEditor::_add_node(int p_idx, const Vector<Variant> &p_ops, const String &p_resource_path, int p_node_idx) {
  3024. ERR_FAIL_INDEX(p_idx, add_options.size());
  3025. VisualShader::Type type = get_current_shader_type();
  3026. Ref<VisualShaderNode> vsnode;
  3027. bool is_custom = add_options[p_idx].is_custom;
  3028. if (!is_custom && !add_options[p_idx].type.is_empty()) {
  3029. VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[p_idx].type));
  3030. ERR_FAIL_NULL(vsn);
  3031. if (!p_ops.is_empty()) {
  3032. _setup_node(vsn, p_ops);
  3033. }
  3034. VisualShaderNodeParameterRef *parameter_ref = Object::cast_to<VisualShaderNodeParameterRef>(vsn);
  3035. if (parameter_ref && to_node != -1 && to_slot != -1) {
  3036. VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot);
  3037. bool success = false;
  3038. for (int i = 0; i < parameter_ref->get_parameters_count(); i++) {
  3039. if (parameter_ref->get_port_type_by_index(i) == input_port_type) {
  3040. parameter_ref->set_parameter_name(parameter_ref->get_parameter_name_by_index(i));
  3041. success = true;
  3042. break;
  3043. }
  3044. }
  3045. if (!success) {
  3046. for (int i = 0; i < parameter_ref->get_parameters_count(); i++) {
  3047. if (visual_shader->is_port_types_compatible(parameter_ref->get_port_type_by_index(i), input_port_type)) {
  3048. parameter_ref->set_parameter_name(parameter_ref->get_parameter_name_by_index(i));
  3049. break;
  3050. }
  3051. }
  3052. }
  3053. }
  3054. vsnode = Ref<VisualShaderNode>(vsn);
  3055. } else {
  3056. StringName base_type;
  3057. bool is_native = add_options[p_idx].is_native;
  3058. if (is_native) {
  3059. base_type = add_options[p_idx].type;
  3060. } else {
  3061. ERR_FAIL_COND(add_options[p_idx].script.is_null());
  3062. base_type = add_options[p_idx].script->get_instance_base_type();
  3063. }
  3064. VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(base_type));
  3065. ERR_FAIL_NULL(vsn);
  3066. vsnode = Ref<VisualShaderNode>(vsn);
  3067. if (!is_native) {
  3068. vsnode->set_script(add_options[p_idx].script);
  3069. }
  3070. VisualShaderNodeCustom *custom_node = Object::cast_to<VisualShaderNodeCustom>(vsn);
  3071. ERR_FAIL_NULL(custom_node);
  3072. custom_node->update_property_default_values();
  3073. custom_node->update_input_port_default_values();
  3074. custom_node->update_properties();
  3075. }
  3076. bool is_texture2d = (Object::cast_to<VisualShaderNodeTexture>(vsnode.ptr()) != nullptr);
  3077. bool is_texture3d = (Object::cast_to<VisualShaderNodeTexture3D>(vsnode.ptr()) != nullptr);
  3078. bool is_texture2d_array = (Object::cast_to<VisualShaderNodeTexture2DArray>(vsnode.ptr()) != nullptr);
  3079. bool is_cubemap = (Object::cast_to<VisualShaderNodeCubemap>(vsnode.ptr()) != nullptr);
  3080. bool is_curve = (Object::cast_to<VisualShaderNodeCurveTexture>(vsnode.ptr()) != nullptr);
  3081. bool is_curve_xyz = (Object::cast_to<VisualShaderNodeCurveXYZTexture>(vsnode.ptr()) != nullptr);
  3082. bool is_parameter = (Object::cast_to<VisualShaderNodeParameter>(vsnode.ptr()) != nullptr);
  3083. bool is_mesh_emitter = (Object::cast_to<VisualShaderNodeParticleMeshEmitter>(vsnode.ptr()) != nullptr);
  3084. Point2 position = graph->get_scroll_offset();
  3085. if (saved_node_pos_dirty) {
  3086. position += saved_node_pos;
  3087. } else {
  3088. position += graph->get_size() * 0.5;
  3089. position /= EDSCALE;
  3090. }
  3091. position /= graph->get_zoom();
  3092. saved_node_pos_dirty = false;
  3093. int id_to_use = visual_shader->get_valid_node_id(type);
  3094. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3095. if (p_resource_path.is_empty()) {
  3096. undo_redo->create_action(TTR("Add Node to Visual Shader"));
  3097. } else {
  3098. id_to_use += p_node_idx;
  3099. }
  3100. undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, vsnode, position, id_to_use);
  3101. undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_to_use);
  3102. undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_to_use, false, true);
  3103. undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_to_use, false);
  3104. VisualShaderNodeExpression *expr = Object::cast_to<VisualShaderNodeExpression>(vsnode.ptr());
  3105. if (expr) {
  3106. expr->set_size(Size2(250 * EDSCALE, 150 * EDSCALE));
  3107. }
  3108. Ref<VisualShaderNodeFrame> frame = vsnode;
  3109. if (frame.is_valid()) {
  3110. frame->set_size(Size2(320 * EDSCALE, 180 * EDSCALE));
  3111. }
  3112. Ref<VisualShaderNodeReroute> reroute = vsnode;
  3113. bool created_expression_port = false;
  3114. // A node is inserted in an already present connection.
  3115. if (from_node != -1 && from_slot != -1 && to_node != -1 && to_slot != -1) {
  3116. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, to_node, to_slot);
  3117. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, to_node, to_slot);
  3118. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, to_node, to_slot);
  3119. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, to_node, to_slot);
  3120. }
  3121. // Create a connection from the output port of an existing node to the new one.
  3122. if (from_node != -1 && from_slot != -1) {
  3123. VisualShaderNode::PortType output_port_type = visual_shader->get_node(type, from_node)->get_output_port_type(from_slot);
  3124. if (expr && expr->is_editable()) {
  3125. expr->add_input_port(0, output_port_type, "input0");
  3126. created_expression_port = true;
  3127. }
  3128. if (vsnode->get_input_port_count() > 0 || created_expression_port) {
  3129. int _to_node = id_to_use;
  3130. if (created_expression_port) {
  3131. int _to_slot = 0;
  3132. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3133. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3134. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3135. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3136. } else {
  3137. int _to_slot = -1;
  3138. // Attempting to connect to the default input port or to the first correct port (if it's not found).
  3139. for (int i = 0; i < vsnode->get_input_port_count(); i++) {
  3140. if (visual_shader->is_port_types_compatible(output_port_type, vsnode->get_input_port_type(i)) || reroute.is_valid()) {
  3141. if (i == vsnode->get_default_input_port(output_port_type)) {
  3142. _to_slot = i;
  3143. break;
  3144. } else if (_to_slot == -1) {
  3145. _to_slot = i;
  3146. }
  3147. }
  3148. }
  3149. if (_to_slot >= 0) {
  3150. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3151. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3152. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3153. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
  3154. }
  3155. }
  3156. if (output_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) {
  3157. if (is_texture2d) {
  3158. undo_redo->force_fixed_history(); // vsnode is freshly created and has no path, so history can't be correctly determined.
  3159. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeTexture::SOURCE_PORT);
  3160. }
  3161. if (is_texture3d || is_texture2d_array) {
  3162. undo_redo->force_fixed_history();
  3163. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeSample3D::SOURCE_PORT);
  3164. }
  3165. if (is_cubemap) {
  3166. undo_redo->force_fixed_history();
  3167. undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeCubemap::SOURCE_PORT);
  3168. }
  3169. }
  3170. }
  3171. }
  3172. // Create a connection from the new node to an input port of an existing one.
  3173. if (to_node != -1 && to_slot != -1) {
  3174. VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot);
  3175. if (expr && expr->is_editable() && input_port_type != VisualShaderNode::PORT_TYPE_SAMPLER) {
  3176. expr->add_output_port(0, input_port_type, "output0");
  3177. String initial_expression_code;
  3178. switch (input_port_type) {
  3179. case VisualShaderNode::PORT_TYPE_SCALAR:
  3180. initial_expression_code = "output0 = 1.0;";
  3181. break;
  3182. case VisualShaderNode::PORT_TYPE_SCALAR_INT:
  3183. initial_expression_code = "output0 = 1;";
  3184. break;
  3185. case VisualShaderNode::PORT_TYPE_SCALAR_UINT:
  3186. initial_expression_code = "output0 = 1u;";
  3187. break;
  3188. case VisualShaderNode::PORT_TYPE_VECTOR_2D:
  3189. initial_expression_code = "output0 = vec2(1.0, 1.0);";
  3190. break;
  3191. case VisualShaderNode::PORT_TYPE_VECTOR_3D:
  3192. initial_expression_code = "output0 = vec3(1.0, 1.0, 1.0);";
  3193. break;
  3194. case VisualShaderNode::PORT_TYPE_VECTOR_4D:
  3195. initial_expression_code = "output0 = vec4(1.0, 1.0, 1.0, 1.0);";
  3196. break;
  3197. case VisualShaderNode::PORT_TYPE_BOOLEAN:
  3198. initial_expression_code = "output0 = true;";
  3199. break;
  3200. case VisualShaderNode::PORT_TYPE_TRANSFORM:
  3201. initial_expression_code = "output0 = mat4(1.0);";
  3202. break;
  3203. default:
  3204. break;
  3205. }
  3206. expr->set_expression(initial_expression_code);
  3207. expr->set_size(Size2(500 * EDSCALE, 200 * EDSCALE));
  3208. created_expression_port = true;
  3209. }
  3210. if (vsnode->get_output_port_count() > 0 || created_expression_port) {
  3211. int _from_node = id_to_use;
  3212. if (created_expression_port) {
  3213. int _from_slot = 0;
  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(visual_shader.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. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
  3218. } else {
  3219. // Need to setting up Input node properly before committing since `is_port_types_compatible` (calling below) is using `mode` and `shader_type`.
  3220. VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(vsnode.ptr());
  3221. if (input) {
  3222. input->set_shader_mode(visual_shader->get_mode());
  3223. input->set_shader_type(visual_shader->get_shader_type());
  3224. }
  3225. // Attempting to connect to the first correct port.
  3226. for (int i = 0; i < vsnode->get_output_port_count(); i++) {
  3227. if (visual_shader->is_port_types_compatible(vsnode->get_output_port_type(i), input_port_type) || reroute.is_valid()) {
  3228. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot);
  3229. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot);
  3230. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot);
  3231. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot);
  3232. break;
  3233. }
  3234. }
  3235. }
  3236. }
  3237. }
  3238. _member_cancel();
  3239. if (is_parameter) {
  3240. undo_redo->add_do_method(this, "_update_parameters", true);
  3241. undo_redo->add_undo_method(this, "_update_parameters", true);
  3242. }
  3243. if (is_curve) {
  3244. callable_mp(graph_plugin.ptr(), &VisualShaderGraphPlugin::update_curve).call_deferred(id_to_use);
  3245. }
  3246. if (is_curve_xyz) {
  3247. callable_mp(graph_plugin.ptr(), &VisualShaderGraphPlugin::update_curve_xyz).call_deferred(id_to_use);
  3248. }
  3249. if (p_resource_path.is_empty()) {
  3250. undo_redo->commit_action();
  3251. } else {
  3252. //post-initialization
  3253. if (is_texture2d || is_texture3d || is_curve || is_curve_xyz) {
  3254. undo_redo->force_fixed_history();
  3255. undo_redo->add_do_method(vsnode.ptr(), "set_texture", ResourceLoader::load(p_resource_path));
  3256. return;
  3257. }
  3258. if (is_cubemap) {
  3259. undo_redo->force_fixed_history();
  3260. undo_redo->add_do_method(vsnode.ptr(), "set_cube_map", ResourceLoader::load(p_resource_path));
  3261. return;
  3262. }
  3263. if (is_texture2d_array) {
  3264. undo_redo->force_fixed_history();
  3265. undo_redo->add_do_method(vsnode.ptr(), "set_texture_array", ResourceLoader::load(p_resource_path));
  3266. return;
  3267. }
  3268. if (is_mesh_emitter) {
  3269. undo_redo->add_do_method(vsnode.ptr(), "set_mesh", ResourceLoader::load(p_resource_path));
  3270. return;
  3271. }
  3272. }
  3273. }
  3274. void VisualShaderEditor::_add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type) {
  3275. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3276. undo_redo->create_action(vformat(TTR("Add Varying to Visual Shader: %s"), p_name));
  3277. undo_redo->add_do_method(visual_shader.ptr(), "add_varying", p_name, p_mode, p_type);
  3278. undo_redo->add_undo_method(visual_shader.ptr(), "remove_varying", p_name);
  3279. undo_redo->add_do_method(this, "_update_varyings");
  3280. undo_redo->add_undo_method(this, "_update_varyings");
  3281. for (int i = 0; i <= VisualShader::TYPE_LIGHT; i++) {
  3282. if (p_mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT && i == 0) {
  3283. continue;
  3284. }
  3285. VisualShader::Type type = VisualShader::Type(i);
  3286. Vector<int> nodes = visual_shader->get_node_list(type);
  3287. for (int j = 0; j < nodes.size(); j++) {
  3288. int node_id = nodes[j];
  3289. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  3290. Ref<VisualShaderNodeVarying> var = vsnode;
  3291. if (var.is_valid()) {
  3292. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, node_id);
  3293. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, node_id);
  3294. }
  3295. }
  3296. }
  3297. undo_redo->add_do_method(this, "_update_varying_tree");
  3298. undo_redo->add_undo_method(this, "_update_varying_tree");
  3299. undo_redo->commit_action();
  3300. }
  3301. void VisualShaderEditor::_remove_varying(const String &p_name) {
  3302. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3303. undo_redo->create_action(vformat(TTR("Remove Varying from Visual Shader: %s"), p_name));
  3304. VisualShader::VaryingMode var_mode = visual_shader->get_varying_mode(p_name);
  3305. undo_redo->add_do_method(visual_shader.ptr(), "remove_varying", p_name);
  3306. undo_redo->add_undo_method(visual_shader.ptr(), "add_varying", p_name, var_mode, visual_shader->get_varying_type(p_name));
  3307. undo_redo->add_do_method(this, "_update_varyings");
  3308. undo_redo->add_undo_method(this, "_update_varyings");
  3309. for (int i = 0; i <= VisualShader::TYPE_LIGHT; i++) {
  3310. if (var_mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT && i == 0) {
  3311. continue;
  3312. }
  3313. VisualShader::Type type = VisualShader::Type(i);
  3314. Vector<int> nodes = visual_shader->get_node_list(type);
  3315. for (int j = 0; j < nodes.size(); j++) {
  3316. int node_id = nodes[j];
  3317. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id);
  3318. Ref<VisualShaderNodeVarying> var = vsnode;
  3319. if (var.is_valid()) {
  3320. String var_name = var->get_varying_name();
  3321. if (var_name == p_name) {
  3322. undo_redo->add_do_method(var.ptr(), "set_varying_name", "[None]");
  3323. undo_redo->add_undo_method(var.ptr(), "set_varying_name", var_name);
  3324. undo_redo->add_do_method(var.ptr(), "set_varying_type", VisualShader::VARYING_TYPE_FLOAT);
  3325. undo_redo->add_undo_method(var.ptr(), "set_varying_type", var->get_varying_type());
  3326. }
  3327. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, node_id);
  3328. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, node_id);
  3329. }
  3330. }
  3331. List<VisualShader::Connection> node_connections;
  3332. visual_shader->get_node_connections(type, &node_connections);
  3333. for (VisualShader::Connection &E : node_connections) {
  3334. Ref<VisualShaderNodeVaryingGetter> var_getter = Object::cast_to<VisualShaderNodeVaryingGetter>(visual_shader->get_node(type, E.from_node).ptr());
  3335. if (var_getter.is_valid() && E.from_port > 0) {
  3336. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3337. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3338. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3339. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3340. }
  3341. Ref<VisualShaderNodeVaryingSetter> var_setter = Object::cast_to<VisualShaderNodeVaryingSetter>(visual_shader->get_node(type, E.to_node).ptr());
  3342. if (var_setter.is_valid() && E.to_port > 0) {
  3343. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3344. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3345. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3346. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3347. }
  3348. }
  3349. }
  3350. undo_redo->add_do_method(this, "_update_varying_tree");
  3351. undo_redo->add_undo_method(this, "_update_varying_tree");
  3352. undo_redo->commit_action();
  3353. }
  3354. void VisualShaderEditor::_update_varyings() {
  3355. VisualShaderNodeVarying::clear_varyings(visual_shader->get_rid());
  3356. for (int i = 0; i < visual_shader->get_varyings_count(); i++) {
  3357. const VisualShader::Varying *var = visual_shader->get_varying_by_index(i);
  3358. if (var != nullptr) {
  3359. VisualShaderNodeVarying::add_varying(visual_shader->get_rid(), var->name, var->mode, var->type);
  3360. }
  3361. }
  3362. }
  3363. void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) {
  3364. VisualShader::Type type = get_current_shader_type();
  3365. drag_buffer.push_back({ type, p_node, p_from, p_to });
  3366. if (!drag_dirty) {
  3367. callable_mp(this, &VisualShaderEditor::_nodes_dragged).call_deferred();
  3368. }
  3369. drag_dirty = true;
  3370. }
  3371. void VisualShaderEditor::_nodes_dragged() {
  3372. drag_dirty = false;
  3373. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3374. if (frame_node_id_to_link_to == -1) {
  3375. undo_redo->create_action(TTR("Move VisualShader Node(s)"));
  3376. } else {
  3377. undo_redo->create_action(TTR("Move and Attach VisualShader Node(s) to parent frame"));
  3378. }
  3379. for (const DragOp &E : drag_buffer) {
  3380. undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.to);
  3381. undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.from);
  3382. undo_redo->add_do_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.to);
  3383. undo_redo->add_undo_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.from);
  3384. }
  3385. for (const int node_id : nodes_link_to_frame_buffer) {
  3386. VisualShader::Type type = visual_shader->get_shader_type();
  3387. Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, node_id);
  3388. undo_redo->add_do_method(visual_shader.ptr(), "attach_node_to_frame", type, node_id, frame_node_id_to_link_to);
  3389. undo_redo->add_do_method(graph_plugin.ptr(), "attach_node_to_frame", type, node_id, frame_node_id_to_link_to);
  3390. undo_redo->add_undo_method(graph_plugin.ptr(), "detach_node_from_frame", type, node_id);
  3391. undo_redo->add_undo_method(visual_shader.ptr(), "detach_node_from_frame", type, node_id);
  3392. }
  3393. undo_redo->commit_action();
  3394. _handle_node_drop_on_connection();
  3395. drag_buffer.clear();
  3396. nodes_link_to_frame_buffer.clear();
  3397. frame_node_id_to_link_to = -1;
  3398. }
  3399. void VisualShaderEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  3400. VisualShader::Type type = get_current_shader_type();
  3401. int from = p_from.to_int();
  3402. int to = p_to.to_int();
  3403. if (!visual_shader->can_connect_nodes(type, from, p_from_index, to, p_to_index)) {
  3404. return;
  3405. }
  3406. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3407. undo_redo->create_action(TTR("Nodes Connected"));
  3408. List<VisualShader::Connection> conns;
  3409. visual_shader->get_node_connections(type, &conns);
  3410. for (const VisualShader::Connection &E : conns) {
  3411. if (E.to_node == to && E.to_port == p_to_index) {
  3412. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3413. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3414. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3415. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3416. }
  3417. }
  3418. undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3419. undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3420. undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3421. undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3422. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, from);
  3423. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, from);
  3424. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3425. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3426. undo_redo->commit_action();
  3427. }
  3428. void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  3429. graph->disconnect_node(p_from, p_from_index, p_to, p_to_index);
  3430. VisualShader::Type type = get_current_shader_type();
  3431. int from = p_from.to_int();
  3432. int to = p_to.to_int();
  3433. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3434. undo_redo->create_action(TTR("Nodes Disconnected"));
  3435. undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3436. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3437. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index);
  3438. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index);
  3439. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3440. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, to);
  3441. undo_redo->commit_action();
  3442. }
  3443. void VisualShaderEditor::_connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position) {
  3444. from_node = p_from.to_int();
  3445. from_slot = p_from_slot;
  3446. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3447. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3448. Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), from_node);
  3449. if (node.is_valid()) {
  3450. output_port_type = node->get_output_port_type(from_slot);
  3451. }
  3452. _show_members_dialog(true, input_port_type, output_port_type);
  3453. }
  3454. void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position) {
  3455. to_node = p_to.to_int();
  3456. to_slot = p_to_slot;
  3457. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3458. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  3459. Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), to_node);
  3460. if (node.is_valid()) {
  3461. input_port_type = node->get_input_port_type(to_slot);
  3462. }
  3463. _show_members_dialog(true, input_port_type, output_port_type);
  3464. }
  3465. 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) {
  3466. VisualShader::Type shader_type = get_current_shader_type();
  3467. // Get selected graph node.
  3468. Ref<VisualShaderNode> selected_vsnode;
  3469. int selected_node_id = -1;
  3470. int selected_node_count = 0;
  3471. Rect2 selected_node_rect;
  3472. for (int i = 0; i < graph->get_child_count(); i++) {
  3473. GraphNode *graph_node = Object::cast_to<GraphNode>(graph->get_child(i));
  3474. if (graph_node && graph_node->is_selected()) {
  3475. selected_node_id = String(graph_node->get_name()).to_int();
  3476. Ref<VisualShaderNode> vsnode = visual_shader->get_node(shader_type, selected_node_id);
  3477. if (!vsnode->is_deletable()) {
  3478. continue;
  3479. }
  3480. selected_node_count += 1;
  3481. Ref<VisualShaderNode> node = visual_shader->get_node(shader_type, selected_node_id);
  3482. selected_vsnode = node;
  3483. selected_node_rect = graph_node->get_rect();
  3484. }
  3485. }
  3486. // Only a single node - which has both input and output ports but is not connected yet - can be inserted.
  3487. if (selected_node_count != 1 || !selected_vsnode.is_valid()) {
  3488. return false;
  3489. }
  3490. // Check whether the dragged node was dropped over a connection.
  3491. List<Ref<GraphEdit::Connection>> intersecting_connections = graph->get_connections_intersecting_with_rect(selected_node_rect);
  3492. if (intersecting_connections.is_empty()) {
  3493. return false;
  3494. }
  3495. Ref<GraphEdit::Connection> intersecting_connection = intersecting_connections.front()->get();
  3496. if (selected_vsnode->is_any_port_connected() || selected_vsnode->get_input_port_count() == 0 || selected_vsnode->get_output_port_count() == 0) {
  3497. return false;
  3498. }
  3499. 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);
  3500. 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);
  3501. Ref<VisualShaderNodeReroute> reroute_node = selected_vsnode;
  3502. // Searching for the default port or the first compatible input port of the node to insert.
  3503. int _to_port = -1;
  3504. for (int i = 0; i < selected_vsnode->get_input_port_count(); i++) {
  3505. if (visual_shader->is_port_types_compatible(original_port_type_from, selected_vsnode->get_input_port_type(i)) || reroute_node.is_valid()) {
  3506. if (i == selected_vsnode->get_default_input_port(original_port_type_from)) {
  3507. _to_port = i;
  3508. break;
  3509. } else if (_to_port == -1) {
  3510. _to_port = i;
  3511. }
  3512. }
  3513. }
  3514. // Searching for the first compatible output port of the node to insert.
  3515. int _from_port = -1;
  3516. for (int i = 0; i < selected_vsnode->get_output_port_count(); i++) {
  3517. if (visual_shader->is_port_types_compatible(selected_vsnode->get_output_port_type(i), original_port_type_to) || reroute_node.is_valid()) {
  3518. _from_port = i;
  3519. break;
  3520. }
  3521. }
  3522. if (_to_port == -1 || _from_port == -1) {
  3523. return false;
  3524. }
  3525. if (r_closest_connection != nullptr) {
  3526. *r_closest_connection = intersecting_connection;
  3527. }
  3528. if (r_from_port != nullptr) {
  3529. *r_from_port = _from_port;
  3530. }
  3531. if (r_to_port != nullptr) {
  3532. *r_to_port = _to_port;
  3533. }
  3534. return true;
  3535. }
  3536. void VisualShaderEditor::_handle_node_drop_on_connection() {
  3537. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3538. undo_redo->create_action(TTR("Insert node"));
  3539. // Check whether the dragged node was dropped over a connection.
  3540. Ref<GraphEdit::Connection> closest_connection;
  3541. int _from_port = -1;
  3542. int _to_port = -1;
  3543. if (!_check_node_drop_on_connection(graph->get_local_mouse_position(), &closest_connection, &_from_port, &_to_port)) {
  3544. return;
  3545. }
  3546. int selected_node_id = drag_buffer.front()->get().node;
  3547. VisualShader::Type shader_type = get_current_shader_type();
  3548. Ref<VisualShaderNode> selected_vsnode = visual_shader->get_node(shader_type, selected_node_id);
  3549. // Delete the old connection.
  3550. 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);
  3551. 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);
  3552. 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);
  3553. 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);
  3554. // Add the connection to the dropped node.
  3555. 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);
  3556. 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);
  3557. 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);
  3558. 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);
  3559. // Add the connection from the dropped node.
  3560. 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);
  3561. 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);
  3562. 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);
  3563. 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);
  3564. undo_redo->commit_action();
  3565. call_deferred(SNAME("_update_graph"));
  3566. }
  3567. void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) {
  3568. VisualShader::Type type = VisualShader::Type(p_type);
  3569. List<VisualShader::Connection> conns;
  3570. visual_shader->get_node_connections(type, &conns);
  3571. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3572. for (const int &F : p_nodes) {
  3573. for (const VisualShader::Connection &E : conns) {
  3574. if (E.from_node == F || E.to_node == F) {
  3575. undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3576. }
  3577. }
  3578. }
  3579. // The VS nodes need to be added before attaching them to frames.
  3580. for (const int &F : p_nodes) {
  3581. Ref<VisualShaderNode> node = visual_shader->get_node(type, F);
  3582. undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F), F);
  3583. undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F, false, false);
  3584. }
  3585. // Update frame references.
  3586. for (const int &node_id : p_nodes) {
  3587. Ref<VisualShaderNodeFrame> frame = visual_shader->get_node(type, node_id);
  3588. if (frame.is_valid()) {
  3589. for (const int &attached_node_id : frame->get_attached_nodes()) {
  3590. undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", type, attached_node_id);
  3591. undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", type, attached_node_id);
  3592. undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", type, attached_node_id, node_id);
  3593. undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", type, attached_node_id, node_id);
  3594. }
  3595. }
  3596. Ref<VisualShaderNode> node = visual_shader->get_node(type, node_id);
  3597. if (node->get_frame() == -1) {
  3598. continue;
  3599. }
  3600. undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", type, node_id);
  3601. undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", type, node_id);
  3602. undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", type, node_id, node->get_frame());
  3603. undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", type, node_id, node->get_frame());
  3604. }
  3605. // Restore size of the frame nodes.
  3606. for (const int &F : p_nodes) {
  3607. Ref<VisualShaderNodeFrame> frame = visual_shader->get_node(type, F);
  3608. if (frame.is_valid()) {
  3609. undo_redo->add_undo_method(this, "_set_node_size", type, F, frame->get_size());
  3610. }
  3611. }
  3612. HashSet<String> parameter_names;
  3613. for (const int &F : p_nodes) {
  3614. Ref<VisualShaderNode> node = visual_shader->get_node(type, F);
  3615. undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F);
  3616. VisualShaderNodeParameter *parameter = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  3617. if (parameter) {
  3618. parameter_names.insert(parameter->get_parameter_name());
  3619. }
  3620. }
  3621. List<VisualShader::Connection> used_conns;
  3622. for (const int &F : p_nodes) {
  3623. for (const VisualShader::Connection &E : conns) {
  3624. if (E.from_node == F || E.to_node == F) {
  3625. bool cancel = false;
  3626. for (List<VisualShader::Connection>::Element *R = used_conns.front(); R; R = R->next()) {
  3627. 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) {
  3628. cancel = true; // to avoid ERR_ALREADY_EXISTS warning
  3629. break;
  3630. }
  3631. }
  3632. if (!cancel) {
  3633. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3634. undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  3635. used_conns.push_back(E);
  3636. }
  3637. }
  3638. }
  3639. }
  3640. // Delete nodes from the graph.
  3641. for (const int &F : p_nodes) {
  3642. undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, F, false);
  3643. }
  3644. // Update parameter refs if any parameter has been deleted.
  3645. if (parameter_names.size() > 0) {
  3646. undo_redo->add_do_method(this, "_update_parameters", true);
  3647. undo_redo->add_undo_method(this, "_update_parameters", true);
  3648. _update_parameter_refs(parameter_names);
  3649. }
  3650. }
  3651. void VisualShaderEditor::_replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to) {
  3652. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3653. undo_redo->add_do_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_to);
  3654. undo_redo->add_undo_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_from);
  3655. }
  3656. void VisualShaderEditor::_update_constant(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port) {
  3657. Ref<VisualShaderNode> node = visual_shader->get_node(p_type_id, p_node_id);
  3658. ERR_FAIL_COND(!node.is_valid());
  3659. ERR_FAIL_COND(!node->has_method("set_constant"));
  3660. node->call("set_constant", p_var);
  3661. if (p_preview_port != -1) {
  3662. node->set_output_port_for_preview(p_preview_port);
  3663. }
  3664. }
  3665. void VisualShaderEditor::_update_parameter(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port) {
  3666. Ref<VisualShaderNodeParameter> parameter = visual_shader->get_node(p_type_id, p_node_id);
  3667. ERR_FAIL_COND(!parameter.is_valid());
  3668. String valid_name = visual_shader->validate_parameter_name(parameter->get_parameter_name(), parameter);
  3669. parameter->set_parameter_name(valid_name);
  3670. graph_plugin->set_parameter_name(p_type_id, p_node_id, valid_name);
  3671. if (parameter->has_method("set_default_value_enabled")) {
  3672. parameter->call("set_default_value_enabled", true);
  3673. parameter->call("set_default_value", p_var);
  3674. }
  3675. if (p_preview_port != -1) {
  3676. parameter->set_output_port_for_preview(p_preview_port);
  3677. }
  3678. }
  3679. void VisualShaderEditor::_convert_constants_to_parameters(bool p_vice_versa) {
  3680. VisualShader::Type type_id = get_current_shader_type();
  3681. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3682. if (!p_vice_versa) {
  3683. undo_redo->create_action(TTR("Convert Constant Node(s) To Parameter(s)"));
  3684. } else {
  3685. undo_redo->create_action(TTR("Convert Parameter Node(s) To Constant(s)"));
  3686. }
  3687. const HashSet<int> &current_set = p_vice_versa ? selected_parameters : selected_constants;
  3688. HashSet<String> deleted_names;
  3689. for (const int &E : current_set) {
  3690. int node_id = E;
  3691. Ref<VisualShaderNode> node = visual_shader->get_node(type_id, node_id);
  3692. bool caught = false;
  3693. Variant var;
  3694. // float
  3695. if (!p_vice_versa) {
  3696. Ref<VisualShaderNodeFloatConstant> float_const = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
  3697. if (float_const.is_valid()) {
  3698. _replace_node(type_id, node_id, "VisualShaderNodeFloatConstant", "VisualShaderNodeFloatParameter");
  3699. var = float_const->get_constant();
  3700. caught = true;
  3701. }
  3702. } else {
  3703. Ref<VisualShaderNodeFloatParameter> float_parameter = Object::cast_to<VisualShaderNodeFloatParameter>(node.ptr());
  3704. if (float_parameter.is_valid()) {
  3705. _replace_node(type_id, node_id, "VisualShaderNodeFloatParameter", "VisualShaderNodeFloatConstant");
  3706. var = float_parameter->get_default_value();
  3707. caught = true;
  3708. }
  3709. }
  3710. // int
  3711. if (!caught) {
  3712. if (!p_vice_versa) {
  3713. Ref<VisualShaderNodeIntConstant> int_const = Object::cast_to<VisualShaderNodeIntConstant>(node.ptr());
  3714. if (int_const.is_valid()) {
  3715. _replace_node(type_id, node_id, "VisualShaderNodeIntConstant", "VisualShaderNodeIntParameter");
  3716. var = int_const->get_constant();
  3717. caught = true;
  3718. }
  3719. } else {
  3720. Ref<VisualShaderNodeIntParameter> int_parameter = Object::cast_to<VisualShaderNodeIntParameter>(node.ptr());
  3721. if (int_parameter.is_valid()) {
  3722. _replace_node(type_id, node_id, "VisualShaderNodeIntParameter", "VisualShaderNodeIntConstant");
  3723. var = int_parameter->get_default_value();
  3724. caught = true;
  3725. }
  3726. }
  3727. }
  3728. // boolean
  3729. if (!caught) {
  3730. if (!p_vice_versa) {
  3731. Ref<VisualShaderNodeBooleanConstant> boolean_const = Object::cast_to<VisualShaderNodeBooleanConstant>(node.ptr());
  3732. if (boolean_const.is_valid()) {
  3733. _replace_node(type_id, node_id, "VisualShaderNodeBooleanConstant", "VisualShaderNodeBooleanParameter");
  3734. var = boolean_const->get_constant();
  3735. caught = true;
  3736. }
  3737. } else {
  3738. Ref<VisualShaderNodeBooleanParameter> boolean_parameter = Object::cast_to<VisualShaderNodeBooleanParameter>(node.ptr());
  3739. if (boolean_parameter.is_valid()) {
  3740. _replace_node(type_id, node_id, "VisualShaderNodeBooleanParameter", "VisualShaderNodeBooleanConstant");
  3741. var = boolean_parameter->get_default_value();
  3742. caught = true;
  3743. }
  3744. }
  3745. }
  3746. // vec2
  3747. if (!caught) {
  3748. if (!p_vice_versa) {
  3749. Ref<VisualShaderNodeVec2Constant> vec2_const = Object::cast_to<VisualShaderNodeVec2Constant>(node.ptr());
  3750. if (vec2_const.is_valid()) {
  3751. _replace_node(type_id, node_id, "VisualShaderNodeVec2Constant", "VisualShaderNodeVec2Parameter");
  3752. var = vec2_const->get_constant();
  3753. caught = true;
  3754. }
  3755. } else {
  3756. Ref<VisualShaderNodeVec2Parameter> vec2_parameter = Object::cast_to<VisualShaderNodeVec2Parameter>(node.ptr());
  3757. if (vec2_parameter.is_valid()) {
  3758. _replace_node(type_id, node_id, "VisualShaderNodeVec2Parameter", "VisualShaderNodeVec2Constant");
  3759. var = vec2_parameter->get_default_value();
  3760. caught = true;
  3761. }
  3762. }
  3763. }
  3764. // vec3
  3765. if (!caught) {
  3766. if (!p_vice_versa) {
  3767. Ref<VisualShaderNodeVec3Constant> vec3_const = Object::cast_to<VisualShaderNodeVec3Constant>(node.ptr());
  3768. if (vec3_const.is_valid()) {
  3769. _replace_node(type_id, node_id, "VisualShaderNodeVec3Constant", "VisualShaderNodeVec3Parameter");
  3770. var = vec3_const->get_constant();
  3771. caught = true;
  3772. }
  3773. } else {
  3774. Ref<VisualShaderNodeVec3Parameter> vec3_parameter = Object::cast_to<VisualShaderNodeVec3Parameter>(node.ptr());
  3775. if (vec3_parameter.is_valid()) {
  3776. _replace_node(type_id, node_id, "VisualShaderNodeVec3Parameter", "VisualShaderNodeVec3Constant");
  3777. var = vec3_parameter->get_default_value();
  3778. caught = true;
  3779. }
  3780. }
  3781. }
  3782. // vec4
  3783. if (!caught) {
  3784. if (!p_vice_versa) {
  3785. Ref<VisualShaderNodeVec4Constant> vec4_const = Object::cast_to<VisualShaderNodeVec4Constant>(node.ptr());
  3786. if (vec4_const.is_valid()) {
  3787. _replace_node(type_id, node_id, "VisualShaderNodeVec4Constant", "VisualShaderNodeVec4Parameter");
  3788. var = vec4_const->get_constant();
  3789. caught = true;
  3790. }
  3791. } else {
  3792. Ref<VisualShaderNodeVec4Parameter> vec4_parameter = Object::cast_to<VisualShaderNodeVec4Parameter>(node.ptr());
  3793. if (vec4_parameter.is_valid()) {
  3794. _replace_node(type_id, node_id, "VisualShaderNodeVec4Parameter", "VisualShaderNodeVec4Constant");
  3795. var = vec4_parameter->get_default_value();
  3796. caught = true;
  3797. }
  3798. }
  3799. }
  3800. // color
  3801. if (!caught) {
  3802. if (!p_vice_versa) {
  3803. Ref<VisualShaderNodeColorConstant> color_const = Object::cast_to<VisualShaderNodeColorConstant>(node.ptr());
  3804. if (color_const.is_valid()) {
  3805. _replace_node(type_id, node_id, "VisualShaderNodeColorConstant", "VisualShaderNodeColorParameter");
  3806. var = color_const->get_constant();
  3807. caught = true;
  3808. }
  3809. } else {
  3810. Ref<VisualShaderNodeColorParameter> color_parameter = Object::cast_to<VisualShaderNodeColorParameter>(node.ptr());
  3811. if (color_parameter.is_valid()) {
  3812. _replace_node(type_id, node_id, "VisualShaderNodeColorParameter", "VisualShaderNodeColorConstant");
  3813. var = color_parameter->get_default_value();
  3814. caught = true;
  3815. }
  3816. }
  3817. }
  3818. // transform
  3819. if (!caught) {
  3820. if (!p_vice_versa) {
  3821. Ref<VisualShaderNodeTransformConstant> transform_const = Object::cast_to<VisualShaderNodeTransformConstant>(node.ptr());
  3822. if (transform_const.is_valid()) {
  3823. _replace_node(type_id, node_id, "VisualShaderNodeTransformConstant", "VisualShaderNodeTransformParameter");
  3824. var = transform_const->get_constant();
  3825. caught = true;
  3826. }
  3827. } else {
  3828. Ref<VisualShaderNodeTransformParameter> transform_parameter = Object::cast_to<VisualShaderNodeTransformParameter>(node.ptr());
  3829. if (transform_parameter.is_valid()) {
  3830. _replace_node(type_id, node_id, "VisualShaderNodeTransformParameter", "VisualShaderNodeTransformConstant");
  3831. var = transform_parameter->get_default_value();
  3832. caught = true;
  3833. }
  3834. }
  3835. }
  3836. ERR_CONTINUE(!caught);
  3837. int preview_port = node->get_output_port_for_preview();
  3838. if (!p_vice_versa) {
  3839. undo_redo->add_do_method(this, "_update_parameter", type_id, node_id, var, preview_port);
  3840. undo_redo->add_undo_method(this, "_update_constant", type_id, node_id, var, preview_port);
  3841. } else {
  3842. undo_redo->add_do_method(this, "_update_constant", type_id, node_id, var, preview_port);
  3843. undo_redo->add_undo_method(this, "_update_parameter", type_id, node_id, var, preview_port);
  3844. Ref<VisualShaderNodeParameter> parameter = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  3845. ERR_CONTINUE(!parameter.is_valid());
  3846. deleted_names.insert(parameter->get_parameter_name());
  3847. }
  3848. undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type_id, node_id);
  3849. undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type_id, node_id);
  3850. }
  3851. undo_redo->add_do_method(this, "_update_parameters", true);
  3852. undo_redo->add_undo_method(this, "_update_parameters", true);
  3853. if (deleted_names.size() > 0) {
  3854. _update_parameter_refs(deleted_names);
  3855. }
  3856. undo_redo->commit_action();
  3857. }
  3858. void VisualShaderEditor::_detach_nodes_from_frame(int p_type, const List<int> &p_nodes) {
  3859. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3860. for (int node_id : p_nodes) {
  3861. Ref<VisualShaderNode> node = visual_shader->get_node((VisualShader::Type)p_type, node_id);
  3862. if (!node.is_valid()) {
  3863. continue;
  3864. }
  3865. int frame_id = node->get_frame();
  3866. if (frame_id != -1) {
  3867. undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", p_type, node_id);
  3868. undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", p_type, node_id);
  3869. undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", p_type, node_id, frame_id);
  3870. undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", p_type, node_id, frame_id);
  3871. }
  3872. }
  3873. }
  3874. void VisualShaderEditor::_detach_nodes_from_frame_request() {
  3875. // Called from context menu.
  3876. List<int> to_detach_node_ids;
  3877. for (int i = 0; i < graph->get_child_count(); i++) {
  3878. GraphElement *gn = Object::cast_to<GraphElement>(graph->get_child(i));
  3879. if (gn) {
  3880. int id = String(gn->get_name()).to_int();
  3881. if (gn->is_selected()) {
  3882. to_detach_node_ids.push_back(id);
  3883. }
  3884. }
  3885. }
  3886. if (to_detach_node_ids.is_empty()) {
  3887. return;
  3888. }
  3889. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3890. undo_redo->create_action(TTR("Detach VisualShader Node(s) from Frame"));
  3891. _detach_nodes_from_frame(get_current_shader_type(), to_detach_node_ids);
  3892. undo_redo->commit_action();
  3893. }
  3894. void VisualShaderEditor::_delete_node_request(int p_type, int p_node) {
  3895. Ref<VisualShaderNode> node = visual_shader->get_node((VisualShader::Type)p_type, p_node);
  3896. if (!node->is_deletable()) {
  3897. return;
  3898. }
  3899. List<int> to_erase;
  3900. to_erase.push_back(p_node);
  3901. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3902. undo_redo->create_action(TTR("Delete VisualShader Node"));
  3903. _delete_nodes(p_type, to_erase);
  3904. undo_redo->commit_action();
  3905. }
  3906. void VisualShaderEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) {
  3907. List<int> to_erase;
  3908. if (p_nodes.is_empty()) {
  3909. // Called from context menu.
  3910. for (int i = 0; i < graph->get_child_count(); i++) {
  3911. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  3912. if (!graph_element) {
  3913. continue;
  3914. }
  3915. VisualShader::Type type = get_current_shader_type();
  3916. int id = String(graph_element->get_name()).to_int();
  3917. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  3918. if (vsnode->is_deletable() && graph_element->is_selected()) {
  3919. to_erase.push_back(graph_element->get_name().operator String().to_int());
  3920. }
  3921. }
  3922. } else {
  3923. VisualShader::Type type = get_current_shader_type();
  3924. for (int i = 0; i < p_nodes.size(); i++) {
  3925. int id = p_nodes[i].operator String().to_int();
  3926. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  3927. if (vsnode->is_deletable()) {
  3928. to_erase.push_back(id);
  3929. }
  3930. }
  3931. }
  3932. if (to_erase.is_empty()) {
  3933. return;
  3934. }
  3935. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  3936. undo_redo->create_action(TTR("Delete VisualShader Node(s)"));
  3937. _delete_nodes(get_current_shader_type(), to_erase);
  3938. undo_redo->commit_action();
  3939. }
  3940. void VisualShaderEditor::_node_selected(Object *p_node) {
  3941. VisualShader::Type type = get_current_shader_type();
  3942. GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
  3943. ERR_FAIL_NULL(graph_element);
  3944. int id = String(graph_element->get_name()).to_int();
  3945. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  3946. ERR_FAIL_COND(!vsnode.is_valid());
  3947. }
  3948. void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
  3949. Ref<InputEventMouseMotion> mm = p_event;
  3950. Ref<InputEventMouseButton> mb = p_event;
  3951. VisualShader::Type type = get_current_shader_type();
  3952. // Highlight valid connection on which a node can be dropped.
  3953. if (mm.is_valid() && mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) {
  3954. Ref<GraphEdit::Connection> closest_connection;
  3955. graph->reset_all_connection_activity();
  3956. if (_check_node_drop_on_connection(graph->get_local_mouse_position(), &closest_connection)) {
  3957. graph->set_connection_activity(closest_connection->from_node, closest_connection->from_port, closest_connection->to_node, closest_connection->to_port, 1.0);
  3958. }
  3959. }
  3960. Ref<VisualShaderNode> selected_vsnode;
  3961. // Right click actions.
  3962. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {
  3963. selected_constants.clear();
  3964. selected_parameters.clear();
  3965. selected_frame = -1;
  3966. selected_float_constant = -1;
  3967. List<int> selected_deletable_graph_elements;
  3968. List<GraphElement *> selected_graph_elements;
  3969. for (int i = 0; i < graph->get_child_count(); i++) {
  3970. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  3971. if (!graph_element) {
  3972. continue;
  3973. }
  3974. int id = String(graph_element->get_name()).to_int();
  3975. Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id);
  3976. if (!graph_element->is_selected()) {
  3977. continue;
  3978. }
  3979. selected_graph_elements.push_back(graph_element);
  3980. if (!vsnode->is_deletable()) {
  3981. continue;
  3982. }
  3983. selected_deletable_graph_elements.push_back(id);
  3984. Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
  3985. selected_vsnode = node;
  3986. VisualShaderNodeFrame *frame_node = Object::cast_to<VisualShaderNodeFrame>(node.ptr());
  3987. if (frame_node != nullptr) {
  3988. selected_frame = id;
  3989. }
  3990. VisualShaderNodeConstant *constant_node = Object::cast_to<VisualShaderNodeConstant>(node.ptr());
  3991. if (constant_node != nullptr) {
  3992. selected_constants.insert(id);
  3993. }
  3994. VisualShaderNodeFloatConstant *float_constant_node = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
  3995. if (float_constant_node != nullptr) {
  3996. selected_float_constant = id;
  3997. }
  3998. VisualShaderNodeParameter *parameter_node = Object::cast_to<VisualShaderNodeParameter>(node.ptr());
  3999. if (parameter_node != nullptr && parameter_node->is_convertible_to_constant()) {
  4000. selected_parameters.insert(id);
  4001. }
  4002. }
  4003. if (selected_deletable_graph_elements.size() > 1) {
  4004. selected_frame = -1;
  4005. selected_float_constant = -1;
  4006. }
  4007. bool copy_buffer_empty = true;
  4008. for (const CopyItem &item : copy_items_buffer) {
  4009. if (!item.disabled) {
  4010. copy_buffer_empty = false;
  4011. break;
  4012. }
  4013. }
  4014. menu_point = graph->get_local_mouse_position();
  4015. Point2 gpos = get_screen_position() + get_local_mouse_position();
  4016. Ref<GraphEdit::Connection> closest_connection = graph->get_closest_connection_at_point(menu_point);
  4017. if (closest_connection.is_valid()) {
  4018. clicked_connection = closest_connection;
  4019. saved_node_pos = graph->get_local_mouse_position();
  4020. saved_node_pos_dirty = true;
  4021. connection_popup_menu->set_position(gpos);
  4022. connection_popup_menu->reset_size();
  4023. connection_popup_menu->popup();
  4024. } else if (selected_graph_elements.is_empty() && copy_buffer_empty) {
  4025. _show_members_dialog(true);
  4026. } else {
  4027. popup_menu->set_item_disabled(NodeMenuOptions::CUT, selected_deletable_graph_elements.is_empty());
  4028. popup_menu->set_item_disabled(NodeMenuOptions::COPY, selected_deletable_graph_elements.is_empty());
  4029. popup_menu->set_item_disabled(NodeMenuOptions::PASTE, copy_buffer_empty);
  4030. popup_menu->set_item_disabled(NodeMenuOptions::DELETE, selected_deletable_graph_elements.is_empty());
  4031. popup_menu->set_item_disabled(NodeMenuOptions::DUPLICATE, selected_deletable_graph_elements.is_empty());
  4032. popup_menu->set_item_disabled(NodeMenuOptions::CLEAR_COPY_BUFFER, copy_buffer_empty);
  4033. int temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR2);
  4034. if (temp != -1) {
  4035. popup_menu->remove_item(temp);
  4036. }
  4037. temp = popup_menu->get_item_index(NodeMenuOptions::FLOAT_CONSTANTS);
  4038. if (temp != -1) {
  4039. popup_menu->remove_item(temp);
  4040. }
  4041. temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS);
  4042. if (temp != -1) {
  4043. popup_menu->remove_item(temp);
  4044. }
  4045. temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS);
  4046. if (temp != -1) {
  4047. popup_menu->remove_item(temp);
  4048. }
  4049. temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR3);
  4050. if (temp != -1) {
  4051. popup_menu->remove_item(temp);
  4052. }
  4053. temp = popup_menu->get_item_index(NodeMenuOptions::UNLINK_FROM_PARENT_FRAME);
  4054. if (temp != -1) {
  4055. popup_menu->remove_item(temp);
  4056. }
  4057. temp = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_TITLE);
  4058. if (temp != -1) {
  4059. popup_menu->remove_item(temp);
  4060. }
  4061. temp = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR);
  4062. if (temp != -1) {
  4063. popup_menu->remove_item(temp);
  4064. }
  4065. temp = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_COLOR);
  4066. if (temp != -1) {
  4067. popup_menu->remove_item(temp);
  4068. }
  4069. temp = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  4070. if (temp != -1) {
  4071. popup_menu->remove_item(temp);
  4072. }
  4073. if (selected_constants.size() > 0 || selected_parameters.size() > 0) {
  4074. popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2);
  4075. if (selected_float_constant != -1) {
  4076. if (!constants_submenu) {
  4077. constants_submenu = memnew(PopupMenu);
  4078. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  4079. constants_submenu->add_item(float_constant_defs[i].name, i);
  4080. }
  4081. constants_submenu->connect("index_pressed", callable_mp(this, &VisualShaderEditor::_float_constant_selected));
  4082. }
  4083. popup_menu->add_submenu_node_item(TTR("Float Constants"), constants_submenu, int(NodeMenuOptions::FLOAT_CONSTANTS));
  4084. }
  4085. if (selected_constants.size() > 0) {
  4086. popup_menu->add_item(TTR("Convert Constant(s) to Parameter(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS);
  4087. }
  4088. if (selected_parameters.size() > 0) {
  4089. popup_menu->add_item(TTR("Convert Parameter(s) to Constant(s)"), NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS);
  4090. }
  4091. }
  4092. // Check if any selected node is attached to a frame.
  4093. bool is_attached_to_frame = false;
  4094. for (GraphElement *graph_element : selected_graph_elements) {
  4095. if (graph->get_element_frame(graph_element->get_name())) {
  4096. is_attached_to_frame = true;
  4097. break;
  4098. }
  4099. }
  4100. if (is_attached_to_frame) {
  4101. popup_menu->add_item(TTR("Detach from Parent Frame"), NodeMenuOptions::UNLINK_FROM_PARENT_FRAME);
  4102. }
  4103. if (selected_frame != -1) {
  4104. popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3);
  4105. popup_menu->add_item(TTR("Set Frame Title"), NodeMenuOptions::SET_FRAME_TITLE);
  4106. popup_menu->add_check_item(TTR("Enable Auto Shrink"), NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  4107. popup_menu->add_check_item(TTR("Enable Tint Color"), NodeMenuOptions::ENABLE_FRAME_COLOR);
  4108. VisualShaderNodeFrame *frame_ref = Object::cast_to<VisualShaderNodeFrame>(selected_vsnode.ptr());
  4109. if (frame_ref) {
  4110. int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR);
  4111. popup_menu->set_item_checked(item_index, frame_ref->is_tint_color_enabled());
  4112. if (frame_ref->is_tint_color_enabled()) {
  4113. popup_menu->add_item(TTR("Set Tint Color"), NodeMenuOptions::SET_FRAME_COLOR);
  4114. }
  4115. item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK);
  4116. popup_menu->set_item_checked(item_index, frame_ref->is_autoshrink_enabled());
  4117. }
  4118. }
  4119. popup_menu->set_position(gpos);
  4120. popup_menu->reset_size();
  4121. popup_menu->popup();
  4122. }
  4123. }
  4124. }
  4125. void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type, VisualShaderNode::PortType p_output_port_type) {
  4126. if (members_input_port_type != p_input_port_type || members_output_port_type != p_output_port_type) {
  4127. members_input_port_type = p_input_port_type;
  4128. members_output_port_type = p_output_port_type;
  4129. _update_options_menu();
  4130. }
  4131. if (at_mouse_pos) {
  4132. saved_node_pos_dirty = true;
  4133. saved_node_pos = graph->get_local_mouse_position();
  4134. Point2 gpos = get_screen_position() + get_local_mouse_position();
  4135. members_dialog->set_position(gpos);
  4136. } else {
  4137. saved_node_pos_dirty = false;
  4138. members_dialog->set_position(graph->get_screen_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  4139. }
  4140. if (members_dialog->is_visible()) {
  4141. members_dialog->grab_focus();
  4142. return;
  4143. }
  4144. members_dialog->popup();
  4145. // Keep dialog within window bounds.
  4146. Rect2 window_rect = Rect2(get_window()->get_position(), get_window()->get_size());
  4147. Rect2 dialog_rect = Rect2(members_dialog->get_position(), members_dialog->get_size());
  4148. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0);
  4149. members_dialog->set_position(members_dialog->get_position() - difference);
  4150. callable_mp((Control *)node_filter, &Control::grab_focus).call_deferred(); // Still not visible.
  4151. node_filter->select_all();
  4152. }
  4153. void VisualShaderEditor::_varying_menu_id_pressed(int p_idx) {
  4154. switch (VaryingMenuOptions(p_idx)) {
  4155. case VaryingMenuOptions::ADD: {
  4156. _show_add_varying_dialog();
  4157. } break;
  4158. case VaryingMenuOptions::REMOVE: {
  4159. _show_remove_varying_dialog();
  4160. } break;
  4161. default:
  4162. break;
  4163. }
  4164. }
  4165. void VisualShaderEditor::_show_add_varying_dialog() {
  4166. _varying_name_changed(varying_name->get_text());
  4167. add_varying_dialog->set_position(graph->get_screen_position() + varying_button->get_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  4168. add_varying_dialog->popup();
  4169. // Keep dialog within window bounds.
  4170. Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size());
  4171. Rect2 dialog_rect = Rect2(add_varying_dialog->get_position(), add_varying_dialog->get_size());
  4172. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0);
  4173. add_varying_dialog->set_position(add_varying_dialog->get_position() - difference);
  4174. }
  4175. void VisualShaderEditor::_show_remove_varying_dialog() {
  4176. remove_varying_dialog->set_position(graph->get_screen_position() + varying_button->get_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
  4177. remove_varying_dialog->popup();
  4178. // Keep dialog within window bounds.
  4179. Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size());
  4180. Rect2 dialog_rect = Rect2(remove_varying_dialog->get_position(), remove_varying_dialog->get_size());
  4181. Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0);
  4182. remove_varying_dialog->set_position(remove_varying_dialog->get_position() - difference);
  4183. }
  4184. void VisualShaderEditor::_sbox_input(const Ref<InputEvent> &p_ie) {
  4185. Ref<InputEventKey> ie = p_ie;
  4186. if (ie.is_valid() && (ie->get_keycode() == Key::UP || ie->get_keycode() == Key::DOWN || ie->get_keycode() == Key::ENTER || ie->get_keycode() == Key::KP_ENTER)) {
  4187. members->gui_input(ie);
  4188. node_filter->accept_event();
  4189. }
  4190. }
  4191. void VisualShaderEditor::_param_filter_changed(const String &p_text) {
  4192. param_filter_name = p_text;
  4193. if (!_update_preview_parameter_tree()) {
  4194. _clear_preview_param();
  4195. }
  4196. }
  4197. void VisualShaderEditor::_param_property_changed(const String &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
  4198. if (p_changing) {
  4199. return;
  4200. }
  4201. String raw_prop_name = p_property.trim_prefix("shader_parameter/");
  4202. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4203. undo_redo->create_action(vformat(TTR("Edit Preview Parameter: %s"), p_property));
  4204. undo_redo->add_do_method(visual_shader.ptr(), "_set_preview_shader_parameter", raw_prop_name, p_value);
  4205. undo_redo->add_undo_method(visual_shader.ptr(), "_set_preview_shader_parameter", raw_prop_name, preview_material->get(p_property));
  4206. undo_redo->add_do_method(this, "_update_current_param");
  4207. undo_redo->add_undo_method(this, "_update_current_param");
  4208. undo_redo->commit_action();
  4209. }
  4210. void VisualShaderEditor::_update_current_param() {
  4211. if (current_prop != nullptr) {
  4212. String name = current_prop->get_meta("id");
  4213. preview_material->set("shader_parameter/" + name, visual_shader->_get_preview_shader_parameter(name));
  4214. current_prop->update_property();
  4215. current_prop->update_editor_property_status();
  4216. current_prop->update_cache();
  4217. }
  4218. }
  4219. void VisualShaderEditor::_param_selected() {
  4220. _clear_preview_param();
  4221. TreeItem *item = parameters->get_selected();
  4222. selected_param_id = item->get_meta("id");
  4223. PropertyInfo pi = parameter_props.get(selected_param_id);
  4224. EditorProperty *prop = EditorInspector::instantiate_property_editor(preview_material.ptr(), pi.type, pi.name, pi.hint, pi.hint_string, pi.usage);
  4225. if (!prop) {
  4226. return;
  4227. }
  4228. prop->connect("property_changed", callable_mp(this, &VisualShaderEditor::_param_property_changed));
  4229. prop->set_h_size_flags(SIZE_EXPAND_FILL);
  4230. prop->set_object_and_property(preview_material.ptr(), "shader_parameter/" + pi.name);
  4231. prop->set_label(TTR("Value:"));
  4232. prop->update_property();
  4233. prop->update_editor_property_status();
  4234. prop->update_cache();
  4235. current_prop = prop;
  4236. current_prop->set_meta("id", selected_param_id);
  4237. param_vbox2->add_child(prop);
  4238. param_vbox->show();
  4239. }
  4240. void VisualShaderEditor::_param_unselected() {
  4241. parameters->deselect_all();
  4242. _clear_preview_param();
  4243. }
  4244. void VisualShaderEditor::_notification(int p_what) {
  4245. switch (p_what) {
  4246. case NOTIFICATION_POSTINITIALIZE: {
  4247. _update_options_menu();
  4248. } break;
  4249. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  4250. if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/panning")) {
  4251. 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")));
  4252. graph->set_warped_panning(bool(EDITOR_GET("editors/panning/warped_mouse_panning")));
  4253. }
  4254. if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/visual_editors")) {
  4255. graph->set_minimap_opacity(EDITOR_GET("editors/visual_editors/minimap_opacity"));
  4256. graph->set_grid_pattern((GraphEdit::GridPattern) int(EDITOR_GET("editors/visual_editors/grid_pattern")));
  4257. graph->set_connection_lines_curvature(EDITOR_GET("editors/visual_editors/lines_curvature"));
  4258. _update_graph();
  4259. }
  4260. } break;
  4261. case NOTIFICATION_ENTER_TREE: {
  4262. node_filter->set_clear_button_enabled(true);
  4263. // collapse tree by default
  4264. TreeItem *category = members->get_root()->get_first_child();
  4265. while (category) {
  4266. category->set_collapsed(true);
  4267. TreeItem *sub_category = category->get_first_child();
  4268. while (sub_category) {
  4269. sub_category->set_collapsed(true);
  4270. sub_category = sub_category->get_next();
  4271. }
  4272. category = category->get_next();
  4273. }
  4274. 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")));
  4275. graph->set_warped_panning(bool(EDITOR_GET("editors/panning/warped_mouse_panning")));
  4276. } break;
  4277. case NOTIFICATION_THEME_CHANGED: {
  4278. highend_label->set_modulate(get_theme_color(SNAME("highend_color"), EditorStringName(Editor)));
  4279. param_filter->set_right_icon(Control::get_editor_theme_icon(SNAME("Search")));
  4280. node_filter->set_right_icon(Control::get_editor_theme_icon(SNAME("Search")));
  4281. code_preview_button->set_icon(Control::get_editor_theme_icon(SNAME("Shader")));
  4282. shader_preview_button->set_icon(Control::get_editor_theme_icon(SNAME("SubViewport")));
  4283. {
  4284. Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color");
  4285. Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color");
  4286. Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
  4287. Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color");
  4288. Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
  4289. Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color");
  4290. Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color");
  4291. Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color");
  4292. Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color");
  4293. Color error_color = get_theme_color(SNAME("error_color"), EditorStringName(Editor));
  4294. preview_text->add_theme_color_override("background_color", background_color);
  4295. varying_error_label->add_theme_color_override(SceneStringName(font_color), error_color);
  4296. for (const String &E : keyword_list) {
  4297. if (ShaderLanguage::is_control_flow_keyword(E)) {
  4298. syntax_highlighter->add_keyword_color(E, control_flow_keyword_color);
  4299. } else {
  4300. syntax_highlighter->add_keyword_color(E, keyword_color);
  4301. }
  4302. }
  4303. preview_text->begin_bulk_theme_override();
  4304. preview_text->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("expression"), EditorStringName(EditorFonts)));
  4305. preview_text->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("expression_size"), EditorStringName(EditorFonts)));
  4306. preview_text->add_theme_color_override(SceneStringName(font_color), text_color);
  4307. preview_text->end_bulk_theme_override();
  4308. syntax_highlighter->set_number_color(number_color);
  4309. syntax_highlighter->set_symbol_color(symbol_color);
  4310. syntax_highlighter->set_function_color(function_color);
  4311. syntax_highlighter->set_member_variable_color(members_color);
  4312. syntax_highlighter->clear_color_regions();
  4313. syntax_highlighter->add_color_region("/*", "*/", comment_color, false);
  4314. syntax_highlighter->add_color_region("//", "", comment_color, true);
  4315. preview_text->clear_comment_delimiters();
  4316. preview_text->add_comment_delimiter("/*", "*/", false);
  4317. preview_text->add_comment_delimiter("//", "", true);
  4318. error_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Panel")));
  4319. error_label->begin_bulk_theme_override();
  4320. error_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));
  4321. error_label->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));
  4322. error_label->add_theme_color_override(SceneStringName(font_color), error_color);
  4323. error_label->end_bulk_theme_override();
  4324. }
  4325. tools->set_icon(get_editor_theme_icon(SNAME("Tools")));
  4326. if (is_visible_in_tree()) {
  4327. _update_graph();
  4328. }
  4329. } break;
  4330. case NOTIFICATION_DRAG_BEGIN: {
  4331. Dictionary dd = get_viewport()->gui_get_drag_data();
  4332. if (members->is_visible_in_tree() && dd.has("id")) {
  4333. members->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
  4334. }
  4335. } break;
  4336. case NOTIFICATION_DRAG_END: {
  4337. members->set_drop_mode_flags(0);
  4338. } break;
  4339. }
  4340. }
  4341. void VisualShaderEditor::_scroll_changed(const Vector2 &p_scroll) {
  4342. if (updating) {
  4343. return;
  4344. }
  4345. updating = true;
  4346. visual_shader->set_graph_offset(p_scroll / EDSCALE);
  4347. updating = false;
  4348. }
  4349. void VisualShaderEditor::_node_changed(int p_id) {
  4350. if (updating) {
  4351. return;
  4352. }
  4353. if (is_visible_in_tree()) {
  4354. _update_graph();
  4355. }
  4356. }
  4357. void VisualShaderEditor::_nodes_linked_to_frame_request(const TypedArray<StringName> &p_nodes, const StringName &p_frame) {
  4358. Vector<int> node_ids;
  4359. for (int i = 0; i < p_nodes.size(); i++) {
  4360. node_ids.push_back(p_nodes[i].operator String().to_int());
  4361. }
  4362. frame_node_id_to_link_to = p_frame.operator String().to_int();
  4363. nodes_link_to_frame_buffer = node_ids;
  4364. }
  4365. void VisualShaderEditor::_frame_rect_changed(const GraphFrame *p_frame, const Rect2 &p_new_rect) {
  4366. if (p_frame == nullptr) {
  4367. return;
  4368. }
  4369. int node_id = String(p_frame->get_name()).to_int();
  4370. Ref<VisualShaderNodeResizableBase> vsnode = visual_shader->get_node(visual_shader->get_shader_type(), node_id);
  4371. if (vsnode.is_null()) {
  4372. return;
  4373. }
  4374. vsnode->set_size(p_new_rect.size / graph->get_zoom());
  4375. }
  4376. void VisualShaderEditor::_dup_copy_nodes(int p_type, List<CopyItem> &r_items, List<VisualShader::Connection> &r_connections) {
  4377. VisualShader::Type type = (VisualShader::Type)p_type;
  4378. selection_center.x = 0.0f;
  4379. selection_center.y = 0.0f;
  4380. HashSet<int> nodes;
  4381. for (int i = 0; i < graph->get_child_count(); i++) {
  4382. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  4383. if (graph_element) {
  4384. int id = String(graph_element->get_name()).to_int();
  4385. Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
  4386. Ref<VisualShaderNodeOutput> output = node;
  4387. if (output.is_valid()) { // can't duplicate output
  4388. continue;
  4389. }
  4390. if (node.is_valid() && graph_element->is_selected()) {
  4391. Vector2 pos = visual_shader->get_node_position(type, id);
  4392. selection_center += pos;
  4393. CopyItem item;
  4394. item.id = id;
  4395. item.node = visual_shader->get_node(type, id)->duplicate();
  4396. item.position = visual_shader->get_node_position(type, id);
  4397. Ref<VisualShaderNodeResizableBase> resizable_base = node;
  4398. if (resizable_base.is_valid()) {
  4399. item.size = resizable_base->get_size();
  4400. }
  4401. Ref<VisualShaderNodeGroupBase> group = node;
  4402. if (group.is_valid()) {
  4403. item.group_inputs = group->get_inputs();
  4404. item.group_outputs = group->get_outputs();
  4405. }
  4406. Ref<VisualShaderNodeExpression> expression = node;
  4407. if (expression.is_valid()) {
  4408. item.expression = expression->get_expression();
  4409. }
  4410. r_items.push_back(item);
  4411. nodes.insert(id);
  4412. }
  4413. }
  4414. }
  4415. List<VisualShader::Connection> node_connections;
  4416. visual_shader->get_node_connections(type, &node_connections);
  4417. for (const VisualShader::Connection &E : node_connections) {
  4418. if (nodes.has(E.from_node) && nodes.has(E.to_node)) {
  4419. r_connections.push_back(E);
  4420. }
  4421. }
  4422. selection_center /= (float)r_items.size();
  4423. }
  4424. 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) {
  4425. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4426. if (p_duplicate) {
  4427. undo_redo->create_action(TTR("Duplicate VisualShader Node(s)"));
  4428. } else {
  4429. bool copy_buffer_empty = true;
  4430. for (const CopyItem &item : copy_items_buffer) {
  4431. if (!item.disabled) {
  4432. copy_buffer_empty = false;
  4433. break;
  4434. }
  4435. }
  4436. if (copy_buffer_empty) {
  4437. return;
  4438. }
  4439. undo_redo->create_action(TTR("Paste VisualShader Node(s)"));
  4440. }
  4441. VisualShader::Type type = (VisualShader::Type)p_type;
  4442. int base_id = visual_shader->get_valid_node_id(type);
  4443. int id_from = base_id;
  4444. HashMap<int, int> connection_remap; // Used for connections and frame attachments.
  4445. HashSet<int> unsupported_set;
  4446. HashSet<int> added_set;
  4447. for (CopyItem &item : r_items) {
  4448. if (item.disabled) {
  4449. unsupported_set.insert(item.id);
  4450. continue;
  4451. }
  4452. connection_remap[item.id] = id_from;
  4453. Ref<VisualShaderNode> node = item.node->duplicate();
  4454. node->set_frame(-1); // Do not reattach nodes to frame (for now).
  4455. Ref<VisualShaderNodeResizableBase> resizable_base = Object::cast_to<VisualShaderNodeResizableBase>(node.ptr());
  4456. if (resizable_base.is_valid()) {
  4457. undo_redo->add_do_method(node.ptr(), "set_size", item.size);
  4458. }
  4459. Ref<VisualShaderNodeFrame> frame = Object::cast_to<VisualShaderNodeFrame>(node.ptr());
  4460. if (frame.is_valid()) {
  4461. // Do not reattach nodes to frame (for now).
  4462. undo_redo->add_do_method(node.ptr(), "set_attached_nodes", PackedInt32Array());
  4463. }
  4464. Ref<VisualShaderNodeGroupBase> group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
  4465. if (group.is_valid()) {
  4466. undo_redo->add_do_method(node.ptr(), "set_inputs", item.group_inputs);
  4467. undo_redo->add_do_method(node.ptr(), "set_outputs", item.group_outputs);
  4468. }
  4469. Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
  4470. if (expression.is_valid()) {
  4471. undo_redo->add_do_method(node.ptr(), "set_expression", item.expression);
  4472. }
  4473. undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, node, item.position + p_offset, id_from);
  4474. undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_from, false, false);
  4475. added_set.insert(id_from);
  4476. id_from++;
  4477. }
  4478. // Attach nodes to frame.
  4479. for (const CopyItem &item : r_items) {
  4480. Ref<VisualShaderNode> node = item.node;
  4481. if (node->get_frame() == -1) {
  4482. continue;
  4483. }
  4484. int new_node_id = connection_remap[item.id];
  4485. int new_frame_id = node->get_frame();
  4486. undo_redo->add_do_method(visual_shader.ptr(), "attach_node_to_frame", type, new_node_id, new_frame_id);
  4487. undo_redo->add_do_method(graph_plugin.ptr(), "attach_node_to_frame", type, new_node_id, new_frame_id);
  4488. }
  4489. // Connect nodes.
  4490. for (const VisualShader::Connection &E : p_connections) {
  4491. if (unsupported_set.has(E.from_node) || unsupported_set.has(E.to_node)) {
  4492. continue;
  4493. }
  4494. 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);
  4495. 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);
  4496. 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);
  4497. }
  4498. id_from = base_id;
  4499. for (const CopyItem &item : r_items) {
  4500. if (item.disabled) {
  4501. continue;
  4502. }
  4503. undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_from);
  4504. undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_from, false);
  4505. id_from++;
  4506. }
  4507. undo_redo->commit_action();
  4508. // Reselect nodes by excluding the other ones.
  4509. for (int i = 0; i < graph->get_child_count(); i++) {
  4510. GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i));
  4511. if (graph_element) {
  4512. int id = String(graph_element->get_name()).to_int();
  4513. if (added_set.has(id)) {
  4514. graph_element->set_selected(true);
  4515. } else {
  4516. graph_element->set_selected(false);
  4517. }
  4518. }
  4519. }
  4520. }
  4521. void VisualShaderEditor::_clear_copy_buffer() {
  4522. copy_items_buffer.clear();
  4523. copy_connections_buffer.clear();
  4524. }
  4525. void VisualShaderEditor::_duplicate_nodes() {
  4526. int type = get_current_shader_type();
  4527. List<CopyItem> items;
  4528. List<VisualShader::Connection> node_connections;
  4529. _dup_copy_nodes(type, items, node_connections);
  4530. if (items.is_empty()) {
  4531. return;
  4532. }
  4533. _dup_paste_nodes(type, items, node_connections, Vector2(10, 10) * EDSCALE, true);
  4534. }
  4535. void VisualShaderEditor::_copy_nodes(bool p_cut) {
  4536. _clear_copy_buffer();
  4537. _dup_copy_nodes(get_current_shader_type(), copy_items_buffer, copy_connections_buffer);
  4538. if (p_cut) {
  4539. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4540. undo_redo->create_action(TTR("Cut VisualShader Node(s)"));
  4541. List<int> ids;
  4542. for (const CopyItem &E : copy_items_buffer) {
  4543. ids.push_back(E.id);
  4544. }
  4545. _delete_nodes(get_current_shader_type(), ids);
  4546. undo_redo->commit_action();
  4547. }
  4548. }
  4549. void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2 &p_custom_position) {
  4550. if (copy_items_buffer.is_empty()) {
  4551. return;
  4552. }
  4553. int type = get_current_shader_type();
  4554. float scale = graph->get_zoom();
  4555. Vector2 mpos;
  4556. if (p_use_custom_position) {
  4557. mpos = p_custom_position;
  4558. } else {
  4559. mpos = graph->get_local_mouse_position();
  4560. }
  4561. _dup_paste_nodes(type, copy_items_buffer, copy_connections_buffer, graph->get_scroll_offset() / scale + mpos / scale - selection_center, false);
  4562. }
  4563. void VisualShaderEditor::_mode_selected(int p_id) {
  4564. int offset = 0;
  4565. if (mode & MODE_FLAGS_PARTICLES) {
  4566. offset = 3;
  4567. if (p_id + offset > VisualShader::TYPE_PROCESS) {
  4568. custom_mode_box->set_visible(false);
  4569. custom_mode_enabled = false;
  4570. } else {
  4571. custom_mode_box->set_visible(true);
  4572. if (custom_mode_box->is_pressed()) {
  4573. custom_mode_enabled = true;
  4574. offset += 3;
  4575. }
  4576. }
  4577. } else if (mode & MODE_FLAGS_SKY) {
  4578. offset = 8;
  4579. } else if (mode & MODE_FLAGS_FOG) {
  4580. offset = 9;
  4581. }
  4582. visual_shader->set_shader_type(VisualShader::Type(p_id + offset));
  4583. _update_nodes();
  4584. _update_graph();
  4585. graph->grab_focus();
  4586. }
  4587. void VisualShaderEditor::_custom_mode_toggled(bool p_enabled) {
  4588. if (!(mode & MODE_FLAGS_PARTICLES)) {
  4589. return;
  4590. }
  4591. custom_mode_enabled = p_enabled;
  4592. int id = edit_type->get_selected() + 3;
  4593. if (p_enabled) {
  4594. visual_shader->set_shader_type(VisualShader::Type(id + 3));
  4595. } else {
  4596. visual_shader->set_shader_type(VisualShader::Type(id));
  4597. }
  4598. _update_options_menu();
  4599. _update_graph();
  4600. }
  4601. void VisualShaderEditor::_input_select_item(Ref<VisualShaderNodeInput> p_input, const String &p_name) {
  4602. String prev_name = p_input->get_input_name();
  4603. if (p_name == prev_name) {
  4604. return;
  4605. }
  4606. VisualShaderNode::PortType next_input_type = p_input->get_input_type_by_name(p_name);
  4607. VisualShaderNode::PortType prev_input_type = p_input->get_input_type_by_name(prev_name);
  4608. bool type_changed = next_input_type != prev_input_type;
  4609. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  4610. undo_redo_man->create_action(TTR("Visual Shader Input Type Changed"));
  4611. undo_redo_man->add_do_method(p_input.ptr(), "set_input_name", p_name);
  4612. undo_redo_man->add_undo_method(p_input.ptr(), "set_input_name", prev_name);
  4613. if (type_changed) {
  4614. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  4615. VisualShader::Type type = VisualShader::Type(type_id);
  4616. int id = visual_shader->find_node_id(type, p_input);
  4617. if (id != VisualShader::NODE_ID_INVALID) {
  4618. bool is_expanded = p_input->is_output_port_expandable(0) && p_input->_is_output_port_expanded(0);
  4619. int type_size = 0;
  4620. if (is_expanded) {
  4621. switch (next_input_type) {
  4622. case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
  4623. type_size = 2;
  4624. } break;
  4625. case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
  4626. type_size = 3;
  4627. } break;
  4628. case VisualShaderNode::PORT_TYPE_VECTOR_4D: {
  4629. type_size = 4;
  4630. } break;
  4631. default:
  4632. break;
  4633. }
  4634. }
  4635. List<VisualShader::Connection> conns;
  4636. visual_shader->get_node_connections(type, &conns);
  4637. for (const VisualShader::Connection &E : conns) {
  4638. int cn_from_node = E.from_node;
  4639. int cn_from_port = E.from_port;
  4640. int cn_to_node = E.to_node;
  4641. int cn_to_port = E.to_port;
  4642. if (cn_from_node == id) {
  4643. 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));
  4644. if (is_incompatible_types || cn_from_port > type_size) {
  4645. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4646. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4647. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4648. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port);
  4649. }
  4650. }
  4651. }
  4652. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  4653. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  4654. }
  4655. }
  4656. }
  4657. undo_redo_man->commit_action();
  4658. }
  4659. void VisualShaderEditor::_parameter_ref_select_item(Ref<VisualShaderNodeParameterRef> p_parameter_ref, const String &p_name) {
  4660. String prev_name = p_parameter_ref->get_parameter_name();
  4661. if (p_name == prev_name) {
  4662. return;
  4663. }
  4664. bool type_changed = p_parameter_ref->get_parameter_type_by_name(p_name) != p_parameter_ref->get_parameter_type_by_name(prev_name);
  4665. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  4666. undo_redo_man->create_action(TTR("ParameterRef Name Changed"));
  4667. undo_redo_man->add_do_method(p_parameter_ref.ptr(), "set_parameter_name", p_name);
  4668. undo_redo_man->add_undo_method(p_parameter_ref.ptr(), "set_parameter_name", prev_name);
  4669. // update output port
  4670. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  4671. VisualShader::Type type = VisualShader::Type(type_id);
  4672. int id = visual_shader->find_node_id(type, p_parameter_ref);
  4673. if (id != VisualShader::NODE_ID_INVALID) {
  4674. if (type_changed) {
  4675. List<VisualShader::Connection> conns;
  4676. visual_shader->get_node_connections(type, &conns);
  4677. for (const VisualShader::Connection &E : conns) {
  4678. if (E.from_node == id) {
  4679. 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))) {
  4680. continue;
  4681. }
  4682. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4683. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4684. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4685. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4686. }
  4687. }
  4688. }
  4689. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  4690. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  4691. break;
  4692. }
  4693. }
  4694. undo_redo_man->commit_action();
  4695. }
  4696. void VisualShaderEditor::_varying_select_item(Ref<VisualShaderNodeVarying> p_varying, const String &p_name) {
  4697. String prev_name = p_varying->get_varying_name();
  4698. if (p_name == prev_name) {
  4699. return;
  4700. }
  4701. bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid();
  4702. EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton();
  4703. undo_redo_man->create_action(TTR("Varying Name Changed"));
  4704. undo_redo_man->add_do_method(p_varying.ptr(), "set_varying_name", p_name);
  4705. undo_redo_man->add_undo_method(p_varying.ptr(), "set_varying_name", prev_name);
  4706. VisualShader::VaryingType vtype = p_varying->get_varying_type_by_name(p_name);
  4707. VisualShader::VaryingType prev_vtype = p_varying->get_varying_type_by_name(prev_name);
  4708. bool type_changed = vtype != prev_vtype;
  4709. if (type_changed) {
  4710. undo_redo_man->add_do_method(p_varying.ptr(), "set_varying_type", vtype);
  4711. undo_redo_man->add_undo_method(p_varying.ptr(), "set_varying_type", prev_vtype);
  4712. }
  4713. // update ports
  4714. for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) {
  4715. VisualShader::Type type = VisualShader::Type(type_id);
  4716. int id = visual_shader->find_node_id(type, p_varying);
  4717. if (id != VisualShader::NODE_ID_INVALID) {
  4718. if (type_changed) {
  4719. List<VisualShader::Connection> conns;
  4720. visual_shader->get_node_connections(type, &conns);
  4721. for (const VisualShader::Connection &E : conns) {
  4722. if (is_getter) {
  4723. if (E.from_node == id) {
  4724. 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))) {
  4725. continue;
  4726. }
  4727. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4728. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4729. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4730. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4731. }
  4732. } else {
  4733. if (E.to_node == id) {
  4734. 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))) {
  4735. continue;
  4736. }
  4737. undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4738. undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4739. undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4740. undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  4741. }
  4742. }
  4743. }
  4744. }
  4745. undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id);
  4746. undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id);
  4747. break;
  4748. }
  4749. }
  4750. undo_redo_man->commit_action();
  4751. }
  4752. void VisualShaderEditor::_float_constant_selected(int p_which) {
  4753. ERR_FAIL_INDEX(p_which, MAX_FLOAT_CONST_DEFS);
  4754. VisualShader::Type type = get_current_shader_type();
  4755. Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, selected_float_constant);
  4756. ERR_FAIL_COND(!node.is_valid());
  4757. if (Math::is_equal_approx(node->get_constant(), float_constant_defs[p_which].value)) {
  4758. return; // same
  4759. }
  4760. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4761. undo_redo->create_action(vformat(TTR("Set Constant: %s"), float_constant_defs[p_which].name));
  4762. undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_which].value);
  4763. undo_redo->add_undo_method(node.ptr(), "set_constant", node->get_constant());
  4764. undo_redo->commit_action();
  4765. }
  4766. void VisualShaderEditor::_member_filter_changed(const String &p_text) {
  4767. _update_options_menu();
  4768. }
  4769. void VisualShaderEditor::_member_selected() {
  4770. TreeItem *item = members->get_selected();
  4771. if (item != nullptr && item->has_meta("id")) {
  4772. members_dialog->get_ok_button()->set_disabled(false);
  4773. highend_label->set_visible(add_options[item->get_meta("id")].highend);
  4774. node_desc->set_text(_get_description(item->get_meta("id")));
  4775. } else {
  4776. highend_label->set_visible(false);
  4777. members_dialog->get_ok_button()->set_disabled(true);
  4778. node_desc->set_text("");
  4779. }
  4780. }
  4781. void VisualShaderEditor::_member_unselected() {
  4782. }
  4783. void VisualShaderEditor::_member_create() {
  4784. TreeItem *item = members->get_selected();
  4785. if (item != nullptr && item->has_meta("id")) {
  4786. int idx = members->get_selected()->get_meta("id");
  4787. if (connection_node_insert_requested) {
  4788. from_node = String(clicked_connection->from_node).to_int();
  4789. from_slot = clicked_connection->from_port;
  4790. to_node = String(clicked_connection->to_node).to_int();
  4791. to_slot = clicked_connection->to_port;
  4792. connection_node_insert_requested = false;
  4793. saved_node_pos_dirty = true;
  4794. // Find both graph nodes and get their positions.
  4795. GraphNode *from_graph_element = Object::cast_to<GraphNode>(graph->get_node(itos(from_node)));
  4796. GraphNode *to_graph_element = Object::cast_to<GraphNode>(graph->get_node(itos(to_node)));
  4797. ERR_FAIL_NULL(from_graph_element);
  4798. ERR_FAIL_NULL(to_graph_element);
  4799. // Since the size of the node to add is not known yet, it's not possible to center it exactly.
  4800. float zoom = graph->get_zoom();
  4801. 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));
  4802. }
  4803. _add_node(idx, add_options[idx].ops);
  4804. members_dialog->hide();
  4805. }
  4806. }
  4807. void VisualShaderEditor::_member_cancel() {
  4808. to_node = -1;
  4809. to_slot = -1;
  4810. from_node = -1;
  4811. from_slot = -1;
  4812. connection_node_insert_requested = false;
  4813. }
  4814. void VisualShaderEditor::_update_varying_tree() {
  4815. varyings->clear();
  4816. TreeItem *root = varyings->create_item();
  4817. int count = visual_shader->get_varyings_count();
  4818. for (int i = 0; i < count; i++) {
  4819. const VisualShader::Varying *varying = visual_shader->get_varying_by_index(i);
  4820. if (varying) {
  4821. TreeItem *item = varyings->create_item(root);
  4822. item->set_text(0, varying->name);
  4823. if (i == 0) {
  4824. item->select(0);
  4825. }
  4826. switch (varying->type) {
  4827. case VisualShader::VARYING_TYPE_FLOAT:
  4828. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)));
  4829. break;
  4830. case VisualShader::VARYING_TYPE_INT:
  4831. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)));
  4832. break;
  4833. case VisualShader::VARYING_TYPE_UINT:
  4834. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)));
  4835. break;
  4836. case VisualShader::VARYING_TYPE_VECTOR_2D:
  4837. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)));
  4838. break;
  4839. case VisualShader::VARYING_TYPE_VECTOR_3D:
  4840. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)));
  4841. break;
  4842. case VisualShader::VARYING_TYPE_VECTOR_4D:
  4843. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)));
  4844. break;
  4845. case VisualShader::VARYING_TYPE_BOOLEAN:
  4846. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)));
  4847. break;
  4848. case VisualShader::VARYING_TYPE_TRANSFORM:
  4849. item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)));
  4850. break;
  4851. default:
  4852. break;
  4853. }
  4854. }
  4855. }
  4856. varying_button->get_popup()->set_item_disabled(int(VaryingMenuOptions::REMOVE), count == 0);
  4857. }
  4858. void VisualShaderEditor::_varying_create() {
  4859. _add_varying(varying_name->get_text(), (VisualShader::VaryingMode)varying_mode->get_selected(), (VisualShader::VaryingType)varying_type->get_selected());
  4860. add_varying_dialog->hide();
  4861. }
  4862. void VisualShaderEditor::_varying_name_changed(const String &p_name) {
  4863. if (!p_name.is_valid_ascii_identifier()) {
  4864. varying_error_label->show();
  4865. varying_error_label->set_text(TTR("Invalid name for varying."));
  4866. add_varying_dialog->get_ok_button()->set_disabled(true);
  4867. return;
  4868. }
  4869. if (visual_shader->has_varying(p_name)) {
  4870. varying_error_label->show();
  4871. varying_error_label->set_text(TTR("Varying with that name is already exist."));
  4872. add_varying_dialog->get_ok_button()->set_disabled(true);
  4873. return;
  4874. }
  4875. if (varying_error_label->is_visible()) {
  4876. varying_error_label->hide();
  4877. add_varying_dialog->set_size(Size2(add_varying_dialog->get_size().x, 0));
  4878. }
  4879. add_varying_dialog->get_ok_button()->set_disabled(false);
  4880. }
  4881. void VisualShaderEditor::_varying_deleted() {
  4882. TreeItem *item = varyings->get_selected();
  4883. if (item != nullptr) {
  4884. _remove_varying(item->get_text(0));
  4885. remove_varying_dialog->hide();
  4886. }
  4887. }
  4888. void VisualShaderEditor::_varying_selected() {
  4889. add_varying_dialog->get_ok_button()->set_disabled(false);
  4890. }
  4891. void VisualShaderEditor::_varying_unselected() {
  4892. add_varying_dialog->get_ok_button()->set_disabled(true);
  4893. }
  4894. void VisualShaderEditor::_tools_menu_option(int p_idx) {
  4895. TreeItem *category = members->get_root()->get_first_child();
  4896. switch (p_idx) {
  4897. case EXPAND_ALL:
  4898. while (category) {
  4899. category->set_collapsed(false);
  4900. TreeItem *sub_category = category->get_first_child();
  4901. while (sub_category) {
  4902. sub_category->set_collapsed(false);
  4903. sub_category = sub_category->get_next();
  4904. }
  4905. category = category->get_next();
  4906. }
  4907. break;
  4908. case COLLAPSE_ALL:
  4909. while (category) {
  4910. category->set_collapsed(true);
  4911. TreeItem *sub_category = category->get_first_child();
  4912. while (sub_category) {
  4913. sub_category->set_collapsed(true);
  4914. sub_category = sub_category->get_next();
  4915. }
  4916. category = category->get_next();
  4917. }
  4918. break;
  4919. default:
  4920. break;
  4921. }
  4922. }
  4923. void VisualShaderEditor::_node_menu_id_pressed(int p_idx) {
  4924. switch (p_idx) {
  4925. case NodeMenuOptions::ADD:
  4926. _show_members_dialog(true);
  4927. break;
  4928. case NodeMenuOptions::CUT:
  4929. _copy_nodes(true);
  4930. break;
  4931. case NodeMenuOptions::COPY:
  4932. _copy_nodes(false);
  4933. break;
  4934. case NodeMenuOptions::PASTE:
  4935. _paste_nodes(true, menu_point);
  4936. break;
  4937. case NodeMenuOptions::DELETE:
  4938. _delete_nodes_request(TypedArray<StringName>());
  4939. break;
  4940. case NodeMenuOptions::DUPLICATE:
  4941. _duplicate_nodes();
  4942. break;
  4943. case NodeMenuOptions::CLEAR_COPY_BUFFER:
  4944. _clear_copy_buffer();
  4945. break;
  4946. case NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS:
  4947. _convert_constants_to_parameters(false);
  4948. break;
  4949. case NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS:
  4950. _convert_constants_to_parameters(true);
  4951. break;
  4952. case NodeMenuOptions::UNLINK_FROM_PARENT_FRAME:
  4953. _detach_nodes_from_frame_request();
  4954. break;
  4955. case NodeMenuOptions::SET_FRAME_TITLE:
  4956. _frame_title_popup_show(get_screen_position() + get_local_mouse_position(), selected_frame);
  4957. break;
  4958. case NodeMenuOptions::ENABLE_FRAME_COLOR:
  4959. _frame_color_enabled_changed(selected_frame);
  4960. break;
  4961. case NodeMenuOptions::SET_FRAME_COLOR:
  4962. _frame_color_popup_show(get_screen_position() + get_local_mouse_position(), selected_frame);
  4963. break;
  4964. case NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK:
  4965. _frame_autoshrink_enabled_changed(selected_frame);
  4966. break;
  4967. default:
  4968. break;
  4969. }
  4970. }
  4971. void VisualShaderEditor::_connection_menu_id_pressed(int p_idx) {
  4972. switch (p_idx) {
  4973. case ConnectionMenuOptions::DISCONNECT: {
  4974. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  4975. undo_redo->create_action(TTR("Disconnect"));
  4976. 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);
  4977. 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);
  4978. 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);
  4979. 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);
  4980. undo_redo->commit_action();
  4981. } break;
  4982. case ConnectionMenuOptions::INSERT_NEW_NODE: {
  4983. VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  4984. VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  4985. Ref<VisualShaderNode> node1 = visual_shader->get_node(get_current_shader_type(), String(clicked_connection->from_node).to_int());
  4986. if (node1.is_valid()) {
  4987. output_port_type = node1->get_output_port_type(from_slot);
  4988. }
  4989. Ref<VisualShaderNode> node2 = visual_shader->get_node(get_current_shader_type(), String(clicked_connection->to_node).to_int());
  4990. if (node2.is_valid()) {
  4991. input_port_type = node2->get_input_port_type(to_slot);
  4992. }
  4993. connection_node_insert_requested = true;
  4994. _show_members_dialog(true, input_port_type, output_port_type);
  4995. } break;
  4996. case ConnectionMenuOptions::INSERT_NEW_REROUTE: {
  4997. from_node = String(clicked_connection->from_node).to_int();
  4998. from_slot = clicked_connection->from_port;
  4999. to_node = String(clicked_connection->to_node).to_int();
  5000. to_slot = clicked_connection->to_port;
  5001. // Manual offset to place the port exactly at the mouse position.
  5002. saved_node_pos -= Vector2(11 * EDSCALE * graph->get_zoom(), 50 * EDSCALE * graph->get_zoom());
  5003. // Find reroute addoptions.
  5004. int idx = -1;
  5005. for (int i = 0; i < add_options.size(); i++) {
  5006. if (add_options[i].name == "Reroute") {
  5007. idx = i;
  5008. break;
  5009. }
  5010. }
  5011. _add_node(idx, add_options[idx].ops);
  5012. } break;
  5013. default:
  5014. break;
  5015. }
  5016. }
  5017. Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  5018. if (p_from == members) {
  5019. TreeItem *it = members->get_item_at_position(p_point);
  5020. if (!it) {
  5021. return Variant();
  5022. }
  5023. if (!it->has_meta("id")) {
  5024. return Variant();
  5025. }
  5026. int id = it->get_meta("id");
  5027. AddOption op = add_options[id];
  5028. Dictionary d;
  5029. d["id"] = id;
  5030. Label *label = memnew(Label);
  5031. label->set_text(it->get_text(0));
  5032. set_drag_preview(label);
  5033. return d;
  5034. }
  5035. return Variant();
  5036. }
  5037. bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  5038. if (p_from == graph) {
  5039. Dictionary d = p_data;
  5040. if (d.has("id")) {
  5041. return true;
  5042. }
  5043. if (d.has("files")) {
  5044. return true;
  5045. }
  5046. }
  5047. return false;
  5048. }
  5049. void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  5050. if (p_from == graph) {
  5051. Dictionary d = p_data;
  5052. if (d.has("id")) {
  5053. int idx = d["id"];
  5054. saved_node_pos = p_point;
  5055. saved_node_pos_dirty = true;
  5056. _add_node(idx, add_options[idx].ops);
  5057. } else if (d.has("files")) {
  5058. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  5059. undo_redo->create_action(TTR("Add Node(s) to Visual Shader"));
  5060. if (d["files"].get_type() == Variant::PACKED_STRING_ARRAY) {
  5061. PackedStringArray arr = d["files"];
  5062. for (int i = 0; i < arr.size(); i++) {
  5063. String type = ResourceLoader::get_resource_type(arr[i]);
  5064. if (type == "GDScript") {
  5065. Ref<Script> scr = ResourceLoader::load(arr[i]);
  5066. if (scr->get_instance_base_type() == "VisualShaderNodeCustom") {
  5067. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5068. saved_node_pos_dirty = true;
  5069. int idx = -1;
  5070. for (int j = custom_node_option_idx; j < add_options.size(); j++) {
  5071. if (add_options[j].script.is_valid()) {
  5072. if (add_options[j].script->get_path() == arr[i]) {
  5073. idx = j;
  5074. break;
  5075. }
  5076. }
  5077. }
  5078. if (idx != -1) {
  5079. _add_node(idx, {}, arr[i], i);
  5080. }
  5081. }
  5082. } else if (type == "CurveTexture") {
  5083. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5084. saved_node_pos_dirty = true;
  5085. _add_node(curve_node_option_idx, {}, arr[i], i);
  5086. } else if (type == "CurveXYZTexture") {
  5087. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5088. saved_node_pos_dirty = true;
  5089. _add_node(curve_xyz_node_option_idx, {}, arr[i], i);
  5090. } else if (ClassDB::get_parent_class(type) == "Texture2D") {
  5091. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5092. saved_node_pos_dirty = true;
  5093. _add_node(texture2d_node_option_idx, {}, arr[i], i);
  5094. } else if (type == "Texture2DArray") {
  5095. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5096. saved_node_pos_dirty = true;
  5097. _add_node(texture2d_array_node_option_idx, {}, arr[i], i);
  5098. } else if (ClassDB::get_parent_class(type) == "Texture3D") {
  5099. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5100. saved_node_pos_dirty = true;
  5101. _add_node(texture3d_node_option_idx, {}, arr[i], i);
  5102. } else if (type == "Cubemap") {
  5103. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5104. saved_node_pos_dirty = true;
  5105. _add_node(cubemap_node_option_idx, {}, arr[i], i);
  5106. } else if (type == "Mesh" && visual_shader->get_mode() == Shader::MODE_PARTICLES &&
  5107. (visual_shader->get_shader_type() == VisualShader::TYPE_START || visual_shader->get_shader_type() == VisualShader::TYPE_START_CUSTOM)) {
  5108. saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE);
  5109. saved_node_pos_dirty = true;
  5110. _add_node(mesh_emitter_option_idx, {}, arr[i], i);
  5111. }
  5112. }
  5113. }
  5114. undo_redo->commit_action();
  5115. }
  5116. }
  5117. }
  5118. void VisualShaderEditor::_show_preview_text() {
  5119. code_preview_showed = !code_preview_showed;
  5120. if (code_preview_showed) {
  5121. if (code_preview_first) {
  5122. code_preview_window->set_size(Size2(400 * EDSCALE, 600 * EDSCALE));
  5123. code_preview_window->popup_centered();
  5124. code_preview_first = false;
  5125. } else {
  5126. code_preview_window->popup();
  5127. }
  5128. _preview_size_changed();
  5129. if (pending_update_preview) {
  5130. _update_preview();
  5131. pending_update_preview = false;
  5132. }
  5133. } else {
  5134. code_preview_window->hide();
  5135. }
  5136. }
  5137. void VisualShaderEditor::_preview_close_requested() {
  5138. code_preview_showed = false;
  5139. code_preview_window->hide();
  5140. code_preview_button->set_pressed(false);
  5141. }
  5142. void VisualShaderEditor::_preview_size_changed() {
  5143. code_preview_vbox->set_custom_minimum_size(code_preview_window->get_size());
  5144. }
  5145. static ShaderLanguage::DataType _visual_shader_editor_get_global_shader_uniform_type(const StringName &p_variable) {
  5146. RS::GlobalShaderParameterType gvt = RS::get_singleton()->global_shader_parameter_get_type(p_variable);
  5147. return (ShaderLanguage::DataType)RS::global_shader_uniform_type_get_shader_datatype(gvt);
  5148. }
  5149. void VisualShaderEditor::_update_preview() {
  5150. if (!code_preview_showed) {
  5151. pending_update_preview = true;
  5152. return;
  5153. }
  5154. String code = visual_shader->get_code();
  5155. preview_text->set_text(code);
  5156. ShaderLanguage::ShaderCompileInfo info;
  5157. info.functions = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(visual_shader->get_mode()));
  5158. info.render_modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(visual_shader->get_mode()));
  5159. info.shader_types = ShaderTypes::get_singleton()->get_types();
  5160. info.global_shader_uniform_type_func = _visual_shader_editor_get_global_shader_uniform_type;
  5161. for (int i = 0; i < preview_text->get_line_count(); i++) {
  5162. preview_text->set_line_background_color(i, Color(0, 0, 0, 0));
  5163. }
  5164. String preprocessed_code;
  5165. {
  5166. String path = visual_shader->get_path();
  5167. String error_pp;
  5168. List<ShaderPreprocessor::FilePosition> err_positions;
  5169. ShaderPreprocessor preprocessor;
  5170. Error err = preprocessor.preprocess(code, path, preprocessed_code, &error_pp, &err_positions);
  5171. if (err != OK) {
  5172. ERR_FAIL_COND(err_positions.is_empty());
  5173. String file = err_positions.front()->get().file;
  5174. int err_line = err_positions.front()->get().line;
  5175. Color error_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color");
  5176. preview_text->set_line_background_color(err_line - 1, error_line_color);
  5177. error_panel->show();
  5178. error_label->set_text("error(" + file + ":" + itos(err_line) + "): " + error_pp);
  5179. shader_error = true;
  5180. return;
  5181. }
  5182. }
  5183. ShaderLanguage sl;
  5184. Error err = sl.compile(preprocessed_code, info);
  5185. if (err != OK) {
  5186. int err_line;
  5187. String err_text;
  5188. Vector<ShaderLanguage::FilePosition> include_positions = sl.get_include_positions();
  5189. if (include_positions.size() > 1) {
  5190. // Error is in an include.
  5191. err_line = include_positions[0].line;
  5192. 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();
  5193. } else {
  5194. err_line = sl.get_error_line();
  5195. err_text = "error(" + itos(err_line) + "): " + sl.get_error_text();
  5196. }
  5197. Color error_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color");
  5198. preview_text->set_line_background_color(err_line - 1, error_line_color);
  5199. error_panel->show();
  5200. error_label->set_text(err_text);
  5201. shader_error = true;
  5202. } else {
  5203. error_panel->hide();
  5204. shader_error = false;
  5205. }
  5206. }
  5207. void VisualShaderEditor::_update_next_previews(int p_node_id) {
  5208. VisualShader::Type type = get_current_shader_type();
  5209. LocalVector<int> nodes;
  5210. _get_next_nodes_recursively(type, p_node_id, nodes);
  5211. for (int node_id : nodes) {
  5212. if (graph_plugin->is_preview_visible(node_id)) {
  5213. graph_plugin->update_node_deferred(type, node_id);
  5214. }
  5215. }
  5216. }
  5217. void VisualShaderEditor::_get_next_nodes_recursively(VisualShader::Type p_type, int p_node_id, LocalVector<int> &r_nodes) const {
  5218. const LocalVector<int> &next_connections = visual_shader->get_next_connected_nodes(p_type, p_node_id);
  5219. for (int node_id : next_connections) {
  5220. r_nodes.push_back(node_id);
  5221. _get_next_nodes_recursively(p_type, node_id, r_nodes);
  5222. }
  5223. }
  5224. void VisualShaderEditor::_visibility_changed() {
  5225. if (!is_visible()) {
  5226. if (code_preview_window->is_visible()) {
  5227. code_preview_button->set_pressed(false);
  5228. code_preview_window->hide();
  5229. code_preview_showed = false;
  5230. }
  5231. }
  5232. }
  5233. void VisualShaderEditor::_show_shader_preview() {
  5234. shader_preview_showed = !shader_preview_showed;
  5235. if (shader_preview_showed) {
  5236. shader_preview_vbox->show();
  5237. } else {
  5238. shader_preview_vbox->hide();
  5239. _param_unselected();
  5240. }
  5241. }
  5242. void VisualShaderEditor::_bind_methods() {
  5243. ClassDB::bind_method("_update_nodes", &VisualShaderEditor::_update_nodes);
  5244. ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph);
  5245. ClassDB::bind_method("_input_select_item", &VisualShaderEditor::_input_select_item);
  5246. ClassDB::bind_method("_parameter_ref_select_item", &VisualShaderEditor::_parameter_ref_select_item);
  5247. ClassDB::bind_method("_varying_select_item", &VisualShaderEditor::_varying_select_item);
  5248. ClassDB::bind_method("_set_node_size", &VisualShaderEditor::_set_node_size);
  5249. ClassDB::bind_method("_update_parameters", &VisualShaderEditor::_update_parameters);
  5250. ClassDB::bind_method("_update_varyings", &VisualShaderEditor::_update_varyings);
  5251. ClassDB::bind_method("_update_varying_tree", &VisualShaderEditor::_update_varying_tree);
  5252. ClassDB::bind_method("_set_mode", &VisualShaderEditor::_set_mode);
  5253. ClassDB::bind_method("_update_constant", &VisualShaderEditor::_update_constant);
  5254. ClassDB::bind_method("_update_parameter", &VisualShaderEditor::_update_parameter);
  5255. ClassDB::bind_method("_update_next_previews", &VisualShaderEditor::_update_next_previews);
  5256. ClassDB::bind_method("_update_current_param", &VisualShaderEditor::_update_current_param);
  5257. }
  5258. VisualShaderEditor::VisualShaderEditor() {
  5259. ShaderLanguage::get_keyword_list(&keyword_list);
  5260. EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &VisualShaderEditor::_resource_saved));
  5261. FileSystemDock::get_singleton()->get_script_create_dialog()->connect("script_created", callable_mp(this, &VisualShaderEditor::_script_created));
  5262. FileSystemDock::get_singleton()->connect("resource_removed", callable_mp(this, &VisualShaderEditor::_resource_removed));
  5263. HSplitContainer *main_box = memnew(HSplitContainer);
  5264. main_box->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  5265. add_child(main_box);
  5266. graph = memnew(GraphEdit);
  5267. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  5268. graph->set_h_size_flags(SIZE_EXPAND_FILL);
  5269. graph->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
  5270. graph->set_grid_pattern(GraphEdit::GridPattern::GRID_PATTERN_DOTS);
  5271. int grid_pattern = EDITOR_GET("editors/visual_editors/grid_pattern");
  5272. graph->set_grid_pattern((GraphEdit::GridPattern)grid_pattern);
  5273. graph->set_show_zoom_label(true);
  5274. main_box->add_child(graph);
  5275. SET_DRAG_FORWARDING_GCD(graph, VisualShaderEditor);
  5276. float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity");
  5277. graph->set_minimap_opacity(graph_minimap_opacity);
  5278. float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature");
  5279. graph->set_connection_lines_curvature(graph_lines_curvature);
  5280. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR);
  5281. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5282. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5283. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN);
  5284. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5285. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5286. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5287. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_TRANSFORM);
  5288. graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SAMPLER);
  5289. //graph->add_valid_left_disconnect_type(0);
  5290. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  5291. graph->connect("connection_request", callable_mp(this, &VisualShaderEditor::_connection_request), CONNECT_DEFERRED);
  5292. graph->connect("disconnection_request", callable_mp(this, &VisualShaderEditor::_disconnection_request), CONNECT_DEFERRED);
  5293. graph->connect("node_selected", callable_mp(this, &VisualShaderEditor::_node_selected));
  5294. graph->connect("scroll_offset_changed", callable_mp(this, &VisualShaderEditor::_scroll_changed));
  5295. graph->connect("duplicate_nodes_request", callable_mp(this, &VisualShaderEditor::_duplicate_nodes));
  5296. graph->connect("copy_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes).bind(false));
  5297. graph->connect("paste_nodes_request", callable_mp(this, &VisualShaderEditor::_paste_nodes).bind(false, Point2()));
  5298. graph->connect("delete_nodes_request", callable_mp(this, &VisualShaderEditor::_delete_nodes_request));
  5299. graph->connect(SceneStringName(gui_input), callable_mp(this, &VisualShaderEditor::_graph_gui_input));
  5300. graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty));
  5301. graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty));
  5302. graph->connect(SceneStringName(visibility_changed), callable_mp(this, &VisualShaderEditor::_visibility_changed));
  5303. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR);
  5304. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5305. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5306. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5307. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5308. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5309. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5310. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR);
  5311. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5312. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5313. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5314. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5315. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5316. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5317. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR);
  5318. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5319. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5320. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5321. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5322. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5323. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5324. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR);
  5325. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5326. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5327. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5328. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5329. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5330. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5331. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR);
  5332. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5333. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5334. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5335. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5336. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5337. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5338. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR);
  5339. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5340. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5341. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5342. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5343. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5344. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5345. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR);
  5346. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_INT);
  5347. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_UINT);
  5348. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_2D);
  5349. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_3D);
  5350. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_4D);
  5351. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_BOOLEAN);
  5352. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShaderNode::PORT_TYPE_TRANSFORM);
  5353. graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SAMPLER, VisualShaderNode::PORT_TYPE_SAMPLER);
  5354. PanelContainer *toolbar_panel = static_cast<PanelContainer *>(graph->get_menu_hbox()->get_parent());
  5355. toolbar_panel->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE, PRESET_MODE_MINSIZE, 10);
  5356. toolbar_panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
  5357. HFlowContainer *toolbar = memnew(HFlowContainer);
  5358. {
  5359. LocalVector<Node *> nodes;
  5360. for (int i = 0; i < graph->get_menu_hbox()->get_child_count(); i++) {
  5361. Node *child = graph->get_menu_hbox()->get_child(i);
  5362. nodes.push_back(child);
  5363. }
  5364. for (Node *node : nodes) {
  5365. graph->get_menu_hbox()->remove_child(node);
  5366. toolbar->add_child(node);
  5367. }
  5368. graph->get_menu_hbox()->hide();
  5369. toolbar_panel->add_child(toolbar);
  5370. }
  5371. VSeparator *vs = memnew(VSeparator);
  5372. toolbar->add_child(vs);
  5373. toolbar->move_child(vs, 0);
  5374. custom_mode_box = memnew(CheckBox);
  5375. custom_mode_box->set_text(TTR("Custom"));
  5376. custom_mode_box->set_pressed(false);
  5377. custom_mode_box->set_visible(false);
  5378. custom_mode_box->connect(SceneStringName(toggled), callable_mp(this, &VisualShaderEditor::_custom_mode_toggled));
  5379. edit_type_standard = memnew(OptionButton);
  5380. edit_type_standard->add_item(TTR("Vertex"));
  5381. edit_type_standard->add_item(TTR("Fragment"));
  5382. edit_type_standard->add_item(TTR("Light"));
  5383. edit_type_standard->select(1);
  5384. edit_type_standard->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_mode_selected));
  5385. edit_type_particles = memnew(OptionButton);
  5386. edit_type_particles->add_item(TTR("Start"));
  5387. edit_type_particles->add_item(TTR("Process"));
  5388. edit_type_particles->add_item(TTR("Collide"));
  5389. edit_type_particles->select(0);
  5390. edit_type_particles->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_mode_selected));
  5391. edit_type_sky = memnew(OptionButton);
  5392. edit_type_sky->add_item(TTR("Sky"));
  5393. edit_type_sky->select(0);
  5394. edit_type_sky->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_mode_selected));
  5395. edit_type_fog = memnew(OptionButton);
  5396. edit_type_fog->add_item(TTR("Fog"));
  5397. edit_type_fog->select(0);
  5398. edit_type_fog->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_mode_selected));
  5399. edit_type = edit_type_standard;
  5400. toolbar->add_child(custom_mode_box);
  5401. toolbar->move_child(custom_mode_box, 0);
  5402. toolbar->add_child(edit_type_standard);
  5403. toolbar->move_child(edit_type_standard, 0);
  5404. toolbar->add_child(edit_type_particles);
  5405. toolbar->move_child(edit_type_particles, 0);
  5406. toolbar->add_child(edit_type_sky);
  5407. toolbar->move_child(edit_type_sky, 0);
  5408. toolbar->add_child(edit_type_fog);
  5409. toolbar->move_child(edit_type_fog, 0);
  5410. add_node = memnew(Button);
  5411. add_node->set_flat(true);
  5412. add_node->set_text(TTR("Add Node..."));
  5413. toolbar->add_child(add_node);
  5414. toolbar->move_child(add_node, 0);
  5415. add_node->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_members_dialog).bind(false, VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PORT_TYPE_MAX));
  5416. graph->connect("graph_elements_linked_to_frame_request", callable_mp(this, &VisualShaderEditor::_nodes_linked_to_frame_request));
  5417. graph->connect("frame_rect_changed", callable_mp(this, &VisualShaderEditor::_frame_rect_changed));
  5418. varying_button = memnew(MenuButton);
  5419. varying_button->set_text(TTR("Manage Varyings"));
  5420. varying_button->set_switch_on_hover(true);
  5421. toolbar->add_child(varying_button);
  5422. PopupMenu *varying_menu = varying_button->get_popup();
  5423. varying_menu->add_item(TTR("Add Varying"), int(VaryingMenuOptions::ADD));
  5424. varying_menu->add_item(TTR("Remove Varying"), int(VaryingMenuOptions::REMOVE));
  5425. varying_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_varying_menu_id_pressed));
  5426. code_preview_button = memnew(Button);
  5427. code_preview_button->set_theme_type_variation("FlatButton");
  5428. code_preview_button->set_toggle_mode(true);
  5429. code_preview_button->set_tooltip_text(TTR("Show generated shader code."));
  5430. toolbar->add_child(code_preview_button);
  5431. code_preview_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_preview_text));
  5432. shader_preview_button = memnew(Button);
  5433. shader_preview_button->set_theme_type_variation("FlatButton");
  5434. shader_preview_button->set_toggle_mode(true);
  5435. shader_preview_button->set_tooltip_text(TTR("Toggle shader preview."));
  5436. shader_preview_button->set_pressed(true);
  5437. toolbar->add_child(shader_preview_button);
  5438. shader_preview_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_shader_preview));
  5439. ///////////////////////////////////////
  5440. // CODE PREVIEW
  5441. ///////////////////////////////////////
  5442. code_preview_window = memnew(Window);
  5443. code_preview_window->set_title(TTR("Generated Shader Code"));
  5444. code_preview_window->set_visible(code_preview_showed);
  5445. code_preview_window->set_exclusive(true);
  5446. code_preview_window->connect("close_requested", callable_mp(this, &VisualShaderEditor::_preview_close_requested));
  5447. code_preview_window->connect("size_changed", callable_mp(this, &VisualShaderEditor::_preview_size_changed));
  5448. add_child(code_preview_window);
  5449. code_preview_vbox = memnew(VBoxContainer);
  5450. code_preview_window->add_child(code_preview_vbox);
  5451. code_preview_vbox->add_theme_constant_override("separation", 0);
  5452. preview_text = memnew(CodeEdit);
  5453. syntax_highlighter.instantiate();
  5454. code_preview_vbox->add_child(preview_text);
  5455. preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  5456. preview_text->set_syntax_highlighter(syntax_highlighter);
  5457. preview_text->set_draw_line_numbers(true);
  5458. preview_text->set_editable(false);
  5459. error_panel = memnew(PanelContainer);
  5460. code_preview_vbox->add_child(error_panel);
  5461. error_panel->set_visible(false);
  5462. error_label = memnew(Label);
  5463. error_panel->add_child(error_label);
  5464. error_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  5465. ///////////////////////////////////////
  5466. // POPUP MENU
  5467. ///////////////////////////////////////
  5468. popup_menu = memnew(PopupMenu);
  5469. add_child(popup_menu);
  5470. popup_menu->set_hide_on_checkable_item_selection(false);
  5471. popup_menu->add_item(TTR("Add Node"), NodeMenuOptions::ADD);
  5472. popup_menu->add_separator();
  5473. popup_menu->add_item(TTR("Cut"), NodeMenuOptions::CUT);
  5474. popup_menu->add_item(TTR("Copy"), NodeMenuOptions::COPY);
  5475. popup_menu->add_item(TTR("Paste"), NodeMenuOptions::PASTE);
  5476. popup_menu->add_item(TTR("Delete"), NodeMenuOptions::DELETE);
  5477. popup_menu->add_item(TTR("Duplicate"), NodeMenuOptions::DUPLICATE);
  5478. popup_menu->add_item(TTR("Clear Copy Buffer"), NodeMenuOptions::CLEAR_COPY_BUFFER);
  5479. popup_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_node_menu_id_pressed));
  5480. connection_popup_menu = memnew(PopupMenu);
  5481. add_child(connection_popup_menu);
  5482. connection_popup_menu->add_item(TTR("Disconnect"), ConnectionMenuOptions::DISCONNECT);
  5483. connection_popup_menu->add_item(TTR("Insert New Node"), ConnectionMenuOptions::INSERT_NEW_NODE);
  5484. connection_popup_menu->add_item(TTR("Insert New Reroute"), ConnectionMenuOptions::INSERT_NEW_REROUTE);
  5485. connection_popup_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_connection_menu_id_pressed));
  5486. ///////////////////////////////////////
  5487. // SHADER PREVIEW
  5488. ///////////////////////////////////////
  5489. shader_preview_vbox = memnew(VBoxContainer);
  5490. shader_preview_vbox->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
  5491. main_box->add_child(shader_preview_vbox);
  5492. VSplitContainer *preview_split = memnew(VSplitContainer);
  5493. preview_split->set_v_size_flags(SIZE_EXPAND_FILL);
  5494. shader_preview_vbox->add_child(preview_split);
  5495. // Initialize material editor.
  5496. {
  5497. env.instantiate();
  5498. Ref<Sky> sky = memnew(Sky());
  5499. env->set_sky(sky);
  5500. env->set_background(Environment::BG_COLOR);
  5501. env->set_ambient_source(Environment::AMBIENT_SOURCE_SKY);
  5502. env->set_reflection_source(Environment::REFLECTION_SOURCE_SKY);
  5503. preview_material.instantiate();
  5504. preview_material->connect(CoreStringName(property_list_changed), callable_mp(this, &VisualShaderEditor::_update_preview_parameter_list));
  5505. material_editor = memnew(MaterialEditor);
  5506. preview_split->add_child(material_editor);
  5507. }
  5508. VBoxContainer *params_vbox = memnew(VBoxContainer);
  5509. preview_split->add_child(params_vbox);
  5510. param_filter = memnew(LineEdit);
  5511. param_filter->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_param_filter_changed));
  5512. param_filter->set_h_size_flags(SIZE_EXPAND_FILL);
  5513. param_filter->set_placeholder(TTR("Filter Parameters"));
  5514. params_vbox->add_child(param_filter);
  5515. ScrollContainer *sc = memnew(ScrollContainer);
  5516. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  5517. params_vbox->add_child(sc);
  5518. parameters = memnew(Tree);
  5519. parameters->set_hide_root(true);
  5520. parameters->set_allow_reselect(true);
  5521. parameters->set_hide_folding(false);
  5522. parameters->set_h_size_flags(SIZE_EXPAND_FILL);
  5523. parameters->set_v_size_flags(SIZE_EXPAND_FILL);
  5524. parameters->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_param_selected));
  5525. parameters->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_param_unselected));
  5526. sc->add_child(parameters);
  5527. param_vbox = memnew(VBoxContainer);
  5528. param_vbox->set_v_size_flags(SIZE_EXPAND_FILL);
  5529. param_vbox->hide();
  5530. params_vbox->add_child(param_vbox);
  5531. ScrollContainer *sc2 = memnew(ScrollContainer);
  5532. sc2->set_v_size_flags(SIZE_EXPAND_FILL);
  5533. param_vbox->add_child(sc2);
  5534. param_vbox2 = memnew(VBoxContainer);
  5535. param_vbox2->set_h_size_flags(SIZE_EXPAND_FILL);
  5536. sc2->add_child(param_vbox2);
  5537. ///////////////////////////////////////
  5538. // SHADER NODES TREE
  5539. ///////////////////////////////////////
  5540. VBoxContainer *members_vb = memnew(VBoxContainer);
  5541. members_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  5542. HBoxContainer *filter_hb = memnew(HBoxContainer);
  5543. members_vb->add_child(filter_hb);
  5544. node_filter = memnew(LineEdit);
  5545. filter_hb->add_child(node_filter);
  5546. node_filter->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_member_filter_changed));
  5547. node_filter->connect(SceneStringName(gui_input), callable_mp(this, &VisualShaderEditor::_sbox_input));
  5548. node_filter->set_h_size_flags(SIZE_EXPAND_FILL);
  5549. node_filter->set_placeholder(TTR("Search"));
  5550. tools = memnew(MenuButton);
  5551. filter_hb->add_child(tools);
  5552. tools->set_tooltip_text(TTR("Options"));
  5553. tools->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_tools_menu_option));
  5554. tools->get_popup()->add_item(TTR("Expand All"), EXPAND_ALL);
  5555. tools->get_popup()->add_item(TTR("Collapse All"), COLLAPSE_ALL);
  5556. members = memnew(Tree);
  5557. members_vb->add_child(members);
  5558. SET_DRAG_FORWARDING_GCD(members, VisualShaderEditor);
  5559. members->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  5560. members->set_h_size_flags(SIZE_EXPAND_FILL);
  5561. members->set_v_size_flags(SIZE_EXPAND_FILL);
  5562. members->set_hide_root(true);
  5563. members->set_allow_reselect(true);
  5564. members->set_hide_folding(false);
  5565. members->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE));
  5566. members->connect("item_activated", callable_mp(this, &VisualShaderEditor::_member_create));
  5567. members->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_member_selected));
  5568. members->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_member_unselected));
  5569. HBoxContainer *desc_hbox = memnew(HBoxContainer);
  5570. members_vb->add_child(desc_hbox);
  5571. Label *desc_label = memnew(Label);
  5572. desc_hbox->add_child(desc_label);
  5573. desc_label->set_text(TTR("Description:"));
  5574. desc_hbox->add_spacer();
  5575. highend_label = memnew(Label);
  5576. desc_hbox->add_child(highend_label);
  5577. highend_label->set_visible(false);
  5578. highend_label->set_text("Vulkan");
  5579. highend_label->set_mouse_filter(Control::MOUSE_FILTER_STOP);
  5580. highend_label->set_tooltip_text(TTR("High-end node"));
  5581. node_desc = memnew(RichTextLabel);
  5582. members_vb->add_child(node_desc);
  5583. node_desc->set_h_size_flags(SIZE_EXPAND_FILL);
  5584. node_desc->set_v_size_flags(SIZE_FILL);
  5585. node_desc->set_custom_minimum_size(Size2(0, 70 * EDSCALE));
  5586. members_dialog = memnew(ConfirmationDialog);
  5587. members_dialog->set_title(TTR("Create Shader Node"));
  5588. members_dialog->set_exclusive(true);
  5589. members_dialog->add_child(members_vb);
  5590. members_dialog->set_ok_button_text(TTR("Create"));
  5591. members_dialog->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_member_create));
  5592. members_dialog->get_ok_button()->set_disabled(true);
  5593. members_dialog->connect("canceled", callable_mp(this, &VisualShaderEditor::_member_cancel));
  5594. add_child(members_dialog);
  5595. // add varyings dialog
  5596. {
  5597. add_varying_dialog = memnew(ConfirmationDialog);
  5598. add_varying_dialog->set_title(TTR("Create Shader Varying"));
  5599. add_varying_dialog->set_exclusive(true);
  5600. add_varying_dialog->set_ok_button_text(TTR("Create"));
  5601. add_varying_dialog->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_varying_create));
  5602. add_varying_dialog->get_ok_button()->set_disabled(true);
  5603. add_child(add_varying_dialog);
  5604. VBoxContainer *vb = memnew(VBoxContainer);
  5605. add_varying_dialog->add_child(vb);
  5606. HBoxContainer *hb = memnew(HBoxContainer);
  5607. vb->add_child(hb);
  5608. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  5609. varying_type = memnew(OptionButton);
  5610. hb->add_child(varying_type);
  5611. varying_type->add_item("Float");
  5612. varying_type->add_item("Int");
  5613. varying_type->add_item("UInt");
  5614. varying_type->add_item("Vector2");
  5615. varying_type->add_item("Vector3");
  5616. varying_type->add_item("Vector4");
  5617. varying_type->add_item("Boolean");
  5618. varying_type->add_item("Transform");
  5619. varying_name = memnew(LineEdit);
  5620. hb->add_child(varying_name);
  5621. varying_name->set_custom_minimum_size(Size2(150 * EDSCALE, 0));
  5622. varying_name->set_h_size_flags(SIZE_EXPAND_FILL);
  5623. varying_name->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_varying_name_changed));
  5624. varying_mode = memnew(OptionButton);
  5625. hb->add_child(varying_mode);
  5626. varying_mode->add_item("Vertex -> [Fragment, Light]");
  5627. varying_mode->add_item("Fragment -> Light");
  5628. varying_error_label = memnew(Label);
  5629. vb->add_child(varying_error_label);
  5630. varying_error_label->set_h_size_flags(SIZE_EXPAND_FILL);
  5631. varying_error_label->hide();
  5632. }
  5633. // remove varying dialog
  5634. {
  5635. remove_varying_dialog = memnew(ConfirmationDialog);
  5636. remove_varying_dialog->set_title(TTR("Delete Shader Varying"));
  5637. remove_varying_dialog->set_exclusive(true);
  5638. remove_varying_dialog->set_ok_button_text(TTR("Delete"));
  5639. remove_varying_dialog->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_varying_deleted));
  5640. add_child(remove_varying_dialog);
  5641. VBoxContainer *vb = memnew(VBoxContainer);
  5642. remove_varying_dialog->add_child(vb);
  5643. varyings = memnew(Tree);
  5644. vb->add_child(varyings);
  5645. varyings->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  5646. varyings->set_h_size_flags(SIZE_EXPAND_FILL);
  5647. varyings->set_v_size_flags(SIZE_EXPAND_FILL);
  5648. varyings->set_hide_root(true);
  5649. varyings->set_allow_reselect(true);
  5650. varyings->set_hide_folding(false);
  5651. varyings->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE));
  5652. varyings->connect("item_activated", callable_mp(this, &VisualShaderEditor::_varying_deleted));
  5653. varyings->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_selected));
  5654. varyings->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_varying_unselected));
  5655. }
  5656. alert = memnew(AcceptDialog);
  5657. alert->get_label()->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  5658. alert->get_label()->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  5659. alert->get_label()->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  5660. alert->get_label()->set_custom_minimum_size(Size2(400, 60) * EDSCALE);
  5661. add_child(alert);
  5662. frame_title_change_popup = memnew(PopupPanel);
  5663. frame_title_change_edit = memnew(LineEdit);
  5664. frame_title_change_edit->set_expand_to_text_length_enabled(true);
  5665. frame_title_change_edit->set_select_all_on_focus(true);
  5666. frame_title_change_edit->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_frame_title_text_changed));
  5667. frame_title_change_edit->connect("text_submitted", callable_mp(this, &VisualShaderEditor::_frame_title_text_submitted));
  5668. frame_title_change_popup->add_child(frame_title_change_edit);
  5669. frame_title_change_edit->reset_size();
  5670. frame_title_change_popup->reset_size();
  5671. frame_title_change_popup->connect(SceneStringName(focus_exited), callable_mp(this, &VisualShaderEditor::_frame_title_popup_focus_out));
  5672. frame_title_change_popup->connect("popup_hide", callable_mp(this, &VisualShaderEditor::_frame_title_popup_hide));
  5673. add_child(frame_title_change_popup);
  5674. frame_tint_color_pick_popup = memnew(PopupPanel);
  5675. VBoxContainer *frame_popup_item_tint_color_editor = memnew(VBoxContainer);
  5676. frame_tint_color_pick_popup->add_child(frame_popup_item_tint_color_editor);
  5677. frame_tint_color_picker = memnew(ColorPicker);
  5678. frame_popup_item_tint_color_editor->add_child(frame_tint_color_picker);
  5679. frame_tint_color_picker->reset_size();
  5680. frame_tint_color_picker->connect("color_changed", callable_mp(this, &VisualShaderEditor::_frame_color_changed));
  5681. Button *frame_tint_color_confirm_button = memnew(Button);
  5682. frame_tint_color_confirm_button->set_text(TTR("OK"));
  5683. frame_popup_item_tint_color_editor->add_child(frame_tint_color_confirm_button);
  5684. frame_tint_color_confirm_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_frame_color_confirm));
  5685. frame_tint_color_pick_popup->connect("popup_hide", callable_mp(this, &VisualShaderEditor::_frame_color_popup_hide));
  5686. add_child(frame_tint_color_pick_popup);
  5687. ///////////////////////////////////////
  5688. // SHADER NODES TREE OPTIONS
  5689. ///////////////////////////////////////
  5690. // COLOR
  5691. add_options.push_back(AddOption("ColorFunc", "Color/Common", "VisualShaderNodeColorFunc", TTR("Color function."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5692. add_options.push_back(AddOption("ColorOp", "Color/Common", "VisualShaderNodeColorOp", TTR("Color operator."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5693. add_options.push_back(AddOption("Grayscale", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Grayscale function."), { VisualShaderNodeColorFunc::FUNC_GRAYSCALE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5694. 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));
  5695. 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));
  5696. add_options.push_back(AddOption("Sepia", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Sepia function."), { VisualShaderNodeColorFunc::FUNC_SEPIA }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5697. add_options.push_back(AddOption("Burn", "Color/Operators", "VisualShaderNodeColorOp", TTR("Burn operator."), { VisualShaderNodeColorOp::OP_BURN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5698. add_options.push_back(AddOption("Darken", "Color/Operators", "VisualShaderNodeColorOp", TTR("Darken operator."), { VisualShaderNodeColorOp::OP_DARKEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5699. add_options.push_back(AddOption("Difference", "Color/Operators", "VisualShaderNodeColorOp", TTR("Difference operator."), { VisualShaderNodeColorOp::OP_DIFFERENCE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5700. add_options.push_back(AddOption("Dodge", "Color/Operators", "VisualShaderNodeColorOp", TTR("Dodge operator."), { VisualShaderNodeColorOp::OP_DODGE }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5701. add_options.push_back(AddOption("HardLight", "Color/Operators", "VisualShaderNodeColorOp", TTR("HardLight operator."), { VisualShaderNodeColorOp::OP_HARD_LIGHT }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5702. add_options.push_back(AddOption("Lighten", "Color/Operators", "VisualShaderNodeColorOp", TTR("Lighten operator."), { VisualShaderNodeColorOp::OP_LIGHTEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5703. add_options.push_back(AddOption("Overlay", "Color/Operators", "VisualShaderNodeColorOp", TTR("Overlay operator."), { VisualShaderNodeColorOp::OP_OVERLAY }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5704. add_options.push_back(AddOption("Screen", "Color/Operators", "VisualShaderNodeColorOp", TTR("Screen operator."), { VisualShaderNodeColorOp::OP_SCREEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5705. add_options.push_back(AddOption("SoftLight", "Color/Operators", "VisualShaderNodeColorOp", TTR("SoftLight operator."), { VisualShaderNodeColorOp::OP_SOFT_LIGHT }, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  5706. add_options.push_back(AddOption("ColorConstant", "Color/Variables", "VisualShaderNodeColorConstant", TTR("Color constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  5707. add_options.push_back(AddOption("ColorParameter", "Color/Variables", "VisualShaderNodeColorParameter", TTR("Color parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  5708. // COMMON
  5709. 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));
  5710. // CONDITIONAL
  5711. const String &compare_func_desc = TTR("Returns the boolean result of the %s comparison between two parameters.");
  5712. add_options.push_back(AddOption("Equal (==)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Equal (==)")), { VisualShaderNodeCompare::FUNC_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5713. add_options.push_back(AddOption("GreaterThan (>)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Greater Than (>)")), { VisualShaderNodeCompare::FUNC_GREATER_THAN }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5714. 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));
  5715. 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));
  5716. 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));
  5717. 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));
  5718. add_options.push_back(AddOption("LessThan (<)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than (<)")), { VisualShaderNodeCompare::FUNC_LESS_THAN }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5719. 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));
  5720. add_options.push_back(AddOption("NotEqual (!=)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Not Equal (!=)")), { VisualShaderNodeCompare::FUNC_NOT_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5721. 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));
  5722. 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));
  5723. 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));
  5724. 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));
  5725. 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));
  5726. 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));
  5727. 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));
  5728. 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));
  5729. add_options.push_back(AddOption("Compare (==)", "Conditional/Common", "VisualShaderNodeCompare", TTR("Returns the boolean result of the comparison between two parameters."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5730. 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));
  5731. add_options.push_back(AddOption("BooleanConstant", "Conditional/Variables", "VisualShaderNodeBooleanConstant", TTR("Boolean constant."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5732. add_options.push_back(AddOption("BooleanParameter", "Conditional/Variables", "VisualShaderNodeBooleanParameter", TTR("Boolean parameter."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN));
  5733. // INPUT
  5734. const String translation_gdsl = "\n\n" + TTR("Translated to '%s' in Godot Shading Language.");
  5735. const String input_param_shader_modes = TTR("'%s' input parameter for all shader modes.") + translation_gdsl;
  5736. // NODE3D-FOR-ALL
  5737. 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));
  5738. 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));
  5739. 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));
  5740. 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));
  5741. 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));
  5742. 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));
  5743. 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));
  5744. 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));
  5745. 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));
  5746. 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));
  5747. 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));
  5748. 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));
  5749. 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));
  5750. // CANVASITEM-FOR-ALL
  5751. 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));
  5752. 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));
  5753. 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));
  5754. 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));
  5755. // PARTICLES-FOR-ALL
  5756. 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));
  5757. 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));
  5758. 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));
  5759. 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));
  5760. 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));
  5761. 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));
  5762. 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));
  5763. 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));
  5764. 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));
  5765. 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));
  5766. 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));
  5767. 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));
  5768. 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));
  5769. 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));
  5770. /////////////////
  5771. add_options.push_back(AddOption("Input", "Input/Common", "VisualShaderNodeInput", TTR("Input parameter.")));
  5772. const String input_param_for_vertex_and_fragment_shader_modes = TTR("'%s' input parameter for vertex and fragment shader modes.") + translation_gdsl;
  5773. const String input_param_for_fragment_and_light_shader_modes = TTR("'%s' input parameter for fragment and light shader modes.") + translation_gdsl;
  5774. const String input_param_for_fragment_shader_mode = TTR("'%s' input parameter for fragment shader mode.") + translation_gdsl;
  5775. const String input_param_for_sky_shader_mode = TTR("'%s' input parameter for sky shader mode.") + translation_gdsl;
  5776. const String input_param_for_fog_shader_mode = TTR("'%s' input parameter for fog shader mode.") + translation_gdsl;
  5777. const String input_param_for_light_shader_mode = TTR("'%s' input parameter for light shader mode.") + translation_gdsl;
  5778. const String input_param_for_vertex_shader_mode = TTR("'%s' input parameter for vertex shader mode.") + translation_gdsl;
  5779. const String input_param_for_start_shader_mode = TTR("'%s' input parameter for start shader mode.") + translation_gdsl;
  5780. const String input_param_for_process_shader_mode = TTR("'%s' input parameter for process shader mode.") + translation_gdsl;
  5781. const String input_param_for_collide_shader_mode = TTR("'%s' input parameter for collide shader mode." + translation_gdsl);
  5782. const String input_param_for_start_and_process_shader_mode = TTR("'%s' input parameter for start and process shader modes.") + translation_gdsl;
  5783. const String input_param_for_process_and_collide_shader_mode = TTR("'%s' input parameter for process and collide shader modes.") + translation_gdsl;
  5784. const String input_param_for_vertex_and_fragment_shader_mode = TTR("'%s' input parameter for vertex and fragment shader modes.") + translation_gdsl;
  5785. // NODE3D INPUTS
  5786. 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));
  5787. 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));
  5788. 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));
  5789. 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));
  5790. 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));
  5791. 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));
  5792. 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));
  5793. 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));
  5794. 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));
  5795. 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));
  5796. 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));
  5797. 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));
  5798. 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));
  5799. 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));
  5800. 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));
  5801. 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));
  5802. 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));
  5803. 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));
  5804. 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));
  5805. 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));
  5806. 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));
  5807. 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));
  5808. 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));
  5809. 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));
  5810. 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));
  5811. 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));
  5812. 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));
  5813. 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));
  5814. 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));
  5815. 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));
  5816. 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));
  5817. 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));
  5818. 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));
  5819. add_options.push_back(AddOption("ScreenUV", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  5820. 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));
  5821. 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));
  5822. 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));
  5823. 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));
  5824. 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));
  5825. 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));
  5826. 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));
  5827. 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));
  5828. 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));
  5829. 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));
  5830. 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));
  5831. 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));
  5832. 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));
  5833. 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));
  5834. 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));
  5835. 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));
  5836. 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));
  5837. 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));
  5838. // CANVASITEM INPUTS
  5839. 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));
  5840. 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));
  5841. 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));
  5842. 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));
  5843. 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));
  5844. 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));
  5845. 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));
  5846. 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));
  5847. 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));
  5848. 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));
  5849. 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));
  5850. 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));
  5851. 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));
  5852. 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));
  5853. 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));
  5854. 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));
  5855. 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));
  5856. 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));
  5857. 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));
  5858. 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));
  5859. 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));
  5860. 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));
  5861. 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));
  5862. 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));
  5863. 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));
  5864. 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));
  5865. 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));
  5866. 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));
  5867. 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));
  5868. 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));
  5869. 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));
  5870. 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));
  5871. 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));
  5872. 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));
  5873. 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));
  5874. // SKY INPUTS
  5875. 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));
  5876. 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));
  5877. 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));
  5878. 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));
  5879. 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));
  5880. 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));
  5881. 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));
  5882. 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));
  5883. 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));
  5884. 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));
  5885. 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));
  5886. 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));
  5887. 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));
  5888. 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));
  5889. 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));
  5890. 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));
  5891. 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));
  5892. 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));
  5893. 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));
  5894. 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));
  5895. 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));
  5896. 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));
  5897. 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));
  5898. 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));
  5899. 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));
  5900. 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));
  5901. 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));
  5902. 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));
  5903. // FOG INPUTS
  5904. 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));
  5905. 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));
  5906. 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));
  5907. 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));
  5908. 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));
  5909. 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));
  5910. // PARTICLES INPUTS
  5911. 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));
  5912. 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));
  5913. // PARTICLES
  5914. add_options.push_back(AddOption("EmitParticle", "Particles", "VisualShaderNodeParticleEmit", "", {}, -1, TYPE_FLAGS_PROCESS | TYPE_FLAGS_PROCESS_CUSTOM | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  5915. add_options.push_back(AddOption("ParticleAccelerator", "Particles", "VisualShaderNodeParticleAccelerator", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES));
  5916. add_options.push_back(AddOption("ParticleRandomness", "Particles", "VisualShaderNodeParticleRandomness", "", {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT | TYPE_FLAGS_PROCESS | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
  5917. 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));
  5918. add_options.push_back(AddOption("BoxEmitter", "Particles/Emitters", "VisualShaderNodeParticleBoxEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  5919. mesh_emitter_option_idx = add_options.size();
  5920. add_options.push_back(AddOption("MeshEmitter", "Particles/Emitters", "VisualShaderNodeParticleMeshEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  5921. add_options.push_back(AddOption("RingEmitter", "Particles/Emitters", "VisualShaderNodeParticleRingEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  5922. add_options.push_back(AddOption("SphereEmitter", "Particles/Emitters", "VisualShaderNodeParticleSphereEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  5923. add_options.push_back(AddOption("ConeVelocity", "Particles/Velocity", "VisualShaderNodeParticleConeVelocity", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
  5924. // SCALAR
  5925. add_options.push_back(AddOption("FloatFunc", "Scalar/Common", "VisualShaderNodeFloatFunc", TTR("Float function."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  5926. add_options.push_back(AddOption("FloatOp", "Scalar/Common", "VisualShaderNodeFloatOp", TTR("Float operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  5927. add_options.push_back(AddOption("IntFunc", "Scalar/Common", "VisualShaderNodeIntFunc", TTR("Integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  5928. add_options.push_back(AddOption("IntOp", "Scalar/Common", "VisualShaderNodeIntOp", TTR("Integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  5929. add_options.push_back(AddOption("UIntFunc", "Scalar/Common", "VisualShaderNodeUIntFunc", TTR("Unsigned integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  5930. add_options.push_back(AddOption("UIntOp", "Scalar/Common", "VisualShaderNodeUIntOp", TTR("Unsigned integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  5931. // CONSTANTS
  5932. for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
  5933. 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));
  5934. }
  5935. // FUNCTIONS
  5936. add_options.push_back(AddOption("Abs", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ABS }, VisualShaderNode::PORT_TYPE_SCALAR));
  5937. 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));
  5938. add_options.push_back(AddOption("ACos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ACOS }, VisualShaderNode::PORT_TYPE_SCALAR));
  5939. 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));
  5940. add_options.push_back(AddOption("ASin", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ASIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  5941. 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));
  5942. add_options.push_back(AddOption("ATan", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ATAN }, VisualShaderNode::PORT_TYPE_SCALAR));
  5943. add_options.push_back(AddOption("ATan2", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeFloatOp::OP_ATAN2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  5944. 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));
  5945. 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));
  5946. 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));
  5947. 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));
  5948. 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));
  5949. 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));
  5950. 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));
  5951. add_options.push_back(AddOption("Cos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COS }, VisualShaderNode::PORT_TYPE_SCALAR));
  5952. add_options.push_back(AddOption("CosH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COSH }, VisualShaderNode::PORT_TYPE_SCALAR));
  5953. add_options.push_back(AddOption("Degrees", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeFloatFunc::FUNC_DEGREES }, VisualShaderNode::PORT_TYPE_SCALAR));
  5954. 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));
  5955. 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));
  5956. add_options.push_back(AddOption("Exp", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-e Exponential."), { VisualShaderNodeFloatFunc::FUNC_EXP }, VisualShaderNode::PORT_TYPE_SCALAR));
  5957. add_options.push_back(AddOption("Exp2", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 Exponential."), { VisualShaderNodeFloatFunc::FUNC_EXP2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  5958. 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));
  5959. add_options.push_back(AddOption("Fract", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeFloatFunc::FUNC_FRACT }, VisualShaderNode::PORT_TYPE_SCALAR));
  5960. 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));
  5961. add_options.push_back(AddOption("Log", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Natural logarithm."), { VisualShaderNodeFloatFunc::FUNC_LOG }, VisualShaderNode::PORT_TYPE_SCALAR));
  5962. add_options.push_back(AddOption("Log2", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 logarithm."), { VisualShaderNodeFloatFunc::FUNC_LOG2 }, VisualShaderNode::PORT_TYPE_SCALAR));
  5963. add_options.push_back(AddOption("Max", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the greater of two values."), { VisualShaderNodeFloatOp::OP_MAX }, VisualShaderNode::PORT_TYPE_SCALAR));
  5964. add_options.push_back(AddOption("Min", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the lesser of two values."), { VisualShaderNodeFloatOp::OP_MIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  5965. add_options.push_back(AddOption("Mix", "Scalar/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two scalars."), { VisualShaderNodeMix::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR));
  5966. 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));
  5967. 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));
  5968. 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));
  5969. 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));
  5970. add_options.push_back(AddOption("OneMinus (1-)", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 - scalar"), { VisualShaderNodeFloatFunc::FUNC_ONEMINUS }, VisualShaderNode::PORT_TYPE_SCALAR));
  5971. 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));
  5972. add_options.push_back(AddOption("Radians", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeFloatFunc::FUNC_RADIANS }, VisualShaderNode::PORT_TYPE_SCALAR));
  5973. add_options.push_back(AddOption("Reciprocal", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 / scalar"), { VisualShaderNodeFloatFunc::FUNC_RECIPROCAL }, VisualShaderNode::PORT_TYPE_SCALAR));
  5974. add_options.push_back(AddOption("Round", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeFloatFunc::FUNC_ROUND }, VisualShaderNode::PORT_TYPE_SCALAR));
  5975. 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));
  5976. 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));
  5977. add_options.push_back(AddOption("Sign", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SIGN }, VisualShaderNode::PORT_TYPE_SCALAR));
  5978. add_options.push_back(AddOption("Sign", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeIntFunc::FUNC_SIGN }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  5979. add_options.push_back(AddOption("Sin", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SIN }, VisualShaderNode::PORT_TYPE_SCALAR));
  5980. add_options.push_back(AddOption("SinH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SINH }, VisualShaderNode::PORT_TYPE_SCALAR));
  5981. add_options.push_back(AddOption("Sqrt", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SQRT }, VisualShaderNode::PORT_TYPE_SCALAR));
  5982. 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));
  5983. 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));
  5984. 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));
  5985. add_options.push_back(AddOption("Tan", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TAN }, VisualShaderNode::PORT_TYPE_SCALAR));
  5986. add_options.push_back(AddOption("TanH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TANH }, VisualShaderNode::PORT_TYPE_SCALAR));
  5987. add_options.push_back(AddOption("Trunc", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TRUNC }, VisualShaderNode::PORT_TYPE_SCALAR));
  5988. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Sums two floating-point scalars."), { VisualShaderNodeFloatOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR));
  5989. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Sums two integer scalars."), { VisualShaderNodeIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  5990. add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Sums two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  5991. 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));
  5992. 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));
  5993. 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));
  5994. 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));
  5995. 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));
  5996. 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));
  5997. 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));
  5998. 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));
  5999. 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));
  6000. 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));
  6001. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Divides two floating-point scalars."), { VisualShaderNodeFloatOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR));
  6002. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Divides two integer scalars."), { VisualShaderNodeIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6003. add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Divides two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6004. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Multiplies two floating-point scalars."), { VisualShaderNodeFloatOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR));
  6005. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Multiplies two integer scalars."), { VisualShaderNodeIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6006. add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Multiplies two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6007. 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));
  6008. 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));
  6009. 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));
  6010. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Subtracts two floating-point scalars."), { VisualShaderNodeFloatOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR));
  6011. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Subtracts two integer scalars."), { VisualShaderNodeIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6012. add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Subtracts two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6013. add_options.push_back(AddOption("FloatConstant", "Scalar/Variables", "VisualShaderNodeFloatConstant", TTR("Scalar floating-point constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6014. add_options.push_back(AddOption("IntConstant", "Scalar/Variables", "VisualShaderNodeIntConstant", TTR("Scalar integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6015. add_options.push_back(AddOption("UIntConstant", "Scalar/Variables", "VisualShaderNodeUIntConstant", TTR("Scalar unsigned integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6016. add_options.push_back(AddOption("FloatParameter", "Scalar/Variables", "VisualShaderNodeFloatParameter", TTR("Scalar floating-point parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6017. add_options.push_back(AddOption("IntParameter", "Scalar/Variables", "VisualShaderNodeIntParameter", TTR("Scalar integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT));
  6018. add_options.push_back(AddOption("UIntParameter", "Scalar/Variables", "VisualShaderNodeUIntParameter", TTR("Scalar unsigned integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT));
  6019. // SDF
  6020. {
  6021. 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));
  6022. 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));
  6023. 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));
  6024. 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));
  6025. 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));
  6026. }
  6027. // TEXTURES
  6028. add_options.push_back(AddOption("UVFunc", "Textures/Common", "VisualShaderNodeUVFunc", TTR("Function to be applied on texture coordinates."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6029. add_options.push_back(AddOption("UVPolarCoord", "Textures/Common", "VisualShaderNodeUVPolarCoord", TTR("Polar coordinates conversion applied on texture coordinates."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6030. cubemap_node_option_idx = add_options.size();
  6031. add_options.push_back(AddOption("CubeMap", "Textures/Functions", "VisualShaderNodeCubemap", TTR("Perform the cubic texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6032. curve_node_option_idx = add_options.size();
  6033. add_options.push_back(AddOption("CurveTexture", "Textures/Functions", "VisualShaderNodeCurveTexture", TTR("Perform the curve texture lookup."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6034. curve_xyz_node_option_idx = add_options.size();
  6035. add_options.push_back(AddOption("CurveXYZTexture", "Textures/Functions", "VisualShaderNodeCurveXYZTexture", TTR("Perform the three components curve texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6036. 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));
  6037. texture2d_node_option_idx = add_options.size();
  6038. 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));
  6039. texture2d_node_option_idx = add_options.size();
  6040. 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));
  6041. texture2d_node_option_idx = add_options.size();
  6042. add_options.push_back(AddOption("Texture2D", "Textures/Functions", "VisualShaderNodeTexture", TTR("Perform the 2D texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6043. texture2d_array_node_option_idx = add_options.size();
  6044. add_options.push_back(AddOption("Texture2DArray", "Textures/Functions", "VisualShaderNodeTexture2DArray", TTR("Perform the 2D-array texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6045. texture3d_node_option_idx = add_options.size();
  6046. add_options.push_back(AddOption("Texture3D", "Textures/Functions", "VisualShaderNodeTexture3D", TTR("Perform the 3D texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6047. add_options.push_back(AddOption("UVPanning", "Textures/Functions", "VisualShaderNodeUVFunc", TTR("Apply panning function on texture coordinates."), { VisualShaderNodeUVFunc::FUNC_PANNING }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6048. add_options.push_back(AddOption("UVScaling", "Textures/Functions", "VisualShaderNodeUVFunc", TTR("Apply scaling function on texture coordinates."), { VisualShaderNodeUVFunc::FUNC_SCALING }, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6049. add_options.push_back(AddOption("CubeMapParameter", "Textures/Variables", "VisualShaderNodeCubemapParameter", TTR("Cubic texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6050. add_options.push_back(AddOption("Texture2DParameter", "Textures/Variables", "VisualShaderNodeTexture2DParameter", TTR("2D texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6051. 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));
  6052. add_options.push_back(AddOption("Texture2DArrayParameter", "Textures/Variables", "VisualShaderNodeTexture2DArrayParameter", TTR("2D array of textures parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6053. add_options.push_back(AddOption("Texture3DParameter", "Textures/Variables", "VisualShaderNodeTexture3DParameter", TTR("3D texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER));
  6054. // TRANSFORM
  6055. add_options.push_back(AddOption("TransformFunc", "Transform/Common", "VisualShaderNodeTransformFunc", TTR("Transform function."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6056. add_options.push_back(AddOption("TransformOp", "Transform/Common", "VisualShaderNodeTransformOp", TTR("Transform operator."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6057. 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));
  6058. add_options.push_back(AddOption("TransformCompose", "Transform/Composition", "VisualShaderNodeTransformCompose", TTR("Composes transform from four vectors."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6059. add_options.push_back(AddOption("TransformDecompose", "Transform/Composition", "VisualShaderNodeTransformDecompose", TTR("Decomposes transform to four vectors.")));
  6060. add_options.push_back(AddOption("Determinant", "Transform/Functions", "VisualShaderNodeDeterminant", TTR("Calculates the determinant of a transform."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6061. 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));
  6062. add_options.push_back(AddOption("Inverse", "Transform/Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the inverse of a transform."), { VisualShaderNodeTransformFunc::FUNC_INVERSE }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6063. add_options.push_back(AddOption("Transpose", "Transform/Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the transpose of a transform."), { VisualShaderNodeTransformFunc::FUNC_TRANSPOSE }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6064. add_options.push_back(AddOption("Add (+)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Sums two transforms."), { VisualShaderNodeTransformOp::OP_ADD }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6065. add_options.push_back(AddOption("Divide (/)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Divides two transforms."), { VisualShaderNodeTransformOp::OP_A_DIV_B }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6066. add_options.push_back(AddOption("Multiply (*)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Multiplies two transforms."), { VisualShaderNodeTransformOp::OP_AxB }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6067. 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));
  6068. add_options.push_back(AddOption("Subtract (-)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Subtracts two transforms."), { VisualShaderNodeTransformOp::OP_A_MINUS_B }, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6069. add_options.push_back(AddOption("TransformVectorMult (*)", "Transform/Operators", "VisualShaderNodeTransformVecMult", TTR("Multiplies vector by transform."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6070. add_options.push_back(AddOption("TransformConstant", "Transform/Variables", "VisualShaderNodeTransformConstant", TTR("Transform constant."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6071. add_options.push_back(AddOption("TransformParameter", "Transform/Variables", "VisualShaderNodeTransformParameter", TTR("Transform parameter."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM));
  6072. // UTILITY
  6073. 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));
  6074. 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));
  6075. add_options.push_back(AddOption("RandomRange", "Utility", "VisualShaderNodeRandomRange", TTR("Returns a random value between the minimum and maximum input values."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6076. add_options.push_back(AddOption("Remap", "Utility", "VisualShaderNodeRemap", TTR("Remaps a given input from the input range to the output range."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6077. 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));
  6078. // VECTOR
  6079. add_options.push_back(AddOption("VectorFunc", "Vector/Common", "VisualShaderNodeVectorFunc", TTR("Vector function."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6080. add_options.push_back(AddOption("VectorOp", "Vector/Common", "VisualShaderNodeVectorOp", TTR("Vector operator."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6081. add_options.push_back(AddOption("VectorCompose", "Vector/Common", "VisualShaderNodeVectorCompose", TTR("Composes vector from scalars.")));
  6082. add_options.push_back(AddOption("VectorDecompose", "Vector/Common", "VisualShaderNodeVectorDecompose", TTR("Decomposes vector to scalars.")));
  6083. 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));
  6084. add_options.push_back(AddOption("Vector2Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 2D vector to two scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_2D }));
  6085. 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));
  6086. add_options.push_back(AddOption("Vector3Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 3D vector to three scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_3D }));
  6087. 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));
  6088. add_options.push_back(AddOption("Vector4Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 4D vector to four scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_4D }));
  6089. 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));
  6090. 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));
  6091. 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));
  6092. 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));
  6093. 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));
  6094. 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));
  6095. 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));
  6096. 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));
  6097. 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));
  6098. 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));
  6099. 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));
  6100. 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));
  6101. 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));
  6102. 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));
  6103. 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));
  6104. 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));
  6105. 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));
  6106. 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));
  6107. 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));
  6108. 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));
  6109. 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));
  6110. 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));
  6111. 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));
  6112. 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));
  6113. 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));
  6114. 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));
  6115. 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));
  6116. 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));
  6117. 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));
  6118. 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));
  6119. 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));
  6120. 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));
  6121. 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));
  6122. 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));
  6123. 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));
  6124. 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));
  6125. 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));
  6126. 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));
  6127. 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));
  6128. 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));
  6129. 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));
  6130. 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));
  6131. 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));
  6132. 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));
  6133. 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));
  6134. 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));
  6135. 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));
  6136. 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));
  6137. 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));
  6138. add_options.push_back(AddOption("Dot", "Vector/Functions", "VisualShaderNodeDotProduct", TTR("Calculates the dot product of two vectors."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
  6139. 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));
  6140. 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));
  6141. 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));
  6142. 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));
  6143. 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));
  6144. 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));
  6145. 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));
  6146. 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));
  6147. 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));
  6148. 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));
  6149. 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));
  6150. 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));
  6151. 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));
  6152. 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));
  6153. 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));
  6154. 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));
  6155. 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));
  6156. 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));
  6157. 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));
  6158. 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));
  6159. 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));
  6160. 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));
  6161. 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));
  6162. 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));
  6163. 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));
  6164. 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));
  6165. 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));
  6166. 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));
  6167. 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));
  6168. 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));
  6169. 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));
  6170. 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));
  6171. 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));
  6172. 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));
  6173. 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));
  6174. 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));
  6175. 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));
  6176. 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));
  6177. 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));
  6178. 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));
  6179. 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));
  6180. 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));
  6181. 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));
  6182. 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));
  6183. 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));
  6184. 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));
  6185. 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));
  6186. 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));
  6187. 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));
  6188. 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));
  6189. 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));
  6190. 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));
  6191. 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));
  6192. 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));
  6193. 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));
  6194. 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));
  6195. 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));
  6196. 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));
  6197. 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));
  6198. 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));
  6199. 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));
  6200. 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));
  6201. 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));
  6202. 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));
  6203. 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));
  6204. 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));
  6205. 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));
  6206. 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));
  6207. 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));
  6208. 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));
  6209. 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));
  6210. 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));
  6211. 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));
  6212. 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));
  6213. 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));
  6214. 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));
  6215. 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));
  6216. 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));
  6217. 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));
  6218. 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));
  6219. 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));
  6220. 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));
  6221. 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));
  6222. 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));
  6223. 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));
  6224. 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));
  6225. 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));
  6226. 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));
  6227. 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));
  6228. 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));
  6229. 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));
  6230. 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));
  6231. 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));
  6232. 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));
  6233. 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));
  6234. 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));
  6235. 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));
  6236. 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));
  6237. 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));
  6238. 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));
  6239. 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));
  6240. 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));
  6241. 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));
  6242. 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));
  6243. 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));
  6244. 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));
  6245. 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));
  6246. 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));
  6247. 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));
  6248. 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));
  6249. 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));
  6250. 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));
  6251. 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));
  6252. 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));
  6253. 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));
  6254. 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));
  6255. 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));
  6256. 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));
  6257. 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));
  6258. 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));
  6259. 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));
  6260. 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));
  6261. 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));
  6262. 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));
  6263. 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));
  6264. 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));
  6265. add_options.push_back(AddOption("Vector2Constant", "Vector/Variables", "VisualShaderNodeVec2Constant", TTR("2D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6266. add_options.push_back(AddOption("Vector2Parameter", "Vector/Variables", "VisualShaderNodeVec2Parameter", TTR("2D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D));
  6267. add_options.push_back(AddOption("Vector3Constant", "Vector/Variables", "VisualShaderNodeVec3Constant", TTR("3D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6268. add_options.push_back(AddOption("Vector3Parameter", "Vector/Variables", "VisualShaderNodeVec3Parameter", TTR("3D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));
  6269. add_options.push_back(AddOption("Vector4Constant", "Vector/Variables", "VisualShaderNodeVec4Constant", TTR("4D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6270. add_options.push_back(AddOption("Vector4Parameter", "Vector/Variables", "VisualShaderNodeVec4Parameter", TTR("4D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D));
  6271. // SPECIAL
  6272. add_options.push_back(AddOption("Frame", "Special", "VisualShaderNodeFrame", TTR("A rectangular area with a description string for better graph organization.")));
  6273. 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.")));
  6274. 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.")));
  6275. add_options.push_back(AddOption("ParameterRef", "Special", "VisualShaderNodeParameterRef", TTR("A reference to an existing parameter.")));
  6276. add_options.push_back(AddOption("VaryingGetter", "Special", "VisualShaderNodeVaryingGetter", TTR("Get varying parameter."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
  6277. add_options.push_back(AddOption("VaryingSetter", "Special", "VisualShaderNodeVaryingSetter", TTR("Set varying parameter."), {}, -1, TYPE_FLAGS_VERTEX | TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
  6278. add_options.push_back(AddOption("VaryingGetter", "Special", "VisualShaderNodeVaryingGetter", TTR("Get varying parameter."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
  6279. add_options.push_back(AddOption("VaryingSetter", "Special", "VisualShaderNodeVaryingSetter", TTR("Set varying parameter."), {}, -1, TYPE_FLAGS_VERTEX | TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM));
  6280. add_options.push_back(AddOption("Reroute", "Special", "VisualShaderNodeReroute", TTR("Reroute connections freely, can be used to connect multiple input ports to single output port.")));
  6281. custom_node_option_idx = add_options.size();
  6282. /////////////////////////////////////////////////////////////////////
  6283. Ref<VisualShaderNodePluginDefault> default_plugin;
  6284. default_plugin.instantiate();
  6285. default_plugin->set_editor(this);
  6286. add_plugin(default_plugin);
  6287. graph_plugin.instantiate();
  6288. graph_plugin->set_editor(this);
  6289. property_editor_popup = memnew(PopupPanel);
  6290. property_editor_popup->set_min_size(Size2(360, 0) * EDSCALE);
  6291. add_child(property_editor_popup);
  6292. edited_property_holder.instantiate();
  6293. }
  6294. class VisualShaderNodePluginInputEditor : public OptionButton {
  6295. GDCLASS(VisualShaderNodePluginInputEditor, OptionButton);
  6296. VisualShaderEditor *editor = nullptr;
  6297. Ref<VisualShaderNodeInput> input;
  6298. public:
  6299. void _notification(int p_what) {
  6300. switch (p_what) {
  6301. case NOTIFICATION_READY: {
  6302. connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginInputEditor::_item_selected));
  6303. } break;
  6304. }
  6305. }
  6306. void _item_selected(int p_item) {
  6307. editor->call_deferred(SNAME("_input_select_item"), input, get_item_text(p_item));
  6308. }
  6309. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeInput> &p_input) {
  6310. editor = p_editor;
  6311. input = p_input;
  6312. Ref<Texture2D> type_icon[] = {
  6313. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)),
  6314. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)),
  6315. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)),
  6316. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)),
  6317. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)),
  6318. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)),
  6319. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)),
  6320. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)),
  6321. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ImageTexture"), EditorStringName(EditorIcons)),
  6322. };
  6323. add_item("[None]");
  6324. int to_select = -1;
  6325. for (int i = 0; i < input->get_input_index_count(); i++) {
  6326. if (input->get_input_name() == input->get_input_index_name(i)) {
  6327. to_select = i + 1;
  6328. }
  6329. add_icon_item(type_icon[input->get_input_index_type(i)], input->get_input_index_name(i));
  6330. }
  6331. if (to_select >= 0) {
  6332. select(to_select);
  6333. }
  6334. }
  6335. };
  6336. ////////////////
  6337. class VisualShaderNodePluginVaryingEditor : public OptionButton {
  6338. GDCLASS(VisualShaderNodePluginVaryingEditor, OptionButton);
  6339. VisualShaderEditor *editor = nullptr;
  6340. Ref<VisualShaderNodeVarying> varying;
  6341. public:
  6342. void _notification(int p_what) {
  6343. if (p_what == NOTIFICATION_READY) {
  6344. connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginVaryingEditor::_item_selected));
  6345. }
  6346. }
  6347. void _item_selected(int p_item) {
  6348. editor->call_deferred(SNAME("_varying_select_item"), varying, get_item_text(p_item));
  6349. }
  6350. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeVarying> &p_varying, VisualShader::Type p_type) {
  6351. editor = p_editor;
  6352. varying = p_varying;
  6353. Ref<Texture2D> type_icon[] = {
  6354. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)),
  6355. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)),
  6356. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)),
  6357. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)),
  6358. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)),
  6359. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)),
  6360. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)),
  6361. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)),
  6362. };
  6363. bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid();
  6364. add_item("[None]");
  6365. int to_select = -1;
  6366. for (int i = 0, j = 0; i < varying->get_varyings_count(); i++) {
  6367. VisualShader::VaryingMode mode = varying->get_varying_mode_by_index(i);
  6368. if (is_getter) {
  6369. if (mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT) {
  6370. if (p_type != VisualShader::TYPE_LIGHT) {
  6371. j++;
  6372. continue;
  6373. }
  6374. } else {
  6375. if (p_type != VisualShader::TYPE_FRAGMENT && p_type != VisualShader::TYPE_LIGHT) {
  6376. j++;
  6377. continue;
  6378. }
  6379. }
  6380. } else {
  6381. if (mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT) {
  6382. if (p_type != VisualShader::TYPE_FRAGMENT) {
  6383. j++;
  6384. continue;
  6385. }
  6386. } else {
  6387. if (p_type != VisualShader::TYPE_VERTEX) {
  6388. j++;
  6389. continue;
  6390. }
  6391. }
  6392. }
  6393. if (varying->get_varying_name() == varying->get_varying_name_by_index(i)) {
  6394. to_select = i - j + 1;
  6395. }
  6396. add_icon_item(type_icon[varying->get_varying_type_by_index(i)], varying->get_varying_name_by_index(i));
  6397. }
  6398. if (to_select >= 0) {
  6399. select(to_select);
  6400. }
  6401. }
  6402. };
  6403. ////////////////
  6404. class VisualShaderNodePluginParameterRefEditor : public OptionButton {
  6405. GDCLASS(VisualShaderNodePluginParameterRefEditor, OptionButton);
  6406. VisualShaderEditor *editor = nullptr;
  6407. Ref<VisualShaderNodeParameterRef> parameter_ref;
  6408. public:
  6409. void _notification(int p_what) {
  6410. switch (p_what) {
  6411. case NOTIFICATION_READY: {
  6412. connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginParameterRefEditor::_item_selected));
  6413. } break;
  6414. }
  6415. }
  6416. void _item_selected(int p_item) {
  6417. editor->call_deferred(SNAME("_parameter_ref_select_item"), parameter_ref, get_item_text(p_item));
  6418. }
  6419. void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeParameterRef> &p_parameter_ref) {
  6420. editor = p_editor;
  6421. parameter_ref = p_parameter_ref;
  6422. Ref<Texture2D> type_icon[] = {
  6423. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)),
  6424. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)),
  6425. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), 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("Vector2"), EditorStringName(EditorIcons)),
  6428. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)),
  6429. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)),
  6430. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)),
  6431. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Color"), EditorStringName(EditorIcons)),
  6432. EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ImageTexture"), EditorStringName(EditorIcons)),
  6433. };
  6434. add_item("[None]");
  6435. int to_select = -1;
  6436. for (int i = 0; i < p_parameter_ref->get_parameters_count(); i++) {
  6437. if (p_parameter_ref->get_parameter_name() == p_parameter_ref->get_parameter_name_by_index(i)) {
  6438. to_select = i + 1;
  6439. }
  6440. add_icon_item(type_icon[p_parameter_ref->get_parameter_type_by_index(i)], p_parameter_ref->get_parameter_name_by_index(i));
  6441. }
  6442. if (to_select >= 0) {
  6443. select(to_select);
  6444. }
  6445. }
  6446. };
  6447. ////////////////
  6448. class VisualShaderNodePluginDefaultEditor : public VBoxContainer {
  6449. GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer);
  6450. VisualShaderEditor *editor = nullptr;
  6451. Ref<Resource> parent_resource;
  6452. int node_id = 0;
  6453. VisualShader::Type shader_type;
  6454. public:
  6455. void _property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false) {
  6456. if (p_changing) {
  6457. return;
  6458. }
  6459. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  6460. updating = true;
  6461. undo_redo->create_action(vformat(TTR("Edit Visual Property: %s"), p_property), UndoRedo::MERGE_ENDS);
  6462. undo_redo->add_do_property(node.ptr(), p_property, p_value);
  6463. undo_redo->add_undo_property(node.ptr(), p_property, node->get(p_property));
  6464. Ref<VisualShaderNode> vsnode = editor->get_visual_shader()->get_node(shader_type, node_id);
  6465. ERR_FAIL_COND(vsnode.is_null());
  6466. // Check for invalid connections due to removed ports.
  6467. // We need to know the new state of the node to generate the proper undo/redo instructions.
  6468. // Quite hacky but the best way I could come up with for now.
  6469. Ref<VisualShaderNode> vsnode_new = vsnode->duplicate();
  6470. vsnode_new->set(p_property, p_value);
  6471. const int input_port_count = vsnode_new->get_input_port_count();
  6472. const int output_port_count = vsnode_new->get_expanded_output_port_count();
  6473. List<VisualShader::Connection> conns;
  6474. editor->get_visual_shader()->get_node_connections(shader_type, &conns);
  6475. VisualShaderGraphPlugin *graph_plugin = editor->get_graph_plugin();
  6476. bool undo_node_already_updated = false;
  6477. for (const VisualShader::Connection &c : conns) {
  6478. if ((c.from_node == node_id && c.from_port >= output_port_count) || (c.to_node == node_id && c.to_port >= input_port_count)) {
  6479. 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);
  6480. undo_redo->add_do_method(graph_plugin, "disconnect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port);
  6481. // We need to update the node before reconnecting to avoid accessing a non-existing port.
  6482. undo_redo->add_undo_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  6483. undo_node_already_updated = true;
  6484. 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);
  6485. undo_redo->add_undo_method(graph_plugin, "connect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port);
  6486. }
  6487. }
  6488. if (p_value.get_type() == Variant::OBJECT) {
  6489. Ref<Resource> prev_res = vsnode->get(p_property);
  6490. Ref<Resource> curr_res = p_value;
  6491. if (curr_res.is_null()) {
  6492. undo_redo->add_do_method(this, "_open_inspector", (Ref<Resource>)parent_resource.ptr());
  6493. } else {
  6494. undo_redo->add_do_method(this, "_open_inspector", (Ref<Resource>)curr_res.ptr());
  6495. }
  6496. if (!prev_res.is_null()) {
  6497. undo_redo->add_undo_method(this, "_open_inspector", (Ref<Resource>)prev_res.ptr());
  6498. } else {
  6499. undo_redo->add_undo_method(this, "_open_inspector", (Ref<Resource>)parent_resource.ptr());
  6500. }
  6501. }
  6502. if (p_property != "constant") {
  6503. if (graph_plugin) {
  6504. undo_redo->add_do_method(editor, "_update_next_previews", node_id);
  6505. undo_redo->add_undo_method(editor, "_update_next_previews", node_id);
  6506. undo_redo->add_do_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  6507. if (!undo_node_already_updated) {
  6508. undo_redo->add_undo_method(graph_plugin, "update_node_deferred", shader_type, node_id);
  6509. }
  6510. }
  6511. }
  6512. undo_redo->commit_action();
  6513. updating = false;
  6514. }
  6515. void _node_changed() {
  6516. if (updating) {
  6517. return;
  6518. }
  6519. for (int i = 0; i < properties.size(); i++) {
  6520. properties[i]->update_property();
  6521. }
  6522. }
  6523. void _resource_selected(const String &p_path, Ref<Resource> p_resource) {
  6524. _open_inspector(p_resource);
  6525. }
  6526. void _open_inspector(Ref<Resource> p_resource) {
  6527. InspectorDock::get_inspector_singleton()->edit(p_resource.ptr());
  6528. }
  6529. bool updating = false;
  6530. Ref<VisualShaderNode> node;
  6531. Vector<EditorProperty *> properties;
  6532. Vector<Label *> prop_names;
  6533. void _show_prop_names(bool p_show) {
  6534. for (int i = 0; i < prop_names.size(); i++) {
  6535. prop_names[i]->set_visible(p_show);
  6536. }
  6537. }
  6538. 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) {
  6539. editor = p_editor;
  6540. parent_resource = p_parent_resource;
  6541. updating = false;
  6542. node = p_node;
  6543. properties = p_properties;
  6544. node_id = (int)p_node->get_meta("id");
  6545. shader_type = VisualShader::Type((int)p_node->get_meta("shader_type"));
  6546. for (int i = 0; i < p_properties.size(); i++) {
  6547. HBoxContainer *hbox = memnew(HBoxContainer);
  6548. hbox->set_h_size_flags(SIZE_EXPAND_FILL);
  6549. add_child(hbox);
  6550. Label *prop_name = memnew(Label);
  6551. String prop_name_str = p_names[i];
  6552. if (p_overrided_names.has(p_names[i])) {
  6553. prop_name_str = p_overrided_names[p_names[i]] + ":";
  6554. } else {
  6555. prop_name_str = prop_name_str.capitalize() + ":";
  6556. }
  6557. prop_name->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch.
  6558. prop_name->set_text(prop_name_str);
  6559. prop_name->set_visible(false);
  6560. hbox->add_child(prop_name);
  6561. prop_names.push_back(prop_name);
  6562. p_properties[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  6563. hbox->add_child(p_properties[i]);
  6564. bool res_prop = Object::cast_to<EditorPropertyResource>(p_properties[i]);
  6565. if (res_prop) {
  6566. p_properties[i]->connect("resource_selected", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_resource_selected));
  6567. }
  6568. properties[i]->connect("property_changed", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_property_changed));
  6569. properties[i]->set_object_and_property(node.ptr(), p_names[i]);
  6570. properties[i]->update_property();
  6571. properties[i]->set_name_split_ratio(0);
  6572. }
  6573. node->connect_changed(callable_mp(this, &VisualShaderNodePluginDefaultEditor::_node_changed));
  6574. }
  6575. static void _bind_methods() {
  6576. ClassDB::bind_method("_open_inspector", &VisualShaderNodePluginDefaultEditor::_open_inspector); // Used by UndoRedo.
  6577. ClassDB::bind_method("_show_prop_names", &VisualShaderNodePluginDefaultEditor::_show_prop_names); // Used with call_deferred.
  6578. }
  6579. };
  6580. Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) {
  6581. Ref<VisualShader> p_shader = Ref<VisualShader>(p_parent_resource.ptr());
  6582. if (p_shader.is_valid() && (p_node->is_class("VisualShaderNodeVaryingGetter") || p_node->is_class("VisualShaderNodeVaryingSetter"))) {
  6583. VisualShaderNodePluginVaryingEditor *editor = memnew(VisualShaderNodePluginVaryingEditor);
  6584. editor->setup(vseditor, p_node, p_shader->get_shader_type());
  6585. return editor;
  6586. }
  6587. if (p_node->is_class("VisualShaderNodeParameterRef")) {
  6588. VisualShaderNodePluginParameterRefEditor *editor = memnew(VisualShaderNodePluginParameterRefEditor);
  6589. editor->setup(vseditor, p_node);
  6590. return editor;
  6591. }
  6592. if (p_node->is_class("VisualShaderNodeInput")) {
  6593. VisualShaderNodePluginInputEditor *editor = memnew(VisualShaderNodePluginInputEditor);
  6594. editor->setup(vseditor, p_node);
  6595. return editor;
  6596. }
  6597. Vector<StringName> properties = p_node->get_editable_properties();
  6598. if (properties.size() == 0) {
  6599. return nullptr;
  6600. }
  6601. List<PropertyInfo> props;
  6602. p_node->get_property_list(&props);
  6603. Vector<PropertyInfo> pinfo;
  6604. for (const PropertyInfo &E : props) {
  6605. for (int i = 0; i < properties.size(); i++) {
  6606. if (E.name == String(properties[i])) {
  6607. pinfo.push_back(E);
  6608. }
  6609. }
  6610. }
  6611. if (pinfo.size() == 0) {
  6612. return nullptr;
  6613. }
  6614. properties.clear();
  6615. Ref<VisualShaderNode> node = p_node;
  6616. Vector<EditorProperty *> editors;
  6617. for (int i = 0; i < pinfo.size(); i++) {
  6618. EditorProperty *prop = EditorInspector::instantiate_property_editor(node.ptr(), pinfo[i].type, pinfo[i].name, pinfo[i].hint, pinfo[i].hint_string, pinfo[i].usage);
  6619. if (!prop) {
  6620. return nullptr;
  6621. }
  6622. if (Object::cast_to<EditorPropertyResource>(prop)) {
  6623. Object::cast_to<EditorPropertyResource>(prop)->set_use_sub_inspector(false);
  6624. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  6625. } else if (Object::cast_to<EditorPropertyTransform3D>(prop) || Object::cast_to<EditorPropertyVector3>(prop)) {
  6626. prop->set_custom_minimum_size(Size2(250 * EDSCALE, 0));
  6627. } else if (Object::cast_to<EditorPropertyQuaternion>(prop)) {
  6628. prop->set_custom_minimum_size(Size2(320 * EDSCALE, 0));
  6629. } else if (Object::cast_to<EditorPropertyFloat>(prop)) {
  6630. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  6631. } else if (Object::cast_to<EditorPropertyEnum>(prop)) {
  6632. prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  6633. Object::cast_to<EditorPropertyEnum>(prop)->set_option_button_clip(false);
  6634. } else if (Object::cast_to<EditorPropertyColor>(prop)) {
  6635. Object::cast_to<EditorPropertyColor>(prop)->set_live_changes_enabled(false);
  6636. }
  6637. editors.push_back(prop);
  6638. properties.push_back(pinfo[i].name);
  6639. }
  6640. VisualShaderNodePluginDefaultEditor *editor = memnew(VisualShaderNodePluginDefaultEditor);
  6641. editor->setup(vseditor, p_parent_resource, editors, properties, p_node->get_editable_properties_names(), p_node);
  6642. return editor;
  6643. }
  6644. void EditorPropertyVisualShaderMode::_option_selected(int p_which) {
  6645. Ref<VisualShader> visual_shader(Object::cast_to<VisualShader>(get_edited_object()));
  6646. if (visual_shader->get_mode() == p_which) {
  6647. return;
  6648. }
  6649. ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_editor_data().get_editor_by_name("Shader"));
  6650. if (!shader_editor) {
  6651. return;
  6652. }
  6653. VisualShaderEditor *editor = Object::cast_to<VisualShaderEditor>(shader_editor->get_shader_editor(visual_shader));
  6654. if (!editor) {
  6655. return;
  6656. }
  6657. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  6658. undo_redo->create_action(TTR("Visual Shader Mode Changed"));
  6659. //do is easy
  6660. undo_redo->add_do_method(visual_shader.ptr(), "set_mode", p_which);
  6661. undo_redo->add_undo_method(visual_shader.ptr(), "set_mode", visual_shader->get_mode());
  6662. undo_redo->add_do_method(editor, "_set_mode", p_which);
  6663. undo_redo->add_undo_method(editor, "_set_mode", visual_shader->get_mode());
  6664. //now undo is hell
  6665. //1. restore connections to output
  6666. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  6667. VisualShader::Type type = VisualShader::Type(i);
  6668. List<VisualShader::Connection> conns;
  6669. visual_shader->get_node_connections(type, &conns);
  6670. for (const VisualShader::Connection &E : conns) {
  6671. if (E.to_node == VisualShader::NODE_ID_OUTPUT) {
  6672. undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port);
  6673. }
  6674. }
  6675. }
  6676. //2. restore input indices
  6677. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  6678. VisualShader::Type type = VisualShader::Type(i);
  6679. Vector<int> nodes = visual_shader->get_node_list(type);
  6680. for (int j = 0; j < nodes.size(); j++) {
  6681. Ref<VisualShaderNodeInput> input = visual_shader->get_node(type, nodes[j]);
  6682. if (!input.is_valid()) {
  6683. continue;
  6684. }
  6685. undo_redo->add_undo_method(input.ptr(), "set_input_name", input->get_input_name());
  6686. }
  6687. }
  6688. //3. restore enums and flags
  6689. List<PropertyInfo> props;
  6690. visual_shader->get_property_list(&props);
  6691. for (const PropertyInfo &E : props) {
  6692. if (E.name.begins_with("flags/") || E.name.begins_with("modes/")) {
  6693. undo_redo->add_undo_property(visual_shader.ptr(), E.name, visual_shader->get(E.name));
  6694. }
  6695. }
  6696. //4. delete varyings (if needed)
  6697. if (p_which == VisualShader::MODE_PARTICLES || p_which == VisualShader::MODE_SKY || p_which == VisualShader::MODE_FOG) {
  6698. int var_count = visual_shader->get_varyings_count();
  6699. if (var_count > 0) {
  6700. for (int i = 0; i < var_count; i++) {
  6701. const VisualShader::Varying *var = visual_shader->get_varying_by_index(i);
  6702. undo_redo->add_do_method(visual_shader.ptr(), "remove_varying", var->name);
  6703. undo_redo->add_undo_method(visual_shader.ptr(), "add_varying", var->name, var->mode, var->type);
  6704. }
  6705. undo_redo->add_do_method(editor, "_update_varyings");
  6706. undo_redo->add_undo_method(editor, "_update_varyings");
  6707. }
  6708. }
  6709. undo_redo->add_do_method(editor, "_update_nodes");
  6710. undo_redo->add_undo_method(editor, "_update_nodes");
  6711. undo_redo->add_do_method(editor, "_update_graph");
  6712. undo_redo->add_undo_method(editor, "_update_graph");
  6713. undo_redo->commit_action();
  6714. }
  6715. void EditorPropertyVisualShaderMode::update_property() {
  6716. int which = get_edited_property_value();
  6717. options->select(which);
  6718. }
  6719. void EditorPropertyVisualShaderMode::setup(const Vector<String> &p_options) {
  6720. for (int i = 0; i < p_options.size(); i++) {
  6721. options->add_item(p_options[i], i);
  6722. }
  6723. }
  6724. void EditorPropertyVisualShaderMode::set_option_button_clip(bool p_enable) {
  6725. options->set_clip_text(p_enable);
  6726. }
  6727. EditorPropertyVisualShaderMode::EditorPropertyVisualShaderMode() {
  6728. options = memnew(OptionButton);
  6729. options->set_clip_text(true);
  6730. add_child(options);
  6731. add_focusable(options);
  6732. options->connect(SceneStringName(item_selected), callable_mp(this, &EditorPropertyVisualShaderMode::_option_selected));
  6733. }
  6734. bool EditorInspectorVisualShaderModePlugin::can_handle(Object *p_object) {
  6735. return true; // Can handle everything.
  6736. }
  6737. 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) {
  6738. if (p_path == "mode" && p_object->is_class("VisualShader") && p_type == Variant::INT) {
  6739. EditorPropertyVisualShaderMode *mode_editor = memnew(EditorPropertyVisualShaderMode);
  6740. Vector<String> options = p_hint_text.split(",");
  6741. mode_editor->setup(options);
  6742. add_property_editor(p_path, mode_editor);
  6743. return true;
  6744. }
  6745. return false;
  6746. }
  6747. //////////////////////////////////
  6748. void VisualShaderNodePortPreview::_shader_changed() {
  6749. if (!is_valid || shader.is_null()) {
  6750. return;
  6751. }
  6752. Vector<VisualShader::DefaultTextureParam> default_textures;
  6753. String shader_code = shader->generate_preview_shader(type, node, port, default_textures);
  6754. Ref<Shader> preview_shader;
  6755. preview_shader.instantiate();
  6756. preview_shader->set_code(shader_code);
  6757. for (int i = 0; i < default_textures.size(); i++) {
  6758. int j = 0;
  6759. for (List<Ref<Texture>>::ConstIterator itr = default_textures[i].params.begin(); itr != default_textures[i].params.end(); ++itr, ++j) {
  6760. preview_shader->set_default_texture_parameter(default_textures[i].name, *itr, j);
  6761. }
  6762. }
  6763. Ref<ShaderMaterial> mat;
  6764. mat.instantiate();
  6765. mat->set_shader(preview_shader);
  6766. if (preview_mat.is_valid() && preview_mat->get_shader().is_valid()) {
  6767. List<PropertyInfo> params;
  6768. preview_mat->get_shader()->get_shader_uniform_list(&params);
  6769. for (const PropertyInfo &E : params) {
  6770. mat->set_shader_parameter(E.name, preview_mat->get_shader_parameter(E.name));
  6771. }
  6772. }
  6773. set_material(mat);
  6774. }
  6775. void VisualShaderNodePortPreview::setup(const Ref<VisualShader> &p_shader, Ref<ShaderMaterial> &p_preview_material, VisualShader::Type p_type, int p_node, int p_port, bool p_is_valid) {
  6776. shader = p_shader;
  6777. shader->connect_changed(callable_mp(this, &VisualShaderNodePortPreview::_shader_changed), CONNECT_DEFERRED);
  6778. preview_mat = p_preview_material;
  6779. type = p_type;
  6780. port = p_port;
  6781. node = p_node;
  6782. is_valid = p_is_valid;
  6783. queue_redraw();
  6784. _shader_changed();
  6785. }
  6786. Size2 VisualShaderNodePortPreview::get_minimum_size() const {
  6787. int port_preview_size = EDITOR_GET("editors/visual_editors/visual_shader/port_preview_size");
  6788. return Size2(port_preview_size, port_preview_size) * EDSCALE;
  6789. }
  6790. void VisualShaderNodePortPreview::_notification(int p_what) {
  6791. switch (p_what) {
  6792. case NOTIFICATION_DRAW: {
  6793. Vector<Vector2> points = {
  6794. Vector2(),
  6795. Vector2(get_size().width, 0),
  6796. get_size(),
  6797. Vector2(0, get_size().height)
  6798. };
  6799. Vector<Vector2> uvs = {
  6800. Vector2(0, 0),
  6801. Vector2(1, 0),
  6802. Vector2(1, 1),
  6803. Vector2(0, 1)
  6804. };
  6805. if (is_valid) {
  6806. Vector<Color> colors = {
  6807. Color(1, 1, 1, 1),
  6808. Color(1, 1, 1, 1),
  6809. Color(1, 1, 1, 1),
  6810. Color(1, 1, 1, 1)
  6811. };
  6812. draw_primitive(points, colors, uvs);
  6813. } else {
  6814. Vector<Color> colors = {
  6815. Color(0, 0, 0, 1),
  6816. Color(0, 0, 0, 1),
  6817. Color(0, 0, 0, 1),
  6818. Color(0, 0, 0, 1)
  6819. };
  6820. draw_primitive(points, colors, uvs);
  6821. }
  6822. } break;
  6823. }
  6824. }
  6825. //////////////////////////////////
  6826. String VisualShaderConversionPlugin::converts_to() const {
  6827. return "Shader";
  6828. }
  6829. bool VisualShaderConversionPlugin::handles(const Ref<Resource> &p_resource) const {
  6830. Ref<VisualShader> vshader = p_resource;
  6831. return vshader.is_valid();
  6832. }
  6833. Ref<Resource> VisualShaderConversionPlugin::convert(const Ref<Resource> &p_resource) const {
  6834. Ref<VisualShader> vshader = p_resource;
  6835. ERR_FAIL_COND_V(!vshader.is_valid(), Ref<Resource>());
  6836. Ref<Shader> shader;
  6837. shader.instantiate();
  6838. String code = vshader->get_code();
  6839. shader->set_code(code);
  6840. return shader;
  6841. }