12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507 |
- /**************************************************************************/
- /* visual_shader_nodes.cpp */
- /**************************************************************************/
- /* This file is part of: */
- /* GODOT ENGINE */
- /* https://godotengine.org */
- /**************************************************************************/
- /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
- /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
- /* */
- /* Permission is hereby granted, free of charge, to any person obtaining */
- /* a copy of this software and associated documentation files (the */
- /* "Software"), to deal in the Software without restriction, including */
- /* without limitation the rights to use, copy, modify, merge, publish, */
- /* distribute, sublicense, and/or sell copies of the Software, and to */
- /* permit persons to whom the Software is furnished to do so, subject to */
- /* the following conditions: */
- /* */
- /* The above copyright notice and this permission notice shall be */
- /* included in all copies or substantial portions of the Software. */
- /* */
- /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
- /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
- /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
- /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
- /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
- /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
- /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
- /**************************************************************************/
- #include "visual_shader_nodes.h"
- #include "visual_shader_nodes.compat.inc"
- #include "scene/resources/image_texture.h"
- ////////////// Vector Base
- VisualShaderNodeVectorBase::PortType VisualShaderNodeVectorBase::get_input_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_4D:
- return PORT_TYPE_VECTOR_4D;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- VisualShaderNodeVectorBase::PortType VisualShaderNodeVectorBase::get_output_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return p_port == 0 || get_output_port_count() > 1 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_3D:
- return p_port == 0 || get_output_port_count() > 1 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_4D:
- return p_port == 0 || get_output_port_count() > 1 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- void VisualShaderNodeVectorBase::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- op_type = p_op_type;
- emit_changed();
- }
- VisualShaderNodeVectorBase::OpType VisualShaderNodeVectorBase::get_op_type() const {
- return op_type;
- }
- void VisualShaderNodeVectorBase::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_op_type", "type"), &VisualShaderNodeVectorBase::set_op_type);
- ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeVectorBase::get_op_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Vector2,Vector3,Vector4"), "set_op_type", "get_op_type");
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D);
- BIND_ENUM_CONSTANT(OP_TYPE_MAX);
- }
- Vector<StringName> VisualShaderNodeVectorBase::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("op_type");
- return props;
- }
- VisualShaderNodeVectorBase::VisualShaderNodeVectorBase() {
- }
- ////////////// Constants Base
- VisualShaderNodeConstant::VisualShaderNodeConstant() {
- }
- ////////////// Scalar(Float)
- String VisualShaderNodeFloatConstant::get_caption() const {
- return "FloatConstant";
- }
- int VisualShaderNodeFloatConstant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeFloatConstant::PortType VisualShaderNodeFloatConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeFloatConstant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeFloatConstant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeFloatConstant::PortType VisualShaderNodeFloatConstant::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeFloatConstant::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeFloatConstant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + vformat("%.6f", constant) + ";\n";
- }
- void VisualShaderNodeFloatConstant::set_constant(float p_constant) {
- if (Math::is_equal_approx(constant, p_constant)) {
- return;
- }
- constant = p_constant;
- emit_changed();
- }
- float VisualShaderNodeFloatConstant::get_constant() const {
- return constant;
- }
- Vector<StringName> VisualShaderNodeFloatConstant::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("constant");
- return props;
- }
- void VisualShaderNodeFloatConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant", "constant"), &VisualShaderNodeFloatConstant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeFloatConstant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeFloatConstant::VisualShaderNodeFloatConstant() {
- }
- ////////////// Scalar(Int)
- String VisualShaderNodeIntConstant::get_caption() const {
- return "IntConstant";
- }
- int VisualShaderNodeIntConstant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeIntConstant::PortType VisualShaderNodeIntConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_INT;
- }
- String VisualShaderNodeIntConstant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeIntConstant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeIntConstant::PortType VisualShaderNodeIntConstant::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_INT;
- }
- String VisualShaderNodeIntConstant::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeIntConstant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + itos(constant) + ";\n";
- }
- void VisualShaderNodeIntConstant::set_constant(int p_constant) {
- if (constant == p_constant) {
- return;
- }
- constant = p_constant;
- emit_changed();
- }
- int VisualShaderNodeIntConstant::get_constant() const {
- return constant;
- }
- Vector<StringName> VisualShaderNodeIntConstant::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("constant");
- return props;
- }
- void VisualShaderNodeIntConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant", "constant"), &VisualShaderNodeIntConstant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeIntConstant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeIntConstant::VisualShaderNodeIntConstant() {
- }
- ////////////// Scalar(UInt)
- String VisualShaderNodeUIntConstant::get_caption() const {
- return "UIntConstant";
- }
- int VisualShaderNodeUIntConstant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeUIntConstant::PortType VisualShaderNodeUIntConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_UINT;
- }
- String VisualShaderNodeUIntConstant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeUIntConstant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeUIntConstant::PortType VisualShaderNodeUIntConstant::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_UINT;
- }
- String VisualShaderNodeUIntConstant::get_output_port_name(int p_port) const {
- return ""; // No output port means the editor will be used as port.
- }
- String VisualShaderNodeUIntConstant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + itos(constant) + "u;\n";
- }
- void VisualShaderNodeUIntConstant::set_constant(int p_constant) {
- if (constant == p_constant) {
- return;
- }
- constant = p_constant;
- emit_changed();
- }
- int VisualShaderNodeUIntConstant::get_constant() const {
- return constant;
- }
- Vector<StringName> VisualShaderNodeUIntConstant::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("constant");
- return props;
- }
- void VisualShaderNodeUIntConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant", "constant"), &VisualShaderNodeUIntConstant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeUIntConstant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeUIntConstant::VisualShaderNodeUIntConstant() {
- }
- ////////////// Boolean
- String VisualShaderNodeBooleanConstant::get_caption() const {
- return "BooleanConstant";
- }
- int VisualShaderNodeBooleanConstant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeBooleanConstant::PortType VisualShaderNodeBooleanConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_BOOLEAN;
- }
- String VisualShaderNodeBooleanConstant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeBooleanConstant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeBooleanConstant::PortType VisualShaderNodeBooleanConstant::get_output_port_type(int p_port) const {
- return PORT_TYPE_BOOLEAN;
- }
- String VisualShaderNodeBooleanConstant::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeBooleanConstant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + (constant ? "true" : "false") + ";\n";
- }
- void VisualShaderNodeBooleanConstant::set_constant(bool p_constant) {
- if (constant == p_constant) {
- return;
- }
- constant = p_constant;
- emit_changed();
- }
- bool VisualShaderNodeBooleanConstant::get_constant() const {
- return constant;
- }
- Vector<StringName> VisualShaderNodeBooleanConstant::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("constant");
- return props;
- }
- void VisualShaderNodeBooleanConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant", "constant"), &VisualShaderNodeBooleanConstant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeBooleanConstant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeBooleanConstant::VisualShaderNodeBooleanConstant() {
- }
- ////////////// Color
- String VisualShaderNodeColorConstant::get_caption() const {
- return "ColorConstant";
- }
- int VisualShaderNodeColorConstant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeColorConstant::PortType VisualShaderNodeColorConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_4D;
- }
- String VisualShaderNodeColorConstant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeColorConstant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeColorConstant::PortType VisualShaderNodeColorConstant::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeColorConstant::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeColorConstant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + vformat("vec4(%.6f, %.6f, %.6f, %.6f)", constant.r, constant.g, constant.b, constant.a) + ";\n";
- }
- void VisualShaderNodeColorConstant::set_constant(const Color &p_constant) {
- if (constant.is_equal_approx(p_constant)) {
- return;
- }
- constant = p_constant;
- emit_changed();
- }
- Color VisualShaderNodeColorConstant::get_constant() const {
- return constant;
- }
- Vector<StringName> VisualShaderNodeColorConstant::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("constant");
- return props;
- }
- void VisualShaderNodeColorConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant", "constant"), &VisualShaderNodeColorConstant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeColorConstant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::COLOR, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeColorConstant::VisualShaderNodeColorConstant() {
- }
- ////////////// Vector2
- String VisualShaderNodeVec2Constant::get_caption() const {
- return "Vector2Constant";
- }
- int VisualShaderNodeVec2Constant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeVec2Constant::PortType VisualShaderNodeVec2Constant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_2D;
- }
- String VisualShaderNodeVec2Constant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeVec2Constant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVec2Constant::PortType VisualShaderNodeVec2Constant::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeVec2Constant::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeVec2Constant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + vformat("vec2(%.6f, %.6f)", constant.x, constant.y) + ";\n";
- }
- void VisualShaderNodeVec2Constant::set_constant(const Vector2 &p_constant) {
- if (constant.is_equal_approx(p_constant)) {
- return;
- }
- constant = p_constant;
- emit_changed();
- }
- Vector2 VisualShaderNodeVec2Constant::get_constant() const {
- return constant;
- }
- Vector<StringName> VisualShaderNodeVec2Constant::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("constant");
- return props;
- }
- void VisualShaderNodeVec2Constant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant", "constant"), &VisualShaderNodeVec2Constant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeVec2Constant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeVec2Constant::VisualShaderNodeVec2Constant() {
- }
- ////////////// Vector3
- String VisualShaderNodeVec3Constant::get_caption() const {
- return "Vector3Constant";
- }
- int VisualShaderNodeVec3Constant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeVec3Constant::PortType VisualShaderNodeVec3Constant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeVec3Constant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeVec3Constant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVec3Constant::PortType VisualShaderNodeVec3Constant::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeVec3Constant::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeVec3Constant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.x, constant.y, constant.z) + ";\n";
- }
- void VisualShaderNodeVec3Constant::set_constant(const Vector3 &p_constant) {
- if (constant.is_equal_approx(p_constant)) {
- return;
- }
- constant = p_constant;
- emit_changed();
- }
- Vector3 VisualShaderNodeVec3Constant::get_constant() const {
- return constant;
- }
- Vector<StringName> VisualShaderNodeVec3Constant::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("constant");
- return props;
- }
- void VisualShaderNodeVec3Constant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant", "constant"), &VisualShaderNodeVec3Constant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeVec3Constant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeVec3Constant::VisualShaderNodeVec3Constant() {
- }
- ////////////// Vector4
- String VisualShaderNodeVec4Constant::get_caption() const {
- return "Vector4Constant";
- }
- int VisualShaderNodeVec4Constant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeVec4Constant::PortType VisualShaderNodeVec4Constant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_4D;
- }
- String VisualShaderNodeVec4Constant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeVec4Constant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVec4Constant::PortType VisualShaderNodeVec4Constant::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeVec4Constant::get_output_port_name(int p_port) const {
- return ""; // No output port means the editor will be used as port.
- }
- String VisualShaderNodeVec4Constant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + vformat("vec4(%.6f, %.6f, %.6f, %.6f)", constant.x, constant.y, constant.z, constant.w) + ";\n";
- }
- void VisualShaderNodeVec4Constant::set_constant(const Quaternion &p_constant) {
- if (constant.is_equal_approx(p_constant)) {
- return;
- }
- constant = p_constant;
- emit_changed();
- }
- Quaternion VisualShaderNodeVec4Constant::get_constant() const {
- return constant;
- }
- Vector<StringName> VisualShaderNodeVec4Constant::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("constant");
- return props;
- }
- void VisualShaderNodeVec4Constant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant", "constant"), &VisualShaderNodeVec4Constant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeVec4Constant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::QUATERNION, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeVec4Constant::VisualShaderNodeVec4Constant() {
- }
- ////////////// Transform3D
- String VisualShaderNodeTransformConstant::get_caption() const {
- return "TransformConstant";
- }
- int VisualShaderNodeTransformConstant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeTransformConstant::PortType VisualShaderNodeTransformConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeTransformConstant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeTransformConstant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeTransformConstant::PortType VisualShaderNodeTransformConstant::get_output_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformConstant::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeTransformConstant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- Transform3D t = constant;
- t.basis.transpose();
- String code = " " + p_output_vars[0] + " = mat4(";
- code += vformat("vec4(%.6f, %.6f, %.6f, 0.0), ", t.basis[0].x, t.basis[0].y, t.basis[0].z);
- code += vformat("vec4(%.6f, %.6f, %.6f, 0.0), ", t.basis[1].x, t.basis[1].y, t.basis[1].z);
- code += vformat("vec4(%.6f, %.6f, %.6f, 0.0), ", t.basis[2].x, t.basis[2].y, t.basis[2].z);
- code += vformat("vec4(%.6f, %.6f, %.6f, 1.0));\n", t.origin.x, t.origin.y, t.origin.z);
- return code;
- }
- void VisualShaderNodeTransformConstant::set_constant(const Transform3D &p_constant) {
- if (constant.is_equal_approx(p_constant)) {
- return;
- }
- constant = p_constant;
- emit_changed();
- }
- Transform3D VisualShaderNodeTransformConstant::get_constant() const {
- return constant;
- }
- Vector<StringName> VisualShaderNodeTransformConstant::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("constant");
- return props;
- }
- void VisualShaderNodeTransformConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant", "constant"), &VisualShaderNodeTransformConstant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeTransformConstant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeTransformConstant::VisualShaderNodeTransformConstant() {
- }
- ////////////// Texture
- String VisualShaderNodeTexture::get_caption() const {
- return "Texture2D";
- }
- int VisualShaderNodeTexture::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeTexture::PortType VisualShaderNodeTexture::get_input_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR_2D;
- case 1:
- return PORT_TYPE_SCALAR;
- case 2:
- return PORT_TYPE_SAMPLER;
- default:
- return PORT_TYPE_SCALAR;
- }
- }
- String VisualShaderNodeTexture::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "uv";
- case 1:
- return "lod";
- case 2:
- return "sampler2D";
- default:
- return "";
- }
- }
- int VisualShaderNodeTexture::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeTexture::PortType VisualShaderNodeTexture::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeTexture::get_output_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "color";
- default:
- return "";
- }
- }
- bool VisualShaderNodeTexture::is_input_port_default(int p_port, Shader::Mode p_mode) const {
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- if (p_port == 0) {
- return true;
- }
- }
- return false;
- }
- Vector<VisualShader::DefaultTextureParam> VisualShaderNodeTexture::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
- VisualShader::DefaultTextureParam dtp;
- dtp.name = make_unique_id(p_type, p_id, "tex");
- dtp.params.push_back(texture);
- Vector<VisualShader::DefaultTextureParam> ret;
- ret.push_back(dtp);
- return ret;
- }
- String VisualShaderNodeTexture::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code;
- switch (source) {
- case SOURCE_TEXTURE: {
- code += "uniform sampler2D " + make_unique_id(p_type, p_id, "tex");
- switch (texture_type) {
- case TYPE_DATA: {
- } break;
- case TYPE_COLOR: {
- code += " : source_color";
- } break;
- case TYPE_NORMAL_MAP: {
- code += " : hint_normal";
- } break;
- default: {
- } break;
- }
- code += ";\n";
- } break;
- case SOURCE_SCREEN: {
- if ((p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) {
- code += "uniform sampler2D " + make_unique_id(p_type, p_id, "screen_tex") + " : hint_screen_texture;\n";
- }
- } break;
- case SOURCE_DEPTH:
- case SOURCE_3D_NORMAL:
- case SOURCE_ROUGHNESS: {
- if (p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) {
- String sampler_name = "";
- String hint = " : ";
- if (source == SOURCE_DEPTH) {
- sampler_name = "depth_tex";
- hint += "hint_depth_texture;\n";
- } else {
- sampler_name = source == SOURCE_ROUGHNESS ? "roughness_tex" : "normal_roughness_tex";
- hint += "hint_normal_roughness_texture;\n";
- }
- code += "uniform sampler2D " + make_unique_id(p_type, p_id, sampler_name) + hint;
- }
- } break;
- default: {
- } break;
- }
- return code;
- }
- String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String default_uv;
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- if (source == SOURCE_SCREEN) {
- default_uv = "SCREEN_UV";
- } else {
- default_uv = "UV";
- }
- } else {
- default_uv = "vec2(0.0)";
- }
- String code;
- String uv = p_input_vars[0].is_empty() ? default_uv : p_input_vars[0];
- switch (source) {
- case SOURCE_PORT:
- case SOURCE_TEXTURE: {
- String id;
- if (source == SOURCE_PORT) {
- id = p_input_vars[2];
- if (id.is_empty()) {
- break;
- }
- } else { // SOURCE_TEXTURE
- id = make_unique_id(p_type, p_id, "tex");
- }
- if (p_input_vars[1].is_empty()) {
- code += " " + p_output_vars[0] + " = texture(" + id + ", " + uv + ");\n";
- } else {
- code += " " + p_output_vars[0] + " = textureLod(" + id + ", " + uv + ", " + p_input_vars[1] + ");\n";
- }
- return code;
- } break;
- case SOURCE_SCREEN: {
- if ((p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) {
- String id = make_unique_id(p_type, p_id, "screen_tex");
- if (p_input_vars[1].is_empty()) {
- code += " " + p_output_vars[0] + " = texture(" + id + ", " + uv + ");\n";
- } else {
- code += " " + p_output_vars[0] + " = textureLod(" + id + ", " + uv + ", " + p_input_vars[1] + ");\n";
- }
- return code;
- }
- } break;
- case SOURCE_2D_NORMAL:
- case SOURCE_2D_TEXTURE: {
- if (p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) {
- String id = source == SOURCE_2D_TEXTURE ? "TEXTURE" : "NORMAL_TEXTURE";
- if (p_input_vars[1].is_empty()) {
- code += " " + p_output_vars[0] + " = texture(" + id + ", " + uv + ");\n";
- } else {
- code += " " + p_output_vars[0] + " = textureLod(" + id + ", " + uv + ", " + p_input_vars[1] + ");\n";
- }
- return code;
- }
- } break;
- case SOURCE_3D_NORMAL:
- case SOURCE_ROUGHNESS:
- case SOURCE_DEPTH: {
- if (!p_for_preview && p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) {
- String var_name = "";
- String sampler_name = "";
- switch (source) {
- case SOURCE_DEPTH: {
- var_name = "_depth";
- sampler_name = "depth_tex";
- } break;
- case SOURCE_ROUGHNESS: {
- var_name = "_roughness";
- sampler_name = "roughness_tex";
- } break;
- case SOURCE_3D_NORMAL: {
- var_name = "_normal";
- sampler_name = "normal_roughness_tex";
- } break;
- default: {
- } break;
- }
- String id = make_unique_id(p_type, p_id, sampler_name);
- String type = source == SOURCE_3D_NORMAL ? "vec3" : "float";
- String components = source == SOURCE_3D_NORMAL ? "rgb" : "r";
- code += " {\n";
- if (p_input_vars[1].is_empty()) {
- code += " " + type + " " + var_name + " = texture(" + id + ", " + uv + ")." + components + ";\n";
- } else {
- code += " " + type + " " + var_name + " = textureLod(" + id + ", " + uv + ", " + p_input_vars[1] + ")." + components + ";\n";
- }
- if (source == SOURCE_3D_NORMAL) {
- code += " " + p_output_vars[0] + " = vec4(" + var_name + ", 1.0);\n";
- } else {
- code += " " + p_output_vars[0] + " = vec4(" + var_name + ", " + var_name + ", " + var_name + ", 1.0);\n";
- }
- code += " }\n";
- return code;
- }
- } break;
- default: {
- } break;
- }
- code += " " + p_output_vars[0] + " = vec4(0.0);\n";
- return code;
- }
- void VisualShaderNodeTexture::set_source(Source p_source) {
- ERR_FAIL_INDEX(int(p_source), int(SOURCE_MAX));
- if (source == p_source) {
- return;
- }
- switch (p_source) {
- case SOURCE_TEXTURE:
- simple_decl = true;
- break;
- case SOURCE_SCREEN:
- simple_decl = false;
- break;
- case SOURCE_2D_TEXTURE:
- simple_decl = false;
- break;
- case SOURCE_2D_NORMAL:
- simple_decl = false;
- break;
- case SOURCE_DEPTH:
- simple_decl = false;
- break;
- case SOURCE_PORT:
- simple_decl = false;
- break;
- case SOURCE_3D_NORMAL:
- simple_decl = false;
- break;
- case SOURCE_ROUGHNESS:
- simple_decl = false;
- break;
- default:
- break;
- }
- source = p_source;
- emit_changed();
- }
- VisualShaderNodeTexture::Source VisualShaderNodeTexture::get_source() const {
- return source;
- }
- void VisualShaderNodeTexture::set_texture(Ref<Texture2D> p_texture) {
- texture = p_texture;
- emit_changed();
- }
- Ref<Texture2D> VisualShaderNodeTexture::get_texture() const {
- return texture;
- }
- void VisualShaderNodeTexture::set_texture_type(TextureType p_texture_type) {
- ERR_FAIL_INDEX(int(p_texture_type), int(TYPE_MAX));
- if (texture_type == p_texture_type) {
- return;
- }
- texture_type = p_texture_type;
- emit_changed();
- }
- VisualShaderNodeTexture::TextureType VisualShaderNodeTexture::get_texture_type() const {
- return texture_type;
- }
- Vector<StringName> VisualShaderNodeTexture::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("source");
- if (source == SOURCE_TEXTURE) {
- props.push_back("texture");
- props.push_back("texture_type");
- }
- return props;
- }
- String VisualShaderNodeTexture::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const {
- if (is_input_port_connected(2) && source != SOURCE_PORT) {
- return RTR("The sampler port is connected but not used. Consider changing the source to 'SamplerPort'.");
- }
- switch (source) {
- case SOURCE_TEXTURE:
- case SOURCE_PORT: {
- return String(); // All good.
- } break;
- case SOURCE_SCREEN: {
- if ((p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) {
- return String(); // All good.
- }
- } break;
- case SOURCE_2D_NORMAL:
- case SOURCE_2D_TEXTURE: {
- if (p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) {
- return String(); // All good.
- }
- } break;
- case SOURCE_3D_NORMAL:
- case SOURCE_ROUGHNESS:
- case SOURCE_DEPTH: {
- if (p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) {
- if (get_output_port_for_preview() == 0) { // Not supported in preview(canvas_item) shader.
- return RTR("Invalid source for preview.");
- }
- return String(); // All good.
- }
- } break;
- default: {
- } break;
- }
- return RTR("Invalid source for shader.");
- }
- void VisualShaderNodeTexture::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_source", "value"), &VisualShaderNodeTexture::set_source);
- ClassDB::bind_method(D_METHOD("get_source"), &VisualShaderNodeTexture::get_source);
- ClassDB::bind_method(D_METHOD("set_texture", "value"), &VisualShaderNodeTexture::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture"), &VisualShaderNodeTexture::get_texture);
- ClassDB::bind_method(D_METHOD("set_texture_type", "value"), &VisualShaderNodeTexture::set_texture_type);
- ClassDB::bind_method(D_METHOD("get_texture_type"), &VisualShaderNodeTexture::get_texture_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "source", PROPERTY_HINT_ENUM, "Texture,Screen,Texture2D,NormalMap2D,Depth,SamplerPort,Normal3D,Roughness"), "set_source", "get_source");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_type", PROPERTY_HINT_ENUM, "Data,Color,Normal Map"), "set_texture_type", "get_texture_type");
- BIND_ENUM_CONSTANT(SOURCE_TEXTURE);
- BIND_ENUM_CONSTANT(SOURCE_SCREEN);
- BIND_ENUM_CONSTANT(SOURCE_2D_TEXTURE);
- BIND_ENUM_CONSTANT(SOURCE_2D_NORMAL);
- BIND_ENUM_CONSTANT(SOURCE_DEPTH);
- BIND_ENUM_CONSTANT(SOURCE_PORT);
- BIND_ENUM_CONSTANT(SOURCE_3D_NORMAL);
- BIND_ENUM_CONSTANT(SOURCE_ROUGHNESS);
- BIND_ENUM_CONSTANT(SOURCE_MAX);
- BIND_ENUM_CONSTANT(TYPE_DATA);
- BIND_ENUM_CONSTANT(TYPE_COLOR);
- BIND_ENUM_CONSTANT(TYPE_NORMAL_MAP);
- BIND_ENUM_CONSTANT(TYPE_MAX);
- }
- VisualShaderNodeTexture::VisualShaderNodeTexture() {
- }
- ////////////// CurveTexture
- String VisualShaderNodeCurveTexture::get_caption() const {
- return "CurveTexture";
- }
- int VisualShaderNodeCurveTexture::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeCurveTexture::PortType VisualShaderNodeCurveTexture::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeCurveTexture::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeCurveTexture::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeCurveTexture::PortType VisualShaderNodeCurveTexture::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeCurveTexture::get_output_port_name(int p_port) const {
- return String();
- }
- void VisualShaderNodeCurveTexture::set_texture(Ref<CurveTexture> p_texture) {
- texture = p_texture;
- emit_changed();
- }
- Ref<CurveTexture> VisualShaderNodeCurveTexture::get_texture() const {
- return texture;
- }
- Vector<StringName> VisualShaderNodeCurveTexture::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("texture");
- return props;
- }
- String VisualShaderNodeCurveTexture::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- return "uniform sampler2D " + make_unique_id(p_type, p_id, "curve") + " : repeat_disable;\n";
- }
- String VisualShaderNodeCurveTexture::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- if (p_input_vars[0].is_empty()) {
- return " " + p_output_vars[0] + " = 0.0;\n";
- }
- String id = make_unique_id(p_type, p_id, "curve");
- String code;
- code += " " + p_output_vars[0] + " = texture(" + id + ", vec2(" + p_input_vars[0] + ")).r;\n";
- return code;
- }
- Vector<VisualShader::DefaultTextureParam> VisualShaderNodeCurveTexture::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
- VisualShader::DefaultTextureParam dtp;
- dtp.name = make_unique_id(p_type, p_id, "curve");
- dtp.params.push_back(texture);
- Vector<VisualShader::DefaultTextureParam> ret;
- ret.push_back(dtp);
- return ret;
- }
- void VisualShaderNodeCurveTexture::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_texture", "texture"), &VisualShaderNodeCurveTexture::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture"), &VisualShaderNodeCurveTexture::get_texture);
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_texture", "get_texture");
- }
- bool VisualShaderNodeCurveTexture::is_use_prop_slots() const {
- return true;
- }
- VisualShaderNodeCurveTexture::VisualShaderNodeCurveTexture() {
- set_input_port_default_value(0, 0.0);
- simple_decl = true;
- allow_v_resize = false;
- }
- ////////////// CurveXYZTexture
- String VisualShaderNodeCurveXYZTexture::get_caption() const {
- return "CurveXYZTexture";
- }
- int VisualShaderNodeCurveXYZTexture::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeCurveXYZTexture::PortType VisualShaderNodeCurveXYZTexture::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeCurveXYZTexture::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeCurveXYZTexture::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeCurveXYZTexture::PortType VisualShaderNodeCurveXYZTexture::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeCurveXYZTexture::get_output_port_name(int p_port) const {
- return String();
- }
- void VisualShaderNodeCurveXYZTexture::set_texture(Ref<CurveXYZTexture> p_texture) {
- texture = p_texture;
- emit_changed();
- }
- Ref<CurveXYZTexture> VisualShaderNodeCurveXYZTexture::get_texture() const {
- return texture;
- }
- Vector<StringName> VisualShaderNodeCurveXYZTexture::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("texture");
- return props;
- }
- String VisualShaderNodeCurveXYZTexture::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- return "uniform sampler2D " + make_unique_id(p_type, p_id, "curve3d") + ";\n";
- }
- String VisualShaderNodeCurveXYZTexture::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- if (p_input_vars[0].is_empty()) {
- return " " + p_output_vars[0] + " = vec3(0.0);\n";
- }
- String id = make_unique_id(p_type, p_id, "curve3d");
- String code;
- code += " " + p_output_vars[0] + " = texture(" + id + ", vec2(" + p_input_vars[0] + ")).rgb;\n";
- return code;
- }
- Vector<VisualShader::DefaultTextureParam> VisualShaderNodeCurveXYZTexture::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
- VisualShader::DefaultTextureParam dtp;
- dtp.name = make_unique_id(p_type, p_id, "curve3d");
- dtp.params.push_back(texture);
- Vector<VisualShader::DefaultTextureParam> ret;
- ret.push_back(dtp);
- return ret;
- }
- void VisualShaderNodeCurveXYZTexture::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_texture", "texture"), &VisualShaderNodeCurveXYZTexture::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture"), &VisualShaderNodeCurveXYZTexture::get_texture);
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "CurveXYZTexture"), "set_texture", "get_texture");
- }
- bool VisualShaderNodeCurveXYZTexture::is_use_prop_slots() const {
- return true;
- }
- VisualShaderNodeCurveXYZTexture::VisualShaderNodeCurveXYZTexture() {
- set_input_port_default_value(0, 0.0);
- simple_decl = true;
- allow_v_resize = false;
- }
- ////////////// Sample3D
- int VisualShaderNodeSample3D::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeSample3D::PortType VisualShaderNodeSample3D::get_input_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR_3D;
- case 1:
- return PORT_TYPE_SCALAR;
- case 2:
- return PORT_TYPE_SAMPLER;
- default:
- return PORT_TYPE_SCALAR;
- }
- }
- String VisualShaderNodeSample3D::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "uvw";
- case 1:
- return "lod";
- default:
- return "";
- }
- }
- int VisualShaderNodeSample3D::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeSample3D::PortType VisualShaderNodeSample3D::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeSample3D::get_output_port_name(int p_port) const {
- return "color";
- }
- bool VisualShaderNodeSample3D::is_input_port_default(int p_port, Shader::Mode p_mode) const {
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- if (p_port == 0) {
- return true;
- }
- }
- return false;
- }
- String VisualShaderNodeSample3D::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- String id;
- if (source == SOURCE_TEXTURE) {
- id = make_unique_id(p_type, p_id, "tex3d");
- } else { // SOURCE_PORT
- id = p_input_vars[2];
- if (id.is_empty()) {
- code += " " + p_output_vars[0] + " = vec4(0.0);\n";
- return code;
- }
- }
- String default_uv;
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- default_uv = "vec3(UV, 0.0)";
- } else {
- default_uv = "vec3(0.0)";
- }
- String uv = p_input_vars[0].is_empty() ? default_uv : p_input_vars[0];
- if (p_input_vars[1].is_empty()) {
- code += " " + p_output_vars[0] + " = texture(" + id + ", " + uv + ");\n";
- } else {
- code += " " + p_output_vars[0] + " = textureLod(" + id + ", " + uv + ", " + p_input_vars[1] + ");\n";
- }
- return code;
- }
- void VisualShaderNodeSample3D::set_source(Source p_source) {
- ERR_FAIL_INDEX(int(p_source), int(SOURCE_MAX));
- if (source == p_source) {
- return;
- }
- source = p_source;
- emit_changed();
- }
- VisualShaderNodeSample3D::Source VisualShaderNodeSample3D::get_source() const {
- return source;
- }
- void VisualShaderNodeSample3D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_source", "value"), &VisualShaderNodeSample3D::set_source);
- ClassDB::bind_method(D_METHOD("get_source"), &VisualShaderNodeSample3D::get_source);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "source", PROPERTY_HINT_ENUM, "Texture,SamplerPort"), "set_source", "get_source");
- BIND_ENUM_CONSTANT(SOURCE_TEXTURE);
- BIND_ENUM_CONSTANT(SOURCE_PORT);
- BIND_ENUM_CONSTANT(SOURCE_MAX);
- }
- String VisualShaderNodeSample3D::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const {
- if (is_input_port_connected(2) && source != SOURCE_PORT) {
- return RTR("The sampler port is connected but not used. Consider changing the source to 'SamplerPort'.");
- }
- return String();
- }
- VisualShaderNodeSample3D::VisualShaderNodeSample3D() {
- simple_decl = false;
- }
- ////////////// Texture2DArray
- String VisualShaderNodeTexture2DArray::get_caption() const {
- return "Texture2DArray";
- }
- String VisualShaderNodeTexture2DArray::get_input_port_name(int p_port) const {
- if (p_port == 2) {
- return "sampler2DArray";
- }
- return VisualShaderNodeSample3D::get_input_port_name(p_port);
- }
- Vector<VisualShader::DefaultTextureParam> VisualShaderNodeTexture2DArray::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
- VisualShader::DefaultTextureParam dtp;
- dtp.name = make_unique_id(p_type, p_id, "tex3d");
- dtp.params.push_back(texture_array);
- Vector<VisualShader::DefaultTextureParam> ret;
- ret.push_back(dtp);
- return ret;
- }
- String VisualShaderNodeTexture2DArray::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- if (source == SOURCE_TEXTURE) {
- return "uniform sampler2DArray " + make_unique_id(p_type, p_id, "tex3d") + ";\n";
- }
- return String();
- }
- void VisualShaderNodeTexture2DArray::set_texture_array(Ref<TextureLayered> p_texture_array) {
- texture_array = p_texture_array;
- emit_changed();
- }
- Ref<TextureLayered> VisualShaderNodeTexture2DArray::get_texture_array() const {
- return texture_array;
- }
- Vector<StringName> VisualShaderNodeTexture2DArray::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("source");
- if (source == SOURCE_TEXTURE) {
- props.push_back("texture_array");
- }
- return props;
- }
- void VisualShaderNodeTexture2DArray::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_texture_array", "value"), &VisualShaderNodeTexture2DArray::set_texture_array);
- ClassDB::bind_method(D_METHOD("get_texture_array"), &VisualShaderNodeTexture2DArray::get_texture_array);
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_array", PROPERTY_HINT_RESOURCE_TYPE, "Texture2DArray,CompressedTexture2DArray,PlaceholderTexture2DArray,Texture2DArrayRD"), "set_texture_array", "get_texture_array");
- }
- VisualShaderNodeTexture2DArray::VisualShaderNodeTexture2DArray() {
- }
- ////////////// Texture3D
- String VisualShaderNodeTexture3D::get_caption() const {
- return "Texture3D";
- }
- String VisualShaderNodeTexture3D::get_input_port_name(int p_port) const {
- if (p_port == 2) {
- return "sampler3D";
- }
- return VisualShaderNodeSample3D::get_input_port_name(p_port);
- }
- Vector<VisualShader::DefaultTextureParam> VisualShaderNodeTexture3D::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
- VisualShader::DefaultTextureParam dtp;
- dtp.name = make_unique_id(p_type, p_id, "tex3d");
- dtp.params.push_back(texture);
- Vector<VisualShader::DefaultTextureParam> ret;
- ret.push_back(dtp);
- return ret;
- }
- String VisualShaderNodeTexture3D::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- if (source == SOURCE_TEXTURE) {
- return "uniform sampler3D " + make_unique_id(p_type, p_id, "tex3d") + ";\n";
- }
- return String();
- }
- void VisualShaderNodeTexture3D::set_texture(Ref<Texture3D> p_texture) {
- texture = p_texture;
- emit_changed();
- }
- Ref<Texture3D> VisualShaderNodeTexture3D::get_texture() const {
- return texture;
- }
- Vector<StringName> VisualShaderNodeTexture3D::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("source");
- if (source == SOURCE_TEXTURE) {
- props.push_back("texture");
- }
- return props;
- }
- void VisualShaderNodeTexture3D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_texture", "value"), &VisualShaderNodeTexture3D::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture"), &VisualShaderNodeTexture3D::get_texture);
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture3D"), "set_texture", "get_texture");
- }
- VisualShaderNodeTexture3D::VisualShaderNodeTexture3D() {
- }
- ////////////// Cubemap
- String VisualShaderNodeCubemap::get_caption() const {
- return "Cubemap";
- }
- int VisualShaderNodeCubemap::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeCubemap::PortType VisualShaderNodeCubemap::get_input_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR_3D;
- case 1:
- return PORT_TYPE_SCALAR;
- case 2:
- return PORT_TYPE_SAMPLER;
- default:
- return PORT_TYPE_SCALAR;
- }
- }
- String VisualShaderNodeCubemap::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "uv";
- case 1:
- return "lod";
- case 2:
- return "samplerCube";
- default:
- return "";
- }
- }
- int VisualShaderNodeCubemap::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeCubemap::PortType VisualShaderNodeCubemap::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeCubemap::get_output_port_name(int p_port) const {
- return "color";
- }
- Vector<VisualShader::DefaultTextureParam> VisualShaderNodeCubemap::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
- VisualShader::DefaultTextureParam dtp;
- dtp.name = make_unique_id(p_type, p_id, "cube");
- dtp.params.push_back(cube_map);
- Vector<VisualShader::DefaultTextureParam> ret;
- ret.push_back(dtp);
- return ret;
- }
- String VisualShaderNodeCubemap::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- if (source == SOURCE_TEXTURE) {
- String u = "uniform samplerCube " + make_unique_id(p_type, p_id, "cube");
- switch (texture_type) {
- case TYPE_DATA:
- break;
- case TYPE_COLOR:
- u += " : source_color";
- break;
- case TYPE_NORMAL_MAP:
- u += " : hint_normal";
- break;
- default:
- break;
- }
- return u + ";\n";
- }
- return String();
- }
- String VisualShaderNodeCubemap::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- String id;
- if (source == SOURCE_TEXTURE) {
- id = make_unique_id(p_type, p_id, "cube");
- } else { // SOURCE_PORT
- id = p_input_vars[2];
- if (id.is_empty()) {
- code += " " + p_output_vars[0] + " = vec4(0.0);\n";
- return code;
- }
- }
- String default_uv;
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- default_uv = "vec3(UV, 0.0)";
- } else {
- default_uv = "vec3(0.0)";
- }
- String uv = p_input_vars[0].is_empty() ? default_uv : p_input_vars[0];
- if (p_input_vars[1].is_empty()) {
- code += " " + p_output_vars[0] + " = texture(" + id + ", " + uv + ");\n";
- } else {
- code += " " + p_output_vars[0] + " = textureLod(" + id + ", " + uv + ", " + p_input_vars[1] + ");\n";
- }
- return code;
- }
- bool VisualShaderNodeCubemap::is_input_port_default(int p_port, Shader::Mode p_mode) const {
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- if (p_port == 0) {
- return true;
- }
- }
- return false;
- }
- void VisualShaderNodeCubemap::set_source(Source p_source) {
- ERR_FAIL_INDEX(int(p_source), int(SOURCE_MAX));
- if (source == p_source) {
- return;
- }
- source = p_source;
- emit_changed();
- }
- VisualShaderNodeCubemap::Source VisualShaderNodeCubemap::get_source() const {
- return source;
- }
- void VisualShaderNodeCubemap::set_cube_map(Ref<TextureLayered> p_cube_map) {
- cube_map = p_cube_map;
- emit_changed();
- }
- Ref<TextureLayered> VisualShaderNodeCubemap::get_cube_map() const {
- return cube_map;
- }
- void VisualShaderNodeCubemap::set_texture_type(TextureType p_texture_type) {
- ERR_FAIL_INDEX(int(p_texture_type), int(TYPE_MAX));
- if (texture_type == p_texture_type) {
- return;
- }
- texture_type = p_texture_type;
- emit_changed();
- }
- VisualShaderNodeCubemap::TextureType VisualShaderNodeCubemap::get_texture_type() const {
- return texture_type;
- }
- Vector<StringName> VisualShaderNodeCubemap::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("source");
- if (source == SOURCE_TEXTURE) {
- props.push_back("cube_map");
- props.push_back("texture_type");
- }
- return props;
- }
- String VisualShaderNodeCubemap::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const {
- if (is_input_port_connected(2) && source != SOURCE_PORT) {
- return RTR("The sampler port is connected but not used. Consider changing the source to 'SamplerPort'.");
- }
- return String();
- }
- void VisualShaderNodeCubemap::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_source", "value"), &VisualShaderNodeCubemap::set_source);
- ClassDB::bind_method(D_METHOD("get_source"), &VisualShaderNodeCubemap::get_source);
- ClassDB::bind_method(D_METHOD("set_cube_map", "value"), &VisualShaderNodeCubemap::set_cube_map);
- ClassDB::bind_method(D_METHOD("get_cube_map"), &VisualShaderNodeCubemap::get_cube_map);
- ClassDB::bind_method(D_METHOD("set_texture_type", "value"), &VisualShaderNodeCubemap::set_texture_type);
- ClassDB::bind_method(D_METHOD("get_texture_type"), &VisualShaderNodeCubemap::get_texture_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "source", PROPERTY_HINT_ENUM, "Texture,SamplerPort"), "set_source", "get_source");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "cube_map", PROPERTY_HINT_RESOURCE_TYPE, "Cubemap,CompressedCubemap,PlaceholderCubemap,TextureCubemapRD"), "set_cube_map", "get_cube_map");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_type", PROPERTY_HINT_ENUM, "Data,Color,Normal Map"), "set_texture_type", "get_texture_type");
- BIND_ENUM_CONSTANT(SOURCE_TEXTURE);
- BIND_ENUM_CONSTANT(SOURCE_PORT);
- BIND_ENUM_CONSTANT(SOURCE_MAX);
- BIND_ENUM_CONSTANT(TYPE_DATA);
- BIND_ENUM_CONSTANT(TYPE_COLOR);
- BIND_ENUM_CONSTANT(TYPE_NORMAL_MAP);
- BIND_ENUM_CONSTANT(TYPE_MAX);
- }
- VisualShaderNodeCubemap::VisualShaderNodeCubemap() {
- simple_decl = false;
- }
- ////////////// Linear Depth
- String VisualShaderNodeLinearSceneDepth::get_caption() const {
- return "LinearSceneDepth";
- }
- int VisualShaderNodeLinearSceneDepth::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeLinearSceneDepth::PortType VisualShaderNodeLinearSceneDepth::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeLinearSceneDepth::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeLinearSceneDepth::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeLinearSceneDepth::PortType VisualShaderNodeLinearSceneDepth::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeLinearSceneDepth::get_output_port_name(int p_port) const {
- return "linear depth";
- }
- bool VisualShaderNodeLinearSceneDepth::has_output_port_preview(int p_port) const {
- return false;
- }
- String VisualShaderNodeLinearSceneDepth::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- return "uniform sampler2D " + make_unique_id(p_type, p_id, "depth_tex") + " : hint_depth_texture;\n";
- }
- String VisualShaderNodeLinearSceneDepth::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- code += " {\n";
- code += " float __log_depth = textureLod(" + make_unique_id(p_type, p_id, "depth_tex") + ", SCREEN_UV, 0.0).x;\n";
- if (!RenderingServer::get_singleton()->is_low_end()) {
- code += " vec4 __depth_view = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, __log_depth, 1.0);\n";
- } else {
- code += " vec4 __depth_view = INV_PROJECTION_MATRIX * vec4(vec3(SCREEN_UV, __log_depth) * 2.0 - 1.0, 1.0);\n";
- }
- code += " __depth_view.xyz /= __depth_view.w;\n";
- code += vformat(" %s = -__depth_view.z;\n", p_output_vars[0]);
- code += " }\n";
- return code;
- }
- VisualShaderNodeLinearSceneDepth::VisualShaderNodeLinearSceneDepth() {
- simple_decl = false;
- }
- ////////////// World Position from Depth
- String VisualShaderNodeWorldPositionFromDepth::get_caption() const {
- return "WorldPositionFromDepth";
- }
- int VisualShaderNodeWorldPositionFromDepth::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeWorldPositionFromDepth::PortType VisualShaderNodeWorldPositionFromDepth::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_2D;
- }
- String VisualShaderNodeWorldPositionFromDepth::get_input_port_name(int p_port) const {
- return "screen uv";
- }
- bool VisualShaderNodeWorldPositionFromDepth::is_input_port_default(int p_port, Shader::Mode p_mode) const {
- if (p_port == 0) {
- return true;
- }
- return false;
- }
- int VisualShaderNodeWorldPositionFromDepth::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeWorldPositionFromDepth::PortType VisualShaderNodeWorldPositionFromDepth::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeWorldPositionFromDepth::get_output_port_name(int p_port) const {
- return "world position";
- }
- bool VisualShaderNodeWorldPositionFromDepth::has_output_port_preview(int p_port) const {
- return false;
- }
- String VisualShaderNodeWorldPositionFromDepth::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- return "uniform sampler2D " + make_unique_id(p_type, p_id, "depth_tex") + " : hint_depth_texture, repeat_disable, filter_nearest;\n";
- }
- String VisualShaderNodeWorldPositionFromDepth::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- String uv = p_input_vars[0].is_empty() ? "SCREEN_UV" : p_input_vars[0];
- code += " {\n";
- code += " float __log_depth = textureLod(" + make_unique_id(p_type, p_id, "depth_tex") + ", " + uv + ", 0.0).x;\n";
- if (!RenderingServer::get_singleton()->is_low_end()) {
- code += " vec4 __depth_view = INV_PROJECTION_MATRIX * vec4(" + uv + " * 2.0 - 1.0, __log_depth, 1.0);\n";
- } else {
- code += " vec4 __depth_view = INV_PROJECTION_MATRIX * vec4(vec3(" + uv + ", __log_depth) * 2.0 - 1.0, 1.0);\n";
- }
- code += " __depth_view.xyz /= __depth_view.w;\n";
- code += vformat(" %s = (INV_VIEW_MATRIX * __depth_view).xyz;\n", p_output_vars[0]);
- code += " }\n";
- return code;
- }
- VisualShaderNodeWorldPositionFromDepth::VisualShaderNodeWorldPositionFromDepth() {
- simple_decl = false;
- }
- ////////////// Unpack Normals in World Space
- String VisualShaderNodeScreenNormalWorldSpace::get_caption() const {
- return "ScreenNormalWorldSpace";
- }
- int VisualShaderNodeScreenNormalWorldSpace::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeScreenNormalWorldSpace::PortType VisualShaderNodeScreenNormalWorldSpace::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_2D;
- }
- String VisualShaderNodeScreenNormalWorldSpace::get_input_port_name(int p_port) const {
- return "screen uv";
- }
- bool VisualShaderNodeScreenNormalWorldSpace::is_input_port_default(int p_port, Shader::Mode p_mode) const {
- if (p_port == 0) {
- return true;
- }
- return false;
- }
- int VisualShaderNodeScreenNormalWorldSpace::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeScreenNormalWorldSpace::PortType VisualShaderNodeScreenNormalWorldSpace::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScreenNormalWorldSpace::get_output_port_name(int p_port) const {
- return "screen normal";
- }
- bool VisualShaderNodeScreenNormalWorldSpace::has_output_port_preview(int p_port) const {
- return false;
- }
- String VisualShaderNodeScreenNormalWorldSpace::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- return "uniform sampler2D " + make_unique_id(p_type, p_id, "normal_rough_tex") + " : hint_normal_roughness_texture, repeat_disable, filter_nearest;\n";
- }
- String VisualShaderNodeScreenNormalWorldSpace::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- String uv = p_input_vars[0].is_empty() ? "SCREEN_UV" : p_input_vars[0];
- code += " {\n";
- code += " vec3 __normals = textureLod(" + make_unique_id(p_type, p_id, "normal_rough_tex") + ", " + uv + ", 0.0).xyz;\n";
- code += " __normals = __normals * 2.0 - 1.0;\n";
- code += vformat(" %s = mat3(INV_VIEW_MATRIX) * __normals;\n", p_output_vars[0]);
- code += " }\n";
- return code;
- }
- VisualShaderNodeScreenNormalWorldSpace::VisualShaderNodeScreenNormalWorldSpace() {
- simple_decl = false;
- }
- ////////////// Float Op
- String VisualShaderNodeFloatOp::get_caption() const {
- return "FloatOp";
- }
- int VisualShaderNodeFloatOp::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeFloatOp::PortType VisualShaderNodeFloatOp::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeFloatOp::get_input_port_name(int p_port) const {
- return p_port == 0 ? "a" : "b";
- }
- int VisualShaderNodeFloatOp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeFloatOp::PortType VisualShaderNodeFloatOp::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeFloatOp::get_output_port_name(int p_port) const {
- return "op"; //no output port means the editor will be used as port
- }
- String VisualShaderNodeFloatOp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code = " " + p_output_vars[0] + " = ";
- switch (op) {
- case OP_ADD:
- code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
- break;
- case OP_SUB:
- code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n";
- break;
- case OP_MUL:
- code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
- break;
- case OP_DIV:
- code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n";
- break;
- case OP_MOD:
- code += "mod(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_POW:
- code += "pow(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_MAX:
- code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_MIN:
- code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_ATAN2:
- code += "atan(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_STEP:
- code += "step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- default:
- break;
- }
- return code;
- }
- void VisualShaderNodeFloatOp::set_operator(Operator p_op) {
- ERR_FAIL_INDEX(int(p_op), int(OP_ENUM_SIZE));
- if (op == p_op) {
- return;
- }
- op = p_op;
- emit_changed();
- }
- VisualShaderNodeFloatOp::Operator VisualShaderNodeFloatOp::get_operator() const {
- return op;
- }
- Vector<StringName> VisualShaderNodeFloatOp::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("operator");
- return props;
- }
- void VisualShaderNodeFloatOp::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeFloatOp::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeFloatOp::get_operator);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "Add,Subtract,Multiply,Divide,Remainder,Power,Max,Min,ATan2,Step"), "set_operator", "get_operator");
- BIND_ENUM_CONSTANT(OP_ADD);
- BIND_ENUM_CONSTANT(OP_SUB);
- BIND_ENUM_CONSTANT(OP_MUL);
- BIND_ENUM_CONSTANT(OP_DIV);
- BIND_ENUM_CONSTANT(OP_MOD);
- BIND_ENUM_CONSTANT(OP_POW);
- BIND_ENUM_CONSTANT(OP_MAX);
- BIND_ENUM_CONSTANT(OP_MIN);
- BIND_ENUM_CONSTANT(OP_ATAN2);
- BIND_ENUM_CONSTANT(OP_STEP);
- BIND_ENUM_CONSTANT(OP_ENUM_SIZE);
- }
- VisualShaderNodeFloatOp::VisualShaderNodeFloatOp() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- }
- ////////////// Integer Op
- String VisualShaderNodeIntOp::get_caption() const {
- return "IntOp";
- }
- int VisualShaderNodeIntOp::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeIntOp::PortType VisualShaderNodeIntOp::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_INT;
- }
- String VisualShaderNodeIntOp::get_input_port_name(int p_port) const {
- return p_port == 0 ? "a" : "b";
- }
- int VisualShaderNodeIntOp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeIntOp::PortType VisualShaderNodeIntOp::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_INT;
- }
- String VisualShaderNodeIntOp::get_output_port_name(int p_port) const {
- return "op"; // No output port means the editor will be used as port.
- }
- String VisualShaderNodeIntOp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code = " " + p_output_vars[0] + " = ";
- switch (op) {
- case OP_ADD:
- code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
- break;
- case OP_SUB:
- code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n";
- break;
- case OP_MUL:
- code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
- break;
- case OP_DIV:
- code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n";
- break;
- case OP_MOD:
- code += p_input_vars[0] + " % " + p_input_vars[1] + ";\n";
- break;
- case OP_MAX:
- code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_MIN:
- code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_BITWISE_AND:
- code += p_input_vars[0] + " & " + p_input_vars[1] + ";\n";
- break;
- case OP_BITWISE_OR:
- code += p_input_vars[0] + " | " + p_input_vars[1] + ";\n";
- break;
- case OP_BITWISE_XOR:
- code += p_input_vars[0] + " ^ " + p_input_vars[1] + ";\n";
- break;
- case OP_BITWISE_LEFT_SHIFT:
- code += p_input_vars[0] + " << " + p_input_vars[1] + ";\n";
- break;
- case OP_BITWISE_RIGHT_SHIFT:
- code += p_input_vars[0] + " >> " + p_input_vars[1] + ";\n";
- break;
- default:
- break;
- }
- return code;
- }
- void VisualShaderNodeIntOp::set_operator(Operator p_op) {
- ERR_FAIL_INDEX(int(p_op), OP_ENUM_SIZE);
- if (op == p_op) {
- return;
- }
- op = p_op;
- emit_changed();
- }
- VisualShaderNodeIntOp::Operator VisualShaderNodeIntOp::get_operator() const {
- return op;
- }
- Vector<StringName> VisualShaderNodeIntOp::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("operator");
- return props;
- }
- void VisualShaderNodeIntOp::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeIntOp::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeIntOp::get_operator);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "Add,Subtract,Multiply,Divide,Remainder,Max,Min,Bitwise AND,Bitwise OR,Bitwise XOR,Bitwise Left Shift,Bitwise Right Shift"), "set_operator", "get_operator");
- BIND_ENUM_CONSTANT(OP_ADD);
- BIND_ENUM_CONSTANT(OP_SUB);
- BIND_ENUM_CONSTANT(OP_MUL);
- BIND_ENUM_CONSTANT(OP_DIV);
- BIND_ENUM_CONSTANT(OP_MOD);
- BIND_ENUM_CONSTANT(OP_MAX);
- BIND_ENUM_CONSTANT(OP_MIN);
- BIND_ENUM_CONSTANT(OP_BITWISE_AND);
- BIND_ENUM_CONSTANT(OP_BITWISE_OR);
- BIND_ENUM_CONSTANT(OP_BITWISE_XOR);
- BIND_ENUM_CONSTANT(OP_BITWISE_LEFT_SHIFT);
- BIND_ENUM_CONSTANT(OP_BITWISE_RIGHT_SHIFT);
- BIND_ENUM_CONSTANT(OP_ENUM_SIZE);
- }
- VisualShaderNodeIntOp::VisualShaderNodeIntOp() {
- set_input_port_default_value(0, 0);
- set_input_port_default_value(1, 0);
- }
- ////////////// Unsigned Integer Op
- String VisualShaderNodeUIntOp::get_caption() const {
- return "UIntOp";
- }
- int VisualShaderNodeUIntOp::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeUIntOp::PortType VisualShaderNodeUIntOp::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_UINT;
- }
- String VisualShaderNodeUIntOp::get_input_port_name(int p_port) const {
- return p_port == 0 ? "a" : "b";
- }
- int VisualShaderNodeUIntOp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeUIntOp::PortType VisualShaderNodeUIntOp::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_UINT;
- }
- String VisualShaderNodeUIntOp::get_output_port_name(int p_port) const {
- return "op"; // No output port means the editor will be used as port.
- }
- String VisualShaderNodeUIntOp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code = " " + p_output_vars[0] + " = ";
- switch (op) {
- case OP_ADD:
- code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
- break;
- case OP_SUB:
- code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n";
- break;
- case OP_MUL:
- code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
- break;
- case OP_DIV:
- code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n";
- break;
- case OP_MOD:
- code += p_input_vars[0] + " % " + p_input_vars[1] + ";\n";
- break;
- case OP_MAX:
- code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_MIN:
- code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_BITWISE_AND:
- code += p_input_vars[0] + " & " + p_input_vars[1] + ";\n";
- break;
- case OP_BITWISE_OR:
- code += p_input_vars[0] + " | " + p_input_vars[1] + ";\n";
- break;
- case OP_BITWISE_XOR:
- code += p_input_vars[0] + " ^ " + p_input_vars[1] + ";\n";
- break;
- case OP_BITWISE_LEFT_SHIFT:
- code += p_input_vars[0] + " << " + p_input_vars[1] + ";\n";
- break;
- case OP_BITWISE_RIGHT_SHIFT:
- code += p_input_vars[0] + " >> " + p_input_vars[1] + ";\n";
- break;
- default:
- break;
- }
- return code;
- }
- void VisualShaderNodeUIntOp::set_operator(Operator p_op) {
- ERR_FAIL_INDEX(int(p_op), OP_ENUM_SIZE);
- if (op == p_op) {
- return;
- }
- op = p_op;
- emit_changed();
- }
- VisualShaderNodeUIntOp::Operator VisualShaderNodeUIntOp::get_operator() const {
- return op;
- }
- Vector<StringName> VisualShaderNodeUIntOp::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("operator");
- return props;
- }
- void VisualShaderNodeUIntOp::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeUIntOp::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeUIntOp::get_operator);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "Add,Subtract,Multiply,Divide,Remainder,Max,Min,Bitwise AND,Bitwise OR,Bitwise XOR,Bitwise Left Shift,Bitwise Right Shift"), "set_operator", "get_operator");
- BIND_ENUM_CONSTANT(OP_ADD);
- BIND_ENUM_CONSTANT(OP_SUB);
- BIND_ENUM_CONSTANT(OP_MUL);
- BIND_ENUM_CONSTANT(OP_DIV);
- BIND_ENUM_CONSTANT(OP_MOD);
- BIND_ENUM_CONSTANT(OP_MAX);
- BIND_ENUM_CONSTANT(OP_MIN);
- BIND_ENUM_CONSTANT(OP_BITWISE_AND);
- BIND_ENUM_CONSTANT(OP_BITWISE_OR);
- BIND_ENUM_CONSTANT(OP_BITWISE_XOR);
- BIND_ENUM_CONSTANT(OP_BITWISE_LEFT_SHIFT);
- BIND_ENUM_CONSTANT(OP_BITWISE_RIGHT_SHIFT);
- BIND_ENUM_CONSTANT(OP_ENUM_SIZE);
- }
- VisualShaderNodeUIntOp::VisualShaderNodeUIntOp() {
- set_input_port_default_value(0, 0);
- set_input_port_default_value(1, 0);
- }
- ////////////// Vector Op
- String VisualShaderNodeVectorOp::get_caption() const {
- return "VectorOp";
- }
- int VisualShaderNodeVectorOp::get_input_port_count() const {
- return 2;
- }
- String VisualShaderNodeVectorOp::get_input_port_name(int p_port) const {
- return p_port == 0 ? "a" : "b";
- }
- int VisualShaderNodeVectorOp::get_output_port_count() const {
- return 1;
- }
- String VisualShaderNodeVectorOp::get_output_port_name(int p_port) const {
- return "op";
- }
- String VisualShaderNodeVectorOp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code = " " + p_output_vars[0] + " = ";
- switch (op) {
- case OP_ADD:
- code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
- break;
- case OP_SUB:
- code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n";
- break;
- case OP_MUL:
- code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
- break;
- case OP_DIV:
- code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n";
- break;
- case OP_MOD:
- code += "mod(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_POW:
- code += "pow(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_MAX:
- code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_MIN:
- code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_CROSS:
- if (op_type == OP_TYPE_VECTOR_2D) { // Not supported.
- code += "vec2(0.0);\n";
- } else if (op_type == OP_TYPE_VECTOR_4D) { // Not supported.
- code += "vec4(0.0);\n";
- } else {
- code += "cross(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- }
- break;
- case OP_ATAN2:
- code += "atan(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_REFLECT:
- code += "reflect(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- case OP_STEP:
- code += "step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- break;
- default:
- break;
- }
- return code;
- }
- void VisualShaderNodeVectorOp::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1));
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1));
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1));
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- void VisualShaderNodeVectorOp::set_operator(Operator p_op) {
- ERR_FAIL_INDEX(int(p_op), int(OP_ENUM_SIZE));
- if (op == p_op) {
- return;
- }
- op = p_op;
- emit_changed();
- }
- VisualShaderNodeVectorOp::Operator VisualShaderNodeVectorOp::get_operator() const {
- return op;
- }
- Vector<StringName> VisualShaderNodeVectorOp::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeVectorBase::get_editable_properties();
- props.push_back("operator");
- return props;
- }
- String VisualShaderNodeVectorOp::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const {
- bool invalid_type = false;
- if (op_type == OP_TYPE_VECTOR_2D || op_type == OP_TYPE_VECTOR_4D) {
- if (op == OP_CROSS) {
- invalid_type = true;
- }
- }
- if (invalid_type) {
- return RTR("Invalid operator for that type.");
- }
- return String();
- }
- void VisualShaderNodeVectorOp::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeVectorOp::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeVectorOp::get_operator);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "Add,Subtract,Multiply,Divide,Remainder,Power,Max,Min,Cross,ATan2,Reflect,Step"), "set_operator", "get_operator");
- BIND_ENUM_CONSTANT(OP_ADD);
- BIND_ENUM_CONSTANT(OP_SUB);
- BIND_ENUM_CONSTANT(OP_MUL);
- BIND_ENUM_CONSTANT(OP_DIV);
- BIND_ENUM_CONSTANT(OP_MOD);
- BIND_ENUM_CONSTANT(OP_POW);
- BIND_ENUM_CONSTANT(OP_MAX);
- BIND_ENUM_CONSTANT(OP_MIN);
- BIND_ENUM_CONSTANT(OP_CROSS);
- BIND_ENUM_CONSTANT(OP_ATAN2);
- BIND_ENUM_CONSTANT(OP_REFLECT);
- BIND_ENUM_CONSTANT(OP_STEP);
- BIND_ENUM_CONSTANT(OP_ENUM_SIZE);
- }
- VisualShaderNodeVectorOp::VisualShaderNodeVectorOp() {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2());
- set_input_port_default_value(1, Vector2());
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3());
- set_input_port_default_value(1, Vector3());
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion());
- set_input_port_default_value(1, Quaternion());
- } break;
- default:
- break;
- }
- }
- ////////////// Color Op
- String VisualShaderNodeColorOp::get_caption() const {
- return "ColorOp";
- }
- int VisualShaderNodeColorOp::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeColorOp::PortType VisualShaderNodeColorOp::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeColorOp::get_input_port_name(int p_port) const {
- return p_port == 0 ? "a" : "b";
- }
- int VisualShaderNodeColorOp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeColorOp::PortType VisualShaderNodeColorOp::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeColorOp::get_output_port_name(int p_port) const {
- return "op"; //no output port means the editor will be used as port
- }
- String VisualShaderNodeColorOp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- static const char *axisn[3] = { "x", "y", "z" };
- switch (op) {
- case OP_SCREEN: {
- code += " " + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") * (vec3(1.0) - " + p_input_vars[1] + ");\n";
- } break;
- case OP_DIFFERENCE: {
- code += " " + p_output_vars[0] + " = abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ");\n";
- } break;
- case OP_DARKEN: {
- code += " " + p_output_vars[0] + " = min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- } break;
- case OP_LIGHTEN: {
- code += " " + p_output_vars[0] + " = max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- } break;
- case OP_OVERLAY: {
- for (int i = 0; i < 3; i++) {
- code += " {\n";
- code += " float base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
- code += " float blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
- code += " if (base < 0.5) {\n";
- code += " " + p_output_vars[0] + "." + axisn[i] + " = 2.0 * base * blend;\n";
- code += " } else {\n";
- code += " " + p_output_vars[0] + "." + axisn[i] + " = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);\n";
- code += " }\n";
- code += " }\n";
- }
- } break;
- case OP_DODGE: {
- code += " " + p_output_vars[0] + " = (" + p_input_vars[0] + ") / (vec3(1.0) - " + p_input_vars[1] + ");\n";
- } break;
- case OP_BURN: {
- code += " " + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") / (" + p_input_vars[1] + ");\n";
- } break;
- case OP_SOFT_LIGHT: {
- for (int i = 0; i < 3; i++) {
- code += " {\n";
- code += " float base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
- code += " float blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
- code += " if (base < 0.5) {\n";
- code += " " + p_output_vars[0] + "." + axisn[i] + " = (base * (blend + 0.5));\n";
- code += " } else {\n";
- code += " " + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - (blend - 0.5)));\n";
- code += " }\n";
- code += " }\n";
- }
- } break;
- case OP_HARD_LIGHT: {
- for (int i = 0; i < 3; i++) {
- code += " {\n";
- code += " float base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
- code += " float blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
- code += " if (base < 0.5) {\n";
- code += " " + p_output_vars[0] + "." + axisn[i] + " = (base * (2.0 * blend));\n";
- code += " } else {\n";
- code += " " + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - 2.0 * (blend - 0.5)));\n";
- code += " }\n";
- code += " }\n";
- }
- } break;
- default:
- break;
- }
- return code;
- }
- void VisualShaderNodeColorOp::set_operator(Operator p_op) {
- ERR_FAIL_INDEX(int(p_op), int(OP_MAX));
- if (op == p_op) {
- return;
- }
- switch (p_op) {
- case OP_SCREEN:
- simple_decl = true;
- break;
- case OP_DIFFERENCE:
- simple_decl = true;
- break;
- case OP_DARKEN:
- simple_decl = true;
- break;
- case OP_LIGHTEN:
- simple_decl = true;
- break;
- case OP_OVERLAY:
- simple_decl = false;
- break;
- case OP_DODGE:
- simple_decl = true;
- break;
- case OP_BURN:
- simple_decl = true;
- break;
- case OP_SOFT_LIGHT:
- simple_decl = false;
- break;
- case OP_HARD_LIGHT:
- simple_decl = false;
- break;
- default:
- break;
- }
- op = p_op;
- emit_changed();
- }
- VisualShaderNodeColorOp::Operator VisualShaderNodeColorOp::get_operator() const {
- return op;
- }
- Vector<StringName> VisualShaderNodeColorOp::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("operator");
- return props;
- }
- void VisualShaderNodeColorOp::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeColorOp::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeColorOp::get_operator);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "Screen,Difference,Darken,Lighten,Overlay,Dodge,Burn,Soft Light,Hard Light"), "set_operator", "get_operator");
- BIND_ENUM_CONSTANT(OP_SCREEN);
- BIND_ENUM_CONSTANT(OP_DIFFERENCE);
- BIND_ENUM_CONSTANT(OP_DARKEN);
- BIND_ENUM_CONSTANT(OP_LIGHTEN);
- BIND_ENUM_CONSTANT(OP_OVERLAY);
- BIND_ENUM_CONSTANT(OP_DODGE);
- BIND_ENUM_CONSTANT(OP_BURN);
- BIND_ENUM_CONSTANT(OP_SOFT_LIGHT);
- BIND_ENUM_CONSTANT(OP_HARD_LIGHT);
- BIND_ENUM_CONSTANT(OP_MAX);
- }
- VisualShaderNodeColorOp::VisualShaderNodeColorOp() {
- set_input_port_default_value(0, Vector3());
- set_input_port_default_value(1, Vector3());
- }
- ////////////// Transform Op
- String VisualShaderNodeTransformOp::get_caption() const {
- return "TransformOp";
- }
- int VisualShaderNodeTransformOp::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeTransformOp::PortType VisualShaderNodeTransformOp::get_input_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformOp::get_input_port_name(int p_port) const {
- return p_port == 0 ? "a" : "b";
- }
- int VisualShaderNodeTransformOp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeTransformOp::PortType VisualShaderNodeTransformOp::get_output_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformOp::get_output_port_name(int p_port) const {
- return "mult"; //no output port means the editor will be used as port
- }
- String VisualShaderNodeTransformOp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- switch (op) {
- case OP_AxB:
- return " " + p_output_vars[0] + " = " + p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
- case OP_BxA:
- return " " + p_output_vars[0] + " = " + p_input_vars[1] + " * " + p_input_vars[0] + ";\n";
- case OP_AxB_COMP:
- return " " + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- case OP_BxA_COMP:
- return " " + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[1] + ", " + p_input_vars[0] + ");\n";
- case OP_ADD:
- return " " + p_output_vars[0] + " = " + p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
- case OP_A_MINUS_B:
- return " " + p_output_vars[0] + " = " + p_input_vars[0] + " - " + p_input_vars[1] + ";\n";
- case OP_B_MINUS_A:
- return " " + p_output_vars[0] + " = " + p_input_vars[1] + " - " + p_input_vars[0] + ";\n";
- case OP_A_DIV_B:
- return " " + p_output_vars[0] + " = " + p_input_vars[0] + " / " + p_input_vars[1] + ";\n";
- case OP_B_DIV_A:
- return " " + p_output_vars[0] + " = " + p_input_vars[1] + " / " + p_input_vars[0] + ";\n";
- default:
- return "";
- }
- }
- void VisualShaderNodeTransformOp::set_operator(Operator p_op) {
- ERR_FAIL_INDEX(int(p_op), int(OP_MAX));
- if (op == p_op) {
- return;
- }
- op = p_op;
- emit_changed();
- }
- VisualShaderNodeTransformOp::Operator VisualShaderNodeTransformOp::get_operator() const {
- return op;
- }
- Vector<StringName> VisualShaderNodeTransformOp::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("operator");
- return props;
- }
- void VisualShaderNodeTransformOp::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeTransformOp::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeTransformOp::get_operator);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "A x B,B x A,A x B(per component),B x A(per component),A + B,A - B,B - A,A / B,B / A"), "set_operator", "get_operator");
- BIND_ENUM_CONSTANT(OP_AxB);
- BIND_ENUM_CONSTANT(OP_BxA);
- BIND_ENUM_CONSTANT(OP_AxB_COMP);
- BIND_ENUM_CONSTANT(OP_BxA_COMP);
- BIND_ENUM_CONSTANT(OP_ADD);
- BIND_ENUM_CONSTANT(OP_A_MINUS_B);
- BIND_ENUM_CONSTANT(OP_B_MINUS_A);
- BIND_ENUM_CONSTANT(OP_A_DIV_B);
- BIND_ENUM_CONSTANT(OP_B_DIV_A);
- BIND_ENUM_CONSTANT(OP_MAX);
- }
- VisualShaderNodeTransformOp::VisualShaderNodeTransformOp() {
- set_input_port_default_value(0, Transform3D());
- set_input_port_default_value(1, Transform3D());
- }
- ////////////// TransformVec Mult
- String VisualShaderNodeTransformVecMult::get_caption() const {
- return "TransformVectorMult";
- }
- int VisualShaderNodeTransformVecMult::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeTransformVecMult::PortType VisualShaderNodeTransformVecMult::get_input_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_TRANSFORM : PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeTransformVecMult::get_input_port_name(int p_port) const {
- return p_port == 0 ? "a" : "b";
- }
- int VisualShaderNodeTransformVecMult::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeTransformVecMult::PortType VisualShaderNodeTransformVecMult::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeTransformVecMult::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeTransformVecMult::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- if (op == OP_AxB) {
- return " " + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 1.0)).xyz;\n";
- } else if (op == OP_BxA) {
- return " " + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 1.0) * " + p_input_vars[0] + ").xyz;\n";
- } else if (op == OP_3x3_AxB) {
- return " " + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 0.0)).xyz;\n";
- } else {
- return " " + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 0.0) * " + p_input_vars[0] + ").xyz;\n";
- }
- }
- void VisualShaderNodeTransformVecMult::set_operator(Operator p_op) {
- ERR_FAIL_INDEX(int(p_op), int(OP_MAX));
- if (op == p_op) {
- return;
- }
- op = p_op;
- emit_changed();
- }
- VisualShaderNodeTransformVecMult::Operator VisualShaderNodeTransformVecMult::get_operator() const {
- return op;
- }
- Vector<StringName> VisualShaderNodeTransformVecMult::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("operator");
- return props;
- }
- void VisualShaderNodeTransformVecMult::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeTransformVecMult::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeTransformVecMult::get_operator);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "A x B,B x A,A x B (3x3),B x A (3x3)"), "set_operator", "get_operator");
- BIND_ENUM_CONSTANT(OP_AxB);
- BIND_ENUM_CONSTANT(OP_BxA);
- BIND_ENUM_CONSTANT(OP_3x3_AxB);
- BIND_ENUM_CONSTANT(OP_3x3_BxA);
- BIND_ENUM_CONSTANT(OP_MAX);
- }
- VisualShaderNodeTransformVecMult::VisualShaderNodeTransformVecMult() {
- set_input_port_default_value(0, Transform3D());
- set_input_port_default_value(1, Vector3());
- }
- ////////////// Float Func
- String VisualShaderNodeFloatFunc::get_caption() const {
- return "FloatFunc";
- }
- int VisualShaderNodeFloatFunc::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeFloatFunc::PortType VisualShaderNodeFloatFunc::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeFloatFunc::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeFloatFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeFloatFunc::PortType VisualShaderNodeFloatFunc::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeFloatFunc::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeFloatFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- static const char *functions[FUNC_MAX] = {
- "sin($)",
- "cos($)",
- "tan($)",
- "asin($)",
- "acos($)",
- "atan($)",
- "sinh($)",
- "cosh($)",
- "tanh($)",
- "log($)",
- "exp($)",
- "sqrt($)",
- "abs($)",
- "sign($)",
- "floor($)",
- "round($)",
- "ceil($)",
- "fract($)",
- "min(max($, 0.0), 1.0)",
- "-($)",
- "acosh($)",
- "asinh($)",
- "atanh($)",
- "degrees($)",
- "exp2($)",
- "inversesqrt($)",
- "log2($)",
- "radians($)",
- "1.0 / ($)",
- "roundEven($)",
- "trunc($)",
- "1.0 - $"
- };
- return " " + p_output_vars[0] + " = " + String(functions[func]).replace("$", p_input_vars[0]) + ";\n";
- }
- void VisualShaderNodeFloatFunc::set_function(Function p_func) {
- ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX));
- if (func == p_func) {
- return;
- }
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeFloatFunc::Function VisualShaderNodeFloatFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeFloatFunc::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeFloatFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeFloatFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeFloatFunc::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Sin,Cos,Tan,ASin,ACos,ATan,SinH,CosH,TanH,Log,Exp,Sqrt,Abs,Sign,Floor,Round,Ceil,Fract,Saturate,Negate,ACosH,ASinH,ATanH,Degrees,Exp2,InverseSqrt,Log2,Radians,Reciprocal,RoundEven,Trunc,OneMinus"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_SIN);
- BIND_ENUM_CONSTANT(FUNC_COS);
- BIND_ENUM_CONSTANT(FUNC_TAN);
- BIND_ENUM_CONSTANT(FUNC_ASIN);
- BIND_ENUM_CONSTANT(FUNC_ACOS);
- BIND_ENUM_CONSTANT(FUNC_ATAN);
- BIND_ENUM_CONSTANT(FUNC_SINH);
- BIND_ENUM_CONSTANT(FUNC_COSH);
- BIND_ENUM_CONSTANT(FUNC_TANH);
- BIND_ENUM_CONSTANT(FUNC_LOG);
- BIND_ENUM_CONSTANT(FUNC_EXP);
- BIND_ENUM_CONSTANT(FUNC_SQRT);
- BIND_ENUM_CONSTANT(FUNC_ABS);
- BIND_ENUM_CONSTANT(FUNC_SIGN);
- BIND_ENUM_CONSTANT(FUNC_FLOOR);
- BIND_ENUM_CONSTANT(FUNC_ROUND);
- BIND_ENUM_CONSTANT(FUNC_CEIL);
- BIND_ENUM_CONSTANT(FUNC_FRACT);
- BIND_ENUM_CONSTANT(FUNC_SATURATE);
- BIND_ENUM_CONSTANT(FUNC_NEGATE);
- BIND_ENUM_CONSTANT(FUNC_ACOSH);
- BIND_ENUM_CONSTANT(FUNC_ASINH);
- BIND_ENUM_CONSTANT(FUNC_ATANH);
- BIND_ENUM_CONSTANT(FUNC_DEGREES);
- BIND_ENUM_CONSTANT(FUNC_EXP2);
- BIND_ENUM_CONSTANT(FUNC_INVERSE_SQRT);
- BIND_ENUM_CONSTANT(FUNC_LOG2);
- BIND_ENUM_CONSTANT(FUNC_RADIANS);
- BIND_ENUM_CONSTANT(FUNC_RECIPROCAL);
- BIND_ENUM_CONSTANT(FUNC_ROUNDEVEN);
- BIND_ENUM_CONSTANT(FUNC_TRUNC);
- BIND_ENUM_CONSTANT(FUNC_ONEMINUS);
- BIND_ENUM_CONSTANT(FUNC_MAX);
- }
- VisualShaderNodeFloatFunc::VisualShaderNodeFloatFunc() {
- set_input_port_default_value(0, 0.0);
- }
- ////////////// Int Func
- String VisualShaderNodeIntFunc::get_caption() const {
- return "IntFunc";
- }
- int VisualShaderNodeIntFunc::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeIntFunc::PortType VisualShaderNodeIntFunc::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_INT;
- }
- String VisualShaderNodeIntFunc::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeIntFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeIntFunc::PortType VisualShaderNodeIntFunc::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_INT;
- }
- String VisualShaderNodeIntFunc::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeIntFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- static const char *functions[FUNC_MAX] = {
- "abs($)",
- "-($)",
- "sign($)",
- "~($)"
- };
- return " " + p_output_vars[0] + " = " + String(functions[func]).replace("$", p_input_vars[0]) + ";\n";
- }
- void VisualShaderNodeIntFunc::set_function(Function p_func) {
- ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX));
- if (func == p_func) {
- return;
- }
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeIntFunc::Function VisualShaderNodeIntFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeIntFunc::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeIntFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeIntFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeIntFunc::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Abs,Negate,Sign,Bitwise NOT"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_ABS);
- BIND_ENUM_CONSTANT(FUNC_NEGATE);
- BIND_ENUM_CONSTANT(FUNC_SIGN);
- BIND_ENUM_CONSTANT(FUNC_BITWISE_NOT);
- BIND_ENUM_CONSTANT(FUNC_MAX);
- }
- VisualShaderNodeIntFunc::VisualShaderNodeIntFunc() {
- set_input_port_default_value(0, 0);
- }
- ////////////// Unsigned Int Func
- String VisualShaderNodeUIntFunc::get_caption() const {
- return "UIntFunc";
- }
- int VisualShaderNodeUIntFunc::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeUIntFunc::PortType VisualShaderNodeUIntFunc::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_UINT;
- }
- String VisualShaderNodeUIntFunc::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeUIntFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeUIntFunc::PortType VisualShaderNodeUIntFunc::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_UINT;
- }
- String VisualShaderNodeUIntFunc::get_output_port_name(int p_port) const {
- return ""; // No output port means the editor will be used as port.
- }
- String VisualShaderNodeUIntFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- static const char *functions[FUNC_MAX] = {
- "-($)",
- "~($)"
- };
- return " " + p_output_vars[0] + " = " + String(functions[func]).replace("$", p_input_vars[0]) + ";\n";
- }
- void VisualShaderNodeUIntFunc::set_function(Function p_func) {
- ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX));
- if (func == p_func) {
- return;
- }
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeUIntFunc::Function VisualShaderNodeUIntFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeUIntFunc::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeUIntFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeUIntFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeUIntFunc::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Negate,Bitwise NOT"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_NEGATE);
- BIND_ENUM_CONSTANT(FUNC_BITWISE_NOT);
- BIND_ENUM_CONSTANT(FUNC_MAX);
- }
- VisualShaderNodeUIntFunc::VisualShaderNodeUIntFunc() {
- set_input_port_default_value(0, 0);
- }
- ////////////// Vector Func
- String VisualShaderNodeVectorFunc::get_caption() const {
- return "VectorFunc";
- }
- int VisualShaderNodeVectorFunc::get_input_port_count() const {
- return 1;
- }
- String VisualShaderNodeVectorFunc::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeVectorFunc::get_output_port_count() const {
- return 1;
- }
- String VisualShaderNodeVectorFunc::get_output_port_name(int p_port) const {
- return "result";
- }
- String VisualShaderNodeVectorFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- static const char *funcs[FUNC_MAX] = {
- "normalize($)",
- "", // FUNC_SATURATE
- "-($)",
- "1.0 / ($)",
- "abs($)",
- "acos($)",
- "acosh($)",
- "asin($)",
- "asinh($)",
- "atan($)",
- "atanh($)",
- "ceil($)",
- "cos($)",
- "cosh($)",
- "degrees($)",
- "exp($)",
- "exp2($)",
- "floor($)",
- "fract($)",
- "inversesqrt($)",
- "log($)",
- "log2($)",
- "radians($)",
- "round($)",
- "roundEven($)",
- "sign($)",
- "sin($)",
- "sinh($)",
- "sqrt($)",
- "tan($)",
- "tanh($)",
- "trunc($)",
- "" // FUNC_ONEMINUS
- };
- if (func == FUNC_SATURATE) {
- String code;
- if (op_type == OP_TYPE_VECTOR_2D) {
- code = "max(min($, vec2(1.0)), vec2(0.0))";
- } else if (op_type == OP_TYPE_VECTOR_3D) {
- code = "max(min($, vec3(1.0)), vec3(0.0))";
- } else {
- code = "max(min($, vec4(1.0)), vec4(0.0))";
- }
- return " " + p_output_vars[0] + " = " + code.replace("$", p_input_vars[0]) + ";\n";
- }
- if (func == FUNC_ONEMINUS) {
- String code;
- if (op_type == OP_TYPE_VECTOR_2D) {
- code = "vec2(1.0) - $";
- } else if (op_type == OP_TYPE_VECTOR_3D) {
- code = "vec3(1.0) - $";
- } else {
- code = "vec4(1.0) - $";
- }
- return " " + p_output_vars[0] + " = " + code.replace("$", p_input_vars[0]) + ";\n";
- }
- return " " + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
- }
- void VisualShaderNodeVectorFunc::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- void VisualShaderNodeVectorFunc::set_function(Function p_func) {
- ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX));
- if (func == p_func) {
- return;
- }
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeVectorFunc::Function VisualShaderNodeVectorFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeVectorFunc::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeVectorBase::get_editable_properties();
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeVectorFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeVectorFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeVectorFunc::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Normalize,Saturate,Negate,Reciprocal,Abs,ACos,ACosH,ASin,ASinH,ATan,ATanH,Ceil,Cos,CosH,Degrees,Exp,Exp2,Floor,Fract,InverseSqrt,Log,Log2,Radians,Round,RoundEven,Sign,Sin,SinH,Sqrt,Tan,TanH,Trunc,OneMinus"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_NORMALIZE);
- BIND_ENUM_CONSTANT(FUNC_SATURATE);
- BIND_ENUM_CONSTANT(FUNC_NEGATE);
- BIND_ENUM_CONSTANT(FUNC_RECIPROCAL);
- BIND_ENUM_CONSTANT(FUNC_ABS);
- BIND_ENUM_CONSTANT(FUNC_ACOS);
- BIND_ENUM_CONSTANT(FUNC_ACOSH);
- BIND_ENUM_CONSTANT(FUNC_ASIN);
- BIND_ENUM_CONSTANT(FUNC_ASINH);
- BIND_ENUM_CONSTANT(FUNC_ATAN);
- BIND_ENUM_CONSTANT(FUNC_ATANH);
- BIND_ENUM_CONSTANT(FUNC_CEIL);
- BIND_ENUM_CONSTANT(FUNC_COS);
- BIND_ENUM_CONSTANT(FUNC_COSH);
- BIND_ENUM_CONSTANT(FUNC_DEGREES);
- BIND_ENUM_CONSTANT(FUNC_EXP);
- BIND_ENUM_CONSTANT(FUNC_EXP2);
- BIND_ENUM_CONSTANT(FUNC_FLOOR);
- BIND_ENUM_CONSTANT(FUNC_FRACT);
- BIND_ENUM_CONSTANT(FUNC_INVERSE_SQRT);
- BIND_ENUM_CONSTANT(FUNC_LOG);
- BIND_ENUM_CONSTANT(FUNC_LOG2);
- BIND_ENUM_CONSTANT(FUNC_RADIANS);
- BIND_ENUM_CONSTANT(FUNC_ROUND);
- BIND_ENUM_CONSTANT(FUNC_ROUNDEVEN);
- BIND_ENUM_CONSTANT(FUNC_SIGN);
- BIND_ENUM_CONSTANT(FUNC_SIN);
- BIND_ENUM_CONSTANT(FUNC_SINH);
- BIND_ENUM_CONSTANT(FUNC_SQRT);
- BIND_ENUM_CONSTANT(FUNC_TAN);
- BIND_ENUM_CONSTANT(FUNC_TANH);
- BIND_ENUM_CONSTANT(FUNC_TRUNC);
- BIND_ENUM_CONSTANT(FUNC_ONEMINUS);
- BIND_ENUM_CONSTANT(FUNC_MAX);
- }
- VisualShaderNodeVectorFunc::VisualShaderNodeVectorFunc() {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2());
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3());
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion());
- } break;
- default:
- break;
- }
- }
- ////////////// ColorFunc
- String VisualShaderNodeColorFunc::get_caption() const {
- return "ColorFunc";
- }
- int VisualShaderNodeColorFunc::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeColorFunc::PortType VisualShaderNodeColorFunc::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeColorFunc::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeColorFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeColorFunc::PortType VisualShaderNodeColorFunc::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeColorFunc::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeColorFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- switch (func) {
- case FUNC_GRAYSCALE:
- code += " {\n";
- code += " vec3 c = " + p_input_vars[0] + ";\n";
- code += " float max1 = max(c.r, c.g);\n";
- code += " float max2 = max(max1, c.b);\n";
- code += " " + p_output_vars[0] + " = vec3(max2, max2, max2);\n";
- code += " }\n";
- break;
- case FUNC_HSV2RGB:
- code += " {\n";
- code += " vec3 c = " + p_input_vars[0] + ";\n";
- code += " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n";
- code += " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n";
- code += " " + p_output_vars[0] + " = c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n";
- code += " }\n";
- break;
- case FUNC_RGB2HSV:
- code += " {\n";
- code += " vec3 c = " + p_input_vars[0] + ";\n";
- code += " vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n";
- code += " vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n";
- code += " vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n";
- code += " float d = q.x - min(q.w, q.y);\n";
- code += " float e = 1.0e-10;\n";
- code += " " + p_output_vars[0] + " = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n";
- code += " }\n";
- break;
- case FUNC_SEPIA:
- code += " {\n";
- code += " vec3 c = " + p_input_vars[0] + ";\n";
- code += " float r = (c.r * .393) + (c.g *.769) + (c.b * .189);\n";
- code += " float g = (c.r * .349) + (c.g *.686) + (c.b * .168);\n";
- code += " float b = (c.r * .272) + (c.g *.534) + (c.b * .131);\n";
- code += " " + p_output_vars[0] + " = vec3(r, g, b);\n";
- code += " }\n";
- break;
- case FUNC_LINEAR_TO_SRGB:
- code += " {\n";
- if (RenderingServer::get_singleton()->is_low_end()) {
- code += " vec3 c = " + p_input_vars[0] + ";\n";
- code += " " + p_output_vars[0] + " = max(vec3(1.055) * pow(c, vec3(0.416666667)) - vec3(0.055), vec3(0.0));\n";
- } else {
- code += " vec3 c = clamp(" + p_input_vars[0] + ", vec3(0.0), vec3(1.0));\n";
- code += " const vec3 a = vec3(0.055f);\n";
- code += " " + p_output_vars[0] + " = mix((vec3(1.0f) + a) * pow(c.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * c.rgb, lessThan(c.rgb, vec3(0.0031308f)));\n";
- }
- code += " }\n";
- break;
- case FUNC_SRGB_TO_LINEAR:
- code += " {\n";
- if (RenderingServer::get_singleton()->is_low_end()) {
- code += " vec3 c = " + p_input_vars[0] + ";\n";
- code += " " + p_output_vars[0] + " = c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878);\n";
- } else {
- code += " vec3 c = " + p_input_vars[0] + ";\n";
- code += " " + p_output_vars[0] + " = mix(pow((c.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), c.rgb * (1.0 / 12.92), lessThan(c.rgb, vec3(0.04045)));\n";
- }
- code += " }\n";
- break;
- default:
- break;
- }
- return code;
- }
- void VisualShaderNodeColorFunc::set_function(Function p_func) {
- ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX));
- if (func == p_func) {
- return;
- }
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeColorFunc::Function VisualShaderNodeColorFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeColorFunc::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeColorFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeColorFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeColorFunc::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Grayscale,HSV2RGB,RGB2HSV,Sepia,LinearToSRGB,SRGBToLinear"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_GRAYSCALE);
- BIND_ENUM_CONSTANT(FUNC_HSV2RGB);
- BIND_ENUM_CONSTANT(FUNC_RGB2HSV);
- BIND_ENUM_CONSTANT(FUNC_SEPIA);
- BIND_ENUM_CONSTANT(FUNC_LINEAR_TO_SRGB);
- BIND_ENUM_CONSTANT(FUNC_SRGB_TO_LINEAR);
- BIND_ENUM_CONSTANT(FUNC_MAX);
- }
- VisualShaderNodeColorFunc::VisualShaderNodeColorFunc() {
- simple_decl = false;
- set_input_port_default_value(0, Vector3());
- }
- ////////////// Transform Func
- String VisualShaderNodeTransformFunc::get_caption() const {
- return "TransformFunc";
- }
- int VisualShaderNodeTransformFunc::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeTransformFunc::PortType VisualShaderNodeTransformFunc::get_input_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformFunc::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeTransformFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeTransformFunc::PortType VisualShaderNodeTransformFunc::get_output_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformFunc::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeTransformFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- static const char *functions[FUNC_MAX] = {
- "inverse($)",
- "transpose($)"
- };
- String code;
- code += " " + p_output_vars[0] + " = " + String(functions[func]).replace("$", p_input_vars[0]) + ";\n";
- return code;
- }
- void VisualShaderNodeTransformFunc::set_function(Function p_func) {
- ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX));
- if (func == p_func) {
- return;
- }
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeTransformFunc::Function VisualShaderNodeTransformFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeTransformFunc::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeTransformFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeTransformFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeTransformFunc::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Inverse,Transpose"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_INVERSE);
- BIND_ENUM_CONSTANT(FUNC_TRANSPOSE);
- BIND_ENUM_CONSTANT(FUNC_MAX);
- }
- VisualShaderNodeTransformFunc::VisualShaderNodeTransformFunc() {
- set_input_port_default_value(0, Transform3D());
- }
- ////////////// UV Func
- String VisualShaderNodeUVFunc::get_caption() const {
- return "UVFunc";
- }
- int VisualShaderNodeUVFunc::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeUVFunc::PortType VisualShaderNodeUVFunc::get_input_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR_2D; // uv
- case 1:
- return PORT_TYPE_VECTOR_2D; // scale
- case 2:
- return PORT_TYPE_VECTOR_2D; // offset & pivot
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeUVFunc::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "uv";
- case 1:
- return "scale";
- case 2:
- switch (func) {
- case FUNC_PANNING:
- return "offset";
- case FUNC_SCALING:
- return "pivot";
- default:
- break;
- }
- break;
- default:
- break;
- }
- return "";
- }
- bool VisualShaderNodeUVFunc::is_input_port_default(int p_port, Shader::Mode p_mode) const {
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- if (p_port == 0) {
- return true;
- }
- }
- return false;
- }
- int VisualShaderNodeUVFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeUVFunc::PortType VisualShaderNodeUVFunc::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeUVFunc::get_output_port_name(int p_port) const {
- return "uv";
- }
- bool VisualShaderNodeUVFunc::is_show_prop_names() const {
- return true;
- }
- String VisualShaderNodeUVFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- String uv;
- if (p_input_vars[0].is_empty()) {
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- uv = "UV";
- } else {
- uv = "vec2(0.0)";
- }
- } else {
- uv = vformat("%s", p_input_vars[0]);
- }
- String scale = vformat("%s", p_input_vars[1]);
- String offset_pivot = vformat("%s", p_input_vars[2]);
- switch (func) {
- case FUNC_PANNING: {
- code += vformat(" %s = %s * %s + %s;\n", p_output_vars[0], offset_pivot, scale, uv);
- } break;
- case FUNC_SCALING: {
- code += vformat(" %s = (%s - %s) * %s + %s;\n", p_output_vars[0], uv, offset_pivot, scale, offset_pivot);
- } break;
- default:
- break;
- }
- return code;
- }
- void VisualShaderNodeUVFunc::set_function(VisualShaderNodeUVFunc::Function p_func) {
- ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX));
- if (func == p_func) {
- return;
- }
- if (p_func == FUNC_PANNING) {
- set_input_port_default_value(2, Vector2(), get_input_port_default_value(2)); // offset
- } else { // FUNC_SCALING
- set_input_port_default_value(2, Vector2(0.5, 0.5), get_input_port_default_value(2)); // pivot
- }
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeUVFunc::Function VisualShaderNodeUVFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeUVFunc::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeUVFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeUVFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeUVFunc::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Panning,Scaling"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_PANNING);
- BIND_ENUM_CONSTANT(FUNC_SCALING);
- BIND_ENUM_CONSTANT(FUNC_MAX);
- }
- VisualShaderNodeUVFunc::VisualShaderNodeUVFunc() {
- set_input_port_default_value(1, Vector2(1.0, 1.0)); // scale
- set_input_port_default_value(2, Vector2()); // offset
- }
- ////////////// UV PolarCoord
- String VisualShaderNodeUVPolarCoord::get_caption() const {
- return "UVPolarCoord";
- }
- int VisualShaderNodeUVPolarCoord::get_input_port_count() const {
- return 4;
- }
- VisualShaderNodeUVPolarCoord::PortType VisualShaderNodeUVPolarCoord::get_input_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR_2D; // uv
- case 1:
- return PORT_TYPE_VECTOR_2D; // center
- case 2:
- return PORT_TYPE_SCALAR; // zoom
- case 3:
- return PORT_TYPE_SCALAR; // repeat
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeUVPolarCoord::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "uv";
- case 1:
- return "scale";
- case 2:
- return "zoom strength";
- case 3:
- return "repeat";
- default:
- break;
- }
- return "";
- }
- bool VisualShaderNodeUVPolarCoord::is_input_port_default(int p_port, Shader::Mode p_mode) const {
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- if (p_port == 0) {
- return true;
- }
- }
- return false;
- }
- int VisualShaderNodeUVPolarCoord::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeUVPolarCoord::PortType VisualShaderNodeUVPolarCoord::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeUVPolarCoord::get_output_port_name(int p_port) const {
- return "uv";
- }
- String VisualShaderNodeUVPolarCoord::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- code += " {\n";
- String uv;
- if (p_input_vars[0].is_empty()) {
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- uv = "UV";
- } else {
- uv = "vec2(0.0)";
- }
- } else {
- uv = vformat("%s", p_input_vars[0]);
- }
- String center = vformat("%s", p_input_vars[1]);
- String zoom = vformat("%s", p_input_vars[2]);
- String repeat = vformat("%s", p_input_vars[3]);
- if (p_mode == Shader::MODE_CANVAS_ITEM) {
- code += vformat(" vec2 __dir = %s - %s;\n", uv, center);
- code += " float __radius = length(__dir) * 2.0;\n";
- code += " float __angle = atan(__dir.y, __dir.x) * 1.0 / (PI * 2.0);\n";
- code += vformat(" %s = mod(vec2(__radius * %s, __angle * %s), 1.0);\n", p_output_vars[0], zoom, repeat);
- } else {
- code += vformat(" vec2 __dir = %s - %s;\n", uv, center);
- code += " float __radius = length(__dir) * 2.0;\n";
- code += " float __angle = atan(__dir.y, __dir.x) * 1.0 / (PI * 2.0);\n";
- code += vformat(" %s = vec2(__radius * %s, __angle * %s);\n", p_output_vars[0], zoom, repeat);
- }
- code += " }\n";
- return code;
- }
- VisualShaderNodeUVPolarCoord::VisualShaderNodeUVPolarCoord() {
- set_input_port_default_value(1, Vector2(0.5, 0.5)); // center
- set_input_port_default_value(2, 1.0); // zoom
- set_input_port_default_value(3, 1.0); // repeat
- simple_decl = false;
- }
- ////////////// Dot Product
- String VisualShaderNodeDotProduct::get_caption() const {
- return "DotProduct";
- }
- int VisualShaderNodeDotProduct::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeDotProduct::PortType VisualShaderNodeDotProduct::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeDotProduct::get_input_port_name(int p_port) const {
- return p_port == 0 ? "a" : "b";
- }
- int VisualShaderNodeDotProduct::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeDotProduct::PortType VisualShaderNodeDotProduct::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeDotProduct::get_output_port_name(int p_port) const {
- return "dot";
- }
- String VisualShaderNodeDotProduct::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = dot(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- }
- VisualShaderNodeDotProduct::VisualShaderNodeDotProduct() {
- set_input_port_default_value(0, Vector3());
- set_input_port_default_value(1, Vector3());
- }
- ////////////// Vector Len
- String VisualShaderNodeVectorLen::get_caption() const {
- return "VectorLen";
- }
- int VisualShaderNodeVectorLen::get_input_port_count() const {
- return 1;
- }
- String VisualShaderNodeVectorLen::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeVectorLen::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorLen::PortType VisualShaderNodeVectorLen::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeVectorLen::get_output_port_name(int p_port) const {
- return "length";
- }
- void VisualShaderNodeVectorLen::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- String VisualShaderNodeVectorLen::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = length(" + p_input_vars[0] + ");\n";
- }
- VisualShaderNodeVectorLen::VisualShaderNodeVectorLen() {
- set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0));
- }
- ////////////// Determinant
- String VisualShaderNodeDeterminant::get_caption() const {
- return "Determinant";
- }
- int VisualShaderNodeDeterminant::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeDeterminant::PortType VisualShaderNodeDeterminant::get_input_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeDeterminant::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeDeterminant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeDeterminant::PortType VisualShaderNodeDeterminant::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeDeterminant::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeDeterminant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = determinant(" + p_input_vars[0] + ");\n";
- }
- VisualShaderNodeDeterminant::VisualShaderNodeDeterminant() {
- set_input_port_default_value(0, Transform3D());
- }
- ////////////// Derivative Function
- String VisualShaderNodeDerivativeFunc::get_caption() const {
- return "DerivativeFunc";
- }
- int VisualShaderNodeDerivativeFunc::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeDerivativeFunc::PortType VisualShaderNodeDerivativeFunc::get_input_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_4D:
- return PORT_TYPE_VECTOR_4D;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeDerivativeFunc::get_input_port_name(int p_port) const {
- return "p";
- }
- int VisualShaderNodeDerivativeFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeDerivativeFunc::PortType VisualShaderNodeDerivativeFunc::get_output_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_3D:
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_4D:
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeDerivativeFunc::get_output_port_name(int p_port) const {
- return "result";
- }
- String VisualShaderNodeDerivativeFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- static const char *functions[FUNC_MAX] = {
- "fwidth$($)",
- "dFdx$($)",
- "dFdy$($)"
- };
- static const char *precisions[PRECISION_MAX] = {
- "",
- "Coarse",
- "Fine"
- };
- String code;
- if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
- code += " " + p_output_vars[0] + " = " + String(functions[func]).replace_first("$", "").replace_first("$", p_input_vars[0]) + ";\n";
- return code;
- }
- code += " " + p_output_vars[0] + " = " + String(functions[func]).replace_first("$", String(precisions[precision])).replace_first("$", p_input_vars[0]) + ";\n";
- return code;
- }
- String VisualShaderNodeDerivativeFunc::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const {
- if (precision != PRECISION_NONE && OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
- String precision_str;
- switch (precision) {
- case PRECISION_COARSE: {
- precision_str = "Coarse";
- } break;
- case PRECISION_FINE: {
- precision_str = "Fine";
- } break;
- default: {
- } break;
- }
- return vformat(RTR("`%s` precision mode is not available for `gl_compatibility` profile.\nReverted to `None` precision."), precision_str);
- }
- return String();
- }
- void VisualShaderNodeDerivativeFunc::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX((int)p_op_type, int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_SCALAR: {
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0));
- } break;
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- VisualShaderNodeDerivativeFunc::OpType VisualShaderNodeDerivativeFunc::get_op_type() const {
- return op_type;
- }
- void VisualShaderNodeDerivativeFunc::set_function(Function p_func) {
- ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX));
- if (func == p_func) {
- return;
- }
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeDerivativeFunc::Function VisualShaderNodeDerivativeFunc::get_function() const {
- return func;
- }
- void VisualShaderNodeDerivativeFunc::set_precision(Precision p_precision) {
- ERR_FAIL_INDEX(int(p_precision), int(PRECISION_MAX));
- if (precision == p_precision) {
- return;
- }
- precision = p_precision;
- emit_changed();
- }
- VisualShaderNodeDerivativeFunc::Precision VisualShaderNodeDerivativeFunc::get_precision() const {
- return precision;
- }
- Vector<StringName> VisualShaderNodeDerivativeFunc::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("op_type");
- props.push_back("function");
- props.push_back("precision");
- return props;
- }
- void VisualShaderNodeDerivativeFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_op_type", "type"), &VisualShaderNodeDerivativeFunc::set_op_type);
- ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeDerivativeFunc::get_op_type);
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeDerivativeFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeDerivativeFunc::get_function);
- ClassDB::bind_method(D_METHOD("set_precision", "precision"), &VisualShaderNodeDerivativeFunc::set_precision);
- ClassDB::bind_method(D_METHOD("get_precision"), &VisualShaderNodeDerivativeFunc::get_precision);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector3,Vector4"), "set_op_type", "get_op_type");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Sum,X,Y"), "set_function", "get_function");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "precision", PROPERTY_HINT_ENUM, "None,Coarse,Fine"), "set_precision", "get_precision");
- BIND_ENUM_CONSTANT(OP_TYPE_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D);
- BIND_ENUM_CONSTANT(OP_TYPE_MAX);
- BIND_ENUM_CONSTANT(FUNC_SUM);
- BIND_ENUM_CONSTANT(FUNC_X);
- BIND_ENUM_CONSTANT(FUNC_Y);
- BIND_ENUM_CONSTANT(FUNC_MAX);
- BIND_ENUM_CONSTANT(PRECISION_NONE);
- BIND_ENUM_CONSTANT(PRECISION_COARSE);
- BIND_ENUM_CONSTANT(PRECISION_FINE);
- BIND_ENUM_CONSTANT(PRECISION_MAX);
- }
- VisualShaderNodeDerivativeFunc::VisualShaderNodeDerivativeFunc() {
- set_input_port_default_value(0, 0.0);
- }
- ////////////// Clamp
- String VisualShaderNodeClamp::get_caption() const {
- return "Clamp";
- }
- int VisualShaderNodeClamp::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeClamp::PortType VisualShaderNodeClamp::get_input_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_INT:
- return PORT_TYPE_SCALAR_INT;
- case OP_TYPE_UINT:
- return PORT_TYPE_SCALAR_UINT;
- case OP_TYPE_VECTOR_2D:
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_4D:
- return PORT_TYPE_VECTOR_4D;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeClamp::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "";
- } else if (p_port == 1) {
- return "min";
- } else if (p_port == 2) {
- return "max";
- }
- return "";
- }
- int VisualShaderNodeClamp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeClamp::PortType VisualShaderNodeClamp::get_output_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_INT:
- return PORT_TYPE_SCALAR_INT;
- case OP_TYPE_UINT:
- return PORT_TYPE_SCALAR_UINT;
- case OP_TYPE_VECTOR_2D:
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_3D:
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_4D:
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeClamp::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeClamp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = clamp(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- void VisualShaderNodeClamp::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX((int)p_op_type, int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_FLOAT:
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0));
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1));
- set_input_port_default_value(2, 0.0, get_input_port_default_value(2));
- break;
- case OP_TYPE_UINT:
- case OP_TYPE_INT:
- set_input_port_default_value(0, 0, get_input_port_default_value(0));
- set_input_port_default_value(1, 0, get_input_port_default_value(1));
- set_input_port_default_value(2, 0, get_input_port_default_value(2));
- break;
- case OP_TYPE_VECTOR_2D:
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector2(), get_input_port_default_value(2));
- break;
- case OP_TYPE_VECTOR_3D:
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector3(), get_input_port_default_value(2));
- break;
- case OP_TYPE_VECTOR_4D:
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1));
- set_input_port_default_value(2, Quaternion(), get_input_port_default_value(2));
- break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- VisualShaderNodeClamp::OpType VisualShaderNodeClamp::get_op_type() const {
- return op_type;
- }
- Vector<StringName> VisualShaderNodeClamp::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("op_type");
- return props;
- }
- void VisualShaderNodeClamp::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_op_type", "op_type"), &VisualShaderNodeClamp::set_op_type);
- ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeClamp::get_op_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Float,Int,UInt,Vector2,Vector3,Vector4"), "set_op_type", "get_op_type");
- BIND_ENUM_CONSTANT(OP_TYPE_FLOAT);
- BIND_ENUM_CONSTANT(OP_TYPE_INT);
- BIND_ENUM_CONSTANT(OP_TYPE_UINT);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D);
- BIND_ENUM_CONSTANT(OP_TYPE_MAX);
- }
- VisualShaderNodeClamp::VisualShaderNodeClamp() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, 1.0);
- }
- ////////////// FaceForward
- String VisualShaderNodeFaceForward::get_caption() const {
- return "FaceForward";
- }
- int VisualShaderNodeFaceForward::get_input_port_count() const {
- return 3;
- }
- String VisualShaderNodeFaceForward::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "N";
- case 1:
- return "I";
- case 2:
- return "Nref";
- default:
- return "";
- }
- }
- int VisualShaderNodeFaceForward::get_output_port_count() const {
- return 1;
- }
- String VisualShaderNodeFaceForward::get_output_port_name(int p_port) const {
- return "";
- }
- void VisualShaderNodeFaceForward::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector2(), get_input_port_default_value(2));
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector3(), get_input_port_default_value(2));
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1));
- set_input_port_default_value(2, Quaternion(), get_input_port_default_value(2));
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- String VisualShaderNodeFaceForward::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = faceforward(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- VisualShaderNodeFaceForward::VisualShaderNodeFaceForward() {
- set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0));
- set_input_port_default_value(1, Vector3(0.0, 0.0, 0.0));
- set_input_port_default_value(2, Vector3(0.0, 0.0, 0.0));
- }
- ////////////// Outer Product
- String VisualShaderNodeOuterProduct::get_caption() const {
- return "OuterProduct";
- }
- int VisualShaderNodeOuterProduct::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeOuterProduct::PortType VisualShaderNodeOuterProduct::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeOuterProduct::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "c";
- case 1:
- return "r";
- default:
- return "";
- }
- }
- int VisualShaderNodeOuterProduct::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeOuterProduct::PortType VisualShaderNodeOuterProduct::get_output_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeOuterProduct::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeOuterProduct::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = outerProduct(vec4(" + p_input_vars[0] + ", 0.0), vec4(" + p_input_vars[1] + ", 0.0));\n";
- }
- VisualShaderNodeOuterProduct::VisualShaderNodeOuterProduct() {
- set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0));
- set_input_port_default_value(1, Vector3(0.0, 0.0, 0.0));
- }
- ////////////// Step
- String VisualShaderNodeStep::get_caption() const {
- return "Step";
- }
- int VisualShaderNodeStep::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeStep::PortType VisualShaderNodeStep::get_input_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_2D_SCALAR:
- if (p_port == 1) {
- return PORT_TYPE_VECTOR_2D;
- }
- break;
- case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_3D_SCALAR:
- if (p_port == 1) {
- return PORT_TYPE_VECTOR_3D;
- }
- break;
- case OP_TYPE_VECTOR_4D:
- return PORT_TYPE_VECTOR_4D;
- case OP_TYPE_VECTOR_4D_SCALAR:
- if (p_port == 1) {
- return PORT_TYPE_VECTOR_4D;
- }
- break;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeStep::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "edge";
- case 1:
- return "x";
- }
- return String();
- }
- int VisualShaderNodeStep::get_default_input_port(PortType p_type) const {
- return 1;
- }
- int VisualShaderNodeStep::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeStep::PortType VisualShaderNodeStep::get_output_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- case OP_TYPE_VECTOR_2D_SCALAR:
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_3D:
- case OP_TYPE_VECTOR_3D_SCALAR:
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_4D:
- case OP_TYPE_VECTOR_4D_SCALAR:
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeStep::get_output_port_name(int p_port) const {
- return "";
- }
- void VisualShaderNodeStep::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_SCALAR: {
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0));
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1));
- } break;
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1));
- } break;
- case OP_TYPE_VECTOR_2D_SCALAR: {
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0));
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1));
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1));
- } break;
- case OP_TYPE_VECTOR_3D_SCALAR: {
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0));
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1));
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1));
- } break;
- case OP_TYPE_VECTOR_4D_SCALAR: {
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0));
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1));
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- VisualShaderNodeStep::OpType VisualShaderNodeStep::get_op_type() const {
- return op_type;
- }
- String VisualShaderNodeStep::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- }
- Vector<StringName> VisualShaderNodeStep::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("op_type");
- return props;
- }
- void VisualShaderNodeStep::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_op_type", "op_type"), &VisualShaderNodeStep::set_op_type);
- ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeStep::get_op_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector2Scalar,Vector3,Vector3Scalar,Vector4,Vector4Scalar"), "set_op_type", "get_op_type");
- BIND_ENUM_CONSTANT(OP_TYPE_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_MAX);
- }
- VisualShaderNodeStep::VisualShaderNodeStep() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- }
- ////////////// SmoothStep
- String VisualShaderNodeSmoothStep::get_caption() const {
- return "SmoothStep";
- }
- int VisualShaderNodeSmoothStep::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeSmoothStep::PortType VisualShaderNodeSmoothStep::get_input_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_2D_SCALAR:
- if (p_port == 2) {
- return PORT_TYPE_VECTOR_2D; // x
- }
- break;
- case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_3D_SCALAR:
- if (p_port == 2) {
- return PORT_TYPE_VECTOR_3D; // x
- }
- break;
- case OP_TYPE_VECTOR_4D:
- return PORT_TYPE_VECTOR_4D;
- case OP_TYPE_VECTOR_4D_SCALAR:
- if (p_port == 2) {
- return PORT_TYPE_VECTOR_4D; // x
- }
- break;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeSmoothStep::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "edge0";
- case 1:
- return "edge1";
- case 2:
- return "x";
- }
- return String();
- }
- int VisualShaderNodeSmoothStep::get_default_input_port(PortType p_type) const {
- return 2;
- }
- int VisualShaderNodeSmoothStep::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeSmoothStep::PortType VisualShaderNodeSmoothStep::get_output_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- case OP_TYPE_VECTOR_2D_SCALAR:
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_3D:
- case OP_TYPE_VECTOR_3D_SCALAR:
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_4D:
- case OP_TYPE_VECTOR_4D_SCALAR:
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeSmoothStep::get_output_port_name(int p_port) const {
- return "";
- }
- void VisualShaderNodeSmoothStep::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_SCALAR:
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0)); // edge0
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1)); // edge1
- set_input_port_default_value(2, 0.0, get_input_port_default_value(2)); // x
- break;
- case OP_TYPE_VECTOR_2D:
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0)); // edge0
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1)); // edge1
- set_input_port_default_value(2, Vector2(), get_input_port_default_value(2)); // x
- break;
- case OP_TYPE_VECTOR_2D_SCALAR:
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0)); // edge0
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1)); // edge1
- set_input_port_default_value(2, Vector2(), get_input_port_default_value(2)); // x
- break;
- case OP_TYPE_VECTOR_3D:
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0)); // edge0
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1)); // edge1
- set_input_port_default_value(2, Vector3(), get_input_port_default_value(2)); // x
- break;
- case OP_TYPE_VECTOR_3D_SCALAR:
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0)); // edge0
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1)); // edge1
- set_input_port_default_value(2, Vector3(), get_input_port_default_value(2)); // x
- break;
- case OP_TYPE_VECTOR_4D:
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0)); // edge0
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1)); // edge1
- set_input_port_default_value(2, Quaternion(), get_input_port_default_value(2)); // x
- break;
- case OP_TYPE_VECTOR_4D_SCALAR:
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0)); // edge0
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1)); // edge1
- set_input_port_default_value(2, Quaternion(), get_input_port_default_value(2)); // x
- break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- VisualShaderNodeSmoothStep::OpType VisualShaderNodeSmoothStep::get_op_type() const {
- return op_type;
- }
- String VisualShaderNodeSmoothStep::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = smoothstep(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- Vector<StringName> VisualShaderNodeSmoothStep::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("op_type");
- return props;
- }
- void VisualShaderNodeSmoothStep::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_op_type", "op_type"), &VisualShaderNodeSmoothStep::set_op_type);
- ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeSmoothStep::get_op_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector2Scalar,Vector3,Vector3Scalar,Vector4,Vector4Scalar"), "set_op_type", "get_op_type");
- BIND_ENUM_CONSTANT(OP_TYPE_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_MAX);
- }
- VisualShaderNodeSmoothStep::VisualShaderNodeSmoothStep() {
- set_input_port_default_value(0, 0.0); // edge0
- set_input_port_default_value(1, 1.0); // edge1
- set_input_port_default_value(2, 0.5); // x
- }
- ////////////// Distance
- String VisualShaderNodeVectorDistance::get_caption() const {
- return "Distance";
- }
- int VisualShaderNodeVectorDistance::get_input_port_count() const {
- return 2;
- }
- String VisualShaderNodeVectorDistance::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "a";
- case 1:
- return "b";
- }
- return String();
- }
- int VisualShaderNodeVectorDistance::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorDistance::PortType VisualShaderNodeVectorDistance::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeVectorDistance::get_output_port_name(int p_port) const {
- return "";
- }
- void VisualShaderNodeVectorDistance::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0)); // a
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1)); // b
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0)); // a
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1)); // b
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0)); // a
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1)); // b
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- String VisualShaderNodeVectorDistance::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = distance(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- }
- VisualShaderNodeVectorDistance::VisualShaderNodeVectorDistance() {
- set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0)); // a
- set_input_port_default_value(1, Vector3(0.0, 0.0, 0.0)); // b
- }
- ////////////// Refract Vector
- String VisualShaderNodeVectorRefract::get_caption() const {
- return "Refract";
- }
- int VisualShaderNodeVectorRefract::get_input_port_count() const {
- return 3;
- }
- String VisualShaderNodeVectorRefract::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "I";
- case 1:
- return "N";
- case 2:
- return "eta";
- }
- return String();
- }
- int VisualShaderNodeVectorRefract::get_output_port_count() const {
- return 1;
- }
- String VisualShaderNodeVectorRefract::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeVectorRefract::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = refract(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- void VisualShaderNodeVectorRefract::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1));
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1));
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1));
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- VisualShaderNodeVectorRefract::VisualShaderNodeVectorRefract() {
- set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0));
- set_input_port_default_value(1, Vector3(0.0, 0.0, 0.0));
- set_input_port_default_value(2, 0.0);
- }
- ////////////// Mix
- String VisualShaderNodeMix::get_caption() const {
- return "Mix";
- }
- int VisualShaderNodeMix::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeMix::PortType VisualShaderNodeMix::get_input_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_2D_SCALAR:
- if (p_port == 2) {
- break;
- }
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_3D_SCALAR:
- if (p_port == 2) {
- break;
- }
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_4D:
- return PORT_TYPE_VECTOR_4D;
- case OP_TYPE_VECTOR_4D_SCALAR:
- if (p_port == 2) {
- break;
- }
- return PORT_TYPE_VECTOR_4D;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeMix::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "a";
- } else if (p_port == 1) {
- return "b";
- } else {
- return "weight";
- }
- }
- int VisualShaderNodeMix::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeMix::PortType VisualShaderNodeMix::get_output_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- case OP_TYPE_VECTOR_2D_SCALAR:
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_3D:
- case OP_TYPE_VECTOR_3D_SCALAR:
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_4D:
- case OP_TYPE_VECTOR_4D_SCALAR:
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeMix::get_output_port_name(int p_port) const {
- return "mix";
- }
- void VisualShaderNodeMix::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_SCALAR: {
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0)); // a
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1)); // b
- set_input_port_default_value(2, 0.0, get_input_port_default_value(2)); // weight
- } break;
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0)); // a
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1)); // b
- set_input_port_default_value(2, Vector2(), get_input_port_default_value(2)); // weight
- } break;
- case OP_TYPE_VECTOR_2D_SCALAR: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0)); // a
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1)); // b
- set_input_port_default_value(2, 0.0, get_input_port_default_value(2)); // weight
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0)); // a
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1)); // b
- set_input_port_default_value(2, Vector3(), get_input_port_default_value(2)); // weight
- } break;
- case OP_TYPE_VECTOR_3D_SCALAR: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0)); // a
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1)); // b
- set_input_port_default_value(2, 0.0, get_input_port_default_value(2)); // weight
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0)); // a
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1)); // b
- set_input_port_default_value(2, Quaternion(), get_input_port_default_value(2)); // weight
- } break;
- case OP_TYPE_VECTOR_4D_SCALAR: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0)); // a
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1)); // b
- set_input_port_default_value(2, 0.0, get_input_port_default_value(2)); // weight
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- VisualShaderNodeMix::OpType VisualShaderNodeMix::get_op_type() const {
- return op_type;
- }
- String VisualShaderNodeMix::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = mix(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- Vector<StringName> VisualShaderNodeMix::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("op_type");
- return props;
- }
- void VisualShaderNodeMix::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_op_type", "op_type"), &VisualShaderNodeMix::set_op_type);
- ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeMix::get_op_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector2Scalar,Vector3,Vector3Scalar,Vector4,Vector4Scalar"), "set_op_type", "get_op_type");
- BIND_ENUM_CONSTANT(OP_TYPE_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_MAX);
- }
- VisualShaderNodeMix::VisualShaderNodeMix() {
- set_input_port_default_value(0, 0.0); // a
- set_input_port_default_value(1, 1.0); // b
- set_input_port_default_value(2, 0.5); // weight
- }
- ////////////// Vector Compose
- String VisualShaderNodeVectorCompose::get_caption() const {
- return "VectorCompose";
- }
- int VisualShaderNodeVectorCompose::get_input_port_count() const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return 2;
- case OP_TYPE_VECTOR_3D:
- return 3;
- case OP_TYPE_VECTOR_4D:
- return 4;
- default:
- break;
- }
- return 0;
- }
- VisualShaderNodeVectorCompose::PortType VisualShaderNodeVectorCompose::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeVectorCompose::get_input_port_name(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D: {
- switch (p_port) {
- case 0:
- return "x";
- case 1:
- return "y";
- }
- } break;
- case OP_TYPE_VECTOR_3D: {
- switch (p_port) {
- case 0:
- return "x";
- case 1:
- return "y";
- case 2:
- return "z";
- }
- } break;
- case OP_TYPE_VECTOR_4D: {
- switch (p_port) {
- case 0:
- return "x";
- case 1:
- return "y";
- case 2:
- return "z";
- case 3:
- return "w";
- }
- } break;
- default:
- break;
- }
- return String();
- }
- int VisualShaderNodeVectorCompose::get_output_port_count() const {
- return 1;
- }
- String VisualShaderNodeVectorCompose::get_output_port_name(int p_port) const {
- return "vec";
- }
- void VisualShaderNodeVectorCompose::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_VECTOR_2D: {
- float p1 = get_input_port_default_value(0);
- float p2 = get_input_port_default_value(1);
- set_input_port_default_value(0, p1);
- set_input_port_default_value(1, p2);
- } break;
- case OP_TYPE_VECTOR_3D: {
- float p1 = get_input_port_default_value(0);
- float p2 = get_input_port_default_value(1);
- set_input_port_default_value(0, p1);
- set_input_port_default_value(1, p2);
- set_input_port_default_value(2, 0.0);
- } break;
- case OP_TYPE_VECTOR_4D: {
- float p1 = get_input_port_default_value(0);
- float p2 = get_input_port_default_value(1);
- set_input_port_default_value(0, p1);
- set_input_port_default_value(1, p2);
- set_input_port_default_value(2, 0.0);
- set_input_port_default_value(3, 0.0);
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- String VisualShaderNodeVectorCompose::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- switch (op_type) {
- case OP_TYPE_VECTOR_2D: {
- code += " " + p_output_vars[0] + " = vec2(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- } break;
- case OP_TYPE_VECTOR_3D: {
- code += " " + p_output_vars[0] + " = vec3(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- } break;
- case OP_TYPE_VECTOR_4D: {
- code += " " + p_output_vars[0] + " = vec4(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ", " + p_input_vars[3] + ");\n";
- } break;
- default:
- break;
- }
- return code;
- }
- VisualShaderNodeVectorCompose::VisualShaderNodeVectorCompose() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, 0.0);
- }
- ////////////// Transform Compose
- String VisualShaderNodeTransformCompose::get_caption() const {
- return "TransformCompose";
- }
- int VisualShaderNodeTransformCompose::get_input_port_count() const {
- return 4;
- }
- VisualShaderNodeTransformCompose::PortType VisualShaderNodeTransformCompose::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeTransformCompose::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "x";
- } else if (p_port == 1) {
- return "y";
- } else if (p_port == 2) {
- return "z";
- } else {
- return "origin";
- }
- }
- int VisualShaderNodeTransformCompose::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeTransformCompose::PortType VisualShaderNodeTransformCompose::get_output_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformCompose::get_output_port_name(int p_port) const {
- return "xform";
- }
- String VisualShaderNodeTransformCompose::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = mat4(vec4(" + p_input_vars[0] + ", 0.0), vec4(" + p_input_vars[1] + ", 0.0), vec4(" + p_input_vars[2] + ", 0.0), vec4(" + p_input_vars[3] + ", 1.0));\n";
- }
- VisualShaderNodeTransformCompose::VisualShaderNodeTransformCompose() {
- set_input_port_default_value(0, Vector3());
- set_input_port_default_value(1, Vector3());
- set_input_port_default_value(2, Vector3());
- set_input_port_default_value(3, Vector3());
- }
- ////////////// Vector Decompose
- String VisualShaderNodeVectorDecompose::get_caption() const {
- return "VectorDecompose";
- }
- int VisualShaderNodeVectorDecompose::get_input_port_count() const {
- return 1;
- }
- String VisualShaderNodeVectorDecompose::get_input_port_name(int p_port) const {
- return "vec";
- }
- int VisualShaderNodeVectorDecompose::get_output_port_count() const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return 2;
- case OP_TYPE_VECTOR_3D:
- return 3;
- case OP_TYPE_VECTOR_4D:
- return 4;
- default:
- break;
- }
- return 0;
- }
- VisualShaderNodeVectorDecompose::PortType VisualShaderNodeVectorDecompose::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeVectorDecompose::get_output_port_name(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D: {
- switch (p_port) {
- case 0:
- return "x";
- case 1:
- return "y";
- }
- } break;
- case OP_TYPE_VECTOR_3D: {
- switch (p_port) {
- case 0:
- return "x";
- case 1:
- return "y";
- case 2:
- return "z";
- }
- } break;
- case OP_TYPE_VECTOR_4D: {
- switch (p_port) {
- case 0:
- return "x";
- case 1:
- return "y";
- case 2:
- return "z";
- case 3:
- return "w";
- }
- } break;
- default:
- break;
- }
- return String();
- }
- void VisualShaderNodeVectorDecompose::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- String VisualShaderNodeVectorDecompose::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- switch (op_type) {
- case OP_TYPE_VECTOR_2D: {
- code += " " + p_output_vars[0] + " = " + p_input_vars[0] + ".x;\n";
- code += " " + p_output_vars[1] + " = " + p_input_vars[0] + ".y;\n";
- } break;
- case OP_TYPE_VECTOR_3D: {
- code += " " + p_output_vars[0] + " = " + p_input_vars[0] + ".x;\n";
- code += " " + p_output_vars[1] + " = " + p_input_vars[0] + ".y;\n";
- code += " " + p_output_vars[2] + " = " + p_input_vars[0] + ".z;\n";
- } break;
- case OP_TYPE_VECTOR_4D: {
- code += " " + p_output_vars[0] + " = " + p_input_vars[0] + ".x;\n";
- code += " " + p_output_vars[1] + " = " + p_input_vars[0] + ".y;\n";
- code += " " + p_output_vars[2] + " = " + p_input_vars[0] + ".z;\n";
- code += " " + p_output_vars[3] + " = " + p_input_vars[0] + ".w;\n";
- } break;
- default:
- break;
- }
- return code;
- }
- VisualShaderNodeVectorDecompose::VisualShaderNodeVectorDecompose() {
- set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0));
- }
- ////////////// Transform Decompose
- String VisualShaderNodeTransformDecompose::get_caption() const {
- return "TransformDecompose";
- }
- int VisualShaderNodeTransformDecompose::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeTransformDecompose::PortType VisualShaderNodeTransformDecompose::get_input_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformDecompose::get_input_port_name(int p_port) const {
- return "xform";
- }
- int VisualShaderNodeTransformDecompose::get_output_port_count() const {
- return 4;
- }
- VisualShaderNodeTransformDecompose::PortType VisualShaderNodeTransformDecompose::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeTransformDecompose::get_output_port_name(int p_port) const {
- if (p_port == 0) {
- return "x";
- } else if (p_port == 1) {
- return "y";
- } else if (p_port == 2) {
- return "z";
- } else {
- return "origin";
- }
- }
- String VisualShaderNodeTransformDecompose::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- code += " " + p_output_vars[0] + " = " + p_input_vars[0] + "[0].xyz;\n";
- code += " " + p_output_vars[1] + " = " + p_input_vars[0] + "[1].xyz;\n";
- code += " " + p_output_vars[2] + " = " + p_input_vars[0] + "[2].xyz;\n";
- code += " " + p_output_vars[3] + " = " + p_input_vars[0] + "[3].xyz;\n";
- return code;
- }
- VisualShaderNodeTransformDecompose::VisualShaderNodeTransformDecompose() {
- set_input_port_default_value(0, Transform3D());
- }
- ////////////// Float Parameter
- String VisualShaderNodeFloatParameter::get_caption() const {
- return "FloatParameter";
- }
- int VisualShaderNodeFloatParameter::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeFloatParameter::PortType VisualShaderNodeFloatParameter::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeFloatParameter::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeFloatParameter::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeFloatParameter::PortType VisualShaderNodeFloatParameter::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeFloatParameter::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeFloatParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "";
- if (hint == HINT_RANGE) {
- code += _get_qual_str() + "uniform float " + get_parameter_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ")";
- } else if (hint == HINT_RANGE_STEP) {
- code += _get_qual_str() + "uniform float " + get_parameter_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ", " + rtos(hint_range_step) + ")";
- } else {
- code += _get_qual_str() + "uniform float " + get_parameter_name();
- }
- if (default_value_enabled) {
- code += " = " + rtos(default_value);
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeFloatParameter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + get_parameter_name() + ";\n";
- }
- bool VisualShaderNodeFloatParameter::is_show_prop_names() const {
- return true;
- }
- bool VisualShaderNodeFloatParameter::is_use_prop_slots() const {
- return true;
- }
- void VisualShaderNodeFloatParameter::set_hint(Hint p_hint) {
- ERR_FAIL_INDEX(int(p_hint), int(HINT_MAX));
- if (hint == p_hint) {
- return;
- }
- hint = p_hint;
- emit_changed();
- }
- VisualShaderNodeFloatParameter::Hint VisualShaderNodeFloatParameter::get_hint() const {
- return hint;
- }
- void VisualShaderNodeFloatParameter::set_min(float p_value) {
- if (Math::is_equal_approx(hint_range_min, p_value)) {
- return;
- }
- hint_range_min = p_value;
- emit_changed();
- }
- float VisualShaderNodeFloatParameter::get_min() const {
- return hint_range_min;
- }
- void VisualShaderNodeFloatParameter::set_max(float p_value) {
- if (Math::is_equal_approx(hint_range_max, p_value)) {
- return;
- }
- hint_range_max = p_value;
- emit_changed();
- }
- float VisualShaderNodeFloatParameter::get_max() const {
- return hint_range_max;
- }
- void VisualShaderNodeFloatParameter::set_step(float p_value) {
- if (Math::is_equal_approx(hint_range_step, p_value)) {
- return;
- }
- hint_range_step = p_value;
- emit_changed();
- }
- float VisualShaderNodeFloatParameter::get_step() const {
- return hint_range_step;
- }
- void VisualShaderNodeFloatParameter::set_default_value_enabled(bool p_enabled) {
- if (default_value_enabled == p_enabled) {
- return;
- }
- default_value_enabled = p_enabled;
- emit_changed();
- }
- bool VisualShaderNodeFloatParameter::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeFloatParameter::set_default_value(float p_value) {
- if (Math::is_equal_approx(default_value, p_value)) {
- return;
- }
- default_value = p_value;
- emit_changed();
- }
- float VisualShaderNodeFloatParameter::get_default_value() const {
- return default_value;
- }
- void VisualShaderNodeFloatParameter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_hint", "hint"), &VisualShaderNodeFloatParameter::set_hint);
- ClassDB::bind_method(D_METHOD("get_hint"), &VisualShaderNodeFloatParameter::get_hint);
- ClassDB::bind_method(D_METHOD("set_min", "value"), &VisualShaderNodeFloatParameter::set_min);
- ClassDB::bind_method(D_METHOD("get_min"), &VisualShaderNodeFloatParameter::get_min);
- ClassDB::bind_method(D_METHOD("set_max", "value"), &VisualShaderNodeFloatParameter::set_max);
- ClassDB::bind_method(D_METHOD("get_max"), &VisualShaderNodeFloatParameter::get_max);
- ClassDB::bind_method(D_METHOD("set_step", "value"), &VisualShaderNodeFloatParameter::set_step);
- ClassDB::bind_method(D_METHOD("get_step"), &VisualShaderNodeFloatParameter::get_step);
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeFloatParameter::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeFloatParameter::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeFloatParameter::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeFloatParameter::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "hint", PROPERTY_HINT_ENUM, "None,Range,Range+Step"), "set_hint", "get_hint");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "min"), "set_min", "get_min");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max"), "set_max", "get_max");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "step"), "set_step", "get_step");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "default_value"), "set_default_value", "get_default_value");
- BIND_ENUM_CONSTANT(HINT_NONE);
- BIND_ENUM_CONSTANT(HINT_RANGE);
- BIND_ENUM_CONSTANT(HINT_RANGE_STEP);
- BIND_ENUM_CONSTANT(HINT_MAX);
- }
- bool VisualShaderNodeFloatParameter::is_qualifier_supported(Qualifier p_qual) const {
- return true; // all qualifiers are supported
- }
- bool VisualShaderNodeFloatParameter::is_convertible_to_constant() const {
- return true; // conversion is allowed
- }
- Vector<StringName> VisualShaderNodeFloatParameter::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties();
- props.push_back("hint");
- if (hint == HINT_RANGE || hint == HINT_RANGE_STEP) {
- props.push_back("min");
- props.push_back("max");
- }
- if (hint == HINT_RANGE_STEP) {
- props.push_back("step");
- }
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeFloatParameter::VisualShaderNodeFloatParameter() {
- }
- ////////////// Integer Parameter
- String VisualShaderNodeIntParameter::get_caption() const {
- return "IntParameter";
- }
- int VisualShaderNodeIntParameter::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeIntParameter::PortType VisualShaderNodeIntParameter::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_INT;
- }
- String VisualShaderNodeIntParameter::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeIntParameter::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeIntParameter::PortType VisualShaderNodeIntParameter::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_INT;
- }
- String VisualShaderNodeIntParameter::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeIntParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "";
- if (hint == HINT_RANGE) {
- code += _get_qual_str() + "uniform int " + get_parameter_name() + " : hint_range(" + itos(hint_range_min) + ", " + itos(hint_range_max) + ")";
- } else if (hint == HINT_RANGE_STEP) {
- code += _get_qual_str() + "uniform int " + get_parameter_name() + " : hint_range(" + itos(hint_range_min) + ", " + itos(hint_range_max) + ", " + itos(hint_range_step) + ")";
- } else if (hint == HINT_ENUM) {
- code += _get_qual_str() + "uniform int " + get_parameter_name() + " : hint_enum(";
- bool first = true;
- for (const String &_name : hint_enum_names) {
- if (first) {
- first = false;
- } else {
- code += ", ";
- }
- code += "\"" + _name.c_escape() + "\"";
- }
- code += ")";
- } else {
- code += _get_qual_str() + "uniform int " + get_parameter_name();
- }
- if (default_value_enabled) {
- code += " = " + itos(default_value);
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeIntParameter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + get_parameter_name() + ";\n";
- }
- bool VisualShaderNodeIntParameter::is_show_prop_names() const {
- return true;
- }
- bool VisualShaderNodeIntParameter::is_use_prop_slots() const {
- return true;
- }
- void VisualShaderNodeIntParameter::set_hint(Hint p_hint) {
- ERR_FAIL_INDEX(int(p_hint), int(HINT_MAX));
- if (hint == p_hint) {
- return;
- }
- hint = p_hint;
- emit_changed();
- }
- VisualShaderNodeIntParameter::Hint VisualShaderNodeIntParameter::get_hint() const {
- return hint;
- }
- void VisualShaderNodeIntParameter::set_min(int p_value) {
- if (hint_range_min == p_value) {
- return;
- }
- hint_range_min = p_value;
- emit_changed();
- }
- int VisualShaderNodeIntParameter::get_min() const {
- return hint_range_min;
- }
- void VisualShaderNodeIntParameter::set_max(int p_value) {
- if (hint_range_max == p_value) {
- return;
- }
- hint_range_max = p_value;
- emit_changed();
- }
- int VisualShaderNodeIntParameter::get_max() const {
- return hint_range_max;
- }
- void VisualShaderNodeIntParameter::set_step(int p_value) {
- if (hint_range_step == p_value) {
- return;
- }
- hint_range_step = p_value;
- emit_changed();
- }
- int VisualShaderNodeIntParameter::get_step() const {
- return hint_range_step;
- }
- void VisualShaderNodeIntParameter::set_enum_names(const PackedStringArray &p_names) {
- if (hint_enum_names == p_names) {
- return;
- }
- hint_enum_names = p_names;
- emit_changed();
- }
- PackedStringArray VisualShaderNodeIntParameter::get_enum_names() const {
- return hint_enum_names;
- }
- void VisualShaderNodeIntParameter::set_default_value_enabled(bool p_default_value_enabled) {
- if (default_value_enabled == p_default_value_enabled) {
- return;
- }
- default_value_enabled = p_default_value_enabled;
- emit_changed();
- }
- bool VisualShaderNodeIntParameter::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeIntParameter::set_default_value(int p_default_value) {
- if (default_value == p_default_value) {
- return;
- }
- default_value = p_default_value;
- emit_changed();
- }
- int VisualShaderNodeIntParameter::get_default_value() const {
- return default_value;
- }
- void VisualShaderNodeIntParameter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_hint", "hint"), &VisualShaderNodeIntParameter::set_hint);
- ClassDB::bind_method(D_METHOD("get_hint"), &VisualShaderNodeIntParameter::get_hint);
- ClassDB::bind_method(D_METHOD("set_min", "value"), &VisualShaderNodeIntParameter::set_min);
- ClassDB::bind_method(D_METHOD("get_min"), &VisualShaderNodeIntParameter::get_min);
- ClassDB::bind_method(D_METHOD("set_max", "value"), &VisualShaderNodeIntParameter::set_max);
- ClassDB::bind_method(D_METHOD("get_max"), &VisualShaderNodeIntParameter::get_max);
- ClassDB::bind_method(D_METHOD("set_step", "value"), &VisualShaderNodeIntParameter::set_step);
- ClassDB::bind_method(D_METHOD("get_step"), &VisualShaderNodeIntParameter::get_step);
- ClassDB::bind_method(D_METHOD("set_enum_names", "names"), &VisualShaderNodeIntParameter::set_enum_names);
- ClassDB::bind_method(D_METHOD("get_enum_names"), &VisualShaderNodeIntParameter::get_enum_names);
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeIntParameter::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeIntParameter::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeIntParameter::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeIntParameter::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "hint", PROPERTY_HINT_ENUM, "None,Range,Range + Step,Enum"), "set_hint", "get_hint");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "min"), "set_min", "get_min");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "max"), "set_max", "get_max");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "step"), "set_step", "get_step");
- ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "enum_names"), "set_enum_names", "get_enum_names");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "default_value"), "set_default_value", "get_default_value");
- BIND_ENUM_CONSTANT(HINT_NONE);
- BIND_ENUM_CONSTANT(HINT_RANGE);
- BIND_ENUM_CONSTANT(HINT_RANGE_STEP);
- BIND_ENUM_CONSTANT(HINT_ENUM);
- BIND_ENUM_CONSTANT(HINT_MAX);
- }
- bool VisualShaderNodeIntParameter::is_qualifier_supported(Qualifier p_qual) const {
- return true; // all qualifiers are supported
- }
- bool VisualShaderNodeIntParameter::is_convertible_to_constant() const {
- return true; // conversion is allowed
- }
- Vector<StringName> VisualShaderNodeIntParameter::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties();
- props.push_back("hint");
- if (hint == HINT_RANGE || hint == HINT_RANGE_STEP) {
- props.push_back("min");
- props.push_back("max");
- }
- if (hint == HINT_RANGE_STEP) {
- props.push_back("step");
- }
- if (hint == HINT_ENUM) {
- props.push_back("enum_names");
- }
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeIntParameter::VisualShaderNodeIntParameter() {
- }
- ////////////// Unsigned Integer Parameter
- String VisualShaderNodeUIntParameter::get_caption() const {
- return "UIntParameter";
- }
- int VisualShaderNodeUIntParameter::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeUIntParameter::PortType VisualShaderNodeUIntParameter::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_UINT;
- }
- String VisualShaderNodeUIntParameter::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeUIntParameter::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeUIntParameter::PortType VisualShaderNodeUIntParameter::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR_UINT;
- }
- String VisualShaderNodeUIntParameter::get_output_port_name(int p_port) const {
- return ""; // No output port means the editor will be used as port.
- }
- String VisualShaderNodeUIntParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform uint " + get_parameter_name();
- if (default_value_enabled) {
- code += " = " + itos(default_value);
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeUIntParameter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + get_parameter_name() + ";\n";
- }
- bool VisualShaderNodeUIntParameter::is_show_prop_names() const {
- return true;
- }
- bool VisualShaderNodeUIntParameter::is_use_prop_slots() const {
- return true;
- }
- void VisualShaderNodeUIntParameter::set_default_value_enabled(bool p_default_value_enabled) {
- if (default_value_enabled == p_default_value_enabled) {
- return;
- }
- default_value_enabled = p_default_value_enabled;
- emit_changed();
- }
- bool VisualShaderNodeUIntParameter::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeUIntParameter::set_default_value(int p_default_value) {
- if (default_value == p_default_value) {
- return;
- }
- default_value = p_default_value;
- emit_changed();
- }
- int VisualShaderNodeUIntParameter::get_default_value() const {
- return default_value;
- }
- void VisualShaderNodeUIntParameter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeUIntParameter::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeUIntParameter::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeUIntParameter::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeUIntParameter::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "default_value"), "set_default_value", "get_default_value");
- }
- bool VisualShaderNodeUIntParameter::is_qualifier_supported(Qualifier p_qual) const {
- return true; // All qualifiers are supported.
- }
- bool VisualShaderNodeUIntParameter::is_convertible_to_constant() const {
- return true; // Conversion is allowed.
- }
- Vector<StringName> VisualShaderNodeUIntParameter::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeUIntParameter::VisualShaderNodeUIntParameter() {
- }
- ////////////// Boolean Parameter
- String VisualShaderNodeBooleanParameter::get_caption() const {
- return "BooleanParameter";
- }
- int VisualShaderNodeBooleanParameter::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeBooleanParameter::PortType VisualShaderNodeBooleanParameter::get_input_port_type(int p_port) const {
- return PORT_TYPE_BOOLEAN;
- }
- String VisualShaderNodeBooleanParameter::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeBooleanParameter::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeBooleanParameter::PortType VisualShaderNodeBooleanParameter::get_output_port_type(int p_port) const {
- return PORT_TYPE_BOOLEAN;
- }
- String VisualShaderNodeBooleanParameter::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- void VisualShaderNodeBooleanParameter::set_default_value_enabled(bool p_default_value_enabled) {
- if (default_value_enabled == p_default_value_enabled) {
- return;
- }
- default_value_enabled = p_default_value_enabled;
- emit_changed();
- }
- bool VisualShaderNodeBooleanParameter::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeBooleanParameter::set_default_value(bool p_default_value) {
- if (default_value == p_default_value) {
- return;
- }
- default_value = p_default_value;
- emit_changed();
- }
- bool VisualShaderNodeBooleanParameter::get_default_value() const {
- return default_value;
- }
- String VisualShaderNodeBooleanParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform bool " + get_parameter_name();
- if (default_value_enabled) {
- if (default_value) {
- code += " = true";
- } else {
- code += " = false";
- }
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeBooleanParameter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + get_parameter_name() + ";\n";
- }
- bool VisualShaderNodeBooleanParameter::is_show_prop_names() const {
- return true;
- }
- bool VisualShaderNodeBooleanParameter::is_use_prop_slots() const {
- return true;
- }
- void VisualShaderNodeBooleanParameter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeBooleanParameter::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeBooleanParameter::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeBooleanParameter::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeBooleanParameter::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value"), "set_default_value", "get_default_value");
- }
- bool VisualShaderNodeBooleanParameter::is_qualifier_supported(Qualifier p_qual) const {
- return true; // all qualifiers are supported
- }
- bool VisualShaderNodeBooleanParameter::is_convertible_to_constant() const {
- return true; // conversion is allowed
- }
- Vector<StringName> VisualShaderNodeBooleanParameter::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeBooleanParameter::VisualShaderNodeBooleanParameter() {
- }
- ////////////// Color Parameter
- String VisualShaderNodeColorParameter::get_caption() const {
- return "ColorParameter";
- }
- int VisualShaderNodeColorParameter::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeColorParameter::PortType VisualShaderNodeColorParameter::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeColorParameter::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeColorParameter::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeColorParameter::PortType VisualShaderNodeColorParameter::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeColorParameter::get_output_port_name(int p_port) const {
- return "color";
- }
- void VisualShaderNodeColorParameter::set_default_value_enabled(bool p_enabled) {
- if (default_value_enabled == p_enabled) {
- return;
- }
- default_value_enabled = p_enabled;
- emit_changed();
- }
- bool VisualShaderNodeColorParameter::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeColorParameter::set_default_value(const Color &p_value) {
- if (default_value.is_equal_approx(p_value)) {
- return;
- }
- default_value = p_value;
- emit_changed();
- }
- Color VisualShaderNodeColorParameter::get_default_value() const {
- return default_value;
- }
- String VisualShaderNodeColorParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform vec4 " + get_parameter_name() + " : source_color";
- if (default_value_enabled) {
- code += vformat(" = vec4(%.6f, %.6f, %.6f, %.6f)", default_value.r, default_value.g, default_value.b, default_value.a);
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeColorParameter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + get_parameter_name() + ";\n";
- }
- bool VisualShaderNodeColorParameter::is_show_prop_names() const {
- return true;
- }
- void VisualShaderNodeColorParameter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeColorParameter::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeColorParameter::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeColorParameter::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeColorParameter::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::COLOR, "default_value"), "set_default_value", "get_default_value");
- }
- bool VisualShaderNodeColorParameter::is_qualifier_supported(Qualifier p_qual) const {
- return true; // all qualifiers are supported
- }
- bool VisualShaderNodeColorParameter::is_convertible_to_constant() const {
- return true; // conversion is allowed
- }
- Vector<StringName> VisualShaderNodeColorParameter::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeColorParameter::VisualShaderNodeColorParameter() {
- }
- ////////////// Vector2 Parameter
- String VisualShaderNodeVec2Parameter::get_caption() const {
- return "Vector2Parameter";
- }
- int VisualShaderNodeVec2Parameter::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeVec2Parameter::PortType VisualShaderNodeVec2Parameter::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_2D;
- }
- String VisualShaderNodeVec2Parameter::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeVec2Parameter::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVec2Parameter::PortType VisualShaderNodeVec2Parameter::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeVec2Parameter::get_output_port_name(int p_port) const {
- return "vector";
- }
- void VisualShaderNodeVec2Parameter::set_default_value_enabled(bool p_enabled) {
- default_value_enabled = p_enabled;
- emit_changed();
- }
- bool VisualShaderNodeVec2Parameter::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeVec2Parameter::set_default_value(const Vector2 &p_value) {
- default_value = p_value;
- emit_changed();
- }
- Vector2 VisualShaderNodeVec2Parameter::get_default_value() const {
- return default_value;
- }
- String VisualShaderNodeVec2Parameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform vec2 " + get_parameter_name();
- if (default_value_enabled) {
- code += vformat(" = vec2(%.6f, %.6f)", default_value.x, default_value.y);
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeVec2Parameter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + get_parameter_name() + ";\n";
- }
- void VisualShaderNodeVec2Parameter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeVec2Parameter::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeVec2Parameter::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeVec2Parameter::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeVec2Parameter::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "default_value"), "set_default_value", "get_default_value");
- }
- bool VisualShaderNodeVec2Parameter::is_show_prop_names() const {
- return true;
- }
- bool VisualShaderNodeVec2Parameter::is_use_prop_slots() const {
- return true;
- }
- bool VisualShaderNodeVec2Parameter::is_qualifier_supported(Qualifier p_qual) const {
- return true; // all qualifiers are supported
- }
- bool VisualShaderNodeVec2Parameter::is_convertible_to_constant() const {
- return true; // conversion is allowed
- }
- Vector<StringName> VisualShaderNodeVec2Parameter::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeVec2Parameter::VisualShaderNodeVec2Parameter() {
- }
- ////////////// Vector3 Parameter
- String VisualShaderNodeVec3Parameter::get_caption() const {
- return "Vector3Parameter";
- }
- int VisualShaderNodeVec3Parameter::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeVec3Parameter::PortType VisualShaderNodeVec3Parameter::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeVec3Parameter::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeVec3Parameter::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVec3Parameter::PortType VisualShaderNodeVec3Parameter::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeVec3Parameter::get_output_port_name(int p_port) const {
- return "vector";
- }
- void VisualShaderNodeVec3Parameter::set_default_value_enabled(bool p_enabled) {
- default_value_enabled = p_enabled;
- emit_changed();
- }
- bool VisualShaderNodeVec3Parameter::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeVec3Parameter::set_default_value(const Vector3 &p_value) {
- default_value = p_value;
- emit_changed();
- }
- Vector3 VisualShaderNodeVec3Parameter::get_default_value() const {
- return default_value;
- }
- String VisualShaderNodeVec3Parameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform vec3 " + get_parameter_name();
- if (default_value_enabled) {
- code += vformat(" = vec3(%.6f, %.6f, %.6f)", default_value.x, default_value.y, default_value.z);
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeVec3Parameter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + get_parameter_name() + ";\n";
- }
- void VisualShaderNodeVec3Parameter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeVec3Parameter::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeVec3Parameter::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeVec3Parameter::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeVec3Parameter::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "default_value"), "set_default_value", "get_default_value");
- }
- bool VisualShaderNodeVec3Parameter::is_show_prop_names() const {
- return true;
- }
- bool VisualShaderNodeVec3Parameter::is_use_prop_slots() const {
- return true;
- }
- bool VisualShaderNodeVec3Parameter::is_qualifier_supported(Qualifier p_qual) const {
- return true; // all qualifiers are supported
- }
- bool VisualShaderNodeVec3Parameter::is_convertible_to_constant() const {
- return true; // conversion is allowed
- }
- Vector<StringName> VisualShaderNodeVec3Parameter::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeVec3Parameter::VisualShaderNodeVec3Parameter() {
- }
- ////////////// Vector4 Parameter
- String VisualShaderNodeVec4Parameter::get_caption() const {
- return "Vector4Parameter";
- }
- int VisualShaderNodeVec4Parameter::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeVec4Parameter::PortType VisualShaderNodeVec4Parameter::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_4D;
- }
- String VisualShaderNodeVec4Parameter::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeVec4Parameter::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVec4Parameter::PortType VisualShaderNodeVec4Parameter::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeVec4Parameter::get_output_port_name(int p_port) const {
- return "vector";
- }
- void VisualShaderNodeVec4Parameter::set_default_value_enabled(bool p_enabled) {
- default_value_enabled = p_enabled;
- emit_changed();
- }
- bool VisualShaderNodeVec4Parameter::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeVec4Parameter::set_default_value(const Vector4 &p_value) {
- default_value = p_value;
- emit_changed();
- }
- Vector4 VisualShaderNodeVec4Parameter::get_default_value() const {
- return default_value;
- }
- String VisualShaderNodeVec4Parameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform vec4 " + get_parameter_name();
- if (default_value_enabled) {
- code += vformat(" = vec4(%.6f, %.6f, %.6f, %.6f)", default_value.x, default_value.y, default_value.z, default_value.w);
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeVec4Parameter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + get_parameter_name() + ";\n";
- }
- void VisualShaderNodeVec4Parameter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeVec4Parameter::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeVec4Parameter::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeVec4Parameter::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeVec4Parameter::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR4, "default_value"), "set_default_value", "get_default_value");
- }
- bool VisualShaderNodeVec4Parameter::is_show_prop_names() const {
- return true;
- }
- bool VisualShaderNodeVec4Parameter::is_use_prop_slots() const {
- return true;
- }
- bool VisualShaderNodeVec4Parameter::is_qualifier_supported(Qualifier p_qual) const {
- return true; // All qualifiers are supported.
- }
- bool VisualShaderNodeVec4Parameter::is_convertible_to_constant() const {
- return true; // Conversion is allowed.
- }
- Vector<StringName> VisualShaderNodeVec4Parameter::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeVec4Parameter::VisualShaderNodeVec4Parameter() {
- }
- ////////////// Transform Parameter
- String VisualShaderNodeTransformParameter::get_caption() const {
- return "TransformParameter";
- }
- int VisualShaderNodeTransformParameter::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeTransformParameter::PortType VisualShaderNodeTransformParameter::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeTransformParameter::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeTransformParameter::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeTransformParameter::PortType VisualShaderNodeTransformParameter::get_output_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformParameter::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- void VisualShaderNodeTransformParameter::set_default_value_enabled(bool p_enabled) {
- default_value_enabled = p_enabled;
- emit_changed();
- }
- bool VisualShaderNodeTransformParameter::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeTransformParameter::set_default_value(const Transform3D &p_value) {
- default_value = p_value;
- emit_changed();
- }
- Transform3D VisualShaderNodeTransformParameter::get_default_value() const {
- return default_value;
- }
- String VisualShaderNodeTransformParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform mat4 " + get_parameter_name();
- if (default_value_enabled) {
- Vector3 row0 = default_value.basis.rows[0];
- Vector3 row1 = default_value.basis.rows[1];
- Vector3 row2 = default_value.basis.rows[2];
- Vector3 origin = default_value.origin;
- code += " = mat4(" + vformat("vec4(%.6f, %.6f, %.6f, 0.0)", row0.x, row0.y, row0.z) + vformat(", vec4(%.6f, %.6f, %.6f, 0.0)", row1.x, row1.y, row1.z) + vformat(", vec4(%.6f, %.6f, %.6f, 0.0)", row2.x, row2.y, row2.z) + vformat(", vec4(%.6f, %.6f, %.6f, 1.0)", origin.x, origin.y, origin.z) + ")";
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeTransformParameter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = " + get_parameter_name() + ";\n";
- }
- void VisualShaderNodeTransformParameter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeTransformParameter::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeTransformParameter::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeTransformParameter::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeTransformParameter::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "default_value"), "set_default_value", "get_default_value");
- }
- bool VisualShaderNodeTransformParameter::is_show_prop_names() const {
- return true;
- }
- bool VisualShaderNodeTransformParameter::is_use_prop_slots() const {
- return true;
- }
- bool VisualShaderNodeTransformParameter::is_qualifier_supported(Qualifier p_qual) const {
- if (p_qual == Qualifier::QUAL_INSTANCE) {
- return false;
- }
- return true;
- }
- bool VisualShaderNodeTransformParameter::is_convertible_to_constant() const {
- return true; // conversion is allowed
- }
- Vector<StringName> VisualShaderNodeTransformParameter::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeTransformParameter::VisualShaderNodeTransformParameter() {
- }
- //////////////
- String get_sampler_hint(VisualShaderNodeTextureParameter::TextureType p_texture_type, VisualShaderNodeTextureParameter::ColorDefault p_color_default, VisualShaderNodeTextureParameter::TextureFilter p_texture_filter, VisualShaderNodeTextureParameter::TextureRepeat p_texture_repeat, VisualShaderNodeTextureParameter::TextureSource p_texture_source) {
- String code;
- bool has_colon = false;
- // type
- {
- String type_code;
- switch (p_texture_type) {
- case VisualShaderNodeTextureParameter::TYPE_DATA:
- if (p_color_default == VisualShaderNodeTextureParameter::COLOR_DEFAULT_BLACK) {
- type_code = "hint_default_black";
- } else if (p_color_default == VisualShaderNodeTextureParameter::COLOR_DEFAULT_TRANSPARENT) {
- type_code = "hint_default_transparent";
- }
- break;
- case VisualShaderNodeTextureParameter::TYPE_COLOR:
- type_code = "source_color";
- if (p_color_default == VisualShaderNodeTextureParameter::COLOR_DEFAULT_BLACK) {
- type_code += ", hint_default_black";
- } else if (p_color_default == VisualShaderNodeTextureParameter::COLOR_DEFAULT_TRANSPARENT) {
- type_code += ", hint_default_transparent";
- }
- break;
- case VisualShaderNodeTextureParameter::TYPE_NORMAL_MAP:
- type_code = "hint_normal";
- break;
- case VisualShaderNodeTextureParameter::TYPE_ANISOTROPY:
- type_code = "hint_anisotropy";
- break;
- default:
- break;
- }
- if (!type_code.is_empty()) {
- code += " : " + type_code;
- has_colon = true;
- }
- }
- // filter
- {
- String filter_code;
- switch (p_texture_filter) {
- case VisualShaderNodeTextureParameter::FILTER_NEAREST:
- filter_code = "filter_nearest";
- break;
- case VisualShaderNodeTextureParameter::FILTER_LINEAR:
- filter_code = "filter_linear";
- break;
- case VisualShaderNodeTextureParameter::FILTER_NEAREST_MIPMAP:
- filter_code = "filter_nearest_mipmap";
- break;
- case VisualShaderNodeTextureParameter::FILTER_LINEAR_MIPMAP:
- filter_code = "filter_linear_mipmap";
- break;
- case VisualShaderNodeTextureParameter::FILTER_NEAREST_MIPMAP_ANISOTROPIC:
- filter_code = "filter_nearest_mipmap_anisotropic";
- break;
- case VisualShaderNodeTextureParameter::FILTER_LINEAR_MIPMAP_ANISOTROPIC:
- filter_code = "filter_linear_mipmap_anisotropic";
- break;
- default:
- break;
- }
- if (!filter_code.is_empty()) {
- if (!has_colon) {
- code += " : ";
- has_colon = true;
- } else {
- code += ", ";
- }
- code += filter_code;
- }
- }
- // repeat
- {
- String repeat_code;
- switch (p_texture_repeat) {
- case VisualShaderNodeTextureParameter::REPEAT_ENABLED:
- repeat_code = "repeat_enable";
- break;
- case VisualShaderNodeTextureParameter::REPEAT_DISABLED:
- repeat_code = "repeat_disable";
- break;
- default:
- break;
- }
- if (!repeat_code.is_empty()) {
- if (!has_colon) {
- code += " : ";
- has_colon = true;
- } else {
- code += ", ";
- }
- code += repeat_code;
- }
- }
- // source
- {
- String source_code;
- switch (p_texture_source) {
- case VisualShaderNodeTextureParameter::SOURCE_SCREEN:
- source_code = "hint_screen_texture";
- break;
- case VisualShaderNodeTextureParameter::SOURCE_DEPTH:
- source_code = "hint_depth_texture";
- break;
- case VisualShaderNodeTextureParameter::SOURCE_NORMAL_ROUGHNESS:
- source_code = "hint_normal_roughness_texture";
- break;
- default:
- break;
- }
- if (!source_code.is_empty()) {
- if (!has_colon) {
- code += " : ";
- } else {
- code += ", ";
- }
- code += source_code;
- }
- }
- return code;
- }
- ////////////// Texture Parameter
- int VisualShaderNodeTextureParameter::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeTextureParameter::PortType VisualShaderNodeTextureParameter::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeTextureParameter::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeTextureParameter::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeTextureParameter::PortType VisualShaderNodeTextureParameter::get_output_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_SAMPLER;
- default:
- return PORT_TYPE_SCALAR;
- }
- }
- String VisualShaderNodeTextureParameter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return "";
- }
- void VisualShaderNodeTextureParameter::set_texture_type(TextureType p_texture_type) {
- ERR_FAIL_INDEX(int(p_texture_type), int(TYPE_MAX));
- if (texture_type == p_texture_type) {
- return;
- }
- texture_type = p_texture_type;
- emit_changed();
- }
- VisualShaderNodeTextureParameter::TextureType VisualShaderNodeTextureParameter::get_texture_type() const {
- return texture_type;
- }
- void VisualShaderNodeTextureParameter::set_color_default(ColorDefault p_color_default) {
- ERR_FAIL_INDEX(int(p_color_default), int(COLOR_DEFAULT_MAX));
- if (color_default == p_color_default) {
- return;
- }
- color_default = p_color_default;
- emit_changed();
- }
- VisualShaderNodeTextureParameter::ColorDefault VisualShaderNodeTextureParameter::get_color_default() const {
- return color_default;
- }
- void VisualShaderNodeTextureParameter::set_texture_filter(TextureFilter p_filter) {
- ERR_FAIL_INDEX(int(p_filter), int(FILTER_MAX));
- if (texture_filter == p_filter) {
- return;
- }
- texture_filter = p_filter;
- emit_changed();
- }
- VisualShaderNodeTextureParameter::TextureFilter VisualShaderNodeTextureParameter::get_texture_filter() const {
- return texture_filter;
- }
- void VisualShaderNodeTextureParameter::set_texture_repeat(TextureRepeat p_repeat) {
- ERR_FAIL_INDEX(int(p_repeat), int(REPEAT_MAX));
- if (texture_repeat == p_repeat) {
- return;
- }
- texture_repeat = p_repeat;
- emit_changed();
- }
- VisualShaderNodeTextureParameter::TextureRepeat VisualShaderNodeTextureParameter::get_texture_repeat() const {
- return texture_repeat;
- }
- void VisualShaderNodeTextureParameter::set_texture_source(TextureSource p_source) {
- ERR_FAIL_INDEX(int(p_source), int(SOURCE_MAX));
- if (texture_source == p_source) {
- return;
- }
- texture_source = p_source;
- emit_changed();
- }
- VisualShaderNodeTextureParameter::TextureSource VisualShaderNodeTextureParameter::get_texture_source() const {
- return texture_source;
- }
- Vector<StringName> VisualShaderNodeTextureParameter::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties();
- props.push_back("texture_type");
- if (texture_type == TYPE_DATA || texture_type == TYPE_COLOR) {
- props.push_back("color_default");
- }
- props.push_back("texture_filter");
- props.push_back("texture_repeat");
- props.push_back("texture_source");
- return props;
- }
- bool VisualShaderNodeTextureParameter::is_show_prop_names() const {
- return true;
- }
- String VisualShaderNodeTextureParameter::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const {
- String warning = VisualShaderNodeParameter::get_warning(p_mode, p_type);
- if (texture_source != SOURCE_NONE) {
- String texture_source_str;
- switch (texture_source) {
- case SOURCE_SCREEN: {
- texture_source_str = "Screen";
- } break;
- case SOURCE_DEPTH: {
- texture_source_str = "Depth";
- } break;
- case SOURCE_NORMAL_ROUGHNESS: {
- texture_source_str = "NormalRoughness";
- } break;
- default:
- break;
- }
- if (texture_type == TYPE_NORMAL_MAP || texture_type == TYPE_ANISOTROPY) {
- String texture_type_str;
- switch (texture_type) {
- case TYPE_NORMAL_MAP: {
- texture_type_str = "Normal Map";
- } break;
- case TYPE_ANISOTROPY: {
- texture_type_str = "Anisotropic";
- } break;
- default:
- break;
- }
- if (!warning.is_empty()) {
- warning += "\n";
- }
- warning += vformat(RTR("'%s' type is incompatible with '%s' source."), texture_type_str, texture_source_str);
- } else if (color_default != COLOR_DEFAULT_WHITE) {
- String color_default_str;
- switch (color_default) {
- case COLOR_DEFAULT_BLACK: {
- color_default_str = "Black";
- } break;
- case COLOR_DEFAULT_TRANSPARENT: {
- color_default_str = "Transparent";
- } break;
- default:
- break;
- }
- if (!warning.is_empty()) {
- warning += "\n";
- }
- warning += vformat(RTR("'%s' default color is incompatible with '%s' source."), color_default_str, texture_source_str);
- }
- }
- return warning;
- }
- HashMap<StringName, String> VisualShaderNodeTextureParameter::get_editable_properties_names() const {
- HashMap<StringName, String> names;
- names.insert("texture_type", RTR("Type"));
- names.insert("color_default", RTR("Default Color"));
- names.insert("texture_filter", RTR("Filter"));
- names.insert("texture_repeat", RTR("Repeat"));
- names.insert("texture_source", RTR("Source"));
- return names;
- }
- void VisualShaderNodeTextureParameter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_texture_type", "type"), &VisualShaderNodeTextureParameter::set_texture_type);
- ClassDB::bind_method(D_METHOD("get_texture_type"), &VisualShaderNodeTextureParameter::get_texture_type);
- ClassDB::bind_method(D_METHOD("set_color_default", "color"), &VisualShaderNodeTextureParameter::set_color_default);
- ClassDB::bind_method(D_METHOD("get_color_default"), &VisualShaderNodeTextureParameter::get_color_default);
- ClassDB::bind_method(D_METHOD("set_texture_filter", "filter"), &VisualShaderNodeTextureParameter::set_texture_filter);
- ClassDB::bind_method(D_METHOD("get_texture_filter"), &VisualShaderNodeTextureParameter::get_texture_filter);
- ClassDB::bind_method(D_METHOD("set_texture_repeat", "repeat"), &VisualShaderNodeTextureParameter::set_texture_repeat);
- ClassDB::bind_method(D_METHOD("get_texture_repeat"), &VisualShaderNodeTextureParameter::get_texture_repeat);
- ClassDB::bind_method(D_METHOD("set_texture_source", "source"), &VisualShaderNodeTextureParameter::set_texture_source);
- ClassDB::bind_method(D_METHOD("get_texture_source"), &VisualShaderNodeTextureParameter::get_texture_source);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_type", PROPERTY_HINT_ENUM, "Data,Color,Normal Map,Anisotropic"), "set_texture_type", "get_texture_type");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "color_default", PROPERTY_HINT_ENUM, "White,Black,Transparent"), "set_color_default", "get_color_default");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_filter", PROPERTY_HINT_ENUM, "Default,Nearest,Linear,Nearest Mipmap,Linear Mipmap,Nearest Mipmap Anisotropic,Linear Mipmap Anisotropic"), "set_texture_filter", "get_texture_filter");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_repeat", PROPERTY_HINT_ENUM, "Default,Enabled,Disabled"), "set_texture_repeat", "get_texture_repeat");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_source", PROPERTY_HINT_ENUM, "None,Screen,Depth,NormalRoughness"), "set_texture_source", "get_texture_source");
- BIND_ENUM_CONSTANT(TYPE_DATA);
- BIND_ENUM_CONSTANT(TYPE_COLOR);
- BIND_ENUM_CONSTANT(TYPE_NORMAL_MAP);
- BIND_ENUM_CONSTANT(TYPE_ANISOTROPY);
- BIND_ENUM_CONSTANT(TYPE_MAX);
- BIND_ENUM_CONSTANT(COLOR_DEFAULT_WHITE);
- BIND_ENUM_CONSTANT(COLOR_DEFAULT_BLACK);
- BIND_ENUM_CONSTANT(COLOR_DEFAULT_TRANSPARENT);
- BIND_ENUM_CONSTANT(COLOR_DEFAULT_MAX);
- BIND_ENUM_CONSTANT(FILTER_DEFAULT);
- BIND_ENUM_CONSTANT(FILTER_NEAREST);
- BIND_ENUM_CONSTANT(FILTER_LINEAR);
- BIND_ENUM_CONSTANT(FILTER_NEAREST_MIPMAP);
- BIND_ENUM_CONSTANT(FILTER_LINEAR_MIPMAP);
- BIND_ENUM_CONSTANT(FILTER_NEAREST_MIPMAP_ANISOTROPIC);
- BIND_ENUM_CONSTANT(FILTER_LINEAR_MIPMAP_ANISOTROPIC);
- BIND_ENUM_CONSTANT(FILTER_MAX);
- BIND_ENUM_CONSTANT(REPEAT_DEFAULT);
- BIND_ENUM_CONSTANT(REPEAT_ENABLED);
- BIND_ENUM_CONSTANT(REPEAT_DISABLED);
- BIND_ENUM_CONSTANT(REPEAT_MAX);
- BIND_ENUM_CONSTANT(SOURCE_NONE);
- BIND_ENUM_CONSTANT(SOURCE_SCREEN);
- BIND_ENUM_CONSTANT(SOURCE_DEPTH);
- BIND_ENUM_CONSTANT(SOURCE_NORMAL_ROUGHNESS);
- BIND_ENUM_CONSTANT(SOURCE_MAX);
- }
- bool VisualShaderNodeTextureParameter::is_qualifier_supported(Qualifier p_qual) const {
- switch (p_qual) {
- case Qualifier::QUAL_NONE:
- return true;
- case Qualifier::QUAL_GLOBAL:
- return true;
- case Qualifier::QUAL_INSTANCE:
- return false;
- default:
- break;
- }
- return false;
- }
- bool VisualShaderNodeTextureParameter::is_convertible_to_constant() const {
- return false; // conversion is not allowed
- }
- VisualShaderNodeTextureParameter::VisualShaderNodeTextureParameter() {
- }
- ////////////// Texture2D Parameter
- String VisualShaderNodeTexture2DParameter::get_caption() const {
- return "Texture2DParameter";
- }
- String VisualShaderNodeTexture2DParameter::get_output_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "sampler2D";
- default:
- return "";
- }
- }
- String VisualShaderNodeTexture2DParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform sampler2D " + get_parameter_name();
- code += get_sampler_hint(texture_type, color_default, texture_filter, texture_repeat, texture_source);
- code += ";\n";
- return code;
- }
- VisualShaderNodeTexture2DParameter::VisualShaderNodeTexture2DParameter() {
- }
- ////////////// Texture Parameter (Triplanar)
- String VisualShaderNodeTextureParameterTriplanar::get_caption() const {
- return "TextureParameterTriplanar";
- }
- int VisualShaderNodeTextureParameterTriplanar::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeTextureParameterTriplanar::PortType VisualShaderNodeTextureParameterTriplanar::get_input_port_type(int p_port) const {
- if (p_port == 0 || p_port == 1) {
- return PORT_TYPE_VECTOR_3D;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeTextureParameterTriplanar::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "weights";
- } else if (p_port == 1) {
- return "pos";
- }
- return "";
- }
- int VisualShaderNodeTextureParameterTriplanar::get_output_port_count() const {
- return 2;
- }
- VisualShaderNodeTextureParameterTriplanar::PortType VisualShaderNodeTextureParameterTriplanar::get_output_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR_4D;
- case 1:
- return PORT_TYPE_SAMPLER;
- default:
- return PORT_TYPE_SCALAR;
- }
- }
- String VisualShaderNodeTextureParameterTriplanar::get_output_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "color";
- case 1:
- return "sampler2D";
- default:
- return "";
- }
- }
- String VisualShaderNodeTextureParameterTriplanar::generate_global_per_node(Shader::Mode p_mode, int p_id) const {
- String code;
- code += "// " + get_caption() + "\n";
- code += " vec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) {\n";
- code += " vec4 samp = vec4(0.0);\n";
- code += " samp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z;\n";
- code += " samp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y;\n";
- code += " samp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x;\n";
- code += " return samp;\n";
- code += " }\n";
- code += "\n";
- code += " uniform vec3 triplanar_scale = vec3(1.0, 1.0, 1.0);\n";
- code += " uniform vec3 triplanar_offset;\n";
- code += " uniform float triplanar_sharpness = 0.5;\n";
- code += "\n";
- code += " varying vec3 triplanar_power_normal;\n";
- code += " varying vec3 triplanar_pos;\n";
- return code;
- }
- String VisualShaderNodeTextureParameterTriplanar::generate_global_per_func(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code;
- if (p_type == VisualShader::TYPE_VERTEX) {
- code += "// " + get_caption() + "\n";
- code += " {\n";
- code += " triplanar_power_normal = pow(abs(NORMAL), vec3(triplanar_sharpness));\n";
- code += " triplanar_power_normal /= dot(triplanar_power_normal, vec3(1.0));\n";
- code += " triplanar_pos = VERTEX * triplanar_scale + triplanar_offset;\n";
- code += " triplanar_pos *= vec3(1.0, -1.0, 1.0);\n";
- code += " }\n";
- }
- return code;
- }
- String VisualShaderNodeTextureParameterTriplanar::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform sampler2D " + get_parameter_name();
- code += get_sampler_hint(texture_type, color_default, texture_filter, texture_repeat, texture_source);
- code += ";\n";
- return code;
- }
- String VisualShaderNodeTextureParameterTriplanar::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String id = get_parameter_name();
- String code;
- if (p_input_vars[0].is_empty() && p_input_vars[1].is_empty()) {
- code += " " + p_output_vars[0] + " = triplanar_texture(" + id + ", triplanar_power_normal, triplanar_pos);\n";
- } else if (!p_input_vars[0].is_empty() && p_input_vars[1].is_empty()) {
- code += " " + p_output_vars[0] + " = triplanar_texture(" + id + ", " + p_input_vars[0] + ", triplanar_pos);\n";
- } else if (p_input_vars[0].is_empty() && !p_input_vars[1].is_empty()) {
- code += " " + p_output_vars[0] + " = triplanar_texture(" + id + ", triplanar_power_normal, " + p_input_vars[1] + ");\n";
- } else {
- code += " " + p_output_vars[0] + " = triplanar_texture(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- }
- return code;
- }
- bool VisualShaderNodeTextureParameterTriplanar::is_input_port_default(int p_port, Shader::Mode p_mode) const {
- if (p_port == 0) {
- return true;
- } else if (p_port == 1) {
- return true;
- }
- return false;
- }
- VisualShaderNodeTextureParameterTriplanar::VisualShaderNodeTextureParameterTriplanar() {
- }
- ////////////// Texture2DArray Parameter
- String VisualShaderNodeTexture2DArrayParameter::get_caption() const {
- return "Texture2DArrayParameter";
- }
- String VisualShaderNodeTexture2DArrayParameter::get_output_port_name(int p_port) const {
- return "sampler2DArray";
- }
- String VisualShaderNodeTexture2DArrayParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform sampler2DArray " + get_parameter_name();
- code += get_sampler_hint(texture_type, color_default, texture_filter, texture_repeat, texture_source);
- code += ";\n";
- return code;
- }
- VisualShaderNodeTexture2DArrayParameter::VisualShaderNodeTexture2DArrayParameter() {
- }
- ////////////// Texture3D Parameter
- String VisualShaderNodeTexture3DParameter::get_caption() const {
- return "Texture3DParameter";
- }
- String VisualShaderNodeTexture3DParameter::get_output_port_name(int p_port) const {
- return "sampler3D";
- }
- String VisualShaderNodeTexture3DParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform sampler3D " + get_parameter_name();
- code += get_sampler_hint(texture_type, color_default, texture_filter, texture_repeat, texture_source);
- code += ";\n";
- return code;
- }
- VisualShaderNodeTexture3DParameter::VisualShaderNodeTexture3DParameter() {
- }
- ////////////// Cubemap Parameter
- String VisualShaderNodeCubemapParameter::get_caption() const {
- return "CubemapParameter";
- }
- String VisualShaderNodeCubemapParameter::get_output_port_name(int p_port) const {
- return "samplerCube";
- }
- String VisualShaderNodeCubemapParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = _get_qual_str() + "uniform samplerCube " + get_parameter_name();
- code += get_sampler_hint(texture_type, color_default, texture_filter, texture_repeat, texture_source);
- code += ";\n";
- return code;
- }
- VisualShaderNodeCubemapParameter::VisualShaderNodeCubemapParameter() {
- }
- ////////////// If
- String VisualShaderNodeIf::get_caption() const {
- return "If";
- }
- int VisualShaderNodeIf::get_input_port_count() const {
- return 6;
- }
- VisualShaderNodeIf::PortType VisualShaderNodeIf::get_input_port_type(int p_port) const {
- if (p_port == 0 || p_port == 1 || p_port == 2) {
- return PORT_TYPE_SCALAR;
- }
- return PORT_TYPE_VECTOR_3D;
- }
- String VisualShaderNodeIf::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "a";
- case 1:
- return "b";
- case 2:
- return "tolerance";
- case 3:
- return "a == b";
- case 4:
- return "a > b";
- case 5:
- return "a < b";
- default:
- return "";
- }
- }
- int VisualShaderNodeIf::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeIf::PortType VisualShaderNodeIf::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeIf::get_output_port_name(int p_port) const {
- return "result";
- }
- String VisualShaderNodeIf::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- code += " if(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ")\n"; // abs(a - b) < tolerance eg. a == b
- code += " {\n";
- code += " " + p_output_vars[0] + " = " + p_input_vars[3] + ";\n";
- code += " }\n";
- code += " else if(" + p_input_vars[0] + " < " + p_input_vars[1] + ")\n"; // a < b
- code += " {\n";
- code += " " + p_output_vars[0] + " = " + p_input_vars[5] + ";\n";
- code += " }\n";
- code += " else\n"; // a > b (or a >= b if abs(a - b) < tolerance is false)
- code += " {\n";
- code += " " + p_output_vars[0] + " = " + p_input_vars[4] + ";\n";
- code += " }\n";
- return code;
- }
- VisualShaderNodeIf::VisualShaderNodeIf() {
- simple_decl = false;
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, CMP_EPSILON);
- set_input_port_default_value(3, Vector3(0.0, 0.0, 0.0));
- set_input_port_default_value(4, Vector3(0.0, 0.0, 0.0));
- set_input_port_default_value(5, Vector3(0.0, 0.0, 0.0));
- }
- ////////////// Switch
- String VisualShaderNodeSwitch::get_caption() const {
- return "Switch";
- }
- int VisualShaderNodeSwitch::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeSwitch::PortType VisualShaderNodeSwitch::get_input_port_type(int p_port) const {
- if (p_port == 0) {
- return PORT_TYPE_BOOLEAN;
- }
- if (p_port == 1 || p_port == 2) {
- switch (op_type) {
- case OP_TYPE_INT:
- return PORT_TYPE_SCALAR_INT;
- case OP_TYPE_UINT:
- return PORT_TYPE_SCALAR_UINT;
- case OP_TYPE_VECTOR_2D:
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_4D:
- return PORT_TYPE_VECTOR_4D;
- case OP_TYPE_BOOLEAN:
- return PORT_TYPE_BOOLEAN;
- case OP_TYPE_TRANSFORM:
- return PORT_TYPE_TRANSFORM;
- default:
- break;
- }
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeSwitch::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "value";
- case 1:
- return "true";
- case 2:
- return "false";
- default:
- return "";
- }
- }
- int VisualShaderNodeSwitch::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeSwitch::PortType VisualShaderNodeSwitch::get_output_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_INT:
- return PORT_TYPE_SCALAR_INT;
- case OP_TYPE_UINT:
- return PORT_TYPE_SCALAR_UINT;
- case OP_TYPE_VECTOR_2D:
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_3D:
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_4D:
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- case OP_TYPE_BOOLEAN:
- return PORT_TYPE_BOOLEAN;
- case OP_TYPE_TRANSFORM:
- return PORT_TYPE_TRANSFORM;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeSwitch::get_output_port_name(int p_port) const {
- return "result";
- }
- void VisualShaderNodeSwitch::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_FLOAT:
- set_input_port_default_value(1, 1.0, get_input_port_default_value(1));
- set_input_port_default_value(2, 0.0, get_input_port_default_value(2));
- break;
- case OP_TYPE_UINT:
- case OP_TYPE_INT:
- set_input_port_default_value(1, 1, get_input_port_default_value(1));
- set_input_port_default_value(2, 0, get_input_port_default_value(2));
- break;
- case OP_TYPE_VECTOR_2D:
- set_input_port_default_value(1, Vector2(1.0, 1.0), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector2(0.0, 0.0), get_input_port_default_value(2));
- break;
- case OP_TYPE_VECTOR_3D:
- set_input_port_default_value(1, Vector3(1.0, 1.0, 1.0), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector3(0.0, 0.0, 0.0), get_input_port_default_value(2));
- break;
- case OP_TYPE_VECTOR_4D:
- set_input_port_default_value(1, Quaternion(1.0, 1.0, 1.0, 1.0), get_input_port_default_value(1));
- set_input_port_default_value(2, Quaternion(0.0, 0.0, 0.0, 0.0), get_input_port_default_value(2));
- break;
- case OP_TYPE_BOOLEAN:
- set_input_port_default_value(1, true);
- set_input_port_default_value(2, false);
- break;
- case OP_TYPE_TRANSFORM:
- set_input_port_default_value(1, Transform3D());
- set_input_port_default_value(2, Transform3D());
- break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- VisualShaderNodeSwitch::OpType VisualShaderNodeSwitch::get_op_type() const {
- return op_type;
- }
- Vector<StringName> VisualShaderNodeSwitch::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("op_type");
- return props;
- }
- void VisualShaderNodeSwitch::_bind_methods() { // static
- ClassDB::bind_method(D_METHOD("set_op_type", "type"), &VisualShaderNodeSwitch::set_op_type);
- ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeSwitch::get_op_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Float,Int,UInt,Vector2,Vector3,Vector4,Boolean,Transform"), "set_op_type", "get_op_type");
- BIND_ENUM_CONSTANT(OP_TYPE_FLOAT);
- BIND_ENUM_CONSTANT(OP_TYPE_INT);
- BIND_ENUM_CONSTANT(OP_TYPE_UINT);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D);
- BIND_ENUM_CONSTANT(OP_TYPE_BOOLEAN);
- BIND_ENUM_CONSTANT(OP_TYPE_TRANSFORM);
- BIND_ENUM_CONSTANT(OP_TYPE_MAX);
- }
- String VisualShaderNodeSwitch::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- bool use_mix = false;
- switch (op_type) {
- case OP_TYPE_FLOAT: {
- use_mix = true;
- } break;
- case OP_TYPE_VECTOR_2D: {
- use_mix = true;
- } break;
- case OP_TYPE_VECTOR_3D: {
- use_mix = true;
- } break;
- case OP_TYPE_VECTOR_4D: {
- use_mix = true;
- } break;
- default: {
- } break;
- }
- String code;
- if (use_mix) {
- code += " " + p_output_vars[0] + " = mix(" + p_input_vars[2] + ", " + p_input_vars[1] + ", float(" + p_input_vars[0] + "));\n";
- } else {
- code += " if (" + p_input_vars[0] + ") {\n";
- code += " " + p_output_vars[0] + " = " + p_input_vars[1] + ";\n";
- code += " } else {\n";
- code += " " + p_output_vars[0] + " = " + p_input_vars[2] + ";\n";
- code += " }\n";
- }
- return code;
- }
- VisualShaderNodeSwitch::VisualShaderNodeSwitch() {
- simple_decl = false;
- set_input_port_default_value(0, false);
- set_input_port_default_value(1, 1.0);
- set_input_port_default_value(2, 0.0);
- }
- ////////////// Fresnel
- String VisualShaderNodeFresnel::get_caption() const {
- return "Fresnel";
- }
- int VisualShaderNodeFresnel::get_input_port_count() const {
- return 4;
- }
- VisualShaderNodeFresnel::PortType VisualShaderNodeFresnel::get_input_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR_3D;
- case 1:
- return PORT_TYPE_VECTOR_3D;
- case 2:
- return PORT_TYPE_BOOLEAN;
- case 3:
- return PORT_TYPE_SCALAR;
- default:
- return PORT_TYPE_VECTOR_3D;
- }
- }
- String VisualShaderNodeFresnel::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "normal";
- case 1:
- return "view";
- case 2:
- return "invert";
- case 3:
- return "power";
- default:
- return "";
- }
- }
- int VisualShaderNodeFresnel::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeFresnel::PortType VisualShaderNodeFresnel::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeFresnel::get_output_port_name(int p_port) const {
- return "result";
- }
- bool VisualShaderNodeFresnel::is_generate_input_var(int p_port) const {
- if (p_port == 2) {
- return false;
- }
- return true;
- }
- String VisualShaderNodeFresnel::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String normal;
- String view;
- if (p_input_vars[0].is_empty()) {
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- normal = "NORMAL";
- } else {
- normal = "vec3(0.0)";
- }
- } else {
- normal = p_input_vars[0];
- }
- if (p_input_vars[1].is_empty()) {
- if (p_mode == Shader::MODE_SPATIAL) {
- view = "VIEW";
- } else {
- view = "vec3(0.0)";
- }
- } else {
- view = p_input_vars[1];
- }
- if (is_input_port_connected(2)) {
- return " " + p_output_vars[0] + " = " + p_input_vars[2] + " ? (pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ")) : (pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + "));\n";
- } else {
- if (get_input_port_default_value(2)) {
- return " " + p_output_vars[0] + " = pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n";
- } else {
- return " " + p_output_vars[0] + " = pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n";
- }
- }
- }
- bool VisualShaderNodeFresnel::is_input_port_default(int p_port, Shader::Mode p_mode) const {
- if (p_port == 0) {
- if (p_mode == Shader::MODE_CANVAS_ITEM || p_mode == Shader::MODE_SPATIAL) {
- return true;
- }
- } else if (p_port == 1) {
- if (p_mode == Shader::MODE_SPATIAL) {
- return true;
- }
- }
- return false;
- }
- VisualShaderNodeFresnel::VisualShaderNodeFresnel() {
- set_input_port_default_value(2, false);
- set_input_port_default_value(3, 1.0);
- }
- ////////////// Is
- String VisualShaderNodeIs::get_caption() const {
- return "Is";
- }
- int VisualShaderNodeIs::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeIs::PortType VisualShaderNodeIs::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeIs::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeIs::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeIs::PortType VisualShaderNodeIs::get_output_port_type(int p_port) const {
- return PORT_TYPE_BOOLEAN;
- }
- String VisualShaderNodeIs::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeIs::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- static const char *functions[FUNC_MAX] = {
- "isinf($)",
- "isnan($)"
- };
- String code;
- code += " " + p_output_vars[0] + " = " + String(functions[func]).replace("$", p_input_vars[0]) + ";\n";
- return code;
- }
- void VisualShaderNodeIs::set_function(Function p_func) {
- ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX));
- if (func == p_func) {
- return;
- }
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeIs::Function VisualShaderNodeIs::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeIs::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeIs::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeIs::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeIs::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Inf,NaN"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_IS_INF);
- BIND_ENUM_CONSTANT(FUNC_IS_NAN);
- BIND_ENUM_CONSTANT(FUNC_MAX);
- }
- VisualShaderNodeIs::VisualShaderNodeIs() {
- set_input_port_default_value(0, 0.0);
- }
- ////////////// Compare
- String VisualShaderNodeCompare::get_caption() const {
- return "Compare";
- }
- int VisualShaderNodeCompare::get_input_port_count() const {
- if (comparison_type == CTYPE_SCALAR && (func == FUNC_EQUAL || func == FUNC_NOT_EQUAL)) {
- return 3;
- }
- return 2;
- }
- VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_input_port_type(int p_port) const {
- switch (comparison_type) {
- case CTYPE_SCALAR:
- return PORT_TYPE_SCALAR;
- case CTYPE_SCALAR_INT:
- return PORT_TYPE_SCALAR_INT;
- case CTYPE_SCALAR_UINT:
- return PORT_TYPE_SCALAR_UINT;
- case CTYPE_VECTOR_2D:
- return PORT_TYPE_VECTOR_2D;
- case CTYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR_3D;
- case CTYPE_VECTOR_4D:
- return PORT_TYPE_VECTOR_4D;
- case CTYPE_BOOLEAN:
- return PORT_TYPE_BOOLEAN;
- case CTYPE_TRANSFORM:
- return PORT_TYPE_TRANSFORM;
- default:
- return PORT_TYPE_SCALAR;
- }
- }
- String VisualShaderNodeCompare::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "a";
- } else if (p_port == 1) {
- return "b";
- } else if (p_port == 2) {
- return "tolerance";
- }
- return "";
- }
- int VisualShaderNodeCompare::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_output_port_type(int p_port) const {
- return PORT_TYPE_BOOLEAN;
- }
- String VisualShaderNodeCompare::get_output_port_name(int p_port) const {
- if (p_port == 0) {
- return "result";
- }
- return "";
- }
- String VisualShaderNodeCompare::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const {
- if (comparison_type == CTYPE_BOOLEAN || comparison_type == CTYPE_TRANSFORM) {
- if (func > FUNC_NOT_EQUAL) {
- return RTR("Invalid comparison function for that type.");
- }
- }
- return "";
- }
- String VisualShaderNodeCompare::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- static const char *operators[FUNC_MAX] = {
- "==",
- "!=",
- ">",
- ">=",
- "<",
- "<=",
- };
- static const char *functions[FUNC_MAX] = {
- "equal($)",
- "notEqual($)",
- "greaterThan($)",
- "greaterThanEqual($)",
- "lessThan($)",
- "lessThanEqual($)",
- };
- static const char *conditions[COND_MAX] = {
- "all($)",
- "any($)",
- };
- String code;
- switch (comparison_type) {
- case CTYPE_SCALAR: {
- if (func == FUNC_EQUAL) {
- code += " " + p_output_vars[0] + " = (abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");";
- } else if (func == FUNC_NOT_EQUAL) {
- code += " " + p_output_vars[0] + " = !(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");";
- } else {
- code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", operators[func]) + ";\n";
- }
- } break;
- case CTYPE_SCALAR_UINT:
- case CTYPE_SCALAR_INT: {
- code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", operators[func]) + ";\n";
- } break;
- case CTYPE_VECTOR_2D: {
- code += " {\n";
- code += " bvec2 _bv = " + String(functions[func]).replace("$", p_input_vars[0] + ", " + p_input_vars[1]) + ";\n";
- code += " " + p_output_vars[0] + " = " + String(conditions[condition]).replace("$", "_bv") + ";\n";
- code += " }\n";
- } break;
- case CTYPE_VECTOR_3D: {
- code += " {\n";
- code += " bvec3 _bv = " + String(functions[func]).replace("$", p_input_vars[0] + ", " + p_input_vars[1]) + ";\n";
- code += " " + p_output_vars[0] + " = " + String(conditions[condition]).replace("$", "_bv") + ";\n";
- code += " }\n";
- } break;
- case CTYPE_VECTOR_4D: {
- code += " {\n";
- code += " bvec4 _bv = " + String(functions[func]).replace("$", p_input_vars[0] + ", " + p_input_vars[1]) + ";\n";
- code += " " + p_output_vars[0] + " = " + String(conditions[condition]).replace("$", "_bv") + ";\n";
- code += " }\n";
- } break;
- case CTYPE_BOOLEAN: {
- if (func > FUNC_NOT_EQUAL) {
- return " " + p_output_vars[0] + " = false;\n";
- }
- code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", operators[func]) + ";\n";
- } break;
- case CTYPE_TRANSFORM: {
- if (func > FUNC_NOT_EQUAL) {
- return " " + p_output_vars[0] + " = false;\n";
- }
- code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", operators[func]) + ";\n";
- } break;
- default:
- break;
- }
- return code;
- }
- void VisualShaderNodeCompare::set_comparison_type(ComparisonType p_comparison_type) {
- ERR_FAIL_INDEX(int(p_comparison_type), int(CTYPE_MAX));
- if (comparison_type == p_comparison_type) {
- return;
- }
- switch (p_comparison_type) {
- case CTYPE_SCALAR:
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0));
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1));
- simple_decl = true;
- break;
- case CTYPE_SCALAR_UINT:
- case CTYPE_SCALAR_INT:
- set_input_port_default_value(0, 0, get_input_port_default_value(0));
- set_input_port_default_value(1, 0, get_input_port_default_value(1));
- simple_decl = true;
- break;
- case CTYPE_VECTOR_2D:
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1));
- simple_decl = false;
- break;
- case CTYPE_VECTOR_3D:
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1));
- simple_decl = false;
- break;
- case CTYPE_VECTOR_4D:
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1));
- simple_decl = false;
- break;
- case CTYPE_BOOLEAN:
- set_input_port_default_value(0, false);
- set_input_port_default_value(1, false);
- simple_decl = true;
- break;
- case CTYPE_TRANSFORM:
- set_input_port_default_value(0, Transform3D());
- set_input_port_default_value(1, Transform3D());
- simple_decl = true;
- break;
- default:
- break;
- }
- comparison_type = p_comparison_type;
- emit_changed();
- }
- VisualShaderNodeCompare::ComparisonType VisualShaderNodeCompare::get_comparison_type() const {
- return comparison_type;
- }
- void VisualShaderNodeCompare::set_function(Function p_func) {
- ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX));
- if (func == p_func) {
- return;
- }
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeCompare::Function VisualShaderNodeCompare::get_function() const {
- return func;
- }
- void VisualShaderNodeCompare::set_condition(Condition p_condition) {
- ERR_FAIL_INDEX(int(p_condition), int(COND_MAX));
- if (condition == p_condition) {
- return;
- }
- condition = p_condition;
- emit_changed();
- }
- VisualShaderNodeCompare::Condition VisualShaderNodeCompare::get_condition() const {
- return condition;
- }
- Vector<StringName> VisualShaderNodeCompare::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("type");
- props.push_back("function");
- if (comparison_type == CTYPE_VECTOR_2D || comparison_type == CTYPE_VECTOR_3D || comparison_type == CTYPE_VECTOR_4D) {
- props.push_back("condition");
- }
- return props;
- }
- void VisualShaderNodeCompare::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_comparison_type", "type"), &VisualShaderNodeCompare::set_comparison_type);
- ClassDB::bind_method(D_METHOD("get_comparison_type"), &VisualShaderNodeCompare::get_comparison_type);
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeCompare::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeCompare::get_function);
- ClassDB::bind_method(D_METHOD("set_condition", "condition"), &VisualShaderNodeCompare::set_condition);
- ClassDB::bind_method(D_METHOD("get_condition"), &VisualShaderNodeCompare::get_condition);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, "Float,Int,UInt,Vector2,Vector3,Vector4,Boolean,Transform"), "set_comparison_type", "get_comparison_type");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "a == b,a != b,a > b,a >= b,a < b,a <= b"), "set_function", "get_function");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "condition", PROPERTY_HINT_ENUM, "All,Any"), "set_condition", "get_condition");
- BIND_ENUM_CONSTANT(CTYPE_SCALAR);
- BIND_ENUM_CONSTANT(CTYPE_SCALAR_INT);
- BIND_ENUM_CONSTANT(CTYPE_SCALAR_UINT);
- BIND_ENUM_CONSTANT(CTYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(CTYPE_VECTOR_3D);
- BIND_ENUM_CONSTANT(CTYPE_VECTOR_4D);
- BIND_ENUM_CONSTANT(CTYPE_BOOLEAN);
- BIND_ENUM_CONSTANT(CTYPE_TRANSFORM);
- BIND_ENUM_CONSTANT(CTYPE_MAX);
- BIND_ENUM_CONSTANT(FUNC_EQUAL);
- BIND_ENUM_CONSTANT(FUNC_NOT_EQUAL);
- BIND_ENUM_CONSTANT(FUNC_GREATER_THAN);
- BIND_ENUM_CONSTANT(FUNC_GREATER_THAN_EQUAL);
- BIND_ENUM_CONSTANT(FUNC_LESS_THAN);
- BIND_ENUM_CONSTANT(FUNC_LESS_THAN_EQUAL);
- BIND_ENUM_CONSTANT(FUNC_MAX);
- BIND_ENUM_CONSTANT(COND_ALL);
- BIND_ENUM_CONSTANT(COND_ANY);
- BIND_ENUM_CONSTANT(COND_MAX);
- }
- VisualShaderNodeCompare::VisualShaderNodeCompare() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, CMP_EPSILON);
- }
- ////////////// Fma
- String VisualShaderNodeMultiplyAdd::get_caption() const {
- return "MultiplyAdd";
- }
- int VisualShaderNodeMultiplyAdd::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeMultiplyAdd::PortType VisualShaderNodeMultiplyAdd::get_input_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_4D:
- return PORT_TYPE_VECTOR_4D;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeMultiplyAdd::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "a";
- } else if (p_port == 1) {
- return "b(*)";
- } else if (p_port == 2) {
- return "c(+)";
- }
- return "";
- }
- int VisualShaderNodeMultiplyAdd::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeMultiplyAdd::PortType VisualShaderNodeMultiplyAdd::get_output_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return p_port == 0 ? PORT_TYPE_VECTOR_2D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_3D:
- return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
- case OP_TYPE_VECTOR_4D:
- return p_port == 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeMultiplyAdd::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeMultiplyAdd::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
- return " " + p_output_vars[0] + " = (" + p_input_vars[0] + " * " + p_input_vars[1] + ") + " + p_input_vars[2] + ";\n";
- }
- return " " + p_output_vars[0] + " = fma(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- void VisualShaderNodeMultiplyAdd::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX((int)p_op_type, int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_SCALAR: {
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0));
- set_input_port_default_value(1, 1.0, get_input_port_default_value(1));
- set_input_port_default_value(2, 0.0, get_input_port_default_value(2));
- } break;
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector2(1.0, 1.0), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector2(), get_input_port_default_value(2));
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector3(1.0, 1.0, 1.0), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector3(), get_input_port_default_value(2));
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Vector4(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector4(1.0, 1.0, 1.0, 1.0), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector4(), get_input_port_default_value(2));
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- VisualShaderNodeMultiplyAdd::OpType VisualShaderNodeMultiplyAdd::get_op_type() const {
- return op_type;
- }
- Vector<StringName> VisualShaderNodeMultiplyAdd::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("op_type");
- return props;
- }
- void VisualShaderNodeMultiplyAdd::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_op_type", "type"), &VisualShaderNodeMultiplyAdd::set_op_type);
- ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeMultiplyAdd::get_op_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector3,Vector4"), "set_op_type", "get_op_type");
- BIND_ENUM_CONSTANT(OP_TYPE_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D);
- BIND_ENUM_CONSTANT(OP_TYPE_MAX);
- }
- VisualShaderNodeMultiplyAdd::VisualShaderNodeMultiplyAdd() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 1.0);
- set_input_port_default_value(2, 0.0);
- }
- ////////////// Billboard
- String VisualShaderNodeBillboard::get_caption() const {
- return "GetBillboardMatrix";
- }
- int VisualShaderNodeBillboard::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeBillboard::PortType VisualShaderNodeBillboard::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeBillboard::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeBillboard::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeBillboard::PortType VisualShaderNodeBillboard::get_output_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeBillboard::get_output_port_name(int p_port) const {
- return "model_view_matrix";
- }
- String VisualShaderNodeBillboard::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- switch (billboard_type) {
- case BILLBOARD_TYPE_ENABLED:
- code += " {\n";
- code += " mat4 __mvm = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], INV_VIEW_MATRIX[1], INV_VIEW_MATRIX[2], MODEL_MATRIX[3]);\n";
- if (keep_scale) {
- code += " __mvm = __mvm * mat4(vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
- }
- code += " " + p_output_vars[0] + " = __mvm;\n";
- code += " }\n";
- break;
- case BILLBOARD_TYPE_FIXED_Y:
- code += " {\n";
- code += " mat4 __mvm = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], MODEL_MATRIX[1], vec4(normalize(cross(INV_VIEW_MATRIX[0].xyz, MODEL_MATRIX[1].xyz)), 0.0), MODEL_MATRIX[3]);\n";
- if (keep_scale) {
- code += " __mvm = __mvm * mat4(vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
- } else {
- code += " __mvm = __mvm * mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0 / length(MODEL_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
- }
- code += " " + p_output_vars[0] + " = __mvm;\n";
- code += " }\n";
- break;
- case BILLBOARD_TYPE_PARTICLES:
- code += " {\n";
- code += " mat4 __wm = mat4(normalize(INV_VIEW_MATRIX[0]), normalize(INV_VIEW_MATRIX[1]), normalize(INV_VIEW_MATRIX[2]), MODEL_MATRIX[3]);\n";
- code += " __wm = __wm * mat4(vec4(cos(INSTANCE_CUSTOM.x), -sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
- if (keep_scale) {
- code += " __wm = __wm * mat4(vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
- }
- code += " " + p_output_vars[0] + " = VIEW_MATRIX * __wm;\n";
- code += " }\n";
- break;
- default:
- code += " " + p_output_vars[0] + " = mat4(1.0);\n";
- break;
- }
- return code;
- }
- bool VisualShaderNodeBillboard::is_show_prop_names() const {
- return true;
- }
- void VisualShaderNodeBillboard::set_billboard_type(BillboardType p_billboard_type) {
- ERR_FAIL_INDEX(int(p_billboard_type), int(BILLBOARD_TYPE_MAX));
- if (billboard_type == p_billboard_type) {
- return;
- }
- billboard_type = p_billboard_type;
- simple_decl = bool(billboard_type == BILLBOARD_TYPE_DISABLED);
- set_disabled(simple_decl);
- emit_changed();
- }
- VisualShaderNodeBillboard::BillboardType VisualShaderNodeBillboard::get_billboard_type() const {
- return billboard_type;
- }
- void VisualShaderNodeBillboard::set_keep_scale_enabled(bool p_enabled) {
- keep_scale = p_enabled;
- emit_changed();
- }
- bool VisualShaderNodeBillboard::is_keep_scale_enabled() const {
- return keep_scale;
- }
- Vector<StringName> VisualShaderNodeBillboard::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("billboard_type");
- if (billboard_type == BILLBOARD_TYPE_ENABLED || billboard_type == BILLBOARD_TYPE_FIXED_Y || billboard_type == BILLBOARD_TYPE_PARTICLES) {
- props.push_back("keep_scale");
- }
- return props;
- }
- void VisualShaderNodeBillboard::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_billboard_type", "billboard_type"), &VisualShaderNodeBillboard::set_billboard_type);
- ClassDB::bind_method(D_METHOD("get_billboard_type"), &VisualShaderNodeBillboard::get_billboard_type);
- ClassDB::bind_method(D_METHOD("set_keep_scale_enabled", "enabled"), &VisualShaderNodeBillboard::set_keep_scale_enabled);
- ClassDB::bind_method(D_METHOD("is_keep_scale_enabled"), &VisualShaderNodeBillboard::is_keep_scale_enabled);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "billboard_type", PROPERTY_HINT_ENUM, "Disabled,Enabled,Y-Billboard,Particles"), "set_billboard_type", "get_billboard_type");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_scale"), "set_keep_scale_enabled", "is_keep_scale_enabled");
- BIND_ENUM_CONSTANT(BILLBOARD_TYPE_DISABLED);
- BIND_ENUM_CONSTANT(BILLBOARD_TYPE_ENABLED);
- BIND_ENUM_CONSTANT(BILLBOARD_TYPE_FIXED_Y);
- BIND_ENUM_CONSTANT(BILLBOARD_TYPE_PARTICLES);
- BIND_ENUM_CONSTANT(BILLBOARD_TYPE_MAX);
- }
- VisualShaderNodeBillboard::VisualShaderNodeBillboard() {
- simple_decl = false;
- }
- ////////////// DistanceFade
- String VisualShaderNodeDistanceFade::get_caption() const {
- return "DistanceFade";
- }
- int VisualShaderNodeDistanceFade::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeDistanceFade::PortType VisualShaderNodeDistanceFade::get_input_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_SCALAR;
- case 1:
- return PORT_TYPE_SCALAR;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeDistanceFade::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "min";
- case 1:
- return "max";
- }
- return "";
- }
- int VisualShaderNodeDistanceFade::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeDistanceFade::PortType VisualShaderNodeDistanceFade::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeDistanceFade::get_output_port_name(int p_port) const {
- return "amount";
- }
- bool VisualShaderNodeDistanceFade::has_output_port_preview(int p_port) const {
- return false;
- }
- String VisualShaderNodeDistanceFade::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- code += vformat(" %s = clamp(smoothstep(%s, %s, length(VERTEX)), 0.0, 1.0);\n", p_output_vars[0], p_input_vars[0], p_input_vars[1]);
- return code;
- }
- VisualShaderNodeDistanceFade::VisualShaderNodeDistanceFade() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 10.0);
- }
- ////////////// ProximityFade
- String VisualShaderNodeProximityFade::get_caption() const {
- return "ProximityFade";
- }
- int VisualShaderNodeProximityFade::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeProximityFade::PortType VisualShaderNodeProximityFade::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeProximityFade::get_input_port_name(int p_port) const {
- return "distance";
- }
- int VisualShaderNodeProximityFade::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeProximityFade::PortType VisualShaderNodeProximityFade::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeProximityFade::get_output_port_name(int p_port) const {
- return "fade";
- }
- bool VisualShaderNodeProximityFade::has_output_port_preview(int p_port) const {
- return false;
- }
- String VisualShaderNodeProximityFade::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- return "uniform sampler2D " + make_unique_id(p_type, p_id, "depth_tex") + " : hint_depth_texture;\n";
- }
- String VisualShaderNodeProximityFade::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- code += " {\n";
- code += " float __depth_tex = texture(" + make_unique_id(p_type, p_id, "depth_tex") + ", SCREEN_UV).r;\n";
- if (!RenderingServer::get_singleton()->is_low_end()) {
- code += " vec4 __depth_world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, __depth_tex, 1.0);\n";
- } else {
- code += " vec4 __depth_world_pos = INV_PROJECTION_MATRIX * vec4(vec3(SCREEN_UV, __depth_tex) * 2.0 - 1.0, 1.0);\n";
- }
- code += " __depth_world_pos.xyz /= __depth_world_pos.w;\n";
- code += vformat(" %s = clamp(1.0 - smoothstep(__depth_world_pos.z + %s, __depth_world_pos.z, VERTEX.z), 0.0, 1.0);\n", p_output_vars[0], p_input_vars[0]);
- code += " }\n";
- return code;
- }
- VisualShaderNodeProximityFade::VisualShaderNodeProximityFade() {
- set_input_port_default_value(0, 1.0);
- simple_decl = false;
- }
- ////////////// Random Range
- String VisualShaderNodeRandomRange::get_caption() const {
- return "RandomRange";
- }
- int VisualShaderNodeRandomRange::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeRandomRange::PortType VisualShaderNodeRandomRange::get_input_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR_3D;
- case 1:
- return PORT_TYPE_SCALAR;
- case 2:
- return PORT_TYPE_SCALAR;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeRandomRange::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "seed";
- case 1:
- return "min";
- case 2:
- return "max";
- default:
- break;
- }
- return "";
- }
- int VisualShaderNodeRandomRange::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeRandomRange::PortType VisualShaderNodeRandomRange::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeRandomRange::get_output_port_name(int p_port) const {
- return "value";
- }
- String VisualShaderNodeRandomRange::generate_global_per_node(Shader::Mode p_mode, int p_id) const {
- String code;
- code += "\n\n";
- code += "// 3D Noise with friendly permission by Inigo Quilez\n";
- code += "vec3 hash_noise_range( vec3 p ) {\n";
- code += " p *= mat3(vec3(127.1, 311.7, -53.7), vec3(269.5, 183.3, 77.1), vec3(-301.7, 27.3, 215.3));\n";
- code += " return 2.0 * fract(fract(p)*4375.55) -1.;\n";
- code += "}\n";
- code += "\n";
- return code;
- }
- String VisualShaderNodeRandomRange::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- code += vformat(" %s = mix(%s, %s, hash_noise_range(%s).x);\n", p_output_vars[0], p_input_vars[1], p_input_vars[2], p_input_vars[0]);
- return code;
- }
- VisualShaderNodeRandomRange::VisualShaderNodeRandomRange() {
- set_input_port_default_value(0, Vector3(1.0, 1.0, 1.0));
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, 1.0);
- }
- ////////////// Remap
- String VisualShaderNodeRemap::get_caption() const {
- return "Remap";
- }
- int VisualShaderNodeRemap::get_input_port_count() const {
- return 5;
- }
- VisualShaderNodeRemap::PortType VisualShaderNodeRemap::get_input_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_2D_SCALAR:
- if (p_port == 0) {
- return PORT_TYPE_VECTOR_2D;
- }
- break;
- case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_3D_SCALAR:
- if (p_port == 0) {
- return PORT_TYPE_VECTOR_3D;
- }
- break;
- case OP_TYPE_VECTOR_4D:
- return PORT_TYPE_VECTOR_4D;
- case OP_TYPE_VECTOR_4D_SCALAR:
- if (p_port == 0) {
- return PORT_TYPE_VECTOR_4D;
- }
- break;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeRemap::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "value";
- case 1:
- return "input min";
- case 2:
- return "input max";
- case 3:
- return "output min";
- case 4:
- return "output max";
- default:
- break;
- }
- return "";
- }
- int VisualShaderNodeRemap::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeRemap::PortType VisualShaderNodeRemap::get_output_port_type(int p_port) const {
- switch (op_type) {
- case OP_TYPE_VECTOR_2D:
- case OP_TYPE_VECTOR_2D_SCALAR:
- return PORT_TYPE_VECTOR_2D;
- case OP_TYPE_VECTOR_3D:
- case OP_TYPE_VECTOR_3D_SCALAR:
- return PORT_TYPE_VECTOR_3D;
- case OP_TYPE_VECTOR_4D:
- case OP_TYPE_VECTOR_4D_SCALAR:
- return PORT_TYPE_VECTOR_4D;
- default:
- return PORT_TYPE_SCALAR;
- }
- }
- String VisualShaderNodeRemap::get_output_port_name(int p_port) const {
- return "value";
- }
- void VisualShaderNodeRemap::set_op_type(OpType p_op_type) {
- ERR_FAIL_INDEX(int(p_op_type), int(OP_TYPE_MAX));
- if (op_type == p_op_type) {
- return;
- }
- switch (p_op_type) {
- case OP_TYPE_SCALAR: {
- set_input_port_default_value(0, 0.0, get_input_port_default_value(0));
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1));
- set_input_port_default_value(2, 1.0, get_input_port_default_value(2));
- set_input_port_default_value(3, 0.0, get_input_port_default_value(3));
- set_input_port_default_value(4, 1.0, get_input_port_default_value(4));
- } break;
- case OP_TYPE_VECTOR_2D: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector2(), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector2(1.0, 1.0), get_input_port_default_value(2));
- set_input_port_default_value(3, Vector2(), get_input_port_default_value(3));
- set_input_port_default_value(4, Vector2(1.0, 1.0), get_input_port_default_value(4));
- } break;
- case OP_TYPE_VECTOR_2D_SCALAR: {
- set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1));
- set_input_port_default_value(2, 1.0, get_input_port_default_value(2));
- set_input_port_default_value(3, 0.0, get_input_port_default_value(3));
- set_input_port_default_value(4, 1.0, get_input_port_default_value(4));
- } break;
- case OP_TYPE_VECTOR_3D: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- set_input_port_default_value(1, Vector3(), get_input_port_default_value(1));
- set_input_port_default_value(2, Vector3(1.0, 1.0, 1.0), get_input_port_default_value(2));
- set_input_port_default_value(3, Vector3(), get_input_port_default_value(3));
- set_input_port_default_value(4, Vector3(1.0, 1.0, 1.0), get_input_port_default_value(4));
- } break;
- case OP_TYPE_VECTOR_3D_SCALAR: {
- set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1));
- set_input_port_default_value(2, 1.0, get_input_port_default_value(2));
- set_input_port_default_value(3, 0.0, get_input_port_default_value(3));
- set_input_port_default_value(4, 1.0, get_input_port_default_value(4));
- } break;
- case OP_TYPE_VECTOR_4D: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- set_input_port_default_value(1, Quaternion(), get_input_port_default_value(1));
- set_input_port_default_value(2, Quaternion(1.0, 1.0, 1.0, 1.0), get_input_port_default_value(2));
- set_input_port_default_value(3, Quaternion(), get_input_port_default_value(3));
- set_input_port_default_value(4, Quaternion(1.0, 1.0, 1.0, 1.0), get_input_port_default_value(4));
- } break;
- case OP_TYPE_VECTOR_4D_SCALAR: {
- set_input_port_default_value(0, Quaternion(), get_input_port_default_value(0));
- set_input_port_default_value(1, 0.0, get_input_port_default_value(1));
- set_input_port_default_value(2, 1.0, get_input_port_default_value(2));
- set_input_port_default_value(3, 0.0, get_input_port_default_value(3));
- set_input_port_default_value(4, 1.0, get_input_port_default_value(4));
- } break;
- default:
- break;
- }
- op_type = p_op_type;
- emit_changed();
- }
- VisualShaderNodeRemap::OpType VisualShaderNodeRemap::get_op_type() const {
- return op_type;
- }
- String VisualShaderNodeRemap::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- code += " {\n";
- switch (op_type) {
- case OP_TYPE_SCALAR: {
- code += vformat(" float __input_range = %s - %s;\n", p_input_vars[2], p_input_vars[1]);
- code += vformat(" float __output_range = %s - %s;\n", p_input_vars[4], p_input_vars[3]);
- code += vformat(" %s = %s + __output_range * ((%s - %s) / __input_range);\n", p_output_vars[0], p_input_vars[3], p_input_vars[0], p_input_vars[1]);
- } break;
- case OP_TYPE_VECTOR_2D: {
- code += vformat(" vec2 __input_range = %s - %s;\n", p_input_vars[2], p_input_vars[1]);
- code += vformat(" vec2 __output_range = %s - %s;\n", p_input_vars[4], p_input_vars[3]);
- code += vformat(" %s = %s + __output_range * ((%s - %s) / __input_range);\n", p_output_vars[0], p_input_vars[3], p_input_vars[0], p_input_vars[1]);
- } break;
- case OP_TYPE_VECTOR_2D_SCALAR: {
- code += vformat(" vec2 __input_range = vec2(%s - %s);\n", p_input_vars[2], p_input_vars[1]);
- code += vformat(" vec2 __output_range = vec2(%s - %s);\n", p_input_vars[4], p_input_vars[3]);
- code += vformat(" %s = vec2(%s) + __output_range * ((%s - vec2(%s)) / __input_range);\n", p_output_vars[0], p_input_vars[3], p_input_vars[0], p_input_vars[1]);
- } break;
- case OP_TYPE_VECTOR_3D: {
- code += vformat(" vec3 __input_range = %s - %s;\n", p_input_vars[2], p_input_vars[1]);
- code += vformat(" vec3 __output_range = %s - %s;\n", p_input_vars[4], p_input_vars[3]);
- code += vformat(" %s = %s + __output_range * ((%s - %s) / __input_range);\n", p_output_vars[0], p_input_vars[3], p_input_vars[0], p_input_vars[1]);
- } break;
- case OP_TYPE_VECTOR_3D_SCALAR: {
- code += vformat(" vec3 __input_range = vec3(%s - %s);\n", p_input_vars[2], p_input_vars[1]);
- code += vformat(" vec3 __output_range = vec3(%s - %s);\n", p_input_vars[4], p_input_vars[3]);
- code += vformat(" %s = vec3(%s) + __output_range * ((%s - vec3(%s)) / __input_range);\n", p_output_vars[0], p_input_vars[3], p_input_vars[0], p_input_vars[1]);
- } break;
- case OP_TYPE_VECTOR_4D: {
- code += vformat(" vec4 __input_range = %s - %s;\n", p_input_vars[2], p_input_vars[1]);
- code += vformat(" vec4 __output_range = %s - %s;\n", p_input_vars[4], p_input_vars[3]);
- code += vformat(" %s = %s + __output_range * ((%s - %s) / __input_range);\n", p_output_vars[0], p_input_vars[3], p_input_vars[0], p_input_vars[1]);
- } break;
- case OP_TYPE_VECTOR_4D_SCALAR: {
- code += vformat(" vec4 __input_range = vec4(%s - %s);\n", p_input_vars[2], p_input_vars[1]);
- code += vformat(" vec4 __output_range = vec4(%s - %s);\n", p_input_vars[4], p_input_vars[3]);
- code += vformat(" %s = vec4(%s) + __output_range * ((%s - vec4(%s)) / __input_range);\n", p_output_vars[0], p_input_vars[3], p_input_vars[0], p_input_vars[1]);
- } break;
- default:
- break;
- }
- code += " }\n";
- return code;
- }
- Vector<StringName> VisualShaderNodeRemap::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("op_type");
- return props;
- }
- void VisualShaderNodeRemap::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_op_type", "op_type"), &VisualShaderNodeRemap::set_op_type);
- ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeRemap::get_op_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector2Scalar,Vector3,Vector3Scalar,Vector4,Vector4Scalar"), "set_op_type", "get_op_type");
- BIND_ENUM_CONSTANT(OP_TYPE_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_MAX);
- }
- VisualShaderNodeRemap::VisualShaderNodeRemap() {
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, 1.0);
- set_input_port_default_value(3, 0.0);
- set_input_port_default_value(4, 1.0);
- simple_decl = false;
- }
- ////////////// RotationByAxis
- String VisualShaderNodeRotationByAxis::get_caption() const {
- return "RotationByAxis";
- }
- int VisualShaderNodeRotationByAxis::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeRotationByAxis::PortType VisualShaderNodeRotationByAxis::get_input_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR_3D;
- case 1:
- return PORT_TYPE_SCALAR;
- case 2:
- return PORT_TYPE_VECTOR_3D;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeRotationByAxis::get_input_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "input";
- case 1:
- return "angle";
- case 2:
- return "axis";
- default:
- break;
- }
- return "";
- }
- int VisualShaderNodeRotationByAxis::get_output_port_count() const {
- return 2;
- }
- VisualShaderNodeRotationByAxis::PortType VisualShaderNodeRotationByAxis::get_output_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR_3D;
- case 1:
- return PORT_TYPE_TRANSFORM;
- default:
- break;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeRotationByAxis::get_output_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "output";
- case 1:
- return "rotationMat";
- default:
- break;
- }
- return "";
- }
- bool VisualShaderNodeRotationByAxis::has_output_port_preview(int p_port) const {
- if (p_port == 0) {
- return true;
- }
- return false;
- }
- String VisualShaderNodeRotationByAxis::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- code += " {\n";
- code += vformat(" float __angle = %s;\n", p_input_vars[1]);
- code += vformat(" vec3 __axis = normalize(%s);\n", p_input_vars[2]);
- code += vformat(" mat3 __rot_matrix = mat3(\n");
- code += vformat(" vec3( cos(__angle)+__axis.x*__axis.x*(1.0 - cos(__angle)), __axis.x*__axis.y*(1.0-cos(__angle))-__axis.z*sin(__angle), __axis.x*__axis.z*(1.0-cos(__angle))+__axis.y*sin(__angle) ),\n");
- code += vformat(" vec3( __axis.y*__axis.x*(1.0-cos(__angle))+__axis.z*sin(__angle), cos(__angle)+__axis.y*__axis.y*(1.0-cos(__angle)), __axis.y*__axis.z*(1.0-cos(__angle))-__axis.x*sin(__angle) ),\n");
- code += vformat(" vec3( __axis.z*__axis.x*(1.0-cos(__angle))-__axis.y*sin(__angle), __axis.z*__axis.y*(1.0-cos(__angle))+__axis.x*sin(__angle), cos(__angle)+__axis.z*__axis.z*(1.0-cos(__angle)) )\n");
- code += vformat(" );\n");
- if (is_output_port_connected(0)) {
- code += vformat(" %s = %s * __rot_matrix;\n", p_output_vars[0], p_input_vars[0]);
- }
- if (is_output_port_connected(1)) {
- code += vformat(" %s = mat4(__rot_matrix);\n", p_output_vars[1]);
- }
- code += " }\n";
- return code;
- }
- VisualShaderNodeRotationByAxis::VisualShaderNodeRotationByAxis() {
- set_input_port_default_value(0, Vector3());
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, Vector3());
- simple_decl = false;
- }
- String VisualShaderNodeReroute::get_caption() const {
- return "Reroute";
- }
- int VisualShaderNodeReroute::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeReroute::PortType VisualShaderNodeReroute::get_input_port_type(int p_port) const {
- return input_port_type;
- }
- String VisualShaderNodeReroute::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeReroute::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeReroute::PortType VisualShaderNodeReroute::get_output_port_type(int p_port) const {
- return input_port_type;
- }
- String VisualShaderNodeReroute::get_output_port_name(int p_port) const {
- return String();
- }
- String VisualShaderNodeReroute::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- String code;
- for (int i = 0; i < get_output_port_count(); i++) {
- if (input_port_type == PORT_TYPE_SAMPLER) {
- continue;
- }
- String input = p_input_vars[0];
- if (input.is_empty()) {
- code += vformat(" %s;\n", p_output_vars[i]);
- continue;
- }
- code += vformat(" %s = %s;\n", p_output_vars[i], input);
- }
- return code;
- }
- void VisualShaderNodeReroute::_set_port_type(PortType p_type) {
- input_port_type = p_type;
- switch (p_type) {
- case PORT_TYPE_SCALAR:
- set_input_port_default_value(0, 0.0);
- break;
- case PORT_TYPE_VECTOR_2D:
- set_input_port_default_value(0, Vector2());
- break;
- case PORT_TYPE_VECTOR_3D:
- set_input_port_default_value(0, Vector3());
- break;
- case PORT_TYPE_VECTOR_4D:
- set_input_port_default_value(0, Vector4());
- break;
- case PORT_TYPE_TRANSFORM:
- set_input_port_default_value(0, Transform3D());
- break;
- default:
- break;
- }
- }
- void VisualShaderNodeReroute::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_set_port_type", "port_type"), &VisualShaderNodeReroute::_set_port_type);
- ClassDB::bind_method(D_METHOD("get_port_type"), &VisualShaderNodeReroute::get_port_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "port_type", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_port_type", "get_port_type");
- }
- VisualShaderNodeReroute::VisualShaderNodeReroute() {
- set_input_port_default_value(0, 0.0);
- }
|