So I know there are a lot of good programmer hlsl guys here because Ive read a lot of the threads about custom HLSL stuff for Unreal.
I was hoping to make a custom node for a random Int. Some of the stuff Ive been reading suggests using a random tex coordinate on a bw tex2d which seems like it could work but I have no idea how to implement this in Unreal.
Any help would be fantastic!
Replies
The perlin noise thing is much more complex, it gets it's random numbers from a noise texture, BUT this texture depends on uncompressed texture data, something UDK doesn't like.
Either way, you will need the customcode node, and UDK really isn't the best environment for this. I'd suggest you just try to work with pre-generated cloud textures that are offset with world coordinates for example, much less hassle and can give good results in most cases.
Secondly, a true random generator burns too many instructions to be worth, I think it was Vailias that said he ran out of instruction space for his noise function, and had to resort to a texture sampler to do most of he grease work, same info I keep on finding with google. So even if you were successful, you wouldn't be able to do much with it in the fist place, and I don't think UDK allows Material-Per-Material sampling to save instruction space.
The best solution I can think of is what Xoliul said, with a per channel noise. You could have one texture, with a noise texture in each one, and afterwards, you could then create a set of 'random' numbers (manual numbers you put up), and use those with a time offset to cycle through them while doing the same for the noise channels, that way you have 'somewhat' of a random thing going on where two sets of times are molding for one texture.
I tried doing this not too long ago, but I was going for something more spiffy, and was trying to do more than simple Sin and Tan function, but didn't work. Sure someone would know a better way of doing this.
Or, you simply use World Space and Texture Coordinaes, and tabulate those.
It became workable when I dumped the 512 number random seed array to a 1d texture lookup.
I did find another way to get pseudo-random noisy behavior via a texturless GLSL Perlin Simplex Noise implementation someone did and posted on the web, but still super heavy. Well over 120 instructions just for a single pass noise function.
Frankly even Ken Perlin has resorted to texture lookups for real-time implementations of his algorithm.. he's not the best at explaining things though, so his examples are good, but hard to follow.
Xoliul and Sprunghunt have some good advice though, as the permute-permute-permute approach in Perlin's algorithm is useful for pseudo-random generation.
Without knowing what effect you're after its hard to give correct and concise direction though.
If that isn't (much of) a concern, just go for pregenerated noise textures in UV space. Multiple UV channels can help you almost completely circumvent the UV seam issue.
There is a "noise()" function in HLSL specifically for generating perlin noise. But it doesn't work in UDK because of the context it's being used in. It's only for generating proceedural textures offline. It might work with the custom texture node?
However here's a fast implementation of perlin noise by ken perlin himself.
http://mrl.nyu.edu/~perlin/noise/
You'll notice he's not actually randomly generating numbers. Rather he's referencing an array of previously generated numbers. Which is what I was suggesting earlier. I'm not sure if it's better than using a texture. I guess there's going to be faster data access?