Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Hollowed Mountain

Discussion in 'Editor & General Support' started by NathanFX, Dec 15, 2007.

  1. NathanFX

    NathanFX

    Joined:
    Dec 15, 2007
    Posts:
    4
    Hi, I'm just starting game designing and I have almost no clue as to what I'm doing. That said, I'm sorry if this is a stupid question, but I have no clue about this and need help.
    I was wondering if there was a way to use Unity's "create terrain" option to make a mountain, and then hollow out caves and caverns in some way. Help would be highly appreciated!
     
  2. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
  3. NathanFX

    NathanFX

    Joined:
    Dec 15, 2007
    Posts:
    4
    Thanks, but I couldn't find what I was looking for. So maybe I can't hollow out terrain, but are there any other methods you could recommend for doing what I want to do?
     
  4. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    Nope, no diging. You can only do this along the y-axis, so an open crater would be possible but for caves, tunnels and similar geometry you'll have to use the modeller or script your way via the mesh interface.
     
  5. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    I think this is a good question.

    What if i want to make a Level in wich i can walk on the land and also in some dungeons?

    In Torque you can cut out a hole in the ground and positioning the dungeon so that the entry is where the hole is and then you have to build something around the hole and the entry so that it loos nice.

    How can we do that in Unity?
     
  6. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    You can't just push the terrain into a hill forming a cave, because the terrain is a heightmap system only and doesn't support overhangs. But there is a hack you can do. It involves making a flat part of the terrain (probably near vertical) then surrounding it with props like rocks to hide a seam you are about to generate. Then with this shader , clever layer masks and guesswork modeling you can cut a visual hole in the terrain with whatever else you want behind it (hand made cave, door into underground building etc). Then you just need to build a collider model that is the same shape as the hole and the terrain around it, which you swap for the terrain collider using Physics.IgnoreCollision on a trigger near the threshold. The only problem is if your camera is in between the terrain and the depthmask mesh, which you can detect and fix with a raycast.

    Its pretty complicated but possible. I think in the future UT plans on adding a feature that lets you cut proper holes in terrains.
     

    Attached Files:

  7. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    Normally you either model the whole scene the way you want it or you combine the terrain with imported/generated models, so place your mountain with the caves in the terrain. Would be nice if you just could sculpt your way through somekind of a polygon block but it's not possible yet. If i remember correctly Crysis for instance was combining voxel objects with their polygon terrain...
     
  8. NathanFX

    NathanFX

    Joined:
    Dec 15, 2007
    Posts:
    4
    Wow... tis is way too complicated for me, but it looks like I'll have to try! :)
     
  9. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    I went ahead and did an example, because I wasn't even sure myself that it was possible. Feel free to pick it up.

    Realistically I think you would probably want to generate such portals procedurally instead of setting them up manually, to accommodate with oddly shaped terrain.
     

    Attached Files:

  10. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    Good job including your example Yoggy. :p
     
  11. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    However my advice with these things is, don't use it until you need it badly or you're just curious about playing around with it as most of the time it'll turn out that you'll loose time contrary to using a officially supported and tested solution were you don't have to change things afterwards.
     
  12. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Large game companies use portals. And so can you :wink:
     
  13. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    To Yoggy: love your DepthMask example!

    Before I saw this post I tried to just paint a transparent zone (using a 0% alpha texture), but it doesn't seem to work.
    Does that mean that the terrain shader ignores alpha? If so, then what is the SplatAlpha? I thought it did just that, but it's probably just the name confusing me.
     
  14. chadchat

    chadchat

    Joined:
    Apr 5, 2008
    Posts:
    154
    I know Taumel alluded to this already but I thought I'd go into a bit more detail..

    One way of dealing with caves and such things in a heightmap is to model the terrain you want in Unity and then export that heightmap to your modeling program. Use the heightmap as a displacement map on a mesh that is (although it doesn't need to be) the same dimensions as the terrain in Unity, and then grab that section of the mesh that you want to build into. Do your modeling work, applying the same textures and resolutions you have in your scene, and simply import that as an asset. Then you have to sculpt away that area in your Unity terrain and blend in your cave section.

    Of course you will have a seam to deal with, but you can use grass and assets to blend it as best you can. Hope that helps.
     
  15. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Thanks Chad, but I'm not worried about the modeling part.
    Our level is mine-themed, so we just have one big mountain (terrain engine), entry points (little wood huts that will acts as seams + disable the terrain collider --mesh + triggers), then big tunnels (mesh) inside the mountain.

    That's the part I'm curious about: how do you sculpt?

    Yoggy uses a DepthMask. What I was trying to accomplish was to just paint the hole, just like you would paint stone or sand or whatever: create a splat texture, but using a 100% transparent texture... doesn't work though, so I'm wondering if I did it wrong or if the terrain shader is incapable of painting transparent splats.
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You didn't do anything wrong; the terrain shader doesn't do transparency.

    --Eric
     
  17. chadchat

    chadchat

    Joined:
    Apr 5, 2008
    Posts:
    154
    Ahh right, I meant nothing as elaborate as that I'm afraid. By 'sculpt' away I meant you would lower that part of the terrain to allow for the mountain 'cap' that contained your cave.

    I guess you want to use the Terrain tech for painting grass etc ..because otherwise you could just use a mesh instead. You'd get better shadows that way too if I understand it correctly.
     
  18. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Eric: Thanks for the confirmation!

    Chad: check out Yoggy's posts (here and here), his solution isn't that complicated... less than the sculpting you suggest I think... but still not as cool as painting holes ;)... I guess we'll just have to wait for an update from UT to get this kind of coolness!
     
  19. chadchat

    chadchat

    Joined:
    Apr 5, 2008
    Posts:
    154
    yeah thx, I looked at those. I think it's really great that you can hack this in. I honestly can't wait to try it out. My only issue would be that, as Yoggy states, it helps if the area is near vertical (I don't know if it has to be this way), and steepness in Terrains is bad due to stretched textures. It sounds like you've got that covered though.
     
  20. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Err, I don't know, I don't really see why it would need to be vertical or steep. According to the wiki the DepthMask shader was made to cover water inside boat hulls so it can certainly work horizontally.

    What you do need is a rather flat zone where you're going to carve, so true you probably can't carve just anywhere... but if you have an object to put in front of the hole (like our mine huts), you can cover pretty much anything and not worry about seams.
    Probably works better with artificial structures than with natural caves...
     
  21. Neodrop

    Neodrop

    Joined:
    Oct 24, 2008
    Posts:
    1,359
    What about Glow Shader on this method? Alpha-depth uses the alpha-channel and discard Glow effect in the scene.
    How can I use Glow and AlphaDepth Mask together ?
     
  22. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    i ve also tried to figure this out,
    i ve been reading this thread and sound too much work arround, since i was used to torque where you just rise up a mountain in the built in terrain editor, cut a hole, and just import you cave modeled from a third party program, then use polysup to the cave and that was it. so simple task.

    I was wondering if, why dont just build the mountain and the cave already welded to it in your third party program and just import the whole mountian and cave to unity, although you may have texture matching issues since may be hard to seamlessly match texture of the mountain with the terrain in unity.

    ohh well, ill give it a try and see whats comes up.
     
  23. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    I am also very interested in combining Glow Shader and DepthMask. Can anyone help? :roll:
     
  24. capnbishop

    capnbishop

    Joined:
    Oct 4, 2007
    Posts:
    50
    After playing around with the example project that forestjohnson, I thought to expand on it slightly.

    That particular example requires that the trigger which handles the transition between the terrain collider and the cave collider be the same shape as the cave. It's clear to see where this is a problem by making the trigger very shallow, as to just cover the entrance of the cave. As soon as the player exits the back side of the trigger, the script swaps the IgnoreCollision between the cave and the terrain, and the player will either fall through the floor or suddenly pops up to the terrain. Not the desired effect.

    I made a slight modification to the script so that it recognizes the difference between the front and back of the trigger. It does so by checking the colliding object's z position relative to the trigger's local space, and only bothers switching the ignored collisions if the object is exiting backwards, toward the terrain.

    Essentially, the trigger can now be placed so it is just covering the cave entrance. It switches to use the cave collider when the player passes through it, into the cave, and switches back to the terrain collider only when the player exits backward, out of the cave.

    Code (csharp):
    1. var terrain : Collider;
    2. var cave : Collider;
    3.  
    4. function OnTriggerEnter (other : Collider)
    5. {
    6.     Physics.IgnoreCollision(other, cave, false);
    7.     Physics.IgnoreCollision(other, terrain, true);
    8. }
    9.  
    10. function OnTriggerExit (other : Collider)
    11. {  
    12.     if (transform.InverseTransformPoint(other.transform.position).z < 0) {
    13.         Physics.IgnoreCollision(other, cave, true);
    14.         Physics.IgnoreCollision(other, terrain, false);
    15.     }
    16. }
     
  25. capnbishop

    capnbishop

    Joined:
    Oct 4, 2007
    Posts:
    50
    I've expanded on the script even more. Basically I thought it would be nice to be able to visually see the entrance and exit of the portal trigger. Adding this code to the trigger will use the gizmo drawing to highlight the front of the trigger with blue, and the back with red:

    Code (csharp):
    1. function OnDrawGizmosSelected () {
    2.     var center = collider.center;
    3.     var size = Vector3(collider.size.x, collider.size.y, collider.size.z);
    4.    
    5.     var matrix = Gizmos.matrix;
    6.     Gizmos.matrix = transform.localToWorldMatrix;
    7.    
    8.     var center1 = Vector3(center.x, center.y, center.z - size.z/2.0);
    9.     var center2 = Vector3(center.x, center.y, center.z + size.z/2.0);
    10.     size.z = 0;
    11.    
    12.     Gizmos.color = Color.blue;
    13.     Gizmos.DrawWireCube (center1, size);
    14.     Gizmos.color = Color.red;
    15.     Gizmos.DrawWireCube (center2, size);
    16.    
    17.     Gizmos.matrix = matrix;
    18. }
     

    Attached Files:

  26. lues de fabulam

    lues de fabulam

    Joined:
    May 18, 2009
    Posts:
    41
    Beautiful workaround and even better improvements. I have an AI related concern though. Can we have AI make visibility checks on objects beyond the shader and inside the cave from outside?

    On the other hand, since the faces on terrain are one-sided, AI should be able to do it just as normal, looking from inside, from behind the terrain faces, to out, right?
     
  27. Doo 2000

    Doo 2000

    Joined:
    Apr 5, 2009
    Posts:
    60
    you could always create part of the terrain in cinema 4D and ise the bolean tool (spelling?) to create a cave than export to unity.
     
  28. Vimalakirti

    Vimalakirti

    Joined:
    Oct 12, 2009
    Posts:
    755
    Great work! Can't wait to try this out when I get home to my computer!
     
  29. Vimalakirti

    Vimalakirti

    Joined:
    Oct 12, 2009
    Posts:
    755
    I got the whole thing working, but what I see below the terrain is flat blue, like my plain skybox, I guess. See, I'm trying to make a staircase down into a crypt type place, underground, so I'm going straight DOWN, not sideways.

    It's not the skybox, though it's the same flat blue. I tried it on a hilltop and it's flat blue. Maybe something's wrong with my shader?
     
  30. Katori

    Katori

    Joined:
    Nov 30, 2009
    Posts:
    60
    I'm getting the same thing, and I was really counting on this method to help me with my cave problem.

    Did a change in Unity break this shader?
     
  31. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    Will have to try that.

    But my thought was to try using two terrains butted up to each other and create an opening to put your modelled cave in on the join.

    Would that work?
     
  32. johnnyfire

    johnnyfire

    Joined:
    May 21, 2010
    Posts:
    3
    Well I was supposed to finish my project today. I stayed up all night trying to work out how to dig into the terrain I realised that Unity need to do something.
    Putting two Terrain together Hmm! will that work? please help ! I cannot sleep
    :? javascript:emoticon(':?')
     
  33. thellama

    thellama

    Joined:
    Mar 25, 2010
    Posts:
    360
    Here's the totally bas akwards way my team and I are doing caves. Works pretty darn well.

    First we model the terrain how we want it. Then in the locations we need caves, we model the caves in Maya and bring them into unity. Place them into the scene and then cut giant valleys and ditches into the terrain to conform to the cave system. Because you will never see beyond the cave walls you won't notice the huge valley. Then we cover the cave entrance with rocks and a large fake cliff face.

    The result is a cave system in a mountain. Since you never fly in this game or get high enough to see the mountains from above, the caves work great.

    Games are nothing more than smoke and mirrors.

    NOTE: The car tutorial has some awesome examples of how to do this.
     
  34. Vimalakirti

    Vimalakirti

    Joined:
    Oct 12, 2009
    Posts:
    755
    I'm not sure why people aren't using the holeinterrain.unityPackage that forest johnson so kindly included in his post on page 2. It works well and it's all right there. You don't even need to do any scripting or shader writing, just use the elements he's already put together and put them in your scene.

    Is there some problem someone was having with the package that I didn't see (besides the usual amount of de-bugging)?
     
  35. thellama

    thellama

    Joined:
    Mar 25, 2010
    Posts:
    360
    I used the demo, while cool the problem is unless you use the written shader for objects beyond the depth mask they cannot be seen while the camera is behind the mask, including the character. This is a current inconvenience seeing as the player should always be able to see her character.
     
  36. Vimalakirti

    Vimalakirti

    Joined:
    Oct 12, 2009
    Posts:
    755
    That's true. This is a serious problem. I wonder if anyone from the Shader Lab forum could help with this. Perhaps a post over there would get some help.

    If anyone solves this, please keep us posted!
     
  37. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    What I wondered is if you can't simply layer multiple terrains on top of each other to create a) a surface layer, b) an underground ceiling layer, and c) an underground floor layer.

    Then to be able to move from a surface layer to the underground layers you'd have to split the terrain into smaller terrains aligned to each other. The surface layer would have to dip down to meet the cave floor at its edge. Wherever you want to enter a cave, a surface terrain has to have an edge. Then you can easily transition between terrains, have a bunch of caves, and have very large underground areas with hanging down rock/stalagmites etc and also a floor. And where the two lower terrains meet you create your walls.

    Would this not work?
     
  38. thellama

    thellama

    Joined:
    Mar 25, 2010
    Posts:
    360
    Terrain cannot be rotated, and the underside is culled so you'll see right through it. unless you can make terrain double sided I can't figure out a way to make your idea work.
     
  39. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hmm oh, so you'd need some kind of `ceiling shader` I guess to draw the back-face of the ceiling layer?
     
  40. thellama

    thellama

    Joined:
    Mar 25, 2010
    Posts:
    360
  41. johnnyfire

    johnnyfire

    Joined:
    May 21, 2010
    Posts:
    3
    can you lay terrains side by side? like in the diagram
     

    Attached Files:

  42. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Yah you can do that, although if you just make the surface terrain dip down at the edge as a slope going down to the cave floor, where it is at cave floor level before the cave floor terrain takes over, you wouldn't need the terrains 3 and 4 as filler.

    You could also implement overhanging landscape parts on the surface by implementing two additional terrain layers, one for the underside of the overhangs and one for the top side. But then you need a way to render the outside of the terrain transparent otherwise you'll have to have square rocks.
     
  43. johnnyfire

    johnnyfire

    Joined:
    May 21, 2010
    Posts:
    3
    Thank you very much Imaginary human if I do use this technique do I still need to use the Terrain.SetNeighbors and if the answer is yes how do I apply it
     
  44. Balmung

    Balmung

    Joined:
    May 9, 2010
    Posts:
    40
    My idea is this (fast and simple example):



    When the cave is above all other in the level, the player can not go higher, he never will see that corner, only that what he should see.

    Or you plan your map so, that the terrain not overlap the entry.

    The cave needs anyway a ceiling and the entry can cover with rock objects.

    I think that is the easiest and not the baddest legally way to make a cave so that the mounten looks good. And when you make it right the seam is near invisible (dont get it in this short time).
     
  45. U2

    U2

    Joined:
    Aug 12, 2008
    Posts:
    216
    The package offered in here for hole in terrain doesn't seem to work anymore with Unity 3. Anyone been able to make it work?

    ============

    Seems like the way to make it work is to create a selection of underground shaders with the proper geometry-101 and 102 etc.. then switch between them and the normal difuse etc.. depending on if the object is below or above the terrain.
     
  46. crasyboy42

    crasyboy42

    Joined:
    Jun 29, 2010
    Posts:
    28
    this isnt working on the new unity 3.0 :( please help
     
  47. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    733
    Last edited: Nov 27, 2010
  48. Mingo

    Mingo

    Joined:
    Nov 14, 2010
    Posts:
    39
    Be warned that using a method like the above has the potential to recursively render the terrain into that "window" mesh if you set up the layer incorrectly, and that will very quickly crash Unity and possibly your machine. Be careful when setting it up, and maybe disable your terrain first.
     
  49. fatshoe

    fatshoe

    Joined:
    Sep 28, 2010
    Posts:
    16
    The hollowed mountain demo does not work in Unity 3.X any more.

    Does anyone have any idea how to get it run in 3.x?
     
  50. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    733
    yes, it could be a good thing. Someone can fix "hollowed mountain" on Unity 3.x .?