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

Add LensFlarePass (ogre2 engine) #752

Merged
merged 36 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8591135
Add LensFlarePass
darksylinc Oct 23, 2022
adb56f9
Fix lens flare appearing when looking away from sun
darksylinc Oct 23, 2022
680b7ce
Start integrating occlusion into Lens Flare
darksylinc Oct 24, 2022
0b6a5fe
Occlusion scale is finally working
darksylinc Oct 24, 2022
876a2bd
Performance optimization of Ogre2RayQuery (CPU)
darksylinc Oct 24, 2022
7aa402c
Speed up Ogre2RayQuery::ClosestPointByIntersection using multithreading
darksylinc Oct 29, 2022
be207ba
Add parameters to LensFlarePass
darksylinc Oct 29, 2022
171a53c
Add LensFlarePass test
darksylinc Oct 29, 2022
4d876f4
Fix AddRenderPass calls missed if the pass is added late
darksylinc Oct 29, 2022
f2c5ad7
Adding LensFlarePass integration test
darksylinc Oct 29, 2022
63440c2
Port LensFlare shader to Metal
darksylinc Oct 30, 2022
d9e4a41
Add coordinate convention test to LensFlare
darksylinc Oct 30, 2022
fd8ec47
Fix build errors on some systems
darksylinc Oct 30, 2022
4b6a25c
Fix codecheck
darksylinc Oct 30, 2022
2f47102
Fix SLOW_METHOD macro
darksylinc Oct 30, 2022
1ce850d
Ogre2WideAngleCamera is now compatible with RenderPass
darksylinc Nov 6, 2022
8f6ee8b
Add RayQuery::SetFromCamera with WideAngleCamera as input
darksylinc Nov 6, 2022
690f1f4
Support toggling RenderPasses in Ogre2WideAngleCamera
darksylinc Nov 7, 2022
a7c6d5b
Add LensFlare in WideAngleCamera test
darksylinc Nov 7, 2022
6cb9bee
Integration tests passed
darksylinc Nov 7, 2022
a9aca1a
Remove RenderDoc debug calls
darksylinc Nov 7, 2022
4007824
Add fixes based on feedback
darksylinc Nov 12, 2022
7fe29a1
LensFlare's Occlussion Steps API should be uint
darksylinc Nov 12, 2022
0aac38f
Fix test: OcclusionSteps is no longer double
darksylinc Nov 12, 2022
7970cb1
Remove debug code accidentally committed
darksylinc Nov 13, 2022
76d36ee
Fix memory leak
darksylinc Nov 13, 2022
d16a648
Fix uninitialized variable
darksylinc Nov 13, 2022
cf3a3fd
Fix RenderPass integration test failure
darksylinc Nov 13, 2022
c1bb369
Increase uncomparablePixelCount thresholds
darksylinc Nov 15, 2022
d531288
Fix XCode warnings
darksylinc Nov 15, 2022
e8aefc8
Fix Metal shader definition
darksylinc Nov 15, 2022
cba1f87
Fix Windows warnings
darksylinc Nov 15, 2022
b6b88bb
Fix XCode warning
darksylinc Nov 15, 2022
88b5293
Fix Ogre2Scene::SetBackgroundColor being ignored
darksylinc Nov 19, 2022
b7ea98e
Add coordinate convention test for WideAngleCamera
darksylinc Nov 19, 2022
7b175e8
Fix Metal tests failures
darksylinc Nov 19, 2022
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
74 changes: 74 additions & 0 deletions include/gz/rendering/LensFlarePass.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GZ_RENDERING_LENSFLAREPASS_HH_
#define GZ_RENDERING_LENSFLAREPASS_HH_

#include <string>
#include "gz/rendering/config.hh"
#include "gz/rendering/Export.hh"
#include "gz/rendering/RenderPass.hh"

#include "gz/math/Vector3.hh"

namespace gz
{
namespace rendering
{
inline namespace GZ_RENDERING_VERSION_NAMESPACE {

/// \brief A render pass that applies Lens Flare to the render target
class GZ_RENDERING_VISIBLE LensFlarePass
: public virtual RenderPass
{
/// \brief Initializes the Lens Flare Pass with given scene
/// \param[in] _scene Pointer to scene
public: virtual void Init(ScenePtr _scene) = 0;

/// \brief Set the light that generates lens flare
/// \param[in] _light Pointer to light
public: virtual void SetLight(LightPtr _light) = 0;

/// \brief Set the scale of lens flare.
/// \param[in] _scale Scale of lens flare
public: virtual void SetScale(double _scale) = 0;

/// \brief Returns the scale set in SetScale()
/// \return Scale of lens flare
public: virtual double Scale() const = 0;

/// \brief Set the color of lens flare.
/// \param[in] _color Color of lens flare
public: virtual void SetColor(const math::Vector3d &_color) = 0;

/// \brief Returns the color set in SetColor()
/// \return Color of lens flare
public: virtual const math::Vector3d &Color() const = 0;

/// \brief Set the number of steps to take in each direction when
/// checking for occlusions.
/// \param[in] _occlusionSteps number of steps to take in each direction
/// when checking for occlusion. A value of 0 disables occlusion.
public: virtual void SetOcclusionSteps(uint32_t _occlusionSteps) = 0;

/// \brief Returns the number of steps set in SetOcclusionSteps()
/// \return Number of occlusion steps
public: virtual uint32_t OcclusionSteps() const = 0;
};
}
}
}
#endif
30 changes: 30 additions & 0 deletions include/gz/rendering/RayQuery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,36 @@ namespace gz
public: virtual void SetFromCamera(const CameraPtr &_camera,
const math::Vector2d &_coord) = 0;

