Search code examples
c#androidunity-game-enginevuforiagoogle-cardboard

Does RenderTexture works with Vuforia, Google Cardboard and Unity5?


I was working with Vuforia and Google Cardboard in Unity5, all the newest versions I could get. I started it sometime ago, and I need RenderTexture for a visual effect, but while I can make it work in the Unity Player, I can't manage to make it work in an android build. Let me explain.

I need to show the live camera that Vuforia uses, and I need the SDK of Cardboard for this project, so I first tried to make them work nice together, and it's done. Cool. Now, I tried to used a mask to render only half of the screen. Done, despite in the android build it covered the opposite half of the screen. No problem, I just was testing.

Here's where it comes the major problem. I wanted to show the other half that it's showing actually, mirrored. I tried lot of things, and the one that seemed to work was using RenderTexture in a Plane that was a child of the camera, using a third camera, independent from the cardboard ones, which I specified the Target Texture to the RenderTexture (called mirror) which I created with a material. I assigned the material to the plane, and it worked. I just needed to adjust the tiling and offset of the texture, as so I adjusted the position in the transform, so the effect was complete. Despite some flaws, it worked, so I did the android build. And... in all the smartphones I tested, the RenderTexture seemed black.

I tried a cube that I could see easily, so I can be sure that the plane isn't displaced or something. No luck, it was a black cube. I tried searching for the buffer (TextureBufferCamera) that's made in execution time. Got it in LateUpdate of a script in the cube, and assigned the cube's RenderTexture to the same RenderTexture the TextureBufferCamera was using, and it works. Only in play mode, as you could suppose. The android build shows a perfect black cube.

I tried too in a separate project, only with vuforia, and I got the exact same error with both methods (searching for TextureBufferCamera, and with the third independent camera). And... I don't know exactly why it's not working by any means.

I don't know exactly what you guys would need to have more info, just ask and I'll edit with any info that you would find useful. Oh, and it's my first time using Cardboard and Vuforia... So please, take that in mind, as I possibly miss something or... I don't know. I searched everywhere (not only here), and I only see very, VERY old posts with an error like this.


Solution

  • Well, after a while I come down to one thing. As far as I now, MovieTexture doesn't work in Android, but I couldn't see any problem with the RenderTexture... besides it doesn't renders at all.

    I came down with an alternate solution. I duplicated the BackgroundPlane in the Left Stereo Camera, and used a copy of the material that BackgroundPlane has. In this copy, I removed the Background Plane Behaviour, and I assured the second material have the same shader that the first video material. Then, I had to be constantly moving (in LateUpdate) the position of the two planes to have them both in the view at all. And I had to cut in half the scale of both of them too, in real time too, so they fit.

    It works really well, and the only issue I'm having right now, it's that I need to fit the point where they merge in the smartphone, as it's kind of displaced or something... but it renders! so, the original problem it's solved.

    I didn't saw too much attention in the question, and don't have so much time, so if someone needs more info about this, I'll post screenshots, code, or whatever he needs. But I think what I said is almost all the fix... so, yeah. I'll edit this answer if I need to, but for today, it's done.