I cannot run my program with shaders in node geometry in iOS 9. Here is the test code:
import SceneKit
class Test: NSObject, SCNProgramDelegate {
private static let SIZE = 10
private static let RES = 256
var node: SCNNode!
override init() {
super.init()
setup()
}
func program(program: SCNProgram, handleError error: NSError) {
NSLog("program error: %@", error)
}
private func setup() {
node = SCNNode()
node.rotation = SCNVector4Make(1, 0, 0, -Float(M_PI) / 2)
node.geometry = createGeometry()
}
private func createGeometry() -> SCNGeometry {
let size = CGFloat(GpuHeightFieldWater.SIZE)
let geometry = SCNPlane(width: size, height: size)
geometry.widthSegmentCount = GpuHeightFieldWater.RES
geometry.heightSegmentCount = GpuHeightFieldWater.RES
let program = SCNProgram()
program.delegate = self
program.vertexShader = loadShader("test.vsh")
program.fragmentShader = loadShader("test.fsh")
program.setSemantic(SCNGeometrySourceSemanticVertex, forSymbol: "a_position", options: nil)
program.setSemantic(SCNModelViewProjectionTransform, forSymbol: "u_mvpMatrix", options: nil)
geometry.program = program
return geometry
}
private func loadShader(name: String) -> String! {
let file = NSString(string: name)
let url = NSBundle.mainBundle().URLForResource(file.stringByDeletingPathExtension, withExtension: file.pathExtension)
let data = NSData(contentsOfURL: url!)
return String(data: data!, encoding: NSUTF8StringEncoding)
}
}
test.vsh:
attribute vec4 a_position;
uniform mat4 u_mvpMatrix;
void main()
{
vec4 a = a_position;
a.x = 0;
gl_Position = u_mvpMatrix * a;
}
test.fsh:
void main()
{
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
}
Node is added to the root of the scene node, and I see a plane (with a strange purple color), but my program never starts, and I see no errors for my program. So it looks like my program is being ignored.
What is wrong and how to run the program for geometry?
Update # 1
When I ran the application on the iPhone 5 simulator, it printed an error about my vertex shader code on line 7.
ERROR: 0: 7: Incompatible types (float and int) in assignment (and there is no implicit conversion available)
When I fix this error, it works. It is strange that when I launch this application on my iPad Mini 2 (iOS 9.0), I do not see any errors.
# 2
, , , iPhone 5s . iPad Mini 2 iOS 9.
, Metal (Mt):

iPhone GL:

, -.