【问题标题】:Wrong colors when rendering SKTexture渲染 SKTexture 时颜色错误
【发布时间】:2020-10-29 02:07:33
【问题描述】:

我有一个由 GKNoiseMap 生成的 SKTexture。当我在一个快速的操场上查看纹理时,它具有预期的颜色。当我将纹理应用到材质并在 SCNView 中渲染时,颜色不同(见下图)。我做错了什么?

完整代码:

import GameKit
import SpriteKit
import PlaygroundSupport

let source = GKPerlinNoiseSource()
let noise = GKNoise(source)
noise.gradientColors = [-1: #colorLiteral(red: 0.7537418008, green: 0.4404714704, blue: 0.2776784003, alpha: 1) , 1: #colorLiteral(red: 0.2008953691, green: 0.186568588, blue: 0.2595013976, alpha: 1)]
let map = GKNoiseMap(noise, size: vector2(1.0, 1.0), origin: vector2(0.0, 0.0), sampleCount: vector2(Int32(256), Int32(256)), seamless: false)
let texture = SKTexture(noiseMap: map )


let ball = SCNSphere(radius: 1)
let materials = SCNMaterial()
materials.diffuse.contents = texture
ball.materials = [materials]
var node = SCNNode(geometry: ball)


var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
var scene = SCNScene()
sceneView.scene = scene
PlaygroundPage.current.liveView = sceneView

var cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 3)
scene.rootNode.addChildNode(cameraNode)
scene.rootNode.addChildNode(node)

【问题讨论】:

    标签: swift sprite-kit


    【解决方案1】:

    我不明白为什么会这样(我怀疑这与伽马校正有关),但这里有一个解决方法:

    将 SKTexture 转换为 UIImage,然后将 UIimage 分配给材质的漫反射内容。这显示了正确的颜色。

    【讨论】:

      猜你喜欢
      • 2021-09-29
      • 2023-04-05
      • 2020-06-19
      • 1970-01-01
      • 2015-02-20
      • 2018-04-24
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      相关资源
      最近更新 更多