I’m working on a shader which billboards a quad, but want to use the final vertex positions of the billboarded mesh in the fragment shader. My assumption was that I could simply billboard it the usual way, and then use the inverse model view matrix to find the correct positions. Like so:
float scaledX = v.pos.x * length(unityObjectToWorld._m00_m10_m20);
float scaledY = v.pos.y * length(unityObjectToWorld._m01_m11_m21);
float4 viewPos = mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(scaledX, scaledY, 0, 0);
o.pos = mul(UNITY_MATRIX_P, viewPos);
o.modelPos = mul(viewPos, UNITY_MATRIX_IT_MV);
But this isn’t quite working how I expected. It creates an effect where only rotating the camera changes the output, while moving the object relative to the camera does nothing, even though the billboard rotation, and therefore the final vertex positions, are changing.
I’m fairly new to shaders, so I might be missing something obvious. But I’ve tried researching for a while and came up empty. Any help would be appreciated!