Hi! I have a question about noise that I’m not sure is in scope for this forum but here goes.
I’d like to be able to query the exact SimplexPerlin3D noise algorithm shown here in NME (like noise.getValue(x,z)) and get the value at that point as a float between 0 and 1. I know that it’s not possible to query the material from the CPU, but is there a way to run the exact same algorithm in the CPU so I have some data structure with the same data just for querying? I’d like the performance of the shader in my rendering, but i’d also like to have some way to access the data about the resulting shape, and that doesn’t have to be super performant.
Specifically:
how do I get the worldPos seed so my output is guaranteed to be the same?
is there already a JS version of this algorithm? if not, would it be possible for me to write one or is there some obstacle I’m not considering?
What about generating a procedural texture by using the SimplexPerlin3D block and applying this texture on your mesh instead? You could then read back this texture into the CPU to get the values you want.
I don’t think you will be able to do things the way you would like, worldPos is coming from the geometry (those are the vertices of your geometry), and is interpolated by your GPU for each pixel. You would need to implement this same interpolation and in exactly the same way to be sure to get the exact same values. Also, the computations are probably not done in 64 bits by the GPU, which is the precision you would have in javascript because a number is 64 bits. So you would end up with numbers being different just because of that.
yeah it’s the right PG–my issue is the dumped buffer doesn’t appear to have any relation to the perlin noise. every pixel in the dumped buffer has rgba value (51, 51, 76, 255) whereas the noise has variation and is grayscale so 51,51,76 appears nowhere on it.
That’s because you are using the mesh position in your shader but when generating a procedural texture with nodeMaterial.createProceduralTexture(256) there’s no mesh rendering taking place. So mesh position is (0,0,0) during the texture generation.
Your node material will only work when applied to a mesh, not to create a procedural texture.
ahh okay that makes sense. how do i generate the procedural texture using the block as you suggest here?
What about generating a procedural texture by using the SimplexPerlin3D block and applying this texture on your mesh instead? You could then read back this texture into the CPU to get the values you want.
is there a way to pass the mesh in when i call createProceduralTexture?
No, you can’t pass the mesh in createProceduralTexture. You should create a procedure texture in the NME without using the mesh data, only screen.position, something like:
@george Here is the demo how to calc perlin noise in texture (ProceduralTexture) and read values from it with readPixels and then use it in your JS code