transparentMaterials.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. // Copyright (C) 2008-2012 Christian Stehno, Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. using namespace core;
  6. using namespace scene;
  7. using namespace video;
  8. //! Check that EMT_TRANSPARENT_ALPHA_CHANNEL_REF works as expected
  9. bool testTransparentAlphaChannelRef(video::E_DRIVER_TYPE driverType)
  10. {
  11. IrrlichtDevice* device = createDevice(driverType, core::dimension2d<u32>(160, 120), 32);
  12. if (!device)
  13. return true;
  14. video::IVideoDriver* driver = device->getVideoDriver();
  15. scene::ISceneManager* smgr = device->getSceneManager();
  16. if (driver->getColorFormat() != video::ECF_A8R8G8B8)
  17. {
  18. device->closeDevice();
  19. device->run();
  20. device->drop();
  21. return true;
  22. }
  23. stabilizeScreenBackground(driver);
  24. logTestString("Testing driver %ls\n", driver->getName());
  25. driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
  26. ISceneNode * backCube = smgr->addCubeSceneNode();
  27. backCube->setPosition(vector3df(0, 0, 10));
  28. backCube->setScale(vector3df(5, 5, 1));
  29. backCube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
  30. backCube->setMaterialType(video::EMT_SOLID);
  31. backCube->setMaterialFlag(video::EMF_LIGHTING, false);
  32. ISceneNode * frontCube = smgr->addCubeSceneNode();
  33. frontCube->setMaterialTexture(0, driver->getTexture("../media/help.png"));
  34. frontCube->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
  35. frontCube->setMaterialFlag(video::EMF_LIGHTING, false);
  36. (void)smgr->addCameraSceneNode(0, vector3df(0, 0, -15));
  37. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
  38. smgr->drawAll();
  39. driver->endScene();
  40. bool result = takeScreenshotAndCompareAgainstReference(driver, "-transparentAlphaChannelRef.png", 99.18f);
  41. device->closeDevice();
  42. device->run();
  43. device->drop();
  44. return result;
  45. }
  46. //! Check that EMT_TRANSPARENT_ALPHA_CHANNEL works as expected
  47. bool testTransparentAlphaChannel(video::E_DRIVER_TYPE driverType)
  48. {
  49. IrrlichtDevice* device = createDevice(driverType, core::dimension2d<u32>(160, 120), 32);
  50. if (!device)
  51. return true;
  52. video::IVideoDriver* driver = device->getVideoDriver();
  53. scene::ISceneManager* smgr = device->getSceneManager();
  54. if (driver->getColorFormat() != video::ECF_A8R8G8B8)
  55. {
  56. device->closeDevice();
  57. device->run();
  58. device->drop();
  59. return true;
  60. }
  61. stabilizeScreenBackground(driver);
  62. logTestString("Testing driver %ls\n", driver->getName());
  63. driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
  64. ISceneNode * backCube = smgr->addCubeSceneNode();
  65. backCube->setPosition(vector3df(0, 0, 10));
  66. backCube->setScale(vector3df(5, 5, 1));
  67. backCube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
  68. backCube->setMaterialType(video::EMT_SOLID);
  69. backCube->setMaterialFlag(video::EMF_LIGHTING, false);
  70. ISceneNode * frontCube = smgr->addCubeSceneNode();
  71. frontCube->setMaterialTexture(0, driver->getTexture("../media/help.png"));
  72. frontCube->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
  73. frontCube->setMaterialFlag(video::EMF_LIGHTING, false);
  74. (void)smgr->addCameraSceneNode(0, vector3df(0, 0, -15));
  75. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
  76. smgr->drawAll();
  77. driver->endScene();
  78. bool result = takeScreenshotAndCompareAgainstReference(driver, "-transparentAlphaChannel.png");
  79. device->closeDevice();
  80. device->run();
  81. device->drop();
  82. return result;
  83. }
  84. //! Check that EMT_TRANSPARENT_VERTEX_ALPHA works as expected
  85. bool testTransparentVertexAlpha(video::E_DRIVER_TYPE driverType)
  86. {
  87. IrrlichtDevice* device = createDevice(driverType, core::dimension2d<u32>(160, 120), 32);
  88. if (!device)
  89. return true;
  90. video::IVideoDriver* driver = device->getVideoDriver();
  91. scene::ISceneManager* smgr = device->getSceneManager();
  92. if (driver->getColorFormat() != video::ECF_A8R8G8B8)
  93. {
  94. device->closeDevice();
  95. device->run();
  96. device->drop();
  97. return true;
  98. }
  99. stabilizeScreenBackground(driver);
  100. logTestString("Testing driver %ls\n", driver->getName());
  101. driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
  102. ISceneNode * backCube = smgr->addCubeSceneNode();
  103. backCube->setPosition(vector3df(0, 0, 10));
  104. backCube->setScale(vector3df(5, 5, 1));
  105. backCube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
  106. // vertex color has alpha 255, hence solid
  107. backCube->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
  108. backCube->setMaterialFlag(video::EMF_LIGHTING, false);
  109. IMeshSceneNode * frontCube = smgr->addCubeSceneNode(10,0,-1,core::vector3df(-10,0,0));
  110. frontCube->setMaterialTexture(0, driver->getTexture("../media/help.png"));
  111. frontCube->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
  112. frontCube->setMaterialFlag(video::EMF_LIGHTING, false);
  113. driver->getMeshManipulator()->setVertexColorAlpha(frontCube->getMesh(), 128);
  114. frontCube = smgr->addCubeSceneNode(10,0,-1,core::vector3df(10,0,0));
  115. frontCube->setMaterialTexture(0, driver->getTexture("../media/help.png"));
  116. frontCube->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
  117. frontCube->setMaterialFlag(video::EMF_LIGHTING, false);
  118. driver->getMeshManipulator()->setVertexColorAlpha(frontCube->getMesh(), 45);
  119. (void)smgr->addCameraSceneNode(0, vector3df(0, 0, -15));
  120. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
  121. smgr->drawAll();
  122. driver->endScene();
  123. bool result = takeScreenshotAndCompareAgainstReference(driver, "-transparentVertexAlpha.png", 98.76f);
  124. device->closeDevice();
  125. device->run();
  126. device->drop();
  127. return result;
  128. }
  129. //! Check that EMT_TRANSPARENT_REFLECTION_2_LAYER works as expected
  130. bool testTransparentReflection2Layer(video::E_DRIVER_TYPE driverType)
  131. {
  132. IrrlichtDevice* device = createDevice(driverType, core::dimension2d<u32>(160, 120), 32);
  133. if (!device)
  134. return true;
  135. video::IVideoDriver* driver = device->getVideoDriver();
  136. scene::ISceneManager* smgr = device->getSceneManager();
  137. if (driver->getColorFormat() != video::ECF_A8R8G8B8)
  138. {
  139. device->closeDevice();
  140. device->run();
  141. device->drop();
  142. return true;
  143. }
  144. stabilizeScreenBackground(driver);
  145. logTestString("Testing driver %ls\n", driver->getName());
  146. driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
  147. ISceneNode * backCube = smgr->addCubeSceneNode();
  148. backCube->setPosition(vector3df(0, 0, 10));
  149. backCube->setScale(vector3df(5, 5, 1));
  150. backCube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
  151. backCube->setMaterialTexture(1, driver->getTexture("../media/water.jpg"));
  152. // vertex color has alpha 255, hence solid
  153. backCube->setMaterialType(video::EMT_TRANSPARENT_REFLECTION_2_LAYER);
  154. backCube->setMaterialFlag(video::EMF_LIGHTING, false);
  155. IMeshSceneNode * frontCube = smgr->addCubeSceneNode(10,0,-1,core::vector3df(-10,0,0));
  156. frontCube->setMaterialTexture(0, driver->getTexture("../media/help.png"));
  157. frontCube->setMaterialTexture(1, driver->getTexture("../media/water.jpg"));
  158. frontCube->setMaterialType(video::EMT_TRANSPARENT_REFLECTION_2_LAYER);
  159. frontCube->setMaterialFlag(video::EMF_LIGHTING, false);
  160. driver->getMeshManipulator()->setVertexColorAlpha(frontCube->getMesh(), 128);
  161. frontCube = smgr->addCubeSceneNode(10,0,-1,core::vector3df(10,0,0));
  162. frontCube->setMaterialTexture(0, driver->getTexture("../media/help.png"));
  163. frontCube->setMaterialTexture(1, driver->getTexture("../media/water.jpg"));
  164. frontCube->setMaterialType(video::EMT_TRANSPARENT_REFLECTION_2_LAYER);
  165. frontCube->setMaterialFlag(video::EMF_LIGHTING, false);
  166. driver->getMeshManipulator()->setVertexColorAlpha(frontCube->getMesh(), 45);
  167. (void)smgr->addCameraSceneNode(0, vector3df(0, 0, -15));
  168. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
  169. smgr->drawAll();
  170. driver->endScene();
  171. bool result = takeScreenshotAndCompareAgainstReference(driver, "-transparentReflection2Layer.png");
  172. device->closeDevice();
  173. device->run();
  174. device->drop();
  175. return result;
  176. }
  177. //! Check that EMT_TRANSPARENT_ADD_COLOR works as expected
  178. bool testTransparentAddColor(video::E_DRIVER_TYPE driverType)
  179. {
  180. IrrlichtDevice* device = createDevice(driverType, core::dimension2d<u32>(160, 120), 32);
  181. if (!device)
  182. return true;
  183. video::IVideoDriver* driver = device->getVideoDriver();
  184. scene::ISceneManager* smgr = device->getSceneManager();
  185. if (driver->getColorFormat() != video::ECF_A8R8G8B8)
  186. {
  187. device->closeDevice();
  188. device->run();
  189. device->drop();
  190. return true;
  191. }
  192. stabilizeScreenBackground(driver);
  193. logTestString("Testing driver %ls\n", driver->getName());
  194. driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
  195. ISceneNode * backCube = smgr->addCubeSceneNode();
  196. backCube->setPosition(vector3df(0, 0, 10));
  197. backCube->setScale(vector3df(5, 5, 1));
  198. backCube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
  199. backCube->setMaterialType(video::EMT_SOLID);
  200. backCube->setMaterialFlag(video::EMF_LIGHTING, false);
  201. IMeshSceneNode * frontCube = smgr->addCubeSceneNode();
  202. frontCube->setMaterialTexture(0, driver->getTexture("../media/help.png"));
  203. frontCube->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
  204. frontCube->setMaterialFlag(video::EMF_LIGHTING, false);
  205. (void)smgr->addCameraSceneNode(0, vector3df(0, 0, -15));
  206. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
  207. smgr->drawAll();
  208. driver->endScene();
  209. bool result = takeScreenshotAndCompareAgainstReference(driver, "-transparentAddColor.png");
  210. device->closeDevice();
  211. device->run();
  212. device->drop();
  213. return result;
  214. }
  215. bool testTransparentVertexAlphaMore(E_DRIVER_TYPE driverType)
  216. {
  217. IrrlichtDevice *device = createDevice(driverType, dimension2d<u32>(160, 120));
  218. if (!device)
  219. return true;
  220. IVideoDriver* driver = device->getVideoDriver();
  221. ISceneManager* smgr = device->getSceneManager();
  222. if (driver->getColorFormat() != video::ECF_A8R8G8B8)
  223. {
  224. device->closeDevice();
  225. device->run();
  226. device->drop();
  227. return true;
  228. }
  229. stabilizeScreenBackground(driver);
  230. logTestString("Testing driver %ls\n", driver->getName());
  231. IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");
  232. IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
  233. IMeshSceneNode* cube = smgr->addCubeSceneNode(10.0f,0,-1,vector3df(-5,3,-15));
  234. if (node)
  235. {
  236. node->setMaterialFlag(EMF_LIGHTING, false);
  237. node->setFrameLoop(0, 310);
  238. node->setMaterialTexture( 0, driver->getTexture("../media/sydney.bmp") );
  239. }
  240. if (cube)
  241. {
  242. cube->getMaterial(0).MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA;
  243. cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
  244. cube->setMaterialFlag(EMF_LIGHTING, false);
  245. smgr->getMeshManipulator()->setVertexColorAlpha(cube->getMesh(),128);
  246. }
  247. // second cube without texture
  248. cube = smgr->addCubeSceneNode(10.0f,0,-1,vector3df(5,3,-15));
  249. if (cube)
  250. {
  251. cube->getMaterial(0).MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA;
  252. cube->setMaterialFlag(EMF_LIGHTING, false);
  253. smgr->getMeshManipulator()->setVertexColorAlpha(cube->getMesh(),128);
  254. }
  255. smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
  256. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0,200,200,200));
  257. smgr->drawAll();
  258. driver->endScene();
  259. bool result = takeScreenshotAndCompareAgainstReference(driver, "-transparentVertexAlphaChannelMore.png", 99.18f);
  260. device->closeDevice();
  261. device->run();
  262. device->drop();
  263. return result;
  264. }
  265. bool transparentMaterials(void)
  266. {
  267. bool result = true;
  268. TestWithAllDrivers(testTransparentAlphaChannel);
  269. // FIXME Rogerborg 8-January-2010. Burning's video currently produces unexpected results,
  270. // blending using the full alpha value instead of using a boolean mask. This test is being
  271. // added now anyway to help verify the fix when it's done; it should just require an
  272. // update of the reference image.
  273. TestWithAllDrivers(testTransparentAlphaChannelRef);
  274. // This type seems to be broken as well for Burning's video.
  275. TestWithAllDrivers(testTransparentVertexAlpha);
  276. TestWithAllDrivers(testTransparentAddColor);
  277. // TODO: this simply does not work in OpenGL due to the sphere map
  278. // at least it creates different results, and also varies across drivers
  279. TestWithAllDrivers(testTransparentReflection2Layer);
  280. // This type seems to be broken as well for Burning's video.
  281. TestWithAllDrivers(testTransparentVertexAlphaMore);
  282. return result;
  283. }