I'm trying to write a simple shader able to pass the color to be used for drawing in the fragment shader, through a uniform. I load the shader modifier and pass the uniform:
let fragmentShaderPath = bundle.pathForResource("Cube", ofType: "fragment")!
let fragmentShader = try String(contentsOfFile: fragmentShaderPath)
let shaderModifiers : [String:String] = [
SCNShaderModifierEntryPointFragment : fragmentShader
]
cube.geometry?.shaderModifiers = shaderModifiers
SCNTransaction.begin()
cube.geometry?.setValue(NSValue(SCNVector4: SCNVector4Make(0.0,1.0,0.0,1.0)), forKey: "myColor")
SCNTransaction.commit()
And this is my fragment shader modifier code:
#include <metal_stdlib>
using namespace metal;
float4 myColor;
_output.color = myColor;
But nothing happens: the object is drawn as black. If I try declaring myColor as a uniform, I get an error:
