Search Unity

Have you ever tried using tileable textures to cover large surfaces or add fine-scale detail to your meshes? If so, you’re probably familiar with the visible repetition pattern that quickly emerges with higher tiling values. At Unity Labs, we have developed a new texturing technique that avoids this issue, Procedural Stochastic Texturing.

Tileable textures are a useful tool to add detail to your 3D scenes. However, whenever you want to texture large areas or achieve highly detailed surfaces using tileable textures and detail maps, tiling patterns become visible. This effect is illustrated on the left-hand side of the following picture. Typically, reducing repetition patterns requires bigger textures or hiding the visible repetition with additional objects. In this blog post, we provide a plugin that solves this problem for textures with stochastic appearances, such as rust, moss, bark, etc. Its impact is shown on the right-hand side of the following picture.

Rusted metal material with regular texturing (left) and our technique (right).

Download the plugin here.

Given an input texture, the plugin will procedurally generate an infinite texture that matches the appearance of the input. We do so by leveraging a state-of-the-art texture blending function that operates on a modified version of the input texture, which only requires three texture samples per fragment, and by fetching a small lookup-table. Since the plugin avoids the need for tiling, it makes it possible to cover larger surfaces with smaller textures and higher levels of detail without any repetition artifacts.

Using the StandardStochastic shader

The plugin provides a variant of the Standard shader, which is included in a Unity package. Once you have imported the package, select the StandardStochastic shader for your material. The interface is the same as that of the Standard shader, with the addition of two new controls at the top, corresponding to the two required setup steps:

 

  1. The Stochastic Inputs menu allows you to specify on which of the input textures you wish to enable our technique (it can be set to Everything, or specific textures, e.g., albedo and/or normal map).
  2. The Apply button pre-computes data for the selected stochastic inputs and updates the material, finishing the process. For each input texture, this step generates two intermediate textures located in the same folder.

A few additional remarks:

  • Because existing intermediate textures are loaded when they are found to skip generation times, any modification to the original texture requires deleting them both before hitting the Apply button again to force their regeneration.
  • When switching between the Standard and StandardStochastic shaders, parameters are transferred back and forth.
  • A StandardStochastic (Specular setup) shader is also provided for materials using the Specular workflow.

The following examples show the prototype working with different materials using small (256²) input textures.

Wood detail maps with albedo, normal and occlusion textures

 

Rock material with albedo, normal, occlusion and height textures

 

Iron material with albedo, normal, and metallic/smoothness textures

Limitations

This technique is only compatible with tileable stochastic and near-stochastic textures, such as textures resembling random noise when viewed from a distance and typically natural-looking materials without precise geometric shapes.

Feedback

This is a research prototype; it is not under active development. As such, we don’t guarantee maintenance or support but feel free to ask any question and offer feedback on this Unity Forum thread. We are currently working on a ShaderGraph implementation for custom shaders and compatibility with the new rendering pipelines. Look out for updates on the forum thread!

Further reading

Curious about how the plugin works? Check out our two recently published research papers on the subject, which our plugin builds upon:

The code delivered with the plugin features comments referring to specific sections of the technical chapter.

