Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose lighting setup and individual object lighting manipulation #500

Merged
merged 23 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
42614d8
update drawables to reference shader manager
matthewjmay Feb 6, 2020
e2be1ad
fix test failure by turning BUILD_DEPRECATED off
matthewjmay Feb 12, 2020
de53150
format error
matthewjmay Feb 12, 2020
c9a8d5b
more lint errors
matthewjmay Feb 12, 2020
d4b5e72
address comments
matthewjmay Feb 13, 2020
31f8123
Merge branch 'master' into simpler-shader-manager
matthewjmay Feb 13, 2020
1e1d660
fix test failure by closing sim
matthewjmay Feb 13, 2020
a094aac
try another test fix
matthewjmay Feb 13, 2020
dcb61c2
change default specularity to no highlights
matthewjmay Feb 14, 2020
210e342
Merge branch 'master' into simpler-shader-manager
matthewjmay Feb 18, 2020
7b2e668
don't skip multiple sim test
matthewjmay Feb 18, 2020
7644d89
support manipulation of light setup used for individual physics objects
matthewjmay Feb 15, 2020
0771462
expose light setup selection to simulator
matthewjmay Feb 15, 2020
f564109
add python bindings for creating and getting light setups
matthewjmay Feb 19, 2020
645da28
add tests
matthewjmay Feb 19, 2020
e522b14
fix default parameter array to pointer decay issue
matthewjmay Feb 19, 2020
9ccd8f0
review comments
matthewjmay Feb 19, 2020
60f0648
Merge branch 'master' into entity-lighting-options
matthewjmay Feb 19, 2020
e61a6c5
merge issues
matthewjmay Feb 19, 2020
62925ef
add screenshot tests for different lighting configurations
matthewjmay Feb 20, 2020
32400ea
review comments
matthewjmay Feb 20, 2020
ef2cd97
ignore max pixel difference in tests
matthewjmay Feb 25, 2020
44b66a6
Merge remote-tracking branch 'origin/master' into entity-lighting-opt…
matthewjmay Feb 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions data/test_assets/testing.phys_scene_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"physics simulator": "bullet",
"timestep": 0.0041666666,
"gravity": [0,-9.8,0],
"friction coefficient": 0.4,
"restitution coefficient": 0.1,
"rigid object paths":[
"objects/nested_box"
]
}
20 changes: 18 additions & 2 deletions habitat_sim/gfx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from habitat_sim._ext.habitat_sim_bindings import Camera, Renderer, RenderTarget
from habitat_sim._ext.habitat_sim_bindings import (
DEFAULT_LIGHTING_KEY,
NO_LIGHT_KEY,
Camera,
LightInfo,
LightPositionModel,
Renderer,
RenderTarget,
)

__all__ = ["Camera", "Renderer", "RenderTarget"]
__all__ = [
"Camera",
"Renderer",
"RenderTarget",
"LightPositionModel",
"LightInfo",
"DEFAULT_LIGHTING_KEY",
"NO_LIGHT_KEY",
]
15 changes: 13 additions & 2 deletions habitat_sim/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import habitat_sim.bindings as hsim
import habitat_sim.errors
from habitat_sim.agent import Agent, AgentConfiguration, AgentState
from habitat_sim.gfx import DEFAULT_LIGHTING_KEY
from habitat_sim.logging import logger
from habitat_sim.nav import GreedyGeodesicFollower, NavMeshSettings
from habitat_sim.physics import MotionType
Expand Down Expand Up @@ -273,8 +274,8 @@ def __del__(self):
self.close()

# --- physics functions ---
def add_object(self, object_lib_index):
return self._sim.add_object(object_lib_index)
def add_object(self, object_lib_index, light_setup_key=DEFAULT_LIGHTING_KEY):
return self._sim.add_object(object_lib_index, light_setup_key=light_setup_key)

def get_physics_object_library_size(self):
return self._sim.get_physics_object_library_size()
Expand Down Expand Up @@ -324,6 +325,16 @@ def get_world_time(self, scene_id=0):
def recompute_navmesh(self, pathfinder, navmesh_settings):
return self._sim.recompute_navmesh(pathfinder, navmesh_settings)

# --- lighting functions ---
def get_light_setup(self, key=DEFAULT_LIGHTING_KEY):
return self._sim.get_light_setup(key)

def set_light_setup(self, light_setup, key=DEFAULT_LIGHTING_KEY):
self._sim.set_light_setup(light_setup, key)

