Jump to content
  • Advertisement
LazyDuke

"3D Decals" for roads on terrain.

Recommended Posts

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!

Edited by LazyDuke

Share this post


Link to post
Share on other sites
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

Edited by MarcusAseth

Share this post


Link to post
Share on other sites
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.:(

Share this post


Link to post
Share on other sites
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!)

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
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.

Edited by LazyDuke

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

  • Advertisement
  • Advertisement
  • Popular Tags

  • Similar Content

    • By RoKabium Games
      Been a bit quiet recently, but we've been busy bug fixing and tweaking things... Now we have lots more 'Particle effects' in the game, specifically here the Flamethrower and Enemy attacks!
    • By Alexander_Vovk
      Hello Guys!
      Please share your experience, where is it better to find sales manager  specialists for indie team of 6 + people(remotely)?
      Maybe someone has a good experience of cooperation with finding projects through sale managers(USA and Canada)?
        
      In our team more than 6 developers. We are working since 2014 now we are looking for projects mainly on upWork and Unity Connect.
      But that's not enough 
      This is the site of our team https://www.sixteensq.com/             
                                                 https://www.behance.net/Dezignw136f
      Thank you
      Best Regards
      Alex Vovk
      Co-Founder of Sixteen Squares
      Alexander_Vovk@outlook.com
       
    • By JoshuaFraser
      Hi and thanks for reading, I have an issue with this reactive crosshair script, everything works fine until I start changing the offset. Give the script a go and you will see what I mean, when I do SetOffset(0f); it doesnt always set back to the origional state, if anyone can spot a fix I'd be super appreciative!
      using System.Collections; using System.Collections.Generic; using UnityEngine; public class ReactiveCrosshair : MonoBehaviour { [SerializeField] GameObject c_limb_prefab; private float center_offset = 0f; private float current_offset = 0f; private float max_offset = .5f; private int number_of_limbs = 4; private float limb_length = .05f; private float limb_width = .005f; private List<GameObject> c_limbs = new List<GameObject>(); public void SetupCrosshair(){ for (int i = 0; i < number_of_limbs; i++) { GameObject line_go = (GameObject)Instantiate (c_limb_prefab); line_go.transform.SetParent (this.transform); Vector3 limb_pos = new Vector3 (0f,0f,0f); //line_go.transform.position = limb_pos; line_go.transform.localPosition = limb_pos; LineRenderer line = line_go.GetComponent<LineRenderer>(); line.startWidth = limb_width; line.positionCount = 2; line.SetPosition (0, line_go.transform.localPosition + new Vector3(center_offset, 0f, 0f)); line.SetPosition (1, line_go.transform.localPosition + new Vector3(center_offset + limb_length, 0f, 0f)); line.useWorldSpace = false; c_limbs.Add(line_go.gameObject); } if (c_limbs != null) { OrientLimbs (); SetOffset (0f); } } public void OrientLimbs(){ for (int i = 0; i < c_limbs.Count; i++) { float rotation_step = 360f / (float)c_limbs.Count; c_limbs [i].transform.RotateAround (c_limbs[i].transform.position, c_limbs[i].transform.forward, 90f + (rotation_step * (float)i)); } } public void SetOffset(float _current_spread){ float offset = Mathf.Lerp (0f, max_offset, _current_spread); for (int i = 0; i < number_of_limbs; i++) { if (offset > current_offset) { Vector3 pos = c_limbs [i].transform.position + (c_limbs [i].transform.TransformDirection (Vector3.right) * offset); c_limbs [i].transform.position = pos; } if (offset < current_offset) { Vector3 pos = c_limbs [i].transform.position - (c_limbs [i].transform.TransformDirection (Vector3.right) * offset); c_limbs [i].transform.position = pos; } } Debug.Log ("SetOffset() offset: " + offset.ToString () + " _current_spread: " + _current_spread.ToString() + " localPos: " + c_limbs[1].transform.localPosition); current_offset = offset; } }  
    • By Erik Nivala
      So, as the title says i am trying to figure out a good way sync all that information with other players in Unity. My problem is that i can't come up with a good solution since i am used to creating classes for everything e.g. attachments are its own class and then the weapon would save a reference to that attachment. But since you can't send custom classes over [Command] & [ClientRPC] i am a little stuck. A solution for this would be giving each attachment for a slot a unique ID and then passing the ID to other player but i feel like that is very error prone if other ppl add a new attachment or the IDs get mixed up.
      Is there a "standard" way that this is usually done that i am missing?
      I am fairly new to programming so any help is appreciated!
    • By MintyLyton
      I'm looking for any team / people that need a programmer for their project. I'm looking to expand my portfolio which you can see Here. I'm more experienced with Unity but I can spend the time to learn new Engines if that's your preference. I have worked on Unreal Engine 4 before but I might take some time to re-learn it, if the project requires it. Feel free to DM here or use the contact info on my website. 
    • By ethancodes
      I'm working on a system for my game that will allow the player to stack pick ups in a queue. As one pick up expires, the next automatically activates. I'm having an issue though where if I pick up the first one, it activates fine, but if i pick up a second directly after it, it overrides the first one, activates the second one, and then once it has run it's course, everything goes back to normal gameplay, no first pick up. I'm not sure why this is happening. Hopefully someone can spot what I'm doing wrong in my code.
      Here is the code for the pick up manager:
      // Update is called once per frame void Update () { if (pickUpQueue.Count != 0 && !pickUpActive) { pickUpActive = true; pickUpQueue[0].ActivatePickUp(); } DeactivatePickUp(); } void DeactivatePickUp () { if (pickUpQueue.Count != 0 && pickUpActive) { Destroy (pickUpQueue [0]); pickUpQueue.RemoveAt (0); pickUpActive = false; } } And here is the PickUp:
      public override void ActivatePickUp () { ball.GetComponent<Ball>().Speed = 2.0f; //increase ball speed... ball.GetComponent<Ball>().StartCoroutine(timer); //...set time that power up is active }  
      There is also a Base Pick Up:
      public void OnCollisionEnter2D (Collision2D collision) { Vector2 tweak = new Vector2 (Random.Range(0f, 0.2f),Random.Range(0f, 0.2f)); this.gameObject.GetComponent<Rigidbody2D>().velocity += tweak; //if the pickup makes contact with the paddle or ball.... if (collision.gameObject.tag == "Paddle" || collision.gameObject.tag == "Ball") { GameObject.FindObjectOfType<GameManager>().GetComponent<PickUpManager>().pickUpQueue.Add(this); Destroy(gameObject); //...and finally destroy power up object } } As a side note, I am trying to find a solution to this that will work for all of my pickups. Some pickups are ammo based, some are timed. 
    • By NanaMarfo
      Hello Everyone!
      I am looking for a small team to do a rendering project with me. The roles I need are:
      -Character Modeller
      -Environment Designer
      -Environment Modeller(Found)
      You can use this in your portfolio and you will be credited at the end.
      If you are interested, please email me at marfo343@gmail.com. Thank you!
    • By D34DPOOL
      Edit Your Profile D34DPOOL 0 Threads 0 Updates 0 Messages Network Mod DB GameFront Sign Out Add jobEdit jobDeleteC# Programmer for a Unity FPS at Anywhere   Programmers located Anywhere.
      Posted by D34DPOOL on May 20th, 2018
      Hello, my name is Mason, and I've been working on a Quake style arena shooter about destroying boxes on and off for about a year now. I have a proof of concept with all of the basic features, but as an artist with little programming skill I've reached the end of my abilities as a programmer haha. I need someone to help fix bugs, optomize code, and to implent new features into the game. As a programmer you will have creative freedom to suggest new features and modes to add into the game if you choose to, I'm usually very open to suggestions :).
      What is required:
      Skill using C#
      Experience with Unity
      Experience using UNET (since it is a multiplayer game), or the effort and ability to learn it
      Compensation:
      Since the game currently has no funding, we can split whatever revenue the game makes in the future. However if you would perfer I can create 2D and/or 3D assets for whatever you need in return for your time and work.
      It's a very open and chill enviornment, where you'll have relative creative freedom. I hope you are interested in joining the team, and have a good day!
       
      To apply email me at mangemason@yahoo.com
    • By Andrew Parkes
      I am a talented 2D/3D artist with 3 years animation working experience and a Degree in Illustration and Animation. I have won a world-wide art competition hosted by SFX magazine and am looking to develop a survival game. I have some knowledge of C sharp and have notes for a survival based game with flexible storyline and PVP. Looking for developers to team up with. I can create models, animations and artwork and I have beginner knowledge of C sharp with Unity. The idea is Inventory menu based gameplay and is inspired by games like DAYZ.
      Here is some early sci-fi concept art to give you an idea of the work level. Hope to work with like minded people and create something special. email me andrewparkesanim@gmail.com.
      Developers who share the same passion please contact me, or if you have a similar project and want me to join your team email me. 
      Many thanks, Andrew.

  • Advertisement
  • Popular Now

  • Forum Statistics

    • Total Topics
      631394
    • Total Posts
      2999749
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!