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 /
avatar image
0
Question by Maxter · May 10, 2017 at 02:10 PM · 2dshaderstopdownfov

2D top-down field of view visualization

I have a 2d top-down map in a big sprite texture. I want to make all of the map grayscale except the part that is in a field of view (I'm calculating FoV polygon every frame).

As far as I understand, it can be done with shaders, but I have no experience with shaders. I have started reading about them but they are so out of this world that I'm pretty confused on how to do what I need.

I saw this tutorial: https://www.youtube.com/watch?v=xkcCWqifT9M but as far as I understand stencil buffer will not help with my task as it either renders stuff or it doesn't. I will probably use the stencil solution for hiding important objects on the map, but player should see the map itself.

It is pretty clear how to make the whole object grayscale, but how to make only part of it grayscale?

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
0
Best Answer

Answer by Maxter · May 12, 2017 at 12:15 PM

I solved my problem the following way:

  1. I generated grayscale map sprite and positioned both map sprites at the same Z level;

  2. I've implemented the stencil solution from the tutorial I linked in the first post, to show the colored version of the map; Stencil code for the colored map:

     Stencil {
         Ref 1
         Comp equal
     }
    
  3. I've added a new shader to the grayscale map:

     Stencil {
         Ref 1
         Comp NotEqual
     }
    

That way I see the colored map under the mask (field of view area) and grayscale map everywhere else. Exactly what I needed.

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 Masea1 · May 02, 2020 at 02:22 PM 0
Share

But this way, don't you have to edit two maps always? I am using Tilemaps and sadly, you cannot choose more than one active tilemap to work on multiple tilemaps at the same time... So whenever I want to change something on my map, I will also have to change it on the grayscaled map.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Disable angular shadow recieving in 2D? 0 Answers

How do I only show parts of objects that overlap [2D] 1 Answer

2D Top down shooter, gun is shaking while moving and Cursor solutions 0 Answers

Hiding a sprite partially (shader? masking?) 0 Answers

Touch Buttons 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