def set_object_light_setup(self, object_id, light_setup_key, scene_id=0):
self._sim.set_object_light_setup(object_id, light_setup_key, scene_id)


class Sensor:
r"""Wrapper around habitat_sim.Sensor
Expand Down
10 changes: 5 additions & 5 deletions src/esp/assets/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ PhysicsManagerAttributes ResourceManager::loadPhysicsConfig(
//! For load-only: set parent = nullptr, drawables = nullptr
int ResourceManager::loadObject(const std::string& objPhysConfigFilename,
scene::SceneNode* parent,
DrawableGroup* drawables) {
DrawableGroup* drawables,
const Mn::ResourceKey& lightSetup) {
// Load Object from config
const bool objectIsLoaded =
physicsObjectLibrary_.count(objPhysConfigFilename) > 0;
Expand Down Expand Up @@ -441,8 +442,7 @@ int ResourceManager::loadObject(const std::string& objPhysConfigFilename,
physicsObjectAttributes.getMagnumVec3("scale");
scalingNode.setScaling(objectScaling);

// TODO: make lighting selection configurable
addComponent(meshMetaData, scalingNode, DEFAULT_LIGHTING_KEY, drawables,
addComponent(meshMetaData, scalingNode, lightSetup, drawables,
meshMetaData.root);
// compute the full BB hierarchy for the new tree.
parent->computeCumulativeBB();
Expand Down Expand Up @@ -1465,8 +1465,8 @@ void ResourceManager::addPrimitiveToDrawables(int primitiveID,
DEFAULT_LIGHTING_KEY, DEFAULT_MATERIAL_KEY, drawables);
}

void ResourceManager::setLightSetup(const Mn::ResourceKey& key,
gfx::LightSetup setup) {
void ResourceManager::setLightSetup(gfx::LightSetup setup,
const Mn::ResourceKey& key) {
shaderManager_.set(key, std::move(setup), Mn::ResourceDataState::Mutable,
Mn::ResourcePolicy::Manual);
}
Expand Down
32 changes: 18 additions & 14 deletions src/esp/assets/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "esp/gfx/MaterialData.h"
#include "esp/gfx/ShaderManager.h"
#include "esp/gfx/configure.h"
#include "esp/physics/PhysicsManager.h"
#include "esp/scene/SceneNode.h"

// forward declarations
Expand Down Expand Up @@ -75,6 +74,15 @@ class ResourceManager {
/** @brief Convenience typedef for Importer class */
using Importer = Magnum::Trade::AbstractImporter;

//! @brief The @ref ShaderManager key for @ref LightInfo which has no lights
static constexpr char NO_LIGHT_KEY[] = "no_lights";

//! @brief The @ref ShaderManager key for the default @ref LightInfo
static constexpr char DEFAULT_LIGHTING_KEY[] = "";

//! @brief The @ref ShaderManager key for the default @ref MaterialInfo
static constexpr char DEFAULT_MATERIAL_KEY[] = "";

/**
* @brief Set whether textures should be compressed.
* @param newVal New texture compression setting.
Expand Down Expand Up @@ -192,7 +200,9 @@ class ResourceManager {
*/
int loadObject(const std::string& objPhysConfigFilename,
scene::SceneNode* parent,
DrawableGroup* drawables);
DrawableGroup* drawables,
const Magnum::ResourceKey& lightSetup = Magnum::ResourceKey{
DEFAULT_LIGHTING_KEY});

/**
* @brief Load and parse a physics object template config file and generates a
Expand Down Expand Up @@ -346,25 +356,19 @@ class ResourceManager {
* If this name already exists, the @ref LightSetup is updated and all @ref
* Drawables using this setup are updated.
*
* @param setup Light setup this key will now reference
* @param key Key to identify this @ref LightSetup
* @param setup Light setup this key will now references
*/
void setLightSetup(const Magnum::ResourceKey& key, gfx::LightSetup setup);
void setLightSetup(gfx::LightSetup setup,
const Magnum::ResourceKey& key = Magnum::ResourceKey{
DEFAULT_LIGHTING_KEY});

/**
* @brief Get a named @ref LightSetup
*/
Magnum::Resource<gfx::LightSetup> getLightSetup(
const Magnum::ResourceKey& key);

//! @brief The @ref ShaderManager key for @ref LightInfo which has no lights
static constexpr char NO_LIGHT_KEY[] = "no_lights";

//! @brief The @ref ShaderManager key for the default @ref LightInfo
static constexpr char DEFAULT_LIGHTING_KEY[] = "default_lighting";

//! @brief The @ref ShaderManager key for the default @ref MaterialInfo
static constexpr char DEFAULT_MATERIAL_KEY[] = "default_material";
const Magnum::ResourceKey& key = Magnum::ResourceKey{
DEFAULT_LIGHTING_KEY});

protected:
//======== Scene Functions ========
Expand Down
22 changes: 22 additions & 0 deletions src/esp/bindings/GfxBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <Magnum/Python.h>
#include <Magnum/SceneGraph/Python.h>

#include "esp/assets/ResourceManager.h"
#include "esp/gfx/LightSetup.h"
#include "esp/gfx/RenderCamera.h"
#include "esp/gfx/Renderer.h"
#include "esp/scene/SemanticScene.h"
Expand Down Expand Up @@ -111,6 +113,26 @@ void initGfxBindings(py::module& m) {
#endif
.def("render_enter", &RenderTarget::renderEnter)
.def("render_exit", &RenderTarget::renderExit);

py::enum_<LightPositionModel>(m, "LightPositionModel")
.value("CAMERA", LightPositionModel::CAMERA)
.value("GLOBAL", LightPositionModel::GLOBAL)
.value("OBJECT", LightPositionModel::OBJECT);

py::class_<LightInfo>(m, "LightInfo")
.def(py::init())
.def(py::init<Magnum::Vector3, Magnum::Color4, LightPositionModel>(),
"position"_a, "color"_a = Magnum::Color4{1},
"model"_a = LightPositionModel::GLOBAL)
.def_readwrite("position", &LightInfo::position)
.def_readwrite("color", &LightInfo::color)
.def_readwrite("model", &LightInfo::model)
.def(py::self == py::self)
.def(py::self != py::self);

m.attr("DEFAULT_LIGHTING_KEY") =
assets::ResourceManager::DEFAULT_LIGHTING_KEY;
m.attr("NO_LIGHT_KEY") = assets::ResourceManager::NO_LIGHT_KEY;
}

} // namespace gfx
Expand Down
16 changes: 13 additions & 3 deletions src/esp/bindings/SimBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ void initSimBindings(py::module& m) {
&Simulator::setFrustumCullingEnabled,
R"(Enable or disable the frustum culling)")
/* --- Physics functions --- */
.def("add_object", &Simulator::addObject, "object_lib_index"_a,
"scene_id"_a = 0)
.def("add_object", py::overload_cast<int, int>(&Simulator::addObject),
"object_lib_index"_a, "scene_id"_a = 0)
.def("add_object",
py::overload_cast<int, const std::string&, int>(
&Simulator::addObject),
"object_lib_index"_a, "light_setup_key"_a, "scene_id"_a = 0)
.def("get_physics_object_library_size",
&Simulator::getPhysicsObjectLibrarySize)
.def("remove_object", &Simulator::removeObject, "object_id"_a,
Expand Down Expand Up @@ -105,7 +109,13 @@ void initSimBindings(py::module& m) {
.def("contact_test", &Simulator::contactTest, "object_id"_a,
"sceneID"_a = 0)
.def("recompute_navmesh", &Simulator::recomputeNavMesh, "pathfinder"_a,
"navmesh_settings"_a);
"navmesh_settings"_a)
.def("get_light_setup", &Simulator::getLightSetup,
"key"_a = assets::ResourceManager::DEFAULT_LIGHTING_KEY)
.def("set_light_setup", &Simulator::setLightSetup, "light_setup"_a,
"key"_a = assets::ResourceManager::DEFAULT_LIGHTING_KEY)
.def("set_object_light_setup", &Simulator::setObjectLightSetup,
"object_id"_a, "light_setup_key"_a, "scene_id"_a = 0);
}

} // namespace sim
Expand Down
1 change: 1 addition & 0 deletions src/esp/gfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(gfx_SOURCES
WindowlessContext.h
RenderTarget.cpp
RenderTarget.h
ShaderManager.cpp
ShaderManager.h
)

Expand Down
8 changes: 8 additions & 0 deletions src/esp/gfx/LightSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
namespace esp {
namespace gfx {

bool operator==(const LightInfo& a, const LightInfo& b) {
return a.position == b.position && a.color == b.color && a.model == b.model;
}

bool operator!=(const LightInfo& a, const LightInfo& b) {
return !(a == b);
}

Magnum::Vector3 getLightPositionRelativeToCamera(
const LightInfo& light,
const Magnum::Matrix4& transformationMatrix,
Expand Down
3 changes: 3 additions & 0 deletions src/esp/gfx/LightSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ struct LightInfo {
LightPositionModel model = LightPositionModel::GLOBAL;
};

bool operator==(const LightInfo& a, const LightInfo& b);
bool operator!=(const LightInfo& a, const LightInfo& b);

using LightSetup = std::vector<LightInfo>;

/**
Expand Down
23 changes: 23 additions & 0 deletions src/esp/gfx/ShaderManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Facebook, Inc. and its affiliates.
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

#include "ShaderManager.h"

#include "esp/core/esp.h"
#include "esp/gfx/Drawable.h"
#include "esp/scene/SceneNode.h"

namespace esp {
namespace gfx {

void setLightSetupForSubTree(scene::SceneNode& root,
const Magnum::ResourceKey& lightSetup) {
scene::preOrderFeatureTraversalWithCallback<Drawable>(
root, [&lightSetup](Drawable& drawable) {
drawable.setLightSetup(lightSetup);
});
}
matthewjmay marked this conversation as resolved.
Show resolved Hide resolved

} // namespace gfx
} // namespace esp
11 changes: 11 additions & 0 deletions src/esp/gfx/ShaderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@ using ShaderManager = Magnum::ResourceManager<Magnum::GL::AbstractShaderProgram,
gfx::LightSetup,
gfx::MaterialData>;

/**
* @brief Set the light setup for a subtree
*
* All drawables in the subtree starting at root will have the new lightSetup
*
* @param root Subtree root
* @param lightSetup @ref LightSetup key in the ShaderManager
*/
void setLightSetupForSubTree(scene::SceneNode& root,
const Magnum::ResourceKey& lightSetup);

} // namespace gfx
} // namespace esp
25 changes: 17 additions & 8 deletions src/esp/physics/PhysicsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "PhysicsManager.h"
#include "esp/assets/CollisionMeshData.h"
#include "esp/assets/ResourceManager.h"

#include <Magnum/Math/Range.h>

Expand Down Expand Up @@ -48,7 +47,8 @@ bool PhysicsManager::addScene(
}

int PhysicsManager::addObject(const int objectLibIndex,
DrawableGroup* drawables) {
DrawableGroup* drawables,
const Magnum::ResourceKey& lightSetup) {
const std::string configFile =
resourceManager_->getObjectConfig(objectLibIndex);

Expand All @@ -67,8 +67,9 @@ int PhysicsManager::addObject(const int objectLibIndex,

//! Draw object via resource manager
//! Render node as child of physics node
resourceManager_->loadObject(
configFile, &existingObjects_.at(nextObjectID_)->node(), drawables);
resourceManager_->loadObject(configFile,
&existingObjects_.at(nextObjectID_)->node(),
drawables, lightSetup);

if (physicsObjectAttributes.existsAs(assets::DataType::BOOL,
"COM_provided")) {
Expand All @@ -86,10 +87,11 @@ int PhysicsManager::addObject(const int objectLibIndex,
}

int PhysicsManager::addObject(const std::string& configFile,
DrawableGroup* drawables) {
DrawableGroup* drawables,
const Magnum::ResourceKey& lightSetup) {
int resObjectID = resourceManager_->getObjectID(configFile);
//! Invoke resourceManager to draw object
int physObjectID = addObject(resObjectID, drawables);
int physObjectID = addObject(resObjectID, drawables, lightSetup);
return physObjectID;
}

Expand Down Expand Up @@ -471,9 +473,16 @@ void PhysicsManager::setObjectBBDraw(int physObjectID,
}
}

const scene::SceneNode& PhysicsManager::getObjectSceneNode(int physObjectID) {
const scene::SceneNode& PhysicsManager::getObjectSceneNode(
int physObjectID) const {
assertIDValidity(physObjectID);
return existingObjects_[physObjectID]->node();
return existingObjects_.at(physObjectID)->node();
}

scene::SceneNode& PhysicsManager::getObjectSceneNode(int physObjectID) {
return const_cast<scene::SceneNode&>(
const_cast<const PhysicsManager&>(*this).getObjectSceneNode(
physObjectID));
}

} // namespace physics
Expand Down
Loading