<NME> bulb_self_shadow_scene.cpp
<BEF> #include <babylon/cameras/arc_rotate_camera.h>
#include <babylon/engines/scene.h>
#include <babylon/interfaces/irenderable_scene.h>
#include <babylon/lights/point_light.h>
#include <babylon/lights/shadows/shadow_generator.h>
#include <babylon/lights/spot_light.h>
#include <babylon/materials/pbr/pbr_metallic_roughness_material.h>
#include <babylon/materials/standard_material.h>
#include <babylon/maths/color3.h>
#include <babylon/maths/vector3.h>
#include <babylon/meshes/builders/mesh_builder_options.h>
#include <babylon/meshes/mesh.h>
#include <babylon/meshes/mesh_builder.h>
#include <babylon/samples/babylon_register_sample.h>

namespace BABYLON {
namespace Samples {
    : IRenderableScene(iCanvas)
    , _i{0.f}
    , _lightPos{Vector3(0.f, 8.f, 0.f)}
    , _light0{nullptr}
    , _light1{nullptr}
    , _torus{nullptr}

public:
  BulbSelfShadowScene(ICanvas* iCanvas)
      : IRenderableScene(iCanvas)
      , _i{0.f}
      , _lightPos{Vector3(0.f, 8.f, 0.f)}
      , _lightDiffuse{Color3(1.f, 1.f, 1.f)}
      , _light0{nullptr}
      , _light1{nullptr}
      , _torus{nullptr}
      , _bulb{nullptr}
  {

void BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)
{
  auto lightDiffuse = Color3(1.f, 1.f, 1.f);

  // mats
  auto matEmit             = StandardMaterial::New("matEmit", scene);
  matEmit->emissiveColor   = lightDiffuse;
  matEmit->disableLighting = true;

  auto matMetal       = PBRMetallicRoughnessMaterial::New("matMetal", scene);
  void initializeScene(ICanvas* canvas, Scene* scene) override
  {
    // mats
    auto matEmit             = StandardMaterial::New("matEmit", scene);
    matEmit->emissiveColor   = _lightDiffuse;
    matEmit->disableLighting = true;

    auto matMetal       = PBRMetallicRoughnessMaterial::New("matMetal", scene);
    matMetal->metallic  = 0.9f;
    matMetal->roughness = 0.1f;
    matMetal->baseColor = Color3(1.f, 1.f, 1.f);

    auto matWall       = PBRMetallicRoughnessMaterial::New("matWall", scene);
    matWall->metallic  = 0.f;
    matWall->roughness = 1.f;
    matWall->baseColor = Color3(0.9f, 0.1f, 0.1f);

    // meshes
    TorusKnotOptions torusKnotOptions;
    torusKnotOptions.radialSegments  = 200;
    torusKnotOptions.tubularSegments = 50;
    torusKnotOptions.sideOrientation = Mesh::FRONTSIDE;
    _torus               = MeshBuilder::CreateTorusKnot("torus", torusKnotOptions, scene);
    _torus->position().y = 3.3f;
    _torus->material     = matMetal;

    SphereOptions bulbOptions;
    bulbOptions.diameter = 2.f;
    _bulb                = MeshBuilder::CreateSphere("bulb", bulbOptions, scene);
    _bulb->position      = _lightPos;
    _bulb->material      = matEmit;

    BoxOptions roomOptions;
    roomOptions.width           = 20.f;
    roomOptions.height          = 20.f;
    roomOptions.depth           = 20.f;
    roomOptions.sideOrientation = Mesh::BACKSIDE;
    auto room                   = MeshBuilder::CreateBox("room", roomOptions, scene);
    room->material              = matWall;

    BoxOptions groundOptions;
    groundOptions.width  = 6.f;
    groundOptions.height = 10.f;
    groundOptions.depth  = 6.f;
    auto ground          = MeshBuilder::CreateBox("ground", groundOptions, scene);
    _light0            = SpotLight::New("light0", _lightPos,
                             _torus->position().subtract(_lightPos),
                             Math::PI * 2.f / 3.f, 0.f, scene);
    _light0->diffuse   = lightDiffuse;
    _light0->intensity = 20.f;
    _light0->includedOnlyMeshes().emplace_back(_torus); // <<<<<<<<<<<<<<<<<<<<<
    auto shadowGen = ShadowGenerator::New(2048, _light0);
    {
      _light0          = SpotLight::New("light0", _lightPos, _torus->position().subtract(_lightPos),
                               Math::PI * 2.f / 3.f, 0.f, scene);
      _light0->diffuse = _lightDiffuse;
      _light0->intensity = 20.f;
  // pointlight that lits all meshes excepts the bulb
  {
    _light1            = PointLight::New("light1", _lightPos, scene);
    _light1->diffuse   = lightDiffuse;
    _light1->intensity = 200.f;
    _light1->excludedMeshes().emplace_back(_bulb); // <<<<<<<<<<<<<<<<<<<<<<<<<<
    auto shadowGen  = ShadowGenerator::New(1024, _light1);
    // pointlight that lits all meshes excepts the bulb
    {
      _light1            = PointLight::New("light1", _lightPos, scene);
      _light1->diffuse   = _lightDiffuse;
      _light1->intensity = 200.f;
      _light1->excludedMeshes().emplace_back(_bulb); // <<<<<<<<<<<<<<<<<<<<<<<<<<
      auto shadowGen                          = ShadowGenerator::New(1024, _light1);
      shadowGen->bias                         = 0.0005f;
      shadowGen->usePercentageCloserFiltering = true;
      shadowGen->setDarkness(0.3f);
      shadowGen->addShadowCaster(_torus); // caster
      shadowGen->addShadowCaster(ground);
      _torus->receiveShadows = true; // receiver
      room->receiveShadows   = true; // receiver
      ground->receiveShadows = true; // receiver
    }

    // camera
    auto camera = ArcRotateCamera::New("camera", Math::PI / 3.f, Math::PI * 3.f / 5.f, 9.f,
                                       _torus->position(), scene, true);
    camera->attachControl(canvas, true);
    camera->upperBetaLimit   = Math::PI * 3.f / 4.f;
    camera->wheelPrecision   = 10.f;
    camera->upperRadiusLimit = 11.f;
    camera->lowerRadiusLimit = 5.f;

    // update
    scene->registerBeforeRender([this](Scene*, EventState&) {
      _i += 0.008f;

      _lightPos.x = -std::cos(_i) * 8.f;
      _lightPos.z = std::sin(_i) * 8.f;

      _light0->position  = _lightPos;
      _light0->direction = _torus->position().subtract(_lightPos);

      _light1->position = _lightPos;

      _bulb->position = _lightPos;
    });
  }

private:
  float _i;
  Vector3 _lightPos;
  Color3 _lightDiffuse;
  SpotLightPtr _light0;
  PointLightPtr _light1;
  MeshPtr _torus;
  MeshPtr _bulb;

}; // end of class BulbSelfShadowScene

BABYLON_REGISTER_SAMPLE("Shadows", BulbSelfShadowScene)

} // end of namespace Samples
} // end of namespace BABYLON

<MSG> Made light diffuse color a class property

<DFF> @@ -18,6 +18,7 @@ BulbSelfShadowScene::BulbSelfShadowScene(ICanvas* iCanvas)
     : IRenderableScene(iCanvas)
     , _i{0.f}
     , _lightPos{Vector3(0.f, 8.f, 0.f)}
+    , _lightDiffuse{Color3(1.f, 1.f, 1.f)}
     , _light0{nullptr}
     , _light1{nullptr}
     , _torus{nullptr}
@@ -36,11 +37,9 @@ const char* BulbSelfShadowScene::getName()
 
