1
\$\begingroup\$

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:
enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Are you sure you need to include "#include <metal_stdlib> using namespace metal;" in the modifier ? Is it not already included in the main shader the modifier snippet is going to fit in? \$\endgroup\$ Commented Sep 16, 2016 at 0:41

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.