SceneKit passes a single vector for shader modifiers

I am trying to pass GLKVector4to a shader, which should get it as vec4. I use the fragment shader modifier:

material.shaderModifiers = [ SCNShaderModifierEntryPoint.fragment: shaderModifier ]

where shaderModifier:

// color changes
uniform float colorModifier;
uniform vec4 colorOffset;

vec4 color = _output.color;

color = color + colorOffset;
color = color + vec4(0.0, colorModifier, 0.0, 0.0);

_output.color = color;

(I just add color offset) I tried:

material.setValue(GLKVector4(v: (250.0, 0.0, 0.0, 0.0)), "colorOffset")

which does not work (no offset is added, and the shader uses the default value (0, 0, 0, 0)). The same thing happens if I replaced GLKVector4withSCNVector4

Following this , I also tried:

let points: [float2] = [float2(250.0), float2(0.0), float2(0.0), float2(0.0)]
material.setValue(NSData(bytes: points, length: points.count * sizeof(float2)), "colorOffset")

However, I can easily pass the float value to a uniform colorModifierone by doing:

material.setValue(250.0, forKey: "colorModifier")

and this will increase the green channel as excluded

+4
source share
1 answer

, NSValue, SCNVector4, :

let v = SCNVector4(x: 250.0, y: 0.0, z: 0.0, w: 0.0)
material.setValue(NSValue(scnVector4: v), "colorOffset")

, SceneKit ...

+2

Source: https://habr.com/ru/post/1654077/


All Articles