SceneKit Shader Modifiers with GLSL Arrays

I am trying to pass an array of points to a shader modifier in SceneKit, but I cannot work out the correct syntax. In my shader expansion code, I have:

uniform vec2 points[100];

If I call ...

material.setValue(NSValue(point: CGPoint(x: 100.5, y: 50.5)), forKey: "points")

... then he sets the meaning points[0], which makes me think that perhaps this is impossible. I tried many other combinations for both key and value, but nothing works.

Is there a better way to do this? My ultimate goal is to change the diffuse surface color for a set of points in the array and otherwise use the default rendering. Is there a better way to do this in a shader than looping through an vec2s array ?

Thank you for your help.

+1
1

- , GL GPU, , .

, SceneKit, blob, NSData, . .

// warning: coded in Safari and untested

import simd
let points: [float2] = [[100.5, 50.5], [110.5, 60.5], /* ... */ ]
// make sure you have 100...
let data = NSData(bytes: points, length: points.count * sizeof(float2))
material.setValue(data, forKey: "points")

, , SceneKit CGPoint GPU vec2, , SceneKit , ... , GPU, , .

, , , . , CGPoint -its CGFloat, . float2 SIMD GL vec2 Metal float2.

+1

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


All Articles