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

scale ambient by 0.5 for collada and other assimp-loaded resources #841

Merged
merged 1 commit into from
Feb 12, 2015
Merged

scale ambient by 0.5 for collada and other assimp-loaded resources #841

merged 1 commit into from
Feb 12, 2015

Conversation

mikeferguson
Copy link
Contributor

I've been bringing up a new robot in RVIZ/Gazebo using Collada meshes and URDF and have found that it was nearly impossible to get the meshes to look remotely similar within Gazebo and RVIZ. If the robot looked OK in Gazebo it was washed out in RVIZ, if it was OK in RVIZ it was too dark in Gazebo.

Searching the RVIZ codebase for "setAmbient" shows that almost always the r,g,b values have been scaled by 0.5 (not sure why). As soon as I add this commit, I no longer get washed out collada files (Tested with both my new robot and the PR2). This commit does not change anything for users specifying pure STL files or OGRE mesh files, only Collada users.

This is a potential solution for #515

This is consistent with numerous other places within the codebase where ambient is almost always scaled by 0.5
@wjwwood
Copy link
Member

wjwwood commented Feb 4, 2015

@mikeferguson does it have anything to do with this change? #837

That is merged into indigo-devel but not released yet.

@mikeferguson
Copy link
Contributor Author

@wjwwood #837 plays no part in this. The problem this addresses exists both in indigo-devel as well as the latest released debians, and has been around for quite some time and exists even when using non-zero ambient values.

@adolfo-rt
Copy link

Wow, halving the rgb coordinates definitely explains the darker rendering produced by rviz. So are meshes rendered qualitatively similar now (at least color-wise) between rviz and Gazebo?.

@mikeferguson
Copy link
Contributor Author

So, in the case of collada meshes with ambient = 1 1 1 1 and emission = 0 0 0 0 (as in the case of the PR2), this makes them render almost as nicely as they do in gazebo. It certainly makes the colors correct (my white robot is actually a nice white in both rviz and gazebo, and you can actually make out the robot's shape).

@wjwwood
Copy link
Member

wjwwood commented Feb 5, 2015

I believe you that it helps, but I just don't understand the change. It seems pretty arbitrary to adjust the ambient values in a collada file by multiplying them by 0.5. #837 may not be related, but if I were to cherry-pick this commit without the one in #837 it would certainly behave differently for collada files which have 0 for any of rgb.

Searching the RVIZ codebase for "setAmbient" shows that almost always the r,g,b values have been scaled by 0.5 (not sure why).

I guess there is a good reason for this, but I'd like to know why. Maybe @hersh or @dgossow have some historical perspective on it.

Also, because we apparently "cribbed" (wtf does that even mean) this from Gazebo:

https://github.com/mikeferguson/rviz/blob/ambient_fix/src/rviz/mesh_loader.cpp#L430

maybe @nkoenig has some idea why the ambients are scaled by 0.5?

@wjwwood
Copy link
Member

wjwwood commented Feb 5, 2015

@mikeferguson for historical reasons, could you please post before and after images of a box or something which shows the difference this change makes?

@mikeferguson
Copy link
Contributor Author

@wjwwood -- I will post some images tomorrow -- I was rushing to submit the PR last night before leaving the office.

As for the gazebo reference -- from what I can tell, this code was old gazebo code in ~2010 or so when rviz was first written. This file appears to have not been updated much over time, and the lines in question have no edits since inception. Gazebo appears to have rewritten their mesh loading significantly since then, and I could find no overlap between this code and anything in trunk of gazebo.

@wjwwood
Copy link
Member

wjwwood commented Feb 5, 2015

@mikeferguson Ok, thanks.

@wjwwood
Copy link
Member

wjwwood commented Feb 6, 2015

Searching the RVIZ codebase for "setAmbient" shows that almost always the r,g,b values have been scaled by 0.5 (not sure why).

For posterity, I was curious about this, and currently there a many instances of this, in several forms:

Notably this one is not like that:

But it's the only instance I could find that seems to set the ambient without scaling it (other than the one being modified in this pull request).

@wjwwood
Copy link
Member

wjwwood commented Feb 9, 2015

@mikeferguson (or anyone else), I'd like to ask again for either before and after images or a test mesh so that I can reproduce the before and after myself. I know you're busy, but I'd like to get this merged in for the next release which is imminent for more soak testing time, but I don't feel confident until I can try it out and observe it myself (or at least see what you're talking about in images).

Thanks!

@mikeferguson
Copy link
Contributor Author

@wjwwood here you go. This is a cube, in collada, with ambient = 1 1 1 1. I also tested a mesh.xml with ambient and got similar results. In addition, I included an image of the mesh in Gazebo 2.0 (which is my main need for this fix, to get (more) consistent results between Gazebo and RVIZ)

gazebo

@wjwwood
Copy link
Member

wjwwood commented Feb 12, 2015

Awesome, thanks for getting those for me.

I guess the remaining inconsistency between rviz w/ this patch and gazebo is the placement of the lights?

@wjwwood
Copy link
Member

wjwwood commented Feb 12, 2015

I'm gonna merge this now, but one thought is that rather than changing the mat for every mesh we might be able to achieve the same effect with global lighting. However, that's out of my expertise, so I'll punt that for later.

wjwwood added a commit that referenced this pull request Feb 12, 2015
scale ambient by 0.5 for collada and other assimp-loaded resources
@wjwwood wjwwood merged commit 3c570d2 into ros-visualization:indigo-devel Feb 12, 2015
@mikeferguson
Copy link
Contributor Author

@wjwwood I actually tried the lighting -- it can get closer to Gazebo, but it still requires this fix to avoid washing out. My guess is that Gazebo does this divide by 2 as well inside (although I couldn't figure out where that exact code is, I went down several layers in their codebase but eventually it looks like they rely on an external library for initial collada loading).

I am planning to eventually put a pull request together that adds a menu to select either the point light (as we have right now) or a global light (like gazebo has) or both. I figured out the lighting aspects, but not the menuing thus far.

@mikeferguson mikeferguson deleted the ambient_fix branch February 12, 2015 01:05
@wjwwood
Copy link
Member

wjwwood commented Feb 12, 2015

Cool, let me know if I can help.

@adolfo-rt
Copy link

I guess the remaining inconsistency between rviz w/ this patch and gazebo is the placement of the lights?

In the general case Gazebo and rviz will render differently because of lighting. This is because Gazebo allows you to control the number, type and location of light sources, whereas rviz only has a fixed directional light source (I think, I haven't checked). What could maybe be done is make the direction of the rviz light source with that of the typical Gazebo empty world, which I believe is overhead.

@hersh
Copy link
Contributor

hersh commented Feb 12, 2015

Lighting has largely been ignored in the development of RViz, at least during my tenure with it. I think it might be a great addition to add a configurable lighting system. It might already be possible with rviz plugins, since you can use all of Ogre from rviz::Display plugins.

Shadows would also be really useful at times. I'm sure they would be a performance hit in some cases, so they should be optional, but when you're moving interactive markers in 3D, shadows could give a nice extra bit of feedback about where your object is. Because of the extra rendering step required for shadows, I would expect that to be a change within rviz itself and not just a plugin.

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.

4 participants