Procedural Generation Tutorial Brick Noise Texture - Part 5
Before you start you should know these things:
- Create Texture variables
- Manipulate textures using SetPixels
You should have gone through and completed all the ‘Checker Board Texture’ and 'Brick Pattern Texture' tutorials before going any further. If you find yourself not understanding some of the terminology or code of the tutorial I would also recommend going through the previous tutorial to get up to speed. I will leave a link to it below to go through at your leisure.
http://joseph-easter.blogspot.com/2017/01/procedural-generation-tutorial-brick_39.html
If you follow this tutorial and find I am moving too fast or if you don’t know the things in the list above, I would recommend getting up to speed and then come back to this tutorial when you are ready.
With this tutorial if you want to convert this into JavaScript by all means do so but it may be easier for you to follow this in C# and stick with the language of the tutorial to make it easier.
PROJECT RESOURCES: At the bottom of the post there is a download link to a zip file. This files includes all files needed to follow Part 5 and the completed project file of Part 5.
In this tutorial series, we will be adding to the brick pattern texture using code by adding noise to the texture image.
In this tutorial series, we will be adding to the brick pattern texture using code by adding noise to the texture image.
We will:
- Explain the theory
- Learn to create 3D noise using the quads 'x', 'y' and 'z' position
- Put one indexer in another to mask the value
Step 1: The theory
In todays tutorial we will cover how to create 3D noise building upon what we have learnt by creating 2D noise. Like Part 3, this part will be very quick and straight forward because we are essentially tweaking what we already have to create a new function. Also we are adding more complexity to it, to make the random noise more convincing, depending on your needs.
Step 2: The basics
Code:
using UnityEngine;
public static class NoiseLibrary()
public static class NoiseLibrary()
{
...
public static float RandomValue2D (Vector3
point, float patternAlternationSpeed)
{
point *= patternAlternationSpeed;
int intX = Mathf.FloorToInt(point.x);
int intY = Mathf.FloorToInt(point.y);
intX &= 15f;
intY &= 15f;
return hashValue[(hashValue[intX] + intY)
& 15f] * (1f / 15f);
}
public static float RandomValue3D (Vector3
point, float patternAlternationSpeed)
{
point *= patternAlternationSpeed;
int intX = Mathf.FloorToInt(point.x);
int intY = Mathf.FloorToInt(point.y);
intX &= 15f;
intY &= 15f;
return hashValue[(hashValue[intX] + intY)
& 15f] * (1f / 15f);
}
}
Code:
using UnityEngine;
public static class NoiseLibrary()
public static class NoiseLibrary()
{
...
public static float RandomValue3D (Vector3
point, float patternAlternationSpeed)
{
point *= patternAlternationSpeed;
int intX = Mathf.FloorToInt(point.x);
int intY = Mathf.FloorToInt(point.y);
int intZ = Mathf.FloorToInt(point.z);
int intZ = Mathf.FloorToInt(point.z);
intX &= 15f;
intY &= 15f;
intZ &= 15f;
intZ &= 15f;
return hashValue[(hashValue[intX] + intY)
& 15f] * (1f / 15f);
}
}
Code:
using UnityEngine;
public static class NoiseLibrary()
public static class NoiseLibrary()
{
...
public static float RandomValue3D (Vector3
point, float patternAlternationSpeed)
{
point *= patternAlternationSpeed;
int intX = Mathf.FloorToInt(point.x);
int intY = Mathf.FloorToInt(point.y);
int intZ = Mathf.FloorToInt(point.z);
int intZ = Mathf.FloorToInt(point.z);
intX &= 15f;
intY &= 15f;
intZ &= 15f;
intZ &= 15f;
return hashValue[(hashValue[(
hashValue[intX] + intY)
hashValue[intX] + intY)
& 15f]+ intZ) & 15f] * (1f / 15f));
}
}
- Create 3D Noise
- Put one indexer in another and mask the previous values again
In Part 5 we will learn how to use the skills learnt here to create Perlin Noise, create a mask variable meaning we don’t need to change the length manually when masking. We will also learn how to avoid the need for masking the values a second time in the hash table indexer.
No comments:
Post a Comment