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

Advanced Texturing for terrain and meshes

Discussion in 'Works In Progress - Archive' started by Deleted User, Jul 26, 2012.

  1. Deleted User

    Deleted User

    Guest

    (04/10/2012)Component up on the asset store! Thread in the Asset Store forum

    (22/08/2012)New webplayer showing Parallax Occlusion Mapping with self shadowing here! For more info see the post at the bottom of this page.


    I have finally got this system together, after the feedback in the last thread:)

    Advanced Texturing for terrain and meshes

    This system allows for multitexturing a mesh, based on a splat map with up to 4 textures. Each splat is normal mapped, and they have the option (at runtime or compile time) of being parallax mapped or relief mapped. The level of displacement is set per texture, as is the specular colour. A specular map can be integrated into the diffuse map alpha channel using the tools provided. A full mesh normal map can be integrated with the splat normal maps, and a fallback texture can be provided as well.

    As this is not a terrain replacement shader (as the terrain system doesn't seem to play well with complex displacement shaders), a set of tools is provided to export the terrain and the required maps (although not vegetation or trees at this point) for use in this shader.

    In short, this system provides:

    • 4 texture multitexturing with normal maps
    • parallax mapping
    • relief mapping
    • per splat specular and specular colour
    • whole mesh normal map
    • whole mesh fallback texture
    • PS 2.0 fallback(4 mesh multitexture+ whole mesh normal map) that also runs on modern mobile gpus
    • whole mesh shininess for Beast interaction
    • specular map into alpha of diffuse tool
    • tool for integrating splat heightmaps for displacement mapping
    • built in terrain mesh exporter
    • built in terrain splatmap exporter
    • heightmap exporter for built in terrain to generate whole mesh normal map
    • texture grayscale exporter for simplified displacement map, where displacement map for texture is unavailable

    Here is the web player, with full instructions, and whole mesh displacement level for simplicity:
    (may take a while to load, due to the number of textures involved, and after the first button is pressed for the same reason)
    Web Player
     
    Last edited by a moderator: Oct 4, 2012
  2. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    I'll take a peak at the web player. See what you've got here.
     
  3. Deleted User

    Deleted User

    Guest

    An update: I've added an optional feature to the shader that works in all mapping modes. It uses the heightmap of each texture along with the texture blending information to blend by height at the texture interfaces. This means that if you have a brick texture and a sand texture, at the interface between the two, the sand could appear (dependent on it's heightmap) filling the grout between the bricks. Here is an example (based on one of the webplayer scenes) of sand filling the gaps in rock:

    It isn't i the webplayer yet, but that should give you an idea of how it looks.
     
    RC-1290 likes this.
  4. ATNEDev

    ATNEDev

    Joined:
    Jul 13, 2012
    Posts:
    54
    Does the parallax here mean it can recognise the depth of the texture and model te mesh based on the picture, like in Crysis?
     
  5. Deleted User

    Deleted User

    Guest

    Both parallax and relief mapping give the impression of tessellation by adjusting the texture coordinates based on the height of the texture(from a displacement map), albeit without sihouettes. You can see how this works by increasing and decreasing the displacement slider in the webplayer. Crysis uses a similar method, called "Parallax Occlusion Mapping with Silhouettes". I am looking towards doing that in this shader(as it would work), but the way Unity does deferred rendering means that if I do it, it'll only work in forward rendering, and some DX9 cards lack a couple of the required instructions as well. However, as it needs no more information than this shader does, if I do it, this shader will be used as a fallback.
     
  6. ATNEDev

    ATNEDev

    Joined:
    Jul 13, 2012
    Posts:
    54
    So, you say, basically, a few GPU's wouldn't be able to run a game that would use your parallax occlusion mapping and it would be a step forward for this shader. Can't you make users choose if they want this type or the POM type? Like, this type for medium and low settings and POM for high? Anyways, quite useful system you created! I'll be looking for your POM, as that's really interesting to me... And I believe that if you DO make this Parallax Occlusion Mapping, you're the first person to include it in game making processes other than the CryEngine team. Two more question... I can't really test it so I'm wondering if this is some kind of Unity add-on, and if it is, do you intend to keep it free or will the finished product require for users to buy it?
     
  7. Deleted User

    Deleted User

    Guest

    The idea would be to choose the kind of mapping you want, dependent on a quality setting, as you suggest, with an event sent to all the meshes telling them which mapping to use, or to allow you to set it manually, as if the GPU can't handle POM, it'll drop it down to the normal non-POM shader as a fallback.

    It will be an add on for the Unity Asset Store, and it will cost money, albeit a sensible amount, as there has been a great deal of work put into it, as well as all the utility scripts you get with it. When it's done, I'll ask what people think is good price for it.

    When you say you can't test it, are you saying the webplayer above won't run on your system? If so, I intend to put up an updated one with any new features in the near future.
     
  8. TheDavil86

    TheDavil86

    Joined:
    Jul 6, 2012
    Posts:
    46
    To be honest it more or less looks like a decal on top of a regular texture.
     
  9. Deleted User

    Deleted User

    Guest

    That's why I hope to have a new webplayer out soon, so it can be seen in action. I agree, the image doesn't do it justice.
     
  10. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    It most certainly does not.
     
  11. Deleted User

    Deleted User

    Guest

    Okay - I have Parallax Occlusion Mapping running. Unfortunately, as the kind of mesh that this multi-channel shader is used for (terrains, etc) contains tiled textures, it doesn't seem to be possible to get silhouettes, however, on normal meshes with a single set of untiled textures (diffuse, normal map, etc), silhouettes work fine, so I'll include that shader too.

    Here are a couple of examples:

    Parallax occlusion mapping with the multichannel shader, including splatmap and height-based blending and self-shadowing.
    And

    Parallax occlusion mapping with silhouettes and self-shadowing.

    Both of these examples involve the shader being used on a flat plane - all appearance of displacement is done by the shader.
     
  12. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Looking great!
     
  13. caldrin

    caldrin

    Joined:
    Dec 4, 2011
    Posts:
    127
  14. Deleted User

    Deleted User

    Guest

    While I'm doing the new webplayer, I also redid the mobile port. On a Tegra3@1280x720 with 4 terrain splats(diffuse w/specular in alpha), each with normal maps and specular colour, I'm getting between 17.5 and 30fps. I used a script to encode the 4 normal maps into two textures so that with the splat control map it would fit into OpenGL ES 2.0's 8 texture sampler limit. On lower specced OGLES chips, it runs a 4 terrain splat with a whole terrain normal map.

    Here is the Tegra3's output (click for full-size):


    For some reason it is point sampling instead of bilinearly filtering the textures, but that seems to be a Tegra3 thing, as on PowerVR chipsets(iPhone, iPad, etc) the filtering is fine, but I'll look into that.
     
    Last edited by a moderator: Aug 9, 2012
  15. Deleted User

    Deleted User

    Guest

    Just a quickie, as I'm still building the scene for the webplayer. Here's a prop from said scene. What makes it special is that the wax uses a translucency shader based on the method used in the Frostbite 2 (Battlefield 3) engine (Paper here)!
     
  16. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    Getting a solid 60 on my MPB.
     
  17. Deleted User

    Deleted User

    Guest

    Here is the webplayer showing off multi-textured blended parallax occlusion mapping with self-shadowing.

    As with all displacement algorithms, the illusion of depth is generated by algorithmically moving the texture coordinates as opposed to tesselation. Case in point:


    This demo contains two meshes with the shader, the terrain, with four splats, and the tree with two - the bark and the moss. In both cases the boundaries between the splats are blended by the "height" of each splat. This can cause some slight movement (as can be seen in the demo - POM is calculated with respect to the view vector), but the effect is far more realistic, as can be seen by the grass overgrowing the space between the stones.
    The terrain mesh also blends between a whole-mesh normal map and the normals of each of the splats, so a much more complex terrain normal map can be observed beyond the actual low-poly terrain mesh.
    There are four lights, three point lights for the candles and one directional light for the moon acting upon the meshes.
    The webplayer is limited at ~60fps as it observes vsync, even if (as it was in this case) it is turned off in the options.
     
  18. Deleted User

    Deleted User

    Guest

    I've just tested the standalone version of the webplayer above on the Unity4 beta - I tested it on 2 PCs, one with an AMD Radeon 5750 and one with an nVidia GTX260-216 and found an average FPS increase of ~20%!

    In all cases, the standalone was set to 1024x768, "Fantastic" mode with vsync off.

    AMD Radeon HD5750 (DirectX 11 part) :-
    (Unity 3.5):


    (Unity 4.0b7)


    Increase = 21.72%

    nVidia GTX260 - 216 (DirectX 10 part) :-
    (Unity 3.5)


    (Unity 4.0b7)


    Increase = 20.3%

    There could be a number of reasons for this increase, but I feel that it is brilliant on a shader-bound demo such as this.
     
  19. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    This is really great news to see such performance improvement with DX11.
     
  20. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    I know, I'll have to try it.
     
  21. Deleted User

    Deleted User

    Guest

    My last Unity 4 update before I go back to finishing the quality system of this asset (for Unity 3 and 4):

    I tweaked the shaders and the scripts a bit, and got them working as a plug-in material for Unity 4 terrain(as in, you don't have to export the terrain, you just add the material and the script).

    Here's built in Unity 4 terrain with parallax occlusion mapping and depth blending.



    As you can see, there's some orientation drift on the hills. This is due to the tangent having to be estimated by the shader. Hopefully, if they get geometry shaders working with surface shaders(they just work with vertex/fragment shader setups at the moment), I might be able to corect that for DX10+ systems.
     
  22. Deleted User

    Deleted User

    Guest

    Actually, this performance increase is with Unity 4's DirectX 9 mode!
     
  23. Deleted User

    Deleted User

    Guest

    Okay, probably the last feature demo before release!

    As promised, I have implemented a quality settings feature, which sends an event to each object using this shader, changing its settings. The changes to use are decided by the developer and are stored in an XML file which is given to a settings manager object in the scene, which in turn sends the events, depending on the settings chosen. The XML file is generated by an editor script which lets you choose the desired settings for each level.

    Here is an example webplayer.

    In this case, the settings are:
    Very Low: Normal mapping, normal blending.
    Low: Normal mapping, height blending.
    Medium: Parallax mapped normal mapping, height blending
    High: Parallax occlusion mapped normal mapping, height blending
    Very High: Parallax occlusion mapped normal mapping, height blending and self-shadowing

    Now I'm going to finish the documentation, then hopefully, it'll be complete!
     
  24. Deleted User

    Deleted User

    Guest

    Right - I'm just finishing up the documentaion, which I'm going to wikify before release.

    As I said, I was going to ask how much people would be willing to spend for this full set of shaders (including the mobile ones mentioned earlier), and all the tools. First Person versions of all the demos are included and the POM with sihouettes for flat planes shader is there too.

    Given the amount of shaders and scripts, I was thinking somewhere around the $30 - $50 range.
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    hi gaustwick,

    i have just tested your latest demo and it seems that is does not work for me properly (mac book pro, nvidia geforce 9400m).
    first of all the screen is more or less black (at all quality settings).

    next thing is that i do not get any decent framerates.
    very low: 25fps
    low: 20 fps
    medium: 15fps
    high: 3fps
    very high: 3fps

    so i would think that your shaders or not really suitable for any game production not targeting the latest hardware.
    blame my graphic card but 3fps for a 640 x 480px screen not showing much geometry and absolutely no gameplay doesn’t sound like these were shaders amde to drive an average unity title.

    sorry about that.


    lars



    $Bildschirmfoto 2012-09-13 um 19.06.55.png
     
  26. Deleted User

    Deleted User

    Guest

    I'm sorry that it didn't work well on your machine. The shaders are really meant for higher-end cards, as multichannel POM (the one you got 3fps on) really is quite hard on the GPU, especially as there are 4 lights on the scene and the quality is set to "Fantastic". I have tested it on a Windows PC with an AMD HD5750, a Windows PC with a Geforce 260GTX and an iMac with an AMD HD 4650(the lowest, but still much higher than you're seeing), and have had interactive frame rates in all cases, as can be seen by the screenshots on the last page. I also have not seen the darkening you mention either, which makes me wonder when was the last time Apple updated the drivers for the 9x00 series.

    Maybe if I do sell this, I should make it clear that you will need a minimum system requirement to use this.
     
  27. Deleted User

    Deleted User

    Guest

    Okay, I've rebuilt the scene with two fewer lights (their spheres of influence were outside the frustrum, but still affecting the framerate), switched the Unity quality to "Good" and removed post-process AA. Hopefully you get a better result, whilst still getting the idea of the shader's capabilities:) Webplayer. (this is separate from the one above)
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    hi gaustwick,

    even turning on my NVIDIA GeForce 9600M GT won’t give me framerate above 6fps at very high settings.
    and it is still much too dark.
    so it is at least an nvidia/mac issue.

    lars
     
  29. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    This one gives me a solid 50fps on all settings no problem : )
     
  30. Deleted User

    Deleted User

    Guest

    Lars -

    The only thing I can think of off the top of my head - are you using the drivers that came with the Mac Book Pro(via updates), or the MBP drivers from nVidia's site? I don't know if there would be any difference.

    Either way, thanks for testing it out, so I know which systems have problems with it.
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899

    hi gaustwick,
    my system is running the drivers shipped by apple.
    sorry about that, but some shaders really have problems on mac/nvidia…

    lars
     
  32. Deleted User

    Deleted User

    Guest

    Lars -

    That is annoying:( I've added a feature that might help though. It allows you to use the quality interface to switch to one of the fallback shaders, so you at least get 4 shaders blended with specular + a whole mesh normal map. It's a SM2.0 shader, so hopefully it'll have fewer problems. Here's the webplayer.
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    hi gaustwick,

    the fallback shader works for mew – but nothing else though.
    this is what i get:

    $Bildschirmfoto 2012-09-14 um 23.20.21.png


    btw.: i does not have to be sm 2.0 to run on my computer. i have a lof of sm 3.0 shader working perfectly… but there must be some bug in the nvidia driver.
    look at farfarer’s triplanar shader: it works on almost all computers but not on some macs using nvidia cards.

    lars
     
  34. Deleted User

    Deleted User

    Guest

    Thank you for trying that out, and I'm glad it worked. Looking at Farfarer's shader, the only similarity code-wise is the (relatively)high number of texture accesses, so maybe if there is a bug, it's somewhere in that part of the driver.
     
    Last edited by a moderator: Sep 14, 2012
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    nope, it is not the high number of texture fetches – as i have successfully ported this shader to run on my mac…
    in farfarer’s case it was one operation which corrupted the shader’s output: the calculation of the projection plane.

    but i really can’t tell you what exactly was the point. i just completely skipped it a and implemented nvidia’s blending function…

    lars
     
  36. Deleted User

    Deleted User

    Guest

  37. Deleted User

    Deleted User

    Guest

  38. Deleted User

    Deleted User

    Guest

    Upcoming WIP feature for Unity 4 version- Tessellated displacement for built in terrain!
    Normal mapped:

    Tessellated displacement:
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    could you please post some more details about "Tessellated displacement for built in terrain"?

    thanks, lars
     
  40. Deleted User

    Deleted User

    Guest

    Lars -

    Using the displacement data that the component already has for POM, etc - a heightmap for each splat and a displacement level, this new DX11 shader generates a new denser mesh that follows that information to actually give depth to each splat. As Unity 4 lets you specify a material for the terrain, it's as simple as adding the shader to a new material. The only limitations are a maximum of 4 splats to avoid discontinuities in the displacement and the splat tiling has to be set in the shader as opposed to the terrain.
     
  41. Deleted User

    Deleted User

    Guest

    The new version is just about done, I'm just finishing the documentation.
    Here's a video showing the new Unity Terrain version of the component (with tessellation too):

    ( watch in HD for the best effect:) )