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

There is no method for collision on vertex shader shapes or heightmaps #27601

Closed
ConnorBP opened this issue Apr 2, 2019 · 8 comments
Closed

Comments

@ConnorBP
Copy link

ConnorBP commented Apr 2, 2019

Godot version: 7f691e8

OS/device including version:
Windows 10 Pro (64), Intel 7700k, GTX 1080 Gaming X MSI

Issue description:
When using vertex shaders for things such as terrain generation for example there does not seem to be any way to have a collision shape for it. This is what happens when you apply a static collision mesh to a plane affected by terrain code made in this tutorial: https://docs.godotengine.org/en/2.1/community/tutorials/3d/mesh_generation_with_heightmap_and_shaders.html
https://docs.godotengine.org/en/3.1/tutorials/shading/vertex_displacement_with_shaders.html?highlight=terrain
Image of collision mesh being the current mesh before its shader transformations

i found some related issues and PRs but none seem to be implemented, available, or conver all cases (for example people not using bullet, using your own terrain generation code instead of bullets height map implementation, or other vertex transforms that people may want to make collide-able)

#24548
#17806
#9046

Some potential options I can think of for allowing collision on these types of objects are:
Vertex Shaders on collision, Heightmaps for bullet, vertex "baking" (applying the vertex transformation currently happening permanently, having the collision generator check for vertex transforms, or allowing vertex shaders on physics shapes?
and of course the built in bullet functionality is still an option if anyone ever decides to add that.

Steps to reproduce:
follow https://docs.godotengine.org/en/2.1/community/tutorials/3d/mesh_generation_with_heightmap_and_shaders.html
or
https://docs.godotengine.org/en/3.1/tutorials/shading/vertex_displacement_with_shaders.html?highlight=terrain
click add trimesh static body to resulting terrain

If there is some buried way to make a collision mesh for this already I ask that the documentation on that be made more clear, but as I cannot find it being anywhere at all I doubt there is a feature for this at all. I would like to see at least some way for this to be achievable in godot as having no proper or standardized method of terrain generation that can actually have physics is kind of a road block.

Minimal reproduction project:
https://gitlab.com/atorresm/Godot-LowPolyTerrainDemo (not mine)

@clayjohn
Copy link
Member

clayjohn commented Apr 2, 2019

You are misunderstanding how shaders work. They are not applied until the data is sent to the GPU to be drawn to the screen. The data never comes back to the CPU. The mesh itself is never changed. Each frame a flat plane is being drawn and the shader deforms it based on the vertex shader. The key part is that this happens every frame and the values are thrown away every time. There is no way to bake the height values in. This is a limitation of shaders (not Godot), but it is also a reason why shaders are able to run so fast.

You can see in the issues you linked to, there is interest in exposing the heightfield abilities of bullet. This is as close as you can get to what you want to do. Making a static heightmap and having bullet use it for collisions and also apply it to your terrain.

@ConnorBP
Copy link
Author

ConnorBP commented Apr 2, 2019

what about the option of native heightmap mesh instance or shape which you can pass a texture into?

@clayjohn
Copy link
Member

clayjohn commented Apr 2, 2019

That's exactly what the issue you linked is asking for #24548 and the PR you linked implements #17806 (but only from physicsserver)

@ConnorBP
Copy link
Author

ConnorBP commented Apr 2, 2019

What on earth... I just found this. https://github.com/Zylann/godot_heightmap_plugin/tree/master/addons/zylann.hterrain

If this guy can check the collision of shader terrain using only gdscript i'm sure the devs can do it in c++

@clayjohn
Copy link
Member

clayjohn commented Apr 2, 2019

He is the author of PR #17806. The technique he implemented in that PR is the one he uses in that plugin. Its using a heightmap. And the functionality is in the engine.

@kaadmy
Copy link
Contributor

kaadmy commented Apr 2, 2019

What on earth... I just found this. https://github.com/Zylann/godot_heightmap_plugin/tree/master/addons/zylann.hterrain

If this guy can check the collision of shader terrain using only gdscript i'm sure the devs can do it in c++

I'm pretty sure that implementation uses a shader for the mesh generation but still computes the mesh CPU-side for the collisions.

@Zylann
Copy link
Contributor

Zylann commented Apr 2, 2019

That's the case, I use shader displacement for rendering the terrain, but the heightmap is also copied in RAM for handling collisions and performing edition/height/texture query tasks. The PR I made basically exposes Bullet's heightmap shape to a minimum, which was just there waiting to be used, and without which collision would have been really hard to do. It's Bullet-only because Godot Physics is lacking an implementation of that shape and needs more involvement.

The PhysicsServer API is powerful but a bit harder to use, so #27156 has been recently proposed to add this API to the node/resource system. But still, it won't give a full-featured system for making such terrains, which is what I was doing so far with my plugin, by combining together various features of the engine. Hopefully Godot will get such a system built-in in the future, at least after Vulkan is added.

@akien-mga
Copy link
Member

I think this issue can be closed, it's not clear what the expected outcome is, but the feature requested is available via #17806 and #27156.

Anything beyond that should now go through the godot-proposals repository (though I'm sure there are already proposals relative to making terrains open there).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants