I have a problem with the FogFilter, which i was wondering if anyone has a solution to.
I’m working on a multiplayer voxel game and tried adding fog to it, but the default jME3 shader doesn’t work as i’d like it to - it appears to draw fog in the distance based on the distance from the camera plane.
This means that you are able to see more of the game world around the sides of the screen compared to the middle, which is not optimal (players could “peek” and see further than they should be able to by rotating the camera).
See these screenshots for a description of the problem:
I was hoping that someone could provide me with an alternative shader that uses the distance from the camera itself (as described here: Create a fog shader, under “Getting the distance: Z-Depth vs Length”), because i tried solving the problem myself for the majority of the past 3 days unsuccessfully.
It should be a simple fix, but i cannot wrap my head around GLSL.
For reference (and convenience), here’s an archive of the default shaders: Dropbox link
files taken from: jME3-effects.jar/Common/MatDefs/Post/
contained within are:
In addition, here’s the (seemingly) relevant code inside of Fog15.frag
Your best (and probably most efficient also by the way) option would be to incorporate fog into your actual shaders. It only takes a few lines added to the end and you can calculate distance however you want.
Edit: note it also gives you the ability to turn off fog for some objects (like lights if you use the fog for night-time darkness, for example).
Bottom line, i can’t do it myself and have no idea where to start, therefore i decided to ask the community before giving up. I’m not really concerned about how it looks, i just need to make the limited rendering distance. That is all.
Tried making the changes you suggested by copying the files, changing the filenames (and fixing the paths), as well as creating a new .java file that extends FogFilter.java to set the proper fog start and end values so they don’t have to be hardcoded.
Got the following error when i tried to launch the game:
At first, you should make changes not to post but to Lightning (or your object’s shader). At second, it is just a pattern and it would be good for you to learn shaders a bit. Because in my case it is not the same for every shader. Just similar. https://drive.google.com/open?id=0B1tgYi3V4RzsSmlfMlhnY0gxY1E
Biting the bullet and learning basic shaders is probably worth the time. Even if you don’t write your own in the end. It gives you are really good idea on what works, what is easy, and what will really use up all the fillrate.
In this case, this type of fog was is very similar to fix pipeline functionally in days of old. So a fairly easy one to add. At least in the bigger scheme of things. And then you can even contribute!
Some shaders i am considering adding to jME. Screen Space Reflections, Finite distance IBL (this is very experimental, but lots of fun, i even get to do math!), Planner Reflectors if that doesn’t work out, however jME sort of already has this with some of its water shaders.