12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421 |
- /**************************************************************************/
- /* 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"
- ////////////// Scalar
- String VisualShaderNodeScalarConstant::get_caption() const {
- return "Scalar";
- }
- int VisualShaderNodeScalarConstant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeScalarConstant::PortType VisualShaderNodeScalarConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarConstant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeScalarConstant::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeScalarConstant::PortType VisualShaderNodeScalarConstant::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarConstant::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeScalarConstant::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 "\t" + p_output_vars[0] + " = " + vformat("%.6f", constant) + ";\n";
- }
- void VisualShaderNodeScalarConstant::set_constant(float p_value) {
- constant = p_value;
- emit_changed();
- }
- float VisualShaderNodeScalarConstant::get_constant() const {
- return constant;
- }
- Vector<StringName> VisualShaderNodeScalarConstant::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("constant");
- return props;
- }
- void VisualShaderNodeScalarConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant", "value"), &VisualShaderNodeScalarConstant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeScalarConstant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeScalarConstant::VisualShaderNodeScalarConstant() {
- constant = 0;
- }
- ////////////// Boolean
- String VisualShaderNodeBooleanConstant::get_caption() const {
- return "Boolean";
- }
- 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 "\t" + p_output_vars[0] + " = " + (constant ? "true" : "false") + ";\n";
- }
- void VisualShaderNodeBooleanConstant::set_constant(bool p_value) {
- constant = p_value;
- 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", "value"), &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() {
- constant = false;
- }
- ////////////// Color
- String VisualShaderNodeColorConstant::get_caption() const {
- return "Color";
- }
- int VisualShaderNodeColorConstant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeColorConstant::PortType VisualShaderNodeColorConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeColorConstant::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeColorConstant::get_output_port_count() const {
- return 2;
- }
- VisualShaderNodeColorConstant::PortType VisualShaderNodeColorConstant::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeColorConstant::get_output_port_name(int p_port) const {
- return p_port == 0 ? "" : "alpha"; //no output port means the editor will be used as port
- }
- 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 {
- String code;
- code += "\t" + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.r, constant.g, constant.b) + ";\n";
- code += "\t" + p_output_vars[1] + " = " + vformat("%.6f", constant.a) + ";\n";
- return code;
- }
- void VisualShaderNodeColorConstant::set_constant(Color p_value) {
- constant = p_value;
- 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", "value"), &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() {
- constant = Color(1, 1, 1, 1);
- }
- ////////////// Vector
- String VisualShaderNodeVec3Constant::get_caption() const {
- return "Vector";
- }
- int VisualShaderNodeVec3Constant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeVec3Constant::PortType VisualShaderNodeVec3Constant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- 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 PORT_TYPE_VECTOR;
- }
- 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 "\t" + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.x, constant.y, constant.z) + ";\n";
- }
- void VisualShaderNodeVec3Constant::set_constant(Vector3 p_value) {
- constant = p_value;
- 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", "value"), &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() {
- }
- ////////////// Transform
- String VisualShaderNodeTransformConstant::get_caption() const {
- return "Transform";
- }
- int VisualShaderNodeTransformConstant::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeTransformConstant::PortType VisualShaderNodeTransformConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- 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 {
- Transform t = constant;
- t.basis.transpose();
- String code = "\t" + 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(Transform p_value) {
- constant = p_value;
- emit_changed();
- }
- Transform 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", "value"), &VisualShaderNodeTransformConstant::set_constant);
- ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeTransformConstant::get_constant);
- ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "constant"), "set_constant", "get_constant");
- }
- VisualShaderNodeTransformConstant::VisualShaderNodeTransformConstant() {
- }
- ////////////// Texture
- String VisualShaderNodeTexture::get_caption() const {
- return "Texture";
- }
- 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;
- 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 2;
- }
- VisualShaderNodeTexture::PortType VisualShaderNodeTexture::get_output_port_type(int p_port) const {
- if (p_port == 0 && source == SOURCE_DEPTH) {
- return PORT_TYPE_SCALAR;
- }
- return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeTexture::get_output_port_name(int p_port) const {
- if (p_port == 0 && source == SOURCE_DEPTH) {
- return "depth";
- }
- return p_port == 0 ? "rgb" : "alpha";
- }
- String VisualShaderNodeTexture::get_input_port_default_hint(int p_port) const {
- if (p_port == 0) {
- return "UV.xy";
- }
- return "";
- }
- static String make_unique_id(VisualShader::Type p_type, int p_id, const String &p_name) {
- static const char *typepf[VisualShader::TYPE_MAX] = { "vtx", "frg", "lgt" };
- return p_name + "_" + String(typepf[p_type]) + "_" + itos(p_id);
- }
- 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.param = 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 {
- if (source == SOURCE_TEXTURE) {
- String u = "uniform sampler2D " + make_unique_id(p_type, p_id, "tex");
- switch (texture_type) {
- case TYPE_DATA:
- break;
- case TYPE_COLOR:
- u += " : hint_albedo";
- break;
- case TYPE_NORMALMAP:
- u += " : hint_normal";
- break;
- }
- return u + ";\n";
- }
- return String();
- }
- 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 {
- if (source == SOURCE_TEXTURE) {
- String id = make_unique_id(p_type, p_id, "tex");
- String code;
- if (p_input_vars[0] == String()) { // Use UV by default.
- if (p_input_vars[1] == String()) {
- code += "\tvec4 " + id + "_read = texture(" + id + ", UV.xy);\n";
- } else {
- code += "\tvec4 " + id + "_read = textureLod(" + id + ", UV.xy, " + p_input_vars[1] + ");\n";
- }
- } else if (p_input_vars[1] == String()) {
- //no lod
- code += "\tvec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n";
- } else {
- code += "\tvec4 " + id + "_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
- }
- code += "\t" + p_output_vars[0] + " = " + id + "_read.rgb;\n";
- code += "\t" + p_output_vars[1] + " = " + id + "_read.a;\n";
- return code;
- }
- if (source == SOURCE_PORT) {
- String id = p_input_vars[2];
- String code;
- code += "\t{\n";
- if (id == String()) {
- code += "\t\tvec4 " + id + "_tex_read = vec4(0.0);\n";
- } else {
- if (p_input_vars[0] == String()) { // Use UV by default.
- if (p_input_vars[1] == String()) {
- code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", UV.xy);\n";
- } else {
- code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", UV.xy, " + p_input_vars[1] + ");\n";
- }
- } else if (p_input_vars[1] == String()) {
- //no lod
- code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n";
- } else {
- code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
- }
- code += "\t\t" + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = " + id + "_tex_read.a;\n";
- }
- code += "\t}\n";
- return code;
- }
- if (source == SOURCE_SCREEN && (p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) {
- String code = "\t{\n";
- if (p_input_vars[0] == String() || p_for_preview) { // Use UV by default.
- if (p_input_vars[1] == String()) {
- code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, UV.xy, 0.0 );\n";
- } else {
- code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, UV.xy, " + p_input_vars[1] + ");\n";
- }
- } else if (p_input_vars[1] == String()) {
- //no lod
- code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, 0.0);\n";
- } else {
- code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
- }
- code += "\t\t" + p_output_vars[0] + " = _tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = _tex_read.a;\n";
- code += "\t}\n";
- return code;
- }
- if (source == SOURCE_2D_TEXTURE && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) {
- String code = "\t{\n";
- if (p_input_vars[0] == String()) { // Use UV by default.
- if (p_input_vars[1] == String()) {
- code += "\t\tvec4 _tex_read = texture(TEXTURE , UV.xy);\n";
- } else {
- code += "\t\tvec4 _tex_read = textureLod(TEXTURE, UV.xy, " + p_input_vars[1] + ");\n";
- }
- } else if (p_input_vars[1] == String()) {
- //no lod
- code += "\t\tvec4 _tex_read = texture(TEXTURE, " + p_input_vars[0] + ".xy);\n";
- } else {
- code += "\t\tvec4 _tex_read = textureLod(TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
- }
- code += "\t\t" + p_output_vars[0] + " = _tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = _tex_read.a;\n";
- code += "\t}\n";
- return code;
- }
- if (source == SOURCE_2D_NORMAL && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) {
- String code = "\t{\n";
- if (p_input_vars[0] == String()) { // Use UV by default.
- if (p_input_vars[1] == String()) {
- code += "\t\tvec4 _tex_read = texture(NORMAL_TEXTURE, UV.xy);\n";
- } else {
- code += "\t\tvec4 _tex_read = textureLod(NORMAL_TEXTURE, UV.xy, " + p_input_vars[1] + ");\n";
- }
- } else if (p_input_vars[1] == String()) {
- //no lod
- code += "\t\tvec4 _tex_read = texture(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy);\n";
- } else {
- code += "\t\tvec4 _tex_read = textureLod(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
- }
- code += "\t\t" + p_output_vars[0] + " = _tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = _tex_read.a;\n";
- code += "\t}\n";
- return code;
- }
- if (p_for_preview) // DEPTH_TEXTURE is not supported in preview(canvas_item) shader
- {
- if (source == SOURCE_DEPTH) {
- String code;
- code += "\t" + p_output_vars[0] + " = 0.0;\n";
- code += "\t" + p_output_vars[1] + " = 1.0;\n";
- return code;
- }
- }
- if (source == SOURCE_DEPTH && p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) {
- String code = "\t{\n";
- if (p_input_vars[0] == String()) { // Use UV by default.
- if (p_input_vars[1] == String()) {
- code += "\t\tfloat _depth = texture(DEPTH_TEXTURE, UV.xy).r;\n";
- } else {
- code += "\t\tfloat _depth = textureLod(DEPTH_TEXTURE, UV.xy, " + p_input_vars[1] + ").r;\n";
- }
- } else if (p_input_vars[1] == String()) {
- //no lod
- code += "\t\tfloat _depth = texture(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy).r;\n";
- } else {
- code += "\t\tfloat _depth = textureLod(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ").r;\n";
- }
- code += "\t\t" + p_output_vars[0] + " = _depth;\n";
- code += "\t\t" + p_output_vars[1] + " = 1.0;\n";
- code += "\t}\n";
- return code;
- } else if (source == SOURCE_DEPTH) {
- String code;
- code += "\t" + p_output_vars[0] + " = 0.0;\n";
- code += "\t" + p_output_vars[1] + " = 1.0;\n";
- return code;
- }
- //none
- String code;
- code += "\t" + p_output_vars[0] + " = vec3(0.0);\n";
- code += "\t" + p_output_vars[1] + " = 1.0;\n";
- return code;
- }
- void VisualShaderNodeTexture::set_source(Source p_source) {
- source = p_source;
- switch (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;
- }
- emit_changed();
- emit_signal("editor_refresh_request");
- }
- VisualShaderNodeTexture::Source VisualShaderNodeTexture::get_source() const {
- return source;
- }
- void VisualShaderNodeTexture::set_texture(Ref<Texture> p_value) {
- texture = p_value;
- emit_changed();
- }
- Ref<Texture> VisualShaderNodeTexture::get_texture() const {
- return texture;
- }
- void VisualShaderNodeTexture::set_texture_type(TextureType p_type) {
- texture_type = p_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 TTR("The sampler port is connected but not used. Consider changing the source to 'SamplerPort'.");
- }
- if (source == SOURCE_TEXTURE) {
- return String(); // all good
- }
- if (source == SOURCE_PORT) {
- return String(); // all good
- }
- if (source == SOURCE_SCREEN && (p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) {
- return String(); // all good
- }
- if (source == SOURCE_2D_TEXTURE && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) {
- return String(); // all good
- }
- if (source == SOURCE_2D_NORMAL && p_mode == Shader::MODE_CANVAS_ITEM) {
- return String(); // all good
- }
- if (source == SOURCE_DEPTH && p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) {
- if (get_output_port_for_preview() == 0) { // DEPTH_TEXTURE is not supported in preview(canvas_item) shader
- return TTR("Invalid source for preview.");
- }
- return String(); // all good
- }
- return TTR("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"), "set_source", "get_source");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_type", PROPERTY_HINT_ENUM, "Data,Color,Normalmap"), "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(TYPE_DATA);
- BIND_ENUM_CONSTANT(TYPE_COLOR);
- BIND_ENUM_CONSTANT(TYPE_NORMALMAP);
- }
- VisualShaderNodeTexture::VisualShaderNodeTexture() {
- texture_type = TYPE_DATA;
- source = SOURCE_TEXTURE;
- }
- ////////////// 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;
- 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 2;
- }
- VisualShaderNodeCubeMap::PortType VisualShaderNodeCubeMap::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeCubeMap::get_output_port_name(int p_port) const {
- return p_port == 0 ? "rgb" : "alpha";
- }
- 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.param = 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 += " : hint_albedo";
- break;
- case TYPE_NORMALMAP:
- u += " : hint_normal";
- 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 if (source == SOURCE_PORT) {
- id = p_input_vars[2];
- } else {
- return String();
- }
- code += "\t{\n";
- if (id == String()) {
- code += "\t\tvec4 " + id + "_read = vec4(0.0);\n";
- code += "\t\t" + p_output_vars[0] + " = " + id + "_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = " + id + "_read.a;\n";
- code += "\t}\n";
- return code;
- }
- if (p_input_vars[0] == String()) { // Use UV by default.
- if (p_input_vars[1] == String()) {
- code += "\t\tvec4 " + id + "_read = texture(" + id + " , vec3(UV, 0.0));\n";
- } else {
- code += "\t\tvec4 " + id + "_read = textureLod(" + id + " , vec3(UV, 0.0)" + " , " + p_input_vars[1] + " );\n";
- }
- } else if (p_input_vars[1] == String()) {
- //no lod
- code += "\t\tvec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ");\n";
- } else {
- code += "\t\tvec4 " + id + "_read = textureLod(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- }
- code += "\t\t" + p_output_vars[0] + " = " + id + "_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = " + id + "_read.a;\n";
- code += "\t}\n";
- return code;
- }
- String VisualShaderNodeCubeMap::get_input_port_default_hint(int p_port) const {
- if (p_port == 0) {
- return "vec3(UV, 0.0)";
- }
- return "";
- }
- void VisualShaderNodeCubeMap::set_source(Source p_source) {
- source = p_source;
- emit_changed();
- emit_signal("editor_refresh_request");
- }
- VisualShaderNodeCubeMap::Source VisualShaderNodeCubeMap::get_source() const {
- return source;
- }
- void VisualShaderNodeCubeMap::set_cube_map(Ref<CubeMap> p_value) {
- cube_map = p_value;
- emit_changed();
- }
- Ref<CubeMap> VisualShaderNodeCubeMap::get_cube_map() const {
- return cube_map;
- }
- void VisualShaderNodeCubeMap::set_texture_type(TextureType p_type) {
- texture_type = p_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 TTR("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"), "set_cube_map", "get_cube_map");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_type", PROPERTY_HINT_ENUM, "Data,Color,Normalmap"), "set_texture_type", "get_texture_type");
- BIND_ENUM_CONSTANT(SOURCE_TEXTURE);
- BIND_ENUM_CONSTANT(SOURCE_PORT);
- BIND_ENUM_CONSTANT(TYPE_DATA);
- BIND_ENUM_CONSTANT(TYPE_COLOR);
- BIND_ENUM_CONSTANT(TYPE_NORMALMAP);
- }
- VisualShaderNodeCubeMap::VisualShaderNodeCubeMap() {
- texture_type = TYPE_DATA;
- source = SOURCE_TEXTURE;
- simple_decl = false;
- }
- ////////////// Scalar Op
- String VisualShaderNodeScalarOp::get_caption() const {
- return "ScalarOp";
- }
- int VisualShaderNodeScalarOp::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeScalarOp::PortType VisualShaderNodeScalarOp::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarOp::get_input_port_name(int p_port) const {
- return p_port == 0 ? "a" : "b";
- }
- int VisualShaderNodeScalarOp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeScalarOp::PortType VisualShaderNodeScalarOp::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarOp::get_output_port_name(int p_port) const {
- return "op"; //no output port means the editor will be used as port
- }
- String VisualShaderNodeScalarOp::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 = "\t" + 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;
- }
- return code;
- }
- void VisualShaderNodeScalarOp::set_operator(Operator p_op) {
- op = p_op;
- emit_changed();
- }
- VisualShaderNodeScalarOp::Operator VisualShaderNodeScalarOp::get_operator() const {
- return op;
- }
- Vector<StringName> VisualShaderNodeScalarOp::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("operator");
- return props;
- }
- void VisualShaderNodeScalarOp::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeScalarOp::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeScalarOp::get_operator);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "Add,Sub,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);
- }
- VisualShaderNodeScalarOp::VisualShaderNodeScalarOp() {
- op = OP_ADD;
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- }
- ////////////// Vector Op
- String VisualShaderNodeVectorOp::get_caption() const {
- return "VectorOp";
- }
- int VisualShaderNodeVectorOp::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeVectorOp::PortType VisualShaderNodeVectorOp::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- 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;
- }
- VisualShaderNodeVectorOp::PortType VisualShaderNodeVectorOp::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorOp::get_output_port_name(int p_port) const {
- return "op"; //no output port means the editor will be used as port
- }
- 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 = "\t" + 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:
- 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;
- }
- return code;
- }
- void VisualShaderNodeVectorOp::set_operator(Operator p_op) {
- op = p_op;
- emit_changed();
- }
- VisualShaderNodeVectorOp::Operator VisualShaderNodeVectorOp::get_operator() const {
- return op;
- }
- Vector<StringName> VisualShaderNodeVectorOp::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("operator");
- return props;
- }
- 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,Sub,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);
- }
- VisualShaderNodeVectorOp::VisualShaderNodeVectorOp() {
- op = OP_ADD;
- set_input_port_default_value(0, Vector3());
- set_input_port_default_value(1, Vector3());
- }
- ////////////// 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;
- }
- 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 PORT_TYPE_VECTOR;
- }
- 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 += "\t" + 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 += "\t" + p_output_vars[0] + " = abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ");\n";
- } break;
- case OP_DARKEN: {
- code += "\t" + p_output_vars[0] + " = min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- } break;
- case OP_LIGHTEN: {
- code += "\t" + 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 += "\t{\n";
- code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
- code += "\t\tfloat blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
- code += "\t\tif (base < 0.5) {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = 2.0 * base * blend;\n";
- code += "\t\t} else {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);\n";
- code += "\t\t}\n";
- code += "\t}\n";
- }
- } break;
- case OP_DODGE: {
- code += "\t" + p_output_vars[0] + " = (" + p_input_vars[0] + ") / (vec3(1.0) - " + p_input_vars[1] + ");\n";
- } break;
- case OP_BURN: {
- code += "\t" + 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 += "\t{\n";
- code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
- code += "\t\tfloat blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
- code += "\t\tif (base < 0.5) {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (base * (blend + 0.5));\n";
- code += "\t\t} else {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - (blend - 0.5)));\n";
- code += "\t\t}\n";
- code += "\t}\n";
- }
- } break;
- case OP_HARD_LIGHT: {
- for (int i = 0; i < 3; i++) {
- code += "\t{\n";
- code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n";
- code += "\t\tfloat blend = " + p_input_vars[1] + "." + axisn[i] + ";\n";
- code += "\t\tif (base < 0.5) {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (base * (2.0 * blend));\n";
- code += "\t\t} else {\n";
- code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - 2.0 * (blend - 0.5)));\n";
- code += "\t\t}\n";
- code += "\t}\n";
- }
- } break;
- }
- return code;
- }
- void VisualShaderNodeColorOp::set_operator(Operator p_op) {
- op = p_op;
- switch (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;
- }
- 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,SoftLight,HardLight"), "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);
- }
- VisualShaderNodeColorOp::VisualShaderNodeColorOp() {
- op = OP_SCREEN;
- set_input_port_default_value(0, Vector3());
- set_input_port_default_value(1, Vector3());
- }
- ////////////// Transform Mult
- String VisualShaderNodeTransformMult::get_caption() const {
- return "TransformMult";
- }
- int VisualShaderNodeTransformMult::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeTransformMult::PortType VisualShaderNodeTransformMult::get_input_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformMult::get_input_port_name(int p_port) const {
- return p_port == 0 ? "a" : "b";
- }
- int VisualShaderNodeTransformMult::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeTransformMult::PortType VisualShaderNodeTransformMult::get_output_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformMult::get_output_port_name(int p_port) const {
- return "mult"; //no output port means the editor will be used as port
- }
- String VisualShaderNodeTransformMult::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 "\t" + p_output_vars[0] + " = " + p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
- } else if (op == OP_BxA) {
- return "\t" + p_output_vars[0] + " = " + p_input_vars[1] + " * " + p_input_vars[0] + ";\n";
- } else if (op == OP_AxB_COMP) {
- return "\t" + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- } else {
- return "\t" + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[1] + ", " + p_input_vars[0] + ");\n";
- }
- }
- void VisualShaderNodeTransformMult::set_operator(Operator p_op) {
- op = p_op;
- emit_changed();
- }
- VisualShaderNodeTransformMult::Operator VisualShaderNodeTransformMult::get_operator() const {
- return op;
- }
- Vector<StringName> VisualShaderNodeTransformMult::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("operator");
- return props;
- }
- void VisualShaderNodeTransformMult::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeTransformMult::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeTransformMult::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)"), "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);
- }
- VisualShaderNodeTransformMult::VisualShaderNodeTransformMult() {
- op = OP_AxB;
- set_input_port_default_value(0, Transform());
- set_input_port_default_value(1, Transform());
- }
- ////////////// 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;
- }
- 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 PORT_TYPE_VECTOR;
- }
- 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 "\t" + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 1.0)).xyz;\n";
- } else if (op == OP_BxA) {
- return "\t" + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 1.0) * " + p_input_vars[0] + ").xyz;\n";
- } else if (op == OP_3x3_AxB) {
- return "\t" + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 0.0)).xyz;\n";
- } else {
- return "\t" + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 0.0) * " + p_input_vars[0] + ").xyz;\n";
- }
- }
- void VisualShaderNodeTransformVecMult::set_operator(Operator p_op) {
- 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);
- }
- VisualShaderNodeTransformVecMult::VisualShaderNodeTransformVecMult() {
- op = OP_AxB;
- set_input_port_default_value(0, Transform());
- set_input_port_default_value(1, Vector3());
- }
- ////////////// Scalar Func
- String VisualShaderNodeScalarFunc::get_caption() const {
- return "ScalarFunc";
- }
- int VisualShaderNodeScalarFunc::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeScalarFunc::PortType VisualShaderNodeScalarFunc::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarFunc::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeScalarFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeScalarFunc::PortType VisualShaderNodeScalarFunc::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarFunc::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeScalarFunc::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 *scalar_func_id[FUNC_ONEMINUS + 1] = {
- "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 "\t" + p_output_vars[0] + " = " + String(scalar_func_id[func]).replace("$", p_input_vars[0]) + ";\n";
- }
- void VisualShaderNodeScalarFunc::set_function(Function p_func) {
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeScalarFunc::Function VisualShaderNodeScalarFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeScalarFunc::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeScalarFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeScalarFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeScalarFunc::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,Frac,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_FRAC);
- 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);
- }
- VisualShaderNodeScalarFunc::VisualShaderNodeScalarFunc() {
- func = FUNC_SIGN;
- set_input_port_default_value(0, 0.0);
- }
- ////////////// Vector Func
- String VisualShaderNodeVectorFunc::get_caption() const {
- return "VectorFunc";
- }
- int VisualShaderNodeVectorFunc::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorFunc::PortType VisualShaderNodeVectorFunc::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorFunc::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeVectorFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorFunc::PortType VisualShaderNodeVectorFunc::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorFunc::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- 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 *vec_func_id[FUNC_ONEMINUS + 1] = {
- "normalize($)",
- "max(min($, vec3(1.0)), vec3(0.0))",
- "-($)",
- "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($)",
- "vec3(1.0, 1.0, 1.0) - $"
- };
- String code;
- if (func == FUNC_RGB2HSV) {
- code += "\t{\n";
- code += "\t\tvec3 c = " + p_input_vars[0] + ";\n";
- code += "\t\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n";
- code += "\t\tvec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n";
- code += "\t\tvec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n";
- code += "\t\tfloat d = q.x - min(q.w, q.y);\n";
- code += "\t\tfloat e = 1.0e-10;\n";
- code += "\t\t" + p_output_vars[0] + " = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n";
- code += "\t}\n";
- } else if (func == FUNC_HSV2RGB) {
- code += "\t{\n";
- code += "\t\tvec3 c = " + p_input_vars[0] + ";\n";
- code += "\t\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n";
- code += "\t\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n";
- code += "\t\t" + p_output_vars[0] + " = c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n";
- code += "\t}\n";
- } else {
- code += "\t" + p_output_vars[0] + " = " + String(vec_func_id[func]).replace("$", p_input_vars[0]) + ";\n";
- }
- return code;
- }
- void VisualShaderNodeVectorFunc::set_function(Function p_func) {
- func = p_func;
- if (func == FUNC_RGB2HSV) {
- simple_decl = false;
- } else if (func == FUNC_HSV2RGB) {
- simple_decl = false;
- } else {
- simple_decl = true;
- }
- emit_changed();
- }
- VisualShaderNodeVectorFunc::Function VisualShaderNodeVectorFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeVectorFunc::get_editable_properties() const {
- Vector<StringName> props;
- 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,RGB2HSV,HSV2RGB,Abs,ACos,ACosH,ASin,ASinH,ATan,ATanH,Ceil,Cos,CosH,Degrees,Exp,Exp2,Floor,Frac,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_RGB2HSV);
- BIND_ENUM_CONSTANT(FUNC_HSV2RGB);
- 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_FRAC);
- 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);
- }
- VisualShaderNodeVectorFunc::VisualShaderNodeVectorFunc() {
- func = FUNC_NORMALIZE;
- set_input_port_default_value(0, Vector3());
- }
- ////////////// 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;
- }
- 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 PORT_TYPE_VECTOR;
- }
- 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 += "\t{\n";
- code += "\t\tvec3 c = " + p_input_vars[0] + ";\n";
- code += "\t\tfloat max1 = max(c.r, c.g);\n";
- code += "\t\tfloat max2 = max(max1, c.b);\n";
- code += "\t\t" + p_output_vars[0] + " = vec3(max2, max2, max2);\n";
- code += "\t}\n";
- break;
- case FUNC_SEPIA:
- code += "\t{\n";
- code += "\t\tvec3 c = " + p_input_vars[0] + ";\n";
- code += "\t\tfloat r = (c.r * .393) + (c.g *.769) + (c.b * .189);\n";
- code += "\t\tfloat g = (c.r * .349) + (c.g *.686) + (c.b * .168);\n";
- code += "\t\tfloat b = (c.r * .272) + (c.g *.534) + (c.b * .131);\n";
- code += "\t\t" + p_output_vars[0] + " = vec3(r, g, b);\n";
- code += "\t}\n";
- break;
- }
- return code;
- }
- void VisualShaderNodeColorFunc::set_function(Function p_func) {
- 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,Sepia"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_GRAYSCALE);
- BIND_ENUM_CONSTANT(FUNC_SEPIA);
- }
- VisualShaderNodeColorFunc::VisualShaderNodeColorFunc() {
- func = FUNC_GRAYSCALE;
- set_input_port_default_value(0, Vector3());
- simple_decl = false;
- }
- ////////////// 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 *funcs[FUNC_TRANSPOSE + 1] = {
- "inverse($)",
- "transpose($)"
- };
- String code;
- code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
- return code;
- }
- void VisualShaderNodeTransformFunc::set_function(Function p_func) {
- 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);
- }
- VisualShaderNodeTransformFunc::VisualShaderNodeTransformFunc() {
- func = FUNC_INVERSE;
- set_input_port_default_value(0, Transform());
- }
- ////////////// 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;
- }
- 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 "\t" + 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;
- }
- VisualShaderNodeVectorLen::PortType VisualShaderNodeVectorLen::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- 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";
- }
- 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 "\t" + p_output_vars[0] + " = length(" + p_input_vars[0] + ");\n";
- }
- VisualShaderNodeVectorLen::VisualShaderNodeVectorLen() {
- set_input_port_default_value(0, Vector3());
- }
- ////////////// 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 "\t" + p_output_vars[0] + " = determinant(" + p_input_vars[0] + ");\n";
- }
- VisualShaderNodeDeterminant::VisualShaderNodeDeterminant() {
- set_input_port_default_value(0, Transform());
- }
- ////////////// Scalar Derivative Function
- String VisualShaderNodeScalarDerivativeFunc::get_caption() const {
- return "ScalarDerivativeFunc";
- }
- int VisualShaderNodeScalarDerivativeFunc::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeScalarDerivativeFunc::PortType VisualShaderNodeScalarDerivativeFunc::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarDerivativeFunc::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeScalarDerivativeFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeScalarDerivativeFunc::PortType VisualShaderNodeScalarDerivativeFunc::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarDerivativeFunc::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeScalarDerivativeFunc::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_Y + 1] = {
- "fwidth($)",
- "dFdx($)",
- "dFdy($)"
- };
- String code;
- code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
- return code;
- }
- void VisualShaderNodeScalarDerivativeFunc::set_function(Function p_func) {
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeScalarDerivativeFunc::Function VisualShaderNodeScalarDerivativeFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeScalarDerivativeFunc::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeScalarDerivativeFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeScalarDerivativeFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeScalarDerivativeFunc::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Sum,X,Y"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_SUM);
- BIND_ENUM_CONSTANT(FUNC_X);
- BIND_ENUM_CONSTANT(FUNC_Y);
- }
- VisualShaderNodeScalarDerivativeFunc::VisualShaderNodeScalarDerivativeFunc() {
- func = FUNC_SUM;
- set_input_port_default_value(0, 0.0);
- }
- ////////////// Vector Derivative Function
- String VisualShaderNodeVectorDerivativeFunc::get_caption() const {
- return "VectorDerivativeFunc";
- }
- int VisualShaderNodeVectorDerivativeFunc::get_input_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorDerivativeFunc::PortType VisualShaderNodeVectorDerivativeFunc::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorDerivativeFunc::get_input_port_name(int p_port) const {
- return "";
- }
- int VisualShaderNodeVectorDerivativeFunc::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorDerivativeFunc::PortType VisualShaderNodeVectorDerivativeFunc::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorDerivativeFunc::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeVectorDerivativeFunc::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_Y + 1] = {
- "fwidth($)",
- "dFdx($)",
- "dFdy($)"
- };
- String code;
- code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
- return code;
- }
- void VisualShaderNodeVectorDerivativeFunc::set_function(Function p_func) {
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeVectorDerivativeFunc::Function VisualShaderNodeVectorDerivativeFunc::get_function() const {
- return func;
- }
- Vector<StringName> VisualShaderNodeVectorDerivativeFunc::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("function");
- return props;
- }
- void VisualShaderNodeVectorDerivativeFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeVectorDerivativeFunc::set_function);
- ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeVectorDerivativeFunc::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Sum,X,Y"), "set_function", "get_function");
- BIND_ENUM_CONSTANT(FUNC_SUM);
- BIND_ENUM_CONSTANT(FUNC_X);
- BIND_ENUM_CONSTANT(FUNC_Y);
- }
- VisualShaderNodeVectorDerivativeFunc::VisualShaderNodeVectorDerivativeFunc() {
- func = FUNC_SUM;
- set_input_port_default_value(0, Vector3());
- }
- ////////////// Scalar Clamp
- String VisualShaderNodeScalarClamp::get_caption() const {
- return "ScalarClamp";
- }
- int VisualShaderNodeScalarClamp::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeScalarClamp::PortType VisualShaderNodeScalarClamp::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarClamp::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 VisualShaderNodeScalarClamp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeScalarClamp::PortType VisualShaderNodeScalarClamp::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarClamp::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeScalarClamp::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 "\t" + p_output_vars[0] + " = clamp(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- VisualShaderNodeScalarClamp::VisualShaderNodeScalarClamp() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, 1.0);
- }
- ////////////// Vector Clamp
- String VisualShaderNodeVectorClamp::get_caption() const {
- return "VectorClamp";
- }
- int VisualShaderNodeVectorClamp::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeVectorClamp::PortType VisualShaderNodeVectorClamp::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorClamp::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 VisualShaderNodeVectorClamp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorClamp::PortType VisualShaderNodeVectorClamp::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorClamp::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeVectorClamp::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 "\t" + p_output_vars[0] + " = clamp(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- VisualShaderNodeVectorClamp::VisualShaderNodeVectorClamp() {
- set_input_port_default_value(0, Vector3(0, 0, 0));
- set_input_port_default_value(1, Vector3(0, 0, 0));
- set_input_port_default_value(2, Vector3(1, 1, 1));
- }
- ////////////// FaceForward
- String VisualShaderNodeFaceForward::get_caption() const {
- return "FaceForward";
- }
- int VisualShaderNodeFaceForward::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeFaceForward::PortType VisualShaderNodeFaceForward::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- 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;
- }
- VisualShaderNodeFaceForward::PortType VisualShaderNodeFaceForward::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeFaceForward::get_output_port_name(int p_port) const {
- return "";
- }
- 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 "\t" + 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;
- }
- 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 "\t" + 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));
- }
- ////////////// Vector-Scalar Step
- String VisualShaderNodeVectorScalarStep::get_caption() const {
- return "VectorScalarStep";
- }
- int VisualShaderNodeVectorScalarStep::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeVectorScalarStep::PortType VisualShaderNodeVectorScalarStep::get_input_port_type(int p_port) const {
- if (p_port == 0) {
- return PORT_TYPE_SCALAR;
- }
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorScalarStep::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "edge";
- } else if (p_port == 1) {
- return "x";
- }
- return "";
- }
- int VisualShaderNodeVectorScalarStep::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorScalarStep::PortType VisualShaderNodeVectorScalarStep::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorScalarStep::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeVectorScalarStep::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 "\t" + p_output_vars[0] + " = step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- }
- VisualShaderNodeVectorScalarStep::VisualShaderNodeVectorScalarStep() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, Vector3(0.0, 0.0, 0.0));
- }
- ////////////// Scalar SmoothStep
- String VisualShaderNodeScalarSmoothStep::get_caption() const {
- return "ScalarSmoothStep";
- }
- int VisualShaderNodeScalarSmoothStep::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeScalarSmoothStep::PortType VisualShaderNodeScalarSmoothStep::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarSmoothStep::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "edge0";
- } else if (p_port == 1) {
- return "edge1";
- } else if (p_port == 2) {
- return "x";
- }
- return "";
- }
- int VisualShaderNodeScalarSmoothStep::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeScalarSmoothStep::PortType VisualShaderNodeScalarSmoothStep::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarSmoothStep::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeScalarSmoothStep::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 "\t" + p_output_vars[0] + " = smoothstep(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- VisualShaderNodeScalarSmoothStep::VisualShaderNodeScalarSmoothStep() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, 0.0);
- }
- ////////////// Vector SmoothStep
- String VisualShaderNodeVectorSmoothStep::get_caption() const {
- return "VectorSmoothStep";
- }
- int VisualShaderNodeVectorSmoothStep::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeVectorSmoothStep::PortType VisualShaderNodeVectorSmoothStep::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorSmoothStep::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "edge0";
- } else if (p_port == 1) {
- return "edge1";
- } else if (p_port == 2) {
- return "x";
- }
- return "";
- }
- int VisualShaderNodeVectorSmoothStep::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorSmoothStep::PortType VisualShaderNodeVectorSmoothStep::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorSmoothStep::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeVectorSmoothStep::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 "\t" + p_output_vars[0] + " = smoothstep(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- VisualShaderNodeVectorSmoothStep::VisualShaderNodeVectorSmoothStep() {
- 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));
- }
- ////////////// Vector-Scalar SmoothStep
- String VisualShaderNodeVectorScalarSmoothStep::get_caption() const {
- return "VectorScalarSmoothStep";
- }
- int VisualShaderNodeVectorScalarSmoothStep::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeVectorScalarSmoothStep::PortType VisualShaderNodeVectorScalarSmoothStep::get_input_port_type(int p_port) const {
- if (p_port == 0) {
- return PORT_TYPE_SCALAR;
- } else if (p_port == 1) {
- return PORT_TYPE_SCALAR;
- }
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorScalarSmoothStep::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "edge0";
- } else if (p_port == 1) {
- return "edge1";
- } else if (p_port == 2) {
- return "x";
- }
- return "";
- }
- int VisualShaderNodeVectorScalarSmoothStep::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorScalarSmoothStep::PortType VisualShaderNodeVectorScalarSmoothStep::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorScalarSmoothStep::get_output_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeVectorScalarSmoothStep::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 "\t" + p_output_vars[0] + " = smoothstep(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- VisualShaderNodeVectorScalarSmoothStep::VisualShaderNodeVectorScalarSmoothStep() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, Vector3(0.0, 0.0, 0.0));
- }
- ////////////// Distance
- String VisualShaderNodeVectorDistance::get_caption() const {
- return "Distance";
- }
- int VisualShaderNodeVectorDistance::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeVectorDistance::PortType VisualShaderNodeVectorDistance::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorDistance::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "p0";
- } else if (p_port == 1) {
- return "p1";
- }
- return "";
- }
- 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 "";
- }
- 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 "\t" + 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));
- set_input_port_default_value(1, Vector3(0.0, 0.0, 0.0));
- }
- ////////////// Refract Vector
- String VisualShaderNodeVectorRefract::get_caption() const {
- return "Refract";
- }
- int VisualShaderNodeVectorRefract::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeVectorRefract::PortType VisualShaderNodeVectorRefract::get_input_port_type(int p_port) const {
- if (p_port == 2) {
- return PORT_TYPE_SCALAR;
- }
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorRefract::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "I";
- } else if (p_port == 1) {
- return "N";
- } else if (p_port == 2) {
- return "eta";
- }
- return "";
- }
- int VisualShaderNodeVectorRefract::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorRefract::PortType VisualShaderNodeVectorRefract::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- 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 "\t" + p_output_vars[0] + " = refract(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- 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);
- }
- ////////////// Scalar Mix
- String VisualShaderNodeScalarInterp::get_caption() const {
- return "ScalarMix";
- }
- int VisualShaderNodeScalarInterp::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeScalarInterp::PortType VisualShaderNodeScalarInterp::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarInterp::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 VisualShaderNodeScalarInterp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeScalarInterp::PortType VisualShaderNodeScalarInterp::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarInterp::get_output_port_name(int p_port) const {
- return "mix";
- }
- String VisualShaderNodeScalarInterp::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 "\t" + p_output_vars[0] + " = mix(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- VisualShaderNodeScalarInterp::VisualShaderNodeScalarInterp() {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 1.0);
- set_input_port_default_value(2, 0.5);
- }
- ////////////// Vector Mix
- String VisualShaderNodeVectorInterp::get_caption() const {
- return "VectorMix";
- }
- int VisualShaderNodeVectorInterp::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeVectorInterp::PortType VisualShaderNodeVectorInterp::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorInterp::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 VisualShaderNodeVectorInterp::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorInterp::PortType VisualShaderNodeVectorInterp::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorInterp::get_output_port_name(int p_port) const {
- return "mix";
- }
- String VisualShaderNodeVectorInterp::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 "\t" + p_output_vars[0] + " = mix(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- VisualShaderNodeVectorInterp::VisualShaderNodeVectorInterp() {
- set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0));
- set_input_port_default_value(1, Vector3(1.0, 1.0, 1.0));
- set_input_port_default_value(2, Vector3(0.5, 0.5, 0.5));
- }
- ////////////// Vector Mix (by scalar)
- String VisualShaderNodeVectorScalarMix::get_caption() const {
- return "VectorScalarMix";
- }
- int VisualShaderNodeVectorScalarMix::get_input_port_count() const {
- return 3;
- }
- VisualShaderNodeVectorScalarMix::PortType VisualShaderNodeVectorScalarMix::get_input_port_type(int p_port) const {
- if (p_port == 2) {
- return PORT_TYPE_SCALAR;
- }
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorScalarMix::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 VisualShaderNodeVectorScalarMix::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorScalarMix::PortType VisualShaderNodeVectorScalarMix::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorScalarMix::get_output_port_name(int p_port) const {
- return "mix";
- }
- String VisualShaderNodeVectorScalarMix::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 "\t" + p_output_vars[0] + " = mix(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- VisualShaderNodeVectorScalarMix::VisualShaderNodeVectorScalarMix() {
- set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0));
- set_input_port_default_value(1, Vector3(1.0, 1.0, 1.0));
- set_input_port_default_value(2, 0.5);
- }
- ////////////// Vector Compose
- String VisualShaderNodeVectorCompose::get_caption() const {
- return "VectorCompose";
- }
- int VisualShaderNodeVectorCompose::get_input_port_count() const {
- return 3;
- }
- 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 {
- if (p_port == 0) {
- return "x";
- } else if (p_port == 1) {
- return "y";
- } else {
- return "z";
- }
- }
- int VisualShaderNodeVectorCompose::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVectorCompose::PortType VisualShaderNodeVectorCompose::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorCompose::get_output_port_name(int p_port) const {
- return "vec";
- }
- 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 {
- return "\t" + p_output_vars[0] + " = vec3(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n";
- }
- 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;
- }
- 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 "\t" + 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;
- }
- VisualShaderNodeVectorDecompose::PortType VisualShaderNodeVectorDecompose::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVectorDecompose::get_input_port_name(int p_port) const {
- return "vec";
- }
- int VisualShaderNodeVectorDecompose::get_output_port_count() const {
- return 3;
- }
- 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 {
- if (p_port == 0) {
- return "x";
- } else if (p_port == 1) {
- return "y";
- } else {
- return "z";
- }
- }
- 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;
- code += "\t" + p_output_vars[0] + " = " + p_input_vars[0] + ".x;\n";
- code += "\t" + p_output_vars[1] + " = " + p_input_vars[0] + ".y;\n";
- code += "\t" + p_output_vars[2] + " = " + p_input_vars[0] + ".z;\n";
- return code;
- }
- VisualShaderNodeVectorDecompose::VisualShaderNodeVectorDecompose() {
- set_input_port_default_value(0, Vector3());
- }
- ////////////// 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;
- }
- 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 += "\t" + p_output_vars[0] + " = " + p_input_vars[0] + "[0].xyz;\n";
- code += "\t" + p_output_vars[1] + " = " + p_input_vars[0] + "[1].xyz;\n";
- code += "\t" + p_output_vars[2] + " = " + p_input_vars[0] + "[2].xyz;\n";
- code += "\t" + p_output_vars[3] + " = " + p_input_vars[0] + "[3].xyz;\n";
- return code;
- }
- VisualShaderNodeTransformDecompose::VisualShaderNodeTransformDecompose() {
- set_input_port_default_value(0, Transform());
- }
- ////////////// Scalar Uniform
- String VisualShaderNodeScalarUniform::get_caption() const {
- return "ScalarUniform";
- }
- int VisualShaderNodeScalarUniform::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeScalarUniform::PortType VisualShaderNodeScalarUniform::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarUniform::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeScalarUniform::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeScalarUniform::PortType VisualShaderNodeScalarUniform::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeScalarUniform::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeScalarUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "uniform float " + get_uniform_name();
- if (hint == HINT_RANGE) {
- code += " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ")";
- } else if (hint == HINT_RANGE_STEP) {
- code += " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ", " + rtos(hint_range_step) + ")";
- }
- if (default_value_enabled) {
- code += " = " + rtos(default_value);
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeScalarUniform::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 "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
- }
- void VisualShaderNodeScalarUniform::set_hint(Hint p_hint) {
- ERR_FAIL_INDEX(int(p_hint), int(HINT_MAX));
- if (hint == p_hint) {
- return;
- }
- hint = p_hint;
- emit_changed();
- }
- VisualShaderNodeScalarUniform::Hint VisualShaderNodeScalarUniform::get_hint() const {
- return hint;
- }
- void VisualShaderNodeScalarUniform::set_min(float p_value) {
- if (Math::is_equal_approx(hint_range_min, p_value)) {
- return;
- }
- hint_range_min = p_value;
- emit_changed();
- }
- float VisualShaderNodeScalarUniform::get_min() const {
- return hint_range_min;
- }
- void VisualShaderNodeScalarUniform::set_max(float p_value) {
- if (Math::is_equal_approx(hint_range_max, p_value)) {
- return;
- }
- hint_range_max = p_value;
- emit_changed();
- }
- float VisualShaderNodeScalarUniform::get_max() const {
- return hint_range_max;
- }
- void VisualShaderNodeScalarUniform::set_step(float p_value) {
- if (Math::is_equal_approx(hint_range_step, p_value)) {
- return;
- }
- hint_range_step = p_value;
- emit_changed();
- }
- float VisualShaderNodeScalarUniform::get_step() const {
- return hint_range_step;
- }
- void VisualShaderNodeScalarUniform::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 VisualShaderNodeScalarUniform::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeScalarUniform::set_default_value(float p_default_value) {
- if (Math::is_equal_approx(default_value, p_default_value)) {
- return;
- }
- default_value = p_default_value;
- emit_changed();
- }
- float VisualShaderNodeScalarUniform::get_default_value() const {
- return default_value;
- }
- Vector<StringName> VisualShaderNodeScalarUniform::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeUniform::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;
- }
- void VisualShaderNodeScalarUniform::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_hint", "hint"), &VisualShaderNodeScalarUniform::set_hint);
- ClassDB::bind_method(D_METHOD("get_hint"), &VisualShaderNodeScalarUniform::get_hint);
- ClassDB::bind_method(D_METHOD("set_min", "value"), &VisualShaderNodeScalarUniform::set_min);
- ClassDB::bind_method(D_METHOD("get_min"), &VisualShaderNodeScalarUniform::get_min);
- ClassDB::bind_method(D_METHOD("set_max", "value"), &VisualShaderNodeScalarUniform::set_max);
- ClassDB::bind_method(D_METHOD("get_max"), &VisualShaderNodeScalarUniform::get_max);
- ClassDB::bind_method(D_METHOD("set_step", "value"), &VisualShaderNodeScalarUniform::set_step);
- ClassDB::bind_method(D_METHOD("get_step"), &VisualShaderNodeScalarUniform::get_step);
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeScalarUniform::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeScalarUniform::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeScalarUniform::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeScalarUniform::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "hint", PROPERTY_HINT_ENUM, "None,Range,Range+Step"), "set_hint", "get_hint");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "min"), "set_min", "get_min");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "max"), "set_max", "get_max");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "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::REAL, "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);
- }
- VisualShaderNodeScalarUniform::VisualShaderNodeScalarUniform() {
- hint = HINT_NONE;
- hint_range_min = 0.0f;
- hint_range_max = 1.0f;
- hint_range_step = 0.1f;
- default_value_enabled = false;
- default_value = 0.0f;
- }
- ////////////// Boolean Uniform
- String VisualShaderNodeBooleanUniform::get_caption() const {
- return "BooleanUniform";
- }
- int VisualShaderNodeBooleanUniform::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeBooleanUniform::PortType VisualShaderNodeBooleanUniform::get_input_port_type(int p_port) const {
- return PORT_TYPE_BOOLEAN;
- }
- String VisualShaderNodeBooleanUniform::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeBooleanUniform::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeBooleanUniform::PortType VisualShaderNodeBooleanUniform::get_output_port_type(int p_port) const {
- return PORT_TYPE_BOOLEAN;
- }
- String VisualShaderNodeBooleanUniform::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeBooleanUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "uniform bool " + get_uniform_name();
- if (default_value_enabled) {
- if (default_value) {
- code += " = true";
- } else {
- code += " = false";
- }
- }
- code += ";\n";
- return code;
- }
- String VisualShaderNodeBooleanUniform::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 "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
- }
- void VisualShaderNodeBooleanUniform::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 VisualShaderNodeBooleanUniform::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeBooleanUniform::set_default_value(bool p_default_value) {
- if (default_value == p_default_value) {
- return;
- }
- default_value = p_default_value;
- emit_changed();
- }
- bool VisualShaderNodeBooleanUniform::get_default_value() const {
- return default_value;
- }
- void VisualShaderNodeBooleanUniform::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeBooleanUniform::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeBooleanUniform::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeBooleanUniform::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeBooleanUniform::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");
- }
- Vector<StringName> VisualShaderNodeBooleanUniform::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeBooleanUniform::VisualShaderNodeBooleanUniform() {
- default_value_enabled = false;
- default_value = false;
- }
- ////////////// Color Uniform
- String VisualShaderNodeColorUniform::get_caption() const {
- return "ColorUniform";
- }
- int VisualShaderNodeColorUniform::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeColorUniform::PortType VisualShaderNodeColorUniform::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeColorUniform::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeColorUniform::get_output_port_count() const {
- return 2;
- }
- VisualShaderNodeColorUniform::PortType VisualShaderNodeColorUniform::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeColorUniform::get_output_port_name(int p_port) const {
- return p_port == 0 ? "color" : "alpha"; //no output port means the editor will be used as port
- }
- String VisualShaderNodeColorUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "uniform vec4 " + get_uniform_name() + " : hint_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 VisualShaderNodeColorUniform::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 = "\t" + p_output_vars[0] + " = " + get_uniform_name() + ".rgb;\n";
- code += "\t" + p_output_vars[1] + " = " + get_uniform_name() + ".a;\n";
- return code;
- }
- void VisualShaderNodeColorUniform::set_default_value_enabled(bool p_enabled) {
- if (default_value_enabled == p_enabled) {
- return;
- }
- default_value_enabled = p_enabled;
- emit_changed();
- }
- bool VisualShaderNodeColorUniform::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeColorUniform::set_default_value(const Color &p_value) {
- if (default_value.is_equal_approx(p_value)) {
- return;
- }
- default_value = p_value;
- emit_changed();
- }
- Color VisualShaderNodeColorUniform::get_default_value() const {
- return default_value;
- }
- void VisualShaderNodeColorUniform::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeColorUniform::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeColorUniform::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeColorUniform::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeColorUniform::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");
- }
- Vector<StringName> VisualShaderNodeColorUniform::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeColorUniform::VisualShaderNodeColorUniform() {
- default_value_enabled = false;
- default_value = Color(1.0, 1.0, 1.0, 1.0);
- }
- ////////////// Vector Uniform
- String VisualShaderNodeVec3Uniform::get_caption() const {
- return "VectorUniform";
- }
- int VisualShaderNodeVec3Uniform::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeVec3Uniform::PortType VisualShaderNodeVec3Uniform::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVec3Uniform::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeVec3Uniform::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeVec3Uniform::PortType VisualShaderNodeVec3Uniform::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeVec3Uniform::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeVec3Uniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "uniform vec3 " + get_uniform_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 VisualShaderNodeVec3Uniform::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 "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
- }
- void VisualShaderNodeVec3Uniform::set_default_value_enabled(bool p_enabled) {
- default_value_enabled = p_enabled;
- emit_changed();
- }
- bool VisualShaderNodeVec3Uniform::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeVec3Uniform::set_default_value(const Vector3 &p_value) {
- default_value = p_value;
- emit_changed();
- }
- Vector3 VisualShaderNodeVec3Uniform::get_default_value() const {
- return default_value;
- }
- void VisualShaderNodeVec3Uniform::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeVec3Uniform::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeVec3Uniform::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeVec3Uniform::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeVec3Uniform::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");
- }
- Vector<StringName> VisualShaderNodeVec3Uniform::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeVec3Uniform::VisualShaderNodeVec3Uniform() {
- default_value_enabled = false;
- }
- ////////////// Transform Uniform
- String VisualShaderNodeTransformUniform::get_caption() const {
- return "TransformUniform";
- }
- int VisualShaderNodeTransformUniform::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeTransformUniform::PortType VisualShaderNodeTransformUniform::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeTransformUniform::get_input_port_name(int p_port) const {
- return String();
- }
- int VisualShaderNodeTransformUniform::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeTransformUniform::PortType VisualShaderNodeTransformUniform::get_output_port_type(int p_port) const {
- return PORT_TYPE_TRANSFORM;
- }
- String VisualShaderNodeTransformUniform::get_output_port_name(int p_port) const {
- return ""; //no output port means the editor will be used as port
- }
- String VisualShaderNodeTransformUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "uniform mat4 " + get_uniform_name();
- if (default_value_enabled) {
- Vector3 row0 = default_value.basis.get_row(0);
- Vector3 row1 = default_value.basis.get_row(1);
- Vector3 row2 = default_value.basis.get_row(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 VisualShaderNodeTransformUniform::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 "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n";
- }
- void VisualShaderNodeTransformUniform::set_default_value_enabled(bool p_enabled) {
- default_value_enabled = p_enabled;
- emit_changed();
- }
- bool VisualShaderNodeTransformUniform::is_default_value_enabled() const {
- return default_value_enabled;
- }
- void VisualShaderNodeTransformUniform::set_default_value(const Transform &p_value) {
- default_value = p_value;
- emit_changed();
- }
- Transform VisualShaderNodeTransformUniform::get_default_value() const {
- return default_value;
- }
- void VisualShaderNodeTransformUniform::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeTransformUniform::set_default_value_enabled);
- ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeTransformUniform::is_default_value_enabled);
- ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeTransformUniform::set_default_value);
- ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeTransformUniform::get_default_value);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "default_value"), "set_default_value", "get_default_value");
- }
- Vector<StringName> VisualShaderNodeTransformUniform::get_editable_properties() const {
- Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
- props.push_back("default_value_enabled");
- if (default_value_enabled) {
- props.push_back("default_value");
- }
- return props;
- }
- VisualShaderNodeTransformUniform::VisualShaderNodeTransformUniform() {
- default_value_enabled = false;
- default_value = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
- }
- ////////////// Texture Uniform
- String VisualShaderNodeTextureUniform::get_caption() const {
- return "TextureUniform";
- }
- int VisualShaderNodeTextureUniform::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeTextureUniform::PortType VisualShaderNodeTextureUniform::get_input_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeTextureUniform::get_input_port_name(int p_port) const {
- return p_port == 0 ? "uv" : "lod";
- }
- int VisualShaderNodeTextureUniform::get_output_port_count() const {
- return 3;
- }
- VisualShaderNodeTextureUniform::PortType VisualShaderNodeTextureUniform::get_output_port_type(int p_port) const {
- switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR;
- case 1:
- return PORT_TYPE_SCALAR;
- case 2:
- return PORT_TYPE_SAMPLER;
- default:
- return PORT_TYPE_SCALAR;
- }
- }
- String VisualShaderNodeTextureUniform::get_output_port_name(int p_port) const {
- switch (p_port) {
- case 0:
- return "rgb";
- case 1:
- return "alpha";
- case 2:
- return "sampler2D";
- default:
- return "";
- }
- }
- bool VisualShaderNodeTextureUniform::is_code_generated() const {
- return is_output_port_connected(0) || is_output_port_connected(1); // rgb or alpha
- }
- bool VisualShaderNodeTextureUniform::is_show_prop_names() const {
- return false;
- }
- String VisualShaderNodeTextureUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "uniform sampler2D " + get_uniform_name();
- switch (texture_type) {
- case TYPE_DATA:
- if (color_default == COLOR_DEFAULT_BLACK) {
- code += " : hint_black;\n";
- } else {
- code += ";\n";
- }
- break;
- case TYPE_COLOR:
- if (color_default == COLOR_DEFAULT_BLACK) {
- code += " : hint_black_albedo;\n";
- } else {
- code += " : hint_albedo;\n";
- }
- break;
- case TYPE_NORMALMAP:
- code += " : hint_normal;\n";
- break;
- case TYPE_ANISO:
- code += " : hint_aniso;\n";
- break;
- }
- return code;
- }
- String VisualShaderNodeTextureUniform::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_uniform_name();
- String code = "\t{\n";
- if (p_input_vars[0] == String()) { // Use UV by default.
- if (p_input_vars[1] == String()) {
- code += "\t\tvec4 n_tex_read = texture(" + id + ", UV.xy);\n";
- } else {
- code += "\t\tvec4 n_tex_read = textureLod(" + id + ", UV.xy, " + p_input_vars[1] + ");\n";
- }
- } else if (p_input_vars[1] == String()) {
- //no lod
- code += "\t\tvec4 n_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n";
- } else {
- code += "\t\tvec4 n_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n";
- }
- code += "\t\t" + p_output_vars[0] + " = n_tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = n_tex_read.a;\n";
- code += "\t}\n";
- return code;
- }
- void VisualShaderNodeTextureUniform::set_texture_type(TextureType p_type) {
- texture_type = p_type;
- emit_changed();
- }
- VisualShaderNodeTextureUniform::TextureType VisualShaderNodeTextureUniform::get_texture_type() const {
- return texture_type;
- }
- void VisualShaderNodeTextureUniform::set_color_default(ColorDefault p_default) {
- color_default = p_default;
- emit_changed();
- }
- VisualShaderNodeTextureUniform::ColorDefault VisualShaderNodeTextureUniform::get_color_default() const {
- return color_default;
- }
- Vector<StringName> VisualShaderNodeTextureUniform::get_editable_properties() const {
- Vector<StringName> props;
- props.push_back("texture_type");
- props.push_back("color_default");
- return props;
- }
- void VisualShaderNodeTextureUniform::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_texture_type", "type"), &VisualShaderNodeTextureUniform::set_texture_type);
- ClassDB::bind_method(D_METHOD("get_texture_type"), &VisualShaderNodeTextureUniform::get_texture_type);
- ClassDB::bind_method(D_METHOD("set_color_default", "type"), &VisualShaderNodeTextureUniform::set_color_default);
- ClassDB::bind_method(D_METHOD("get_color_default"), &VisualShaderNodeTextureUniform::get_color_default);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_type", PROPERTY_HINT_ENUM, "Data,Color,Normalmap,Aniso"), "set_texture_type", "get_texture_type");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "color_default", PROPERTY_HINT_ENUM, "White Default,Black Default"), "set_color_default", "get_color_default");
- BIND_ENUM_CONSTANT(TYPE_DATA);
- BIND_ENUM_CONSTANT(TYPE_COLOR);
- BIND_ENUM_CONSTANT(TYPE_NORMALMAP);
- BIND_ENUM_CONSTANT(TYPE_ANISO);
- BIND_ENUM_CONSTANT(COLOR_DEFAULT_WHITE);
- BIND_ENUM_CONSTANT(COLOR_DEFAULT_BLACK);
- }
- String VisualShaderNodeTextureUniform::get_input_port_default_hint(int p_port) const {
- if (p_port == 0) {
- return "UV.xy";
- }
- return "";
- }
- VisualShaderNodeTextureUniform::VisualShaderNodeTextureUniform() {
- texture_type = TYPE_DATA;
- color_default = COLOR_DEFAULT_WHITE;
- simple_decl = false;
- }
- ////////////// Texture Uniform (Triplanar)
- String VisualShaderNodeTextureUniformTriplanar::get_caption() const {
- return "TextureUniformTriplanar";
- }
- int VisualShaderNodeTextureUniformTriplanar::get_input_port_count() const {
- return 2;
- }
- VisualShaderNodeTextureUniform::PortType VisualShaderNodeTextureUniformTriplanar::get_input_port_type(int p_port) const {
- if (p_port == 0) {
- return PORT_TYPE_VECTOR;
- } else if (p_port == 1) {
- return PORT_TYPE_VECTOR;
- }
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeTextureUniformTriplanar::get_input_port_name(int p_port) const {
- if (p_port == 0) {
- return "weights";
- } else if (p_port == 1) {
- return "pos";
- }
- return "";
- }
- String VisualShaderNodeTextureUniformTriplanar::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code;
- code += "// TRIPLANAR FUNCTION GLOBAL CODE\n";
- code += "\tvec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) {\n";
- code += "\t\tvec4 samp = vec4(0.0);\n";
- code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z;\n";
- code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y;\n";
- code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x;\n";
- code += "\t\treturn samp;\n";
- code += "\t}\n";
- code += "\n";
- code += "\tuniform vec3 triplanar_scale = vec3(1.0, 1.0, 1.0);\n";
- code += "\tuniform vec3 triplanar_offset;\n";
- code += "\tuniform float triplanar_sharpness = 0.5;\n";
- code += "\n";
- code += "\tvarying vec3 triplanar_power_normal;\n";
- code += "\tvarying vec3 triplanar_pos;\n";
- return code;
- }
- String VisualShaderNodeTextureUniformTriplanar::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 += "\t// TRIPLANAR FUNCTION VERTEX CODE\n";
- code += "\t\ttriplanar_power_normal = pow(abs(NORMAL), vec3(triplanar_sharpness));\n";
- code += "\t\ttriplanar_power_normal /= dot(triplanar_power_normal, vec3(1.0));\n";
- code += "\t\ttriplanar_pos = VERTEX * triplanar_scale + triplanar_offset;\n";
- code += "\t\ttriplanar_pos *= vec3(1.0, -1.0, 1.0);\n";
- }
- return code;
- }
- String VisualShaderNodeTextureUniformTriplanar::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_uniform_name();
- String code = "\t{\n";
- if (p_input_vars[0] == String() && p_input_vars[1] == String()) {
- code += "\t\tvec4 n_tex_read = triplanar_texture( " + id + ", triplanar_power_normal, triplanar_pos );\n";
- } else if (p_input_vars[0] != String() && p_input_vars[1] == String()) {
- code += "\t\tvec4 n_tex_read = triplanar_texture( " + id + ", " + p_input_vars[0] + ", triplanar_pos );\n";
- } else if (p_input_vars[0] == String() && p_input_vars[1] != String()) {
- code += "\t\tvec4 n_tex_read = triplanar_texture( " + id + ", triplanar_power_normal," + p_input_vars[1] + " );\n";
- } else {
- code += "\t\tvec4 n_tex_read = triplanar_texture( " + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + " );\n";
- }
- code += "\t\t" + p_output_vars[0] + " = n_tex_read.rgb;\n";
- code += "\t\t" + p_output_vars[1] + " = n_tex_read.a;\n";
- code += "\t}\n";
- return code;
- }
- String VisualShaderNodeTextureUniformTriplanar::get_input_port_default_hint(int p_port) const {
- if (p_port == 0) {
- return "default";
- } else if (p_port == 1) {
- return "default";
- }
- return "";
- }
- VisualShaderNodeTextureUniformTriplanar::VisualShaderNodeTextureUniformTriplanar() {
- }
- ////////////// CubeMap Uniform
- String VisualShaderNodeCubeMapUniform::get_caption() const {
- return "CubeMapUniform";
- }
- int VisualShaderNodeCubeMapUniform::get_output_port_count() const {
- return 1;
- }
- VisualShaderNodeCubeMapUniform::PortType VisualShaderNodeCubeMapUniform::get_output_port_type(int p_port) const {
- return PORT_TYPE_SAMPLER;
- }
- String VisualShaderNodeCubeMapUniform::get_output_port_name(int p_port) const {
- return "samplerCube";
- }
- int VisualShaderNodeCubeMapUniform::get_input_port_count() const {
- return 0;
- }
- VisualShaderNodeCubeMapUniform::PortType VisualShaderNodeCubeMapUniform::get_input_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- String VisualShaderNodeCubeMapUniform::get_input_port_name(int p_port) const {
- return "";
- }
- String VisualShaderNodeCubeMapUniform::get_input_port_default_hint(int p_port) const {
- return "";
- }
- String VisualShaderNodeCubeMapUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "uniform samplerCube " + get_uniform_name();
- switch (texture_type) {
- case TYPE_DATA:
- if (color_default == COLOR_DEFAULT_BLACK) {
- code += " : hint_black;\n";
- } else {
- code += ";\n";
- }
- break;
- case TYPE_COLOR:
- if (color_default == COLOR_DEFAULT_BLACK) {
- code += " : hint_black_albedo;\n";
- } else {
- code += " : hint_albedo;\n";
- }
- break;
- case TYPE_NORMALMAP:
- code += " : hint_normal;\n";
- break;
- case TYPE_ANISO:
- code += " : hint_aniso;\n";
- break;
- }
- return code;
- }
- String VisualShaderNodeCubeMapUniform::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 String();
- }
- VisualShaderNodeCubeMapUniform::VisualShaderNodeCubeMapUniform() {
- }
- ////////////// 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;
- }
- 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 PORT_TYPE_VECTOR;
- }
- 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 += "\tif(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ")\n"; // abs(a - b) < tolerance eg. a == b
- code += "\t{\n";
- code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[3] + ";\n";
- code += "\t}\n";
- code += "\telse if(" + p_input_vars[0] + " < " + p_input_vars[1] + ")\n"; // a < b
- code += "\t{\n";
- code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[5] + ";\n";
- code += "\t}\n";
- code += "\telse\n"; // a > b (or a >= b if abs(a - b) < tolerance is false)
- code += "\t{\n";
- code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[4] + ";\n";
- code += "\t}\n";
- return code;
- }
- VisualShaderNodeIf::VisualShaderNodeIf() {
- 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));
- simple_decl = false;
- }
- ////////////// Switch
- String VisualShaderNodeSwitch::get_caption() const {
- return "VectorSwitch";
- }
- 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;
- }
- return PORT_TYPE_VECTOR;
- }
- 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 {
- return PORT_TYPE_VECTOR;
- }
- String VisualShaderNodeSwitch::get_output_port_name(int p_port) const {
- return "result";
- }
- 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 {
- String code;
- code += "\tif(" + p_input_vars[0] + ")\n";
- code += "\t{\n";
- code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[1] + ";\n";
- code += "\t}\n";
- code += "\telse\n";
- code += "\t{\n";
- code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[2] + ";\n";
- code += "\t}\n";
- return code;
- }
- VisualShaderNodeSwitch::VisualShaderNodeSwitch() {
- set_input_port_default_value(0, false);
- set_input_port_default_value(1, Vector3(1.0, 1.0, 1.0));
- set_input_port_default_value(2, Vector3(0.0, 0.0, 0.0));
- simple_decl = false;
- }
- ////////////// Switch(scalar)
- String VisualShaderNodeScalarSwitch::get_caption() const {
- return "ScalarSwitch";
- }
- VisualShaderNodeScalarSwitch::PortType VisualShaderNodeScalarSwitch::get_input_port_type(int p_port) const {
- if (p_port == 0) {
- return PORT_TYPE_BOOLEAN;
- }
- return PORT_TYPE_SCALAR;
- }
- VisualShaderNodeScalarSwitch::PortType VisualShaderNodeScalarSwitch::get_output_port_type(int p_port) const {
- return PORT_TYPE_SCALAR;
- }
- VisualShaderNodeScalarSwitch::VisualShaderNodeScalarSwitch() {
- 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;
- case 1:
- return PORT_TYPE_VECTOR;
- case 2:
- return PORT_TYPE_BOOLEAN;
- case 3:
- return PORT_TYPE_SCALAR;
- default:
- return PORT_TYPE_VECTOR;
- }
- }
- 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] == String()) {
- normal = "NORMAL";
- } else {
- normal = p_input_vars[0];
- }
- if (p_input_vars[1] == String()) {
- view = "VIEW";
- } else {
- view = p_input_vars[1];
- }
- if (is_input_port_connected(2)) {
- return "\t" + 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 "\t" + p_output_vars[0] + " = pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n";
- } else {
- return "\t" + p_output_vars[0] + " = pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n";
- }
- }
- }
- String VisualShaderNodeFresnel::get_input_port_default_hint(int p_port) const {
- if (p_port == 0) {
- return "default";
- } else if (p_port == 1) {
- return "default";
- }
- return "";
- }
- 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 *funcs[FUNC_IS_NAN + 1] = {
- "isinf($)",
- "isnan($)"
- };
- String code;
- code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n";
- return code;
- }
- void VisualShaderNodeIs::set_function(Function p_func) {
- 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);
- }
- VisualShaderNodeIs::VisualShaderNodeIs() {
- func = FUNC_IS_INF;
- set_input_port_default_value(0, 0.0);
- }
- ////////////// Compare
- String VisualShaderNodeCompare::get_caption() const {
- return "Compare";
- }
- int VisualShaderNodeCompare::get_input_port_count() const {
- if (ctype == CTYPE_SCALAR && (func == FUNC_EQUAL || func == FUNC_NOT_EQUAL)) {
- return 3;
- }
- return 2;
- }
- VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_input_port_type(int p_port) const {
- if (p_port == 2) {
- return PORT_TYPE_SCALAR;
- }
- switch (ctype) {
- case CTYPE_SCALAR:
- return PORT_TYPE_SCALAR;
- case CTYPE_VECTOR:
- return PORT_TYPE_VECTOR;
- case CTYPE_BOOLEAN:
- return PORT_TYPE_BOOLEAN;
- case CTYPE_TRANSFORM:
- return PORT_TYPE_TRANSFORM;
- }
- return PORT_TYPE_VECTOR;
- }
- 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 (ctype == CTYPE_BOOLEAN || ctype == CTYPE_TRANSFORM) {
- if (func > FUNC_NOT_EQUAL) {
- return TTR("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 *ops[FUNC_LESS_THAN_EQUAL + 1] = {
- "==",
- "!=",
- ">",
- ">=",
- "<",
- "<=",
- };
- static const char *funcs[FUNC_LESS_THAN_EQUAL + 1] = {
- "equal($)",
- "notEqual($)",
- "greaterThan($)",
- "greaterThanEqual($)",
- "lessThan($)",
- "lessThanEqual($)",
- };
- static const char *conds[COND_ANY + 1] = {
- "all($)",
- "any($)",
- };
- String code;
- switch (ctype) {
- case CTYPE_SCALAR:
- if (func == FUNC_EQUAL) {
- code += "\t" + p_output_vars[0] + " = (abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");";
- } else if (func == FUNC_NOT_EQUAL) {
- code += "\t" + p_output_vars[0] + " = !(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");";
- } else {
- code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + "$" + p_input_vars[1]).replace("$", ops[func]) + ";\n";
- }
- break;
- case CTYPE_VECTOR:
- code += "\t{\n";
- code += "\t\tbvec3 _bv = " + String(funcs[func]).replace("$", p_input_vars[0] + ", " + p_input_vars[1]) + ";\n";
- code += "\t\t" + p_output_vars[0] + " = " + String(conds[condition]).replace("$", "_bv") + ";\n";
- code += "\t}\n";
- break;
- case CTYPE_BOOLEAN:
- if (func > FUNC_NOT_EQUAL) {
- return "\t" + p_output_vars[0] + " = false;\n";
- }
- code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
- break;
- case CTYPE_TRANSFORM:
- if (func > FUNC_NOT_EQUAL) {
- return "\t" + p_output_vars[0] + " = false;\n";
- }
- code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
- break;
- default:
- break;
- }
- return code;
- }
- void VisualShaderNodeCompare::set_comparison_type(ComparisonType p_type) {
- ctype = p_type;
- switch (ctype) {
- case CTYPE_SCALAR:
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- simple_decl = true;
- break;
- case CTYPE_VECTOR:
- 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));
- 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, Transform());
- set_input_port_default_value(1, Transform());
- simple_decl = true;
- break;
- }
- emit_changed();
- }
- VisualShaderNodeCompare::ComparisonType VisualShaderNodeCompare::get_comparison_type() const {
- return ctype;
- }
- void VisualShaderNodeCompare::set_function(Function p_func) {
- func = p_func;
- emit_changed();
- }
- VisualShaderNodeCompare::Function VisualShaderNodeCompare::get_function() const {
- return func;
- }
- void VisualShaderNodeCompare::set_condition(Condition p_cond) {
- condition = p_cond;
- 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 (ctype == CTYPE_VECTOR) {
- 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, "Scalar,Vector,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_VECTOR);
- BIND_ENUM_CONSTANT(CTYPE_BOOLEAN);
- BIND_ENUM_CONSTANT(CTYPE_TRANSFORM);
- 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(COND_ALL);
- BIND_ENUM_CONSTANT(COND_ANY);
- }
- VisualShaderNodeCompare::VisualShaderNodeCompare() {
- ctype = CTYPE_SCALAR;
- func = FUNC_EQUAL;
- condition = COND_ALL;
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 0.0);
- set_input_port_default_value(2, CMP_EPSILON);
- }
|