Page 1 of 13

[patch] new fog shader

Posted: 24 May 2015, 21:21
by visvaldas
Edit: Port to OSG version: viewtopic.php?f=6&t=2905&start=20#p38328
Edit: newest version: https://gitlab.com/vrresto/openmw/tree/ ... er-cleanup

----------------------------------------

Hi !

This comes probably a bit late with the port to OSG taking place now - anyway here it is. :-)
Probably some of it can be used/ported.

This patch adds a more realistic looking fog shader where the fog density decreases with increasing altitude.

Some screenshots:
screenshot123.jpg
screenshot153.jpg
screenshot135.jpg
Feel free to ask questions, but please not about the mathematical basis of the calculations - this was mostly guesswork + try & error. :mrgreen:

Edit: add patch against 0.36.0 and patchless version

For this to look good you also need to set "distant land = true" and "viewing distance" to a high value (e.g. 500000 for 5km) in settings.cfg.

Patchless version:
Extract this into your resources/materials folder - apparently the location of this can vary.
jirka642 wrote: On my Linux PC is correct folder located in /usr/share/games/openmw/resources/materials/ , but it can be at the same place as your openmw executable depending on how you installed openmw.
You also may need to empty your openmw cache directory (~/.cache/openmw on my system) for the changes to take effect.
Since this version takes no density parameter from the engine you have to manually edit the parameters at the beginning of fog.h to change the density etc.

Re: [patch] new fog shader

Posted: 24 May 2015, 23:02
by scrawl
Looks great. Is that Mountainous Red Mountain in the background?

Ideally, this kind of modification wouldn't require C++ code. I'm thinking post-1.0 we should offer a way for modders to define new weather settings, and pass the current values to a modified shader, all without engine changes.

Re: [patch] new fog shader

Posted: 24 May 2015, 23:02
by psi29a
That's pretty nifty! :D

Re: [patch] new fog shader

Posted: 24 May 2015, 23:40
by visvaldas
Thanks :)
@scrawl: Yep - thats Red Mountain.
Actually I programmed this a while ago (yes I could have submitted this much earlier :oops: ), so my memory of why I did what is already a bit rusty.
The C++ is at least partially to improve performace: some values only need to be calculated once when the fog parameters change, also some arithmetic operations might be impossible/to expensive on shader units (not sure about this - I'm not an experienced shader programmer).

Re: [patch] new fog shader

Posted: 25 May 2015, 00:18
by scrawl
@scrawl: Yep - thats Red Mountain.
Yeah, I was just wondering if that's vanilla or modded. If it's vanilla, then that fog sure does make the mountain seem a lot higher than usual :)

Re: [patch] new fog shader

Posted: 25 May 2015, 06:36
by raevol
That's so gorgeous... will we see this in OpenMW?

Re: [patch] new fog shader

Posted: 25 May 2015, 08:16
by Chris
Hopefully it can be configurable, probably as an added weather property. As pretty as it can look, low-lying fog isn't a constant thing. It's generally caused by warm ground meeting the cold air, and vice versa, creating condensation and mist. The time of day (mornings and evenings are more likely to have it) and season (summer and winter are less likely to have it) also plays a part.

Re: [patch] new fog shader

Posted: 25 May 2015, 10:48
by Okulo
Oof! That is beautiful! Please, please make this work well and add this to the main branch. I think we haven't seen eye-candy like that since Scrawl's Shiny shader.

Re: [patch] new fog shader

Posted: 25 May 2015, 10:53
by Cramal
If you can make configurable decrease/increase with altitude (even if its not through in game menu) i think it would open a lot of cool possibilities

Re: [patch] new fog shader

Posted: 25 May 2015, 16:07
by visvaldas
scrawl wrote:
@scrawl: Yep - thats Red Mountain.
Yeah, I was just wondering if that's vanilla or modded. If it's vanilla, then that fog sure does make the mountain seem a lot higher than usual :)
It's vanilla :)
Chris wrote:Hopefully it can be configurable, probably as an added weather property. As pretty as it can look, low-lying fog isn't a constant thing. It's generally caused by warm ground meeting the cold air, and vice versa, creating condensation and mist. The time of day (mornings and evenings are more likely to have it) and season (summer and winter are less likely to have it) also plays a part.
I've thought of local variations too, but unfortunately the way the shader works this is impossible. Global variation depending on time of day is possible of course.
Currently all parameters are derived from a a single density parameter (ground fog only starts to appear above a certain density) - have a look at Fog.cpp/.h. This could theoretically be fine-tuned by the weather manager.
Okulo wrote:Oof! That is beautiful! Please, please make this work well and add this to the main branch. I think we haven't seen eye-candy like that since Scrawl's Shiny shader.
Well, unfortunately I'm unsure whether I have time for this in the near future. But it probably depends on how much work is required to port this to whatever shader system OSG uses. As I'm a shader newbie I probably could use some help there.