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

Generate spot light shadow maps #2914

Merged
merged 12 commits into from
Jan 21, 2021
Merged

Generate spot light shadow maps #2914

merged 12 commits into from
Jan 21, 2021

Conversation

iche033
Copy link
Contributor

@iche033 iche033 commented Jan 12, 2021

Updated gazebo to generate shadow maps for spot lights. This does not mean the spot lights will now start casting shadows in gazebo - we still need to update the RTShaderSystem code to actually render them. This does however mean that the shadow maps are now available and we can access them through custom material shaders.

I added a spotlight_shadow_demo.world that contains a shadow receiver ground plane with custom material shaders to show how to access the shadow texture generated by OGRE.

spot_light_shadow_receiver

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
@iche033 iche033 requested a review from scpeters January 12, 2021 18:53
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gazebo/rendering/RTShaderSystemPrivate.hh Outdated Show resolved Hide resolved
gazebo/rendering/RTShaderSystem.cc Show resolved Hide resolved
gazebo/rendering/RTShaderSystem.cc Outdated Show resolved Hide resolved
gazebo/rendering/Light.cc Outdated Show resolved Hide resolved
Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noticed from CI some failures in RenderingLight_TEST

I believe this failing test expectation for spot lights should be reversed, but there's also a failing expectation for point lights and I'm not sure what that value should be, if shadows aren't yet working for point lights.

gazebo/rendering/Light.cc Outdated Show resolved Hide resolved
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
@iche033
Copy link
Contributor Author

iche033 commented Jan 14, 2021

haven't tested it yet, but I made a few small comments and noticed from CI some failures in RenderingLight_TEST

should be fixed. 7aa1d35.

@scpeters
Copy link
Member

haven't tested it yet, but I made a few small comments and noticed from CI some failures in RenderingLight_TEST

should be fixed. 7aa1d35.

yep, the test is passing now 👍

@scpeters
Copy link
Member

the spotlight shadows are working on Ubuntu, though they don't seem to be working on macOS. I do see a light grey artifact that changes orientation as I rotate the camera, but not the nice shadows generated on Ubuntu

I tried adding an extra spotlight just for fun in Ubuntu, and I didn't notice an extra dark area where it was shaded by both spot lights. the shadow darkness seems to be uniform color; maybe that is expected, I don't know

Screenshot from 2021-01-14 16-19-07

{
return;
}

for (const auto &scene : this->dataPtr->scenes)
std::lock_guard<std::mutex> lock(this->dataPtr->updateMutex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if we want to minimize the time spent in this lock, we could only lock it while copying the values of this->dataPtr->updateShadows and this->dataPtr->updateShaders, then reset both to false, and then release the mutex

for example:

bool updateShaders, updateShadows;
{
  std::lock_guard<std::mutex> lock(this->dataPtr->updateMutex);
  updateShaders = this->dataPtr->updateShaders;
  updateShadows = this->dataPtr->updateShadows;
  this->dataPtr->updateShaders = false;
  this->dataPtr->updateShadows = false;
}

then read from the local variable instead of the member variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep done. 5f426b2

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
@iche033
Copy link
Contributor Author

iche033 commented Jan 16, 2021

the spotlight shadows are working on Ubuntu, though they don't seem to be working on macOS. I do see a light grey artifact that changes orientation as I rotate the camera, but not the nice shadows generated on Ubuntu

I am guessing it could be related to the glsl version used. I remember we had issue with glsl 130 on macOS so I downgraded to version 120 in cf404b1. Let me know if this makes any difference.

I tried adding an extra spotlight just for fun in Ubuntu, and I didn't notice an extra dark area where it was shaded by both spot lights. the shadow darkness seems to be uniform color; maybe that is expected, I don't know

yes that's expected. I wrote a very simple shader for the demo that just sets the color to a fixed value if it's a shadowed region. It's mainly for demo purposes and the goal is to show that you can access the shadow map texture.

@scpeters
Copy link
Member

looks good to me; I'll approve once the CI finishes assuming there are no related regressions

@scpeters scpeters merged commit 5b4f917 into gazebo9 Jan 21, 2021
@scpeters scpeters deleted the spotlight_shadows_test branch January 21, 2021 06:44
scpeters pushed a commit to scpeters/gazebo that referenced this pull request Jan 26, 2021
Updated gazebo to generate shadow maps for spot lights.
This does not mean the spot lights will now start casting
shadows in gazebo - we still need to update the
RTShaderSystem code to actually render them.
This does however mean that the shadow maps are now
available and we can access them through custom
material shaders.

The spotlight_shadow_demo.world contains a shadow
receiver ground plane with custom material shaders to show
how to access the shadow texture generated by OGRE.

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
scpeters pushed a commit that referenced this pull request Jan 28, 2021
Updated gazebo to generate shadow maps for spot lights.
This does not mean the spot lights will now start casting
shadows in gazebo - we still need to update the
RTShaderSystem code to actually render them.
This does however mean that the shadow maps are now
available and we can access them through custom
material shaders.

The spotlight_shadow_demo.world contains a shadow
receiver ground plane with custom material shaders to show
how to access the shadow texture generated by OGRE.

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants