Abh*_*kar 12 android unity-game-engine vuforia
我一直在努力让相机补丁样本统一工作.
我终于成功地在编辑器中工作了但是因为我的生活不能使它在我的三星galaxy s3(android)上运行.
我能看到的唯一区别是cameraTextureRatio,在编辑器中1.0 1.0,纹理和图像大小相同.在我的手机上它是:
_CAMERATEXTURE_RATIO_X:0.625
_CAMERATEXTURE_RATIO_Y:0.9375
Run Code Online (Sandbox Code Playgroud)
决议:
VideoTextureInfo 1024 512 640 480
Run Code Online (Sandbox Code Playgroud)
我正在计算它:
cameraTextureRatio.x = (float)texInfo.imageSize.x / (float)texInfo.textureSize.x ;
cameraTextureRatio.y = (float)texInfo.imageSize.y / (float)texInfo.textureSize.y ;
Run Code Online (Sandbox Code Playgroud)
我的着色器是:
Shader "Custom/VidTexPatch" {
Properties {
_MainTex("Texture", 2D) = "white" { }
}
SubShader{
Pass{
Cull Back
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4x4 _MATRIX_MVP;
float _CAMERATEXTURE_RATIO_X ;
float _CAMERATEXTURE_RATIO_Y ;
struct v2f{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(appdata_base v){
v2f o;
float2 targetSize = float2(15,15);
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);
// float2 finalCoords = float2(cameraTexCoords.x * cameraTextureRatio.y, cameraTexCoords.y * cameraTextureRatio.y);
o.uv = finalCoords;
//o.uv=cameraTexCoords;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
half4 frag(v2f i) : COLOR{
half4 texcol = tex2D(_MainTex, i.uv);
return texcol;
}
ENDCG
}
}}
Run Code Online (Sandbox Code Playgroud)
缓冲区大小与纹理大小不同.我搜索并发现它与两个硬件限制的功率有关.
运行时,捕获的补丁会显示在摄像头前.当我在我的moto g(android)中尝试分辨率为1280*720(16:9)时,缓冲区为2048*1024.和映射是一些正确的.
当分辨率为4:3时,1280/2048 = 0.62和720/1024 = 0.70的比例更接近: -
640*480(4:3)缓冲区的大小为1024*512,比率为640/1024 = 0.62和480/512 = 0.93.在x方向上必须有一些缩放,当您在设备中查看平面(RenderTargetView)时,您可以观察到这种缩放.我试图调整纹理的大小,但团结不会允许它.
我在这里做了一个干净的团结项目:https: //www.dropbox.com/s/e3nfs62fdm9ajsi/cameraPatch.unitypackage
使用的标记位于Textures/ar.png中
我正处于放弃的边缘,我想我现在已经尝试了所有的东西..:/有没有人知道如何解决这个问题?如果有人可以看一看并且可能发现错误,我会永远感激不尽.谢谢
| 归档时间: |
|
| 查看次数: |
767 次 |
| 最近记录: |