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

Terrain Hole System

Discussion in 'Assets and Asset Store' started by Venryx, May 13, 2013.

  1. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    This Unity extension lets you make holes in your terrain that characters and other objects can go through.

    Webplayer Demo
    Asset Store Page

    Features:
    • Enables transparency for terrains that 'just works'. Simply 'paint on' a transparent texture, and the areas painted will become transparent.
    • Comes with an "object fall through" script, which disables terrain collisions, thus creating genuine holes.
    • Has a "cutout mode" option, for choosing whether you want transparent edges to be rigid or smooth.
    Notes:
    • With shadows enabled, some transparent areas may have darkening artifacts. This can make the surface look a bit odd.
    • With "cutout mode" disabled, partially transparent areas will "clip" opaque terrain areas behind it. You can fix this by enabling "cutout mode", or by disabling terrain shadows (as explained in the manual).
    Screenshots:
    http://d.pr/i/Bx1j+
    http://d.pr/i/HEfX+
    http://d.pr/i/jM00+
    http://d.pr/i/IDDn+
    http://d.pr/i/MRAX+
     

    Attached Files:

    Last edited: May 13, 2013
    ratchai and tequyla like this.
  2. sgoodrow

    sgoodrow

    Joined:
    Sep 28, 2012
    Posts:
    150
    How does this interact with fog and image effects? I'd like to write the depths of the objects behind the window to the depth buffer, is that possible? It might need a second camera and some clever depth blitting...?

    Also, I can't afford to use a terrain texture for this, is there another way to tell the renderer when to hide the terrain (external mask, mesh, etc)?
     
    Last edited: May 24, 2013
  3. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    "How does this interact with fog and image effects? I'd like to write the depths of the objects behind the window to the depth buffer, is that possible? It might need a second camera and some clever depth blitting...?"

    I really don't know. I haven't used it with image effects, but with slight fog in my game, I haven't noticed anything odd, about the terrain.

    Also, "I'd like to write the depths of the objects behind the window to the depth buffer, is that possible?", seems like something that wouldn't be affected by changes to the terrain shader. Can you explain what you mean more?

    "Also, I can't afford to use a terrain texture for this, is there another way to tell the renderer when to hide the terrain (external mask, mesh, etc)?"

    Yes, there are some other ways--but they would basically be a different plugin/product, then. One way would be to create a copy of the terrain mesh, pop out the vertices that aren't transparent parts, then have it use a shader that writes to the depth buffer, preventing the terrain behind it from being drawn. But again, this would be a different plugin, as it's fundamentally quite different from how my plugin does it. (it would shift the changes entirely off of the terrain shader, onto a special shader for a procedurally generated mesh)
     
    Last edited: May 26, 2013
  4. idlebyte

    idlebyte

    Joined:
    Feb 3, 2013
    Posts:
    17
    Can this be applied to any object other than a terrain? I have need to make on demand dynamic holes in other objects. Ideas?

    Thanks,
    -Idle
     
  5. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Not as it's currently implemented; however, the basic idea I used could be used for other objects. You would just need to have some sort of 'second texture', that acts as a map for what areas are supposed to be transparent (which you'd write to whenever you're making dynamic holes). Then you'd have to make a custom shader that uses that data when calculating the final alpha value, to be sent to the GPU for drawing. Collision-disabling for hole areas would be more complicated, but there's probably some way you could do it. (I think you'd have to have it enable/disable collisions after a collision actually occurs, though, since then is the only time you know exactly where the collision would happen, on the object's surface, which you need to know to check for transparency)
     
    Last edited: May 31, 2013
  6. delibowlen

    delibowlen

    Joined:
    Jan 16, 2013
    Posts:
    57
    hi, just bought your asset, and it really fits my Needs, but i have one issue:

    the transparent area appears in black Color all over so the texture itself... am i missing something?
    i have no shadows enabled...

    EDIT: tried the Demo in your asset, and it gets the same error. all transparent Areas Shows up black... ;(

    $holeerror.png

    EDIT2: just made a new Project and it works perfectly... so what could be wrong with mine?

    SOLVED: It was a TerrainReplacementShade that was causing the issue... Great asset, works now for me!!!
     
    Last edited: Jun 10, 2013
  7. UnleadedGames

    UnleadedGames

    Joined:
    Feb 17, 2008
    Posts:
    242
    Can you please confirm rather or not this will not work with deferred rendering mode, so far I have had no luck.
     
    Last edited: Jun 25, 2013
  8. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    The current version on the Asset Store does not work with Deferred Rendering. I just tested it.

    However, while testing it I also discovered how to fix it, without any negative side effects.

    Simply change the "RenderType" to "Opaque", and add " exclude_path:prepass" to the end of the "#pragma surface surf Lambert" line.

    I'll update the Asset Store version, though it may be a few days because I'm very busy with another project. (a website I'm helping a friend make)

    I've tested it myself in Deferred Mode, though, and it does work. If you have trouble adding the above fixes, (which is unlikely), PM me and I'll send you the complete, fixed shader file.
     
    Last edited: Jun 25, 2013
  9. UnleadedGames

    UnleadedGames

    Joined:
    Feb 17, 2008
    Posts:
    242
    Thank you for the quick reply, I'll test this fix out and let you know how it goes!
     
  10. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Wow, I made a mistake. The "RenderType" should be changed to "Opaque", NOT "Transparent". I had accidentally copied the original value, instead of the new value. I've edited my previous post.

    Note also that the current Asset Store version has another problem: it isn't affected by point lights. This issue too I have fixed but haven't yet re-uploaded it. If you need point lights in your project, I can send you the latest shader files ahead-of-release.
     
    Last edited: Jun 25, 2013
  11. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Did the above changes fix it?
     
  12. Mordakie

    Mordakie

    Joined:
    Apr 17, 2013
    Posts:
    13
    I just purchased this system and it doesn't seem to be working for me either. It just renders the areas I paint black. Am I supposed to be doing something with the shaders? They're not mentioned in the Manual.

    I made the changes as you instructed here to the scripts and still don't see any changes.

    I am using deferred rendering with a directional light.

    Any help you can offer would be appreciated.
     
  13. Mordakie

    Mordakie

    Joined:
    Apr 17, 2013
    Posts:
    13
    Well I added the shader to the terrain material, but I get a really strange result. It looks like I can see through some of the painted area on the terrain, but all other meshes behind the exposed area are rendered transparent as well. So all I see through the holes are skybox.

    $TerrainHole.JPG
     
    Last edited: Jul 2, 2013
  14. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    That's odd. I have gotten results similar to this while developing the plugin, but only when cut-out mode was disabled, and the scene had a RenderSetting-based Skybox.

    Could you reproduce this display issue in some sort of 'test scene', that you can then send me? That would give a much better chance for me to fix it, since otherwise I'm pretty much just guessing wildly at where the problem is. (if I have an actual scene with the problem, I can just swap out parts of the shader with the equivalent parts from the original, and just keep narrowing it down until I find the exact lines of code that are causing it)

    Thanks, and sorry you're having trouble with the shader.

    EDIT: Oh, and no, you shouldn't have to 'do anything' to get the shader working. It should work automatically as soon as you import it into your project. (It uses the same 'shader name' as the built-in terrain shader, so when it's imported, Unity thinks its the built-in shader and from that point on uses it for rendering all terrains. The scripts are just for fixing one possible clipping issue, allowing you to change some settings, and of course for controlling the 'terrain fall-through'.)
     
    Last edited: Jul 4, 2013
  15. Mordakie

    Mordakie

    Joined:
    Apr 17, 2013
    Posts:
    13
    After doing a bunch more testing, it appears this system just plain doesn't work in DX11 mode with deferred lighting. Even the demo scene in a new project displays incorrectly. :(

    $TerrainHoleIssues.JPG
     
  16. Mordakie

    Mordakie

    Joined:
    Apr 17, 2013
    Posts:
    13
    Nevermind. Sorry about that. It looks like after I applied the changes to the shaders you posted here, the plug-in works.

    I discover the issue I'm having is actually linked to having the ground material set to Nature/Terrain/Bumped Specular so that I can have normal maps on the terrain.

    Is there any way to get this type of material to still correctly display the holes?

    There is also an issue that if I have shadows on while in deferred mode it draws the skybox over whatever's behind the painted area while in scene mode and does some even stranger things while in game mode.

    And this is all still inside the demo level in a fresh project with only the player settings modified and a directional light added to the scene. This stuff really should have been tested before submitting it to the store.

    I'm afraid as it currently is, there really needs to be a HUGE warning sign on this plug-in stating that it only works at all in very specific circumstances.
     
    Last edited: Jul 7, 2013
  17. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Yes. But I would have to add my transparency changes to that shader then too. This shouldn't be too hard... I'll probably do it in the next update.

    I've tested the above myself and get no unexpected results.

    These first two images are of the Demo scene with Deferred Mode and shadows enabled. As you can see, the shadows work and you can see through to the inner cave walls. The shadowing artifacts in the first one are what I mentioned in the Asset Store description. (it darkens some of the terrain 'behind' the transparent surface rather than just the surfaces beneath)
    $Defferred2.png
    $Defferred1.png

    This third image is of the Demo scene with Deferred Mode enabled, shadows enabled, and a second directional light added (to match fully with the changes you described). Again, I don't get the same 'behind-object clipping' issue you've described.
    $Defferred3.jpg

    Are you sure you didn't make any other changes to the Demo scene? If not, I'm not sure what the cause would be.

    I suppose it could also be that I left something out in describing my shader changes (though I did check pretty carefully). To make sure, I'll send you a 'pre-release' of the updated shader files, and you can test those. If there are still problems with the above changes to the Demo scene, then it's most likely a problem with the graphics card, and I would probably need to ask someone else how to fix it at that point.
     
  18. Mordakie

    Mordakie

    Joined:
    Apr 17, 2013
    Posts:
    13
    Wow, it's really impressive how much effort you've put into supporting your system. Thanks for taking all the time it took to look into this. You really are an A+ developer!
     
  19. Enno

    Enno

    Joined:
    May 26, 2013
    Posts:
    4
    Thanks for this straight forward, easy to use system. So far everything works as expected.
    I have a problem though. I want to use the shader package "Advanced Terrain Shader v2 1.0111", and whenever I import this package to my project, the "Terrain Hole System" stops to work. I can still go through the holes in the terrain, but the "Transparent" texture does appear untransparent and black. I assume this has something to do with conflicting shader overrides.

    Is there any way to combine these two packages?
    Thanks for your help
     
    Last edited: Aug 2, 2013
  20. sgtkoolaid

    sgtkoolaid

    Joined:
    May 11, 2010
    Posts:
    899
    I am having this issue with ATS colormap terrain ultra shader 1.6c. it goes through fine, but mine is also transparent hole is also black as well. any thoughts?
     
  21. alemke

    alemke

    Joined:
    Feb 26, 2013
    Posts:
    12
    Is it possible to use the place tree brush or the paint details brush on the transparent sections of the terrain?
     
  22. sgtkoolaid

    sgtkoolaid

    Joined:
    May 11, 2010
    Posts:
    899
    I would imagine so. so as long as the fall through script is not attached to the object that is placed over the transparency. that is the understanding I got when applying the script to my player character.
     
  23. alemke

    alemke

    Joined:
    Feb 26, 2013
    Posts:
    12
    Any idea if this extensions will work with the Oculus Rift?
     
  24. Enno

    Enno

    Joined:
    May 26, 2013
    Posts:
    4
    Please update this asset package so that it works with bumpmapped terrains and especially the ats v2 package... otherwise buying this has been absolutely useless for me. I don't see how anybody can work with non-bumpmapped terrains nowadays. Plane ground textures look plain awful.
     
  25. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Yes.
     
  26. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    I have no idea. I haven't even heard about the above until today after doing a quick search on it. (and am just now opening the Wikipedia page on it)

    I would guess that it would though, yes, since the Oculus Rift device seems just to be a wrapper around existing graphics, mouse, and keyboard functions.
     
  27. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    PM sent.

    PM sent.
     
  28. Miggl

    Miggl

    Joined:
    Aug 20, 2013
    Posts:
    13
    Hi Venryx, i've been reading up on your work on the terrain holes conundrum. Has the asset store package been updated with all the latest mentioned in the thread, as well as working with bump-mapped terrain?

    Thanks!
    ~Mike
     
  29. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Your question prompted me to action!

    I just now submitted the next version.

    Here's the list of changes:

    * Added a set of THS terrain shaders that work with bump-mapping.
    * Added trees to the demo scene's terrain.
    * Fixed not-being-able-to-exit-alcove issue.
    * Added interface toggling of no shadows mode.
    * Fixed FirstPass shader not working in Deferred Rendering Mode.
    * Fixed point lights not affecting terrain issue.
     
  30. TimeSniper

    TimeSniper

    Joined:
    Nov 26, 2012
    Posts:
    18
    Considering to buy this. But before that, I'd like know if it supports very small hole. To be more precise, I need to place a hole cup under that small hole in my golf game. When the ball is within that hole, it has to fall down into the hole. Will it be possible?
     
  31. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    @TimeSniper

    Email sent. (sorry, I hadn't checked my email for a few days)

    In short, yes.

    (email copy:)
    - - - - - - - - - - - - - - - - - -
    Yes, it would work, as long as you set your terrain's alphamap to a high enough resolution. (if you wanted the hole that small, that is)

    Note that at some point, increasing the resolution will reduce performance, though. (since its also used by the rendering engine for drawing the terrain)

    It should be fine for a golf game, but if performance did become an issue eventually from this, there are a couple ways you could get around the performance decrease. The first would be to create a second "invisible" terrain, that acts as the "collider" version of the terrain, that has the markings of the area in high resolution, but doesn't actually get drawn and so doesn't reduce performance. The other option would be to create an invisible set of planes, just around a larger terrain hole, thus reducing its size, in effect.

    And yes, the physics should work alright inside the hole. My terrain plugin, when it 'allows an object through a hole', simply disables collisions between the terrain and the object temporarily; so it should physically act the same as if there were just no terrain there at all (speaking of after the ball is in the hole, that is--and btw, it does automatically re-enable terrain<>ball physics once the ball moves back out from the hole).
    - - - - - - - - - - - - - - - - - -

    @Everyone

    The updated version of the plugin was accepted yesterday, by the way, with the changes mentioned in my above post.
     
    Last edited: Sep 18, 2013
  32. MaestroGames

    MaestroGames

    Joined:
    Jul 5, 2012
    Posts:
    16
    I have a question not sure if its been answered yet as its really odd and I am sure its something silly on our end, I was wondering if you could PM and we could talk about it. Thanks!
     
  33. SkermunkelStudios

    SkermunkelStudios

    Joined:
    Dec 29, 2012
    Posts:
    156
    I am also having problems merging the Terrain Hole system with ATS Colormap ULTRA 1.6c, also I cant seem to get the tiny black artifacts in the transparent areas to disappear (ive tried everything, enabling/disabling cutout mode, shadows mode and terrain shadows).

    Please can I get some help on these issues asap, this is such an awesome plugin and I want to be able to use it with the awesome ats colormap Ultra terrain shader.

    Thanks in advance for the help.
     
  34. SkermunkelStudios

    SkermunkelStudios

    Joined:
    Dec 29, 2012
    Posts:
    156
    HELLOOOOOO!?!?!?!?!?!?

    Can I get some help please, just acknowledge that I am here ffs!

    Am I talking to a brick wall or something? Dont know what makes me different from the other customers that I get ignored but they all get PM's and replies. Am I like a digital leper or something?
     
  35. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Email sent. (sorry for the delay)
     
  36. Erik Champion

    Erik Champion

    Joined:
    Aug 3, 2013
    Posts:
    1
    Hello Venryx;
    I don't know if your script can do this or we could talk about refining it/contracting a specific work around.
    We are doing a world war one trench simulation, my collaborators have accurate drawings of the trenches (as lines), they want to be able to have unity automatically extrude the trenches from the drawings (or code or vectors) onto the terrain. Is this possible? So it would build say 2metre wide and say 1.2 metre deep trenches accurately? (The dimensions are not at all accurate-I cannot remember them- but they give you an idea).
     
  37. SkermunkelStudios

    SkermunkelStudios

    Joined:
    Dec 29, 2012
    Posts:
    156
    Apologies for the rash and harsh behaviour. Thanks for getting back to me Venryx.
     
  38. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hello, I'm considering buying this system but I'd like to know first how does it handle Terrain LOD at long distances etc.
     
  39. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    By that do you mean, does it continue to have transparency at great distances?

    If so, then yes. The script sets the "Base Map Distance" to 1,000,000 meters, or something similar, meaning it won't display the base map/disable transparency at any practical nearness.

    If you instead mean, "does it have a built-in LOD system (as in changing detail level/graphical complexity at varying distances)?", then no. But this shouldn't be an issue anyway, since terrain shaders are already very basic, and couldn't be optimized much more without seriously sacrificing quality, (if even able to be optimized much more).
     
  40. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Just to confirm, deferred is working in the package or needed manual changes?
     
  41. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    The short answer is yes, but with certain limitations, which may or may not be significant for your project.

    Rather than re-explain, I'll just quote from the manual:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    * If deferred rendering is being used, enabling shadows causes objects behind the terrain to no longer be seen through its transparent sections. You currently have three options. You can either: 1) switch your project's rendering path to Forward, 2) disable terrain shadows (in the Terrain Transparency script), or 3) use a seperate camera for the terrain that has its Rendering Path set to Forward. I'd recommend option three, since it doesn't disrupt your project's setup much.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    So the seriousness of the above depends on how important shadows, or deferred rendering specifically on the terrain, are in your project.

    It's a shame one has to choose between one of the above options. I spent a number of hours working on this problem, trying to find a fully satisfying solution, but there seems to be an underlying issue inherent in the shader system that cannot be worked around by simply changing shader code or settings.

    Specifically, the problem is that in deferred rendering mode, when an object is placed in the "Geometry" RenderQueue, and is set to "not draw" over holes, it still blocks other objects from drawing in those areas of the screen (unlike in Forward rendering). And if you change the RenderQueue to "Transparent", you fix the pixel-draw-blocking problem, but then the shadows do not display. (the shadow system apparently requires that its objects be listed as opaque/be on an opaque render layer)

    That said, for the projects I use it in it's not a problem, since I don't mind having the terrain drawn in Forward Rendering mode. But this could be a serious issue if you need both Deferred Rendering and real-time shadows; the only real workaround for this case I can think of currently is to use a third-party shadow system.
     
  42. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Ok great. I have another question; for the fall through script does it disable the terrain collider or the player's collider? Because I'm wondering isn't it possible when the collision is disabled temporarily couldn't the player fall straight through the floor/ground?
     
  43. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    I see. Thanks for the explanation!

    I'll probably give this a try.
     
  44. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Neither actually. The fall-through script disables collisions solely between the player and the terrain object.

    So both the player collider and the terrain collider are still active--the physics engine is just told to ignore collisions between the two.

    The most significant outcome of this is that the plugin won't interfere with any secondary physics going on in your game (such as gunshots or ray-casting).
     
  45. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    That's very clever! I was going to ask whether you've tested this with multiple characters but after your explanation I don't see why it wouldn't work. I have a question about the demo; I've noticed that when standing in the "cave" opening, if I move sideways I can go straight through the terrain. If I move forward or backward until I'm not intersecting the terrain, then the collisions work properly again and I can't go through the terrain any more. Would this be just a matter of placing colliders on the sides of the caves?
     
  46. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Yeah, that's probably what I would do.

    I'm sure there's a more elegant, automated way, (perhaps, for example, a script that constructs a reversed collider object for the terrain automatically), but for static scenes it would probably work fine to just add invisible collider objects.

    One other way would be to add a script that continuously checks if a ray, cast down on a player, reaches the player; or if instead it hits the terrain first. If it hits the terrain, it means your player is underground; if not, then you can reset the player to where he was the last time he was underground. (which should be from the frame just before) This approach does have some gotch-ya's, (like that you need to make sure the ray-casting operates on a special layer, consisting only of the player and terrain, to avoid objects above the player potentially interfering), but with some careful coding it should work fine, and has the advantage of also working on dynamic terrains. (assuming that you always keep a valid 'reset position' in memory)
     
  47. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Sounds interesting, I'll have to try some of these things out. Thanks a lot for your advice
     
  48. Justei

    Justei

    Joined:
    Aug 31, 2012
    Posts:
    133
    I have a simple question, will raycasting work through the hole? For things like shooting etc.
     
  49. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    444
    Hmmm, good question. I haven't tried it with the holes themselves, but from my use of raycasting with other objects: it would not work out of the box. This is because, although you can check for raycast hits for different layers, and therefore different objects, you can't, at least not to my knowledge, tell the ray to only 'hit' places on an object of a given opacity.

    A possible solution could be to create a raycast class/utility, which works in three steps:
    1) Try casting a ray, just normally.
    2) If it hits a different object, good, just return the result. If it hits the terrain, continue to step 3.
    3) Check what the opacity is at the terrain point hit. If it's above the threshold, good, just return that hitpoint. If not, cast an otherwise-identical ray, from the same origin and in the same direction, except with the terrain excluded from the given layer.

    You could also combine the ray-casting parts of step 1 and 3, if you don't like the idea of casting the second ray at a later point than the first was cast. (although this delay would not be noticeable, if even possibly affecting of gameplay, since the Unity core is single-threaded)

    I haven't tried the above approach myself, but as far as I understand, it should work. (I've used raycasting with custom layers/layer exclusion before, but not made use of it to implement 'ray>object pass-through based on opacity of point hit')
     
  50. Setmaster

    Setmaster

    Joined:
    Sep 2, 2013
    Posts:
    239
    Getting the following erros unless I select no shadows mode:

    $FVwrUkh.jpg
    $terrainbug 2.png
    $terrainbug3.png

    $terrainbug3.png
    The first 2 are in forward lighting and the last in deferred.
     
    Last edited: Mar 11, 2014