Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 14ercooper · Aug 14, 2015 at 05:28 PM · cameralighting3d

Have cameras render using different light sources

I have two cameras in my game: MainCamera and Minimap. I want MainCamera to render lighting using Light1 and Minimap to render lighting using Light2. How do I go about doing this?

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

1 Reply

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

Answer by Cherno · Aug 14, 2015 at 06:20 PM

Mirrored here: MiniMap Camera goes dark when sun goes "down"

The hacky way to do this is to use the OnPreRender and OnPostRender methods in a script that is attached to the cameras. In these methods, you have to activate and deactivate all the lights that the camera should render/not render.

Note that this is not recommended as it will probably have a severe impact on your FPS.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class ExcludeLight : MonoBehaviour {
 
     public List<Light> Lights;
     public bool cullLights = true;
 
     
     void OnPreCull(){
         if(cullLights == true) {
             foreach (Light light in Lights){
                 light.enabled = false;
             }
         }
     }
     
     void OnPostRender(){
         if(cullLights == true) {
             foreach (Light light in Lights){
                 light.enabled = true;
             }
         }
     }
     
 }
 


If the issue is a minimap being rendered as it is affected by scene light (you probably want it to be unlit, with no shadows), then it's a lot more complicated. You have to use RenderToTexture to render the minimap camera's scene, apply a Replacement Shader which makes the camera use a shader that renders everything unlit, and display the rendertexture somehow (via OnGUI or UI.Image).

Here are my scripts

This is the one that goes onto the map camera. Drag the Unlit shader into the unlitShader slot in the inspector, or un-comment the commented line.

 using UnityEngine;
 using System.Collections;
 
 public class MapCamera : MonoBehaviour {
 
     public Shader unlitShader;
 
     void Start() {
     //unlitShader = Shader.Find("Unlit/Texture");
         GetComponent<Camera>().SetReplacementShader(unlitShader,"");
     }
 }


This script can go to any GameObject I guess, I had it on my player object. the material variable can hold a masked material, where the mask makes the minimap texture round, for example. Leave the renderTexture variable alone, it gets assigned automatically. the variable mapTextureSzite obviously controls the size of your minimap in pixels.

 using UnityEngine;
 using System.Collections;
 
 public class MiniMap : MonoBehaviour {
 
     public RenderTexture renderTexture;
     public Material material;
 
     public FilterMode filterMode = FilterMode.Point;
 
     public Camera miniMapCamera;
         public Vector2 mapTextureSize = new Vector2(256,256);
 
     void Start() {
 
         renderTexture = new RenderTexture(mapTextureSize.x,mapTextureSize.y,16);
         miniMapCamera.targetTexture = renderTexture;
         
         renderTexture.filterMode = filterMode;
 
          }
 
 
     void OnGUI() {
 
         GUI.depth = 4;
 
         if(miniMapCamera.enabled == true) {
 
             if(Event.current.type == EventType.Repaint) {
                 Graphics.DrawTexture(new Rect(Screen.width - mapTextureSize.x, Screen.height - mapTextureSize.y, mapTextureSize.x, mapTextureSize.y), renderTexture, material);
             }
         }
 
 
     }
 
 }
 


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 14ercooper · Aug 14, 2015 at 07:06 PM 0
Share

Thank you, this worked!

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

26 People are following this question.

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

Related Questions

Improving the look of Unique/User Planned Scenes 0 Answers

3D model not affected by darkness? 2 Answers

HUD animation with game in background 0 Answers

is it possible to have raycasts to cover the whole screen in one Update() time? 0 Answers

How can i make the camera look up and down through keyboard keys? 2 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