Комментарии закрыты.

  1. have an unlit version?

  2. For everyone asking about terrain, I shipped a variation on this technique in MicroSplat’s Texture Cluster module this morning. It replaces the Histogram Preserving operator in the paper with a height blend, which removes the need for preprocessing the textures into custom formats, generating lookup tables, etc.. Results are also posted in the forum thread.

  3. Absolutely love this, as I was searching for a tech like this just a couple of days ago. Will go directly into a new project… Thumbs up!

  4. Super Cool!!!

    1. that is quite expensive for a simple shader: 0.035 vs 0.2 ms.

      1. Which is dramatically faster than alternatives that offer similar results.

  5. I love this kind of stuff:)

    Unity 2017 compatibility would be nice, but i understand if it’s not possible.

    Nice work either way.

  6. Very nice!
    Any notes on GPU cost vs simple tiled texture?
    Mobile use realistic?

    1. We have some performance comparisons on page 20 of the technical chapter:
      https://drive.google.com/file/d/1QecekuuyWgw68HU9tg6ENfrCTCVIjm6l/view
      It is on average 4-5 times slower than simple tiling. Although you can trade performance for memory by using smaller textures than you would normally need to avoid repetition patterns (all of the renders in this post are with 256² textures), which could be a win for some mobile projects.

  7. Please add this option to terrain in hdrp, or give us terrain node into shadergraph

  8. This tool is great and we could use for it for a big project.
    There is one thing though that would make it even better : handling multiple selection.
    In our case, we are procedurally generating textures in another tool and would need to apply this shader to materials with our textures.
    To do that, we created a menu item that checks for textures in a folder, create materials in another one, apply this shader to the materials and set the material’s texture’s «_MainTex».
    The problem is that to trigger the «apply» function, we would have to tweak the StandardStochasticShaderGUI class ourselves since selecting more than one material at a time and clicking on «Apply» will result in the same texture being applied to all of them :/

    Anything you could do about it ?

  9. This is major! Texture repetition has never been fully solved before. Artomatix had an implementation but that is currently not available (I believe they are working on it though). Please integrate this into Unity with full support. It is too valuable to let it get moldy in just another cool but forgotten research project.

    1. Thanks for the feedback ! We are planning on doing a proper release in ShaderGraph as a texture sampler node, making it available for most users in the new render pipelines.

      1. That would be awesome! Any ETA on this?

  10. Hey! Any plans to support this in the lightweight or high-def pipelines?

    1. We are planning on implementing it as a ShaderGraph node, which would make it usable with the new render pipelines in custom shaders.

  11. Just tested:
    A long awaited dream finally comes true.
    Hopfully this will be integrated in the next releases.

  12. Very cool. This helps to solve one of the bigger issues that the standard shader has and honestly I’m all for this. Is there a chance that this shader will also come to the scriptable render pipelines as well? Or do they already have something like this?

  13. veteran person guy dude

    Февраль 15, 2019 в 3:00 дп

    ImageSynth was cool in 2003… so this in 2019 is a bit YAWN… UNLESS you add this; that the texture space is used for a scaleable texel ratio and for the shader to tile within that space.
    THEN YOU’D HAVE SOMETHING NEW. #DURRRRRRRRRRRRRRRRRRRRR

  14. Another great post – back to back with that Shader Graph Vertex Effect – Thanks once again!
    No problems when trying it out in 2018.3.0f2

  15. Strange, i’m using unity 2018.3.5f1 and receiving a:
    Assets/Editor/StandardStochasticShaderGUI.cs(587,12): error CS1644: Feature `byref locals and returns’ cannot be used because it is not part of the C# 4.0 language specification
    I wonder why?

    1. What version of .NET are you using? You can check in the player settings. It should be 4.x.

      1. Thanks for noticing that, the .Net 4 requirement is unnecessary and slipped in, will fix it!

      2. I’ve set it up as Net 4.x and the problem persists. Using Unity 2018.2.20f1.

  16. Looks very promising! Can’t wait to get my hands on this!

  17. Impressive work. Will this work with Unity terrain?

    1. I have exactly the same question!

    2. Great question, this would be amazing on a terrain

    3. The technique can be used with terrain shaders, but that will require manual implementation. The main purpose of this prototype is to make the code available in C# and shaders for Unity developers to use in their own code where they need it. Although we hope to have the technique released as a new ShaderGraph node in the future, for easy integration in custom shaders.

      1. You say it works for terrain, would there be support or a workaround to have seamless neighboring terrains aswell?

  18. AMAZING WORK! Way more efficient than Wang Tiles. Way to go guys!

  19. Awesome! One question: which Unity versions are compatible with this plugin?

    1. Currently it works with the last Unity 2018 releases in the built-in render pipeline. Since the plugin plugs into parts of the Standard Shader code, and some of that has evolved since the initial release in Unity 5, it’s not working with older versions as it is.

      I will be backporting it in the coming days as separate packages for older popular versions of Unity, mainly Unity 5.6!

      1. I could kiss you.