 void BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)
 {
-  auto lightDiffuse = Color3(1.f, 1.f, 1.f);
-
   // mats
   auto matEmit             = StandardMaterial::New("matEmit", scene);
-  matEmit->emissiveColor   = lightDiffuse;
+  matEmit->emissiveColor   = _lightDiffuse;
   matEmit->disableLighting = true;
 
   auto matMetal       = PBRMetallicRoughnessMaterial::New("matMetal", scene);
@@ -92,7 +91,7 @@ void BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)
     _light0            = SpotLight::New("light0", _lightPos,
                              _torus->position().subtract(_lightPos),
                              Math::PI * 2.f / 3.f, 0.f, scene);
-    _light0->diffuse   = lightDiffuse;
+    _light0->diffuse   = _lightDiffuse;
     _light0->intensity = 20.f;
     _light0->includedOnlyMeshes().emplace_back(_torus); // <<<<<<<<<<<<<<<<<<<<<
     auto shadowGen = ShadowGenerator::New(2048, _light0);
@@ -104,7 +103,7 @@ void BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)
   // pointlight that lits all meshes excepts the bulb
   {
     _light1            = PointLight::New("light1", _lightPos, scene);
-    _light1->diffuse   = lightDiffuse;
+    _light1->diffuse   = _lightDiffuse;
     _light1->intensity = 200.f;
     _light1->excludedMeshes().emplace_back(_bulb); // <<<<<<<<<<<<<<<<<<<<<<<<<<
     auto shadowGen  = ShadowGenerator::New(1024, _light1);

{'commit': 'diff --git a/src/Samples/include/babylon/samples/shadows/bulb_self_shadow_scene.h b/src/Samples/include/babylon/samples/shadows/bulb_self_shadow_scene.h\nindex d06d720cd..93901640c 100644\n--- a/src/Samples/include/babylon/samples/shadows/bulb_self_shadow_scene.h\n+++ b/src/Samples/include/babylon/samples/shadows/bulb_self_shadow_scene.h\n@@ -3,6 +3,7 @@\n \n #include <babylon/interfaces/irenderable_scene.h>\n \n+#include <babylon/math/color3.h>\n #include <babylon/math/vector3.h>\n \n namespace BABYLON {\n@@ -33,6 +34,7 @@ public:\n private:\n   float _i;\n   Vector3 _lightPos;\n+  Color3 _lightDiffuse;\n   SpotLightPtr _light0;\n   PointLightPtr _light1;\n   MeshPtr _torus;\ndiff --git a/src/Samples/src/samples/shadows/bulb_self_shadow_scene.cpp b/src/Samples/src/samples/shadows/bulb_self_shadow_scene.cpp\nindex c389819a6..98f7e601d 100644\n--- a/src/Samples/src/samples/shadows/bulb_self_shadow_scene.cpp\n+++ b/src/Samples/src/samples/shadows/bulb_self_shadow_scene.cpp\n@@ -18,6 +18,7 @@ BulbSelfShadowScene::BulbSelfShadowScene(ICanvas* iCanvas)\n     : IRenderableScene(iCanvas)\n     , _i{0.f}\n     , _lightPos{Vector3(0.f, 8.f, 0.f)}\n+    , _lightDiffuse{Color3(1.f, 1.f, 1.f)}\n     , _light0{nullptr}\n     , _light1{nullptr}\n     , _torus{nullptr}\n@@ -36,11 +37,9 @@ const char* BulbSelfShadowScene::getName()\n \n void BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)\n {\n-  auto lightDiffuse = Color3(1.f, 1.f, 1.f);\n-\n   // mats\n   auto matEmit             = StandardMaterial::New("matEmit", scene);\n-  matEmit->emissiveColor   = lightDiffuse;\n+  matEmit->emissiveColor   = _lightDiffuse;\n   matEmit->disableLighting = true;\n \n   auto matMetal       = PBRMetallicRoughnessMaterial::New("matMetal", scene);\n@@ -92,7 +91,7 @@ void BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)\n     _light0            = SpotLight::New("light0", _lightPos,\n                              _torus->position().subtract(_lightPos),\n                              Math::PI * 2.f / 3.f, 0.f, scene);\n-    _light0->diffuse   = lightDiffuse;\n+    _light0->diffuse   = _lightDiffuse;\n     _light0->intensity = 20.f;\n     _light0->includedOnlyMeshes().emplace_back(_torus); // <<<<<<<<<<<<<<<<<<<<<\n     auto shadowGen = ShadowGenerator::New(2048, _light0);\n@@ -104,7 +103,7 @@ void BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)\n   // pointlight that lits all meshes excepts the bulb\n   {\n     _light1            = PointLight::New("light1", _lightPos, scene);\n-    _light1->diffuse   = lightDiffuse;\n+    _light1->diffuse   = _lightDiffuse;\n     _light1->intensity = 200.f;\n     _light1->excludedMeshes().emplace_back(_bulb); // <<<<<<<<<<<<<<<<<<<<<<<<<<\n     auto shadowGen  = ShadowGenerator::New(1024, _light1);\n', 'commit_subject': 'Made light diffuse color a class property', 'repo_name': 'samdauwe/BabylonCpp', 'committer': {'name': 'samdauwe', 'email': '637c8055e0642816555907e78ef80a031b1d7a65@gmail.com', 'time_sec': '1563094852', 'tz_offset': '120', 'date': {'seconds': '1563094852'}}, 'commit_tree': '7b8083f688775880ca76cfea8d6d205a78347876', 'commit_message': 'Made light diffuse color a class property\n', 'language_name': 'Python', 'license': 'apache-2.0', 'hunks': '@@ -18,6 +18,7 @@ BulbSelfShadowScene::BulbSelfShadowScene(ICanvas* iCanvas)\n     : IRenderableScene(iCanvas)\n     , _i{0.f}\n     , _lightPos{Vector3(0.f, 8.f, 0.f)}\n+    , _lightDiffuse{Color3(1.f, 1.f, 1.f)}\n     , _light0{nullptr}\n     , _light1{nullptr}\n     , _torus{nullptr}\n@@ -36,11 +37,9 @@ const char* BulbSelfShadowScene::getName()\n \n void BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)\n {\n-  auto lightDiffuse = Color3(1.f, 1.f, 1.f);\n-\n   // mats\n   auto matEmit             = StandardMaterial::New("matEmit", scene);\n-  matEmit->emissiveColor   = lightDiffuse;\n+  matEmit->emissiveColor   = _lightDiffuse;\n   matEmit->disableLighting = true;\n \n   auto matMetal       = PBRMetallicRoughnessMaterial::New("matMetal", scene);\n@@ -92,7 +91,7 @@ void BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)\n     _light0            = SpotLight::New("light0", _lightPos,\n                              _torus->position().subtract(_lightPos),\n                              Math::PI * 2.f / 3.f, 0.f, scene);\n-    _light0->diffuse   = lightDiffuse;\n+    _light0->diffuse   = _lightDiffuse;\n     _light0->intensity = 20.f;\n     _light0->includedOnlyMeshes().emplace_back(_torus); // <<<<<<<<<<<<<<<<<<<<<\n     auto shadowGen = ShadowGenerator::New(2048, _light0);\n@@ -104,7 +103,7 @@ void BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)\n   // pointlight that lits all meshes excepts the bulb\n   {\n     _light1            = PointLight::New("light1", _lightPos, scene);\n-    _light1->diffuse   = lightDiffuse;\n+    _light1->diffuse   = _lightDiffuse;\n     _light1->intensity = 200.f;\n     _light1->excludedMeshes().emplace_back(_bulb); // <<<<<<<<<<<<<<<<<<<<<<<<<<\n     auto shadowGen  = ShadowGenerator::New(1024, _light1);\n', 'addition_count': 4, 'deletion_count': 5, 'src_file': 'a/src/Samples/src/samples/shadows/bulb_self_shadow_scene.cpp', 'tgt_file': 'b/src/Samples/src/samples/shadows/bulb_self_shadow_scene.cpp', 'file_extension': '.cpp', 'before_file': '#include <babylon/cameras/arc_rotate_camera.h>\n#include <babylon/engines/scene.h>\n#include <babylon/interfaces/irenderable_scene.h>\n#include <babylon/lights/point_light.h>\n#include <babylon/lights/shadows/shadow_generator.h>\n#include <babylon/lights/spot_light.h>\n#include <babylon/materials/pbr/pbr_metallic_roughness_material.h>\n#include <babylon/materials/standard_material.h>\n#include <babylon/maths/color3.h>\n#include <babylon/maths/vector3.h>\n#include <babylon/meshes/builders/mesh_builder_options.h>\n#include <babylon/meshes/mesh.h>\n#include <babylon/meshes/mesh_builder.h>\n#include <babylon/samples/babylon_register_sample.h>\n\nnamespace BABYLON {\nnamespace Samples {\n    : IRenderableScene(iCanvas)\n    , _i{0.f}\n    , _lightPos{Vector3(0.f, 8.f, 0.f)}\n    , _light0{nullptr}\n    , _light1{nullptr}\n    , _torus{nullptr}\n\npublic:\n  BulbSelfShadowScene(ICanvas* iCanvas)\n      : IRenderableScene(iCanvas)\n      , _i{0.f}\n      , _lightPos{Vector3(0.f, 8.f, 0.f)}\n      , _lightDiffuse{Color3(1.f, 1.f, 1.f)}\n      , _light0{nullptr}\n      , _light1{nullptr}\n      , _torus{nullptr}\n      , _bulb{nullptr}\n  {\n\nvoid BulbSelfShadowScene::initializeScene(ICanvas* canvas, Scene* scene)\n{\n  auto lightDiffuse = Color3(1.f, 1.f, 1.f);\n\n  // mats\n  auto matEmit             = StandardMaterial::New("matEmit", scene);\n  matEmit->emissiveColor   = lightDiffuse;\n  matEmit->disableLighting = true;\n\n  auto matMetal       = PBRMetallicRoughnessMaterial::New("matMetal", scene);\n  void initializeScene(ICanvas* canvas, Scene* scene) override\n  {\n    // mats\n    auto matEmit             = StandardMaterial::New("matEmit", scene);\n    matEmit->emissiveColor   = _lightDiffuse;\n    matEmit->disableLighting = true;\n\n    auto matMetal       = PBRMetallicRoughnessMaterial::New("matMetal", scene);\n    matMetal->metallic  = 0.9f;\n    matMetal->roughness = 0.1f;\n    matMetal->baseColor = Color3(1.f, 1.f, 1.f);\n\n    auto matWall       = PBRMetallicRoughnessMaterial::New("matWall", scene);\n    matWall->metallic  = 0.f;\n    matWall->roughness = 1.f;\n    matWall->baseColor = Color3(0.9f, 0.1f, 0.1f);\n\n    // meshes\n    TorusKnotOptions torusKnotOptions;\n    torusKnotOptions.radialSegments  = 200;\n    torusKnotOptions.tubularSegments = 50;\n    torusKnotOptions.sideOrientation = Mesh::FRONTSIDE;\n    _torus               = MeshBuilder::CreateTorusKnot("torus", torusKnotOptions, scene);\n    _torus->position().y = 3.3f;\n    _torus->material     = matMetal;\n\n    SphereOptions bulbOptions;\n    bulbOptions.diameter = 2.f;\n    _bulb                = MeshBuilder::CreateSphere("bulb", bulbOptions, scene);\n    _bulb->position      = _lightPos;\n    _bulb->material      = matEmit;\n\n    BoxOptions roomOptions;\n    roomOptions.width           = 20.f;\n    roomOptions.height          = 20.f;\n    roomOptions.depth           = 20.f;\n    roomOptions.sideOrientation = Mesh::BACKSIDE;\n    auto room                   = MeshBuilder::CreateBox("room", roomOptions, scene);\n    room->material              = matWall;\n\n    BoxOptions groundOptions;\n    groundOptions.width  = 6.f;\n    groundOptions.height = 10.f;\n    groundOptions.depth  = 6.f;\n    auto ground          = MeshBuilder::CreateBox("ground", groundOptions, scene);\n    _light0            = SpotLight::New("light0", _lightPos,\n                             _torus->position().subtract(_lightPos),\n                             Math::PI * 2.f / 3.f, 0.f, scene);\n    _light0->diffuse   = lightDiffuse;\n    _light0->intensity = 20.f;\n    _light0->includedOnlyMeshes().emplace_back(_torus); // <<<<<<<<<<<<<<<<<<<<<\n    auto shadowGen = ShadowGenerator::New(2048, _light0);\n    {\n      _light0          = SpotLight::New("light0", _lightPos, _torus->position().subtract(_lightPos),\n                               Math::PI * 2.f / 3.f, 0.f, scene);\n      _light0->diffuse = _lightDiffuse;\n      _light0->intensity = 20.f;\n  // pointlight that lits all meshes excepts the bulb\n  {\n    _light1            = PointLight::New("light1", _lightPos, scene);\n    _light1->diffuse   = lightDiffuse;\n    _light1->intensity = 200.f;\n    _light1->excludedMeshes().emplace_back(_bulb); // <<<<<<<<<<<<<<<<<<<<<<<<<<\n    auto shadowGen  = ShadowGenerator::New(1024, _light1);\n    // pointlight that lits all meshes excepts the bulb\n    {\n      _light1            = PointLight::New("light1", _lightPos, scene);\n      _light1->diffuse   = _lightDiffuse;\n      _light1->intensity = 200.f;\n      _light1->excludedMeshes().emplace_back(_bulb); // <<<<<<<<<<<<<<<<<<<<<<<<<<\n      auto shadowGen                          = ShadowGenerator::New(1024, _light1);\n      shadowGen->bias                         = 0.0005f;\n      shadowGen->usePercentageCloserFiltering = true;\n      shadowGen->setDarkness(0.3f);\n      shadowGen->addShadowCaster(_torus); // caster\n      shadowGen->addShadowCaster(ground);\n      _torus->receiveShadows = true; // receiver\n      room->receiveShadows   = true; // receiver\n      ground->receiveShadows = true; // receiver\n    }\n\n    // camera\n    auto camera = ArcRotateCamera::New("camera", Math::PI / 3.f, Math::PI * 3.f / 5.f, 9.f,\n                                       _torus->position(), scene, true);\n    camera->attachControl(canvas, true);\n    camera->upperBetaLimit   = Math::PI * 3.f / 4.f;\n    camera->wheelPrecision   = 10.f;\n    camera->upperRadiusLimit = 11.f;\n    camera->lowerRadiusLimit = 5.f;\n\n    // update\n    scene->registerBeforeRender([this](Scene*, EventState&) {\n      _i += 0.008f;\n\n      _lightPos.x = -std::cos(_i) * 8.f;\n      _lightPos.z = std::sin(_i) * 8.f;\n\n      _light0->position  = _lightPos;\n      _light0->direction = _torus->position().subtract(_lightPos);\n\n      _light1->position = _lightPos;\n\n      _bulb->position = _lightPos;\n    });\n  }\n\nprivate:\n  float _i;\n  Vector3 _lightPos;\n  Color3 _lightDiffuse;\n  SpotLightPtr _light0;\n  PointLightPtr _light1;\n  MeshPtr _torus;\n  MeshPtr _bulb;\n\n}; // end of class BulbSelfShadowScene\n\nBABYLON_REGISTER_SAMPLE("Shadows", BulbSelfShadowScene)\n\n} // end of namespace Samples\n} // end of namespace BABYLON\n', 'message': 'Made light diffuse color a class property\n', 'author_name': 'samdauwe', 'lang': 'cpp'}