stencilshadow.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. //
  6. static bool stencilShadow(video::E_DRIVER_TYPE driverType)
  7. {
  8. IrrlichtDevice *device = createDevice (driverType, core::dimension2d<u32>(160,120), 16, false, true);
  9. if (!device)
  10. return true; // No error if device does not exist
  11. stabilizeScreenBackground(device->getVideoDriver());
  12. scene::ICameraSceneNode* cam = device->getSceneManager()->addCameraSceneNodeFPS();
  13. cam->setPosition(core::vector3df(-15,60,40));
  14. cam->setTarget(core::vector3df(+25,-5,-25));
  15. device->getSceneManager()->setAmbientLight(video::SColorf(.5f,.5f,.5f));
  16. device->getSceneManager()->setShadowColor( video::SColor(255, 50, 0, 50));
  17. device->getSceneManager()->addCubeSceneNode(100, 0, -1, core::vector3df(0,50,0), core::vector3df(), core::vector3df(-1,-1,-1));
  18. scene::IAnimatedMeshSceneNode* node = device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->getMesh("../media/ninja.b3d"), 0, -1, core::vector3df(), core::vector3df(0.f, 230.f, 0.f),core::vector3df(5,5,5));
  19. node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
  20. node->addShadowVolumeSceneNode(0, -1, true, 200.f);
  21. node->setAnimationSpeed(0.f);
  22. scene::IMeshSceneNode* cube2 = device->getSceneManager()->addCubeSceneNode(10, 0, -1, core::vector3df(40,0,0), core::vector3df(), core::vector3df(1,1,2.5f));
  23. cube2->getMaterial(0).DiffuseColor = video::SColor(220, 0, 100, 100);
  24. cube2->addShadowVolumeSceneNode(0, -1, false, 200.f);
  25. scene::ILightSceneNode* light = device->getSceneManager()->addLightSceneNode(0, core::vector3df(-40,10,20));
  26. light->setLightType(video::ELT_POINT);
  27. light->setRadius(500.f);
  28. light->getLightData().DiffuseColor.set(1,1,1);
  29. device->getVideoDriver()->beginScene(video::ECBF_ALL, video::SColor(0,0,0,0));
  30. device->getSceneManager()->drawAll();
  31. device->getVideoDriver()->endScene();
  32. bool result = takeScreenshotAndCompareAgainstReference(device->getVideoDriver(), "-stencilShadow.png", 99.91f);
  33. device->closeDevice();
  34. device->run();
  35. device->drop();
  36. return result;
  37. }
  38. // test self-shadowing
  39. static bool selfShadowing(video::E_DRIVER_TYPE driverType)
  40. {
  41. IrrlichtDevice *device = createDevice (driverType, core::dimension2d<u32>(160,120), 16, false, true);
  42. if (!device)
  43. return true; // No error if device does not exist
  44. stabilizeScreenBackground(device->getVideoDriver());
  45. device->getSceneManager()->setAmbientLight(video::SColorf(.5f,.5f,.5f));
  46. device->getSceneManager()->setShadowColor( video::SColor(220, 50, 0, 0));
  47. scene::IAnimatedMeshSceneNode* node = device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->getMesh("../media/dwarf.x"));
  48. node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
  49. node->addShadowVolumeSceneNode();
  50. node->setAnimationSpeed(0.f);
  51. scene::ICameraSceneNode* cam = device->getSceneManager()->addCameraSceneNodeFPS();
  52. cam->setPosition(core::vector3df(0,55,-30));
  53. cam->setTarget(core::vector3df(60,45,150));
  54. scene::ILightSceneNode* light = device->getSceneManager()->addLightSceneNode(0, core::vector3df(100,100,-20));
  55. light->setLightType(video::ELT_POINT);
  56. light->setRadius(500.f);
  57. light->getLightData().DiffuseColor.set(0,1,1);
  58. device->getVideoDriver()->beginScene(video::ECBF_ALL, video::SColor(0,0,0,0));
  59. device->getSceneManager()->drawAll();
  60. device->getVideoDriver()->endScene();
  61. bool result = takeScreenshotAndCompareAgainstReference(device->getVideoDriver(), "-stencilSelfShadow.png", 99.41f);
  62. device->closeDevice();
  63. device->run();
  64. device->drop();
  65. return result;
  66. }
  67. bool stencilShadow(void)
  68. {
  69. bool passed = true;
  70. passed &= stencilShadow(video::EDT_OPENGL);
  71. passed &= stencilShadow(video::EDT_DIRECT3D9);
  72. // no shadows in software renderer
  73. // passed &= stencilShadow(video::EDT_SOFTWARE);
  74. passed &= stencilShadow(video::EDT_BURNINGSVIDEO); // Note: cube has wrong color, if that gets ever changed just update the test-image.
  75. passed &= selfShadowing(video::EDT_OPENGL);
  76. passed &= selfShadowing(video::EDT_DIRECT3D9);
  77. // no shadows in software renderer
  78. // passed &= selfShadowing(video::EDT_SOFTWARE);
  79. passed &= selfShadowing(video::EDT_BURNINGSVIDEO);
  80. return passed;
  81. }