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

Implement holes #60

Closed
TokisanGames opened this issue Feb 19, 2023 · 15 comments
Closed

Implement holes #60

TokisanGames opened this issue Feb 19, 2023 · 15 comments
Assignees
Labels
enhancement New feature or request idea Just an idea, may or may not be implemented
Milestone

Comments

@TokisanGames
Copy link
Owner

TokisanGames commented Feb 19, 2023

See the discussion here:
https://discord.com/channels/691957978680786944/1065519581013229578/1076953191482130582

This probably means:

  • Ability to paint a hole
  • It puts a nan on the heightmap for the pixel/vertex (alternatively a bit on a control map)
  • When meshing, nan/inf the vertex (search "holes" on Juan's proposal for notes from Juan and Calinou Implement Terrain godotengine/godot-proposals#6121)
  • Alternatively, since we're generating our own mesh and collision mesh, I think it might be possible to just punch a hole in the meshes themselves. That is reshape the mesh around the hole data. Although with a clipmap terrain where we're reusing meshes this may not be practical.

Requires #115

@TokisanGames TokisanGames added the enhancement New feature or request label Feb 19, 2023
@TokisanGames TokisanGames added this to the Polished Version milestone Feb 19, 2023
@TokisanGames TokisanGames added the idea Just an idea, may or may not be implemented label Jul 4, 2023
@TokisanGames
Copy link
Owner Author

@Arnklit suggested just doing visual holes. Then when the player walks into a cave entrance, they can turn off their collision mask for the terrain and walk right through it, standing on their own ground mesh.

@SlashScreen
Copy link
Contributor

obviously it depends on how the realtime collision thing ends up working, but it doesn't seem like just omitting some vertices in the collision would be too much more of a challenge than doing the same to the visual mesh.

Also, to the user, having to switch collision masks seems like kind of a weird hack to get around a limitation that, from an outside perspective, shouldn't be there anyway. From your perspective it's a clever way to not have to deal with a potentially challenging problem, but to someone unfamiliar with how this whole thing works internally, it could seem odd that this seemingly obvious feature isn't fully supported, especially since it works visually. It could be worth the extra time to make the plugin seem more polished in the end.

@Arnklit
Copy link

Arnklit commented Aug 6, 2023

obviously it depends on how the realtime collision thing ends up working, but it doesn't seem like just omitting some vertices in the collision would be too much more of a challenge than doing the same to the visual mesh.

you don't use vertices for the collisions with terrains, it would be slow and imprecise, you use the heightmap to generate the collider.

@SlashScreen
Copy link
Contributor

Seems obvious when you put it that way. I guess you could compare the heightmap and the holes map and if the holes map overlaps you skip the quad? May add a little complexity to triangle winding, though. And that might be a lot of back-and-forth with the CPU and the GPU, assuming the collider isn't generated using a compute shader.

@TokisanGames
Copy link
Owner Author

it doesn't seem like just omitting some vertices in the collision would be too much more of a challenge than doing the same to the visual mesh.

We aren't generating a polygonal collision mesh. We are using the heightmap shape, which is a fixed grid. There's no way to punch a hole in it. Some have suggested setting the heights to -10,000 but this won't work if you want the player to pass underneath an overhang.

@Arnklit 's suggestion is the best option, unless we generate our own polygonal collision mesh, which jolt support may require us to. #152. Or we tessellate the terrain, which @painfulexistence started experimenting with but it requires changing the core engine.

However most likely jolt will support what we're doing and the need for generating a polygonal collision mesh won't exist.

Also, to the user, having to switch collision masks seems like kind of a weird hack to get around a limitation that, from an outside perspective, shouldn't be there anyway. From your perspective it's a clever way to not have to deal with a potentially challenging problem, but to someone unfamiliar with how this whole thing works internally, it could seem odd that this seemingly obvious feature isn't fully supported, especially since it works visually.

What is my perspective? Am I an engine dev who doesn't make games or know what is needed? Or am I an intermediate gamedev building tools I need for my game. How did I know @Arnklit 's suggestion was on point? Because of my experience building one of the largest games in the Godot community and knowing what I need. So if I or my team need it, it's likely most others need it. That's what is guiding the building of this tool.

Isn't someone unfamiliar with how this whole thing works, an inexperienced gamedev? As you gain more experience you'll learn all of gamedev is smoke and mirrors and movie set facades.

Using layers is not a weird hack. It is a normal, necessary aspect of gamedev. Any developer not using them is just wasting performance. That's normal for new gamedevs. It takes a while to learn the "hacks" of how to optimize your systems. Switching layers takes one line of code and is instant. There's no issue there.

What is a weird hack is using a heightmap terrain and trying to drill holes into it so you have what appears to be a 3d terrain. The true, right solution for that is a voxel terrain. But we will provide way to do it so we can have the performance benefit of heightmaps.

The discussion and questions are welcome.

@SlashScreen
Copy link
Contributor

I see, the heightmap collider. It seems my worries are unfounded, and that I may be putting the cart before the horse on this one.

@SpockBauru
Copy link

Hello, I'm still studying and interested in this feature, hope is not a dumb question. It's about Arnklit suggestion of visual holes.

In this case I have a racing game and the cars are about to enter a tunnel. The tunnel is inside a terrain hole in the hill. If the collision layer is turned off when the player enter the tunnel, the cars that are still on the terrain wouldn't fall off?
Here is the prototype in other engine (that I want to ditch off...)

Screen_Recording_20231004_105826_CountryRun_edit.mp4

@TokisanGames
Copy link
Owner Author

Here is the prototype in other engine (that I want to ditch off...)

Looks cool. Should look exactly like in the video when finished. We'll have a working demo.

The tunnel is inside a terrain hole in the hill. If the collision layer is turned off when the player enter the tunnel, the cars that are still on the terrain wouldn't fall off?

No, you adjust the layers for only the player or cars that are entering the tunnel.

Terrain is on its own layer. As are the tunnel mesh, the player, and enemy/cars. You just turn off the Player's mask for the terrain. The player just no longer recognizes the terrain collision, but it does recognize the tunnel collision.

@SpockBauru
Copy link

No, you adjust the layers for only the player or cars that are entering the tunnel.

Terrain is on its own layer. As are the tunnel mesh, the player, and enemy/cars. You just turn off the Player's mask for the terrain. The player just no longer recognizes the terrain collision, but it does recognize the tunnel collision.

Thanks for the answer, I will study more about layers. Looking forward future versions of Terrain3D, please keep the good work :D

@TokisanGames
Copy link
Owner Author

TokisanGames commented Nov 6, 2023

Actual holes in collision may work, not just with visuals and toggling physics layers. @tcoxon says this is working for him in Godot physics. We need to test it more in both Godot and Jolt as well.

Holes are still on hold until the new control map is finished #115 #234. I'm 90-95% of the way there, just polishing up texture blending.

@TokisanGames TokisanGames self-assigned this Nov 16, 2023
@TokisanGames
Copy link
Owner Author

TokisanGames commented Nov 18, 2023

Holes in the mesh and collision shape were implemented in 2456e0d and 59c6a1f in 0.9. Try it with this artifact build.

To fill in holes with say a tunnel, place your own rock or cave meshes with collision there.

The editor paints visual holes as expected. I've also built in the shader snippet that disables the ground outside of regions. This World Background option has three options: None (shown), flat (default), Noise (collisionless infinite generated landscape). In this picture I disabled the background and painted "holes" around the whole outside edge.

image

Godot Physics

Collision holes work perfectly using Godot physics.

holes-godot.mp4

Jolt Physics

In Jolt physics 0.10, collision holes partially work sometimes. Vertices are set to some nearby low value. In the demo with nearby ground at 100, it was -38.4. But if I sculpted down to -50, then the holes went to -50. So holes in Jolt are either a pit or visual only.

I've filed a feature request on the Godot-jolt repository. Track it here.

holes-jolt.mp4

Workaround:

You should be separating your objects into different collision layers normally. e.g. one for each of terrain, fixed objects, enemies, player, interactable items, etc. If there are objects that will never interact with each other, you don't want the physics system wasting cycles calculating collisions between them.

Then you can place an area around the entrance of a tunnel to detect when your player is about to enter, then disable the player's collision layer mask for the ground. It's a few lines of code and very easy to do.
e.g. when our player's weapon is equiped, we turn on it's hitbox

     hitbox.set_collision_mask_value(3, true)        # Enable enemy hit detection

@SpockBauru
Copy link

SpockBauru commented Nov 19, 2023

Hello, thank you for the update, I just tested the demo scene with Godot physics in Godot 4.1.3.

Unfortunately found a weird bug where painted holes appear on random locations... It appears depending on the camera positions, in this video if I rotate the camera just a little the holes are painted in the right place. Sometimes holes appear pretty far.

Terrain3D_Holes_Bug.mp4

I'm attaching the test project, in this file I aimed just for the holes inside the tunnel, but lots of holes appeared outside. Ah, just made a basic tunnel. Use as you wish ^-^.

GitHub don't like the project size... Here's a link: https://pixeldrain.com/u/qAn9yhr4

One more little thing: the license link of textures changed, now is https://docs.ambientcg.com/license/

Edit: Just found out that holes are not working on Orthogonal view.

@TokisanGames
Copy link
Owner Author

The issue is the mouse cursor bounces around when the camera is close to the terrain #121. You can see it in a 2 viewport mode, and will also hit the backside of the mesh if drawn sideways.

Move the camera away from the terrain to draw. It's better to draw overly large holes from overhead then move the camera down to fill them in. Also use a solid brush rather than the gradient brush so you can see where your cursor is.

Very little works in Orthogonal view. Holes are visible overhead. No editor tools work. It is unsupported.

Thanks for the updated license link.

@TokisanGames
Copy link
Owner Author

Holes work in both Godot and Jolt physics as of 2c61617. In Jolt, the collision shape is one sided. So, your caves need to have their own collision.

@TokisanGames
Copy link
Owner Author

PR #313 greatly improves the mouse cursor. It allows painting of any kind, even holes, with the camera up close to the terrain. Holes no longer punch through to the other side of the terrain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request idea Just an idea, may or may not be implemented
Projects
Status: Done
Development

No branches or pull requests

4 participants