- Home /
Two outputs, one camera?
Hello, I'm having a hard time figuring this one out, mainly because I have no knowledge on cameras.
I'd like my camera to have an output on the screen (normal camera) as well as on a texture, this is important that I use only one camera for both outputs for optimization reasons: rendering the whole scene twice is not what I'd call best practice for iPhone ;P
From the inspector and as far as I know, there is no way to make the camera output on both a texture and the screen, I could double output on a texture, but the image quality is kind of sloppy...
Can you explain either or both: why you want to out put the same content to the camera and screen and/or what the final effect is that you are trying to achieve by this?
I've found a hack here, to do the trick, I hope it won't render twice though... Link to answer
what I'm wanting to do is make everything cast a linear shadow on the background. just like in this game:
You would much more likely want to use shadows volumes or by other means try to fake it. Have a look at this toolkit: http://forum.unity3d.com/threads/102079-Dynamic-shadows-in-Unity-Free-Pro-possibly-$$anonymous$$obile
I'll see if there's something to do with this, but from what I've read so far, the toolkit won't render well transparent textures and is rather resource hungry.
Answer by save · Jan 29, 2013 at 03:01 PM
This is the only way I can think of using one camera, there might be something more fancy on a more clever level. This renders the camera twice but you can restrict it to certain frames.
var renderTexture : RenderTexture; //Create a RenderTexture in Project view and assign through Inspector
var updateFrameEvery : int = 1; //Update every # frame
private var cam : Camera;
function Start () {
cam = Camera.main;
RenderToTexture();
}
function RenderToTexture () {
var frameCount : int = 0;
while (true) {
if (Time.renderedFrameCount>frameCount+updateFrameEvery) {
renderTexture.active = renderTexture;
cam.targetTexture = renderTexture;
cam.Render();
renderTexture.active = null;
cam.targetTexture = null;
frameCount = Time.renderedFrameCount;
}
yield;
}
}
Thanks alot, I found a similar hack, and I was about to test if it was actually rendering the thing twice (which is why I don't want to have two cameras...), atleast you confirmed this ;)
Did you try this out?
I'm thinking this should be able to go actually as you can go with 30 fps and render twice directly onto a second layer behind non-culled objects. 60 fps is quite a lot and the difference is noticeable but isn't $$anonymous$$d-blowing between 30 and 60 on a handheld device. Running 30 fps is also good thinking of battery consumption. There should be enough juice in a phone to be able to do this in 30 fps on OpenGL ES 2.0.
You should be able to use a camera's "clear flags" when capturing for the render texture and a shader that multiplies on top of your background. It's an interesting problem, please get back to us with your findings!
$$anonymous$$y philosophy on ga$$anonymous$$g is all about the feel good, I couldn't sacrifice the s$$anonymous$$dy 60FPS for anything in the world, because it is one of the most important things for the game to feel good and half the quality of the gameplay comes from the "feel good factor"
Your answer
Follow this Question
Related Questions
Shadow flicker 0 Answers
Capturing the real-time output of multiple cameras in a scene 1 Answer
Flip The Entire Output in App 0 Answers
How to use two cameras in VR to display 3D object on top of UI panel? 0 Answers
Camera.render weird issue? 0 Answers