- Home /
How to Add texture image behind or below a 3D model with second camera?
How do I add a background image below a 3D model for augmented reality? I would like to place a graphic below a 3D character, for example a dragon model on a green image. I have tried the following code and only get a solid color on the second camera without the textured panel or GUI. I have also tried the Vuforia Background Texture Access for Unity. Thanks for any help!
You're almost there, with the 2nd camera approach. Here's how to do it:
Create a new camera (GameObject -> Create Other -> Camera), and name it "Background Camera".
Create a new GUI Texture (GameObject -> Create Other -> GUI Texture), and name it "Background Image".
Click the "Layer" dropdown menu in the Background Image's inspector pane, and select "Add Layer".
In the next free "User Layer" slot, create a new layer name called "Background Image". This will be directly under the layer named "Terrain" if you haven't yet added any others.
Select your Background Image in the hierarchy, and give it the desired texture, and set the x, y, width and height under "Pixel Inset" so that it fills the screen appropriately.
Near the top of the inspector window, Use the layer dropdown menu to assign your "Background Image" layer that you defined earlier to this gameobject.
Now select your Background Camera in the hierarchy, and adjust these settings in the inspector:
Un-Check Flare Layer and Audio Listener (but leave GUILayer enabled)
Set Clear Flags to Solid Color
Set Depth to -1
Set Culling Mask, first to "Nothing", and then to "Background Image"
Now Select you other (main) camera, and in the inspector:
Set its Clear Flags to "Depth Only"
Click its culling mask setting, and un-check "Background Image". This should result in the culling mask displaying as "Mixed ..."
Voila, this should give you your GUI Texture rendered by your background camera, behind everything else rendered by your main camera. And for any other additional cameras (eg, other camera angles) that you want to use, just repeat the last two steps on them.
more ▼ answered Jan 05, 2010 at 01:53 PM duck gravatar image duck ♦♦ 47.6k ● 129 ● 189 ● 457 thanks for this Duck, I was looking for the same thing. Query though, is there anyway to stop the clipping for a full background image when aspect ratio is changed?
Mar 23, 2010 at 12:31 PMRobF 4 It's much better if you set all the pixel inset values to 0, and set the scale to (1, 1, 1) instead. Otherwise, the background image doesn't adapt to different screen sizes. The only possible drawback is that the background image will get stretched or squished with different aspect ratios than the one you used to create the game. If this is not desirable, you can use a script like this one: http://www.unifycommunity.com/wiki/index.php?title=GuiRatioFixer
Apr 21, 2010 at 11:16 PMEric5h5 In 3.2, when I do all the above, the 'background' image is drawn really as a 'foreground' image in the Editor, all my other geometry behind the texture. I changed 'depth', no help. Anyone?
Feb 28, 2011 at 09:21 PMDaveA This solution works excellently. My only problem is when I go to actually make the background scroll, it stutters every now and then as it moves.
I am adding an offset*Time.deltaTime every update to the pixelInset.x. Is there a better way to make the background scroll? Code is below.
function Update () { var xVel : float = -xVelocity*Time.deltaTime; background1.pixelInset.x += xVel; background2.pixelInset.x += xVel; }
Aug 25, 2011 at 05:06 PMpaulg568 I had the same problem as DaveA. I finally realized that while my BG camera's culling mask was set correctly, my actual BG image was assigned to layer Default and not layer BackgroundImage.
That step is listed in the instructions but I must have accidentally skipped it or messed it up.
Your answer
Follow this Question
Related Questions
UnityEditor - Drawing on a Texture 1 Answer
ReadPixels requires an offset while in the Editor? 2 Answers
How can I save the Bild from a Camera, which not main camera is. 1 Answer
Detect WWW Image bitmap dimensions? 2 Answers
Get RenderTexture 1 Answer