Blending tool using height maps and mesh contact!

LouisValet
polycounter lvl 8
Hello!
I have made a blending tool, capable of blending a large amount of materials together using texture arrays and utilizing the height maps for better transitions. It also features shaders to blend objects with the terrain created with that blending tool, designed to hide the intersection seams !
The runtime shaders are not super expensive, they mostly do texture array samples and lerps (around 10 of each) as most of the data required for
the effect is baked inside vertex channels and a control map at editor time.
The "contact blending" tool bakes the normal, UVs, tangent and height to the terrain into the various vertex channels of the object, which are then used for the blending.
Right now it is a naive raycast up and down for the distance to the surface, no fancy signed distance fields but I hope to be able to improve that !
The blending shader uses a control map, which stores inside it's RGB channels the texture index as the int part and the weight of that texture as the floating part (clamped between 0.05 and 0.95 to prevent artefacts). The A channel is used for a bonus wetness overlay, but could be reworked to be anything (burn, frost...). That control texture needs to use point filtering of course, but even at low resolutions it give pretty convincing results, thanks to the blending being modulated by the different height maps.
Here are a couple of ideas I've considered already:
-Figuring out a way to use distance fields or another method for better distance detection (right now it only works for mostly "flat" surfaces)
-Adding a way to mask areas where the blending should or should not happen (Quickly running out of vertex channels though)
I'd love to hear what you think !
Thanks!
I have made a blending tool, capable of blending a large amount of materials together using texture arrays and utilizing the height maps for better transitions. It also features shaders to blend objects with the terrain created with that blending tool, designed to hide the intersection seams !
The runtime shaders are not super expensive, they mostly do texture array samples and lerps (around 10 of each) as most of the data required for
the effect is baked inside vertex channels and a control map at editor time.
The "contact blending" tool bakes the normal, UVs, tangent and height to the terrain into the various vertex channels of the object, which are then used for the blending.
Right now it is a naive raycast up and down for the distance to the surface, no fancy signed distance fields but I hope to be able to improve that !
The blending shader uses a control map, which stores inside it's RGB channels the texture index as the int part and the weight of that texture as the floating part (clamped between 0.05 and 0.95 to prevent artefacts). The A channel is used for a bonus wetness overlay, but could be reworked to be anything (burn, frost...). That control texture needs to use point filtering of course, but even at low resolutions it give pretty convincing results, thanks to the blending being modulated by the different height maps.
Here are a couple of ideas I've considered already:
-Figuring out a way to use distance fields or another method for better distance detection (right now it only works for mostly "flat" surfaces)
-Adding a way to mask areas where the blending should or should not happen (Quickly running out of vertex channels though)
I'd love to hear what you think !
Thanks!
Replies
-
Just awesome, Will try this out when I get the time!
-
Cool stuff! Will check it out for my next Unity project!
-
Menchen said:The "blending with proximity" feature, does also "smoothen up" normals or just applies the terrain texture on the intersecting mesh?
-
This looks awesome! Thanks for sharing and I'm excited to try it out.
-
What I see here is amazing tool. Keep it up.
-
(This item is not available in your location)
is there any other way I can get it? -
salimmatta said:(This item is not available in your location)
is there any other way I can get it?
-
WOW!!!! u can replicate it on Unreal?!?!?!
-
Irensay said:WOW!!!! u can replicate it on Unreal?!?!?!
-
Eternal Black said:
-
lovely!!!!
-
-- Moved the update to the op
-
Oh my god I have been looking for a tool like this for Unity for ages. Thank you so much!
-
Nice one "Blobinet" XD
-
Have you tried using world-aligned UVs for the terrain, and for the blended part on meshes? That would lock the terrain textures in space, so you wouldn't have a UV disconnect when moving the meshes horizontally.
-
Eric Chadwick said:Have you tried using world-aligned UVs for the terrain, and for the blended part on meshes? That would lock the terrain textures in space, so you wouldn't have a UV disconnect when moving the meshes horizontally.
I could add world-aligned UVs, but wouldn't that suffer from the same problem unless I did tri-planar mapping ?
-
For the rock meshes, I would use custom artist-authored UVs. For the terrain, world-up-axis UVs. For the blend on the rock mesh, adopt the world UV.
-
Thanks for posting and sharing your work. Will give this a go. You should consider putting this on the asset store. Im sure people would buy it
-
I'm working on some better promo/demo material and I'll put it up on the asset store as well for sure (It's a shame the asset store does not have a pay what you want model...)
-
nice and thanks for the share, one question though,
how's the performance on this ?
-
Very cool, how many instructions for the material?
-
Here are the stats from the compiled shaders (I suppose that also includes Unity's PBR shading ? Not sure how to isolate that)
Terrain blending :
Simple contact blending (Between an object's material and another single material) :- // Stats for Vertex shader:<br> // d3d11: 37 avg math (27..59)<br> // Stats for Fragment shader:<br> // d3d11: 213 avg math (192..235), 13 avg texture (11..15), 7 avg branch (6..8)
Advanced contact blending (Between an object and a terrain blending shader) :- // Stats for Vertex shader:<br> // d3d11: 49 avg math (39..71)<br> // Stats for Fragment shader:<br> // d3d11: 188 avg math (172..205), 12 avg texture (10..14), 7 avg branch (6..8)
Now, I don't have much experience with shader performance yet, so you are going to have to help me make sense of this- // Stats for Vertex shader:<br> // d3d11: 48 avg math (38..70)<br> // Stats for Fragment shader:<br> // d3d11: 233 avg math (213..254), 18 avg texture (16..20), 7 avg branch (6..8)
EDIT: I did compiled Unity's default Standard shader for comparison :- // Stats for Vertex shader:<br> // d3d11: 32 avg math (22..53)<br> // Stats for Fragment shader:<br> // d3d11: 159 avg math (142..176), 5 avg texture (3..7), 7 avg branch (6..8)
-
Good Job my dude !
-
Thanks for posting and sharing your work. I will give this a go. You should consider putting this in the unity asset store. I'm sure people would buy it.
-
Thanks for posting and sharing your work. Will give this a go. You should consider putting this in the asset store. I'm sure people would buy it.