I want to know if it is possible to pass a structured buffer to my material containing a struct that has a Vector3 array. I feel like this should be doable - my buffer stride is initialized properly.
Ultimately my goal is to have this flexibility, given that I initialize the size of positions[ ] before filling and setting the data on the buffer:
struct Line
{
public Vector3[] positions;
}
As opposed to a fixed set of Vector3:
struct Line
{
public Vector3 position0;
public Vector3 position1;
public Vector3 position2;
public Vector3 position3;
}
On the shader side, I’m passing this Vector3 array along like so:
struct Line
{
float3 positions[4];
};
uniform StructuredBuffer<Line> lineBuffer;
struct v2g
{
float4 pos : SV_POSITION;
float3 positions[4] : LINEPOSITIONS;
};
v2g vert(appdata_base v, uint id : SV_VertexID)
{
Line line = lineBuffer[id];
v2g OUT;
OUT.pos = mul(_Object2World, v.vertex);
OUT.positions = line.positions;
return OUT;
}
However, I’m getting no errors that would indicate that this isn’t allowed, instead it just doesn’t work. The former (fixed) count of Vector3’s, and the below shader snippet does work however:
struct Line
{
float3 position0;
float3 position1;
float3 position2;
float3 position3;
};
uniform StructuredBuffer<Line> lineBuffer;
struct v2g
{
float4 pos : SV_POSITION;
float3 position0 : LINEPOSITION0;
float3 position1 : LINEPOSITION1;
float3 position2 : LINEPOSITION2;
float3 position3 : LINEPOSITION3;
};
v2g vert(appdata_base v, uint id : SV_VertexID)
{
Line line = lineBuffer[id];
v2g OUT;
OUT.pos = mul(_Object2World, v.vertex);
OUT.position0 = line.position0;
OUT.position1 = line.position1;
OUT.position2 = line.position2;
OUT.position3 = line.position3;
return OUT;
}
Any ideas if this is doable?