Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Robert 1 · Mar 15, 2010 at 06:45 PM · cameralight

Turn off shadows for a specific camera?

Hello,

I have two cameras in my scene. One is a top-down camera that is used to render a "radar" (2D) on the HUD. The other camera is the 3rd person gameplay camera that follows the player.

I also have a single directional light in my scene that generates shadows. For my top-down camera, I do not want shadows to be rendered. For the player camera I do want shadows to be rendered.

Is there a way to turn off shadows for a specific camera?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Robert 1 · Mar 17, 2010 at 01:29 PM

I ended up turning off shadows on the scene's lights. This worked perfectly. The solution provided by 'burnumd' does not really work for some reason. It causes strange rendering artifacts as well as makes the scene very dark as if no lights exist at all.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lipis · Mar 17, 2010 at 02:26 PM 0
Share

@Bob consider adding comments ins$$anonymous$$d of posting something as an answer.. this is not the usual forum like site. Read more on how this thing works: http://answers.unity3d.com/faq

avatar image Robert 1 · Mar 17, 2010 at 02:34 PM 0
Share

I know how this works, because I use Stackoverflow as well. I'm literally answering my own question. There's nothing to comment on. I appreciate your kindness, however.

avatar image Waz · May 07, 2010 at 11:19 PM 0
Share

Your answer may be adequate for yourself, but I don't understand it at all. Do you mean you turned off shadows using OnPreRender, or what?

avatar image Robert 1 · May 10, 2010 at 02:41 PM 0
Share

Quite literally I turned off shadows on the light in my scene. There's an option for this in the inspector when you select the light in the scene.

avatar image
6

Answer by burnumd · Mar 15, 2010 at 07:06 PM

You can do what you describe using the Camera.OnPreRender () and Camera.OnPostRender () methods. So, you would attach a script to your minimap camera where, in OnPreRender, you store the current shadow distance in a class variable using QualitySettings.shadowDistance and set the shadow distance to 0. In OnPostRender, you simply restore the stored shadow distance.

var storedShadowDistance : float;

function OnPreRender () { storedShadowDistance = QualitySettings.shadowDistance; QualitySettings.shadowDistance = 0; }

function OnPostRender () { QualitySettings.shadowDistance = storedShadowDistance; }

Comment
Add comment · Show 10 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Robert 1 · Mar 15, 2010 at 07:38 PM 0
Share

I tried this, however shadows are still rendering for some reason. Any idea why?

avatar image burnumd · Mar 15, 2010 at 07:47 PM 0
Share

It works fine for me. Are you, perhaps, referring to lighting effects rather than shadows?

avatar image Robert 1 · Mar 15, 2010 at 08:01 PM 0
Share

Sorry I had it on the wrong camera, it works now. However, the scene is extremely dark on my radar now, as if no lighting is being calculated at all for the landscape. Does the directional light have no affect when shadowDistance is 0?

avatar image Romulas · Mar 25, 2014 at 07:47 AM 0
Share

Thank you, your answer solved my problem too.

avatar image omelchor · Apr 02, 2014 at 05:23 PM 0
Share

Thank you, your answer solved my problem too.

Show more comments
avatar image
1

Answer by Noctys · Feb 26, 2015 at 09:38 PM

I know this is old, but wanted to throw in an example that works based on Burnumd answer.

 public class ShadowToggler : MonoBehaviour
 {
     public Light[] SoftLights;
     public Light[] HardLights;
     void Start()
     {
         if (gameObject.GetComponent<Camera>() == null) { Debug.Log("No Camera Found"); }
     }
 
     void OnPreRender()
     {
         foreach (Light l in SoftLights) { l.shadows = LightShadows.None; }
         foreach (Light l in HardLights) { l.shadows = LightShadows.None; }
     }
 
     void OnPostRender()
     {
         foreach (Light l in SoftLights) { l.shadows = LightShadows.Soft; }
         foreach (Light l in HardLights) { l.shadows = LightShadows.Hard; }
     }
 }

There is probably a better way than having to add your lights to the arrays, but this is the simple method that allows for multiple lights and shadow types.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image erickluiss · Mar 07, 2020 at 05:11 AM 0
Share

Thanks man, this helped me :)

avatar image
1

Answer by Cherno · Mar 19, 2015 at 07:35 AM

From my experiemnce, using PreCull and PostRender methods are extremely resource intensive. There is a far easier way to do it: Just pass the Camera a replacement shader, one which doesn't render shadows (Unlit/Texture, for example).

 using UnityEngine;
 using System.Collections;
 
 public class MapCamera : MonoBehaviour {
 
     public Shader unlitShader;
 
     void Start() {
         //unlitShader = Shader.Find("Unlit/Texture");
         GetComponent<Camera>().SetReplacementShader(unlitShader,"");
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i turn on/off the camera light of my phone? 1 Answer

How do I reset camera and light to default positions?,How do I reset camera and light to default? 0 Answers

Light glitch when not in camera's view 0 Answers

I can see trees, even when there is no light 2 Answers

How to turn on camera light on iPhone? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges