Advertisement

"3D Decals" for roads on terrain.

Started by July 30, 2017 03:02 AM
24 comments, last by 3ddominator 6 years, 11 months ago

Hello! I'm not sure if this is the right place since i'm new to the forums.
I'm creating a simple "City creator" right now, and, obviously, i need to create a Road tool for it. I was planning on doing raytracing to make the road snap to the terrain geometry, but it would clip through the terrain in places with mountains or different heights.

I don't want to make a simple 2D decal because it would not look good without shape(The sidewalk is of course going to be taller and have a different geometry than the road itself) and i want to make it "bendable". I'm not the best at maths and geometry manipulation so i don't know where to start...
I'm using Unity by the way, and sorry for my bad English!

Moving to For Beginners.

 

Advertisement

I can't be really of help since I have no idea how to make such a tool, but maybe I can point the right direction, since what you describe makes me remember this -> https://docs.unrealengine.com/latest/INT/Engine/Landscape/Editing/Splines/

So I would say you need to look into spline curves.

Also, it makes me think to roads into city skyline, and luckily there is a Dev diry Roads entry about it -> https://forum.paradoxplaza.com/forum/index.php?threads/cities-skylines-dev-diary-1-roads.802639/   

I didn't read it, but maybe you find some tips on how they solved those problems :P

Also here all their diary entries -> http://www.skylineswiki.com/Developer_diaries  you should check the 6 Mass Traffic entries, probably

 

Edit: nope, forget it, I read it out of curiosity and it say nothing, I was under the wrong impression that a Dev diary would always go into technical details, since I follow Factorio dev posts every week, but apparently is not the case :D

18 hours ago, LazyDuke said:

the best at maths and geometry manipulation so i don't know where to start...
I'm using Unity

Like so many things Unity is missing it has no scene spline or curve tools. So you will make your own or use some made by others and allow Unity to profit from the micro transaction.

If you are willing to fall for Unity's micro transactions here is a good one: https://www.assetstore.unity3d.com/en/#!/content/61926

If not here is a old tutorial that you will need to adapt: http://catlikecoding.com/unity/tutorials/curves-and-splines/

 

I know this isn't much help but I am done with Unity, after spending days trying to make my own font tools I just cave and bought a set, then I bought a set of 3D model editing tools and terrain tools and brush tools.

The funny part is I don't plan on selling the game I am making with Unity and already it cost over $250 to make. All I can do now is lie to my self, convincing my self that the $250 went to artist who needed it.:(

35 minutes ago, MarcusAseth said:

I can't be really of help since I have no idea how to make such a tool, but maybe I can point the right direction, since what you describe makes me remember this -> https://docs.unrealengine.com/latest/INT/Engine/Landscape/Editing/Splines/

So I would say you need to look into spline curves.

Also, it makes me think to roads into city skyline, and luckily there is a Dev diry Roads entry about it -> https://forum.paradoxplaza.com/forum/index.php?threads/cities-skylines-dev-diary-1-roads.802639/   

I didn't read it, but maybe you find some tips on how they solved those problems :P

Also here all their diary entries -> http://www.skylineswiki.com/Developer_diaries  you should check the 6 Mass Traffic entries, probably

 

Edit: nope, forget it, I read it out of curiosity and it say nothing, I was under the wrong impression that a Dev diary would always go into technical details, since I follow Factorio dev posts every week, but apparently is not the case :D

Thanks! The Splines are actually a step forward, and it's exactly what i was looking for, BUT, i still need a way to modify the geometry of the curved mesh to match the underlying terrain without clipping through it.

This is what i mean(Sorry for the 5 years old kid drawing lol):

ffigures2.png.5774db0d80c52ad646a2f7880b9093cf.png

Image 1 would be the geometry of the curved road, and the second image is the terrain wireframe. As you can see in the third image, the road doesn't have enough gemoetry to snap correctly to the terrain so it will clip through it. That's what i need help with right now.

33 minutes ago, Scouting Ninja said:

Like so many things Unity is missing it has no scene spline or curve tools. So you will make your own or use some made by others and allow Unity to profit from the micro transaction.

If you are willing to fall for Unity's micro transactions here is a good one: https://www.assetstore.unity3d.com/en/#!/content/61926

If not here is a old tutorial that you will need to adapt: http://catlikecoding.com/unity/tutorials/curves-and-splines/

 

I know this isn't much help but I am done with Unity, after spending days trying to make my own font tools I just cave and bought a set, then I bought a set of 3D model editing tools and terrain tools and brush tools.

The funny part is I don't plan on selling the game I am making with Unity and already it cost over $250 to make. All I can do now is lie to my self, convincing my self that the $250 went to artist who needed it.:(

I agree that Unity is missing a lot of very important tools that other game engines like Unreal already have, and it's a shame. I was planning on buying an asset that does what i want, but i prefer scripting it myself so i can fully understand it and make it do exactly what i want(And for free!)

OK, so I've implemented the exact problem you are facing into, and I used splines also.  There are 2 problem spaces, you have identified both.

1 - Splines for roads.

2 - Decals in geometry.  

My solutions.

1. For spines on roads, you are on the right path.  I did something slightly different with splines.  Using a spline SPINE, I generate my geometry.  So the spine is only a guide, I create parallel splines based upon the perpendicular vectors.  I actually end up with 4 guide lines and I create 3 rows of triangles.  This gives you a decent resolution on most terrain, you can up this more if you have more detailed terrain.   That only solves part of the problem, gives you a decent approximation.  NOW...for the more interesting part, blending to your varying terrain.  The extra "rails" also allow for alpha blending per point to smooth off edges also.

2.  I actually render my spline roads to a separate back buffer texture, there is reason for this.  This is to deal with mapping to the terrain in a close approximate way.    When rendering my terrain, I sample from this buffer (as a texture) and apply to it per pixel.

This works well for forward rendering, but the limitation is that because the terrain depth hasn't been rendered before generating so z depth wont be tested.  Deferred works better as you will have access to the z depth.

I know you are using unity, so I cant offer a solution in that space, only the technique I used for decals.

My game is on the page below, its downloadable.   You will find spline decals on the waters edges, roads, decals used also burn marks.  Decals are also used for boat wakes on water as well.

https://www.facebook.com/InsaneSoftware.com.au/

Gl with this!

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

Advertisement
32 minutes ago, ErnieDingo said:

OK, so I've implemented the exact problem you are facing into, and I used splines also.  There are 2 problem spaces, you have identified both.

1 - Splines for roads.

2 - Decals in geometry.  

My solutions.

1. For spines on roads, you are on the right path.  I did something slightly different with splines.  Using a spline SPINE, I generate my geometry.  So the spine is only a guide, I create parallel splines based upon the perpendicular vectors.  I actually end up with 4 guide lines and I create 3 rows of triangles.  This gives you a decent resolution on most terrain, you can up this more if you have more detailed terrain.   That only solves part of the problem, gives you a decent approximation.  NOW...for the more interesting part, blending to your varying terrain.  The extra "rails" also allow for alpha blending per point to smooth off edges also.

2.  I actually render my spline roads to a separate back buffer texture, there is reason for this.  This is to deal with mapping to the terrain in a close approximate way.    When rendering my terrain, I sample from this buffer (as a texture) and apply to it per pixel.

This works well for forward rendering, but the limitation is that because the terrain depth hasn't been rendered before generating so z depth wont be tested.  Deferred works better as you will have access to the z depth.

I know you are using unity, so I cant offer a solution in that space, only the technique I used for decals.

My game is on the page below, its downloadable.   You will find spline decals on the waters edges, roads, decals used also burn marks.  Decals are also used for boat wakes on water as well.

https://www.facebook.com/InsaneSoftware.com.au/

Gl with this!

It looks like just what i want to achieve!(By the way, i also love how the ocean changes quality the farther you get from it).

I'm just getting started with shaders, so i don't know how all that back buffer texture and sampling works, so i'm a little confused there. But the way i understood it, you're drawing the roads "flattened" into the terrain texture/pixel shader instead of a road model over the terrain, right? I could probably do that with the roads and just raytrace the sidewalk, i guess clipping won't be noticeable on the sidewalk since it's meant to be taller than the road. I think Planet Coaster does something similar to this.

Will i be able to use a separate shader for the roads this way? I want to do some normal mapping on them.

Yeah correct, so the roads just use RGBA back buffer which I render to.   The clipping issue will be there if you don't use deferred rendering, its the only issue with the technique I have used.  I'm not sure how Unity does its rendering if it is deferred or not, I assume it is.

For the water I use a separate texture for this also, I use render slightly different.  I use the RGB values for a normal map, so my water texture is actually a full screen normal map.  I use the Alpha value to impact "whiteness" on the water.

I actually also don't ray trace the decals, I'm using a uniform grid of height data to ascertain the height of the vertices at each point.  I interpolate between each point on the grid to ensure the height of the vertices are semi accurate.

 

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

55 minutes ago, ErnieDingo said:

Yeah correct, so the roads just use RGBA back buffer which I render to.   The clipping issue will be there if you don't use deferred rendering, its the only issue with the technique I have used.  I'm not sure how Unity does its rendering if it is deferred or not, I assume it is.

For the water I use a separate texture for this also, I use render slightly different.  I use the RGB values for a normal map, so my water texture is actually a full screen normal map.  I use the Alpha value to impact "whiteness" on the water.

I actually also don't ray trace the decals, I'm using a uniform grid of height data to ascertain the height of the vertices at each point.  I interpolate between each point on the grid to ensure the height of the vertices are semi accurate.

 

Yes, Unity lets you choose between forward and deferred, and i'm using deferred for my project. I'll try to get something working, thanks! I'll ask for more help if i can't get it to work.

2 hours ago, ErnieDingo said:

Yeah correct, so the roads just use RGBA back buffer which I render to.   The clipping issue will be there if you don't use deferred rendering, its the only issue with the technique I have used.  I'm not sure how Unity does its rendering if it is deferred or not, I assume it is.

For the water I use a separate texture for this also, I use render slightly different.  I use the RGB values for a normal map, so my water texture is actually a full screen normal map.  I use the Alpha value to impact "whiteness" on the water.

I actually also don't ray trace the decals, I'm using a uniform grid of height data to ascertain the height of the vertices at each point.  I interpolate between each point on the grid to ensure the height of the vertices are semi accurate.

 

Okay, so i ran into a problem...

My project is a small "city builder", and the player will modify the terrain(I got the terrain tools already covered). If i simply let the player draw the road with the spline system, if they set the start and end of the road to have a mountain in between, the road will go through the mountain.

With the back buffer technique the road will still be drawn over the terrain, but it will look weird, right? Or did i completely misunderstand it?

This topic is closed to new replies.

Advertisement