Sunday, 24th May, 2009

Rendering roads ontop of terrain in Unity3D

Filed under: Unity3D — dominique @ 04:13

I've already my roads most of the time hovering above the terrain but still sometimes the terrain temporarily "shines" through depending on distance and view angle. I guess it's due the terrain's LOD, so some polys might become higher than intended on some LOD levels.

Terrain and roads intersection

In Virtools there is something called "Render Priority": a per-object settings that can be adjusted in the hierarchy manager. It can help for these kind of situations. I was looking for something similar in Unity. The editor itself doesn't seem to have anything related but the shader framework, called ShaderLab, itself has.

So you have to download the built-in shader sources, and create a derivate. First I thought it's the SubShader RenderQueue-Tag, but that didn't had any visual impact. You have to adjust/bias the z/depth buffer value via the Offset state.

Less intersection due Offsetting the depth

In my case I went through the "diffuse" shader and added an "Offset -1,-1" to any spot where RenderStates where set. Like you can see from the image above, it helped a lot. Unfortunately it's not perfect, I am still having tiny but annoying cracks here and there when driving or flying along the roads:

still some small artefacts

I guess I've no choice and adjust further the terrain heights manually to get rid of them…

Bookmark and Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • Digg
  • Reddit
  • Google Bookmarks
  • YahooMyWeb
  • Live-MSN
  • Facebook

7 Comments »

  1. [...] Rendering Roads on Top of Terrain with Unity3D Share and Enjoy: [...]

    Pingback by Unity 3D Procedural Content Generation Roundup diamondTearz’s Flex, Flash, iPhone & Unity3D Blog — Wednesday, 22nd July, 2009 @ 04:45

  2. i realy need your help. iam developing a game using unity3d, but iam finding difficulty in developing the road since my game is a racing game. i will greatly appreciate your assistance. Thanks.

    Comment by chaiwa berian — Friday, 31st July, 2009 @ 04:34

  3. [...] Rendering Roads on-áTop of-áTerrain with Unity3D [...]

    Pingback by Precedural Content Generation in Unity3D — Tuesday, 10th November, 2009 @ 03:40

  4. Hai!! i need a 3d road model,like the one in your screenshots, can you share one with me. iam doing a school project(a bicycle racing game) . please help. i will graetly appreciate your help.

    Comment by chaiwa — Wednesday, 30th December, 2009 @ 09:46

  5. This look interesting to me. Nice looking 3d road model you make. Do you intend to sell it?

    Comment by 3d renderings — Monday, 18th January, 2010 @ 03:23

  6. [...] Rendering Roads on Top of Terrain with Unity3D [...]

    Pingback by Procedural Content Generation in Unity3D — Wednesday, 17th February, 2010 @ 04:52

  7. [...] Rendering Roads on Top of Terrain with Unity3D [...]

    Pingback by Procedural Content Generation in Unity3D » Infinite Unity3D — Sunday, 28th February, 2010 @ 10:40

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

:D :) ^_^ :( :o 8O :shock: 8) ;-( :lol: xD :wink: :evil: :p :whistle: :woot: :sleep: =] :sick: :straight: :ninja: :love: :kiss: :angel: :bandit: :alien:
Bookmark and Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • Digg
  • Reddit
  • Google Bookmarks
  • YahooMyWeb
  • Live-MSN
  • Facebook