Send enums to compute shader?
Hey guys! I'm having problems sending an enum value to a compute shader.
What I basically have is a component Shape with a public enum ShapeType and a public attribute shapeType of type ShapeType, so I can select it from the inspector.
public class Shape : MonoBehaviour
{
public enum ShapeType {Sphere, Cube, Torus}
public ShapeType shapeType;
}
In my main script I'm rendering a texture using a compute shader which looks like this
Texture2D<float4> source;
RWTexture2D<float4> result;
struct Shape {
int shapeType;
};
StructuredBuffer<Shape> shapes;
int numShapes = 0;
[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
Shape shape = shapes[0];
result[id.xy] = float4(63.75 * shape.shapeType, 0, 0, 0.0);
}
The texture is rendered on OnRenderImage which is also where I set the structured buffer and its size. There I get all the objects with Shape in my scene and convert them to an array of ShapeData struct which looks like this.
struct ShapeData {
public int shapeType;
public static int GetSize() {
return sizeof (int);
}
}
The problem is, when I change the shape type of an object in the scene, the screen stays black, indicating that the shape type remains 0, even though it should be a shade of red. Am I missing something?
Your answer
![](https://koobas.hobune.stream/wayback/20220613055300im_/https://answers.unity.com/themes/thub/images/avi.jpg)