Scenekit some textures have a red tint

I have a scene that has a lot of objects, everyone has different textures. For some reason, 2 objects have a red tint, although their textures are not red. You can still see the pattern in the texture, it just has different shades of red. (On the simulator, 2 objects have black and white textures and shades of a red device) Does anyone know why this is happening? Other objects are working fine.

+4
source share
3 answers

For material properties, such as metalnessand roughness, SceneKit supports single channel (grayscale) images. To preserve memory, these images are saved as shades of gray; they are not converted to RGB textures that have the same data in each channel.

When you use such an image for the “color” property of the material (for example diffuse), SceneKit will request the red, green, and blue components of the sample, and green and blue will always be 0, and the image will be red.

One bad decision is to recycle your texture in an image editing application to save it as RBG instead of shades of gray.

You can also try shader modifiers to convert from grayscale to RGB:

_surface.diffuse.rgb = _surface.diffuse.rrr;

Edit

iOS 11 textureComponents :

material.diffuse.textureComponents = .red
+3

().png SCNMaterial.

. , .

let texture = SCNMaterial()
texture.diffuse.contents = UIImage(named: "rgb image with only gray")

, UIImage UIImage:

let texture = SCNMaterial()
var newImage: UIImage?
if let textureImage = UIImage(named: "rgb image with only gray") {
    UIGraphicsBeginImageContext(textureImage.size)
    let width = textureImage.size.width
    let height = textureImage.size.height
    textureImage.draw(in: CGRect(x: 0, y: 0, width: width, height: height))
    newImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
}
texture.diffuse.contents = newImage

+2

png .
, , - png truecolor png.

NSImage. CGImage png, .

let url = URL(fileURLWithPath: pngFileName, relativeTo: directoryPath)

// let reddishImage = NSImage(contentsOf: url)

let cgDataProvider = CGDataProvider(url: url as CFURL)!
let cgImage = CGImage(pngDataProviderSource: cgDataProvider, decode: nil, shouldInterpolate: false, intent: CGColorRenderingIntent.defaultIntent)!
let imageSize = CGSize(width: cgImage.width, height: cgImage.height)
let correctImage = NSImage(cgImage: cgImage, size: imageSize)
0

Source: https://habr.com/ru/post/1657853/


All Articles