Author Topic: Tasharen Fog of War  (Read 65991 times)

maesla

  • Guest
Fog move wrongly with orthographic camera
« Reply #30 on: September 23, 2013, 06:29:30 AM »
Hello.

I'm having problem with the fow. When I move the camera with perspective camera, everything works fine. But if I change to orthographic camera, the fog move with the camera, and it is not anchored to the entities as it should be.

It is very important to fix that. Any idea?

Thanks a lot.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #31 on: September 23, 2013, 06:45:49 AM »
Can't say I've ever tried using it with an orthographic camera, so off the top of my head I can't tell you what's wrong. Can you post a pic of your game and what you're trying to do?

maesla

  • Guest
Re: Tasharen Fog of War
« Reply #32 on: September 23, 2013, 07:45:45 AM »
I have more details.

I have two effects attached to the camera. Fow and the highlighting system (http://forum.unity3d.com/threads/143043-Highlighting-System-Released). When I deactivate the highlighting system, the fow works fine, but when I active it, the fow grows and it move with the camera. All of this is in orthographic camera, in perspective works fine.

Both effects have OnRenderImage and it is there where the problem is. I am going to mail to the highlighting system author aswell to see if we can find a solution between all of us.

Do you need more details? I am going to ask him If I can send you the highlighting system effect code.

Thank you


Edit:
I have exactly the line
  1. public class HighlightingEffect : MonoBehaviour
  2. {
  3. ...
  4. private int layerMask = (1 << HighlightableObject.highlightingLayer);
  5.  
  6. ...
  7.  
  8. void OnPreRender()
  9. {
  10. ...
  11. shaderCamera.cullingMask = layerMask; //If I comment this line, the problem is fixed but the highlighting system do not work
  12. ...
  13. shaderCamera.Render();
  14. }
  15.  
« Last Edit: September 23, 2013, 08:01:14 AM by maesla »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #33 on: September 23, 2013, 08:16:49 AM »
Does he ever change the cullingMask back after drawing with that camera? What is shaderCamera? Make sure the shader camera doesn't draw the fog of war. Fog of war should happen after everything else.

maesla

  • Guest
Re: Tasharen Fog of War
« Reply #34 on: September 23, 2013, 09:11:56 AM »
It is the fog camera and the culling mask is never restored. The weird things is that only happens with orthographic camera. I am going to ask with the author of the other plugin

jchowdown

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Tasharen Fog of War
« Reply #35 on: October 22, 2013, 09:05:46 PM »
Hi, I've been using FOW in my game for a few weeks and I've been thinking about some optimizations:

1) my units are stationary most of the time. I was thinking about leaving their LOSChecks value as OnlyOnce while they're standing still, and only set it to EveryUpdate while they're actually moving. Is it safe to set this on my revealer in the main thread? I think this would be a huge optimization.

2) As a test, I took my running game and for one FOWRevealer instance, I set the LOSChecks value to OnlyOnce in Unity's inspector. I immediately got an out of bounds crash here (in RevealIntoCache): http://screencast.com/t/Bt4ivGYfb5
The size of the buffer is 41616 ( or 204*204 as determined by xmax - ymin) but the range given by ymax-ymin is actually 205. The actually array index into r.cachedBuffer is 41709. I believe this is a rounding error in this code: http://screencast.com/t/VnJMUXDFaMjQ.
One artificial way of fixing this is to set ymax be exactly ymin + ( xmax - xmin ). What do you think?

3) In RevealUsingLOS and RevealUsingRadius, there is a two-level nested for() loop that performs a check that x and y are within the bounds of the texture size. Can't those checks be pulled out of the for() loops for optimization? What if we clamped ymin,ymax,xmin,xmax like this? http://screencast.com/t/u5rqTvDm

Thanks in advance,
jeff

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #36 on: October 25, 2013, 01:22:42 AM »
1. Seems logical, yes.

2. I don't get this one. There is a check that only executes the code if the sx and sy are within 0 to (textureSize-1) bounds, which means that it won't execute with a dimension of 255. How are you getting to that?