/// \brief Create the ray query from WideAngleCamera
/// \param[in] _camera Camera to construct ray
/// \param[in] _faceIdx In range [0; 6)
/// * 0 = +X
/// * 1 = -X
/// * 2 = +Y
/// * 3 = -Y
/// * 4 = +Z
/// * 5 = -Z
/// \param[in] _coord normalized device coords [-1, +1]
public: virtual void SetFromCamera(const WideAngleCameraPtr &_camera,
uint32_t _faceIdx,
const math::Vector2d &_coord) = 0;

/// \brief If possible & supported (and user called SetFromCamera())
/// will use the GPU to perform the ray query.
/// Triangle-level accurate.
/// \remark It's not guaranteed the GPU will be used. See UsesGpu()
/// \remark Using the GPU is not necessarily faster.
/// \param[in] _preferGpu True to use the GPU if available & possible.
/// False to never use the GPU.
public: virtual void SetPreferGpu(bool _preferGpu) = 0;

/// \brief Returns true if the GPU will be used for the next
/// ClosestPoint() call.
/// \remark The thread ID is important. Calling this value from
/// different threads may result in different return values.
/// \return True if next ClosestPoint() call will use the GPU.
public: virtual bool UsesGpu() const = 0;

/// \brief Compute intersections
/// \param[in] _forceSceneUpdate Performance optimization hint
/// When true Ogre2 will update all derived transforms to their
Expand Down
6 changes: 6 additions & 0 deletions include/gz/rendering/RenderPass.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ namespace gz
/// \brief Get whether or not the render pass is enabled
/// \return True if the render pass is enabled, false otherwise.
public: virtual bool IsEnabled() const = 0;

/// \brief See Object::PreRender. This function will call
/// Object::PreRender but with the added bonus that it has access
/// to the camera that is about to render
/// \param[in] _camera Camera that is about to render
public: virtual void PreRender(const CameraPtr &_camera) = 0;
};
}
}
Expand Down
6 changes: 6 additions & 0 deletions include/gz/rendering/RenderTarget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ namespace gz
/// \return Render target background color.
public: virtual math::Color BackgroundColor() const = 0;

/// \brief See Object::PreRender. This function will call
/// Object::PreRender but with the added bonus that it has access
/// to the camera that is about to render
/// \param[in] _camera Camera that is about to render
public: virtual void PreRender(const CameraPtr &_camera) = 0;

/// \brief Add a render pass to the render target
/// \param[in] _pass New render pass to add
public: virtual void AddRenderPass(const RenderPassPtr &_pass) = 0;
Expand Down
5 changes: 5 additions & 0 deletions include/gz/rendering/RenderTypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace gz
class Heightmap;
class Image;
class InertiaVisual;
class LensFlarePass;
class Light;
class LightVisual;
class JointVisual;
Expand Down Expand Up @@ -175,6 +176,10 @@ namespace gz
/// \def Shared pointer to InertiaVisual
typedef shared_ptr<InertiaVisual> InertiaVisualPtr;

/// \typedef LensFlarePassPtr
/// \brief Shared pointer to LensFlarePass
typedef shared_ptr<LensFlarePass> LensFlarePassPtr;

