SCNShadable Reference指出SceneKit
中的某個遮罩修改器可能包含自定義全局函數。但是,自更新至Xcode 7
後,此選項似乎不再適用。即使參考頁面的Apple示例也不再編譯。根據錯誤消息,自定義函數根本不存在於由SceneKit
生成的OpenGL
着色器源代碼中。 有誰知道這個新的限制(或錯誤?)可以如何解決?也許需要額外的編譯指示?SceneKit:Shademodifier忽略Xcode 7中的自定義全局函數
在「Writing a Shader Modifier Snippet」下的SCNShadable Reference上給出的第一個示例中可以看到問題。 要看到錯誤,只需創建一個新Xcode
「遊戲」項目,並在GameViewController.viewDidLoad()
末粘貼以下代碼:
let fragmentShader =
"// 1. Custom variable declarations (optional)\n" +
"// For Metal, a pragma directive and one custom variable on each line:\n" +
"#pragma arguments\n" +
"float intensity;\n" +
"// For OpenGL, a separate uniform declaration for each custom variable\n" +
"uniform float intensity;\n" +
"\n" +
"// 2. Custom global functions (optional)\n" +
"vec2 sincos(float t) { return vec2(sin(t), cos(t)); }\n" +
"\n" +
"// 3. Pragma directives (optional)\n" +
"#pragma transparent\n" +
"#pragma body\n" +
"\n" +
"// 4. Code snippet\n" +
"_geometry.position.xy = sincos(u_time);\n"
"_geometry.position.z = intensity;\n"
if let material = ship.childNodes.first?.geometry?.materials.first {
material.shaderModifiers = [SCNShaderModifierEntryPointGeometry: fragmentShader]
}
運行的程序提供了以下錯誤,指出自定義標識sincos
未定義:
SceneKit: error, failed to link program: ERROR: 0:191: Invalid call of undeclared identifier 'sincos'
在錯誤消息中,您還可以看到SceneKit爲陰影修飾符生成的程序。它包含所有內容,但已被過濾掉的sincos
的定義。
也許顯示您正在使用的代碼和您提到的具體Apple示例。 –
謝謝,提示,@我將會。我已經編輯了我的問題。 –
很少有人在野外使用SceneKit。 Apple內部似乎沒有人使用它。因此你對樣品的問題。基本測試沒有完成,更不用說文檔更新了。蘋果公司及其員工對其內部的系統問題沒有任何交流。這導致幾乎沒有人認真對待它。或許最好把蘋果的遊戲框架看作是一個慢慢發展的創意糖果,朝着一個未來的方向發展,這個糖果能夠爲蘋果公司提供資金支持,併爲他們選擇遊戲開發商,讓他們慢慢成爲遊戲內容的製作者。 – Confused