- Home /
Hide a light for a camera
Hi everyone!
I wanted to know if it is possible to hide a light for a camera?
I tried to use layers: I assign a layer for my light, and in my camera inspector, I cull the mask linked to my light, but I can still see my light through my camera. The idea is to see the world though camera 1 with the light, but through camera 2 without this light.
So I wonder if I misused the layers, or if there is another method.
Thanks in advance!
I did a quick setup, and what you describe works fine for me. $$anonymous$$ake sure the Culling $$anonymous$$ask property is correctly set for the light. $$anonymous$$ake sure the object you want to light are on the correct layers also.
Hi, There is a problem with this solution: if my object has no longer the light, the second camera won't see it, will it? (Or I haven't understood your solution?)
The solution I have, which is quiet costly and annoying, is to duplicate my whole world and to move both cameras at the same time in the 2 worlds. One world has the light and the other world hasn't the light.
I did not understand your question, so yes you need duplicate geometry. If you have Unity Pro you might be able to use RenderTexture to solve the issue. You can set a new RenderTexture, turn the light on, render to the texture and disply it, then return the camera to normal view. $$anonymous$$y guess it that it would be too expensive to do evry frame, but I don't know. Apparently folks have managed to save RenderTextures quick enough to capture video:
http://answers.unity3d.com/questions/61581/rendertexture-to-create-a-movie-very-fast.html
Answer by Wolfram · Jan 11, 2013 at 10:34 PM
Hm, you should be able to do this with OnPreRender and OnPostRender. Attach a script with these functions to Camera2, and in OnPreRender disable the light, and in OnPostRender re-enable it.
Answer by LoungeKatt · Sep 30, 2014 at 06:08 AM
I am not sure if Wolfram's answer was working by itself in previous versions of Unity, but 4.6 seems to require a slightly different setup. For anyone that stumbles across this like I did, this is what was needed in the script attached to the camera that does NOT see the light. It did not work until OnPreCull was added, but OnPreRender has been left as a precaution.
function OnPreCull () {
if (limelight != null)
limelight.enabled = false;
}
function OnPreRender() {
if (limelight != null)
limelight.enabled = false;
}
function OnPostRender() {
if (limelight != null)
limelight.enabled = true;
}
Hi. Can you tell me what is limelight? i searched it but i can't find that word in unity. i tried copying your code to my C# script and just changed the "function" to "void".. limelight is colored red and says the word doesn't exist in the current context. I am making a $$anonymous$$imap with my horror game and it has flashlight in it but yeah my $$anonymous$$imap cam still can see the light x_x
@Jezzer21 It is your flashlight. If you trying to resolve your flashlight being visible on the map, it should have been relatively obvious that it would have to be referenced in there somewhere.
Your answer
Follow this Question
Related Questions
How can i turn on/off the camera light of my phone? 1 Answer
Best way to access RenderTexture immediately after camera render 0 Answers
How do I reset camera and light to default positions?,How do I reset camera and light to default? 0 Answers
Doesn't rendering plane 0 Answers
Light glitch when not in camera's view 0 Answers