-
Notifications
You must be signed in to change notification settings - Fork 51
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
Support heightmaps on Ogre 2 #187
Comments
the terrain component is not enabled by default when building ogre2 so I believe our ogre-2.1 debs do not ship the terrain component. Last I tried, I ran in to a build error compiling the ogre2 terrain component on ubuntu bionic but the ogre2 dev says it should be a finished product. |
We talked this via video conference and email, but just in case it wasn't clear or the information got lost: The sample at Samples/2.0/Tutorials/Tutorial_Terrain implements the terrain system entirely (aka Terra) in a few C++ and shader files and does not depend on the Terrain Component. The terrain component is currently abandoned. The reason for this being is that Ogre 2.1+ targets newer rendering APIs which allow for much simpler yet more powerful terrain systems; for example Terra does not even have vertex buffers. The vertices are made procedural and the only memory it needs (excluding colouring/shading) is the heightmap. This was impossible in older APIs, which led to much higher complexity in the Terrain Component where a lot of work went into managing vertex buffers of the current pages and LODs. The reason Terra was implemented as a self-contained sample and not a Component is that requirements for Terrain are very specific to each project, and users are very likely to customize it for their own needs. Given the simplicity of the code, it made more sense to do it as a sample exposing the source files directly; rather than adding a new library |
ah thanks for clarifying this. In that case, we'll need to copy this Terra directory and relevant shader files over to ignition? |
Yep. That is correct. |
This is great to know! So we can add heightmap support to earlier versions of Ignition as well 😄 |
I'm tackling this issue and I have a few questions, based on my analysis of the ogre1 version:
RemarksNow I understand @iche033 insistence on questions about LODs and paging. It seems Ogre1 did a lot of work to cache:
Terra has no such things. Everything that was baked either no longer exists (Terra has no vertex geometry, and without it, LODs are trivial as well) or is calculated in realtime. This is like a hover car using antigravity devices and asking what happens when you get a flat tire: This is a hover car, it has no tires 😄 IntegrationThe way I set it up was to copy-paste the Terra files into your own projects, and modify what you need (although for upgrade-ability sake, keep them to a minimum or submit contributions to upstream) But I noticed the coding standards and naming conventions (i.e. including project folder structure, CamelCase, etc) are too different from Ignition. I think it may be best if we build a small library and ign-rendering links to it. However where would that library live? as part of https://github.com/ignitionrobotics like sdformat? as part of ign-rendering/terra? RapidjsonIt seems Ogre so far has been compiled without JSON support. Terra needs it. Fortunately rapidjson is a header-only API so it's all about setting up include_directories in CMake, but Ignition has a specific way of doing things with CMake scripts that I prefer someone else performs (right now I'm hacking it) Minor challenges
ProgressChanges started in https://github.com/darksylinc/ign-rendering/tree/matias-ogre22-terra |
We could update that class to also accept 16bpp.
An alternative way to get heightmaps in is through the Dem class (gazebosim/gz-sim#235). I didn't add support to that while porting the Ogre 1 code for expediency, but we should eventually support it.
I'm not completely sure, but it may be important for physics, which also uses that class to import heightmaps.
🚀
We can include it in the codebase as "vendored" code, which we usually don't run linters on (like GTest, Remotery, etc).
I think it can be part of I think another potential place for it could be our Ogre 2 fork?
I don't think Ogre uses
Maybe all we need is to update some documentation? Like this one: https://github.com/ignitionrobotics/ign-common/blob/465bb7780e552b278de559fafaffe3d061a99782/graphics/include/ignition/common/Dem.hh#L74-L81 |
We mainly use ImageHeightmap to create simple terrains. For more accurate terrain simulation, we would import DEMs from online GIS sites. Sometimes we find that the DEM data contain negative heights.
We also had a heightmap editor once in gazebo-classic and increasing the resolution allowed us to make finer modification to the terrain
We've used 16K resolution before on more beefy machines with ogre 1.x. So it should be fine. For that particular project the terrain size is actually not very large, 300x300m, it just needed really high fidelity for physics simulation, and we used ogre 1.x's LOD so we can get reasonable framerate. That's one extreme case. I think dynamic streaming would be beneficial for more projects actually but we should still keep the ability for users to use 16K if they choose to.
yeah let's put it in ign-rendering.
ok so we'll need to add
ah ok, sounds like there'll be some performance hit here.
👍 |
Gotcha. That's all I needed to know.
Ideally the changes in the fork get to upstream to reduce the need for a fork at all :)
We'll see what we can do. In theory we could just ignore the last row and column. Or perhaps that introduces problems. Once we get there we'll evaluate. I was pointing it out.
1.83 cm per pixel, impressive. Yeah Terra can do that.
Nah, no perf hit. I was just pointing it out; it is a minor inconvenience because all the rendering cameras (e.g. Ogre2GpuRays, Thermal, etc) need to call a function that iterates through all Terras and updates them with the current Camera. Might also be fixed with a Workspace listener. I'm undecided on the best approach yet. |
Some progress to get everyone excited. Alignment / size is not exact to Ogre1 yet. Left is Ogre2, Right is Ogre1 'heightmap_bowl.png' is an edge case scenario for Terra (extremely artificial, non-natural terrain; looking the terrain from outside rather than the inside; and being looked from the outside without having more terrain in its surroundings), which is why the skirts and LODs are so obvious; |
I'm close to finishing it and it looks they way I'd expect to given the input parameters (btw we support much more to make it more beautiful...) but I don't understand why it looks so different from reference in ogre1 (actually reference looks weird...) What's missing:
Regarding the last one (the non-deterministic bug) some runs it looks like this: Edit:Oh I understand why it looks so different from reference now. HeightmapTexture::Size is in meters. I thought it was a scale parameter in UV space. |
I managed to look it like reference: The only weird thing is that in order to do that, I had to disable a feature. It appears ogre1 is ignoring the alpha channel of the source textures; while ogre2 was using them. I'm not sure what's the intended scenario but considering the source textures do have alpha channel, it looks it the idea was for it be used. |
Progress with the non-deterministic bug: It's not mine. It's gazebo's. Sometimes I've printed the last 10 pixels of row 0; it should be all 0s: I suspect two possibilities:
Update: Disk access cannot be (the weirdness is there; but that's not the bug). I've added immutable flag on the file Update 2: Sigh
Update 3: Image::Data not only corrupts, it also leaks. |
OK to recap what I'm now missing
|
chances are that we just didn't use the alpha channel with ogre 1.x. We copied shader material generation code from ogre 1.x and tweaked it to fix some issues with glsl shaders some time ago. I haven't paid much attention to the blending logic but a quick look seems to suggest that the alpha channel is used to store specular map? https://github.com/ignitionrobotics/ign-rendering/blob/ign-rendering5/ogre/src/OgreHeightmap.cc#L2275-L2291 The latest ogre 1.x doc also talks about merging the diffuse and spec textures into one texture: https://ogrecave.github.io/ogre/api/latest/tut__terrain_sky_fog.html I think we should respect the alpha channel in ogre 2.x implementation.
At first glance, I think it may be better to have the terra folder live inside @mjcarroll, do you have any recommendation on the best way to include some ogre2-related external source files (so we can also make windows and bazel happy)? |
ahh.. :( looks like there needs to be a check for image format before trying to swap.. |
Yes. But please note it's also leaking because a copy /clone of the freeimage handle is made which is never freed (the handle is lost) |
Done in #386 🎉 |
Terrain support is being added for Ogre 1 on #180 . The implementation for Ogre 2 is being left empty for now.
Here's a tutorial using terrain on Ogre 2 upstream:
https://github.com/OGRECave/ogre-next/tree/v2-1/Samples/2.0/Tutorials/Tutorial_Terrain
The text was updated successfully, but these errors were encountered: