Our app lets users upload custom images to serve as materials for SCNNodes, as you can see from the screenshots and code below.
Screenshot 1 shows SCNNodes when the materials use a scale of 1.
Screenshot 2 shows the same nodes with a scale of 2.
While using a scale of 2 sharpens the texture/materials noticeably, it also repeats the image because of the wrapS
and wrapT
properties. Using Mirror
or Clamp
for these properties instead of Repeat
did not help.
In SceneKit or UIKit, you supply an image of higher resolution and scale down to improve sharpness for different devices. For instance, for a 50x50 button, you supply a 100x100 image. You can see the contrast between UIKit sharpness and SceneKit sharpness for the same image by viewing the sharpness of the same images when rendered in UIKit components at the bottom.
1) How do you apply the same principle to SceneKit?
2) More importantly, how can you achieve the texture/material sharpness of screenshot 2 while avoiding the repeating behavior?
Code:
// Create box geometry
let box = SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 0.0)
box.firstMaterial!.diffuse.contents = style.getContents() // This returns a UIImage
box.firstMaterial!.specular.contents = UIColor.whiteColor()
// Increase resolution for image styles
let scale = Float(2)
if style.type == .Image {
box.firstMaterial!.diffuse.contentsTransform = SCNMatrix4MakeScale(scale, scale, scale)
//box.firstMaterial!.locksAmbientWithDiffuse = true
box.firstMaterial!.diffuse.wrapS = .Repeat
box.firstMaterial!.diffuse.wrapT = .Repeat
box.firstMaterial!.diffuse.mipFilter = .Linear
}
Textures: