material.h 24 KB

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