The following fragment shader will accept an array of [int2]
fragment half4 array_FragmentShader(Vertex_Out in [[ stage_in ]],
constant int2 *int2Array [[ buffer(1) ]]){
half4 retVal = half4(0.0,0.0,0.0,1.0);
if(int2Array[0].x==1){retVal = half4(0.6,0.0,0.0,1.0);}
return retVal;
}
nothing particularly difficult about that, however what Im wondering at the minute is how I pass an array of arrays into a fragment shader. Im only trying to find out the parameter syntax , for example do I use two asterisks to indicate a pointer to a pointer or something like that?
constant int2 **int2Array [[ buffer(1) ]])
addendum, should have included this in the very first place...
the code calling this is on the cpu side and is utilising a SCNProgram , see below:
let gridProgram = {
let p = SCNProgram()
p.vertexFunctionName = "boolVertexShader"
p.fragmentFunctionName = "array_FragmentShader"
p.isOpaque = false;
return p
}()
currentMaterial.program = gridProgram
let i2 = simd_make_int2(1,1)
var int2Array = [i2]
gridProgram.handleBinding(ofBufferNamed: "int2Array", frequency: .perFrame) { (bufferStream, node, shadable, renderer) in
bufferStream.writeBytes(&int2Array,count:MemoryLayout<SIMD2<Int32>>.stride*int2Array.count)
}
I also need to figure out how to send the 2d array from the cpu side because the .handleBinding requires 1: the swift side array and 2: the size of the data going to the cpu, Im guessing that if I go down this route with a 2d array that the individual arrays will have to be of uniform size?... anyone come across this before?