material.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. /*************************************************************************/
  2. /* material.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 MATERIAL_H
  31. #define MATERIAL_H
  32. #include "core/io/resource.h"
  33. #include "core/templates/self_list.h"
  34. #include "scene/resources/shader.h"
  35. #include "scene/resources/texture.h"
  36. #include "servers/rendering_server.h"
  37. class Material : public Resource {
  38. GDCLASS(Material, Resource);
  39. RES_BASE_EXTENSION("material")
  40. OBJ_SAVE_TYPE(Material);
  41. RID material;
  42. Ref<Material> next_pass;
  43. int render_priority;
  44. void inspect_native_shader_code();
  45. protected:
  46. _FORCE_INLINE_ RID _get_material() const { return material; }
  47. static void _bind_methods();
  48. virtual bool _can_do_next_pass() const;
  49. virtual bool _can_use_render_priority() const;
  50. void _validate_property(PropertyInfo &property) const override;
  51. GDVIRTUAL0RC(RID, _get_shader_rid)
  52. GDVIRTUAL0RC(Shader::Mode, _get_shader_mode)
  53. GDVIRTUAL0RC(bool, _can_do_next_pass)
  54. GDVIRTUAL0RC(bool, _can_use_render_priority)
  55. public:
  56. enum {
  57. RENDER_PRIORITY_MAX = RS::MATERIAL_RENDER_PRIORITY_MAX,
  58. RENDER_PRIORITY_MIN = RS::MATERIAL_RENDER_PRIORITY_MIN,
  59. };
  60. void set_next_pass(const Ref<Material> &p_pass);
  61. Ref<Material> get_next_pass() const;
  62. void set_render_priority(int p_priority);
  63. int get_render_priority() const;
  64. virtual RID get_rid() const override;
  65. virtual RID get_shader_rid() const;
  66. virtual Shader::Mode get_shader_mode() const;
  67. Material();
  68. virtual ~Material();
  69. };
  70. class ShaderMaterial : public Material {
  71. GDCLASS(ShaderMaterial, Material);
  72. Ref<Shader> shader;
  73. Map<StringName, Variant> param_cache;
  74. protected:
  75. bool _set(const StringName &p_name, const Variant &p_value);
  76. bool _get(const StringName &p_name, Variant &r_ret) const;
  77. void _get_property_list(List<PropertyInfo> *p_list) const;
  78. bool property_can_revert(const String &p_name);
  79. Variant property_get_revert(const String &p_name);
  80. static void _bind_methods();
  81. void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
  82. virtual bool _can_do_next_pass() const override;
  83. virtual bool _can_use_render_priority() const override;
  84. void _shader_changed();
  85. public:
  86. void set_shader(const Ref<Shader> &p_shader);
  87. Ref<Shader> get_shader() const;
  88. void set_shader_param(const StringName &p_param, const Variant &p_value);
  89. Variant get_shader_param(const StringName &p_param) const;
  90. virtual Shader::Mode get_shader_mode() const override;
  91. virtual RID get_shader_rid() const override;
  92. ShaderMaterial();
  93. ~ShaderMaterial();
  94. };
  95. class StandardMaterial3D;
  96. class BaseMaterial3D : public Material {
  97. GDCLASS(BaseMaterial3D, Material);
  98. public:
  99. enum TextureParam {
  100. TEXTURE_ALBEDO,
  101. TEXTURE_METALLIC,
  102. TEXTURE_ROUGHNESS,
  103. TEXTURE_EMISSION,
  104. TEXTURE_NORMAL,
  105. TEXTURE_RIM,
  106. TEXTURE_CLEARCOAT,
  107. TEXTURE_FLOWMAP,
  108. TEXTURE_AMBIENT_OCCLUSION,
  109. TEXTURE_HEIGHTMAP,
  110. TEXTURE_SUBSURFACE_SCATTERING,
  111. TEXTURE_SUBSURFACE_TRANSMITTANCE,
  112. TEXTURE_BACKLIGHT,
  113. TEXTURE_REFRACTION,
  114. TEXTURE_DETAIL_MASK,
  115. TEXTURE_DETAIL_ALBEDO,
  116. TEXTURE_DETAIL_NORMAL,
  117. TEXTURE_ORM,
  118. TEXTURE_MAX
  119. };
  120. enum TextureFilter {
  121. TEXTURE_FILTER_NEAREST,
  122. TEXTURE_FILTER_LINEAR,
  123. TEXTURE_FILTER_NEAREST_WITH_MIPMAPS,
  124. TEXTURE_FILTER_LINEAR_WITH_MIPMAPS,
  125. TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC,
  126. TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC,
  127. TEXTURE_FILTER_MAX
  128. };
  129. enum DetailUV {
  130. DETAIL_UV_1,
  131. DETAIL_UV_2,
  132. DETAIL_UV_MAX
  133. };
  134. enum Transparency {
  135. TRANSPARENCY_DISABLED,
  136. TRANSPARENCY_ALPHA,
  137. TRANSPARENCY_ALPHA_SCISSOR,
  138. TRANSPARENCY_ALPHA_HASH,
  139. TRANSPARENCY_ALPHA_DEPTH_PRE_PASS,
  140. TRANSPARENCY_MAX,
  141. };
  142. enum AlphaAntiAliasing {
  143. ALPHA_ANTIALIASING_OFF,
  144. ALPHA_ANTIALIASING_ALPHA_TO_COVERAGE,
  145. ALPHA_ANTIALIASING_ALPHA_TO_COVERAGE_AND_TO_ONE,
  146. ALPHA_ANTIALIASING_MAX
  147. };
  148. enum ShadingMode {
  149. SHADING_MODE_UNSHADED,
  150. SHADING_MODE_PER_PIXEL,
  151. SHADING_MODE_PER_VERTEX,
  152. SHADING_MODE_MAX
  153. };
  154. enum Feature {
  155. FEATURE_EMISSION,
  156. FEATURE_NORMAL_MAPPING,
  157. FEATURE_RIM,
  158. FEATURE_CLEARCOAT,
  159. FEATURE_ANISOTROPY,
  160. FEATURE_AMBIENT_OCCLUSION,
  161. FEATURE_HEIGHT_MAPPING,
  162. FEATURE_SUBSURFACE_SCATTERING,
  163. FEATURE_SUBSURFACE_TRANSMITTANCE,
  164. FEATURE_BACKLIGHT,
  165. FEATURE_REFRACTION,
  166. FEATURE_DETAIL,
  167. FEATURE_MAX
  168. };
  169. enum BlendMode {
  170. BLEND_MODE_MIX,
  171. BLEND_MODE_ADD,
  172. BLEND_MODE_SUB,
  173. BLEND_MODE_MUL,
  174. BLEND_MODE_MAX
  175. };
  176. enum DepthDrawMode {
  177. DEPTH_DRAW_OPAQUE_ONLY,
  178. DEPTH_DRAW_ALWAYS,
  179. DEPTH_DRAW_DISABLED,
  180. DEPTH_DRAW_MAX
  181. };
  182. enum CullMode {
  183. CULL_BACK,
  184. CULL_FRONT,
  185. CULL_DISABLED,
  186. CULL_MAX
  187. };
  188. enum Flags {
  189. FLAG_DISABLE_DEPTH_TEST,
  190. FLAG_ALBEDO_FROM_VERTEX_COLOR,
  191. FLAG_SRGB_VERTEX_COLOR,
  192. FLAG_USE_POINT_SIZE,
  193. FLAG_FIXED_SIZE,
  194. FLAG_BILLBOARD_KEEP_SCALE,
  195. FLAG_UV1_USE_TRIPLANAR,
  196. FLAG_UV2_USE_TRIPLANAR,
  197. FLAG_UV1_USE_WORLD_TRIPLANAR,
  198. FLAG_UV2_USE_WORLD_TRIPLANAR,
  199. FLAG_AO_ON_UV2,
  200. FLAG_EMISSION_ON_UV2,
  201. FLAG_ALBEDO_TEXTURE_FORCE_SRGB,
  202. FLAG_DONT_RECEIVE_SHADOWS,
  203. FLAG_DISABLE_AMBIENT_LIGHT,
  204. FLAG_USE_SHADOW_TO_OPACITY,
  205. FLAG_USE_TEXTURE_REPEAT,
  206. FLAG_INVERT_HEIGHTMAP,
  207. FLAG_SUBSURFACE_MODE_SKIN,
  208. FLAG_PARTICLE_TRAILS_MODE,
  209. FLAG_ALBEDO_TEXTURE_MSDF,
  210. FLAG_MAX
  211. };
  212. enum DiffuseMode {
  213. DIFFUSE_BURLEY,
  214. DIFFUSE_LAMBERT,
  215. DIFFUSE_LAMBERT_WRAP,
  216. DIFFUSE_TOON,
  217. DIFFUSE_MAX
  218. };
  219. enum SpecularMode {
  220. SPECULAR_SCHLICK_GGX,
  221. SPECULAR_TOON,
  222. SPECULAR_DISABLED,
  223. SPECULAR_MAX
  224. };
  225. enum BillboardMode {
  226. BILLBOARD_DISABLED,
  227. BILLBOARD_ENABLED,
  228. BILLBOARD_FIXED_Y,
  229. BILLBOARD_PARTICLES,
  230. BILLBOARD_MAX
  231. };
  232. enum TextureChannel {
  233. TEXTURE_CHANNEL_RED,
  234. TEXTURE_CHANNEL_GREEN,
  235. TEXTURE_CHANNEL_BLUE,
  236. TEXTURE_CHANNEL_ALPHA,
  237. TEXTURE_CHANNEL_GRAYSCALE,
  238. TEXTURE_CHANNEL_MAX
  239. };
  240. enum EmissionOperator {
  241. EMISSION_OP_ADD,
  242. EMISSION_OP_MULTIPLY,
  243. EMISSION_OP_MAX
  244. };
  245. enum DistanceFadeMode {
  246. DISTANCE_FADE_DISABLED,
  247. DISTANCE_FADE_PIXEL_ALPHA,
  248. DISTANCE_FADE_PIXEL_DITHER,
  249. DISTANCE_FADE_OBJECT_DITHER,
  250. DISTANCE_FADE_MAX
  251. };
  252. private:
  253. struct MaterialKey {
  254. // enum values
  255. uint64_t texture_filter : get_num_bits(TEXTURE_FILTER_MAX - 1);
  256. uint64_t detail_uv : get_num_bits(DETAIL_UV_MAX - 1);
  257. uint64_t transparency : get_num_bits(TRANSPARENCY_MAX - 1);
  258. uint64_t alpha_antialiasing_mode : get_num_bits(ALPHA_ANTIALIASING_MAX - 1);
  259. uint64_t shading_mode : get_num_bits(SHADING_MODE_MAX - 1);
  260. uint64_t blend_mode : get_num_bits(BLEND_MODE_MAX - 1);
  261. uint64_t depth_draw_mode : get_num_bits(DEPTH_DRAW_MAX - 1);
  262. uint64_t cull_mode : get_num_bits(CULL_MAX - 1);
  263. uint64_t diffuse_mode : get_num_bits(DIFFUSE_MAX - 1);
  264. uint64_t specular_mode : get_num_bits(SPECULAR_MAX - 1);
  265. uint64_t billboard_mode : get_num_bits(BILLBOARD_MAX - 1);
  266. uint64_t detail_blend_mode : get_num_bits(BLEND_MODE_MAX - 1);
  267. uint64_t roughness_channel : get_num_bits(TEXTURE_CHANNEL_MAX - 1);
  268. uint64_t emission_op : get_num_bits(EMISSION_OP_MAX - 1);
  269. uint64_t distance_fade : get_num_bits(DISTANCE_FADE_MAX - 1);
  270. // booleans
  271. uint64_t deep_parallax : 1;
  272. uint64_t grow : 1;
  273. uint64_t proximity_fade : 1;
  274. // flag bitfield
  275. uint32_t feature_mask;
  276. uint32_t flags;
  277. MaterialKey() {
  278. memset(this, 0, sizeof(MaterialKey));
  279. }
  280. bool operator==(const MaterialKey &p_key) const {
  281. return memcmp(this, &p_key, sizeof(MaterialKey)) == 0;
  282. }
  283. bool operator<(const MaterialKey &p_key) const {
  284. return memcmp(this, &p_key, sizeof(MaterialKey)) < 0;
  285. }
  286. };
  287. struct ShaderData {
  288. RID shader;
  289. int users = 0;
  290. };
  291. static Map<MaterialKey, ShaderData> shader_map;
  292. MaterialKey current_key;
  293. _FORCE_INLINE_ MaterialKey _compute_key() const {
  294. MaterialKey mk;
  295. mk.detail_uv = detail_uv;
  296. mk.blend_mode = blend_mode;
  297. mk.depth_draw_mode = depth_draw_mode;
  298. mk.cull_mode = cull_mode;
  299. mk.texture_filter = texture_filter;
  300. mk.transparency = transparency;
  301. mk.shading_mode = shading_mode;
  302. mk.roughness_channel = roughness_texture_channel;
  303. mk.detail_blend_mode = detail_blend_mode;
  304. mk.diffuse_mode = diffuse_mode;
  305. mk.specular_mode = specular_mode;
  306. mk.billboard_mode = billboard_mode;
  307. mk.deep_parallax = deep_parallax;
  308. mk.grow = grow_enabled;
  309. mk.proximity_fade = proximity_fade_enabled;
  310. mk.distance_fade = distance_fade;
  311. mk.emission_op = emission_op;
  312. mk.alpha_antialiasing_mode = alpha_antialiasing_mode;
  313. for (int i = 0; i < FEATURE_MAX; i++) {
  314. if (features[i]) {
  315. mk.feature_mask |= ((uint64_t)1 << i);
  316. }
  317. }
  318. for (int i = 0; i < FLAG_MAX; i++) {
  319. if (flags[i]) {
  320. mk.flags |= ((uint64_t)1 << i);
  321. }
  322. }
  323. return mk;
  324. }
  325. struct ShaderNames {
  326. StringName albedo;
  327. StringName specular;
  328. StringName metallic;
  329. StringName roughness;
  330. StringName emission;
  331. StringName emission_energy;
  332. StringName normal_scale;
  333. StringName rim;
  334. StringName rim_tint;
  335. StringName clearcoat;
  336. StringName clearcoat_roughness;
  337. StringName anisotropy;
  338. StringName heightmap_scale;
  339. StringName subsurface_scattering_strength;
  340. StringName transmittance_color;
  341. StringName transmittance_depth;
  342. StringName transmittance_boost;
  343. StringName backlight;
  344. StringName refraction;
  345. StringName point_size;
  346. StringName uv1_scale;
  347. StringName uv1_offset;
  348. StringName uv2_scale;
  349. StringName uv2_offset;
  350. StringName particles_anim_h_frames;
  351. StringName particles_anim_v_frames;
  352. StringName particles_anim_loop;
  353. StringName heightmap_min_layers;
  354. StringName heightmap_max_layers;
  355. StringName heightmap_flip;
  356. StringName uv1_blend_sharpness;
  357. StringName uv2_blend_sharpness;
  358. StringName grow;
  359. StringName proximity_fade_distance;
  360. StringName msdf_pixel_range;
  361. StringName msdf_outline_size;
  362. StringName distance_fade_min;
  363. StringName distance_fade_max;
  364. StringName ao_light_affect;
  365. StringName metallic_texture_channel;
  366. StringName ao_texture_channel;
  367. StringName clearcoat_texture_channel;
  368. StringName rim_texture_channel;
  369. StringName heightmap_texture_channel;
  370. StringName refraction_texture_channel;
  371. StringName texture_names[TEXTURE_MAX];
  372. StringName alpha_scissor_threshold;
  373. StringName alpha_hash_scale;
  374. StringName alpha_antialiasing_edge;
  375. StringName albedo_texture_size;
  376. };
  377. static Mutex material_mutex;
  378. static SelfList<BaseMaterial3D>::List *dirty_materials;
  379. static ShaderNames *shader_names;
  380. SelfList<BaseMaterial3D> element;
  381. void _update_shader();
  382. _FORCE_INLINE_ void _queue_shader_change();
  383. _FORCE_INLINE_ bool _is_shader_dirty() const;
  384. bool is_initialized = false;
  385. bool orm;
  386. Color albedo;
  387. float specular;
  388. float metallic;
  389. float roughness;
  390. Color emission;
  391. float emission_energy;
  392. float normal_scale;
  393. float rim;
  394. float rim_tint;
  395. float clearcoat;
  396. float clearcoat_roughness;
  397. float anisotropy;
  398. float heightmap_scale;
  399. float subsurface_scattering_strength;
  400. float transmittance_amount;
  401. Color transmittance_color;
  402. float transmittance_depth;
  403. float transmittance_boost;
  404. Color backlight;
  405. float refraction;
  406. float point_size;
  407. float alpha_scissor_threshold;
  408. float alpha_hash_scale;
  409. float alpha_antialiasing_edge;
  410. bool grow_enabled = false;
  411. float ao_light_affect;
  412. float grow;
  413. int particles_anim_h_frames;
  414. int particles_anim_v_frames;
  415. bool particles_anim_loop;
  416. Transparency transparency = TRANSPARENCY_DISABLED;
  417. ShadingMode shading_mode = SHADING_MODE_PER_PIXEL;
  418. TextureFilter texture_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS;
  419. Vector3 uv1_scale;
  420. Vector3 uv1_offset;
  421. float uv1_triplanar_sharpness;
  422. Vector3 uv2_scale;
  423. Vector3 uv2_offset;
  424. float uv2_triplanar_sharpness;
  425. DetailUV detail_uv = DETAIL_UV_1;
  426. bool deep_parallax = false;
  427. int deep_parallax_min_layers;
  428. int deep_parallax_max_layers;
  429. bool heightmap_parallax_flip_tangent = false;
  430. bool heightmap_parallax_flip_binormal = false;
  431. bool proximity_fade_enabled = false;
  432. float proximity_fade_distance;
  433. float msdf_pixel_range = 4.f;
  434. float msdf_outline_size = 0.f;
  435. DistanceFadeMode distance_fade = DISTANCE_FADE_DISABLED;
  436. float distance_fade_max_distance;
  437. float distance_fade_min_distance;
  438. BlendMode blend_mode = BLEND_MODE_MIX;
  439. BlendMode detail_blend_mode = BLEND_MODE_MIX;
  440. DepthDrawMode depth_draw_mode = DEPTH_DRAW_OPAQUE_ONLY;
  441. CullMode cull_mode = CULL_BACK;
  442. bool flags[FLAG_MAX] = {};
  443. SpecularMode specular_mode = SPECULAR_SCHLICK_GGX;
  444. DiffuseMode diffuse_mode = DIFFUSE_BURLEY;
  445. BillboardMode billboard_mode;
  446. EmissionOperator emission_op = EMISSION_OP_ADD;
  447. TextureChannel metallic_texture_channel;
  448. TextureChannel roughness_texture_channel;
  449. TextureChannel ao_texture_channel;
  450. TextureChannel refraction_texture_channel;
  451. AlphaAntiAliasing alpha_antialiasing_mode = ALPHA_ANTIALIASING_OFF;
  452. bool features[FEATURE_MAX] = {};
  453. Ref<Texture2D> textures[TEXTURE_MAX];
  454. _FORCE_INLINE_ void _validate_feature(const String &text, Feature feature, PropertyInfo &property) const;
  455. static HashMap<uint64_t, Ref<StandardMaterial3D>> materials_for_2d; //used by Sprite3D, Label3D and other stuff
  456. void _validate_high_end(const String &text, PropertyInfo &property) const;
  457. protected:
  458. static void _bind_methods();
  459. void _validate_property(PropertyInfo &property) const override;
  460. virtual bool _can_do_next_pass() const override { return true; }
  461. virtual bool _can_use_render_priority() const override { return true; }
  462. public:
  463. void set_albedo(const Color &p_albedo);
  464. Color get_albedo() const;
  465. void set_specular(float p_specular);
  466. float get_specular() const;
  467. void set_metallic(float p_metallic);
  468. float get_metallic() const;
  469. void set_roughness(float p_roughness);
  470. float get_roughness() const;
  471. void set_emission(const Color &p_emission);
  472. Color get_emission() const;
  473. void set_emission_energy(float p_emission_energy);
  474. float get_emission_energy() const;
  475. void set_normal_scale(float p_normal_scale);
  476. float get_normal_scale() const;
  477. void set_rim(float p_rim);
  478. float get_rim() const;
  479. void set_rim_tint(float p_rim_tint);
  480. float get_rim_tint() const;
  481. void set_ao_light_affect(float p_ao_light_affect);
  482. float get_ao_light_affect() const;
  483. void set_clearcoat(float p_clearcoat);
  484. float get_clearcoat() const;
  485. void set_clearcoat_roughness(float p_clearcoat_roughness);
  486. float get_clearcoat_roughness() const;
  487. void set_anisotropy(float p_anisotropy);
  488. float get_anisotropy() const;
  489. void set_heightmap_scale(float p_heightmap_scale);
  490. float get_heightmap_scale() const;
  491. void set_heightmap_deep_parallax(bool p_enable);
  492. bool is_heightmap_deep_parallax_enabled() const;
  493. void set_heightmap_deep_parallax_min_layers(int p_layer);
  494. int get_heightmap_deep_parallax_min_layers() const;
  495. void set_heightmap_deep_parallax_max_layers(int p_layer);
  496. int get_heightmap_deep_parallax_max_layers() const;
  497. void set_heightmap_deep_parallax_flip_tangent(bool p_flip);
  498. bool get_heightmap_deep_parallax_flip_tangent() const;
  499. void set_heightmap_deep_parallax_flip_binormal(bool p_flip);
  500. bool get_heightmap_deep_parallax_flip_binormal() const;
  501. void set_subsurface_scattering_strength(float p_subsurface_scattering_strength);
  502. float get_subsurface_scattering_strength() const;
  503. void set_transmittance_color(const Color &p_color);
  504. Color get_transmittance_color() const;
  505. void set_transmittance_depth(float p_depth);
  506. float get_transmittance_depth() const;
  507. void set_transmittance_boost(float p_boost);
  508. float get_transmittance_boost() const;
  509. void set_backlight(const Color &p_backlight);
  510. Color get_backlight() const;
  511. void set_refraction(float p_refraction);
  512. float get_refraction() const;
  513. void set_point_size(float p_point_size);
  514. float get_point_size() const;
  515. void set_transparency(Transparency p_transparency);
  516. Transparency get_transparency() const;
  517. void set_alpha_antialiasing(AlphaAntiAliasing p_alpha_aa);
  518. AlphaAntiAliasing get_alpha_antialiasing() const;
  519. void set_alpha_antialiasing_edge(float p_edge);
  520. float get_alpha_antialiasing_edge() const;
  521. void set_shading_mode(ShadingMode p_shading_mode);
  522. ShadingMode get_shading_mode() const;
  523. void set_detail_uv(DetailUV p_detail_uv);
  524. DetailUV get_detail_uv() const;
  525. void set_blend_mode(BlendMode p_mode);
  526. BlendMode get_blend_mode() const;
  527. void set_detail_blend_mode(BlendMode p_mode);
  528. BlendMode get_detail_blend_mode() const;
  529. void set_depth_draw_mode(DepthDrawMode p_mode);
  530. DepthDrawMode get_depth_draw_mode() const;
  531. void set_cull_mode(CullMode p_mode);
  532. CullMode get_cull_mode() const;
  533. void set_diffuse_mode(DiffuseMode p_mode);
  534. DiffuseMode get_diffuse_mode() const;
  535. void set_specular_mode(SpecularMode p_mode);
  536. SpecularMode get_specular_mode() const;
  537. void set_flag(Flags p_flag, bool p_enabled);
  538. bool get_flag(Flags p_flag) const;
  539. void set_texture(TextureParam p_param, const Ref<Texture2D> &p_texture);
  540. Ref<Texture2D> get_texture(TextureParam p_param) const;
  541. // Used only for shader material conversion
  542. Ref<Texture2D> get_texture_by_name(StringName p_name) const;
  543. void set_texture_filter(TextureFilter p_filter);
  544. TextureFilter get_texture_filter() const;
  545. void set_feature(Feature p_feature, bool p_enabled);
  546. bool get_feature(Feature p_feature) const;
  547. void set_uv1_scale(const Vector3 &p_scale);
  548. Vector3 get_uv1_scale() const;
  549. void set_uv1_offset(const Vector3 &p_offset);
  550. Vector3 get_uv1_offset() const;
  551. void set_uv1_triplanar_blend_sharpness(float p_sharpness);
  552. float get_uv1_triplanar_blend_sharpness() const;
  553. void set_uv2_scale(const Vector3 &p_scale);
  554. Vector3 get_uv2_scale() const;
  555. void set_uv2_offset(const Vector3 &p_offset);
  556. Vector3 get_uv2_offset() const;
  557. void set_uv2_triplanar_blend_sharpness(float p_sharpness);
  558. float get_uv2_triplanar_blend_sharpness() const;
  559. void set_billboard_mode(BillboardMode p_mode);
  560. BillboardMode get_billboard_mode() const;
  561. void set_particles_anim_h_frames(int p_frames);
  562. int get_particles_anim_h_frames() const;
  563. void set_particles_anim_v_frames(int p_frames);
  564. int get_particles_anim_v_frames() const;
  565. void set_particles_anim_loop(bool p_loop);
  566. bool get_particles_anim_loop() const;
  567. void set_grow_enabled(bool p_enable);
  568. bool is_grow_enabled() const;
  569. void set_grow(float p_grow);
  570. float get_grow() const;
  571. void set_alpha_scissor_threshold(float p_threshold);
  572. float get_alpha_scissor_threshold() const;
  573. void set_alpha_hash_scale(float p_scale);
  574. float get_alpha_hash_scale() const;
  575. void set_on_top_of_alpha();
  576. void set_proximity_fade(bool p_enable);
  577. bool is_proximity_fade_enabled() const;
  578. void set_proximity_fade_distance(float p_distance);
  579. float get_proximity_fade_distance() const;
  580. void set_msdf_pixel_range(float p_range);
  581. float get_msdf_pixel_range() const;
  582. void set_msdf_outline_size(float p_size);
  583. float get_msdf_outline_size() const;
  584. void set_distance_fade(DistanceFadeMode p_mode);
  585. DistanceFadeMode get_distance_fade() const;
  586. void set_distance_fade_max_distance(float p_distance);
  587. float get_distance_fade_max_distance() const;
  588. void set_distance_fade_min_distance(float p_distance);
  589. float get_distance_fade_min_distance() const;
  590. void set_emission_operator(EmissionOperator p_op);
  591. EmissionOperator get_emission_operator() const;
  592. void set_metallic_texture_channel(TextureChannel p_channel);
  593. TextureChannel get_metallic_texture_channel() const;
  594. void set_roughness_texture_channel(TextureChannel p_channel);
  595. TextureChannel get_roughness_texture_channel() const;
  596. void set_ao_texture_channel(TextureChannel p_channel);
  597. TextureChannel get_ao_texture_channel() const;
  598. void set_refraction_texture_channel(TextureChannel p_channel);
  599. TextureChannel get_refraction_texture_channel() const;
  600. static void init_shaders();
  601. static void finish_shaders();
  602. static void flush_changes();
  603. static Ref<Material> get_material_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard = false, bool p_billboard_y = false, bool p_msdf = false, bool p_no_depth = false, bool p_fixed_size = false, TextureFilter p_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS, RID *r_shader_rid = nullptr);
  604. virtual RID get_shader_rid() const override;
  605. virtual Shader::Mode get_shader_mode() const override;
  606. BaseMaterial3D(bool p_orm);
  607. virtual ~BaseMaterial3D();
  608. };
  609. VARIANT_ENUM_CAST(BaseMaterial3D::TextureParam)
  610. VARIANT_ENUM_CAST(BaseMaterial3D::TextureFilter)
  611. VARIANT_ENUM_CAST(BaseMaterial3D::ShadingMode)
  612. VARIANT_ENUM_CAST(BaseMaterial3D::Transparency)
  613. VARIANT_ENUM_CAST(BaseMaterial3D::AlphaAntiAliasing)
  614. VARIANT_ENUM_CAST(BaseMaterial3D::DetailUV)
  615. VARIANT_ENUM_CAST(BaseMaterial3D::Feature)
  616. VARIANT_ENUM_CAST(BaseMaterial3D::BlendMode)
  617. VARIANT_ENUM_CAST(BaseMaterial3D::DepthDrawMode)
  618. VARIANT_ENUM_CAST(BaseMaterial3D::CullMode)
  619. VARIANT_ENUM_CAST(BaseMaterial3D::Flags)
  620. VARIANT_ENUM_CAST(BaseMaterial3D::DiffuseMode)
  621. VARIANT_ENUM_CAST(BaseMaterial3D::SpecularMode)
  622. VARIANT_ENUM_CAST(BaseMaterial3D::BillboardMode)
  623. VARIANT_ENUM_CAST(BaseMaterial3D::TextureChannel)
  624. VARIANT_ENUM_CAST(BaseMaterial3D::EmissionOperator)
  625. VARIANT_ENUM_CAST(BaseMaterial3D::DistanceFadeMode)
  626. class StandardMaterial3D : public BaseMaterial3D {
  627. GDCLASS(StandardMaterial3D, BaseMaterial3D)
  628. protected:
  629. #ifndef DISABLE_DEPRECATED
  630. // Kept for compatibility from 3.x to 4.0.
  631. bool _set(const StringName &p_name, const Variant &p_value);
  632. #endif
  633. public:
  634. StandardMaterial3D() :
  635. BaseMaterial3D(false) {}
  636. };
  637. class ORMMaterial3D : public BaseMaterial3D {
  638. GDCLASS(ORMMaterial3D, BaseMaterial3D)
  639. public:
  640. ORMMaterial3D() :
  641. BaseMaterial3D(true) {}
  642. };
  643. class PlaceholderMaterial : public Material {
  644. GDCLASS(PlaceholderMaterial, Material)
  645. public:
  646. virtual RID get_shader_rid() const override { return RID(); }
  647. virtual Shader::Mode get_shader_mode() const override { return Shader::MODE_CANVAS_ITEM; }
  648. };
  649. //////////////////////
  650. #endif