• 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 Rukas90 · Oct 15, 2018 at 04:58 PM · performancertsfog-of-warcheap

Cheap way in making Fog of War

Hello,
I'm working on an RTS game and I am trying to implement Fog of war. In my game there will be lots of units and buildings.

I know that fog of war and easily become really heavy. Especially when there's lot's of units / building in the game. What is the cheapest way in making fog of war?
I don't need anything necessarily fancy as well.

I'm pretty sure that I need to write shaders to achieve that, the problem is that I am not so good with shaders. As a matter of fact I'm quite terrible..

Can someone give some advice on this?
Thank you

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

Answer by Pangamini · Oct 16, 2018 at 08:47 AM

There are definitely more solutions, and perhaps different requirements. For example, you may want a simple RTS-like FoW where a simple circular area is revealed around each unit, or you may want to have some line of sight obstruction , or even take the heightof the scene into consideration.

For me, the usual solution is: Generate a renderTexture that represents the whole level (well, only works for a finite-size levels, up to some size of course). Then you can render your unit's visible area into this texture. You can do that simply by rendering a circle mesh, a quad with a circle texture, or some more advanced technique for line of sight and height - which may be suitable for a shader, but may also be done on CPU, ideally on a separate worker thread.

Make sure the process does not halt your game, by threading or at least coroutines (split rendering between frames)

After you have this world overlaying texture, it's time to project it on the world. One obvious solution is to have every shader in the game to sample this texture in world space and darken itself accordingly, but that's not very practical. Instead, I suggest you take this texture and project it on a rendered scene (as a camera image effect / postprocessing) using the camera's depth texture.

An extra trick would be to render one channel (eg. red) as currently visible, and other channel (eg. green) as previously visited / seen areas.

The challenge I found when using the CPU method is the time it takes to upload the new texture content to the GPU (which blocks the main unity thread), so if you can, make everything work on the GPU entirely.

Now, you say you don't have any experience with the shaders. Well perhaps it's time to get some :) Here you'd be working with simple (not lit) single pass shaders only.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

110 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

More than 20 instances of a certain script cause fps to skyrocket, is there something I'm doing wrong here? 0 Answers

What`s more expensive GUI Texures or Quads for displaying units health?(RTS) 1 Answer

Performance - is raycasting for ground on Update() optimal? 1 Answer

Whats the most efficient method for placing UI elements at world positions? (Above units etc.) 2 Answers

Whats an efficient method for drawing hundreds of Health Bars etc. over units for an RTS? 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