visual_shader_nodes.h 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181
  1. /**************************************************************************/
  2. /* visual_shader_nodes.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef VISUAL_SHADER_NODES_H
  31. #define VISUAL_SHADER_NODES_H
  32. #include "scene/resources/compressed_texture.h"
  33. #include "scene/resources/curve_texture.h"
  34. #include "scene/resources/visual_shader.h"
  35. class Cubemap;
  36. class Texture2DArray;
  37. ///////////////////////////////////////
  38. /// Vector Base Node
  39. ///////////////////////////////////////
  40. class VisualShaderNodeVectorBase : public VisualShaderNode {
  41. GDCLASS(VisualShaderNodeVectorBase, VisualShaderNode);
  42. public:
  43. enum OpType {
  44. OP_TYPE_VECTOR_2D,
  45. OP_TYPE_VECTOR_3D,
  46. OP_TYPE_VECTOR_4D,
  47. OP_TYPE_MAX,
  48. };
  49. protected:
  50. OpType op_type = OP_TYPE_VECTOR_3D;
  51. protected:
  52. static void _bind_methods();
  53. public:
  54. virtual String get_caption() const override = 0;
  55. virtual int get_input_port_count() const override = 0;
  56. virtual PortType get_input_port_type(int p_port) const override;
  57. virtual String get_input_port_name(int p_port) const override = 0;
  58. virtual int get_output_port_count() const override = 0;
  59. virtual PortType get_output_port_type(int p_port) const override;
  60. virtual String get_output_port_name(int p_port) const override = 0;
  61. virtual String 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 = false) const override = 0;
  62. virtual void set_op_type(OpType p_op_type);
  63. OpType get_op_type() const;
  64. virtual Vector<StringName> get_editable_properties() const override;
  65. virtual Category get_category() const override { return CATEGORY_VECTOR; }
  66. VisualShaderNodeVectorBase();
  67. };
  68. VARIANT_ENUM_CAST(VisualShaderNodeVectorBase::OpType)
  69. ///////////////////////////////////////
  70. /// CONSTANTS
  71. ///////////////////////////////////////
  72. class VisualShaderNodeConstant : public VisualShaderNode {
  73. GDCLASS(VisualShaderNodeConstant, VisualShaderNode);
  74. public:
  75. virtual String get_caption() const override = 0;
  76. virtual int get_input_port_count() const override = 0;
  77. virtual PortType get_input_port_type(int p_port) const override = 0;
  78. virtual String get_input_port_name(int p_port) const override = 0;
  79. virtual int get_output_port_count() const override = 0;
  80. virtual PortType get_output_port_type(int p_port) const override = 0;
  81. virtual String get_output_port_name(int p_port) const override = 0;
  82. virtual String 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 = false) const override = 0;
  83. virtual Category get_category() const override { return CATEGORY_INPUT; }
  84. VisualShaderNodeConstant();
  85. };
  86. class VisualShaderNodeFloatConstant : public VisualShaderNodeConstant {
  87. GDCLASS(VisualShaderNodeFloatConstant, VisualShaderNodeConstant);
  88. float constant = 0.0f;
  89. protected:
  90. static void _bind_methods();
  91. public:
  92. virtual String get_caption() const override;
  93. virtual int get_input_port_count() const override;
  94. virtual PortType get_input_port_type(int p_port) const override;
  95. virtual String get_input_port_name(int p_port) const override;
  96. virtual int get_output_port_count() const override;
  97. virtual PortType get_output_port_type(int p_port) const override;
  98. virtual String get_output_port_name(int p_port) const override;
  99. virtual String 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 = false) const override;
  100. void set_constant(float p_constant);
  101. float get_constant() const;
  102. virtual Vector<StringName> get_editable_properties() const override;
  103. VisualShaderNodeFloatConstant();
  104. };
  105. ///////////////////////////////////////
  106. class VisualShaderNodeIntConstant : public VisualShaderNodeConstant {
  107. GDCLASS(VisualShaderNodeIntConstant, VisualShaderNodeConstant);
  108. int constant = 0;
  109. protected:
  110. static void _bind_methods();
  111. public:
  112. virtual String get_caption() const override;
  113. virtual int get_input_port_count() const override;
  114. virtual PortType get_input_port_type(int p_port) const override;
  115. virtual String get_input_port_name(int p_port) const override;
  116. virtual int get_output_port_count() const override;
  117. virtual PortType get_output_port_type(int p_port) const override;
  118. virtual String get_output_port_name(int p_port) const override;
  119. virtual String 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 = false) const override;
  120. void set_constant(int p_constant);
  121. int get_constant() const;
  122. virtual Vector<StringName> get_editable_properties() const override;
  123. VisualShaderNodeIntConstant();
  124. };
  125. ///////////////////////////////////////
  126. class VisualShaderNodeUIntConstant : public VisualShaderNodeConstant {
  127. GDCLASS(VisualShaderNodeUIntConstant, VisualShaderNodeConstant);
  128. int constant = 0;
  129. protected:
  130. static void _bind_methods();
  131. public:
  132. virtual String get_caption() const override;
  133. virtual int get_input_port_count() const override;
  134. virtual PortType get_input_port_type(int p_port) const override;
  135. virtual String get_input_port_name(int p_port) const override;
  136. virtual int get_output_port_count() const override;
  137. virtual PortType get_output_port_type(int p_port) const override;
  138. virtual String get_output_port_name(int p_port) const override;
  139. virtual String 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 = false) const override;
  140. void set_constant(int p_constant);
  141. int get_constant() const;
  142. virtual Vector<StringName> get_editable_properties() const override;
  143. VisualShaderNodeUIntConstant();
  144. };
  145. ///////////////////////////////////////
  146. class VisualShaderNodeBooleanConstant : public VisualShaderNodeConstant {
  147. GDCLASS(VisualShaderNodeBooleanConstant, VisualShaderNodeConstant);
  148. bool constant = false;
  149. protected:
  150. static void _bind_methods();
  151. public:
  152. virtual String get_caption() const override;
  153. virtual int get_input_port_count() const override;
  154. virtual PortType get_input_port_type(int p_port) const override;
  155. virtual String get_input_port_name(int p_port) const override;
  156. virtual int get_output_port_count() const override;
  157. virtual PortType get_output_port_type(int p_port) const override;
  158. virtual String get_output_port_name(int p_port) const override;
  159. virtual String 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 = false) const override;
  160. void set_constant(bool p_constant);
  161. bool get_constant() const;
  162. virtual Vector<StringName> get_editable_properties() const override;
  163. VisualShaderNodeBooleanConstant();
  164. };
  165. ///////////////////////////////////////
  166. class VisualShaderNodeColorConstant : public VisualShaderNodeConstant {
  167. GDCLASS(VisualShaderNodeColorConstant, VisualShaderNodeConstant);
  168. Color constant = Color(1, 1, 1, 1);
  169. protected:
  170. static void _bind_methods();
  171. public:
  172. virtual String get_caption() const override;
  173. virtual int get_input_port_count() const override;
  174. virtual PortType get_input_port_type(int p_port) const override;
  175. virtual String get_input_port_name(int p_port) const override;
  176. virtual int get_output_port_count() const override;
  177. virtual PortType get_output_port_type(int p_port) const override;
  178. virtual String get_output_port_name(int p_port) const override;
  179. virtual String 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 = false) const override;
  180. void set_constant(const Color &p_constant);
  181. Color get_constant() const;
  182. virtual Vector<StringName> get_editable_properties() const override;
  183. VisualShaderNodeColorConstant();
  184. };
  185. ///////////////////////////////////////
  186. class VisualShaderNodeVec2Constant : public VisualShaderNodeConstant {
  187. GDCLASS(VisualShaderNodeVec2Constant, VisualShaderNodeConstant);
  188. Vector2 constant;
  189. protected:
  190. static void _bind_methods();
  191. public:
  192. virtual String get_caption() const override;
  193. virtual int get_input_port_count() const override;
  194. virtual PortType get_input_port_type(int p_port) const override;
  195. virtual String get_input_port_name(int p_port) const override;
  196. virtual int get_output_port_count() const override;
  197. virtual PortType get_output_port_type(int p_port) const override;
  198. virtual String get_output_port_name(int p_port) const override;
  199. virtual String 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 = false) const override;
  200. void set_constant(const Vector2 &p_constant);
  201. Vector2 get_constant() const;
  202. virtual Vector<StringName> get_editable_properties() const override;
  203. VisualShaderNodeVec2Constant();
  204. };
  205. ///////////////////////////////////////
  206. class VisualShaderNodeVec3Constant : public VisualShaderNodeConstant {
  207. GDCLASS(VisualShaderNodeVec3Constant, VisualShaderNodeConstant);
  208. Vector3 constant;
  209. protected:
  210. static void _bind_methods();
  211. public:
  212. virtual String get_caption() const override;
  213. virtual int get_input_port_count() const override;
  214. virtual PortType get_input_port_type(int p_port) const override;
  215. virtual String get_input_port_name(int p_port) const override;
  216. virtual int get_output_port_count() const override;
  217. virtual PortType get_output_port_type(int p_port) const override;
  218. virtual String get_output_port_name(int p_port) const override;
  219. virtual String 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 = false) const override;
  220. void set_constant(const Vector3 &p_constant);
  221. Vector3 get_constant() const;
  222. virtual Vector<StringName> get_editable_properties() const override;
  223. VisualShaderNodeVec3Constant();
  224. };
  225. ///////////////////////////////////////
  226. class VisualShaderNodeVec4Constant : public VisualShaderNodeConstant {
  227. GDCLASS(VisualShaderNodeVec4Constant, VisualShaderNodeConstant);
  228. Quaternion constant;
  229. protected:
  230. static void _bind_methods();
  231. public:
  232. virtual String get_caption() const override;
  233. virtual int get_input_port_count() const override;
  234. virtual PortType get_input_port_type(int p_port) const override;
  235. virtual String get_input_port_name(int p_port) const override;
  236. virtual int get_output_port_count() const override;
  237. virtual PortType get_output_port_type(int p_port) const override;
  238. virtual String get_output_port_name(int p_port) const override;
  239. virtual String 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 = false) const override;
  240. void set_constant(const Quaternion &p_constant);
  241. Quaternion get_constant() const;
  242. virtual Vector<StringName> get_editable_properties() const override;
  243. VisualShaderNodeVec4Constant();
  244. };
  245. ///////////////////////////////////////
  246. class VisualShaderNodeTransformConstant : public VisualShaderNodeConstant {
  247. GDCLASS(VisualShaderNodeTransformConstant, VisualShaderNodeConstant);
  248. Transform3D constant;
  249. protected:
  250. static void _bind_methods();
  251. public:
  252. virtual String get_caption() const override;
  253. virtual int get_input_port_count() const override;
  254. virtual PortType get_input_port_type(int p_port) const override;
  255. virtual String get_input_port_name(int p_port) const override;
  256. virtual int get_output_port_count() const override;
  257. virtual PortType get_output_port_type(int p_port) const override;
  258. virtual String get_output_port_name(int p_port) const override;
  259. virtual String 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 = false) const override;
  260. void set_constant(const Transform3D &p_constant);
  261. Transform3D get_constant() const;
  262. virtual Vector<StringName> get_editable_properties() const override;
  263. VisualShaderNodeTransformConstant();
  264. };
  265. ///////////////////////////////////////
  266. /// TEXTURES
  267. ///////////////////////////////////////
  268. class VisualShaderNodeTexture : public VisualShaderNode {
  269. GDCLASS(VisualShaderNodeTexture, VisualShaderNode);
  270. Ref<Texture2D> texture;
  271. public:
  272. enum Source {
  273. SOURCE_TEXTURE,
  274. SOURCE_SCREEN,
  275. SOURCE_2D_TEXTURE,
  276. SOURCE_2D_NORMAL,
  277. SOURCE_DEPTH,
  278. SOURCE_PORT,
  279. SOURCE_3D_NORMAL,
  280. SOURCE_ROUGHNESS,
  281. SOURCE_MAX,
  282. };
  283. enum TextureType {
  284. TYPE_DATA,
  285. TYPE_COLOR,
  286. TYPE_NORMAL_MAP,
  287. TYPE_MAX,
  288. };
  289. private:
  290. Source source = SOURCE_TEXTURE;
  291. TextureType texture_type = TYPE_DATA;
  292. protected:
  293. static void _bind_methods();
  294. public:
  295. virtual String get_caption() const override;
  296. virtual int get_input_port_count() const override;
  297. virtual PortType get_input_port_type(int p_port) const override;
  298. virtual String get_input_port_name(int p_port) const override;
  299. virtual int get_output_port_count() const override;
  300. virtual PortType get_output_port_type(int p_port) const override;
  301. virtual String get_output_port_name(int p_port) const override;
  302. virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override;
  303. virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override;
  304. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  305. virtual String 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 = false) const override;
  306. void set_source(Source p_source);
  307. Source get_source() const;
  308. void set_texture(Ref<Texture2D> p_texture);
  309. Ref<Texture2D> get_texture() const;
  310. void set_texture_type(TextureType p_texture_type);
  311. TextureType get_texture_type() const;
  312. virtual Vector<StringName> get_editable_properties() const override;
  313. virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const override;
  314. virtual Category get_category() const override { return CATEGORY_TEXTURES; }
  315. VisualShaderNodeTexture();
  316. };
  317. VARIANT_ENUM_CAST(VisualShaderNodeTexture::TextureType)
  318. VARIANT_ENUM_CAST(VisualShaderNodeTexture::Source)
  319. ///////////////////////////////////////
  320. class VisualShaderNodeCurveTexture : public VisualShaderNodeResizableBase {
  321. GDCLASS(VisualShaderNodeCurveTexture, VisualShaderNodeResizableBase);
  322. Ref<CurveTexture> texture;
  323. protected:
  324. static void _bind_methods();
  325. public:
  326. virtual String get_caption() const override;
  327. virtual int get_input_port_count() const override;
  328. virtual PortType get_input_port_type(int p_port) const override;
  329. virtual String get_input_port_name(int p_port) const override;
  330. virtual int get_output_port_count() const override;
  331. virtual PortType get_output_port_type(int p_port) const override;
  332. virtual String get_output_port_name(int p_port) const override;
  333. virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override;
  334. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  335. virtual String 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 = false) const override;
  336. void set_texture(Ref<CurveTexture> p_texture);
  337. Ref<CurveTexture> get_texture() const;
  338. virtual Vector<StringName> get_editable_properties() const override;
  339. virtual bool is_use_prop_slots() const override;
  340. virtual Category get_category() const override { return CATEGORY_TEXTURES; }
  341. VisualShaderNodeCurveTexture();
  342. };
  343. ///////////////////////////////////////
  344. class VisualShaderNodeCurveXYZTexture : public VisualShaderNodeResizableBase {
  345. GDCLASS(VisualShaderNodeCurveXYZTexture, VisualShaderNodeResizableBase);
  346. Ref<CurveXYZTexture> texture;
  347. protected:
  348. static void _bind_methods();
  349. public:
  350. virtual String get_caption() const override;
  351. virtual int get_input_port_count() const override;
  352. virtual PortType get_input_port_type(int p_port) const override;
  353. virtual String get_input_port_name(int p_port) const override;
  354. virtual int get_output_port_count() const override;
  355. virtual PortType get_output_port_type(int p_port) const override;
  356. virtual String get_output_port_name(int p_port) const override;
  357. virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override;
  358. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  359. virtual String 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 = false) const override;
  360. void set_texture(Ref<CurveXYZTexture> p_texture);
  361. Ref<CurveXYZTexture> get_texture() const;
  362. virtual Vector<StringName> get_editable_properties() const override;
  363. virtual bool is_use_prop_slots() const override;
  364. virtual Category get_category() const override { return CATEGORY_TEXTURES; }
  365. VisualShaderNodeCurveXYZTexture();
  366. };
  367. ///////////////////////////////////////
  368. class VisualShaderNodeSample3D : public VisualShaderNode {
  369. GDCLASS(VisualShaderNodeSample3D, VisualShaderNode);
  370. public:
  371. enum Source {
  372. SOURCE_TEXTURE,
  373. SOURCE_PORT,
  374. SOURCE_MAX,
  375. };
  376. protected:
  377. Source source = SOURCE_TEXTURE;
  378. static void _bind_methods();
  379. public:
  380. virtual int get_input_port_count() const override;
  381. virtual PortType get_input_port_type(int p_port) const override;
  382. virtual String get_input_port_name(int p_port) const override;
  383. virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override;
  384. virtual int get_output_port_count() const override;
  385. virtual PortType get_output_port_type(int p_port) const override;
  386. virtual String get_output_port_name(int p_port) const override;
  387. virtual String 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 = false) const override;
  388. void set_source(Source p_source);
  389. Source get_source() const;
  390. virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const override;
  391. virtual Category get_category() const override { return CATEGORY_TEXTURES; }
  392. VisualShaderNodeSample3D();
  393. };
  394. VARIANT_ENUM_CAST(VisualShaderNodeSample3D::Source)
  395. class VisualShaderNodeTexture2DArray : public VisualShaderNodeSample3D {
  396. GDCLASS(VisualShaderNodeTexture2DArray, VisualShaderNodeSample3D);
  397. Ref<TextureLayered> texture_array;
  398. protected:
  399. #ifndef DISABLE_DEPRECATED
  400. void _set_texture_array_bind_compat_95126(Ref<Texture2DArray> p_texture_array);
  401. Ref<Texture2DArray> _get_texture_array_bind_compat_95126() const;
  402. static void _bind_compatibility_methods();
  403. #endif // DISABLE_DEPRECATED
  404. static void _bind_methods();
  405. public:
  406. virtual String get_caption() const override;
  407. virtual String get_input_port_name(int p_port) const override;
  408. virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override;
  409. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  410. void set_texture_array(Ref<TextureLayered> p_texture_array);
  411. Ref<TextureLayered> get_texture_array() const;
  412. virtual Vector<StringName> get_editable_properties() const override;
  413. VisualShaderNodeTexture2DArray();
  414. };
  415. class VisualShaderNodeTexture3D : public VisualShaderNodeSample3D {
  416. GDCLASS(VisualShaderNodeTexture3D, VisualShaderNodeSample3D);
  417. Ref<Texture3D> texture;
  418. protected:
  419. static void _bind_methods();
  420. public:
  421. virtual String get_caption() const override;
  422. virtual String get_input_port_name(int p_port) const override;
  423. virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override;
  424. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  425. void set_texture(Ref<Texture3D> p_texture);
  426. Ref<Texture3D> get_texture() const;
  427. virtual Vector<StringName> get_editable_properties() const override;
  428. VisualShaderNodeTexture3D();
  429. };
  430. class VisualShaderNodeCubemap : public VisualShaderNode {
  431. GDCLASS(VisualShaderNodeCubemap, VisualShaderNode);
  432. Ref<TextureLayered> cube_map;
  433. public:
  434. enum Source {
  435. SOURCE_TEXTURE,
  436. SOURCE_PORT,
  437. SOURCE_MAX,
  438. };
  439. enum TextureType {
  440. TYPE_DATA,
  441. TYPE_COLOR,
  442. TYPE_NORMAL_MAP,
  443. TYPE_MAX,
  444. };
  445. private:
  446. Source source = SOURCE_TEXTURE;
  447. TextureType texture_type = TYPE_DATA;
  448. protected:
  449. #ifndef DISABLE_DEPRECATED
  450. void _set_cube_map_bind_compat_95126(Ref<Cubemap> p_cube_map);
  451. Ref<Cubemap> _get_cube_map_bind_compat_95126() const;
  452. static void _bind_compatibility_methods();
  453. #endif // DISABLE_DEPRECATED
  454. static void _bind_methods();
  455. public:
  456. virtual String get_caption() const override;
  457. virtual int get_input_port_count() const override;
  458. virtual PortType get_input_port_type(int p_port) const override;
  459. virtual String get_input_port_name(int p_port) const override;
  460. virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override;
  461. virtual int get_output_port_count() const override;
  462. virtual PortType get_output_port_type(int p_port) const override;
  463. virtual String get_output_port_name(int p_port) const override;
  464. virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override;
  465. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  466. virtual String 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 = false) const override;
  467. void set_source(Source p_source);
  468. Source get_source() const;
  469. void set_cube_map(Ref<TextureLayered> p_cube_map);
  470. Ref<TextureLayered> get_cube_map() const;
  471. void set_texture_type(TextureType p_texture_type);
  472. TextureType get_texture_type() const;
  473. virtual Vector<StringName> get_editable_properties() const override;
  474. virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const override;
  475. virtual Category get_category() const override { return CATEGORY_TEXTURES; }
  476. VisualShaderNodeCubemap();
  477. };
  478. VARIANT_ENUM_CAST(VisualShaderNodeCubemap::TextureType)
  479. VARIANT_ENUM_CAST(VisualShaderNodeCubemap::Source)
  480. ///////////////////////////////////////
  481. class VisualShaderNodeLinearSceneDepth : public VisualShaderNode {
  482. GDCLASS(VisualShaderNodeLinearSceneDepth, VisualShaderNode);
  483. public:
  484. virtual String get_caption() const override;
  485. virtual int get_input_port_count() const override;
  486. virtual PortType get_input_port_type(int p_port) const override;
  487. virtual String get_input_port_name(int p_port) const override;
  488. virtual int get_output_port_count() const override;
  489. virtual PortType get_output_port_type(int p_port) const override;
  490. virtual String get_output_port_name(int p_port) const override;
  491. virtual bool has_output_port_preview(int p_port) const override;
  492. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  493. virtual String 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 = false) const override;
  494. virtual Category get_category() const override { return CATEGORY_TEXTURES; }
  495. VisualShaderNodeLinearSceneDepth();
  496. };
  497. class VisualShaderNodeWorldPositionFromDepth : public VisualShaderNode {
  498. GDCLASS(VisualShaderNodeWorldPositionFromDepth, VisualShaderNode);
  499. public:
  500. virtual String get_caption() const override;
  501. virtual int get_input_port_count() const override;
  502. virtual PortType get_input_port_type(int p_port) const override;
  503. virtual String get_input_port_name(int p_port) const override;
  504. virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override;
  505. virtual int get_output_port_count() const override;
  506. virtual PortType get_output_port_type(int p_port) const override;
  507. virtual String get_output_port_name(int p_port) const override;
  508. virtual bool has_output_port_preview(int p_port) const override;
  509. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  510. virtual String 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 = false) const override;
  511. virtual Category get_category() const override { return CATEGORY_TEXTURES; }
  512. VisualShaderNodeWorldPositionFromDepth();
  513. };
  514. class VisualShaderNodeScreenNormalWorldSpace : public VisualShaderNode {
  515. GDCLASS(VisualShaderNodeScreenNormalWorldSpace, VisualShaderNode);
  516. public:
  517. virtual String get_caption() const override;
  518. virtual int get_input_port_count() const override;
  519. virtual PortType get_input_port_type(int p_port) const override;
  520. virtual String get_input_port_name(int p_port) const override;
  521. virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override;
  522. virtual int get_output_port_count() const override;
  523. virtual PortType get_output_port_type(int p_port) const override;
  524. virtual String get_output_port_name(int p_port) const override;
  525. virtual bool has_output_port_preview(int p_port) const override;
  526. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  527. virtual String 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 = false) const override;
  528. virtual Category get_category() const override { return CATEGORY_TEXTURES; }
  529. VisualShaderNodeScreenNormalWorldSpace();
  530. };
  531. ///////////////////////////////////////
  532. /// OPS
  533. ///////////////////////////////////////
  534. class VisualShaderNodeFloatOp : public VisualShaderNode {
  535. GDCLASS(VisualShaderNodeFloatOp, VisualShaderNode);
  536. public:
  537. enum Operator {
  538. OP_ADD,
  539. OP_SUB,
  540. OP_MUL,
  541. OP_DIV,
  542. OP_MOD,
  543. OP_POW,
  544. OP_MAX,
  545. OP_MIN,
  546. OP_ATAN2,
  547. OP_STEP,
  548. OP_ENUM_SIZE,
  549. };
  550. protected:
  551. Operator op = OP_ADD;
  552. static void _bind_methods();
  553. public:
  554. virtual String get_caption() const override;
  555. virtual int get_input_port_count() const override;
  556. virtual PortType get_input_port_type(int p_port) const override;
  557. virtual String get_input_port_name(int p_port) const override;
  558. virtual int get_output_port_count() const override;
  559. virtual PortType get_output_port_type(int p_port) const override;
  560. virtual String get_output_port_name(int p_port) const override;
  561. virtual String 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 = false) const override;
  562. void set_operator(Operator p_op);
  563. Operator get_operator() const;
  564. virtual Vector<StringName> get_editable_properties() const override;
  565. virtual Category get_category() const override { return CATEGORY_SCALAR; }
  566. VisualShaderNodeFloatOp();
  567. };
  568. VARIANT_ENUM_CAST(VisualShaderNodeFloatOp::Operator)
  569. class VisualShaderNodeIntOp : public VisualShaderNode {
  570. GDCLASS(VisualShaderNodeIntOp, VisualShaderNode);
  571. public:
  572. enum Operator {
  573. OP_ADD,
  574. OP_SUB,
  575. OP_MUL,
  576. OP_DIV,
  577. OP_MOD,
  578. OP_MAX,
  579. OP_MIN,
  580. OP_BITWISE_AND,
  581. OP_BITWISE_OR,
  582. OP_BITWISE_XOR,
  583. OP_BITWISE_LEFT_SHIFT,
  584. OP_BITWISE_RIGHT_SHIFT,
  585. OP_ENUM_SIZE,
  586. };
  587. protected:
  588. Operator op = OP_ADD;
  589. static void _bind_methods();
  590. public:
  591. virtual String get_caption() const override;
  592. virtual int get_input_port_count() const override;
  593. virtual PortType get_input_port_type(int p_port) const override;
  594. virtual String get_input_port_name(int p_port) const override;
  595. virtual int get_output_port_count() const override;
  596. virtual PortType get_output_port_type(int p_port) const override;
  597. virtual String get_output_port_name(int p_port) const override;
  598. virtual String 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 = false) const override;
  599. void set_operator(Operator p_op);
  600. Operator get_operator() const;
  601. virtual Vector<StringName> get_editable_properties() const override;
  602. virtual Category get_category() const override { return CATEGORY_SCALAR; }
  603. VisualShaderNodeIntOp();
  604. };
  605. VARIANT_ENUM_CAST(VisualShaderNodeIntOp::Operator)
  606. class VisualShaderNodeUIntOp : public VisualShaderNode {
  607. GDCLASS(VisualShaderNodeUIntOp, VisualShaderNode);
  608. public:
  609. enum Operator {
  610. OP_ADD,
  611. OP_SUB,
  612. OP_MUL,
  613. OP_DIV,
  614. OP_MOD,
  615. OP_MAX,
  616. OP_MIN,
  617. OP_BITWISE_AND,
  618. OP_BITWISE_OR,
  619. OP_BITWISE_XOR,
  620. OP_BITWISE_LEFT_SHIFT,
  621. OP_BITWISE_RIGHT_SHIFT,
  622. OP_ENUM_SIZE,
  623. };
  624. protected:
  625. Operator op = OP_ADD;
  626. static void _bind_methods();
  627. public:
  628. virtual String get_caption() const override;
  629. virtual int get_input_port_count() const override;
  630. virtual PortType get_input_port_type(int p_port) const override;
  631. virtual String get_input_port_name(int p_port) const override;
  632. virtual int get_output_port_count() const override;
  633. virtual PortType get_output_port_type(int p_port) const override;
  634. virtual String get_output_port_name(int p_port) const override;
  635. virtual String 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 = false) const override;
  636. void set_operator(Operator p_op);
  637. Operator get_operator() const;
  638. virtual Vector<StringName> get_editable_properties() const override;
  639. virtual Category get_category() const override { return CATEGORY_SCALAR; }
  640. VisualShaderNodeUIntOp();
  641. };
  642. VARIANT_ENUM_CAST(VisualShaderNodeUIntOp::Operator)
  643. class VisualShaderNodeVectorOp : public VisualShaderNodeVectorBase {
  644. GDCLASS(VisualShaderNodeVectorOp, VisualShaderNodeVectorBase);
  645. public:
  646. enum Operator {
  647. OP_ADD,
  648. OP_SUB,
  649. OP_MUL,
  650. OP_DIV,
  651. OP_MOD,
  652. OP_POW,
  653. OP_MAX,
  654. OP_MIN,
  655. OP_CROSS,
  656. OP_ATAN2,
  657. OP_REFLECT,
  658. OP_STEP,
  659. OP_ENUM_SIZE,
  660. };
  661. protected:
  662. Operator op = OP_ADD;
  663. static void _bind_methods();
  664. public:
  665. virtual String get_caption() const override;
  666. virtual int get_input_port_count() const override;
  667. virtual String get_input_port_name(int p_port) const override;
  668. virtual int get_output_port_count() const override;
  669. virtual String get_output_port_name(int p_port) const override;
  670. virtual String 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 = false) const override;
  671. virtual void set_op_type(OpType p_op_type) override;
  672. void set_operator(Operator p_op);
  673. Operator get_operator() const;
  674. virtual Vector<StringName> get_editable_properties() const override;
  675. String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const override;
  676. VisualShaderNodeVectorOp();
  677. };
  678. VARIANT_ENUM_CAST(VisualShaderNodeVectorOp::Operator)
  679. ///////////////////////////////////////
  680. class VisualShaderNodeColorOp : public VisualShaderNode {
  681. GDCLASS(VisualShaderNodeColorOp, VisualShaderNode);
  682. public:
  683. enum Operator {
  684. OP_SCREEN,
  685. OP_DIFFERENCE,
  686. OP_DARKEN,
  687. OP_LIGHTEN,
  688. OP_OVERLAY,
  689. OP_DODGE,
  690. OP_BURN,
  691. OP_SOFT_LIGHT,
  692. OP_HARD_LIGHT,
  693. OP_MAX,
  694. };
  695. protected:
  696. Operator op = OP_SCREEN;
  697. static void _bind_methods();
  698. public:
  699. virtual String get_caption() const override;
  700. virtual int get_input_port_count() const override;
  701. virtual PortType get_input_port_type(int p_port) const override;
  702. virtual String get_input_port_name(int p_port) const override;
  703. virtual int get_output_port_count() const override;
  704. virtual PortType get_output_port_type(int p_port) const override;
  705. virtual String get_output_port_name(int p_port) const override;
  706. virtual String 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 = false) const override;
  707. void set_operator(Operator p_op);
  708. Operator get_operator() const;
  709. virtual Vector<StringName> get_editable_properties() const override;
  710. virtual Category get_category() const override { return CATEGORY_COLOR; }
  711. VisualShaderNodeColorOp();
  712. };
  713. VARIANT_ENUM_CAST(VisualShaderNodeColorOp::Operator)
  714. ////////////////////////////////
  715. /// TRANSFORM-TRANSFORM OPERATOR
  716. ////////////////////////////////
  717. class VisualShaderNodeTransformOp : public VisualShaderNode {
  718. GDCLASS(VisualShaderNodeTransformOp, VisualShaderNode);
  719. public:
  720. enum Operator {
  721. OP_AxB,
  722. OP_BxA,
  723. OP_AxB_COMP,
  724. OP_BxA_COMP,
  725. OP_ADD,
  726. OP_A_MINUS_B,
  727. OP_B_MINUS_A,
  728. OP_A_DIV_B,
  729. OP_B_DIV_A,
  730. OP_MAX,
  731. };
  732. protected:
  733. Operator op = OP_AxB;
  734. static void _bind_methods();
  735. public:
  736. virtual String get_caption() const override;
  737. virtual int get_input_port_count() const override;
  738. virtual PortType get_input_port_type(int p_port) const override;
  739. virtual String get_input_port_name(int p_port) const override;
  740. virtual int get_output_port_count() const override;
  741. virtual PortType get_output_port_type(int p_port) const override;
  742. virtual String get_output_port_name(int p_port) const override;
  743. virtual String 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 = false) const override;
  744. void set_operator(Operator p_op);
  745. Operator get_operator() const;
  746. virtual Vector<StringName> get_editable_properties() const override;
  747. virtual Category get_category() const override { return CATEGORY_TRANSFORM; }
  748. VisualShaderNodeTransformOp();
  749. };
  750. VARIANT_ENUM_CAST(VisualShaderNodeTransformOp::Operator)
  751. ///////////////////////////////////////
  752. /// TRANSFORM-VECTOR MULTIPLICATION
  753. ///////////////////////////////////////
  754. class VisualShaderNodeTransformVecMult : public VisualShaderNode {
  755. GDCLASS(VisualShaderNodeTransformVecMult, VisualShaderNode);
  756. public:
  757. enum Operator {
  758. OP_AxB,
  759. OP_BxA,
  760. OP_3x3_AxB,
  761. OP_3x3_BxA,
  762. OP_MAX,
  763. };
  764. protected:
  765. Operator op = OP_AxB;
  766. static void _bind_methods();
  767. public:
  768. virtual String get_caption() const override;
  769. virtual int get_input_port_count() const override;
  770. virtual PortType get_input_port_type(int p_port) const override;
  771. virtual String get_input_port_name(int p_port) const override;
  772. virtual int get_output_port_count() const override;
  773. virtual PortType get_output_port_type(int p_port) const override;
  774. virtual String get_output_port_name(int p_port) const override;
  775. virtual String 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 = false) const override;
  776. void set_operator(Operator p_op);
  777. Operator get_operator() const;
  778. virtual Vector<StringName> get_editable_properties() const override;
  779. virtual Category get_category() const override { return CATEGORY_TRANSFORM; }
  780. VisualShaderNodeTransformVecMult();
  781. };
  782. VARIANT_ENUM_CAST(VisualShaderNodeTransformVecMult::Operator)
  783. ///////////////////////////////////////
  784. /// FLOAT FUNC
  785. ///////////////////////////////////////
  786. class VisualShaderNodeFloatFunc : public VisualShaderNode {
  787. GDCLASS(VisualShaderNodeFloatFunc, VisualShaderNode);
  788. public:
  789. enum Function {
  790. FUNC_SIN,
  791. FUNC_COS,
  792. FUNC_TAN,
  793. FUNC_ASIN,
  794. FUNC_ACOS,
  795. FUNC_ATAN,
  796. FUNC_SINH,
  797. FUNC_COSH,
  798. FUNC_TANH,
  799. FUNC_LOG,
  800. FUNC_EXP,
  801. FUNC_SQRT,
  802. FUNC_ABS,
  803. FUNC_SIGN,
  804. FUNC_FLOOR,
  805. FUNC_ROUND,
  806. FUNC_CEIL,
  807. FUNC_FRACT,
  808. FUNC_SATURATE,
  809. FUNC_NEGATE,
  810. FUNC_ACOSH,
  811. FUNC_ASINH,
  812. FUNC_ATANH,
  813. FUNC_DEGREES,
  814. FUNC_EXP2,
  815. FUNC_INVERSE_SQRT,
  816. FUNC_LOG2,
  817. FUNC_RADIANS,
  818. FUNC_RECIPROCAL,
  819. FUNC_ROUNDEVEN,
  820. FUNC_TRUNC,
  821. FUNC_ONEMINUS,
  822. FUNC_MAX,
  823. };
  824. protected:
  825. Function func = FUNC_SIGN;
  826. static void _bind_methods();
  827. public:
  828. virtual String get_caption() const override;
  829. virtual int get_input_port_count() const override;
  830. virtual PortType get_input_port_type(int p_port) const override;
  831. virtual String get_input_port_name(int p_port) const override;
  832. virtual int get_output_port_count() const override;
  833. virtual PortType get_output_port_type(int p_port) const override;
  834. virtual String get_output_port_name(int p_port) const override;
  835. virtual String 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 = false) const override;
  836. void set_function(Function p_func);
  837. Function get_function() const;
  838. virtual Vector<StringName> get_editable_properties() const override;
  839. virtual Category get_category() const override { return CATEGORY_SCALAR; }
  840. VisualShaderNodeFloatFunc();
  841. };
  842. VARIANT_ENUM_CAST(VisualShaderNodeFloatFunc::Function)
  843. ///////////////////////////////////////
  844. /// INT FUNC
  845. ///////////////////////////////////////
  846. class VisualShaderNodeIntFunc : public VisualShaderNode {
  847. GDCLASS(VisualShaderNodeIntFunc, VisualShaderNode);
  848. public:
  849. enum Function {
  850. FUNC_ABS,
  851. FUNC_NEGATE,
  852. FUNC_SIGN,
  853. FUNC_BITWISE_NOT,
  854. FUNC_MAX,
  855. };
  856. protected:
  857. Function func = FUNC_SIGN;
  858. static void _bind_methods();
  859. public:
  860. virtual String get_caption() const override;
  861. virtual int get_input_port_count() const override;
  862. virtual PortType get_input_port_type(int p_port) const override;
  863. virtual String get_input_port_name(int p_port) const override;
  864. virtual int get_output_port_count() const override;
  865. virtual PortType get_output_port_type(int p_port) const override;
  866. virtual String get_output_port_name(int p_port) const override;
  867. virtual String 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 = false) const override;
  868. void set_function(Function p_func);
  869. Function get_function() const;
  870. virtual Vector<StringName> get_editable_properties() const override;
  871. virtual Category get_category() const override { return CATEGORY_SCALAR; }
  872. VisualShaderNodeIntFunc();
  873. };
  874. VARIANT_ENUM_CAST(VisualShaderNodeIntFunc::Function)
  875. ///////////////////////////////////////
  876. /// UINT FUNC
  877. ///////////////////////////////////////
  878. class VisualShaderNodeUIntFunc : public VisualShaderNode {
  879. GDCLASS(VisualShaderNodeUIntFunc, VisualShaderNode);
  880. public:
  881. enum Function {
  882. FUNC_NEGATE,
  883. FUNC_BITWISE_NOT,
  884. FUNC_MAX,
  885. };
  886. protected:
  887. Function func = FUNC_NEGATE;
  888. static void _bind_methods();
  889. public:
  890. virtual String get_caption() const override;
  891. virtual int get_input_port_count() const override;
  892. virtual PortType get_input_port_type(int p_port) const override;
  893. virtual String get_input_port_name(int p_port) const override;
  894. virtual int get_output_port_count() const override;
  895. virtual PortType get_output_port_type(int p_port) const override;
  896. virtual String get_output_port_name(int p_port) const override;
  897. virtual String 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 = false) const override;
  898. void set_function(Function p_func);
  899. Function get_function() const;
  900. virtual Vector<StringName> get_editable_properties() const override;
  901. virtual Category get_category() const override { return CATEGORY_SCALAR; }
  902. VisualShaderNodeUIntFunc();
  903. };
  904. VARIANT_ENUM_CAST(VisualShaderNodeUIntFunc::Function)
  905. ///////////////////////////////////////
  906. /// VECTOR FUNC
  907. ///////////////////////////////////////
  908. class VisualShaderNodeVectorFunc : public VisualShaderNodeVectorBase {
  909. GDCLASS(VisualShaderNodeVectorFunc, VisualShaderNodeVectorBase);
  910. void _update_default_input_values();
  911. public:
  912. enum Function {
  913. FUNC_NORMALIZE,
  914. FUNC_SATURATE,
  915. FUNC_NEGATE,
  916. FUNC_RECIPROCAL,
  917. FUNC_ABS,
  918. FUNC_ACOS,
  919. FUNC_ACOSH,
  920. FUNC_ASIN,
  921. FUNC_ASINH,
  922. FUNC_ATAN,
  923. FUNC_ATANH,
  924. FUNC_CEIL,
  925. FUNC_COS,
  926. FUNC_COSH,
  927. FUNC_DEGREES,
  928. FUNC_EXP,
  929. FUNC_EXP2,
  930. FUNC_FLOOR,
  931. FUNC_FRACT,
  932. FUNC_INVERSE_SQRT,
  933. FUNC_LOG,
  934. FUNC_LOG2,
  935. FUNC_RADIANS,
  936. FUNC_ROUND,
  937. FUNC_ROUNDEVEN,
  938. FUNC_SIGN,
  939. FUNC_SIN,
  940. FUNC_SINH,
  941. FUNC_SQRT,
  942. FUNC_TAN,
  943. FUNC_TANH,
  944. FUNC_TRUNC,
  945. FUNC_ONEMINUS,
  946. FUNC_MAX,
  947. };
  948. protected:
  949. Function func = FUNC_NORMALIZE;
  950. static void _bind_methods();
  951. public:
  952. virtual String get_caption() const override;
  953. virtual int get_input_port_count() const override;
  954. virtual String get_input_port_name(int p_port) const override;
  955. virtual int get_output_port_count() const override;
  956. virtual String get_output_port_name(int p_port) const override;
  957. virtual String 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 = false) const override;
  958. virtual void set_op_type(OpType p_op_type) override;
  959. void set_function(Function p_func);
  960. Function get_function() const;
  961. virtual Vector<StringName> get_editable_properties() const override;
  962. VisualShaderNodeVectorFunc();
  963. };
  964. VARIANT_ENUM_CAST(VisualShaderNodeVectorFunc::Function)
  965. ///////////////////////////////////////
  966. /// COLOR FUNC
  967. ///////////////////////////////////////
  968. class VisualShaderNodeColorFunc : public VisualShaderNode {
  969. GDCLASS(VisualShaderNodeColorFunc, VisualShaderNode);
  970. public:
  971. enum Function {
  972. FUNC_GRAYSCALE,
  973. FUNC_HSV2RGB,
  974. FUNC_RGB2HSV,
  975. FUNC_SEPIA,
  976. FUNC_LINEAR_TO_SRGB,
  977. FUNC_SRGB_TO_LINEAR,
  978. FUNC_MAX,
  979. };
  980. protected:
  981. Function func = FUNC_GRAYSCALE;
  982. static void _bind_methods();
  983. public:
  984. virtual String get_caption() const override;
  985. virtual int get_input_port_count() const override;
  986. virtual PortType get_input_port_type(int p_port) const override;
  987. virtual String get_input_port_name(int p_port) const override;
  988. virtual int get_output_port_count() const override;
  989. virtual PortType get_output_port_type(int p_port) const override;
  990. virtual String get_output_port_name(int p_port) const override;
  991. virtual String 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 = false) const override;
  992. void set_function(Function p_func);
  993. Function get_function() const;
  994. virtual Vector<StringName> get_editable_properties() const override;
  995. virtual Category get_category() const override { return CATEGORY_COLOR; }
  996. VisualShaderNodeColorFunc();
  997. };
  998. VARIANT_ENUM_CAST(VisualShaderNodeColorFunc::Function)
  999. ///////////////////////////////////////
  1000. /// TRANSFORM FUNC
  1001. ///////////////////////////////////////
  1002. class VisualShaderNodeTransformFunc : public VisualShaderNode {
  1003. GDCLASS(VisualShaderNodeTransformFunc, VisualShaderNode);
  1004. public:
  1005. enum Function {
  1006. FUNC_INVERSE,
  1007. FUNC_TRANSPOSE,
  1008. FUNC_MAX,
  1009. };
  1010. protected:
  1011. Function func = FUNC_INVERSE;
  1012. static void _bind_methods();
  1013. public:
  1014. virtual String get_caption() const override;
  1015. virtual int get_input_port_count() const override;
  1016. virtual PortType get_input_port_type(int p_port) const override;
  1017. virtual String get_input_port_name(int p_port) const override;
  1018. virtual int get_output_port_count() const override;
  1019. virtual PortType get_output_port_type(int p_port) const override;
  1020. virtual String get_output_port_name(int p_port) const override;
  1021. virtual String 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 = false) const override;
  1022. void set_function(Function p_func);
  1023. Function get_function() const;
  1024. virtual Vector<StringName> get_editable_properties() const override;
  1025. virtual Category get_category() const override { return CATEGORY_TRANSFORM; }
  1026. VisualShaderNodeTransformFunc();
  1027. };
  1028. VARIANT_ENUM_CAST(VisualShaderNodeTransformFunc::Function)
  1029. ///////////////////////////////////////
  1030. /// UV FUNC
  1031. ///////////////////////////////////////
  1032. class VisualShaderNodeUVFunc : public VisualShaderNode {
  1033. GDCLASS(VisualShaderNodeUVFunc, VisualShaderNode);
  1034. public:
  1035. enum Function {
  1036. FUNC_PANNING,
  1037. FUNC_SCALING,
  1038. FUNC_MAX,
  1039. };
  1040. protected:
  1041. Function func = FUNC_PANNING;
  1042. static void _bind_methods();
  1043. public:
  1044. virtual String get_caption() const override;
  1045. virtual int get_input_port_count() const override;
  1046. virtual PortType get_input_port_type(int p_port) const override;
  1047. virtual String get_input_port_name(int p_port) const override;
  1048. virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override;
  1049. virtual int get_output_port_count() const override;
  1050. virtual PortType get_output_port_type(int p_port) const override;
  1051. virtual String get_output_port_name(int p_port) const override;
  1052. virtual bool is_show_prop_names() const override;
  1053. virtual String 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 = false) const override;
  1054. void set_function(Function p_func);
  1055. Function get_function() const;
  1056. virtual Vector<StringName> get_editable_properties() const override;
  1057. virtual Category get_category() const override { return CATEGORY_TEXTURES; }
  1058. VisualShaderNodeUVFunc();
  1059. };
  1060. VARIANT_ENUM_CAST(VisualShaderNodeUVFunc::Function)
  1061. ///////////////////////////////////////
  1062. /// UV POLARCOORD
  1063. ///////////////////////////////////////
  1064. class VisualShaderNodeUVPolarCoord : public VisualShaderNode {
  1065. GDCLASS(VisualShaderNodeUVPolarCoord, VisualShaderNode);
  1066. public:
  1067. virtual String get_caption() const override;
  1068. virtual int get_input_port_count() const override;
  1069. virtual PortType get_input_port_type(int p_port) const override;
  1070. virtual String get_input_port_name(int p_port) const override;
  1071. virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override;
  1072. virtual int get_output_port_count() const override;
  1073. virtual PortType get_output_port_type(int p_port) const override;
  1074. virtual String get_output_port_name(int p_port) const override;
  1075. virtual String 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 = false) const override;
  1076. virtual Category get_category() const override { return CATEGORY_TEXTURES; }
  1077. VisualShaderNodeUVPolarCoord();
  1078. };
  1079. ///////////////////////////////////////
  1080. /// DOT
  1081. ///////////////////////////////////////
  1082. class VisualShaderNodeDotProduct : public VisualShaderNode {
  1083. GDCLASS(VisualShaderNodeDotProduct, VisualShaderNode);
  1084. public:
  1085. virtual String get_caption() const override;
  1086. virtual int get_input_port_count() const override;
  1087. virtual PortType get_input_port_type(int p_port) const override;
  1088. virtual String get_input_port_name(int p_port) const override;
  1089. virtual int get_output_port_count() const override;
  1090. virtual PortType get_output_port_type(int p_port) const override;
  1091. virtual String get_output_port_name(int p_port) const override;
  1092. virtual String 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 = false) const override;
  1093. virtual Category get_category() const override { return CATEGORY_VECTOR; }
  1094. VisualShaderNodeDotProduct();
  1095. };
  1096. ///////////////////////////////////////
  1097. /// LENGTH
  1098. ///////////////////////////////////////
  1099. class VisualShaderNodeVectorLen : public VisualShaderNodeVectorBase {
  1100. GDCLASS(VisualShaderNodeVectorLen, VisualShaderNodeVectorBase);
  1101. public:
  1102. virtual String get_caption() const override;
  1103. virtual int get_input_port_count() const override;
  1104. virtual String get_input_port_name(int p_port) const override;
  1105. virtual int get_output_port_count() const override;
  1106. virtual PortType get_output_port_type(int p_port) const override;
  1107. virtual String get_output_port_name(int p_port) const override;
  1108. virtual void set_op_type(OpType p_op_type) override;
  1109. virtual String 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 = false) const override;
  1110. VisualShaderNodeVectorLen();
  1111. };
  1112. ///////////////////////////////////////
  1113. /// DETERMINANT
  1114. ///////////////////////////////////////
  1115. class VisualShaderNodeDeterminant : public VisualShaderNode {
  1116. GDCLASS(VisualShaderNodeDeterminant, VisualShaderNode);
  1117. public:
  1118. virtual String get_caption() const override;
  1119. virtual int get_input_port_count() const override;
  1120. virtual PortType get_input_port_type(int p_port) const override;
  1121. virtual String get_input_port_name(int p_port) const override;
  1122. virtual int get_output_port_count() const override;
  1123. virtual PortType get_output_port_type(int p_port) const override;
  1124. virtual String get_output_port_name(int p_port) const override;
  1125. virtual String 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 = false) const override;
  1126. virtual Category get_category() const override { return CATEGORY_VECTOR; }
  1127. VisualShaderNodeDeterminant();
  1128. };
  1129. ///////////////////////////////////////
  1130. /// CLAMP
  1131. ///////////////////////////////////////
  1132. class VisualShaderNodeClamp : public VisualShaderNode {
  1133. GDCLASS(VisualShaderNodeClamp, VisualShaderNode);
  1134. public:
  1135. enum OpType {
  1136. OP_TYPE_FLOAT,
  1137. OP_TYPE_INT,
  1138. OP_TYPE_UINT,
  1139. OP_TYPE_VECTOR_2D,
  1140. OP_TYPE_VECTOR_3D,
  1141. OP_TYPE_VECTOR_4D,
  1142. OP_TYPE_MAX,
  1143. };
  1144. protected:
  1145. OpType op_type = OP_TYPE_FLOAT;
  1146. static void _bind_methods();
  1147. public:
  1148. virtual String get_caption() const override;
  1149. virtual int get_input_port_count() const override;
  1150. virtual PortType get_input_port_type(int p_port) const override;
  1151. virtual String get_input_port_name(int p_port) const override;
  1152. virtual int get_output_port_count() const override;
  1153. virtual PortType get_output_port_type(int p_port) const override;
  1154. virtual String get_output_port_name(int p_port) const override;
  1155. void set_op_type(OpType p_op_type);
  1156. OpType get_op_type() const;
  1157. virtual Vector<StringName> get_editable_properties() const override;
  1158. virtual String 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 = false) const override;
  1159. virtual Category get_category() const override {
  1160. if (op_type == OP_TYPE_FLOAT || op_type == OP_TYPE_INT || op_type == OP_TYPE_UINT) {
  1161. return CATEGORY_SCALAR;
  1162. } else {
  1163. return CATEGORY_VECTOR;
  1164. }
  1165. }
  1166. VisualShaderNodeClamp();
  1167. };
  1168. VARIANT_ENUM_CAST(VisualShaderNodeClamp::OpType)
  1169. ///////////////////////////////////////
  1170. /// DERIVATIVE FUNCTION
  1171. ///////////////////////////////////////
  1172. class VisualShaderNodeDerivativeFunc : public VisualShaderNode {
  1173. GDCLASS(VisualShaderNodeDerivativeFunc, VisualShaderNode);
  1174. public:
  1175. enum OpType {
  1176. OP_TYPE_SCALAR,
  1177. OP_TYPE_VECTOR_2D,
  1178. OP_TYPE_VECTOR_3D,
  1179. OP_TYPE_VECTOR_4D,
  1180. OP_TYPE_MAX,
  1181. };
  1182. enum Function {
  1183. FUNC_SUM,
  1184. FUNC_X,
  1185. FUNC_Y,
  1186. FUNC_MAX,
  1187. };
  1188. enum Precision {
  1189. PRECISION_NONE,
  1190. PRECISION_COARSE,
  1191. PRECISION_FINE,
  1192. PRECISION_MAX,
  1193. };
  1194. protected:
  1195. OpType op_type = OP_TYPE_SCALAR;
  1196. Function func = FUNC_SUM;
  1197. Precision precision = PRECISION_NONE;
  1198. protected:
  1199. static void _bind_methods();
  1200. public:
  1201. virtual String get_caption() const override;
  1202. virtual int get_input_port_count() const override;
  1203. virtual PortType get_input_port_type(int p_port) const override;
  1204. virtual String get_input_port_name(int p_port) const override;
  1205. virtual int get_output_port_count() const override;
  1206. virtual PortType get_output_port_type(int p_port) const override;
  1207. virtual String get_output_port_name(int p_port) const override;
  1208. virtual String 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 = false) const override;
  1209. virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const override;
  1210. void set_op_type(OpType p_op_type);
  1211. OpType get_op_type() const;
  1212. void set_function(Function p_func);
  1213. Function get_function() const;
  1214. void set_precision(Precision p_precision);
  1215. Precision get_precision() const;
  1216. virtual Vector<StringName> get_editable_properties() const override;
  1217. virtual Category get_category() const override { return CATEGORY_UTILITY; }
  1218. VisualShaderNodeDerivativeFunc();
  1219. };
  1220. VARIANT_ENUM_CAST(VisualShaderNodeDerivativeFunc::OpType)
  1221. VARIANT_ENUM_CAST(VisualShaderNodeDerivativeFunc::Function)
  1222. VARIANT_ENUM_CAST(VisualShaderNodeDerivativeFunc::Precision)
  1223. ///////////////////////////////////////
  1224. /// FACEFORWARD
  1225. ///////////////////////////////////////
  1226. class VisualShaderNodeFaceForward : public VisualShaderNodeVectorBase {
  1227. GDCLASS(VisualShaderNodeFaceForward, VisualShaderNodeVectorBase);
  1228. public:
  1229. virtual String get_caption() const override;
  1230. virtual int get_input_port_count() const override;
  1231. virtual String get_input_port_name(int p_port) const override;
  1232. virtual int get_output_port_count() const override;
  1233. virtual String get_output_port_name(int p_port) const override;
  1234. virtual void set_op_type(OpType p_op_type) override;
  1235. virtual String 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 = false) const override;
  1236. VisualShaderNodeFaceForward();
  1237. };
  1238. ///////////////////////////////////////
  1239. /// OUTER PRODUCT
  1240. ///////////////////////////////////////
  1241. class VisualShaderNodeOuterProduct : public VisualShaderNode {
  1242. GDCLASS(VisualShaderNodeOuterProduct, VisualShaderNode);
  1243. public:
  1244. virtual String get_caption() const override;
  1245. virtual int get_input_port_count() const override;
  1246. virtual PortType get_input_port_type(int p_port) const override;
  1247. virtual String get_input_port_name(int p_port) const override;
  1248. virtual int get_output_port_count() const override;
  1249. virtual PortType get_output_port_type(int p_port) const override;
  1250. virtual String get_output_port_name(int p_port) const override;
  1251. virtual String 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 = false) const override;
  1252. virtual Category get_category() const override { return CATEGORY_TRANSFORM; }
  1253. VisualShaderNodeOuterProduct();
  1254. };
  1255. ///////////////////////////////////////
  1256. /// STEP
  1257. ///////////////////////////////////////
  1258. class VisualShaderNodeStep : public VisualShaderNode {
  1259. GDCLASS(VisualShaderNodeStep, VisualShaderNode);
  1260. public:
  1261. enum OpType {
  1262. OP_TYPE_SCALAR,
  1263. OP_TYPE_VECTOR_2D,
  1264. OP_TYPE_VECTOR_2D_SCALAR,
  1265. OP_TYPE_VECTOR_3D,
  1266. OP_TYPE_VECTOR_3D_SCALAR,
  1267. OP_TYPE_VECTOR_4D,
  1268. OP_TYPE_VECTOR_4D_SCALAR,
  1269. OP_TYPE_MAX,
  1270. };
  1271. protected:
  1272. OpType op_type = OP_TYPE_SCALAR;
  1273. static void _bind_methods();
  1274. public:
  1275. virtual String get_caption() const override;
  1276. virtual int get_input_port_count() const override;
  1277. virtual PortType get_input_port_type(int p_port) const override;
  1278. virtual String get_input_port_name(int p_port) const override;
  1279. virtual int get_default_input_port(PortType p_type) const override;
  1280. virtual int get_output_port_count() const override;
  1281. virtual PortType get_output_port_type(int p_port) const override;
  1282. virtual String get_output_port_name(int p_port) const override;
  1283. void set_op_type(OpType p_op_type);
  1284. OpType get_op_type() const;
  1285. virtual Vector<StringName> get_editable_properties() const override;
  1286. virtual String 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 = false) const override;
  1287. virtual Category get_category() const override {
  1288. if (op_type == OP_TYPE_SCALAR) {
  1289. return CATEGORY_SCALAR;
  1290. } else {
  1291. return CATEGORY_VECTOR;
  1292. }
  1293. }
  1294. VisualShaderNodeStep();
  1295. };
  1296. VARIANT_ENUM_CAST(VisualShaderNodeStep::OpType)
  1297. ///////////////////////////////////////
  1298. /// SMOOTHSTEP
  1299. ///////////////////////////////////////
  1300. class VisualShaderNodeSmoothStep : public VisualShaderNode {
  1301. GDCLASS(VisualShaderNodeSmoothStep, VisualShaderNode);
  1302. public:
  1303. enum OpType {
  1304. OP_TYPE_SCALAR,
  1305. OP_TYPE_VECTOR_2D,
  1306. OP_TYPE_VECTOR_2D_SCALAR,
  1307. OP_TYPE_VECTOR_3D,
  1308. OP_TYPE_VECTOR_3D_SCALAR,
  1309. OP_TYPE_VECTOR_4D,
  1310. OP_TYPE_VECTOR_4D_SCALAR,
  1311. OP_TYPE_MAX,
  1312. };
  1313. protected:
  1314. OpType op_type = OP_TYPE_SCALAR;
  1315. static void _bind_methods();
  1316. public:
  1317. virtual String get_caption() const override;
  1318. virtual int get_input_port_count() const override;
  1319. virtual PortType get_input_port_type(int p_port) const override;
  1320. virtual String get_input_port_name(int p_port) const override;
  1321. virtual int get_default_input_port(PortType p_type) const override;
  1322. virtual int get_output_port_count() const override;
  1323. virtual PortType get_output_port_type(int p_port) const override;
  1324. virtual String get_output_port_name(int p_port) const override;
  1325. void set_op_type(OpType p_op_type);
  1326. OpType get_op_type() const;
  1327. virtual Vector<StringName> get_editable_properties() const override;
  1328. virtual String 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 = false) const override;
  1329. virtual Category get_category() const override {
  1330. if (op_type == OP_TYPE_SCALAR) {
  1331. return CATEGORY_SCALAR;
  1332. } else {
  1333. return CATEGORY_VECTOR;
  1334. }
  1335. }
  1336. VisualShaderNodeSmoothStep();
  1337. };
  1338. VARIANT_ENUM_CAST(VisualShaderNodeSmoothStep::OpType)
  1339. ///////////////////////////////////////
  1340. /// DISTANCE
  1341. ///////////////////////////////////////
  1342. class VisualShaderNodeVectorDistance : public VisualShaderNodeVectorBase {
  1343. GDCLASS(VisualShaderNodeVectorDistance, VisualShaderNodeVectorBase);
  1344. public:
  1345. virtual String get_caption() const override;
  1346. virtual int get_input_port_count() const override;
  1347. virtual String get_input_port_name(int p_port) const override;
  1348. virtual int get_output_port_count() const override;
  1349. virtual PortType get_output_port_type(int p_port) const override;
  1350. virtual String get_output_port_name(int p_port) const override;
  1351. virtual void set_op_type(OpType p_op_type) override;
  1352. virtual String 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 = false) const override;
  1353. VisualShaderNodeVectorDistance();
  1354. };
  1355. ///////////////////////////////////////
  1356. /// REFRACT
  1357. ///////////////////////////////////////
  1358. class VisualShaderNodeVectorRefract : public VisualShaderNodeVectorBase {
  1359. GDCLASS(VisualShaderNodeVectorRefract, VisualShaderNodeVectorBase);
  1360. public:
  1361. virtual String get_caption() const override;
  1362. virtual int get_input_port_count() const override;
  1363. virtual String get_input_port_name(int p_port) const override;
  1364. virtual int get_output_port_count() const override;
  1365. virtual String get_output_port_name(int p_port) const override;
  1366. virtual String 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 = false) const override;
  1367. virtual void set_op_type(OpType p_op_type) override;
  1368. VisualShaderNodeVectorRefract();
  1369. };
  1370. ///////////////////////////////////////
  1371. /// MIX
  1372. ///////////////////////////////////////
  1373. class VisualShaderNodeMix : public VisualShaderNode {
  1374. GDCLASS(VisualShaderNodeMix, VisualShaderNode);
  1375. public:
  1376. enum OpType {
  1377. OP_TYPE_SCALAR,
  1378. OP_TYPE_VECTOR_2D,
  1379. OP_TYPE_VECTOR_2D_SCALAR,
  1380. OP_TYPE_VECTOR_3D,
  1381. OP_TYPE_VECTOR_3D_SCALAR,
  1382. OP_TYPE_VECTOR_4D,
  1383. OP_TYPE_VECTOR_4D_SCALAR,
  1384. OP_TYPE_MAX,
  1385. };
  1386. protected:
  1387. OpType op_type = OP_TYPE_SCALAR;
  1388. static void _bind_methods();
  1389. public:
  1390. virtual String get_caption() const override;
  1391. virtual int get_input_port_count() const override;
  1392. virtual PortType get_input_port_type(int p_port) const override;
  1393. virtual String get_input_port_name(int p_port) const override;
  1394. virtual int get_output_port_count() const override;
  1395. virtual PortType get_output_port_type(int p_port) const override;
  1396. virtual String get_output_port_name(int p_port) const override;
  1397. void set_op_type(OpType p_op_type);
  1398. OpType get_op_type() const;
  1399. virtual Vector<StringName> get_editable_properties() const override;
  1400. virtual String 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 = false) const override;
  1401. virtual Category get_category() const override {
  1402. if (op_type == OP_TYPE_SCALAR) {
  1403. return CATEGORY_SCALAR;
  1404. } else {
  1405. return CATEGORY_VECTOR;
  1406. }
  1407. }
  1408. VisualShaderNodeMix();
  1409. };
  1410. VARIANT_ENUM_CAST(VisualShaderNodeMix::OpType)
  1411. ///////////////////////////////////////
  1412. /// COMPOSE
  1413. ///////////////////////////////////////
  1414. class VisualShaderNodeVectorCompose : public VisualShaderNodeVectorBase {
  1415. GDCLASS(VisualShaderNodeVectorCompose, VisualShaderNodeVectorBase);
  1416. public:
  1417. virtual String get_caption() const override;
  1418. virtual int get_input_port_count() const override;
  1419. virtual PortType get_input_port_type(int p_port) const override;
  1420. virtual String get_input_port_name(int p_port) const override;
  1421. virtual int get_output_port_count() const override;
  1422. virtual String get_output_port_name(int p_port) const override;
  1423. virtual void set_op_type(OpType p_op_type) override;
  1424. virtual String 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 = false) const override;
  1425. VisualShaderNodeVectorCompose();
  1426. };
  1427. ///////////////////////////////////////
  1428. class VisualShaderNodeTransformCompose : public VisualShaderNode {
  1429. GDCLASS(VisualShaderNodeTransformCompose, VisualShaderNode);
  1430. public:
  1431. virtual String get_caption() const override;
  1432. virtual int get_input_port_count() const override;
  1433. virtual PortType get_input_port_type(int p_port) const override;
  1434. virtual String get_input_port_name(int p_port) const override;
  1435. virtual int get_output_port_count() const override;
  1436. virtual PortType get_output_port_type(int p_port) const override;
  1437. virtual String get_output_port_name(int p_port) const override;
  1438. virtual String 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 = false) const override;
  1439. virtual Category get_category() const override { return CATEGORY_TRANSFORM; }
  1440. VisualShaderNodeTransformCompose();
  1441. };
  1442. ///////////////////////////////////////
  1443. /// DECOMPOSE
  1444. ///////////////////////////////////////
  1445. class VisualShaderNodeVectorDecompose : public VisualShaderNodeVectorBase {
  1446. GDCLASS(VisualShaderNodeVectorDecompose, VisualShaderNodeVectorBase);
  1447. public:
  1448. virtual String get_caption() const override;
  1449. virtual int get_input_port_count() const override;
  1450. virtual String get_input_port_name(int p_port) const override;
  1451. virtual int get_output_port_count() const override;
  1452. virtual PortType get_output_port_type(int p_port) const override;
  1453. virtual String get_output_port_name(int p_port) const override;
  1454. virtual void set_op_type(OpType p_op_type) override;
  1455. virtual String 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 = false) const override;
  1456. VisualShaderNodeVectorDecompose();
  1457. };
  1458. ///////////////////////////////////////
  1459. class VisualShaderNodeTransformDecompose : public VisualShaderNode {
  1460. GDCLASS(VisualShaderNodeTransformDecompose, VisualShaderNode);
  1461. public:
  1462. virtual String get_caption() const override;
  1463. virtual int get_input_port_count() const override;
  1464. virtual PortType get_input_port_type(int p_port) const override;
  1465. virtual String get_input_port_name(int p_port) const override;
  1466. virtual int get_output_port_count() const override;
  1467. virtual PortType get_output_port_type(int p_port) const override;
  1468. virtual String get_output_port_name(int p_port) const override;
  1469. virtual String 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 = false) const override;
  1470. virtual Category get_category() const override { return CATEGORY_TRANSFORM; }
  1471. VisualShaderNodeTransformDecompose();
  1472. };
  1473. ///////////////////////////////////////
  1474. /// PARAMETERS
  1475. ///////////////////////////////////////
  1476. class VisualShaderNodeFloatParameter : public VisualShaderNodeParameter {
  1477. GDCLASS(VisualShaderNodeFloatParameter, VisualShaderNodeParameter);
  1478. public:
  1479. enum Hint {
  1480. HINT_NONE,
  1481. HINT_RANGE,
  1482. HINT_RANGE_STEP,
  1483. HINT_MAX,
  1484. };
  1485. private:
  1486. Hint hint = HINT_NONE;
  1487. float hint_range_min = 0.0f;
  1488. float hint_range_max = 1.0f;
  1489. float hint_range_step = 0.1f;
  1490. bool default_value_enabled = false;
  1491. float default_value = 0.0f;
  1492. protected:
  1493. static void _bind_methods();
  1494. public:
  1495. virtual String get_caption() const override;
  1496. virtual int get_input_port_count() const override;
  1497. virtual PortType get_input_port_type(int p_port) const override;
  1498. virtual String get_input_port_name(int p_port) const override;
  1499. virtual int get_output_port_count() const override;
  1500. virtual PortType get_output_port_type(int p_port) const override;
  1501. virtual String get_output_port_name(int p_port) const override;
  1502. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1503. virtual String 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 = false) const override;
  1504. virtual bool is_show_prop_names() const override;
  1505. virtual bool is_use_prop_slots() const override;
  1506. void set_hint(Hint p_hint);
  1507. Hint get_hint() const;
  1508. void set_min(float p_value);
  1509. float get_min() const;
  1510. void set_max(float p_value);
  1511. float get_max() const;
  1512. void set_step(float p_value);
  1513. float get_step() const;
  1514. void set_default_value_enabled(bool p_enabled);
  1515. bool is_default_value_enabled() const;
  1516. void set_default_value(float p_value);
  1517. float get_default_value() const;
  1518. bool is_qualifier_supported(Qualifier p_qual) const override;
  1519. bool is_convertible_to_constant() const override;
  1520. virtual Vector<StringName> get_editable_properties() const override;
  1521. VisualShaderNodeFloatParameter();
  1522. };
  1523. VARIANT_ENUM_CAST(VisualShaderNodeFloatParameter::Hint)
  1524. class VisualShaderNodeIntParameter : public VisualShaderNodeParameter {
  1525. GDCLASS(VisualShaderNodeIntParameter, VisualShaderNodeParameter);
  1526. public:
  1527. enum Hint {
  1528. HINT_NONE,
  1529. HINT_RANGE,
  1530. HINT_RANGE_STEP,
  1531. HINT_ENUM,
  1532. HINT_MAX,
  1533. };
  1534. private:
  1535. Hint hint = HINT_NONE;
  1536. int hint_range_min = 0;
  1537. int hint_range_max = 100;
  1538. int hint_range_step = 1;
  1539. PackedStringArray hint_enum_names;
  1540. bool default_value_enabled = false;
  1541. int default_value = 0;
  1542. protected:
  1543. static void _bind_methods();
  1544. public:
  1545. virtual String get_caption() const override;
  1546. virtual int get_input_port_count() const override;
  1547. virtual PortType get_input_port_type(int p_port) const override;
  1548. virtual String get_input_port_name(int p_port) const override;
  1549. virtual int get_output_port_count() const override;
  1550. virtual PortType get_output_port_type(int p_port) const override;
  1551. virtual String get_output_port_name(int p_port) const override;
  1552. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1553. virtual String 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 = false) const override;
  1554. virtual bool is_show_prop_names() const override;
  1555. virtual bool is_use_prop_slots() const override;
  1556. void set_hint(Hint p_hint);
  1557. Hint get_hint() const;
  1558. void set_min(int p_value);
  1559. int get_min() const;
  1560. void set_max(int p_value);
  1561. int get_max() const;
  1562. void set_step(int p_value);
  1563. int get_step() const;
  1564. void set_enum_names(const PackedStringArray &p_names);
  1565. PackedStringArray get_enum_names() const;
  1566. void set_default_value_enabled(bool p_enabled);
  1567. bool is_default_value_enabled() const;
  1568. void set_default_value(int p_value);
  1569. int get_default_value() const;
  1570. bool is_qualifier_supported(Qualifier p_qual) const override;
  1571. bool is_convertible_to_constant() const override;
  1572. virtual Vector<StringName> get_editable_properties() const override;
  1573. VisualShaderNodeIntParameter();
  1574. };
  1575. VARIANT_ENUM_CAST(VisualShaderNodeIntParameter::Hint)
  1576. ///////////////////////////////////////
  1577. class VisualShaderNodeUIntParameter : public VisualShaderNodeParameter {
  1578. GDCLASS(VisualShaderNodeUIntParameter, VisualShaderNodeParameter);
  1579. private:
  1580. bool default_value_enabled = false;
  1581. int default_value = 0;
  1582. protected:
  1583. static void _bind_methods();
  1584. public:
  1585. virtual String get_caption() const override;
  1586. virtual int get_input_port_count() const override;
  1587. virtual PortType get_input_port_type(int p_port) const override;
  1588. virtual String get_input_port_name(int p_port) const override;
  1589. virtual int get_output_port_count() const override;
  1590. virtual PortType get_output_port_type(int p_port) const override;
  1591. virtual String get_output_port_name(int p_port) const override;
  1592. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1593. virtual String 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 = false) const override;
  1594. virtual bool is_show_prop_names() const override;
  1595. virtual bool is_use_prop_slots() const override;
  1596. void set_default_value_enabled(bool p_enabled);
  1597. bool is_default_value_enabled() const;
  1598. void set_default_value(int p_value);
  1599. int get_default_value() const;
  1600. bool is_qualifier_supported(Qualifier p_qual) const override;
  1601. bool is_convertible_to_constant() const override;
  1602. virtual Vector<StringName> get_editable_properties() const override;
  1603. VisualShaderNodeUIntParameter();
  1604. };
  1605. ///////////////////////////////////////
  1606. class VisualShaderNodeBooleanParameter : public VisualShaderNodeParameter {
  1607. GDCLASS(VisualShaderNodeBooleanParameter, VisualShaderNodeParameter);
  1608. private:
  1609. bool default_value_enabled = false;
  1610. bool default_value = false;
  1611. protected:
  1612. static void _bind_methods();
  1613. public:
  1614. virtual String get_caption() const override;
  1615. virtual int get_input_port_count() const override;
  1616. virtual PortType get_input_port_type(int p_port) const override;
  1617. virtual String get_input_port_name(int p_port) const override;
  1618. virtual int get_output_port_count() const override;
  1619. virtual PortType get_output_port_type(int p_port) const override;
  1620. virtual String get_output_port_name(int p_port) const override;
  1621. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1622. virtual String 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 = false) const override;
  1623. virtual bool is_show_prop_names() const override;
  1624. virtual bool is_use_prop_slots() const override;
  1625. void set_default_value_enabled(bool p_enabled);
  1626. bool is_default_value_enabled() const;
  1627. void set_default_value(bool p_value);
  1628. bool get_default_value() const;
  1629. bool is_qualifier_supported(Qualifier p_qual) const override;
  1630. bool is_convertible_to_constant() const override;
  1631. virtual Vector<StringName> get_editable_properties() const override;
  1632. VisualShaderNodeBooleanParameter();
  1633. };
  1634. ///////////////////////////////////////
  1635. class VisualShaderNodeColorParameter : public VisualShaderNodeParameter {
  1636. GDCLASS(VisualShaderNodeColorParameter, VisualShaderNodeParameter);
  1637. private:
  1638. bool default_value_enabled = false;
  1639. Color default_value = Color(1.0, 1.0, 1.0, 1.0);
  1640. protected:
  1641. static void _bind_methods();
  1642. public:
  1643. virtual String get_caption() const override;
  1644. virtual int get_input_port_count() const override;
  1645. virtual PortType get_input_port_type(int p_port) const override;
  1646. virtual String get_input_port_name(int p_port) const override;
  1647. virtual int get_output_port_count() const override;
  1648. virtual PortType get_output_port_type(int p_port) const override;
  1649. virtual String get_output_port_name(int p_port) const override;
  1650. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1651. virtual String 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 = false) const override;
  1652. virtual bool is_show_prop_names() const override;
  1653. void set_default_value_enabled(bool p_enabled);
  1654. bool is_default_value_enabled() const;
  1655. void set_default_value(const Color &p_value);
  1656. Color get_default_value() const;
  1657. bool is_qualifier_supported(Qualifier p_qual) const override;
  1658. bool is_convertible_to_constant() const override;
  1659. virtual Vector<StringName> get_editable_properties() const override;
  1660. VisualShaderNodeColorParameter();
  1661. };
  1662. ///////////////////////////////////////
  1663. class VisualShaderNodeVec2Parameter : public VisualShaderNodeParameter {
  1664. GDCLASS(VisualShaderNodeVec2Parameter, VisualShaderNodeParameter);
  1665. private:
  1666. bool default_value_enabled = false;
  1667. Vector2 default_value;
  1668. protected:
  1669. static void _bind_methods();
  1670. public:
  1671. virtual String get_caption() const override;
  1672. virtual int get_input_port_count() const override;
  1673. virtual PortType get_input_port_type(int p_port) const override;
  1674. virtual String get_input_port_name(int p_port) const override;
  1675. virtual int get_output_port_count() const override;
  1676. virtual PortType get_output_port_type(int p_port) const override;
  1677. virtual String get_output_port_name(int p_port) const override;
  1678. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1679. virtual String 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 = false) const override;
  1680. virtual bool is_show_prop_names() const override;
  1681. virtual bool is_use_prop_slots() const override;
  1682. void set_default_value_enabled(bool p_enabled);
  1683. bool is_default_value_enabled() const;
  1684. void set_default_value(const Vector2 &p_value);
  1685. Vector2 get_default_value() const;
  1686. bool is_qualifier_supported(Qualifier p_qual) const override;
  1687. bool is_convertible_to_constant() const override;
  1688. virtual Vector<StringName> get_editable_properties() const override;
  1689. VisualShaderNodeVec2Parameter();
  1690. };
  1691. ///////////////////////////////////////
  1692. class VisualShaderNodeVec3Parameter : public VisualShaderNodeParameter {
  1693. GDCLASS(VisualShaderNodeVec3Parameter, VisualShaderNodeParameter);
  1694. private:
  1695. bool default_value_enabled = false;
  1696. Vector3 default_value;
  1697. protected:
  1698. static void _bind_methods();
  1699. public:
  1700. virtual String get_caption() const override;
  1701. virtual int get_input_port_count() const override;
  1702. virtual PortType get_input_port_type(int p_port) const override;
  1703. virtual String get_input_port_name(int p_port) const override;
  1704. virtual int get_output_port_count() const override;
  1705. virtual PortType get_output_port_type(int p_port) const override;
  1706. virtual String get_output_port_name(int p_port) const override;
  1707. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1708. virtual String 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 = false) const override;
  1709. virtual bool is_show_prop_names() const override;
  1710. virtual bool is_use_prop_slots() const override;
  1711. void set_default_value_enabled(bool p_enabled);
  1712. bool is_default_value_enabled() const;
  1713. void set_default_value(const Vector3 &p_value);
  1714. Vector3 get_default_value() const;
  1715. bool is_qualifier_supported(Qualifier p_qual) const override;
  1716. bool is_convertible_to_constant() const override;
  1717. virtual Vector<StringName> get_editable_properties() const override;
  1718. VisualShaderNodeVec3Parameter();
  1719. };
  1720. ///////////////////////////////////////
  1721. class VisualShaderNodeVec4Parameter : public VisualShaderNodeParameter {
  1722. GDCLASS(VisualShaderNodeVec4Parameter, VisualShaderNodeParameter);
  1723. private:
  1724. bool default_value_enabled = false;
  1725. Vector4 default_value;
  1726. protected:
  1727. static void _bind_methods();
  1728. public:
  1729. virtual String get_caption() const override;
  1730. virtual int get_input_port_count() const override;
  1731. virtual PortType get_input_port_type(int p_port) const override;
  1732. virtual String get_input_port_name(int p_port) const override;
  1733. virtual int get_output_port_count() const override;
  1734. virtual PortType get_output_port_type(int p_port) const override;
  1735. virtual String get_output_port_name(int p_port) const override;
  1736. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1737. virtual String 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 = false) const override;
  1738. virtual bool is_show_prop_names() const override;
  1739. virtual bool is_use_prop_slots() const override;
  1740. void set_default_value_enabled(bool p_enabled);
  1741. bool is_default_value_enabled() const;
  1742. void set_default_value(const Vector4 &p_value);
  1743. Vector4 get_default_value() const;
  1744. bool is_qualifier_supported(Qualifier p_qual) const override;
  1745. bool is_convertible_to_constant() const override;
  1746. virtual Vector<StringName> get_editable_properties() const override;
  1747. VisualShaderNodeVec4Parameter();
  1748. };
  1749. ///////////////////////////////////////
  1750. class VisualShaderNodeTransformParameter : public VisualShaderNodeParameter {
  1751. GDCLASS(VisualShaderNodeTransformParameter, VisualShaderNodeParameter);
  1752. private:
  1753. bool default_value_enabled = false;
  1754. Transform3D default_value = Transform3D(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
  1755. protected:
  1756. static void _bind_methods();
  1757. public:
  1758. virtual String get_caption() const override;
  1759. virtual int get_input_port_count() const override;
  1760. virtual PortType get_input_port_type(int p_port) const override;
  1761. virtual String get_input_port_name(int p_port) const override;
  1762. virtual int get_output_port_count() const override;
  1763. virtual PortType get_output_port_type(int p_port) const override;
  1764. virtual String get_output_port_name(int p_port) const override;
  1765. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1766. virtual String 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 = false) const override;
  1767. virtual bool is_show_prop_names() const override;
  1768. virtual bool is_use_prop_slots() const override;
  1769. void set_default_value_enabled(bool p_enabled);
  1770. bool is_default_value_enabled() const;
  1771. void set_default_value(const Transform3D &p_value);
  1772. Transform3D get_default_value() const;
  1773. bool is_qualifier_supported(Qualifier p_qual) const override;
  1774. bool is_convertible_to_constant() const override;
  1775. virtual Vector<StringName> get_editable_properties() const override;
  1776. VisualShaderNodeTransformParameter();
  1777. };
  1778. ///////////////////////////////////////
  1779. class VisualShaderNodeTextureParameter : public VisualShaderNodeParameter {
  1780. GDCLASS(VisualShaderNodeTextureParameter, VisualShaderNodeParameter);
  1781. public:
  1782. enum TextureType {
  1783. TYPE_DATA,
  1784. TYPE_COLOR,
  1785. TYPE_NORMAL_MAP,
  1786. TYPE_ANISOTROPY,
  1787. TYPE_MAX,
  1788. };
  1789. enum ColorDefault {
  1790. COLOR_DEFAULT_WHITE,
  1791. COLOR_DEFAULT_BLACK,
  1792. COLOR_DEFAULT_TRANSPARENT,
  1793. COLOR_DEFAULT_MAX,
  1794. };
  1795. enum TextureFilter {
  1796. FILTER_DEFAULT,
  1797. FILTER_NEAREST,
  1798. FILTER_LINEAR,
  1799. FILTER_NEAREST_MIPMAP,
  1800. FILTER_LINEAR_MIPMAP,
  1801. FILTER_NEAREST_MIPMAP_ANISOTROPIC,
  1802. FILTER_LINEAR_MIPMAP_ANISOTROPIC,
  1803. FILTER_MAX,
  1804. };
  1805. enum TextureRepeat {
  1806. REPEAT_DEFAULT,
  1807. REPEAT_ENABLED,
  1808. REPEAT_DISABLED,
  1809. REPEAT_MAX,
  1810. };
  1811. enum TextureSource {
  1812. SOURCE_NONE,
  1813. SOURCE_SCREEN,
  1814. SOURCE_DEPTH,
  1815. SOURCE_NORMAL_ROUGHNESS,
  1816. SOURCE_MAX,
  1817. };
  1818. protected:
  1819. TextureType texture_type = TYPE_DATA;
  1820. ColorDefault color_default = COLOR_DEFAULT_WHITE;
  1821. TextureFilter texture_filter = FILTER_DEFAULT;
  1822. TextureRepeat texture_repeat = REPEAT_DEFAULT;
  1823. TextureSource texture_source = SOURCE_NONE;
  1824. protected:
  1825. static void _bind_methods();
  1826. public:
  1827. virtual int get_input_port_count() const override;
  1828. virtual PortType get_input_port_type(int p_port) const override;
  1829. virtual String get_input_port_name(int p_port) const override;
  1830. virtual int get_output_port_count() const override;
  1831. virtual PortType get_output_port_type(int p_port) const override;
  1832. virtual String 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 = false) const override;
  1833. virtual HashMap<StringName, String> get_editable_properties_names() const override;
  1834. virtual bool is_show_prop_names() const override;
  1835. virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const override;
  1836. Vector<StringName> get_editable_properties() const override;
  1837. void set_texture_type(TextureType p_type);
  1838. TextureType get_texture_type() const;
  1839. void set_color_default(ColorDefault p_default);
  1840. ColorDefault get_color_default() const;
  1841. void set_texture_filter(TextureFilter p_filter);
  1842. TextureFilter get_texture_filter() const;
  1843. void set_texture_repeat(TextureRepeat p_repeat);
  1844. TextureRepeat get_texture_repeat() const;
  1845. void set_texture_source(TextureSource p_source);
  1846. TextureSource get_texture_source() const;
  1847. bool is_qualifier_supported(Qualifier p_qual) const override;
  1848. bool is_convertible_to_constant() const override;
  1849. VisualShaderNodeTextureParameter();
  1850. };
  1851. VARIANT_ENUM_CAST(VisualShaderNodeTextureParameter::TextureType)
  1852. VARIANT_ENUM_CAST(VisualShaderNodeTextureParameter::ColorDefault)
  1853. VARIANT_ENUM_CAST(VisualShaderNodeTextureParameter::TextureFilter)
  1854. VARIANT_ENUM_CAST(VisualShaderNodeTextureParameter::TextureRepeat)
  1855. VARIANT_ENUM_CAST(VisualShaderNodeTextureParameter::TextureSource)
  1856. ///////////////////////////////////////
  1857. class VisualShaderNodeTexture2DParameter : public VisualShaderNodeTextureParameter {
  1858. GDCLASS(VisualShaderNodeTexture2DParameter, VisualShaderNodeTextureParameter);
  1859. public:
  1860. virtual String get_caption() const override;
  1861. virtual String get_output_port_name(int p_port) const override;
  1862. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1863. VisualShaderNodeTexture2DParameter();
  1864. };
  1865. ///////////////////////////////////////
  1866. class VisualShaderNodeTextureParameterTriplanar : public VisualShaderNodeTextureParameter {
  1867. GDCLASS(VisualShaderNodeTextureParameterTriplanar, VisualShaderNodeTextureParameter);
  1868. public:
  1869. virtual String get_caption() const override;
  1870. virtual int get_input_port_count() const override;
  1871. virtual PortType get_input_port_type(int p_port) const override;
  1872. virtual String get_input_port_name(int p_port) const override;
  1873. virtual int get_output_port_count() const override;
  1874. virtual PortType get_output_port_type(int p_port) const override;
  1875. virtual String get_output_port_name(int p_port) const override;
  1876. virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override;
  1877. virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override;
  1878. virtual String generate_global_per_func(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1879. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1880. virtual String 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 = false) const override;
  1881. VisualShaderNodeTextureParameterTriplanar();
  1882. };
  1883. ///////////////////////////////////////
  1884. class VisualShaderNodeTexture2DArrayParameter : public VisualShaderNodeTextureParameter {
  1885. GDCLASS(VisualShaderNodeTexture2DArrayParameter, VisualShaderNodeTextureParameter);
  1886. public:
  1887. virtual String get_caption() const override;
  1888. virtual String get_output_port_name(int p_port) const override;
  1889. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1890. VisualShaderNodeTexture2DArrayParameter();
  1891. };
  1892. ///////////////////////////////////////
  1893. class VisualShaderNodeTexture3DParameter : public VisualShaderNodeTextureParameter {
  1894. GDCLASS(VisualShaderNodeTexture3DParameter, VisualShaderNodeTextureParameter);
  1895. public:
  1896. virtual String get_caption() const override;
  1897. virtual String get_output_port_name(int p_port) const override;
  1898. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1899. VisualShaderNodeTexture3DParameter();
  1900. };
  1901. ///////////////////////////////////////
  1902. class VisualShaderNodeCubemapParameter : public VisualShaderNodeTextureParameter {
  1903. GDCLASS(VisualShaderNodeCubemapParameter, VisualShaderNodeTextureParameter);
  1904. public:
  1905. virtual String get_caption() const override;
  1906. virtual String get_output_port_name(int p_port) const override;
  1907. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  1908. VisualShaderNodeCubemapParameter();
  1909. };
  1910. ///////////////////////////////////////
  1911. /// IF
  1912. ///////////////////////////////////////
  1913. class VisualShaderNodeIf : public VisualShaderNode {
  1914. GDCLASS(VisualShaderNodeIf, VisualShaderNode);
  1915. public:
  1916. virtual String get_caption() const override;
  1917. virtual int get_input_port_count() const override;
  1918. virtual PortType get_input_port_type(int p_port) const override;
  1919. virtual String get_input_port_name(int p_port) const override;
  1920. virtual int get_output_port_count() const override;
  1921. virtual PortType get_output_port_type(int p_port) const override;
  1922. virtual String get_output_port_name(int p_port) const override;
  1923. virtual String 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 = false) const override;
  1924. virtual Category get_category() const override { return CATEGORY_CONDITIONAL; }
  1925. VisualShaderNodeIf();
  1926. };
  1927. ///////////////////////////////////////
  1928. /// SWITCH
  1929. ///////////////////////////////////////
  1930. class VisualShaderNodeSwitch : public VisualShaderNode {
  1931. GDCLASS(VisualShaderNodeSwitch, VisualShaderNode);
  1932. public:
  1933. enum OpType {
  1934. OP_TYPE_FLOAT,
  1935. OP_TYPE_INT,
  1936. OP_TYPE_UINT,
  1937. OP_TYPE_VECTOR_2D,
  1938. OP_TYPE_VECTOR_3D,
  1939. OP_TYPE_VECTOR_4D,
  1940. OP_TYPE_BOOLEAN,
  1941. OP_TYPE_TRANSFORM,
  1942. OP_TYPE_MAX,
  1943. };
  1944. protected:
  1945. OpType op_type = OP_TYPE_FLOAT;
  1946. static void _bind_methods();
  1947. public:
  1948. virtual String get_caption() const override;
  1949. virtual int get_input_port_count() const override;
  1950. virtual PortType get_input_port_type(int p_port) const override;
  1951. virtual String get_input_port_name(int p_port) const override;
  1952. virtual int get_output_port_count() const override;
  1953. virtual PortType get_output_port_type(int p_port) const override;
  1954. virtual String get_output_port_name(int p_port) const override;
  1955. void set_op_type(OpType p_op_type);
  1956. OpType get_op_type() const;
  1957. virtual Vector<StringName> get_editable_properties() const override;
  1958. virtual String 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 = false) const override;
  1959. virtual Category get_category() const override { return CATEGORY_CONDITIONAL; }
  1960. VisualShaderNodeSwitch();
  1961. };
  1962. VARIANT_ENUM_CAST(VisualShaderNodeSwitch::OpType)
  1963. ///////////////////////////////////////
  1964. /// FRESNEL
  1965. ///////////////////////////////////////
  1966. class VisualShaderNodeFresnel : public VisualShaderNode {
  1967. GDCLASS(VisualShaderNodeFresnel, VisualShaderNode);
  1968. public:
  1969. virtual String get_caption() const override;
  1970. virtual int get_input_port_count() const override;
  1971. virtual PortType get_input_port_type(int p_port) const override;
  1972. virtual String get_input_port_name(int p_port) const override;
  1973. virtual int get_output_port_count() const override;
  1974. virtual PortType get_output_port_type(int p_port) const override;
  1975. virtual String get_output_port_name(int p_port) const override;
  1976. virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override;
  1977. virtual bool is_generate_input_var(int p_port) const override;
  1978. virtual String 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 = false) const override;
  1979. virtual Category get_category() const override { return CATEGORY_UTILITY; }
  1980. VisualShaderNodeFresnel();
  1981. };
  1982. ///////////////////////////////////////
  1983. /// Is
  1984. ///////////////////////////////////////
  1985. class VisualShaderNodeIs : public VisualShaderNode {
  1986. GDCLASS(VisualShaderNodeIs, VisualShaderNode);
  1987. public:
  1988. enum Function {
  1989. FUNC_IS_INF,
  1990. FUNC_IS_NAN,
  1991. FUNC_MAX,
  1992. };
  1993. protected:
  1994. Function func = FUNC_IS_INF;
  1995. protected:
  1996. static void _bind_methods();
  1997. public:
  1998. virtual String get_caption() const override;
  1999. virtual int get_input_port_count() const override;
  2000. virtual PortType get_input_port_type(int p_port) const override;
  2001. virtual String get_input_port_name(int p_port) const override;
  2002. virtual int get_output_port_count() const override;
  2003. virtual PortType get_output_port_type(int p_port) const override;
  2004. virtual String get_output_port_name(int p_port) const override;
  2005. virtual String 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 = false) const override;
  2006. void set_function(Function p_func);
  2007. Function get_function() const;
  2008. virtual Vector<StringName> get_editable_properties() const override;
  2009. virtual Category get_category() const override { return CATEGORY_CONDITIONAL; }
  2010. VisualShaderNodeIs();
  2011. };
  2012. VARIANT_ENUM_CAST(VisualShaderNodeIs::Function)
  2013. ///////////////////////////////////////
  2014. /// Compare
  2015. ///////////////////////////////////////
  2016. class VisualShaderNodeCompare : public VisualShaderNode {
  2017. GDCLASS(VisualShaderNodeCompare, VisualShaderNode);
  2018. public:
  2019. enum ComparisonType {
  2020. CTYPE_SCALAR,
  2021. CTYPE_SCALAR_INT,
  2022. CTYPE_SCALAR_UINT,
  2023. CTYPE_VECTOR_2D,
  2024. CTYPE_VECTOR_3D,
  2025. CTYPE_VECTOR_4D,
  2026. CTYPE_BOOLEAN,
  2027. CTYPE_TRANSFORM,
  2028. CTYPE_MAX,
  2029. };
  2030. enum Function {
  2031. FUNC_EQUAL,
  2032. FUNC_NOT_EQUAL,
  2033. FUNC_GREATER_THAN,
  2034. FUNC_GREATER_THAN_EQUAL,
  2035. FUNC_LESS_THAN,
  2036. FUNC_LESS_THAN_EQUAL,
  2037. FUNC_MAX,
  2038. };
  2039. enum Condition {
  2040. COND_ALL,
  2041. COND_ANY,
  2042. COND_MAX,
  2043. };
  2044. protected:
  2045. ComparisonType comparison_type = CTYPE_SCALAR;
  2046. Function func = FUNC_EQUAL;
  2047. Condition condition = COND_ALL;
  2048. protected:
  2049. static void _bind_methods();
  2050. public:
  2051. virtual String get_caption() const override;
  2052. virtual int get_input_port_count() const override;
  2053. virtual PortType get_input_port_type(int p_port) const override;
  2054. virtual String get_input_port_name(int p_port) const override;
  2055. virtual int get_output_port_count() const override;
  2056. virtual PortType get_output_port_type(int p_port) const override;
  2057. virtual String get_output_port_name(int p_port) const override;
  2058. virtual String 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 = false) const override;
  2059. void set_comparison_type(ComparisonType p_type);
  2060. ComparisonType get_comparison_type() const;
  2061. void set_function(Function p_func);
  2062. Function get_function() const;
  2063. void set_condition(Condition p_cond);
  2064. Condition get_condition() const;
  2065. virtual Vector<StringName> get_editable_properties() const override;
  2066. virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const override;
  2067. virtual Category get_category() const override { return CATEGORY_CONDITIONAL; }
  2068. VisualShaderNodeCompare();
  2069. };
  2070. VARIANT_ENUM_CAST(VisualShaderNodeCompare::ComparisonType)
  2071. VARIANT_ENUM_CAST(VisualShaderNodeCompare::Function)
  2072. VARIANT_ENUM_CAST(VisualShaderNodeCompare::Condition)
  2073. class VisualShaderNodeMultiplyAdd : public VisualShaderNode {
  2074. GDCLASS(VisualShaderNodeMultiplyAdd, VisualShaderNode);
  2075. public:
  2076. enum OpType {
  2077. OP_TYPE_SCALAR,
  2078. OP_TYPE_VECTOR_2D,
  2079. OP_TYPE_VECTOR_3D,
  2080. OP_TYPE_VECTOR_4D,
  2081. OP_TYPE_MAX,
  2082. };
  2083. protected:
  2084. OpType op_type = OP_TYPE_SCALAR;
  2085. protected:
  2086. static void _bind_methods();
  2087. public:
  2088. virtual String get_caption() const override;
  2089. virtual int get_input_port_count() const override;
  2090. virtual PortType get_input_port_type(int p_port) const override;
  2091. virtual String get_input_port_name(int p_port) const override;
  2092. virtual int get_output_port_count() const override;
  2093. virtual PortType get_output_port_type(int p_port) const override;
  2094. virtual String get_output_port_name(int p_port) const override;
  2095. virtual String 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 = false) const override;
  2096. void set_op_type(OpType p_op_type);
  2097. OpType get_op_type() const;
  2098. virtual Vector<StringName> get_editable_properties() const override;
  2099. virtual Category get_category() const override {
  2100. if (op_type == OP_TYPE_SCALAR) {
  2101. return CATEGORY_SCALAR;
  2102. } else {
  2103. return CATEGORY_VECTOR;
  2104. }
  2105. }
  2106. VisualShaderNodeMultiplyAdd();
  2107. };
  2108. VARIANT_ENUM_CAST(VisualShaderNodeMultiplyAdd::OpType)
  2109. class VisualShaderNodeBillboard : public VisualShaderNode {
  2110. GDCLASS(VisualShaderNodeBillboard, VisualShaderNode);
  2111. public:
  2112. enum BillboardType {
  2113. BILLBOARD_TYPE_DISABLED,
  2114. BILLBOARD_TYPE_ENABLED,
  2115. BILLBOARD_TYPE_FIXED_Y,
  2116. BILLBOARD_TYPE_PARTICLES,
  2117. BILLBOARD_TYPE_MAX,
  2118. };
  2119. protected:
  2120. BillboardType billboard_type = BILLBOARD_TYPE_ENABLED;
  2121. bool keep_scale = false;
  2122. protected:
  2123. static void _bind_methods();
  2124. public:
  2125. virtual String get_caption() const override;
  2126. virtual int get_input_port_count() const override;
  2127. virtual PortType get_input_port_type(int p_port) const override;
  2128. virtual String get_input_port_name(int p_port) const override;
  2129. virtual int get_output_port_count() const override;
  2130. virtual PortType get_output_port_type(int p_port) const override;
  2131. virtual String get_output_port_name(int p_port) const override;
  2132. virtual String 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 = false) const override;
  2133. virtual bool is_show_prop_names() const override;
  2134. void set_billboard_type(BillboardType p_billboard_type);
  2135. BillboardType get_billboard_type() const;
  2136. void set_keep_scale_enabled(bool p_enabled);
  2137. bool is_keep_scale_enabled() const;
  2138. virtual Vector<StringName> get_editable_properties() const override;
  2139. virtual Category get_category() const override { return CATEGORY_UTILITY; }
  2140. VisualShaderNodeBillboard();
  2141. };
  2142. VARIANT_ENUM_CAST(VisualShaderNodeBillboard::BillboardType)
  2143. ///////////////////////////////////////
  2144. /// DistanceFade
  2145. ///////////////////////////////////////
  2146. class VisualShaderNodeDistanceFade : public VisualShaderNode {
  2147. GDCLASS(VisualShaderNodeDistanceFade, VisualShaderNode);
  2148. public:
  2149. virtual String get_caption() const override;
  2150. virtual int get_input_port_count() const override;
  2151. virtual PortType get_input_port_type(int p_port) const override;
  2152. virtual String get_input_port_name(int p_port) const override;
  2153. virtual int get_output_port_count() const override;
  2154. virtual PortType get_output_port_type(int p_port) const override;
  2155. virtual String get_output_port_name(int p_port) const override;
  2156. virtual bool has_output_port_preview(int p_port) const override;
  2157. virtual String 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 = false) const override;
  2158. virtual Category get_category() const override { return CATEGORY_UTILITY; }
  2159. VisualShaderNodeDistanceFade();
  2160. };
  2161. class VisualShaderNodeProximityFade : public VisualShaderNode {
  2162. GDCLASS(VisualShaderNodeProximityFade, VisualShaderNode);
  2163. public:
  2164. virtual String get_caption() const override;
  2165. virtual int get_input_port_count() const override;
  2166. virtual PortType get_input_port_type(int p_port) const override;
  2167. virtual String get_input_port_name(int p_port) const override;
  2168. virtual int get_output_port_count() const override;
  2169. virtual PortType get_output_port_type(int p_port) const override;
  2170. virtual String get_output_port_name(int p_port) const override;
  2171. virtual bool has_output_port_preview(int p_port) const override;
  2172. virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
  2173. virtual String 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 = false) const override;
  2174. virtual Category get_category() const override { return CATEGORY_UTILITY; }
  2175. VisualShaderNodeProximityFade();
  2176. };
  2177. class VisualShaderNodeRandomRange : public VisualShaderNode {
  2178. GDCLASS(VisualShaderNodeRandomRange, VisualShaderNode);
  2179. public:
  2180. virtual String get_caption() const override;
  2181. virtual int get_input_port_count() const override;
  2182. virtual PortType get_input_port_type(int p_port) const override;
  2183. virtual String get_input_port_name(int p_port) const override;
  2184. virtual int get_output_port_count() const override;
  2185. virtual PortType get_output_port_type(int p_port) const override;
  2186. virtual String get_output_port_name(int p_port) const override;
  2187. virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override;
  2188. virtual String 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 = false) const override;
  2189. virtual Category get_category() const override { return CATEGORY_UTILITY; }
  2190. VisualShaderNodeRandomRange();
  2191. };
  2192. ///////////////////////////////////////
  2193. /// Remap
  2194. ///////////////////////////////////////
  2195. class VisualShaderNodeRemap : public VisualShaderNode {
  2196. GDCLASS(VisualShaderNodeRemap, VisualShaderNode);
  2197. public:
  2198. enum OpType {
  2199. OP_TYPE_SCALAR,
  2200. OP_TYPE_VECTOR_2D,
  2201. OP_TYPE_VECTOR_2D_SCALAR,
  2202. OP_TYPE_VECTOR_3D,
  2203. OP_TYPE_VECTOR_3D_SCALAR,
  2204. OP_TYPE_VECTOR_4D,
  2205. OP_TYPE_VECTOR_4D_SCALAR,
  2206. OP_TYPE_MAX,
  2207. };
  2208. protected:
  2209. OpType op_type = OP_TYPE_SCALAR;
  2210. static void _bind_methods();
  2211. public:
  2212. virtual String get_caption() const override;
  2213. virtual int get_input_port_count() const override;
  2214. virtual PortType get_input_port_type(int p_port) const override;
  2215. virtual String get_input_port_name(int p_port) const override;
  2216. virtual int get_output_port_count() const override;
  2217. virtual PortType get_output_port_type(int p_port) const override;
  2218. virtual String get_output_port_name(int p_port) const override;
  2219. void set_op_type(OpType p_op_type);
  2220. OpType get_op_type() const;
  2221. virtual Vector<StringName> get_editable_properties() const override;
  2222. virtual String 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 = false) const override;
  2223. virtual Category get_category() const override {
  2224. if (op_type == OP_TYPE_SCALAR) {
  2225. return CATEGORY_SCALAR;
  2226. } else {
  2227. return CATEGORY_VECTOR;
  2228. }
  2229. }
  2230. VisualShaderNodeRemap();
  2231. };
  2232. VARIANT_ENUM_CAST(VisualShaderNodeRemap::OpType)
  2233. class VisualShaderNodeRotationByAxis : public VisualShaderNode {
  2234. GDCLASS(VisualShaderNodeRotationByAxis, VisualShaderNode);
  2235. public:
  2236. virtual String get_caption() const override;
  2237. virtual int get_input_port_count() const override;
  2238. virtual PortType get_input_port_type(int p_port) const override;
  2239. virtual String get_input_port_name(int p_port) const override;
  2240. virtual int get_output_port_count() const override;
  2241. virtual PortType get_output_port_type(int p_port) const override;
  2242. virtual String get_output_port_name(int p_port) const override;
  2243. virtual bool has_output_port_preview(int p_port) const override;
  2244. virtual String 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 = false) const override;
  2245. virtual Category get_category() const override { return CATEGORY_UTILITY; }
  2246. VisualShaderNodeRotationByAxis();
  2247. };
  2248. class VisualShaderNodeReroute : public VisualShaderNode {
  2249. GDCLASS(VisualShaderNodeReroute, VisualShaderNode);
  2250. PortType input_port_type = PORT_TYPE_SCALAR;
  2251. protected:
  2252. static void _bind_methods();
  2253. public:
  2254. virtual String get_caption() const override;
  2255. virtual int get_input_port_count() const override;
  2256. virtual PortType get_input_port_type(int p_port) const override;
  2257. virtual String get_input_port_name(int p_port) const override;
  2258. virtual int get_output_port_count() const override;
  2259. virtual PortType get_output_port_type(int p_port) const override;
  2260. virtual String get_output_port_name(int p_port) const override;
  2261. virtual bool has_output_port_preview(int p_port) const override { return false; }
  2262. virtual bool is_output_port_expandable(int p_port) const override { return false; }
  2263. virtual String 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 = false) const override;
  2264. virtual Category get_category() const override { return CATEGORY_SPECIAL; }
  2265. void _set_port_type(PortType p_type);
  2266. PortType get_port_type() const { return input_port_type; }
  2267. VisualShaderNodeReroute();
  2268. };
  2269. #endif // VISUAL_SHADER_NODES_H