gpt4 book ai didi

ios - 为什么我的场景相机在使用 SCNTechnique 时只显示黑屏?

转载 作者:行者123 更新时间:2023-11-29 05:57:10 25 4
gpt4 key购买 nike

所以我在 iOS 12 (Swift 4.2) 中使用 SceneKit,并且我想向相机添加旋转/凹凸变形。我在这里发现了类似的东西( Fish Eye Wide-angle with a Scene Kit Camera: Possible? ),据说会产生桶形失真。但是当我尝试将其添加到我的项目中时,场景变黑,并且控制台中出现错误

2019-03-07 13:35:14.982232+0000 TestingSCN[551:66202] [framework] CUIThemeStore: No theme registered with id=0

2019-03-07 13:35:15.064859+0000 TestingSCN[551:66202] [framework] CUIThemeStore: No theme registered with id=0

2019-03-07 13:35:15.097517+0000 TestingSCN[551:66270] [framework] CUIThemeStore: No theme registered with id=0

2019-03-07 13:35:15.118445+0000 TestingSCN[551:66270] [SceneKit] Error: can not render without programs, using default

现在该方法基本上使用 JSON 字典文件来定义技术以及 GLSL 顶点和片段着色器文件。然后在我的主 swift 文件中,我将该技术添加到相机中。这是我使用的代码:barrel.json(位于 art.scnassets 中)

{
"passes" : {
"barrel" : {
"outputs" : {
"color" : "COLOR"
},
"inputs" : {
"colorSampler" : "COLOR",
"noiseSampler" : "noiseSymbol",
"a_position" : "a_position-symbol"
},
"program" : "art.scnassets/barrel",
"draw" : "DRAW_QUAD"
}
},
"sequence" : [
"barrel"
],
"symbols" : {
"a_position-symbol" : {
"semantic" : "vertex"
},
"noiseSymbol" : {
"image" : "noise.png",
"type" : "sampler2D"
},
"barrelPower" : {
"type" : "float"
}
}
}

桶.fsh

uniform sampler2D colorSampler;
const float PI = 3.1415926535;
uniform float barrelPower;
varying vec2 uv;
vec2 Distort(vec2 p)
{
float theta = atan(p.y, p.x);
float radius = length(p);
radius = pow(radius, barrelPower);
p.x = radius * cos(theta);
p.y = radius * sin(theta);
return 0.5 * (p + 1.0);
}
void main() {
vec2 rg = 2.0 * uv.xy - 1.0;
vec2 uv2;
float d = length(xy);
if (d < 1.0){
uv2 = Distort(xy);
} else {
uv2 = uv.xy;
}
gl_FragColor = texture2D(colorSampler, uv2);
}

桶.vsh

attribute vec4 a_position;
varying vec2 uv;

void main() {
gl_Position = a_position;
uv = a_position.xy;
}

GameViewController.swift(在 viewDidLoad 中)

let url: URL = Bundle.main.url(forResource: "art.scnassets/barrel", withExtension: "json")!

do {
let jsonData = try Data(contentsOf: url)
let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options:JSONSerialization.ReadingOptions(rawValue: 0))
guard let dictionary = jsonObject as? Dictionary<String, Any> else {
print("Not a Dictionary")
return
}
var technique: SCNTechnique? = nil
technique = SCNTechnique(dictionary: dictionary)
technique?.setValue(NSNumber(value: 0.5), forKey: "barrelPower")
cameraNode.camera?.technique = technique
}
catch let error as NSError {
print("Found an error - \(error)")
}

我并不是真正的着色器专家,我知道编写 SCNProgram 或其他东西可能会更好,但我不知道从哪里开始。如有任何帮助,我们将不胜感激:)

最佳答案

你可以尝试一下

    let scnView = self.view as! SCNView
scnView.technique = technique

当您使用 ("draw": "DRAW_QUAD") 来渲染渲染对象的纹理时。

还有一个编译器错误:

 float d = length(xy);  // `xy` is not defined

关于ios - 为什么我的场景相机在使用 SCNTechnique 时只显示黑屏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55045564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com