Procedural Generation using Noise

Saw a thread about changing the noise scale via parameter and another engine dev said this is only possible if you take the HLSL noise function and put it into a Custom node. The reason I bring this up is because I need my planets to be quite large, but the noise is scaling down/up with the mesh size, so I have like a billion continents per planet. Obviously this is not right and I’ve tried fixing this via the position input on the noise with some object scale/radius nodes and other nodes, but nothing seems to work. I don’t want you to just spoon feed me, but is that other dev right? Is that the only way to change scale? This shader is going to be BP driven and I need the scale to be accurate per planet size. I can set the hardcoded scale to like .001 but this is only a temporary fix.

I feel like I should be able to use the code you posted at the very beginning to rectify this, but I have zero experience with HLSL and the Custom node, though I am hopeful I can figure it out.

You can scale the world position value before feeding it into the noise and then the resulting noise will be the same as long as what you feed into it is relatively the same for each planet.

Yeah, got it to work by dividing the world position by a scalar value and then plugged that into some existing node network. Thanks.

So, I took a look at this thread again and after going through the OpenSimplex noise function in Java and understanding how octaves work, I think it could be possible to understand just what you folks have been saying. I appreciate that this is good for veteran users of UE4, but I can’t seem to decipher what is being said, since it doesn’t seem to follow a specific pattern of steps. Using my Heightmap generator I got this

but mapping it to UE4 doesn’t seem like a good approach since it will have to use the same texture every time. Is there a way someone could dumb down the steps taken so I can produce something like what the person who made the planets with clouds did? I imagine the built in noise function can do exactly what this did since its the same algorithm (Simplex)

Post #23 I tried out but didn’t get your result, it was far worse than that:

Could just be the scale is different based on your preview tiling value. In the first screenshot I had divided the UVs by 0.1 which is like multiplying it by 10. And remember that is just one octave. Does look weird that your preview shows such a checkerboard pattern though. I would just try the custom node version I also posted a few posts down. There will be less chance of some random link or line being slightly wrong.

Got another question about noise (it probably will not be my last). I’ve been tweaking this shader a lot and have been wanting to implement some custom voronoi noise into the editor but I am not sure if this is possible, and if it is, will it be okay performance wise.

a7fdc23be68c30902f1ef102912c5903e918291c.jpeg

This is a pretty good example of want I want to do, but I am not sure if it’s possible with HLSL. I know that particular picture was written in C# and has custom functions in the script, but that is about as far as my knowledge goes.

It is possible. The above looks like perlin or simplex noise overlaid with a slight secondary voronoi. Voronoi noise is just getting a bunch of random point locations and always using the minimum distance. Regular voronoi noise looks like spheres because it uses a simple distance formula from each point, the weird diamond looking ones like above do weird things and us a combination of random distances along each axis with random use of min/max and squares going on. This page has info:

http://mines.lumpylumpy.com/Electronics/Computers/Software/Cpp/Graphics/Bitmap/Textures/Noise/Voronoi.php#.VhhzhyvF_ng

My guess is that the basic spherical voronoi noise will be doable but then it just gets slower from there. The thing you need to figure out is how to get a bunch of random locations, but for each point only evaluate a few. Look up a technique called texture bombing as it faces a similar problem with ideas of how to get randomness that can be per-cell and aligned between neighbors.

Thanks for that info, just saw that GPUGems has a chapter on texture bombing. One last thing, do you have any recommendations on where to start with HLSL? I’m still learning C++ and I want to learn HLSL so I can use the material editor to a better degree at some point but am just really lost on where to begin. Most of the things I’ve seen have are like tutorials and papers from 2005 or earlier. I basically just want to use C++/HLSL with UE4 and can’t seem to find a clear path with HLSL.

I would start with the custom node at first since doing hlsl inside of c++ files is slightly trickier since you have to use Compiler macros. Don’t be scared by that. Inside of the custom node hlsl is very easy. Doing math is as easy as knowing some these operations (you can do most of them, but some require special case, such as ddx is DDX all caps):

https://msdn.microsoft.com/en-us/library/windows/desktop/ff471376(v=vs.85).aspx

there are a few things from that list that you can’t do… like ddx_fine but don’t worry about that.

Try out our simple custom node blur doc page. Don’t just copy it but re-write it and try to figure out what each bit does. Then try to change the blur to do something slightly different etc. I basically started out with simple blurs like that and went from there.

https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/ExpressionReference/Custom/index.html

If you want to see how nodes work I suggest looking at some easy nodes like Spheremask in code. Just search for spheremask.

The one which gave the noise texture look? I didn’t get that at all, I got a corrupted black and white checkerboard looking texture instead.

Check out examples on shadertoy. Like 's some 3D voronoi noise.
https://www.shadertoy.com/view/ldl3Dl

It’s in GLSL but translation to HLSL is fairly straightforward. vec3->float3, fract->frac, mix->lerp, etc. If you want to use it in custom nodes you have to figure out how to do it without using functions. Or otherwise, once you’ve translated it, you can add it as a .usf file to /Engine/Shaders and include it in MaterialTemplate.usf. Then you can call functions from the new .usf with the custom node. Huge recompile each time you mess with .usf files though.

Okay, really glad to know that GLSL - HLSL is easy to do. I knew HLSL in the custom node couldn’t use functions, but didn’t know I could translate all of it and place as a .usf and call functions. That is a really great tidbit, thank you.

Okay, I used the code:



float P=1;
float accum, singlesample, toprow, botrow=0;
float2 offsets[4] = {float2(0,0),float2(1,0),float2(0,1),float2(1,1)};
float corners[4] = {0,0,0,0};


//sample each octave
for (int i = 0; i <= Octaves; i++)
{
	//sample 4 corners	
	for (int j = 0; j < 4; j++)
	{

		float2 noise = cos(dot(floor(uv) + offsets[j] ,float2(10.3,63.233)*2.0)) * 6743.31385;
		corners[j] = frac(noise.x + noise.y);
	}

	//cosine interpolation
	float2 cosblend = (1-cos(frac(uv)*PI))*0.5;
		
	//blend the 4 corners
	toprow = lerp(corners[0], corners[1], cosblend.x);
	botrow = lerp(corners[2], corners[3], cosblend.x);
	singlesample = (lerp(toprow, botrow, cosblend.y)-0.5)*2.0;

	
	//accumulate octaves
	accum+=singlesample*P;
	P*=Persistence;
	uv*=2;
}

return 0.5 * (accum+1);


and got:


For a brief moment, I had similar pictures as what you show for the result, but when I hit save, it changed to that.

I am using 10 for the texture coord in both u and v, 0.4 for persistence and 4 octaves. However, it seems to be in the cosine interpolation that the problem occurs.

In case any more people come across this thread and decide to PM me asking for help with planets, 's a link to the material: [FREE] Procedural Planet Material - Asset Creation - Epic Developer Community Forums