Topic locked

BackgroundTexture to RenderTexture

July 7, 2014 - 2:20am #1

Hi there!

I really need to get the camera image each frame, it is necessary to build virtual objects reflection. I tried using GetСameraImage (), and this method works but is very slow (
 
I read the forum and saw the posts in 2010, which stated that it was not possible because the background running natively using OpenGL, whether the situation in the current version of the SDK?
 
Maybe you can advise me any other way to get images from the camera in each frame?

BackgroundTexture to RenderTexture

December 15, 2014 - 6:05am #6

Glad to hear ;-)

BackgroundTexture to RenderTexture

December 15, 2014 - 5:06am #5

Thanks for the info.

I actualy managed to get it working yesterday. The problem I had was that I had only one camera in the scene during design time but then, during runtime, something (i have not been able to track down what or where) instantiates a prefab found under the "Internals" folder (I forgot what the prefab is now) and THAT is then the one that renderes the actual camera, not the ARCamera prefab's camera component.

So I simply duplicated one of my existing textures in the project and set THAT prefab's camera to render to that image. From there I just created a RawTexture component in UGUI and gave it that texture as it's source and that was that. The camera now renders into a region I can set with the normal size and scalling tools of Unity :)

It was all very straight forward and simple and required no code on my end at all... one I noticed that prefab being instantiated and finding it in the projects tab. :)

So really, from me to you, kudos on making this kit work this beautifully :)

Thanks :D

BackgroundTexture to RenderTexture

December 15, 2014 - 3:08am #4

myBadStudios : 

According to the website I should follow the example in the "BackgroundTextureAccess" sample but there is no such sampel included in the Unity samples download

The BTA sample can be downloaded from here:

https://developer.vuforia.com/resources/sample-apps/background-texture-access-sample-app

or you can also go to the main Samples page:

https://developer.vuforia.com/resources/sample-apps/features

and scroll down the page and click on "Background Texture"

 

To achieve the scenario that you describe, you need to:

  • create a Texture in a custom script (e.g. something like   "public Texture2D myTexture; "); make sure to create the Texture with some code like 
  • myTexture = new Texture2D(0,0); 
  • use QCARRenderer.Instance.SetVideoBackgroundTexture(  myTexture ) to make sure that Vuforia will redirect the camera background to your Texture
  • you can then set your Texture to a Material of your choice; for example, you can define a simple plane and set the Material in it.

Note that this is mostly about Unity programming; strictly speaking, the only part which is really about Vuforia is the SetVideoBackgroundTexture API that ensures that the camera background fos to your texture.

If you want to have a good starting example of this, have a look at the VideoTextureBehaviour.cs script that you can find in the BTA sample.

 

 

 

 

BackgroundTexture to RenderTexture

December 14, 2014 - 3:21am #3

Could I please get a more detailed response to this?

According to the website I should follow the example in the "BackgroundTextureAccess" sample but there is no such sampel included in the Unity samples download so am I to understand that I should look at iOS or Android code to learn how to use this in Unity?

My needs are quite simple, I think, but I have no idea where to code what since the samples are fileld with so many scripts that derive from devied classes of derived calsses each calling the base of the one before and when I look at the forum or website it just gives a one line answer like above "add this line of code" but no indication of when or where in this entire process...

I have to say that I find all of this super confusing. I just spent the last 5 hours trying to figure out how to NOT show the camera full screen and I still have no idea hwo to do it :(

 

Here is what I want to do:

Render the camera into a RenderTexture which is, in turn, dispayed in a region of my screen (say, on a billboard) but have the rest of my scene be my 3D scene, NOT whatever my camera is seeing.

So I assigned the Camera's renderer target to a RenderTexture and I then go and draw that to the screen during an OnGUI function. I found that the camera does in deed NOT render to the image and just gives me a black screen, always. If I change the ClearFlags to SolidColour and set it to a color, THAT gets rendered to the image, sure, but the camera does not. So to test my theory that the camer is not being used I changed the ViewPort Rect and even turned off the camera completely and in both cases the entire screen still showed the video feed.... 

Considering the fact that this isthe only camera in my scene, what the heck is going on here, then??? This is the TextRecognition demo scene, by the way.

So my question is super simple:

How can I take the Text recorgnition demo scene and make it so that the video feed is NOT displayed full screen but only in a specfied region of my display?

I don't care if I have to do this via RenderTextires or via viewport rect manipulation or hwo many cameras I need to use to do this. The question is: "How?"

Thanks in advance.

BackgroundTexture to RenderTexture

July 9, 2014 - 12:28pm #2

If you need the camera texture for some OpenGL texture processing, you can use the approach used in the Background Texture Access sample, i..e you can reguster a Texture2D object as target for Vuforia, using this function:

QCARRenderer.Instance.SetVideoBackgroundTexture(  myTexture )

where myTexture is a standard Unity Texture2D object. So, basically you could use the same texture both for rendering the video background (as explained in te BTA sample) and for other visual effects in your app.

 

Topic locked