- Home /
Two camera rendering an object differents textures
Hello everyone,
I have an issue of algorithmy. Here is what I have to explain the context : I have one camera, displaying the object in his "normal" texture, and I want another camera to show the same object but with a different texture (Infrared texture), because I want a normal and an Infrared camera.
But I can't find an optimised way to do that.. Because I have a lot of objects which some are pretty heavy. Duplicating the object will make the program very very slow...
Thanks for your help.
You dont need to duplicate anything. Just have another camera and slap some image effects on it.
I can't put a shader on my camera, because i'm working on a simulation and so that i have pre-made texture with infrared put on the good spots of the object. (So in fact the infrared texture is generated by a special software)
This sounds like a job for RenderWithShader to me. This is a powerful, often-overlooked, and slightly confusing feature. Look into it and see if it will satisfy your request. If not, or if you get stuck, please explain why this will not work for you, and perhaps we'll come up with some alternatives.
http://docs.unity3d.com/ScriptReference/Camera.RenderWithShader.html
Well I don't know if RenderWithShader can allow a changing of texture ? I mean here is my example : One camera Cam1 is looking at the world with normal texture, Cam2 is also looking at the world with normal texture too, and when I want the infrared to come the Cam1 now see the world with Infrared textures (But not with maths on shader, just on replacing a texture by another one in Resources) do you see?
Ah, I see the conundrum now: Not all cameras should view the infrared textures, and the method doesn't (yet) involve an image effect.
Something tells me an image effect is still the best approach. Ideally you would store the infrared textures with the material as an extra texture property on the shader, which implies editing whatever shader you're using.
This is a request I have no experience with. If no one comes along to help, you might consider asking the question in the shader forum armed with the knowledge of which approach you want to use. Any workable approach is going to involve an image effect, or at least the OnPreRender/OnPostRender methods of a camera script.
e.g. in descending order of wisdom:
A) image effects + edited shader with alternate texture property
B) multiple materials switched on/off during OnPreRender / OnPostRender
C) multiple independent objects on respective layers to achieve desired render results.
Answer by AurimasBlazulionis · Jul 06, 2015 at 10:33 AM
You are wrong about duplicating objects making your program super slow, just put the normal ones to 1 layer and infrared to another layer, then one camera draws normal objects (choosing their culling mask), and another infrared ones, enable and disable cameras when you need another one to be drawn (you can also make both cameras visible at the same time). Also remove colliders from infrared ones to not be interacted by physics. Make infrared objects be a child of normal one and you are good to go.
You can also simply change the material of object to make it infrared. If you want to do so you are probably interested in this question. This should be used if you want to switch between modes, but won't really work if you want to display both infrared and normal object at the same time.
The thing is, I already duplicate every object by 3, because what I am making is a drone simulator, and we need to duplicate each objects 3 times for 3 different drones (not only the drones, but the ground as well, I am using a system of bundle and chunk so the drones are already not on the same layer and the cameras currently display the good culling mask) so If I do your method, I will have 6 duplication to do right ? Won't it be a bit heavy ? I am sorry for my bad english tell me if you don't understand what I am saying.
@TheDiamondPlay - This is not sound advice. It is true that extra game objects do not necessarily cripple draw calls if they're culled properly, and duplicates can be a valid solution to some problems. This is not one of those situations. GameObjects most definitely have a negative impact on performance, even if they're not drawn or even active. Technically duplicates could solve the OP's problem, but that's also the worst possible approach. The better "brute force" method would involve switching out materials during OnPre/OnPostRender of the specific camera(s).
@$$anonymous$$angoo13 - Why do you need to "duplicate every object by 3"? I cannot imagine a good reason for this. What does this help you accomplish? There's got to be a better way. Definitely don't make it 6. You should try very hard to avoid using duplication as a design strategy; there's almost always a better way.
Answer by patchworkx · Jan 06, 2017 at 06:04 PM
Whats about an video texture with 2 frames .. 1 frame normal../2nd frame infrared.. camera 1 stop@first frame.... or frame 1 / camera 2 stop @last frame .. or 2nd frame..
u Can have more than 2 different textuers that way
Your answer
Follow this Question
Related Questions
Capturing the real-time output of multiple cameras in a scene 1 Answer
Rendering a Pygame surface in Unity 0 Answers
Create texture from current camera view 3 Answers
Multiple Render Texture and Ordering 0 Answers
Render texture and shader issues 0 Answers