Skip to content

Commit

Permalink
store name in variable, dbg msg, license, indentation
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Oct 28, 2020
1 parent b7d20aa commit 0823885
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 17 deletions.
11 changes: 8 additions & 3 deletions ogre2/src/Ogre2DepthCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class ignition::rendering::Ogre2DepthCameraPrivate
public: ignition::common::EventT<void(const float *,
unsigned int, unsigned int, unsigned int,
const std::string &)> newDepthFrame;

/// \brief Name of sky box material
public: std::string skyboxMaterialName = "SkyBox";
};

using namespace ignition;
Expand Down Expand Up @@ -291,11 +294,12 @@ void Ogre2DepthCamera::CreateDepthTexture()
if (validBackground)
{
Ogre::MaterialManager &matManager = Ogre::MaterialManager::getSingleton();
std::string skyMatName = "SkyBox_" + this->Name();
std::string skyMatName = this->dataPtr->skyboxMaterialName + "_"
+ this->Name();
auto mat = matManager.getByName(skyMatName);
if (!mat)
{
auto skyboxMat = matManager.getByName("SkyBox");
auto skyboxMat = matManager.getByName(this->dataPtr->skyboxMaterialName);
if (!skyboxMat)
{
ignerr << "Unable to find skybox material" << std::endl;
Expand Down Expand Up @@ -424,7 +428,8 @@ void Ogre2DepthCamera::CreateDepthTexture()
Ogre::CompositorPassQuadDef *passQuad =
static_cast<Ogre::CompositorPassQuadDef *>(
colorTargetDef->addPass(Ogre::PASS_QUAD));
passQuad->mMaterialName = "SkyBox_" + this->Name();
passQuad->mMaterialName = this->dataPtr->skyboxMaterialName + "_"
+ this->Name();
passQuad->mFrustumCorners =
Ogre::CompositorPassQuadDef::CAMERA_DIRECTION;
}
Expand Down
35 changes: 25 additions & 10 deletions ogre2/src/Ogre2RenderTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ class ignition::rendering::Ogre2RenderTargetPrivate
{
/// \brief Listener for chaning compositor pass properties
public: Ogre2RenderTargetCompositorListener *rtListener = nullptr;

/// \brief Name of sky box material
public: std::string skyboxMaterialName = "SkyBox";

/// \brief Name of base rendering compositor node
public: std::string baseNodeName = "PbsMaterialsRenderingNode";

/// \brief Name of final rendering compositor node
public: std::string finalNodeName = "FinalComposition";

/// \brief Name of shadow compositor node
public: std::string shadowNodeName = "PbsMaterialsShadowNode";
};

using namespace ignition;
Expand Down Expand Up @@ -131,7 +143,7 @@ void Ogre2RenderTarget::BuildCompositor()
if (!ogreCompMgr->hasWorkspaceDefinition(wsDefName))
{
// PbsMaterialsRenderingNode
std::string nodeDefName = wsDefName + "/PbsMaterialsRenderingNode";
std::string nodeDefName = wsDefName + "/" + this->dataPtr->baseNodeName;
Ogre::CompositorNodeDef *nodeDef =
ogreCompMgr->addNodeDefinition(nodeDefName);

Expand Down Expand Up @@ -193,7 +205,8 @@ void Ogre2RenderTarget::BuildCompositor()
Ogre::CompositorPassQuadDef *passQuad =
static_cast<Ogre::CompositorPassQuadDef *>(
rt0TargetDef->addPass(Ogre::PASS_QUAD));
passQuad->mMaterialName = "SkyBox_" + this->Name();
passQuad->mMaterialName = this->dataPtr->skyboxMaterialName + "_"
+ this->Name();
passQuad->mFrustumCorners =
Ogre::CompositorPassQuadDef::CAMERA_DIRECTION;
}
Expand All @@ -202,7 +215,7 @@ void Ogre2RenderTarget::BuildCompositor()
Ogre::CompositorPassSceneDef *passScene =
static_cast<Ogre::CompositorPassSceneDef *>(
rt0TargetDef->addPass(Ogre::PASS_SCENE));
passScene->mShadowNode = "PbsMaterialsShadowNode";
passScene->mShadowNode = this->dataPtr->shadowNodeName;
passScene->mIncludeOverlays = true;
}

Expand Down Expand Up @@ -270,9 +283,10 @@ void Ogre2RenderTarget::DestroyCompositor()
ogreCompMgr->removeWorkspace(this->ogreCompositorWorkspace);
ogreCompMgr->removeWorkspaceDefinition(this->ogreCompositorWorkspaceDefName);
ogreCompMgr->removeNodeDefinition(this->ogreCompositorWorkspaceDefName +
"/PbsMaterialsRenderingNode");
"/" + this->dataPtr->baseNodeName);
ogreCompMgr->removeNodeDefinition(this->ogreCompositorWorkspaceDefName +
"/FinalComposition");
"/" + this->dataPtr->finalNodeName);

