Question: Using Noise to SELECT a Random Texture

Hi everyone,

I have been searching the internet after finding numerous discussions on how to use “noise” in a Material BP to create random colours or textures. Now, with the understanding that noise *may have the ability to *output a random number, I am hoping someone may be able to give me some insight into how this may be used…

Here is my current idea/logic:

In the image above, it has the facility to use the “A” input (currently empty) to trigger the selection, for which I require a random number. Once I have this (if it’s possible) the “if” statement should trigger the choice of one image of another.

I have found all sorts of iterations which rely on noise to generate random images and patterns, even to generate moving textures which mimic fluids. I think my idea may be even simpler, in the fact that if noise generates a random number, I should be able to tack on some numeric functions (ie. add/subtract/multiply/divide) which will bring the value provided by noise up to a level that I can attach it to the “if” statement, and somehow select between the two textures. (Even if it’s not a strict integer, applying mathematical functions should be able to give me a good starting point.)

Is there a “Noise Guru” here, who may be able to assist? I would very, very much appreciate it!

DISCLAIMER: Yes, I am aware I could do all of this through standard blueprints. :slight_smile: I just have a bunch of textures of broken glass that are all the same resolution, which I would much rather not have to create a material for each, if possible. I believe the above would help immensely to reduce the amount of work I’ll need to do to get this in a format I’m hoping for. (I would prefer not to have to write code for an array, as I should just be able to drop the newly created code (hopefully!) into a different material blueprint for the same effect. (My current idea is to use the same format for random posters, pictures and monitor/screen displays. I do realize that I may have to create multiple branches of the “if” statement, dependent upon the number of selections, but I am thinking if I get the good starting point, I may be able to wrangle a way around that as well.)

THANK YOU in advance for any ideas!


You would be better off using a dynamic material instance instead of doing it like you proposed. The reason behind this is that with the setup being as you described, you will be sampling each of the broken glass textures, even though only one will ever be shown. Imagine if instead of just the two now, you have a set of 8 variants. Now on top of that, you want to add normals to your decal as well - suddenly you’re sampling 16 textures, where only 2 are actually shown to the player.

To use texture parameters, do the following: have just one texture sampler in your material, plugged into your base color. Now right click it, and select “Convert to parameter”. Give it a desriptive name, such as BaseColorTexture.

Next, create a blueprint which will be or spawn the decal. Use the following nodes to apply a random texture to the decal:

You will still have just one material, but can use any number of textures on it without wasting GPU and memory on unnecessary texture samples. Good luck!

Ah ha! See, now THIS is even better. You’ve given me the insight into why my idea … is a BAD idea. THANK YOU!

While I like your idea, and will use it for some future plans I have in my game, I have come up with this:

Basically, the inputs on the left of the macro bring in a link to the component target, and the material array being used. I set up a branch to check whether the component (mesh, primitive, what-have-you) has multiple materials within, and randomly select from the material array to apply them. (It took a bit of trial and error, as the original code didn’t have this branch to check for multiple materials, so first, I had one unique drawer in each desk, and then after some faulty code, I had a beautiful set of twenty patchwork desks… …with every piece of them a different colour. :smiley:

Thank you for setting me straight on this one! I’m much, much happier with this new result!


Check this out:

Great tuorial, tried here and worked well!

I wanted to do something similar, but I chose a method which seemed easier to me. I created a grid of the potential textures, specifically x16 1024x1024 textures in a 4096x4096 atlas. I placed this big image in a texture sampler and through a material instance and UV parameterization I use this material instance in a blueprint. Thus, making use of this Dynamic Material Instance, I changed the material instance’s parameters and ultimately chose a random texture out of those 16 I wanted to. It worked very well.