The SCNShadable Reference states that the hue modifier in SceneKit
may contain custom global functions. However, since upgrading to Xcode 7
, this option no longer works. Even the Apple example from the link page no longer compiles. According to the error message, user-defined functions are simply missing from the source code of the OpenGL
shader that is generated SceneKit
. Does anyone know how to use this new restriction (or bug?)? Maybe you need extra pragma?
The problem can be considered in the first example given in the SCNShadable Reference in the "Writing a Shader Modifier Fragment " section. To see this error, simply create a new Xcode
“game” project and paste the following code at the end GameViewController.viewDidLoad()
:
let fragmentShader =
"// 1. Custom variable declarations (optional)\n" +
"// For Metal, a pragma directive and one custom variable on each line:\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]
}
Running the program gives the following error, indicating that the user identifier sincos
is undefined:
SceneKit: error, failed to link program: ERROR: 0:191: Invalid call of undeclared identifier 'sincos'
In the error message, you can also see the program generated by SceneKit for the hue modifier. It contains everything except the definition sincos
, which is somehow filtered.
source
share