this->ogreCompositorWorkspace = nullptr;
delete this->dataPtr->rtListener;
this->dataPtr->rtListener = nullptr;
Expand Down Expand Up @@ -448,11 +462,12 @@ void Ogre2RenderTarget::UpdateBackgroundMaterial()
if (validBackground)
{
Ogre::MaterialManager &matManager = Ogre::MaterialManager::getSingleton();
std::string skyMatName = "SkyBox_" + this->Name();
std::string skyMatName = this->dataPtr->skyboxMaterialName + "_"
+ this->Name();
auto mat = matManager.getByName(skyMatName);
if (!mat)
{
auto skyboxMat = matManager.getByName("SkyBox");
auto skyboxMat = matManager.getByName(this->dataPtr->skyboxMaterialName);
if (!skyboxMat)
{
ignerr << "Unable to find skybox material" << std::endl;
Expand Down Expand Up @@ -521,10 +536,10 @@ void Ogre2RenderTarget::UpdateRenderPassChain()
// PbsMaterials.compositor
// the first node is the base scene pass node
std::string outNodeDefName = this->ogreCompositorWorkspaceDefName +
"/PbsMaterialsRenderingNode";
"/" + this->dataPtr->baseNodeName;
// the final compositor node
std::string finalNodeDefName = ogreCompositorWorkspaceDefName +
"/FinalComposition";
"/" + this->dataPtr->finalNodeName;
std::string inNodeDefName;

// if new nodes need to be added then clear everything,
Expand Down Expand Up @@ -660,7 +675,7 @@ void Ogre2RenderTarget::UpdateShadowNode()
}
}

std::string shadowNodeDefName = "PbsMaterialsShadowNode";
std::string shadowNodeDefName = this->dataPtr->shadowNodeName;
if (compositorManager->hasShadowNodeDefinition(shadowNodeDefName))
compositorManager->removeShadowNodeDefinition(shadowNodeDefName);

Expand Down
6 changes: 5 additions & 1 deletion ogre2/src/Ogre2Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class ignition::rendering::Ogre2ScenePrivate
{
/// \brief Flag to indicate if shadows need to be updated
public: bool shadowsDirty = true;

/// \brief Flag to indicate if sky is enabled or not
public: bool skyEnabled = false;
};

using namespace ignition;
Expand Down Expand Up @@ -598,10 +601,11 @@ void Ogre2Scene::SetSkyEnabled(bool _enabled)
camera->SetBackgroundMaterial(skyboxMat);
}
}
this->dataPtr->skyEnabled = _enabled;
}

//////////////////////////////////////////////////
bool Ogre2Scene::SkyEnabled() const
{
return this->BackgroundMaterial() != nullptr;
return this->dataPtr->skyEnabled;
}
32 changes: 31 additions & 1 deletion ogre2/src/media/materials/programs/skybox_fs.glsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
// The code in this file is adapted from OGRE Samples. The OGRE's license and
// copyright header is copied below.

/*
-----------------------------------------------------------------------------
OGRE (www.ogre3d.org) is made available under the MIT License.
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/


#version 330

uniform samplerCube skyCubemap;

in block
{
vec3 cameraDir;
vec3 cameraDir;
} inPs;

out vec3 fragColour;
Expand Down
34 changes: 32 additions & 2 deletions ogre2/src/media/materials/programs/skybox_vs.glsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
// The code in this file is adapted from OGRE Samples. The OGRE's license and
// copyright header is copied below.

/*
-----------------------------------------------------------------------------
OGRE (www.ogre3d.org) is made available under the MIT License.
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/


#version 330

in vec4 vertex;
Expand All @@ -6,12 +36,12 @@ uniform mat4 worldViewProj;

out gl_PerVertex
{
vec4 gl_Position;
vec4 gl_Position;
};

out block
{
vec3 cameraDir;
vec3 cameraDir;
} outVs;

void main()
Expand Down
30 changes: 30 additions & 0 deletions ogre2/src/media/materials/scripts/skybox.material
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
// The code in this file is adapted from OGRE Samples. The OGRE's license and
// copyright header is copied below.

/*
-----------------------------------------------------------------------------
OGRE (www.ogre3d.org) is made available under the MIT License.

Copyright (c) 2000-2013 Torus Knot Software Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/


// GLSL shaders
vertex_program SkyBox_vs glsl
{
Expand Down
18 changes: 18 additions & 0 deletions src/Scene_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ using namespace rendering;
class SceneTest : public testing::Test,
public testing::WithParamInterface<const char *>
{
// Documentation inherited
public: void SetUp() override
{
ignition::common::Console::SetVerbosity(4);
}

public: void Scene(const std::string &_renderEngine);
public: void Nodes(const std::string &_renderEngine);

Expand Down Expand Up @@ -749,6 +755,18 @@ void SceneTest::Sky(const std::string &_renderEngine)
scene->SetSkyEnabled(false);
EXPECT_FALSE(scene->SkyEnabled());

// set background material and verify sky remains disabled
rendering::MaterialPtr mat = scene->CreateMaterial("test_mat");
scene->SetBackgroundMaterial(mat);
EXPECT_EQ(mat, scene->BackgroundMaterial());
EXPECT_FALSE(scene->SkyEnabled());

// enable sky and verify it is not affected by background material
scene->SetSkyEnabled(true);
EXPECT_TRUE(scene->SkyEnabled());
scene->SetBackgroundMaterial(nullptr);
EXPECT_TRUE(scene->SkyEnabled());

// Clean up
engine->DestroyScene(scene);
rendering::unloadEngine(engine->Name());
Expand Down
6 changes: 6 additions & 0 deletions test/integration/sky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ using namespace rendering;
class SkyTest: public testing::Test,
public testing::WithParamInterface<const char *>
{
// Documentation inherited
public: void SetUp() override
{
ignition::common::Console::SetVerbosity(4);
}

// Test and verify sky is created
public: void Sky(const std::string &_renderEngine);
};
Expand Down

0 comments on commit 0823885

Please sign in to comment.