Adjusting the Fog of War Vision Grid for a rotated plane (and rotated camera) #104
Replies: 9 comments 15 replies
-
Hello! I have some questions for you:
|
Beta Was this translation helpful? Give feedback.
-
Hi!! Thank you so much for such a prompt reply.
|
Beta Was this translation helpful? Give feedback.
-
You might try this quick hack: Currently, in the FoW shader, for each rendered pixel, its tile position is computed so that we can compute the fog value. To compute this tile position, I use a view projection matrix of the current camera. There are these two lines of code in the
As you can see, I use
Note that one |
Beta Was this translation helpful? Give feedback.
-
After changing that line of code to However, if I used my desired 45 degrees, it is still black like so: |
Beta Was this translation helpful? Give feedback.
-
I believe you're right, I just need to find the correct relationship here. While I still haven't figured out how to combine that, I did at least figure out how to incorporate my custom projection matrix (I use an oblique projection matrix). Before, if I had my custom projection matrix enabled, I wasn't able to find the red overlay anywhere. However, after making this change in the Before:
After:
|
Beta Was this translation helpful? Give feedback.
-
Looking into the offset a bit more, I discovered that even if I brute force figure out the "correct" FoW-Test.mp4 |
Beta Was this translation helpful? Give feedback.
-
I think that this repository https://github.com/chriscummings100/worldspaceposteffect might be worth looking into. There's a slightly different approach to computing world coordinates in image effects so maybe it works even with this camera rotation. I probably won't be able to try that right now but I should have some time in 1-3 days. |
Beta Was this translation helpful? Give feedback.
-
I've got some news. It seems like tilemaps (or maybe all 2D objects?) are not "recorder" to the depth texture which is used when converting screen coordinates to world coordinates. You can see that in the video below. The checkerboard texture should be aligned with the tilemap but it desyncs as soon as you start rotating the camera. without_plane.mp4BUT if I add a 3D plane to the scene which is aligned with the tilemap, the screen to world conversion starts working again. with_plane.mp4Now there's this obvious problem that you probably don't want to have a 3D plane in your scene.. But I think it's progress.l The bad news is that I'm very new to shaders too so I don't really know how to utilize this information to get a fully working solution. What you can at least do is try this setup in your game. Add this additional 3D plane to your scene, align it with your tilemaps and see if it works. |
Beta Was this translation helpful? Give feedback.
-
Excellent find, that may indeed be true. I'm trying to do a bit more research myself about tilemaps + depth textures. As for your example showcasing with/without the plane, it looks like you've pulled down that other project right? Is there a special material on the plane? I'm trying to replicate your findings with your FogOfWar example scene with just a simple plane object, but I'm having no luck. See the video below: FoW-WithPlane_FogOfWarExampleScene.mp4 |
Beta Was this translation helpful? Give feedback.
-
Hi there!
First off, I wanted to say fantastic job with this asset. I was a very early adopter and purchased this during your first release, but only recently have started to integrate it into my project.
Now a little bit about my current issue:
Context:
My game world uses a grid that exists on the X - Z plane (instead of the traditional X - Y plane for most 2D games).
Furthermore, my orthographic camera is facing this plane at a 45 degree rotation around the x axis like so:
Long story short, I do this in order to create a "2.5"d perspective that allows sprite objects tilted at 45 degrees easily sort in front of each other like a 3d game would. This is a very similar approach to what games like Enter the Gungeon do. Furthermore, I'm actually manipulating the projection matrix inorder to force an oblique projection so that I can get around any vertical distortion (though we can ignore the projection matrix alteration for now).
I'm trying to get your Fog of War functionality to work for this set up.
Problem
From what I understand, the logic behind the fog of war works like so: each tile of the grid is tracked along with its fade/visibility value. That grid is then translated to a texture which is then blit on the camera.
Now this works perfectly fine assuming the game world grid is on the X - Y plane. However, as mentioned above, my game world grid lays on the X - Z plane.
My highschool math lessons are failing me here, and I'm having trouble understanding how I have to manipulate the FogOfWarVisionGrid in order to account for my set up. My best attempt so far is trying to manipulate the X Y values within the
GetVisionTextures
method of theFogOfWarVisionGrid
script, but I can't seem to get it right.Any help/guidance would be greatly appreciated :) That said, I totally recognize this is beyond the scope of what your tool is made for (traditional 2d games).
Beta Was this translation helpful? Give feedback.
All reactions