Anatta336 / driven-decals

A mesh-based PBR decal system for Unity's universal render pipeline.
MIT License
580 stars 75 forks source link

Doesn't work with Unity's Terrain #1

Closed zwcloud closed 4 years ago

zwcloud commented 4 years ago

image

using Unity 2019.3.9f1 URP 7.3.1

Anatta336 commented 4 years ago

Hello, thanks for the report.

It looks like the problem is that it doesn't recognise Unity's Terrain as being a mesh that it can project against. This issue is reproducible, the decal projection system completely doesn't work with Unity's Terrain.

I think it would be a lot of work to get this type of decal system to work in a satisfactory way with Unity's Terrain. Although we cannot directly access the meshes generated by Terrain, we could still build a decal mesh by looking up height data from the Terrain. The bigger problem is that the Terrain swaps between different resolution meshes as the camera moves. To avoid visually clipping through the terrain, the generated decal mesh would need to also swap between matching meshes under the exact same conditions.

That would be possible to do, but it feels to me like something that would better be done by a dedicated Terrain-based system, or a decal system that does the projection at render-time and so doesn't need to access mesh data at all.

zwcloud commented 4 years ago

It looks like the problem is that it doesn't recognise Unity's Terrain as being a mesh that it can project against.

That's a terrain-like mesh, not a Unity terrain: MeshB.zip

I have also tried regular meshes like sphere, plane and box, it doesn't work either.

Anatta336 commented 4 years ago

Aha, okay. By default the decal looks for nearby meshes that are on objects flagged as "static" (the checkbox on top-right of the inspector when the mesh's object is selected.) If the meshes you're testing with aren't static then the decal will normally not try to project against them.

If you want a decal to project against non-static mesh objects you can untick "All static meshes" on the Decal Mesh and add whatever MeshFilters you wish to the "Target meshes" list.

Here is a decal projecting against the example mesh, with the mesh itself still being non-static: projectedOnMeshB

Hopefully that helps.