Hello,
I've been struggling to get the camera patch sample to work in unity.
I finally succeded to make it work in the editor but for the life of me can't make it work on ios.
The only difference I can see is cameraTextureRatio which is 1.0 1.0 in the editor the texture and image size being identical.
On my iphone it is:
_CAMERATEXTURE_RATIO_X:0.625
_CAMERATEXTURE_RATIO_Y:0.9375
with resolutions of:
VideoTextureInfo 1024 512 640 480
I'm calculating it like so:
float4x4 _MATRIX_MVP; float _CAMERATEXTURE_RATIO_X = 0; float _CAMERATEXTURE_RATIO_Y = 0; struct v2f{ float4 pos : SV_POSITION; float2 uv : TEXCOORD0; }; v2f vert(appdata_base v){ v2f o; float2 targetSize = float2(10,10); float2 cameraTextureRatio = float2 (_CAMERATEXTURE_RATIO_X, _CAMERATEXTURE_RATIO_Y); float4 targetPoint = float4(targetSize.x * (v.texcoord.x - 0.5), targetSize.y * (v.texcoord.y - 0.5), 0.0, 1.0); float4 clipCoords = mul(_MATRIX_MVP, targetPoint); float3 normalizedDeviceCoords = clipCoords.xyz / clipCoords.w; float2 cameraTexCoords = float2((normalizedDeviceCoords.x + 1.0) / 2.0, ((normalizedDeviceCoords.y * -1.0) + 1.0) / 2.0); float2 finalCoords = float2(cameraTexCoords.x * cameraTextureRatio.x, cameraTexCoords.y * cameraTextureRatio.y); o.uv = finalCoords; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); return o; }
There must be something else I'm missing - if anybody has a hint I'd really appreciate it to know.. desperate... :/
Thanks a lot in advance,
Seb
Little update:
so it actually *does* work on the device - but only if I set the camera direction to CAMERA_FRONT. I suppose now the camera is matching the one from the webcam in the unity editor and I get the same result.
I bet there is just one thing that needs to be inverted .. *somewhere* .. :/
Any eye-openers, please send them my way.
Thanks muchly!
seb