I'm trying to pass a vector array into a shader in unity, but every vector in the array is automatically setting itself to zero.
C# (in start funciton)
mat.SetVectorArray("_Vtex", p4);
Shader (in pass)
float4 _Vtex[pow(5,3)];
Shader (in v2f function)
for (float cube = 0; cube < pow(5, 3); cube++)
{
float3 p1 = i.worldPos;
float3 p2 = _Vtex[cube].rgb;
dist = distance(p1,p2);
if (dist < minDist)
{
minDist = dist;
minDex = cube;
}
}
col.rgb = minDist;
This should generate a Voronoi pattern from the points _Vtex that its given from the C# and finding the closest point to draw the distance from, however, I think that all the points in _Vtex are being read as (0,0,0,0) because the resulting cube is all white and gets darker as it is scaled down.
large bright cube
small dark cube
This wouldn't be so strange if I could not still retrieve the vector array from the shader in C# and read its points to the console.
C# (in update function)
print(mat.GetVectorArray("_Vtex")[(int)Mathf.Floor(Time.time/2)]);
console printing point locations perfectly fine
What is going on in this shader that is voiding all of the data?
The main suspect is some wrongness happening when I change the data type in the shader from float4 to float3 so I tried adding .rgb to the point (pictured above) and .xyz, but neither worked.
I also checked for any wrongness with the indices being called, the p4 list being passed into the shader is the same length as the loop.
Finally I checked i.worldpos, which is working fine.
question from:
https://stackoverflow.com/questions/65874059/passing-data-into-shaderlabs-is-being-very-strange 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…