This is somewhat related to a previous question I asked How to create a seamless cubemap noise texture?
I have managed to successfully step through a 3D noise function to create a cubemap texture which I'm then applying to an icosphere. This is done by stepping though it as suggested above.
However, I'm getting some mixed results on some of my edges:
In this picture, I'm not sure if it's clear but you can see the seam up the middle. However, this "seam" is actually perfectly smooth from a noise perspective. The problem is that both of these cube faces seem to be distorted, like they are being dragged up the sphere.
This picture shows one of the corners. Again, the noise is perfectly fine, but I think it's obvious that the way I'm stepping through my noise along a sphere surface is wrong. It's like it's going in opposite directions?
From RenderDoc I was able to retrieve the actual cubemap generated:
Which I think shows the this problem is only apparent on a few face edges, or at least, not all of them.
The code I'm using goes through all six faces individually (so that I don't have to generate the noise from inside the sphere, just the surface). The code looks like this:
...
glm::vec3 origin = glm::vec3(100,100,100); // really whatever, just some arbitrary point
int radius = 100; // the "size" of my textures
glm::vec3 dimensions = glm::vec3(radius,radius,radius);
ImageObject img1;
ImageObject img2;
ImageObject img3;
ImageObject img4;
ImageObject img5;
ImageObject img6;
for(int y = radius-1; y >= 0; --y)
{
for(int z = 0; z < radius; ++z)
{
glm::vec3 pointDirection = glm::normalize(glm::vec3(0,y,z)-origin);
glm::vec3 pointOnSphere = pointDirection * dimensions;
glm::vec3 pointOnSphereAdjustedForCenter = pointOnSphere + origin;
float noise = noise_function(pointOnSphereAdjustedForCenter.x, pointOnSphereAdjustedForCenter.y,pointOnSphereAdjustedForCenter.z);
img1.SetPixel(y,z,0,noise);
}
}
for(int y = 0; y < radius; ++y)
{
for(int z = 0; z < radius; ++z)
{
glm::vec3 pointDirection = glm::normalize(glm::vec3(radius-1,z,y)-origin);
glm::vec3 pointOnSphere = pointDirection * dimensions;
glm::vec3 pointOnSphereAdjustedForCenter = pointOnSphere + origin;
float noise = noise_function(pointOnSphereAdjustedForCenter.x, pointOnSphereAdjustedForCenter.y,pointOnSphereAdjustedForCenter.z);
img2.SetPixel(z,radius-1-y,0,noise);
}
}
for(int x = radius-1; x >= 0; --x)
{
for(int z = 0; z < radius; ++z)
{
glm::vec3 pointDirection = glm::normalize(glm::vec3(x,0,z)-origin);
glm::vec3 pointOnSphere = pointDirection * dimensions;
glm::vec3 pointOnSphereAdjustedForCenter = pointOnSphere + origin;
float noise = noise_function(pointOnSphereAdjustedForCenter.x, pointOnSphereAdjustedForCenter.y,pointOnSphereAdjustedForCenter.z);
img3.SetPixel(z,x,0,noise);
}
}
for(int z = 0; z < radius; ++z)
{
for(int x = 0; x < radius; ++x)
{
glm::vec3 pointDirection = glm::normalize(glm::vec3(x,0,z)-origin);
glm::vec3 pointOnSphere = pointDirection * dimensions;
glm::vec3 pointOnSphereAdjustedForCenter = pointOnSphere + origin;
float noise = noise_function(pointOnSphereAdjustedForCenter.x, pointOnSphereAdjustedForCenter.y,pointOnSphereAdjustedForCenter.z);
img4.SetPixel(radius-1-z,x,0,noise);
}
}
for(int y = radius-1; y >= 0; --y)
{
for(int x = 0; x < radius; ++x)
{
glm::vec3 pointDirection = glm::normalize(glm::vec3(x,0,z)-origin);
glm::vec3 pointOnSphere = pointDirection * dimensions;
glm::vec3 pointOnSphereAdjustedForCenter = pointOnSphere + origin;
float noise = noise_function(pointOnSphereAdjustedForCenter.x, pointOnSphereAdjustedForCenter.y,pointOnSphereAdjustedForCenter.z);
img5.SetPixel(y,radius-1-x,0,noise);
}
}
for(int y = radius-1; y >= 0; --y)
{
for(int x = 0; x < radius; ++x)
{
glm::vec3 pointDirection = glm::normalize(glm::vec3(x,y,radius-1)-origin);
glm::vec3 pointOnSphere = pointDirection * dimensions;
glm::vec3 pointOnSphereAdjustedForCenter = pointOnSphere + origin;
float noise = noise_function(pointOnSphereAdjustedForCenter.x, pointOnSphereAdjustedForCenter.y,pointOnSphereAdjustedForCenter.z);
img6.SetPixel(y,x,0,noise);
}
}
I'm sure that the problem is the way that I'm stepping through each cube face. I'm stepping in different directions. I had to do this because it was the only way to get my cubemap textures to line-up; but now that they're lined up, they've got something going wrong with them.
img1
only, shouldn't you be setting a different one each iteration? \$\endgroup\$for
"init" and not in thefor
"body". \$\endgroup\$