I have, so far, been able to create the vertices and UV coords etc for a sphere that would be textured with a cube map. I have also successfully loaded a cube texture from file and applied it to my sphere and it looks awesome.
So now, I want to randomly create a noise cube texture map to apply to my sphere.
I have a class which can create 1d, 2d, 3d and 4d noise. My problem is I don't know the math needed to sample a sphere map out of the cube, and then how to translate this to the 6 textures that make up with my cubemap.
I guess first I need to know how to first sample the points of a sphere in 3d; and then how to translate these to x,y,z coordinates for the 6 sides. I can probably work it out from there.
I would have thought this would be simple enough to Google, but I'm not finding what I need.
SOLUTION
For whomever comes along next, here's the answer. @Jason has the right idea below. Here's how I solved it:
- March through each of the faces of the cube and each UV coord for that face
- Normalize each position vector
- Multiply by the radius of your sphere. You now have the coordinates of the sphere edge
- These coordinates can be used to sample from your 3D noise function
You'll end up with each faces UV coordinates being filled with the noise that is at the spherical equivalents position in the noise.
(I hope that was in english). I will try to remember to update this later with full code once I've cleaned it up.
Answer
To generate noise which is isotropic, you need to sample from 3D space but from the surface of as sphere:
Here the black point is the location in space of the pixel in the image you want to generate the color for. Project it onto the unit sphere (the green point) by normalizing the vector from the origin (red), and then sample from your noise function (scale it up by a constant to get finer noise, or down to get softer noise). You will need functions to compute the x,y,z coordinates of a cube map pixel given the image dimensions, pixel x,y, and which face the pixel is on.
Note that classic Perlin noise has some serious artifacts when taking a 2D slice of 3D noise, so you should use another function, or add a bunch of randomly rotated copies of classic noise (which kinda hides the artifacts).
This noise will look distorted when you look at the raw images, but when rendered as a skybox it will appear uniform in every direction.
No comments:
Post a Comment