Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Texture seam in iOS SceneKit

I'm getting intermittent appearances of seams in the textures that I apply to spheres in SceneKit. It's always at the "back" of the sphere, where the two edges of the texture meet. It looks as though the texture doesn't quite connect with itself, and you can see the background through the thin line. The problem seems to exist on all devices and across all recent iOS versions. My experiments have indicated that the resolution of the texture seems to be a factor, but I haven't nailed down exactly what that impact is.

I've attached a screenshot to illustrate, on a white background for clarity, but the seam isn't inherently white it just allows the background to show through:

Planet Seam

Does anyone know why SceneKit would be rendering the textures this way? I've got a fairly simple implementation, just creating a sphere and a material and applying a diffuse and normal map to it. Here's my code:

// create planet
SCNNode *baseNode = [SCNNode node];
[baseNode setName:name];

// Planet
SCNSphere *planet = [SCNSphere sphereWithRadius:5];
SCNNode *planetNode = [SCNNode nodeWithGeometry:planet];
[planetNode setName:@"planetNode"];
[baseNode addChildNode:planetNode];

SCNMaterial *material = [SCNMaterial material];
material.shininess = 1;
material.normal.intensity = 0.5;
material.normal.contents = normalMap;
material.diffuse.contents = diffuseMap;

planetNode.geometry.materials = @[material];

Does anyone have any experience with what might cause this "seam" to appear, and how I might get rid of it? My textures are generally either 1000x500 or 2048x1024, depending on the situation, and the seam has appeared at both resolutions. Is there an ideal resolution for SceneKit textures, or something well-known that could cause this behavior?

like image 581
Nerrolken Avatar asked Mar 14 '17 04:03

Nerrolken


1 Answers

The answer ended up being frustratingly simple: I was rescaling the textures for quality reasons, and this line was the result of a fractional resolution, like 1025.25f * 2048.5f.

Rounding the values to int before scaling the texture fixed the problem.

like image 53
Nerrolken Avatar answered Nov 12 '22 15:11

Nerrolken