Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by SVTiare-Tom · Mar 31, 2016 at 09:58 AM · 2dshadermaskshaderlabstencil

What is the best approach to mask players vision?

I am making a top down shooter, where players have a limited viewing angle. Now I have a dynamic lighting system down pat, however I've run into issues with hiding anything that is NOT in your vision cone.

Now the guys at Monaco posted their approach for their sexy lighting and vision, and was wondering how this could be done in Unity? They mention stencil and stencil buffers, and inverse stencil, but as someone who has never touched shaders before, it quickly goes over my head.

Monaco Game: https://www.facebook.com/notes/monaco/vector-lighting-explained/395139091995/

What would be the best approach? Would learning ShaderLab (through the Unity Manual) teach me what is required to pull of something like this?

Any tips, tutorials, or guides are appreciated!

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 Eudaimonium · Mar 31, 2016 at 10:36 AM

What exactly do you wish to hide from view cone? Only enemies and some objects, or everything and just leave it black?

If it's just objects, consider implementing a large cone-like collider as a child of your Player object, which is set as Trigger. Anything it touches should fade in the view, and anything not touching it should fade out. You can implement a Hidable interface and extend enemy and object scripts from that, and have the collider cone search for that script in collided game objects.

If you wish to hide everything, you can simply only have one lightsource which is the player, leaving everything else dark. Or if you've already lighted up and lightbaked your scenes, consider simply using a screen-wide HUD sprite with cone-like cutout, rotating on the screen mimicking the player's rotation in the game world.

However as a fellow gamer, I would strongly urge you to re-consider a design decision which makes 80% of my screen useless. Why hide anything not in view cone? Is this really necessary for the mechanics and atmosphere of your game? There have been countless top-down shooters without this mechanic which are working fine. There have also been quite a few with this mechanic that I disliked specifically because of it.

Comment
Add comment · Show 5 · 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 SVTiare-Tom · Mar 31, 2016 at 12:34 PM 0
Share

The game I am making is very much like Door $$anonymous$$ickers, slow and tactical, and not showing players who are around or behind walls is very important. This means that Static Objects are always rendered, but Players are only visible when inside you vision cone.

All I want to know is if it is possible to create a shader that does something like what $$anonymous$$onaco here has done.

Though your cone trigger method is a very interesting idea!

avatar image Eudaimonium SVTiare-Tom · Mar 31, 2016 at 01:01 PM 0
Share

Oh you mean something more like XCO$$anonymous$$? Got it.

In that case, one solution I can think of is to do a Raycast from the player, to all enemies. If the raycast makes it (returns an enemy object) - it's visible, if not, you need to hide the enemy.

As to shaders, I believe you may want to just write a custom shader that will draw enemies with transparency control, so that you can fade in/out enemies when you transition between visible and invisible states, but it's not necessary.

avatar image SVTiare-Tom Eudaimonium · Mar 31, 2016 at 11:41 PM 0
Share

So is it not possible to create a mask from a players vision cone via shaders?

draw vision cone > create a mask > render visible object > mask that > render everything else > combine them?

Though raycasting sounds like an easier approach, there would be issues like if a player was half visible, the raycast approach would show his whole body.

Show more comments
avatar image SVTiare-Tom · Apr 02, 2016 at 11:02 PM 0
Share

Ah, I meant fullscreen shaders, sorry about that. I think I will go with your approach however, as it seems the most logical for a game mechanic! Thanks for sticking with my stubborn thoughts on shaders and what not :P

Thank you for answers!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a shader ignore masks 0 Answers

Inverse Sprite Maskin 0 Answers

Shadowcaster Fragment Shader Discard 0 Answers

Customizing a URP Shader to understand masks 1 Answer

Trying to write a 2d mask shader with stencil 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