-
Notifications
You must be signed in to change notification settings - Fork 52
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 shadow texture size for directional lighting in SDF #1034
Conversation
ogre2/src/Ogre2Scene.cc
Outdated
@@ -15,6 +15,8 @@ | |||
* | |||
*/ | |||
|
|||
#include <GL/gl.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll need to use ifdef here as the file path is different on different platforms, see
gz-rendering/ogre2/src/Ogre2Marker.cc
Lines 18 to 26 in f606a32
#ifdef __APPLE__ | |
#define GL_SILENCE_DEPRECATION | |
#include <OpenGL/gl.h> | |
#include <OpenGL/glext.h> | |
#else | |
#ifndef _WIN32 | |
#include <GL/gl.h> | |
#endif | |
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it here - 3b1bc7a
include/gz/rendering/Scene.hh
Outdated
unsigned int _textureSize) = 0; | ||
|
||
/// @brief \brief Get the shadow texture size for the given light type. | ||
/// @param _lightType Light type that creates the shadow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: replace @
with \
for consistency with other doxygen comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (_lightType == LightType::LT_DIRECTIONAL) | ||
{ | ||
this->dataPtr->dirTexSize = _textureSize; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this block to the top of the function so that we just return early if it's not a supported light type. Also add an else block with gzwarn
msg if user specifies spot or point lights.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3b1bc7a. I also have a check for it in MinimalScene
too
ogre2/src/Ogre2Scene.cc
Outdated
unsigned int Ogre2Scene::ShadowTextureSize(LightType _lightType) const | ||
{ | ||
// todo: return based on light type, currently only dir light is supported | ||
if (_lightType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also make spotPointTexSize
a member variable so that you can support returning point and spot light shadow texture size here. The user just won't be able to set them yet.
then you can use switch
to check _lightType
and return the corresponding texture size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/base/BaseScene.cc
Outdated
////////////////////////////////////////////////// | ||
unsigned int BaseScene::ShadowTextureSize(LightType _lightType) const | ||
{ | ||
return this->ShadowTextureSize(_lightType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just print an error here:
gzerr << "Shadow texture size not supported by: "
<< this->Engine()->Name() << std::endl;
ogre2 implements this function so the user should not see the error msg since it should call the ShadowTextureSize
from the derived class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ogre2/src/Ogre2Scene.cc
Outdated
unsigned int _textureSize) | ||
{ | ||
// If _textureSize exceeds max possible tex size, then use default | ||
if (_textureSize > this->dataPtr->maxTexSize / 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just checking, what's the reason for the divide by 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My maxTexSize
is 32K, and I allow texsizes (that are pow of 2 vals) up to 16K. If I set _textureSize
to 32K this happens:
The pitch-black shadow here is from the point light. Compared to the images attached to original PR post, the shadow created by directional light is gone. I think this is maybe because the math on atlasResolution
went crazy. (doesn't fit within atlas?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I tested with 16K max tex size as that's what my machine supports and it works fine. So how about instead of dividing by 2, we set a hard cap on the max tex size to 16K? I remembered and found this comment mentioning the 16K texture size cap as well.
You can do this above when setting this->dataPtr->maxTexSize, e.g.
this->dataPtr->maxTexSize = std::min(glMaxTexSize, 16384u)
and add a todo note mentioning that there are issues with dir shadows when setting to a number larger than 16K.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ogre2/src/Ogre2Scene.cc
Outdated
bool validTexSize = std::find(texSizeOptions.begin(), | ||
texSizeOptions.end(), _textureSize) | ||
!= texSizeOptions.end() ? true : false; | ||
if (!validTexSize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of generating a list of possible tex size options, I think you can simplify this check to
if (_textureSize >= 1024u && math::isPowerOfTwo(_textureSize)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is a good idea. 3b1bc7a
you'll need to retarget this to |
ogre2/src/Ogre2Scene.cc
Outdated
unsigned int _textureSize) | ||
{ | ||
// If _textureSize exceeds max possible tex size, then use default | ||
if (_textureSize > this->dataPtr->maxTexSize / 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I tested with 16K max tex size as that's what my machine supports and it works fine. So how about instead of dividing by 2, we set a hard cap on the max tex size to 16K? I remembered and found this comment mentioning the 16K texture size cap as well.
You can do this above when setting this->dataPtr->maxTexSize, e.g.
this->dataPtr->maxTexSize = std::min(glMaxTexSize, 16384u)
and add a todo note mentioning that there are issues with dir shadows when setting to a number larger than 16K.
enum class GZ_RENDERING_VISIBLE LightType | ||
{ | ||
/// \brief No light type specified | ||
EMPTY = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was there an issue with what you had before, LT_EMPTY
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing LightType
to enum class ensures any usage of it is like rendering::LightType::DIRECTIONAL
(or other light type values) as opposed to rendering::LT_DIRECTIONAL
, so no need for LT_
in the naming anymore.
ogre2/src/Ogre2Scene.cc
Outdated
} | ||
|
||
// if _textureSize is an invalid texture size, then use default | ||
if (_textureSize < 1024u || _textureSize > (this->dataPtr->maxTexSize / 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be fine to set the lower limit to 512?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…point lights Signed-off-by: Athena Z <[email protected]>
Signed-off-by: Athena Z <[email protected]>
…exSize can use GL_MAX_TEXTURE_SIZE instead of currently hardcoded val Signed-off-by: Athena Z <[email protected]>
Signed-off-by: Athena Z <[email protected]>
Signed-off-by: Athena Z <[email protected]>
Signed-off-by: Athena Z <[email protected]>
Signed-off-by: Athena Z <[email protected]>
Co-authored-by: Ian Chen <[email protected]> Signed-off-by: Athena Z. <[email protected]> Signed-off-by: Athena Z <[email protected]>
Signed-off-by: Athena Z <[email protected]>
…e to return bool Signed-off-by: Athena Z <[email protected]>
Co-authored-by: Ian Chen <[email protected]> Signed-off-by: Athena Z. <[email protected]> Signed-off-by: Athena Z <[email protected]>
Signed-off-by: Athena Z <[email protected]>
a5a6d3a
to
ddde4d9
Compare
Signed-off-by: Athena Z <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1034 +/- ##
==========================================
- Coverage 75.68% 75.63% -0.06%
==========================================
Files 177 177
Lines 16959 16998 +39
==========================================
+ Hits 12835 12856 +21
- Misses 4124 4142 +18 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Athena Z <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me!
🎉 New feature
Summary
Shadows appear jagged in some scenes. It would be nice for them to look smoother and sharper. Investigated increasing shadow texture size - it seems that as long as there isn't too many lights, it does not have a significant impact on VRAM.
Thus, added ability to set shadow texture size (currently, only for directional lights) within the
MinimalScene
plugin, and for Ogre2. The default shadow texture size is 2K, but setting it to a higher value (4K, 8K, etc.) allows for sharper shadows.Currently supporting 1K, 2K, 4K, 8K, and 16K. So in SDF file, the respective values 1024, 2048, 4096, 8192, and 16384. In the future, can look to enable setting shadow texture size for other light types (spot, point lights).
Also, if using OpenGL, ensured that max shadow texture size can use
GL_MAX_TEXTURE_SIZE
instead of hardcoding it to 8K.Depot scene from Edifice demo (SDF attached below). Note that scene has 1 directional light (darker shadow) and 1 point light (lighter shadow).
Shadow texture size of 2K for directional light
Shadow texture size of 16K for directional light
Test it
depot_twolights.sdf.txt
shapes.sdf.txt
Modify the param in the SDF.
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.