2
0

SMaterial.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "SColor.h"
  6. #include "matrix4.h"
  7. #include "irrArray.h"
  8. #include "irrMath.h"
  9. #include "EMaterialTypes.h"
  10. #include "EMaterialProps.h"
  11. #include "SMaterialLayer.h"
  12. #include "IrrCompileConfig.h" // for IRRLICHT_API
  13. namespace irr
  14. {
  15. namespace video
  16. {
  17. class ITexture;
  18. //! Flag for MaterialTypeParam (in combination with EMT_ONETEXTURE_BLEND) or for BlendFactor
  19. //! BlendFunc = source * sourceFactor + dest * destFactor
  20. enum E_BLEND_FACTOR
  21. {
  22. EBF_ZERO = 0, //!< src & dest (0, 0, 0, 0)
  23. EBF_ONE, //!< src & dest (1, 1, 1, 1)
  24. EBF_DST_COLOR, //!< src (destR, destG, destB, destA)
  25. EBF_ONE_MINUS_DST_COLOR, //!< src (1-destR, 1-destG, 1-destB, 1-destA)
  26. EBF_SRC_COLOR, //!< dest (srcR, srcG, srcB, srcA)
  27. EBF_ONE_MINUS_SRC_COLOR, //!< dest (1-srcR, 1-srcG, 1-srcB, 1-srcA)
  28. EBF_SRC_ALPHA, //!< src & dest (srcA, srcA, srcA, srcA)
  29. EBF_ONE_MINUS_SRC_ALPHA, //!< src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA)
  30. EBF_DST_ALPHA, //!< src & dest (destA, destA, destA, destA)
  31. EBF_ONE_MINUS_DST_ALPHA, //!< src & dest (1-destA, 1-destA, 1-destA, 1-destA)
  32. EBF_SRC_ALPHA_SATURATE //!< src (min(srcA, 1-destA), idem, ...)
  33. };
  34. //! Values defining the blend operation
  35. enum E_BLEND_OPERATION
  36. {
  37. EBO_NONE = 0, //!< No blending happens
  38. EBO_ADD, //!< Default blending adds the color values
  39. EBO_SUBTRACT, //!< This mode subtracts the color values
  40. EBO_REVSUBTRACT, //!< This modes subtracts destination from source
  41. EBO_MIN, //!< Choose minimum value of each color channel
  42. EBO_MAX, //!< Choose maximum value of each color channel
  43. EBO_MIN_FACTOR, //!< Choose minimum value of each color channel after applying blend factors, not widely supported
  44. EBO_MAX_FACTOR, //!< Choose maximum value of each color channel after applying blend factors, not widely supported
  45. EBO_MIN_ALPHA, //!< Choose minimum value of each color channel based on alpha value, not widely supported
  46. EBO_MAX_ALPHA //!< Choose maximum value of each color channel based on alpha value, not widely supported
  47. };
  48. //! MaterialTypeParam: e.g. DirectX: D3DTOP_MODULATE, D3DTOP_MODULATE2X, D3DTOP_MODULATE4X
  49. enum E_MODULATE_FUNC
  50. {
  51. EMFN_MODULATE_1X = 1,
  52. EMFN_MODULATE_2X = 2,
  53. EMFN_MODULATE_4X = 4
  54. };
  55. //! Comparison function, e.g. for depth buffer test
  56. enum E_COMPARISON_FUNC
  57. {
  58. //! Depth test disabled (disable also write to depth buffer)
  59. ECFN_DISABLED = 0,
  60. //! <= test, default for e.g. depth test
  61. ECFN_LESSEQUAL = 1,
  62. //! Exact equality
  63. ECFN_EQUAL = 2,
  64. //! exclusive less comparison, i.e. <
  65. ECFN_LESS,
  66. //! Succeeds almost always, except for exact equality
  67. ECFN_NOTEQUAL,
  68. //! >= test
  69. ECFN_GREATEREQUAL,
  70. //! inverse of <=
  71. ECFN_GREATER,
  72. //! test succeeds always
  73. ECFN_ALWAYS,
  74. //! Test never succeeds
  75. ECFN_NEVER
  76. };
  77. //! Enum values for enabling/disabling color planes for rendering
  78. enum E_COLOR_PLANE
  79. {
  80. //! No color enabled
  81. ECP_NONE = 0,
  82. //! Alpha enabled
  83. ECP_ALPHA = 1,
  84. //! Red enabled
  85. ECP_RED = 2,
  86. //! Green enabled
  87. ECP_GREEN = 4,
  88. //! Blue enabled
  89. ECP_BLUE = 8,
  90. //! All colors, no alpha
  91. ECP_RGB = 14,
  92. //! All planes enabled
  93. ECP_ALL = 15
  94. };
  95. //! Source of the alpha value to take
  96. /** This is currently only supported in EMT_ONETEXTURE_BLEND. You can use an
  97. or'ed combination of values. Alpha values are modulated (multiplied). */
  98. enum E_ALPHA_SOURCE
  99. {
  100. //! Use no alpha, somewhat redundant with other settings
  101. EAS_NONE = 0,
  102. //! Use vertex color alpha
  103. EAS_VERTEX_COLOR,
  104. //! Use texture alpha channel
  105. EAS_TEXTURE
  106. };
  107. //! Pack srcFact, dstFact, Modulate and alpha source to MaterialTypeParam or BlendFactor
  108. /** alpha source can be an OR'ed combination of E_ALPHA_SOURCE values. */
  109. inline f32 pack_textureBlendFunc(const E_BLEND_FACTOR srcFact, const E_BLEND_FACTOR dstFact,
  110. const E_MODULATE_FUNC modulate = EMFN_MODULATE_1X, const u32 alphaSource = EAS_TEXTURE)
  111. {
  112. const u32 tmp = (alphaSource << 20) | (modulate << 16) | (srcFact << 12) | (dstFact << 8) | (srcFact << 4) | dstFact;
  113. return FR(tmp);
  114. }
  115. //! Pack srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, Modulate and alpha source to MaterialTypeParam or BlendFactor
  116. /** alpha source can be an OR'ed combination of E_ALPHA_SOURCE values. */
  117. inline f32 pack_textureBlendFuncSeparate(const E_BLEND_FACTOR srcRGBFact, const E_BLEND_FACTOR dstRGBFact,
  118. const E_BLEND_FACTOR srcAlphaFact, const E_BLEND_FACTOR dstAlphaFact,
  119. const E_MODULATE_FUNC modulate = EMFN_MODULATE_1X, const u32 alphaSource = EAS_TEXTURE)
  120. {
  121. const u32 tmp = (alphaSource << 20) | (modulate << 16) | (srcAlphaFact << 12) | (dstAlphaFact << 8) | (srcRGBFact << 4) | dstRGBFact;
  122. return FR(tmp);
  123. }
  124. //! Unpack srcFact, dstFact, modulo and alphaSource factors
  125. /** The fields don't use the full byte range, so we could pack even more... */
  126. inline void unpack_textureBlendFunc(E_BLEND_FACTOR &srcFact, E_BLEND_FACTOR &dstFact,
  127. E_MODULATE_FUNC &modulo, u32 &alphaSource, const f32 param)
  128. {
  129. const u32 state = IR(param);
  130. alphaSource = (state & 0x00F00000) >> 20;
  131. modulo = E_MODULATE_FUNC((state & 0x000F0000) >> 16);
  132. srcFact = E_BLEND_FACTOR((state & 0x000000F0) >> 4);
  133. dstFact = E_BLEND_FACTOR((state & 0x0000000F));
  134. }
  135. //! Unpack srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo and alphaSource factors
  136. /** The fields don't use the full byte range, so we could pack even more... */
  137. inline void unpack_textureBlendFuncSeparate(E_BLEND_FACTOR &srcRGBFact, E_BLEND_FACTOR &dstRGBFact,
  138. E_BLEND_FACTOR &srcAlphaFact, E_BLEND_FACTOR &dstAlphaFact,
  139. E_MODULATE_FUNC &modulo, u32 &alphaSource, const f32 param)
  140. {
  141. const u32 state = IR(param);
  142. alphaSource = (state & 0x00F00000) >> 20;
  143. modulo = E_MODULATE_FUNC((state & 0x000F0000) >> 16);
  144. srcAlphaFact = E_BLEND_FACTOR((state & 0x0000F000) >> 12);
  145. dstAlphaFact = E_BLEND_FACTOR((state & 0x00000F00) >> 8);
  146. srcRGBFact = E_BLEND_FACTOR((state & 0x000000F0) >> 4);
  147. dstRGBFact = E_BLEND_FACTOR((state & 0x0000000F));
  148. }
  149. //! has blend factor alphablending
  150. inline bool textureBlendFunc_hasAlpha(const E_BLEND_FACTOR factor)
  151. {
  152. switch (factor) {
  153. case EBF_SRC_ALPHA:
  154. case EBF_ONE_MINUS_SRC_ALPHA:
  155. case EBF_DST_ALPHA:
  156. case EBF_ONE_MINUS_DST_ALPHA:
  157. case EBF_SRC_ALPHA_SATURATE:
  158. return true;
  159. default:
  160. return false;
  161. }
  162. }
  163. //! These flags are used to specify the anti-aliasing and smoothing modes
  164. /** Techniques supported are multisampling, geometry smoothing, and alpha
  165. to coverage.
  166. Some drivers don't support a per-material setting of the anti-aliasing
  167. modes. In those cases, FSAA/multisampling is defined by the device mode
  168. chosen upon creation via irr::SIrrCreationParameters.
  169. */
  170. enum E_ANTI_ALIASING_MODE
  171. {
  172. //! Use to turn off anti-aliasing for this material
  173. EAAM_OFF = 0,
  174. //! Default anti-aliasing mode
  175. EAAM_SIMPLE = 1,
  176. //! High-quality anti-aliasing, not always supported, automatically enables SIMPLE mode
  177. EAAM_QUALITY = 3,
  178. //! Enhanced anti-aliasing for transparent materials
  179. /** Usually used with EMT_TRANSPARENT_ALPHA_CHANNEL_REF and multisampling. */
  180. EAAM_ALPHA_TO_COVERAGE = 4
  181. };
  182. //! These flags allow to define the interpretation of vertex color when lighting is enabled
  183. /** Without lighting being enabled the vertex color is the only value defining the fragment color.
  184. Once lighting is enabled, the four values for diffuse, ambient, emissive, and specular take over.
  185. With these flags it is possible to define which lighting factor shall be defined by the vertex color
  186. instead of the lighting factor which is the same for all faces of that material.
  187. The default is to use vertex color for the diffuse value, another pretty common value is to use
  188. vertex color for both diffuse and ambient factor. */
  189. enum E_COLOR_MATERIAL
  190. {
  191. //! Don't use vertex color for lighting
  192. ECM_NONE = 0,
  193. //! Use vertex color for diffuse light, this is default
  194. ECM_DIFFUSE,
  195. //! Use vertex color for ambient light
  196. ECM_AMBIENT,
  197. //! Use vertex color for emissive light
  198. ECM_EMISSIVE,
  199. //! Use vertex color for specular light
  200. ECM_SPECULAR,
  201. //! Use vertex color for both diffuse and ambient light
  202. ECM_DIFFUSE_AND_AMBIENT
  203. };
  204. //! Names for polygon offset direction
  205. const c8 *const PolygonOffsetDirectionNames[] = {
  206. "Back",
  207. "Front",
  208. 0,
  209. };
  210. //! For SMaterial.ZWriteEnable
  211. enum E_ZWRITE
  212. {
  213. //! zwrite always disabled for this material
  214. EZW_OFF = 0,
  215. //! This is the default setting for SMaterial and tries to handle things automatically.
  216. //! This is what you want to set to enable zwriting.
  217. //! Usually zwriting is enabled non-transparent materials - as far as Irrlicht can recognize those.
  218. //! Basically Irrlicht tries to handle the zwriting for you and assumes transparent materials don't need it.
  219. //! This is addionally affected by IVideoDriver::setAllowZWriteOnTransparent
  220. EZW_AUTO,
  221. //! zwrite always enabled for this material
  222. EZW_ON
  223. };
  224. //! Names for E_ZWRITE
  225. const c8 *const ZWriteNames[] = {
  226. "Off",
  227. "Auto",
  228. "On",
  229. 0,
  230. };
  231. //! Maximum number of texture an SMaterial can have.
  232. /** SMaterial might ignore some textures in most function, like assignment and comparison,
  233. when SIrrlichtCreationParameters::MaxTextureUnits is set to a lower number.
  234. */
  235. const u32 MATERIAL_MAX_TEXTURES = 4;
  236. //! Struct for holding parameters for a material renderer
  237. // Note for implementors: Serialization is in CNullDriver
  238. class SMaterial
  239. {
  240. public:
  241. //! Default constructor. Creates a solid, lit material with white colors
  242. SMaterial() :
  243. MaterialType(EMT_SOLID), AmbientColor(255, 255, 255, 255),
  244. DiffuseColor(255, 255, 255, 255), EmissiveColor(0, 0, 0, 0),
  245. SpecularColor(255, 255, 255, 255), Shininess(0.0f),
  246. MaterialTypeParam(0.0f), Thickness(1.0f), ZBuffer(ECFN_LESSEQUAL),
  247. AntiAliasing(EAAM_SIMPLE), ColorMask(ECP_ALL), ColorMaterial(ECM_DIFFUSE),
  248. BlendOperation(EBO_NONE), BlendFactor(0.0f), PolygonOffsetDepthBias(0.f),
  249. PolygonOffsetSlopeScale(0.f), Wireframe(false), PointCloud(false),
  250. GouraudShading(true), Lighting(true), ZWriteEnable(EZW_AUTO),
  251. BackfaceCulling(true), FrontfaceCulling(false), FogEnable(false),
  252. NormalizeNormals(false), UseMipMaps(true)
  253. {
  254. }
  255. //! Texture layer array.
  256. SMaterialLayer TextureLayers[MATERIAL_MAX_TEXTURES];
  257. //! Type of the material. Specifies how everything is blended together
  258. E_MATERIAL_TYPE MaterialType;
  259. //! How much ambient light (a global light) is reflected by this material.
  260. /** The default is full white, meaning objects are completely
  261. globally illuminated. Reduce this if you want to see diffuse
  262. or specular light effects. */
  263. SColor AmbientColor;
  264. //! How much diffuse light coming from a light source is reflected by this material.
  265. /** The default is full white. */
  266. SColor DiffuseColor;
  267. //! Light emitted by this material. Default is to emit no light.
  268. SColor EmissiveColor;
  269. //! How much specular light (highlights from a light) is reflected.
  270. /** The default is to reflect white specular light. See
  271. SMaterial::Shininess on how to enable specular lights. */
  272. SColor SpecularColor;
  273. //! Value affecting the size of specular highlights.
  274. /** A value of 20 is common. If set to 0, no specular
  275. highlights are being used. To activate, simply set the
  276. shininess of a material to a value in the range [0.5;128]:
  277. \code
  278. sceneNode->getMaterial(0).Shininess = 20.0f;
  279. \endcode
  280. You can change the color of the highlights using
  281. \code
  282. sceneNode->getMaterial(0).SpecularColor.set(255,255,255,255);
  283. \endcode
  284. The specular color of the dynamic lights
  285. (SLight::SpecularColor) will influence the the highlight color
  286. too, but they are set to a useful value by default when
  287. creating the light scene node.*/
  288. f32 Shininess;
  289. //! Free parameter, dependent on the material type.
  290. /** Mostly ignored, used for example in
  291. EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_ONETEXTURE_BLEND. */
  292. f32 MaterialTypeParam;
  293. //! Thickness of non-3dimensional elements such as lines and points.
  294. f32 Thickness;
  295. //! Is the ZBuffer enabled? Default: ECFN_LESSEQUAL
  296. /** If you want to disable depth test for this material
  297. just set this parameter to ECFN_DISABLED.
  298. Values are from E_COMPARISON_FUNC. */
  299. u8 ZBuffer;
  300. //! Sets the antialiasing mode
  301. /** Values are chosen from E_ANTI_ALIASING_MODE. Default is
  302. EAAM_SIMPLE, i.e. simple multi-sample anti-aliasing. */
  303. u8 AntiAliasing;
  304. //! Defines the enabled color planes
  305. /** Values are defined as or'ed values of the E_COLOR_PLANE enum.
  306. Only enabled color planes will be rendered to the current render
  307. target. Typical use is to disable all colors when rendering only to
  308. depth or stencil buffer, or using Red and Green for Stereo rendering. */
  309. u8 ColorMask : 4;
  310. //! Defines the interpretation of vertex color in the lighting equation
  311. /** Values should be chosen from E_COLOR_MATERIAL.
  312. When lighting is enabled, vertex color can be used instead of the
  313. material values for light modulation. This allows to easily change e.g. the
  314. diffuse light behavior of each face. The default, ECM_DIFFUSE, will result in
  315. a very similar rendering as with lighting turned off, just with light shading. */
  316. u8 ColorMaterial : 3;
  317. //! Store the blend operation of choice
  318. /** Values to be chosen from E_BLEND_OPERATION. */
  319. E_BLEND_OPERATION BlendOperation : 4;
  320. //! Store the blend factors
  321. /** textureBlendFunc/textureBlendFuncSeparate functions should be used to write
  322. properly blending factors to this parameter.
  323. Due to historical reasons this parameter is not used for material type
  324. EMT_ONETEXTURE_BLEND which uses MaterialTypeParam instead for the blend factor.
  325. It's generally used only for materials without any blending otherwise (like EMT_SOLID).
  326. It's main use is to allow having shader materials which can enable/disable
  327. blending after they have been created.
  328. When you set this you usually also have to set BlendOperation to a value != EBO_NONE
  329. (setting it to EBO_ADD is probably the most common one value). */
  330. f32 BlendFactor;
  331. //! A constant z-buffer offset for a polygon/line/point
  332. /** The range of the value is driver specific.
  333. On OpenGL you get units which are multiplied by the smallest value that is guaranteed to produce a resolvable offset.
  334. On D3D9 you can pass a range between -1 and 1. But you should likely divide it by the range of the depthbuffer.
  335. Like dividing by 65535.0 for a 16 bit depthbuffer. Thought it still might produce too large of a bias.
  336. Some article (https://aras-p.info/blog/2008/06/12/depth-bias-and-the-power-of-deceiving-yourself/)
  337. recommends multiplying by 2.0*4.8e-7 (and strangely on both 16 bit and 24 bit). */
  338. f32 PolygonOffsetDepthBias;
  339. //! Variable Z-Buffer offset based on the slope of the polygon.
  340. /** For polygons looking flat at a camera you could use 0 (for example in a 2D game)
  341. But in most cases you will have polygons rendered at a certain slope.
  342. The driver will calculate the slope for you and this value allows to scale that slope.
  343. The complete polygon offset is: PolygonOffsetSlopeScale*slope + PolygonOffsetDepthBias
  344. A good default here is to use 1.f if you want to push the polygons away from the camera
  345. and -1.f to pull them towards the camera. */
  346. f32 PolygonOffsetSlopeScale;
  347. //! Draw as wireframe or filled triangles? Default: false
  348. bool Wireframe : 1;
  349. //! Draw as point cloud or filled triangles? Default: false
  350. bool PointCloud : 1;
  351. //! Flat or Gouraud shading? Default: true
  352. bool GouraudShading : 1;
  353. //! Will this material be lighted? Default: true
  354. bool Lighting : 1;
  355. //! Is the zbuffer writable or is it read-only. Default: EZW_AUTO.
  356. /** If this parameter is not EZW_OFF, you probably also want to set ZBuffer
  357. to values other than ECFN_DISABLED */
  358. E_ZWRITE ZWriteEnable : 2;
  359. //! Is backface culling enabled? Default: true
  360. bool BackfaceCulling : 1;
  361. //! Is frontface culling enabled? Default: false
  362. bool FrontfaceCulling : 1;
  363. //! Is fog enabled? Default: false
  364. bool FogEnable : 1;
  365. //! Should normals be normalized?
  366. /** Always use this if the mesh lit and scaled. Default: false */
  367. bool NormalizeNormals : 1;
  368. //! Shall mipmaps be used if available
  369. /** Sometimes, disabling mipmap usage can be useful. Default: true */
  370. bool UseMipMaps : 1;
  371. //! Execute a function on all texture layers.
  372. /** Useful for setting properties which are not per material, but per
  373. texture layer, e.g. bilinear filtering. */
  374. template <typename F>
  375. void forEachTexture(F &&fn)
  376. {
  377. for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; i++) {
  378. fn(TextureLayers[i]);
  379. }
  380. }
  381. //! Gets the texture transformation matrix for level i
  382. /** \param i The desired level. Must not be larger than MATERIAL_MAX_TEXTURES
  383. \return Texture matrix for texture level i. */
  384. core::matrix4 &getTextureMatrix(u32 i)
  385. {
  386. return TextureLayers[i].getTextureMatrix();
  387. }
  388. //! Gets the immutable texture transformation matrix for level i
  389. /** \param i The desired level.
  390. \return Texture matrix for texture level i, or identity matrix for levels larger than MATERIAL_MAX_TEXTURES. */
  391. const core::matrix4 &getTextureMatrix(u32 i) const
  392. {
  393. if (i < MATERIAL_MAX_TEXTURES)
  394. return TextureLayers[i].getTextureMatrix();
  395. else
  396. return core::IdentityMatrix;
  397. }
  398. //! Sets the i-th texture transformation matrix
  399. /** \param i The desired level.
  400. \param mat Texture matrix for texture level i. */
  401. void setTextureMatrix(u32 i, const core::matrix4 &mat)
  402. {
  403. if (i >= MATERIAL_MAX_TEXTURES)
  404. return;
  405. TextureLayers[i].setTextureMatrix(mat);
  406. }
  407. //! Gets the i-th texture
  408. /** \param i The desired level.
  409. \return Texture for texture level i, if defined, else 0. */
  410. ITexture *getTexture(u32 i) const
  411. {
  412. return i < MATERIAL_MAX_TEXTURES ? TextureLayers[i].Texture : 0;
  413. }
  414. //! Sets the i-th texture
  415. /** If i>=MATERIAL_MAX_TEXTURES this setting will be ignored.
  416. \param i The desired level.
  417. \param tex Texture for texture level i. */
  418. void setTexture(u32 i, ITexture *tex)
  419. {
  420. if (i >= MATERIAL_MAX_TEXTURES)
  421. return;
  422. TextureLayers[i].Texture = tex;
  423. }
  424. //! Inequality operator
  425. /** \param b Material to compare to.
  426. \return True if the materials differ, else false. */
  427. inline bool operator!=(const SMaterial &b) const
  428. {
  429. bool different =
  430. MaterialType != b.MaterialType ||
  431. AmbientColor != b.AmbientColor ||
  432. DiffuseColor != b.DiffuseColor ||
  433. EmissiveColor != b.EmissiveColor ||
  434. SpecularColor != b.SpecularColor ||
  435. Shininess != b.Shininess ||
  436. MaterialTypeParam != b.MaterialTypeParam ||
  437. Thickness != b.Thickness ||
  438. Wireframe != b.Wireframe ||
  439. PointCloud != b.PointCloud ||
  440. GouraudShading != b.GouraudShading ||
  441. Lighting != b.Lighting ||
  442. ZBuffer != b.ZBuffer ||
  443. ZWriteEnable != b.ZWriteEnable ||
  444. BackfaceCulling != b.BackfaceCulling ||
  445. FrontfaceCulling != b.FrontfaceCulling ||
  446. FogEnable != b.FogEnable ||
  447. NormalizeNormals != b.NormalizeNormals ||
  448. AntiAliasing != b.AntiAliasing ||
  449. ColorMask != b.ColorMask ||
  450. ColorMaterial != b.ColorMaterial ||
  451. BlendOperation != b.BlendOperation ||
  452. BlendFactor != b.BlendFactor ||
  453. PolygonOffsetDepthBias != b.PolygonOffsetDepthBias ||
  454. PolygonOffsetSlopeScale != b.PolygonOffsetSlopeScale ||
  455. UseMipMaps != b.UseMipMaps;
  456. for (u32 i = 0; (i < MATERIAL_MAX_TEXTURES) && !different; ++i) {
  457. different |= (TextureLayers[i] != b.TextureLayers[i]);
  458. }
  459. return different;
  460. }
  461. //! Equality operator
  462. /** \param b Material to compare to.
  463. \return True if the materials are equal, else false. */
  464. inline bool operator==(const SMaterial &b) const
  465. {
  466. return !(b != *this);
  467. }
  468. //! Check if material needs alpha blending
  469. bool isAlphaBlendOperation() const
  470. {
  471. if (BlendOperation != EBO_NONE && BlendFactor != 0.f) {
  472. E_BLEND_FACTOR srcRGBFact = EBF_ZERO;
  473. E_BLEND_FACTOR dstRGBFact = EBF_ZERO;
  474. E_BLEND_FACTOR srcAlphaFact = EBF_ZERO;
  475. E_BLEND_FACTOR dstAlphaFact = EBF_ZERO;
  476. E_MODULATE_FUNC modulo = EMFN_MODULATE_1X;
  477. u32 alphaSource = 0;
  478. unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, BlendFactor);
  479. if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) ||
  480. textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact)) {
  481. return true;
  482. }
  483. }
  484. return false;
  485. }
  486. //! Check for some fixed-function transparent types. Still used internally, but might be deprecated soon.
  487. //! You probably should not use this anymore, IVideoDriver::needsTransparentRenderPass is more useful in most situations
  488. //! as it asks the material renders directly what they do with the material.
  489. bool isTransparent() const
  490. {
  491. if (MaterialType == EMT_TRANSPARENT_ALPHA_CHANNEL ||
  492. MaterialType == EMT_TRANSPARENT_VERTEX_ALPHA)
  493. return true;
  494. return false;
  495. }
  496. };
  497. //! global const identity Material
  498. IRRLICHT_API extern SMaterial IdentityMaterial;
  499. } // end namespace video
  500. } // end namespace irr