/// \typedef LightPtr
/// \brief Shared pointer to Light
typedef shared_ptr<Light> LightPtr;
Expand Down
6 changes: 5 additions & 1 deletion include/gz/rendering/base/BaseCamera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,11 @@ namespace gz
{
T::PreRender();

this->RenderTarget()->PreRender();
{
CameraPtr camera =
std::dynamic_pointer_cast<Camera>(this->shared_from_this());
this->RenderTarget()->PreRender(camera);
}

// camera following
if (this->followNode)
Expand Down
73 changes: 73 additions & 0 deletions include/gz/rendering/base/BaseLensFlarePass.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GZ_RENDERING_BASE_BASELENSFLAREPASS_HH_
#define GZ_RENDERING_BASE_BASELENSFLAREPASS_HH_

#include <string>
#include <gz/math/Rand.hh>

#include "gz/rendering/LensFlarePass.hh"

namespace gz
{
namespace rendering
{
inline namespace GZ_RENDERING_VERSION_NAMESPACE {

/// \brief Base Gaussian noise render pass.
template <class T>
class BaseLensFlarePass :
public virtual LensFlarePass,
public virtual T
{
/// \brief Constructor
protected: BaseLensFlarePass();

/// \brief Destructor
public: virtual ~BaseLensFlarePass() override;

// Documentation inherited
public: void SetLight(LightPtr _light) override;

/// Light that generates the lens flare
protected: LightPtr light;
};

//////////////////////////////////////////////////
// BaseLensFlarePass
//////////////////////////////////////////////////
template <class T>
BaseLensFlarePass<T>::BaseLensFlarePass()
{
}

//////////////////////////////////////////////////
template <class T>
BaseLensFlarePass<T>::~BaseLensFlarePass()
{
}

//////////////////////////////////////////////////
template <class T>
void BaseLensFlarePass<T>::SetLight(LightPtr _light)
{
this->light = _light;
}
}
}
}
#endif
19 changes: 19 additions & 0 deletions include/gz/rendering/base/BaseRayQuery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ namespace gz
public: virtual void SetFromCamera(const CameraPtr &_camera,
const math::Vector2d &_coord) override;

// Documentation inherited
public: void SetPreferGpu(bool _preferGpu) override;

// Documentation inherited
public: bool UsesGpu() const override;

// Documentation inherited
public: virtual RayQueryResult ClosestPoint(
bool _forceSceneUpdate = true) override;
Expand Down Expand Up @@ -141,6 +147,19 @@ namespace gz
this->direction = dir;
}

//////////////////////////////////////////////////
template <class T>
void BaseRayQuery<T>::SetPreferGpu(bool /*_preferGpu*/) // NOLINT
{
}

//////////////////////////////////////////////////
template <class T>
bool BaseRayQuery<T>::UsesGpu() const
{
return false;
}

//////////////////////////////////////////////////
template <class T>
RayQueryResult BaseRayQuery<T>::ClosestPoint(
Expand Down
11 changes: 11 additions & 0 deletions include/gz/rendering/base/BaseRenderPass.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace gz
// Documentation inherited
public: virtual bool IsEnabled() const override;

// Documentation inherited
public: void PreRender(const CameraPtr &_camera) override;

/// \brief Flag to indicate if render pass is enabled or not
protected: bool enabled = true;
};
Expand Down Expand Up @@ -78,6 +81,14 @@ namespace gz
{
return this->enabled;
}

//////////////////////////////////////////////////
template <class T>
void BaseRenderPass<T>::PreRender(const CameraPtr &/*_camera*/)
{
T *thisT = this;
thisT->PreRender(); // NOT the same as doing T::PreRender
}
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions include/gz/rendering/base/BaseRenderTarget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ namespace gz

public: virtual ~BaseRenderTarget();

// Documentation inherited.
public: virtual void PreRender(const CameraPtr &_camera) override;

// Documentation inherited.
public: virtual void PreRender() override;

Expand Down Expand Up @@ -157,14 +160,21 @@ namespace gz
{
}

//////////////////////////////////////////////////
template <class T>
void BaseRenderTarget<T>::PreRender(const CameraPtr &_camera)
{
this->PreRender();
for (auto &pass : this->renderPasses)
pass->PreRender(_camera);
}

//////////////////////////////////////////////////
template <class T>
void BaseRenderTarget<T>::PreRender()
{
T::PreRender();
this->Rebuild();
for (auto &pass : this->renderPasses)
pass->PreRender();
}

//////////////////////////////////////////////////
Expand Down
9 changes: 7 additions & 2 deletions ogre/include/gz/rendering/ogre/OgreRayQuery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ namespace gz
protected: OgreRayQuery();

/// \brief Destructor
public: virtual ~OgreRayQuery();
public: virtual ~OgreRayQuery() override;

// Documentation inherited
public: virtual void SetFromCamera(const CameraPtr &_camera,
const math::Vector2d &_coord);
const math::Vector2d &_coord) override;

// Documentation inherited
public: void SetFromCamera(const WideAngleCameraPtr &_camera,
uint32_t _faceIdx,
const math::Vector2d &_coord) override;

// Documentation inherited
public: virtual RayQueryResult ClosestPoint(
Expand Down
9 changes: 9 additions & 0 deletions ogre/src/OgreRayQuery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ void OgreRayQuery::SetFromCamera(const CameraPtr &_camera,
this->direction = OgreConversions::Convert(ray.getDirection());
}

//////////////////////////////////////////////////
void OgreRayQuery::SetFromCamera(const WideAngleCameraPtr & /*_camera*/,
uint32_t /*_faceIdx*/,
const math::Vector2d & /*_coord*/)
{
gzerr << "Not Implemented" << std::endl;
throw;
}

//////////////////////////////////////////////////
RayQueryResult OgreRayQuery::ClosestPoint(bool /*_forceSceneUpdate*/) // NOLINT
{
Expand Down
Loading