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.

35 replies on “Procedural Stochastic Texturing in Unity”

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.

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!

I love this kind of stuff:)

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

Nice work either way.

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 ?

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.

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?

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

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

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?

Comments are closed.