stencilshadow.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. static bool shadows(video::E_DRIVER_TYPE driverType)
  6. {
  7. IrrlichtDevice *device = createDevice (driverType, core::dimension2d<u32>(160,120), 16, false, true);
  8. if (!device)
  9. return true; // No error if device does not exist
  10. stabilizeScreenBackground(device->getVideoDriver());
  11. scene::ICameraSceneNode* cam = device->getSceneManager()->addCameraSceneNodeFPS();
  12. cam->setPosition(core::vector3df(-15,55,10));
  13. cam->setTarget(core::vector3df(-5,-5,-15));
  14. device->getSceneManager()->setAmbientLight(video::SColorf(.5f,.5f,.5f));
  15. scene::IMeshSceneNode* cube = device->getSceneManager()->addCubeSceneNode(100, 0, -1, core::vector3df(0,50,0));
  16. cube->setScale(core::vector3df(-1,-1,-1));
  17. scene::IAnimatedMeshSceneNode* node = device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->getMesh("../media/ninja.b3d"), 0, -1, core::vector3df(0,2,0), core::vector3df(),core::vector3df(5,5,5));
  18. node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
  19. node->addShadowVolumeSceneNode();
  20. node->setAnimationSpeed(0.f);
  21. scene::ILightSceneNode* light = device->getSceneManager()->addLightSceneNode(0, core::vector3df(10,10,10));
  22. light->setLightType(video::ELT_POINT);
  23. light->setRadius(500.f);
  24. light->getLightData().DiffuseColor.set(0,1,1);
  25. device->getVideoDriver()->beginScene (true, true, 0);
  26. device->getSceneManager()->drawAll();
  27. device->getVideoDriver()->endScene();
  28. bool result = takeScreenshotAndCompareAgainstReference(device->getVideoDriver(), "-stencilShadow.png", 99.91f);
  29. node->remove();
  30. cube->remove();
  31. // test self-shadowing
  32. node = device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->getMesh("../media/dwarf.x"));
  33. node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
  34. node->addShadowVolumeSceneNode();
  35. node->setAnimationSpeed(0.f);
  36. cam->setPosition(core::vector3df(0,55,-30));
  37. cam->setTarget(core::vector3df(60,45,150));
  38. device->getVideoDriver()->beginScene (true, true, 0);
  39. device->getSceneManager()->drawAll();
  40. device->getVideoDriver()->endScene();
  41. result = takeScreenshotAndCompareAgainstReference(device->getVideoDriver(), "-stencilSelfShadow.png", 99.41f);
  42. device->closeDevice();
  43. device->run();
  44. device->drop();
  45. return result;
  46. }
  47. bool stencilShadow(void)
  48. {
  49. bool passed = true;
  50. passed &= shadows(video::EDT_OPENGL);
  51. // no shadows in these renderers
  52. // passed &= shadows(video::EDT_SOFTWARE);
  53. // passed &= shadows(video::EDT_BURNINGSVIDEO);
  54. passed &= shadows(video::EDT_DIRECT3D9);
  55. passed &= shadows(video::EDT_DIRECT3D8);
  56. return passed;
  57. }