3. Seems fine to me.

Chaosgod_Espér

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Tasharen Fog of War
« Reply #37 on: October 25, 2013, 02:53:38 AM »
I´ve some questions too.

1st:)
I´m creating a Dungeon Keeper like Game - means a RTS. So there are up to 115 Objects that can reveal the FoW. And the revealed parts need to stay revealed.
Is that possible and (more important) fast with Your FoW?


2nd:)
Is there any way to animate the Edges of the fog, to give it a Fog-Look?
« Last Edit: October 25, 2013, 04:30:20 AM by Chaosgod_Espér »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #38 on: October 26, 2013, 07:57:38 PM »
1. To have revealed parts stay revealed just change the "explored" color to match the "visible" color. The more moving revealers you have the slower the performance will be (obviously). Using non-moving revealers will speed it up.

2. Civ 5 style? Sure. FoW generates a texture to you, but how you display it is up to you. Write a shader to display clouds in the areas marked by the fog if you wish.

frarees

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Tasharen Fog of War
« Reply #39 on: October 27, 2013, 01:49:53 PM »
I'm trying to use the FoW for a tile based game, so I need it to be really precise. I've modded it a little to allow point filtering mode, and adjusted texture size to fit tile size. All the objects are snapped to a 2 unity units size grid (the revealer too). See attached image to see current result.

However, I don't see the line of sight being coherent. Am I missing some setting? If not, how could I edit the algorithm (probably the RevealUsingLOS method) to improve it and fit?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #40 on: October 27, 2013, 10:33:31 PM »
To be honest I've never tried using FoW with such large pixels. Whether areas are visible or not are determined by performing height difference checks from revealers to surrounding pixels The algorithm is pretty straightforward as you can see by looking at the code -- but since it's not done using raycasts, it may not give you the expected results in your case.

rsharr

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Tasharen Fog of War
« Reply #41 on: December 02, 2013, 05:59:36 PM »
Is it possible to have multiple "fog of war" prefabs that work with each other?

I have very large terrain tiles and want to attach the fog of war to each tile. 

I attempted this and the fog of war works on the very first tile but as soon as I get to the second tile and the fog system is called, the entire screen turns in to the "explored" state.

Thanks


--edit

I guess whats happening is under the render image it is finding the first object of type and not updating to the new system. Would I accomplish this through a collider and having it trigger to find the correct fog system?

--edit

nevermind, I have no idea what I am doing as far as editing these scripts to find a solution.

Basics of what I want:

I have a tile system, each tile is large compared to the player.
I have the fog system working on one tile.
I want to be able to walk across one tile to another and activate that specific tile's fog system instead of the previous.

having one system on any given tile works just fine, its just when I get 2 or more systems is when it starts acting wonky. I am guessing because this fog system was never designed for this setup and is getting confused as to which system to render to camera. Is there a solution to this that you can think of? Thanks again.
« Last Edit: December 02, 2013, 07:05:00 PM by rsharr »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #42 on: December 03, 2013, 10:42:12 AM »
The fog of war system was designed with only one set of textures to sample in the post-processing shader. Multiple FOW systems mean multiple textures, so it won't work.

rsharr

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Tasharen Fog of War
« Reply #43 on: December 03, 2013, 11:02:26 AM »
Can you think of a way that I can flush the texture "cache" and update to the new fog system upon entering an area? I am not concerned with the fog system remembering where I explored and not, as my explored / unexplored colors are the same. Thanks

edit-

Im not asking you to do it, but rather asking if you think its possible with your system
« Last Edit: December 03, 2013, 11:07:37 AM by rsharr »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #44 on: December 03, 2013, 09:07:02 PM »
You can enable the correct FOW system and/or set the right textures inside a script attached to the object(s) you are trying to draw. Add a OnWillRenderObject function to a script and do it inside. You will also want to create custom shaders that sample the FOW texture inside rather than doing it via the post-process step.