Skip to content

Commit b2da7e1

Browse files
darksylincahcordemjcarrolliche033chapulina
authored
Add Ogre2Heightmap functionality (#386)
* Ogre2.2 Signed-off-by: ahcorde <[email protected]> * Added media files Signed-off-by: ahcorde <[email protected]> * Added Headless mode Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Add OGRE2.2 to dependencies Signed-off-by: Michael Carroll <[email protected]> * Fixed GPUray and depthCamera test Co-authored-by: Michael Carroll <[email protected]> Signed-off-by: ahcorde <[email protected]> * cast based on pf Signed-off-by: Ian Chen <[email protected]> * Fix cleanup with packaged debs Signed-off-by: Michael Carroll <[email protected]> * fix copy raw data Signed-off-by: Ian Chen <[email protected]> * fix material test Signed-off-by: Ian Chen <[email protected]> * Lint and compiler warning Signed-off-by: Michael Carroll <[email protected]> * Trim whitespace Signed-off-by: Michael Carroll <[email protected]> * Apply gamma correction to sky Signed-off-by: ahcorde <[email protected]> * Test fixes to Ogre2.2 branch (#279) Signed-off-by: Michael Carroll <[email protected]> * Revert gamma correction in the sky Signed-off-by: ahcorde <[email protected]> * enable grayscale albedo map to fix red color highlights and disable hardware gamma to fix dark sky color Signed-off-by: Ian Chen <[email protected]> * Local updates for Ogre2.2 against main branch (#317) * Local updates for Ogre2.2 against main branch Signed-off-by: Ian Chen <[email protected]> Co-authored-by: Ian Chen <[email protected]> * Fix merge Signed-off-by: ahcorde <[email protected]> * fix shadows in ogre 2.2 Signed-off-by: Ian Chen <[email protected]> * Lint Signed-off-by: Michael Carroll <[email protected]> * fix toggling sky Signed-off-by: Ian Chen <[email protected]> * fix camera test Signed-off-by: Ian Chen <[email protected]> * make linters happy Signed-off-by: ahcorde <[email protected]> * make linters happy Signed-off-by: ahcorde <[email protected]> * Fix small regression from merge Signed-off-by: Michael Carroll <[email protected]> * Remove problematic leftover files from 2.1 The mere presence of these files can cause incorrect shader generation or unknown visual bugs. IMPORTANT: The installation folder (i.e. CMAKE_INSTALL_PREFIX) must remove them as well. `make install` won't be enough because it won't remove files, only add new ones or update existing ones. This folder is usually installed in ign/install/share/ignition/ignition-rendering6/ogre2/media/Hlms Signed-off-by: Matias N. Goldberg <[email protected]> * Do not crash on shutdown - ogreRoot may be nullptr - Do not destroy textures already scheduled for destruction Signed-off-by: Matias N. Goldberg <[email protected]> * Remove problematic leftover files from 2.1 (#354) The mere presence of these files can cause incorrect shader generation or unknown visual bugs. IMPORTANT: The installation folder (i.e. CMAKE_INSTALL_PREFIX) must remove them as well. `make install` won't be enough because it won't remove files, only add new ones or update existing ones. This folder is usually installed in ign/install/share/ignition/ignition-rendering6/ogre2/media/Hlms Signed-off-by: Matias N. Goldberg <[email protected]> * Do not crash on shutdown (#355) - ogreRoot may be nullptr - Do not destroy textures already scheduled for destruction Signed-off-by: Matias N. Goldberg <[email protected]> * Removed unused variable Signed-off-by: ahcorde <[email protected]> * Restore FSAA support in 2.2 branch Signed-off-by: Matias N. Goldberg <[email protected]> * Fix changing background color not always taking immediate effect Changed pass_clear in favour of LoadAction::Clear which is more efficient on very modern GPUs and specially TBDR ones. Signed-off-by: Matias N. Goldberg <[email protected]> * Changed pass_clear in favour of LoadAction::Clear which is more efficient on very modern GPUs and specially TBDR ones. Signed-off-by: Matias N. Goldberg <[email protected]> * Missing public keyword Signed-off-by: Matias N. Goldberg <[email protected]> * Save VRAM when FSAA is used and no postprocessing There's an unused texture when these conditions are met (which are fairly common) This memory optimization could not be performed in Ogre 2.1, it needs Ogre 2.2+ Signed-off-by: Matias N. Goldberg <[email protected]> * Remove code deprecated in ign-rendering5 Syntax cosmetic changes for consistency Signed-off-by: Matias N. Goldberg <[email protected]> * Remove code deprecated in ign-rendering5 Signed-off-by: Matias N. Goldberg <[email protected]> * Code style fixes Signed-off-by: Matias N. Goldberg <[email protected]> * Undo VRAM saving optimization: It cannot be applied The "Final Composition" node requires both textures to be resident. Thus 2nd texture must always be resident. The optimization could still be applied if we create two Final Composition nodes (one for when 2 textures are needed, another for when only MSAA + 1 texture is needed) but this would: 1. Hurt code readability too much (i.e. what is going on?) 2. Increase debuggability difficulty too much because codepaths taken would differ depending on whether optimization was applied. Also certain bugs could remain hidden until compositors are toggled. This was causing ogre2_demo to fail. Signed-off-by: Matias N. Goldberg <[email protected]> * Merge main branch into Ogre 2.2 and fixes (#359) * Fix floating point precision bug handling alpha channel (#332) (#333) Fixes #332 Fixes #108 Signed-off-by: Matias N. Goldberg <[email protected]> * Test re-enabling depth camera integration test on mac (#335) * Fix floating point precision bug handling alpha channel (#332) Fixes #332 Fixes #108 Signed-off-by: Matias N. Goldberg <[email protected]> * test reenabling depth camera test on mac Signed-off-by: Ian Chen <[email protected]> Co-authored-by: Matias N. Goldberg <[email protected]> * Fix new [] / delete mismatch (#338) Using a custom deallocator to avoid breaking ABI Alternatively C++17 supports the following syntax, which was not used: `typedef std::shared_ptr<unsigned char[]> DataPtr;` Signed-off-by: Matias N. Goldberg <[email protected]> * Fix heap overflow when reading (#337) PF_RGB is 3 bytes. But later on Ogre2SelectionBuffer::OnSelectionClick will try to read 4 bytes from it. Fixed by ensuring it's always at least 4 bytes and zero-initializing those 4 bytes. Signed-off-by: Matias N. Goldberg <[email protected]> Co-authored-by: Ian Chen <[email protected]> * Fix floating point precision bug handling alpha channel (#332) (#333) Fixes #332 Fixes #108 Signed-off-by: Matias N. Goldberg <[email protected]> * Fix depth alpha (#316) * update test Signed-off-by: Ian Chen <[email protected]> * reenable macos test Signed-off-by: Ian Chen <[email protected]> * fix typo Signed-off-by: Ian Chen <[email protected]> * cherry pick f9f1820 and fix conflicts Signed-off-by: Ian Chen <[email protected]> * Fix FSAA in UI and lower VRAM consumption (#313) * Fix FSAA in UI and lower VRAM consumption FSAA was being requested however due to how the compositor was setup, this effect was not taking effect. Additionally, the Compositor setup was improved to lower memory consumption. Originally the setup was taken from Ogre samples which assume they will ultimately be rendering to a window. However this is not the case and thus IGN was creating 3 render targets (two for ping-ponging between postprocess FXs + one for storing the final result) This was optimized so that we only create 2 render targets: two for ping-ponging between postprocess FXs and we pick at runtime which one is storing the final result via the new variable renderTargetResultsIdx Further performance optimizations could be made in Ogre 2.2 to improve unnecessary MSAA resolving when doing postprocess, though considering there's currently only one postprocessing effect (the Gaussian filter) I doubt this optimization would make much of a difference Signed-off-by: Matias N. Goldberg <[email protected]> * Add Ogre2RenderTarget::RenderTarget back Signed-off-by: Matias N. Goldberg <[email protected]> * Rewrote the compositor changes to support RenderWindows As a bonus this new method breaks ABI far less. Fix leak: DestroyCompositor would often not be called Signed-off-by: Matias N. Goldberg <[email protected]> * Mantain ABI compatibility #Ogre2IsRenderWindowABI When merging to newer branches that can break the ABI, revert this commit Signed-off-by: Matias N. Goldberg <[email protected]> * Fix ABI problems I gave up on commit undoing It's clear that on the next release, Ogre2RenderTarget and Ogre2RenderTexture need to be merged together. Signed-off-by: Matias N. Goldberg <[email protected]> * Fix camel case convention Signed-off-by: Matias N. Goldberg <[email protected]> * Make Ogre2RenderTarget::RenderTarget pure virtual again Hopefully this will prevent ABI breakage Signed-off-by: Matias N. Goldberg <[email protected]> * Fix deprecation warnings during build Signed-off-by: Matias N. Goldberg <[email protected]> * Fix invalid write of size 8 This was causing heap corruption. At best it would crash. At worst it would manifeset in subtle weird behaviors Signed-off-by: Matias N. Goldberg <[email protected]> Co-authored-by: Ian Chen <[email protected]> * Backport memory fixes found by ASAN (#340) * Fix heap overflow when reading (#337) PF_RGB is 3 bytes. But later on Ogre2SelectionBuffer::OnSelectionClick will try to read 4 bytes from it. Fixed by ensuring it's always at least 4 bytes and zero-initializing those 4 bytes. Signed-off-by: Matias N. Goldberg <[email protected]> Co-authored-by: Ian Chen <[email protected]> * Fix new [] / delete mismatch (#338) Using a custom deallocator to avoid breaking ABI Alternatively C++17 supports the following syntax, which was not used: `typedef std::shared_ptr<unsigned char[]> DataPtr;` Signed-off-by: Matias N. Goldberg <[email protected]> Co-authored-by: darksylinc <[email protected]> * recreate node only when needed (#342) Signed-off-by: Ian Chen <[email protected]> * Fix custom shaders uniforms ign version number (#343) Signed-off-by: Ian Chen <[email protected]> * relax gaussian test tolerance (#344) Signed-off-by: Ian Chen <[email protected]> * Update light map tutorial (#346) * apply changes Signed-off-by: Ian Chen <[email protected]> * remove line Signed-off-by: Ian Chen <[email protected]> * add ifdef for apple in integration test Signed-off-by: Ian Chen <[email protected]> * 🎈 4.8.0 (#348) Signed-off-by: Louise Poubel <[email protected]> * update ign-rendering version in custom shaders uniform sample Signed-off-by: Ian Chen <[email protected]> * Remove problematic leftover files from 2.1 The mere presence of these files can cause incorrect shader generation or unknown visual bugs. IMPORTANT: The installation folder (i.e. CMAKE_INSTALL_PREFIX) must remove them as well. `make install` won't be enough because it won't remove files, only add new ones or update existing ones. This folder is usually installed in ign/install/share/ignition/ignition-rendering6/ogre2/media/Hlms Signed-off-by: Matias N. Goldberg <[email protected]> * Do not crash on shutdown - ogreRoot may be nullptr - Do not destroy textures already scheduled for destruction Signed-off-by: Matias N. Goldberg <[email protected]> * Restore FSAA support in 2.2 branch Signed-off-by: Matias N. Goldberg <[email protected]> * Fix changing background color not always taking immediate effect Changed pass_clear in favour of LoadAction::Clear which is more efficient on very modern GPUs and specially TBDR ones. Signed-off-by: Matias N. Goldberg <[email protected]> * Changed pass_clear in favour of LoadAction::Clear which is more efficient on very modern GPUs and specially TBDR ones. Signed-off-by: Matias N. Goldberg <[email protected]> * Missing public keyword Signed-off-by: Matias N. Goldberg <[email protected]> * Save VRAM when FSAA is used and no postprocessing There's an unused texture when these conditions are met (which are fairly common) This memory optimization could not be performed in Ogre 2.1, it needs Ogre 2.2+ Signed-off-by: Matias N. Goldberg <[email protected]> * Remove code deprecated in ign-rendering5 Syntax cosmetic changes for consistency Signed-off-by: Matias N. Goldberg <[email protected]> * Remove code deprecated in ign-rendering5 Signed-off-by: Matias N. Goldberg <[email protected]> * Code style fixes Signed-off-by: Matias N. Goldberg <[email protected]> * Undo VRAM saving optimization: It cannot be applied The "Final Composition" node requires both textures to be resident. Thus 2nd texture must always be resident. The optimization could still be applied if we create two Final Composition nodes (one for when 2 textures are needed, another for when only MSAA + 1 texture is needed) but this would: 1. Hurt code readability too much (i.e. what is going on?) 2. Increase debuggability difficulty too much because codepaths taken would differ depending on whether optimization was applied. Also certain bugs could remain hidden until compositors are toggled. This was causing ogre2_demo to fail. Signed-off-by: Matias N. Goldberg <[email protected]> Co-authored-by: Ian Chen <[email protected]> Co-authored-by: Louise Poubel <[email protected]> * Began work on Heightmaps with Ogre2. Very WIP Hardcoded some paths in CMakeLists to get Terra compiling Signed-off-by: Matias N. Goldberg <[email protected]> * Register HlmsTerra Add its Hlms data files Signed-off-by: Matias N. Goldberg <[email protected]> * Update all Terras and show them on screen (WIP) Signed-off-by: Matias N. Goldberg <[email protected]> * Update to latest Terra to get Z-up support Signed-off-by: Matias N. Goldberg <[email protected]> * Better calculation of heightmap size (WIP) Fix crash when heightmap is deleted Update to latest Terra for setCustomSkirtMinHeight Signed-off-by: Matias N. Goldberg <[email protected]> * Fix shader compiler error Signed-off-by: Matias N. Goldberg <[email protected]> * Fix alignment issues in terrain Signed-off-by: Matias N. Goldberg <[email protected]> * Move Terra to its own folder and project Signed-off-by: Matias N. Goldberg <[email protected]> * Enable assert that was accidentally disabled Signed-off-by: Matias N. Goldberg <[email protected]> * Customize Terra for Ignition's requirements Fix barrier assert Signed-off-by: Matias N. Goldberg <[email protected]> * Use custom blending modes to adjust to ign Signed-off-by: Matias N. Goldberg <[email protected]> * HeightmapTexture::Size is in meters, it's not a scale Now it looks close to the reference in ogre1 No longer normalize weights, it's not needed anymore Also fix bug when 5 texture maps could not be supported Signed-off-by: Matias N. Goldberg <[email protected]> * Use same blending algorithm for roughness & metalness Signed-off-by: Matias N. Goldberg <[email protected]> * Deal with edge case where terrain skirts could be above ground Signed-off-by: Matias N. Goldberg <[email protected]> * Fix wrong indentation Remove dead code Signed-off-by: Matias N. Goldberg <[email protected]> * Forgot to push this change Signed-off-by: Matias N. Goldberg <[email protected]> * Disable alpha blending of detail maps for Terrain Signed-off-by: Matias N. Goldberg <[email protected]> * Add terrain shadows to normal objects Signed-off-by: Matias N. Goldberg <[email protected]> * Fix copyright year Signed-off-by: Matias N. Goldberg <[email protected]> * Re-enable ImageHeightmap It shouldn't have been disabled Signed-off-by: Matias N. Goldberg <[email protected]> * Cosmetic changes Signed-off-by: Matias N. Goldberg <[email protected]> * Move Terra's source code into ogre2/src It is ogre2 specific Signed-off-by: Matias N. Goldberg <[email protected]> * Support ogre1 heightmaps via cropping and warn about it Signed-off-by: Matias N. Goldberg <[email protected]> * Support both ogre2 & ogre engines in heightmap sample Default to ogre2 Signed-off-by: Matias N. Goldberg <[email protected]> * Force-disable JSON parts of Terra It's not used by ignition. This avoids detecting rapidjson during ign build Fix Windows build Signed-off-by: Matias N. Goldberg <[email protected]> * Add license to Terra files Signed-off-by: Matias N. Goldberg <[email protected]> * Update to latest version of Terra Adds spotlight & point shadow map support (not working/set yet) Signed-off-by: Matias N. Goldberg <[email protected]> * Add terrain shadows from spot & point lights Use unique_ptr instead of raw ptrs when possible Signed-off-by: Matias N. Goldberg <[email protected]> * Skip Terra headers in cppcheck They should be treated as external code Signed-off-by: Matias N. Goldberg <[email protected]> * fixing tests Signed-off-by: Ian Chen <[email protected]> * add ifdef Signed-off-by: Ian Chen <[email protected]> * suppress warnings Signed-off-by: Ian Chen <[email protected]> * update syntax Signed-off-by: Ian Chen <[email protected]> * update syntax Signed-off-by: Ian Chen <[email protected]> * Fix crash on shutdown due to ptr destroyed too late It should be destroyed before Ogre Root Signed-off-by: Matias N. Goldberg <[email protected]> * Update to latest Terra to fix bug from upstream Upstream OGRECave/ogre-next@d0a01d2 Signed-off-by: Matias N. Goldberg <[email protected]> * Update to latest Hlms from upstream This fixes some compiler bugs with Terra Also adds supports for HlmsPbs::setShadowReceiversInPixelShader which was written specifically for Gazebo Signed-off-by: Matias N. Goldberg <[email protected]> * Fix compiler warning Signed-off-by: Matias N. Goldberg <[email protected]> * Fix Terra shadows on Spot and Point lights Update Terra to latest from upstream Signed-off-by: Matias N. Goldberg <[email protected]> * Fix Terra's point light shadows Terra's workspace listener was being executed before the camera is rotated for cubemap rendering Signed-off-by: Matias N. Goldberg <[email protected]> * Fix documentation Silence warnings from external code to pass build checks Signed-off-by: Matias N. Goldberg <[email protected]> * fixing CI Signed-off-by: Ian Chen <[email protected]> * add include path Signed-off-by: Ian Chen <[email protected]> * windows warning Signed-off-by: Ian Chen <[email protected]> * fix Signed-off-by: Ian Chen <[email protected]> Co-authored-by: ahcorde <[email protected]> Co-authored-by: Michael Carroll <[email protected]> Co-authored-by: Ian Chen <[email protected]> Co-authored-by: Louise Poubel <[email protected]>
1 parent 4bff736 commit b2da7e1

File tree

66 files changed

+8306
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+8306
-57
lines changed

CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ign_configure_project(VERSION_SUFFIX pre1)
2121
# Set project-specific options
2222
#============================================================================
2323

24+
set(CMAKE_CXX_STANDARD 14)
2425
option(USE_UNOFFICAL_OGRE_VERSIONS "Accept unsupported Ogre versions in the build" OFF)
2526

2627
#============================================================================
@@ -153,9 +154,18 @@ if (HAVE_OGRE2)
153154
list(APPEND RENDERING_COMPONENTS ogre2)
154155
endif()
155156

157+
configure_file("${PROJECT_SOURCE_DIR}/cppcheck.suppress.in"
158+
${PROJECT_BINARY_DIR}/cppcheck.suppress)
159+
156160
ign_configure_build(QUIT_IF_BUILD_ERRORS
157161
COMPONENTS ${RENDERING_COMPONENTS})
158162

163+
if (HAVE_OGRE2)
164+
# Must be done after ign_configure_build or else Terra
165+
# won't see IGN_ADD_fPIC_TO_LIBRARIES
166+
add_subdirectory(ogre2/src/terrain/Terra)
167+
endif()
168+
159169
#============================================================================
160170
# Create package information
161171
#============================================================================

cppcheck.suppress.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*:*/Terra/*.h

examples/heightmap/Main.cc

+11-3
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ void buildScene(ScenePtr _scene)
170170
CameraPtr camera = _scene->CreateCamera("camera");
171171
camera->SetLocalPosition(1.441, 25.787, 17.801);
172172
camera->SetLocalRotation(0.0, 0.588, -1.125);
173-
camera->SetImageWidth(800);
174-
camera->SetImageHeight(600);
173+
camera->SetImageWidth(1600);
174+
camera->SetImageHeight(900);
175175
camera->SetAntiAliasing(2);
176176
camera->SetAspectRatio(1.333);
177177
camera->SetHFOV(IGN_PI / 2);
@@ -207,7 +207,15 @@ int main(int _argc, char** _argv)
207207
std::vector<std::string> engineNames;
208208
std::vector<CameraPtr> cameras;
209209

210-
engineNames.push_back("ogre");
210+
// Expose engine name to command line because we can't instantiate both
211+
// ogre and ogre2 at the same time
212+
std::string ogreEngineName("ogre2");
213+
if (_argc > 1)
214+
{
215+
ogreEngineName = _argv[1];
216+
}
217+
218+
engineNames.push_back(ogreEngineName);
211219

212220
for (auto engineName : engineNames)
213221
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (C) 2021 Open Source Robotics Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
#ifndef IGNITION_RENDERING_OGRE2_OGRE2HEIGHTMAP_HH_
19+
#define IGNITION_RENDERING_OGRE2_OGRE2HEIGHTMAP_HH_
20+
21+
#include <memory>
22+
23+
#include "ignition/rendering/base/BaseHeightmap.hh"
24+
#include "ignition/rendering/ogre2/Ogre2Geometry.hh"
25+
26+
// Ignoring warning: "non dll-interface class
27+
// 'ignition::rendering::v5::Heightmap' used as base for dll-interface class"
28+
// because `Heightmap` and `BaseHeightmap` are header-only
29+
#ifdef _MSC_VER
30+
#pragma warning(push)
31+
#pragma warning(disable:4275)
32+
#endif
33+
34+
namespace Ogre
35+
{
36+
class Camera;
37+
class Terra;
38+
}
39+
40+
namespace ignition
41+
{
42+
namespace rendering
43+
{
44+
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
45+
//
46+
// Forward declaration
47+
class Ogre2HeightmapPrivate;
48+
49+
/// \brief Ogre implementation of a heightmap geometry.
50+
class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2Heightmap
51+
: public BaseHeightmap<Ogre2Geometry>
52+
{
53+
/// \brief Constructor
54+
/// \param[in] _desc Parameters describing how a
55+
/// heightmap should be loaded
56+
public: explicit Ogre2Heightmap(const HeightmapDescriptor &_desc);
57+
58+
/// \brief Destructor
59+
public: virtual ~Ogre2Heightmap() override;
60+
61+
// Documentation inherited.
62+
public: virtual void Init() override;
63+
64+
// Documentation inherited.
65+
public: virtual void PreRender() override;
66+
67+
/// \brief Returns the Terra pointer as it is a movable object that
68+
/// must be attached to a regular SceneNode
69+
/// \remarks This behavior is different from ogre1
70+
/// \return Terra pointer
71+
public: virtual Ogre::MovableObject *OgreObject() const override;
72+
73+
/// \brief Returns NULL, heightmap materials don't inherit from
74+
/// MaterialPtr.
75+
/// \return Null pointer.
76+
public: virtual MaterialPtr Material() const override;
77+
78+
/// \brief Has no effect for heightmaps. The material is set through a
79+
/// HeightmapDescriptor.
80+
/// \param[in] _material Not used.
81+
/// \param[in] _unique Not used.
82+
public: virtual void SetMaterial(MaterialPtr _material, bool _unique)
83+
override;
84+
85+
/// \internal
86+
/// \brief Retrieves the internal Terra pointer
87+
/// \return internal Terra pointer
88+
public: Ogre::Terra* Terra();
89+
90+
/// \internal
91+
/// \brief Must be called before rendering with the camera
92+
/// that will perform rendering.
93+
///
94+
/// May update shadows if light direction changed
95+
/// \param[in] _camera Camera about to be used for rendering
96+
public: void UpdateForRender(Ogre::Camera *_activeCamera);
97+
98+
/// \brief Heightmap should only be created by scene.
99+
private: friend class OgreScene;
100+
101+
/// \brief Private data class
102+
private: std::unique_ptr<Ogre2HeightmapPrivate> dataPtr;
103+
};
104+
}
105+
}
106+
}
107+
#ifdef _MSC_VER
108+
#pragma warning(pop)
109+
#endif
110+
111+
#endif

ogre2/include/ignition/rendering/ogre2/Ogre2RenderEngine.hh

+22
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ namespace Ogre
3939
{
4040
class OverlaySystem;
4141
}
42+
43+
class HlmsPbsTerraShadows;
44+
class CompositorWorkspaceListener;
4245
}
4346

4447
namespace ignition
@@ -175,6 +178,25 @@ namespace ignition
175178
/// \return Pointer to the ogre overlay system.
176179
public: Ogre::v1::OverlaySystem *OverlaySystem() const;
177180

181+
/// \internal
182+
/// \brief Get a pointer to the Pbs listener that adds terra shadows.
183+
/// Do NOT assume HlmsPbs::getListener() == HlmsPbsTerraShadows()
184+
/// as there may be more than one listener in the future with
185+
/// a master listener coordinating them
186+
/// \return Pointer to the Pbs listener that adds terra shadows.
187+
public: Ogre::HlmsPbsTerraShadows *HlmsPbsTerraShadows() const;
188+
189+
/// \internal
190+
/// \brief Get a pointer to the workspace listener that adds terra
191+
/// casting shadows from spot and point lights.
192+
///
193+
/// This listener needs to be added to each workspace that wants
194+
/// terrain shadows from spot/point lights. If no terrains are in scene
195+
/// then the workspace's overhead is negligible / almost 0.
196+
/// \return Pointer to the CompositorWorkspaceListener
197+
public: Ogre::CompositorWorkspaceListener
198+
*TerraWorkspaceListener() const;
199+
178200
/// \brief Pointer to the ogre's overlay system
179201
private: Ogre::v1::OverlaySystem *ogreOverlaySystem = nullptr;
180202

ogre2/include/ignition/rendering/ogre2/Ogre2RenderTypes.hh

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace ignition
3939
class Ogre2GizmoVisual;
4040
class Ogre2GpuRays;
4141
class Ogre2Grid;
42+
class Ogre2Heightmap;
4243
class Ogre2InertiaVisual;
4344
class Ogre2JointVisual;
4445
class Ogre2Light;
@@ -87,6 +88,7 @@ namespace ignition
8788
typedef shared_ptr<Ogre2GizmoVisual> Ogre2GizmoVisualPtr;
8889
typedef shared_ptr<Ogre2GpuRays> Ogre2GpuRaysPtr;
8990
typedef shared_ptr<Ogre2Grid> Ogre2GridPtr;
91+
typedef shared_ptr<Ogre2Heightmap> Ogre2HeightmapPtr;
9092
typedef shared_ptr<Ogre2InertiaVisual> Ogre2InertiaVisualPtr;
9193
typedef shared_ptr<Ogre2JointVisual> Ogre2JointVisualPtr;
9294
typedef shared_ptr<Ogre2Light> Ogre2LightPtr;

ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <memory>
2121
#include <string>
22+
#include <vector>
2223

2324
#include "ignition/rendering/Storage.hh"
2425
#include "ignition/rendering/base/BaseScene.hh"
@@ -135,7 +136,12 @@ namespace ignition
135136
/// \brief When LegacyAutoGpuFlush(), this function mimics
136137
/// legacy behavior.
137138
/// When not, it verifies PreRender has been called
138-
public: void StartRendering();
139+
/// It also performs necessary updates for all heightmaps
140+
///
141+
/// \param _camera camera that is about to render, used
142+
/// by heightmaps (Terra). See Ogre2Scene::UpdateAllHeightmaps
143+
/// Can be null
144+
public: void StartRendering(Ogre::Camera *_camera);
139145

140146
/// \internal
141147
/// \brief Every Render() function calls this function with
@@ -334,6 +340,12 @@ namespace ignition
334340
protected: virtual bool InitObject(Ogre2ObjectPtr _object,
335341
unsigned int _id, const std::string &_name);
336342

343+
/// \internal
344+
/// \brief Iterates through all Heightmaps and calls
345+
/// Ogre2Heightmap::UpdateForRender on each of them
346+
/// \param[in] _camera Camera about to be used for rendering
347+
public: void UpdateAllHeightmaps(Ogre::Camera *_camera);
348+
337349
/// \brief Create a compositor shadow node with the same number of shadow
338350
/// textures as the number of shadow casting lights
339351
protected: void UpdateShadowNode();
@@ -405,6 +417,9 @@ namespace ignition
405417
/// \brief A list of ogre materials
406418
protected: Ogre2MaterialMapPtr materials;
407419

420+
/// \brief A list of ogre heightmaps
421+
protected: std::vector<std::weak_ptr<Ogre2Heightmap>> heightmaps;
422+
408423
/// \brief Pointer to the ogre scene manager
409424
protected: Ogre::SceneManager *ogreSceneManager = nullptr;
410425

ogre2/src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ target_link_libraries(${ogre2_target}
3333
PRIVATE
3434
ignition-plugin${IGN_PLUGIN_VER}::register
3535
${OPENGL_LIBRARIES}
36+
terra
3637
IgnOGRE2::IgnOGRE2)
3738

3839
set (versioned ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME_LOWER}-${engine_name}${CMAKE_SHARED_LIBRARY_SUFFIX})

ogre2/src/Ogre2DepthCamera.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,9 @@ void Ogre2DepthCamera::CreateWorkspaceInstance()
929929
this->dataPtr->ogreCompositorWorkspaceDef,
930930
false);
931931

932+
this->dataPtr->ogreCompositorWorkspace->addListener(
933+
engine->TerraWorkspaceListener());
934+
932935
// add the listener
933936
Ogre::CompositorNode *node =
934937
this->dataPtr->ogreCompositorWorkspace->getNodeSequence()[0];
@@ -959,7 +962,7 @@ void Ogre2DepthCamera::Render()
959962
glEnable(GL_DEPTH_CLAMP);
960963
#endif
961964

962-
this->scene->StartRendering();
965+
this->scene->StartRendering(this->ogreCamera);
963966

964967
// update the compositors
965968
this->dataPtr->ogreCompositorWorkspace->_validateFinalTarget();

ogre2/src/Ogre2GpuRays.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,7 @@ void Ogre2GpuRays::UpdateRenderTarget1stPass()
12131213
// update the compositors
12141214
for (auto i : this->dataPtr->cubeFaceIdx)
12151215
{
1216+
this->scene->UpdateAllHeightmaps(this->dataPtr->cubeCam[i]);
12161217
this->dataPtr->ogreCompositorWorkspace1st[i]->setEnabled(true);
12171218

12181219
this->dataPtr->ogreCompositorWorkspace1st[i]->_validateFinalTarget();
@@ -1244,7 +1245,7 @@ void Ogre2GpuRays::UpdateRenderTarget2ndPass()
12441245
//////////////////////////////////////////////////
12451246
void Ogre2GpuRays::Render()
12461247
{
1247-
this->scene->StartRendering();
1248+
this->scene->StartRendering(nullptr);
12481249

12491250
this->UpdateRenderTarget1stPass();
12501251
this->UpdateRenderTarget2ndPass();

0 commit comments

Comments
 (0)