Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 LeWyRaWr · Nov 18, 2013 at 12:09 AM · camerarenderingrendersplitscreencull

Rendering players per camera

Hey guys, I'm hoping you can solve this one for me, as It's giving me quite a headache!

I'm working on a multiplayer game, but it also has splitscreen. Rendering the players for the network players is fine, as you don't have to draw the first person weapon, legs, etc.

Here's where the problem is. For the split screen players, you not only have the player model, but the weapon too. What I've tried doing already is getting the separate list of renderers of the first person weapon, and the first person camera, and tried to force the camera to not render it, but that doesn't seem to work.

Here's the issue I have in more of a visual form: alt text

The green is what I want the other splitscreen players to see in their camera (so basically, just the other split screen players body, not their weapon). The red is what I want the splitscreen players to see only in their camera (their own fps weapon).

I tried using 1 layer called invisible which I add the renderers to a list where the layer is changed OnPreCull(), but to no avail.

I hope you guys can solve my issue here!

Comment
Add comment · Show 1
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 LeWyRaWr · Nov 18, 2013 at 01:42 PM 0
Share

Okay guys, I managed to answer my own question!

What you need to do is get the index of your player number (for instance, player 1 is index 0, player 2 is index 1, etc).

Then you make two Hide0, Hide1, layers or how many layers you want for the amount of players you can have.

Also, make layers for Show0, Show1, etc.

Now here comes the tricky part. You have a script on your camera with a function that adds the culling layermask to the ones you DONT want to be shown:

 public int HideLayer;
 public int ShowLayer;

 public void SetCullLayer(int playerindex)
 {
     // Sets the culling mask
     camera.culling$$anonymous$$ask &= ~(1 << Layer$$anonymous$$ask.NameToLayer("Hide" + playerindex));
     // Hides all other show layers. Change 3 to whatever number you want for the layers
     for (c = 0; c < 3; c++)
     {
         if (c != playerindex)
         camera.culling$$anonymous$$ask &= ~(1 << Layer$$anonymous$$ask.NameToLayer("Show" + c));
     }
     // Sets the layers
     ShowLayer = Layer$$anonymous$$ask.NameToLayer("Show" + playerindex);
     HideLayer = Layer$$anonymous$$ask.NameToLayer("Hide" + playerindex);
 }

So all of player 1's third person meshes (that they dont want to see) are now added to the Hide0 layer. So now Player 1 can't see their third person body!

Now all thats left is hiding the first person weapon from the OTHER players:

All you do is check to see if your layer SHOULD be shown, like so:

     // Hides all other show layers
     for (c = 0; c < 3; c++)
     {
         if (c != playerindex)
         camera.culling$$anonymous$$ask &= ~(1 << Layer$$anonymous$$ask.NameToLayer("Show" + c));
     }

And then finally you call the OnPreCull to do all the layer setting:

 void OnPreCull()
 {
     for (o = 0; o < Hide$$anonymous$$eshes.Count; o++)
             Hide$$anonymous$$eshes[o].layer = HideLayer;
     for (f = 0; f < Show$$anonymous$$eshes.Count; f++)
             Show$$anonymous$$eshes[f].layer = ShowLayer;
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by BerggreenDK · Nov 18, 2013 at 12:13 AM

I would use 2 different cameras, placed two different places and then let the camera output cover half of the screen.

I have used multiple cameras before as HUD effects, rendering some different part of the stage/scene where I had the scores, pickup objects etc. Worked fine. You can render without background too, if you need the dashboard to be transparent. But in your case I would setup two different cameras, vertical or horisontal beside each other.

Once you have two cameras, its even more simple to draw the contents, isnt it?

For each camera, you can also specify a culling mask. If you place the "dont show this in camera 1" objects in a seperate mask and the "dont show this in camera 2" objects in another. It seems quite easy to me.

let me know if this works for you.

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 LeWyRaWr · Nov 18, 2013 at 02:15 AM 0
Share

If I use more than one camera, then I won't be able to preserve the shadowing on the weapons. I'd also like to keep the game as tuned for performance as possible. Having 2 cameras per player, with the ability to have 4 players at once = 8 cameras potentially. Ouch.

I'm sure there's a way you can do it using Unity's culling system, I just think I'm going about it the wrong way.

I'd definitely like to not go the standard '2 Camera' way though, as there's loss in shadow quality and performance.

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

18 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

Related Questions

How do I render only a part of the cameras view? 2 Answers

Render group of objects in front? 0 Answers

Can two cameras render at different speeds? 1 Answer

How do I force my cameras to render in a certain order in URP? 1 Answer

Camera with shader? 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