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
4
Question by e-bonneville · Apr 08, 2010 at 09:23 PM · rtsfog-of-war

How would I do fog of war?

Hi, I've reached an impasse in my game development. I know this has been asked many times before, but I just can't seem to figure out how to create fog of war for an RTS game. I've seen many solutions, and one in particular struck me as being doable. That one is modifying the visibility of portions of a mesh depending on a units position relative to it. An idea I had is modifying the visibility of the terrain, and then just using another script (one that I can easily write) to make visible other gameobjects if the unit is in range. Both seem like good ideas, but I've got no idea on how to implement them. That's where you come in... Thanks in advance!

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

3 Replies

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

Answer by Peter G · Apr 08, 2010 at 10:35 PM

The best idea I have seen is to place plane between your terrain and your camera then raycast from your player upwards into the plane. After that you find the point your raycast hit and lighten that area's vertices.

Here's a forum link with several scripts and examples.Unity Forum/ Fog of War

My only recommendation is to keep the vertex count as low as possible. Fog of war scripts usually require iterating through arrays of mesh colors (or pixels) nearly every frame.

Another idea is to use a texture and change the alpha of pixels instead of vertices. It would work very similarly to the mesh transparency idea.

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 e-bonneville · Apr 08, 2010 at 10:45 PM 0
Share

That leaves me at a loss because I still don't know how to change specific vertices of a mesh. Could you explain that?

avatar image Peter G · Apr 09, 2010 at 01:20 AM 0
Share

The scripting guide does a good job explaining the mesh scripting interface so read that first to understand the concepts behind procedurally modifying the mesh. Then the link does a good job explaining how to modify the color. Basically you iterate through the mesh and change the alpha of the vertices to either 1 or 0 and that makes it transparent or opaque.

avatar image e-bonneville · Apr 09, 2010 at 11:50 AM 0
Share

Actually, I guess my real question is 'how do I find which vertices are closest to me?' I know I have to raycast up, but how do I find which vertices are hit when I raycast?

avatar image Peter G · Apr 09, 2010 at 10:28 PM 0
Share

There are two ways I can think of. Find the triangle index of the mesh and find those vertices (it is as simple as the index * 3 + 0, 1, and 2 for each vertex respectively. That way involves less iterating, but only gives you a small clear area unless your triangles are very large. The other option is to gather all the vertices in the mesh and every time you update your raycast, iterate through the mesh vertices (if you don't know how to do that see the reference) and find the distance between the hit point and the vertex. You will have to use InverseTransformPoint to get the world space.

avatar image Peter G · Apr 09, 2010 at 10:29 PM 0
Share

cont. Then if the distance is under a certain radius, you turn it clear.

avatar image
3

Answer by risk01101 · May 23, 2014 at 10:31 AM

Here is my system:

1) Edit->Render Settings - Enable FOG - Fog Mode Exp2 - Fog Densiti: 0.001 - Ambient Light: RGB(28,28,28) 2) Remove all light in your map 3) Place Point Light inside your character:

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 fahimalavi · Sep 12, 2016 at 04:20 PM 0
Share

Will several lights in screen will add problem like 200 spot lights ?

avatar image
1

Answer by trileletri · Nov 02, 2011 at 03:12 PM

I once made a fog of war. It was really simple once it was made. However i can't locate the files to send you some code, but i remember the algorithm:

  1. lay a plane above the ground

  2. make black generic texture, let's say 512x512

  3. locate certain pixels on texture (the ones which will represent a point from terrain, location of a real time strategy vehicle unit, for example)

  4. using given pixel coordinates, draw a white circle around it on texture (radius is sight range)

  5. for better looks, use blur shader on texture, to smooth "teeth" on texture

  6. apply texture to plane

  7. repeat each 10 frames, or tweak this until you're happy

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 Yxven · Sep 22, 2014 at 10:40 PM 0
Share

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

RTS fog of war texture remapping shader,Fog of war plane texture remapping shader HDRP 0 Answers

Lighting Light Increase 1 Answer

Cheap way in making Fog of War 1 Answer

Multi-Unit Fog Of War for Mobile 2 Answers

RTS Style Camera Scrolling 8 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