Thanks for the reply. I tried implementing this shader and feeding the texture as input by converting it to a tensor like so:
// Setup material properties
Material material = new Material(pixelShader);
material.SetTexture("_MainTex", texture);
material.SetMatrix("affineMatrix", M.ToFloat4x4());
material.SetFloat("X_width", texture.width);
material.SetFloat("X_height", texture.height);
material.SetVector("O_pos", new Vector4(m_DetectorInput.shape[2], m_DetectorInput.shape[1]));
Graphics.Blit(texture, material);
// Feed texture as input tensor to the detector
TextureTransform textureTransform = new TextureTransform();
textureTransform.SetDimensions(width: 192, height: 192, channels: 3);
textureTransform.SetTensorLayout(0, 3, 1, 2);
m_DetectorInput = TextureConverter.ToTensor(texture, textureTransform);
m_HandDetectorWorker.Schedule(m_DetectorInput);
Similarly with the landmarker using its appropriate input size and worker.
Running it with the GPUPixel backend will make Unity hang. If I run it with the GPUCompute backend, the detection appears but is distorted (it looks like its scale matches the ratio of the transformed image).
I remember one time I tried it, i was able to read an error after Unity hangs, it was probably something about GPU readback, it could be the problem or a symptom of it. Is there something I’m missing? Maybe you need a more detailed answer?
P.S: Here is the vertex function of the shader if it’s relevant.
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
And here’s the matrix conversion function.
public static float4x4 ToFloat4x4(this float2x3 matrix) {
return math.float4x4(
matrix.c0.x, matrix.c1.x, matrix.c2.x, 0,
matrix.c0.y, matrix.c1.y, matrix.c2.y, 0,
0, 0, 0, 0,
0, 0, 0, 0
);
}