Mapping 3d perlin noise to a 2d texture

This isn’t strictly a shader question but I think you guys have the math skills for this.

I’ve got 3d perlin noise along the surface of a sphere I am producing, and have the X,Y,Z coordinates and spherical polar coordinates of that noise. I’m know this code is good. (these coordinates do produce a sphere with nice perlin noise on the surface, for instance, verified by spawning a bunch of spheres :slight_smile: )

  for (float alpha = 0; alpha <= twopi; alpha = alpha + .002f)
        {
            for (float gamma = 0; gamma <= pi; gamma = gamma + .002f)
            {
                float x = Mathf.Sin(gamma) * Mathf.Cos(alpha);
                float y = Mathf.Sin(gamma) * Mathf.Sin(alpha);
                float z = Mathf.Cos(gamma);            
                //the above are all [0,1] as expected
                float color = noise.noise3(x*10f, y*10f, z*10f);  //simplex  noise

Now I want to take that and map it onto a texture which will later be put onto a sphere. So I believe if I do the exact same process as UV mapping, I should get produce a texture that will wrap nicely around the sphere, like this kind of image with the increasing smearing as you get near the poles:

So, looking up how UV mapping on a sphere works I come up with this:

                float x2d = Mathf.Atan2(z, x) / twopi + .5f;
                float y2d = Mathf.Asin(y) / pi + .5f;
                // both are 0 to 1 as expected
                x2d = x2d * (float)planetTex.width;
                y2d = y2d * (float)planetTex.height;

                //range of the above is 0 to texture size, as expected

I feel like I am close because I’m getting at least the expected range of values, but the resulting texture is a mess:

Is that stretched horizontally too much for some reason? There is repetition, looks like an image that has the wrong row length.

Yeah I had the same thought. I got a good tip that I am going about this backwards, I should be iterating over the texture x/y and calculating the world space perlin noise from there. Duh. I’m going to try that, should be simpler.

Got it!

The messed up screenshots make a good TV static, if I must say.

feel free to steal it!

That’s actually what a lot of static is: a bunch of waves of varying frequencies being displayed line by line at a completely different frequency.