According to the Apples documentation, "To update a value once, use key encoding: call the setValue: forKey: method, which provides a uniform name from the shader source code as the key and the corresponding data type as the value." (taken from SCNProgram Class Link ).
However, I cannot get this to work.
I have a subclass of SCNMaterial, install a new instance of SCNProgram, load the vertex and fragment shader. I used handleBindingOfSymbol to set custom variables like
self.stringMaterial.handleBindingOfSymbol("waveAmplitude") { programID, location, renderedNode, renderer in glUniform1f(GLint(location), Float(self.amplitude)) }
This is working correctly.
For efficiency, I want to move on to the possibility of using key coding. But if I replace the above code with
self.stringMaterial.setValue(Float(self.amplitude), forKey: "waveAmplitude")
the shape value in the shader is 0.0.
Does anyone have any experience? (I do it on MacOS, but I expect it to be the same on iOS.)
source share