Page 1 of 2

Volumetric Ground Clouds

Posted: 16 Dec 2014, 23:03
by Anarchid
I've been posting some pictures of a fog shader for a while now, so it's time to actually let people have it.

Image
Image

This is a widget that draws volumetric ground clouds which scroll with the wind. That means, one of TA-derivative invisible economies can become very much visible!

It requires GLSL and won't work without. Being a widget means that if it is included in a map and then annoys some people, they can turn it off easily and without restarting the game.

Conceptually, it's a bastard child of jK's glsl ground fog in Blueprint's dual_fog widget, and this.

It is configurable in a map's mapinfo, like this:

Code: Select all

custom = {
		clouds = {
			speed = 1, -- multiplier for speed of scrolling with wind
			color    = {0.46, 0.32, 0.2}, -- diffuse color of the fog
                        -- all altitude values can be either absolute, in percent, or "auto"
			height   = "90%", -- opacity of fog above and at this altitude will be zero
                        bottom = 0, -- no fog below this altitude
			fade_alt = "70%"; -- fog will linearly fade away between this and "height", should be between height and bottom
			scale = 255, -- how large will the clouds be 
			opacity = 0.4, -- what it says
			clamp_to_map = true, -- whether fog volume is sliced to fit map, or spreads to horizon
			sun_penetration = 15, -- how much does the sun penetrate the fog
		},
}
An extra hidden parameter is your sun and its ground specularity color, which are used for fog highlights.

OBTAIN THUSLY

P.S. i've been thinking of putting it into Blueprint but i have failed to make it activate/deactivate based on mapOptions. Maybe i just used wrong case or something.

Re: Volumetric Ground Clouds

Posted: 17 Dec 2014, 00:19
by qray
Hmm, works on one system here but not on the other (test with Quagmire, Linux, Nvidia with prop. drivers, text. compr. off). I see a small change when switching widget on/off, but definetely not the clouds as on the working system (no error message in infolog). Can't spot the difference ATM.

But definetely a neat effect when it works 8)

Re: Volumetric Ground Clouds

Posted: 17 Dec 2014, 06:40
by Funkencool
Looks awesome :shock: makes me want to go back to some of the maps I abandoned :regret:

I don't know nearly as much about shaders as I should but I'm just curious.
Would it be possible to use the LOS texture as a mask to the texture used for noise?
If so, would it have a large impact on performance?

Re: Volumetric Ground Clouds

Posted: 17 Dec 2014, 12:42
by Anarchid
Some people have been having issues with previous version on Quagmire, but you should notice that the released version of that map has rather nasty settings for its standard Spring fog, which seems to cause things like completely gray units and in-world UI elements.

If you want to test it on Quag, you should download it and modify its mapinfo as follows:
atmosphere = {
minWind = 1.0,
maxWind = 4.0,

fogStart = 0.8,
fogEnd = 2.0,
fogColor = {0.0, 0.0, 0.0},

sunColor = {0.9, 0.9, 0.9},
skyColor = {0.45, 0.1, 0.6},
skyDir = {0.0, 0.0, -1.0},
skyBox = "",

cloudDensity = 0.8,
cloudColor = {0.85, 0.6, 0.8},
},

Also, for some people on linux+nvidia-proprietary, this would happen. I'm not sure if it happens on non-Quag maps.
Would it be possible to use the LOS texture as a mask to the texture used for noise?
It is possible and it should not be expensive. In fact, using the volume fog as "literal fog of war" has been suggested, but that would be a game shader thing and not a map shader thing.

I guess once/if the issues with this are sorted, i'll make a "literal fog of war" version :)

Additionally, this technique could possibly be extended to render smoke or explosions. That would, however, require one to basically engineer fourth dimensional functions for the rendered objects, something that returns the volume opacity (or even color) for a given point in space-time (x,y,z,t).
not on the other (test with Quagmire, Linux, Nvidia with prop. drivers, text. compr. off). I see a small change when switching widget on/off, but definetely not the clouds as on the working system (no error message in infolog). Can't spot the difference ATM.
Can you post your springsettings? Preferably all of them, that is:
1) ~/.spring/springsettings.txt
2) ~/.springrc
3) ~/.config/spring/springsettings.txt

I have some suspicions, let's see if that works.

Re: Volumetric Ground Clouds

Posted: 17 Dec 2014, 12:49
by gajop
Github it?

Re: Volumetric Ground Clouds

Posted: 17 Dec 2014, 14:48
by Anarchid
Dunno if it makes sense to github a single widget that would be better served as part of Blueprint. But since i already have it in a git repo, i'll do that anyway.

Re: Volumetric Ground Clouds

Posted: 17 Dec 2014, 14:56
by gajop
Still better than a .zip. If it's really one file you can use https://gist.github.com/
But seeing you also have instructions, maybe a real project?

Re: Volumetric Ground Clouds

Posted: 17 Dec 2014, 17:02
by jK
Anarchid wrote:Dunno if it makes sense to github a single widget that would be better served as part of Blueprint. But since i already have it in a git repo, i'll do that anyway.
Just fork blueprint?

Re: Volumetric Ground Clouds

Posted: 17 Dec 2014, 17:15
by smoth
why not add it? I mean once you get the chance to once over the code?

Re: Volumetric Ground Clouds

Posted: 17 Dec 2014, 17:19
by gajop
smoth wrote:why not add it? I mean once you get the chance to once over the code?
Thats how it gets added usually. Fork, commit and send pull requests

Re: Volumetric Ground Clouds

Posted: 18 Dec 2014, 00:03
by Anarchid
Here's the repository.

The reason i didn't add it to blueprint yet is that - as i've mentioned above - at some point i failed to make it activate/deactivate based on map options like the other things do in Blueprint.

jK seems to have given me a not very high grade for this homework and said he has fixes that more than double the performance (155fps ->320fps).

Re: Volumetric Ground Clouds

Posted: 18 Dec 2014, 01:07
by qray
Anarchid wrote: Can you post your springsettings? Preferably all of them, that is:
1) ~/.spring/springsettings.txt
2) ~/.springrc
3) ~/.config/spring/springsettings.txt

I have some suspicions, let's see if that works.
Attached to this post. I have only one settings file (payed very much attention to this after having some problems; and just checked it again).

Re: Volumetric Ground Clouds

Posted: 18 Dec 2014, 09:24
by PicassoCT
Actually the nuke is in production hell..

Code: Select all

//NUKE
#define NukeHeight 180

//COLUMN
#define ColumnRadiusMin 50
#define ColumnHeight(frame) 

//CIRCLCOLUM
#define CIRCLCOLUM_RAD(frame) 
#define CIRCLCOLUM_DIAMETER(frame) 

//CORIUM
#CoriumMax     160
#CoriumHeight(frame)
#CoriumDiameter(frame)
#CoriumYScalar(frame)

//ANIMATION
#define MaxFrame 1200

#define Stage_BlindingLight 0
#define Stage_Exploded 1
#define Stage_RisingUp 2
#define Stage_PunchingAirLayers 3;
#define Stage_Peak 4

void nuke(vec3 pos, int frame)
{

corium(vec3 pos,int frame);
outClouds(vec3 pos, int frame);

}

int partOfCubeApproximation(vec3 pos, vec3 dim, vec3 posInQuestion)
{
}

int within(int min, int val, int max)
{return min < val && val > max;}

int Stage(int frame)
{
if (within(0,frame,150)) return Stage_BlindingLight;
if (within(150,frame,300)) return Stage_Exploded;
if (within(301,frame,560)) return Stage_RisingUp;
if (within(561,frame,780)) return Stage_PunchingAirLayers;
if (within(781,frame,MaxFrame)) return Stage_Peak;

}

void randNom()
{
	return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

int coriumPos(frame)
{if (Stage(frame)== StageMax) 
	return NukeHeight+15;
 else
	return NukeHeight/MaxFrame* frame+15;	
}




//Explodes at start
void corium(vec3 pos,int frame)
{

int condition=Stage(frame);

switch (condition)
case Stage_BlindingLight: {break;}
case Stage_Exploded		: {break;}
case Stage_RisingUp		: {break;}
case Stage_PunchingAirLayers		: {break;}
case Stage_Peak		: {break;}
default: {break;}
};

vec3 colourGradientByCoriumDistance()
{
	
}

//how far out from the colum do the clouds move .. distance follows a streched upwards and squeezed sidewars x^2 - 
//scaled sidwards by time
void outClouds(vec3 pos, int frame)
{

};
What do i have to do with your shadder- to get something simple. Like SC2s drifting dust/sand?

Re: Volumetric Ground Clouds

Posted: 18 Dec 2014, 09:53
by Anarchid
Drifing sand is what it does by default, see the Red Comet screenshot.

With assistance from federation jK, the compression issue has also been fixed.

Re: Volumetric Ground Clouds

Posted: 18 Dec 2014, 10:42
by PicassoCT
Anarchid wrote:Drifing sand is what it does by default, see the Red Comet screenshot.

With assistance from federation jK, the compression issue has also been fixed.
It does this?
http://youtu.be/qZkcstuf2Fw?t=2m15s
Cant really check cause shadder-challenged grafics card on laptop.

Re: Volumetric Ground Clouds

Posted: 18 Dec 2014, 12:28
by Anarchid
Less pretty, but basically yes.

It doesn't bend with terrain (though it could easily enough), and it doesn't move dunes :)

The original reason for existence of this entire thing was that some people in ZK decided that our Featured maps need to be nicened up, and a whole "touch-up" project started. Its first target was Red Comet, and i somehow volunteered to make something to draw Martian dust storms.

I though it would take a week.

Re: Volumetric Ground Clouds

Posted: 18 Dec 2014, 14:08
by PicassoCT
who volunteered for the skybox?

Re: Volumetric Ground Clouds

Posted: 18 Dec 2014, 17:05
by Anarchid
Noone; is default.

Re: Volumetric Ground Clouds

Posted: 20 Dec 2014, 11:57
by jK
needs more pics!
Image

Re: Volumetric Ground Clouds

Posted: 20 Dec 2014, 14:04
by PicassoCT
Volumetric Fire

Code: Select all

vec3 savannahFire(vec3 pos, float groundHeight, int timeSinceSpotStartedBurning)
 {
vec3 returnVec= new Vec3(0,0,0);
if (timeSinceSpotStartedBurning <= 0) return returnVec;
 //smoke rises with temprature, which we will assume is doing a log curve from the start
float heat= log(timeSinceSpotStartedBurning+1)*600;
 //assuming that the smoke starts to pour out immediatly and cools over a distance of 300 meters
 // smoke rises 0.376 m/s
 float maxHeight= min(300,0.376*time);
 //our colourgradient stretches over the whole distance;
 float colourgrad={0.2; 0;3; 0.8;1;}
 float mygrad=pos.y/maxHeight;
 
 if (colourgrad[1] >=mygrad) return orangeFire(); 
 if (colourgrad[2] >=mygrad) return redGlowSmoke(); 
 if (colourgrad[3] >=mygrad) return blackThickSmoke(); 
 if (colourgrad[4] >=mygrad) return greySmoke(); 
 
 }
 
 void randNom()
{
	return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

 vec3 orangeFire()
 {
 return new Vec3(	mixAPair(randNom(),1,0.95),
					mixAPair(randNom(),0.6,0.9),
					0.2f);
 }
 
 vec3 redGlowSmoke()
 {
 return new Vec3(	mixAPair(randNom(),1,0.6),
					mixAPair(randNom(),0.3,0.1),
					0.05f);
 }
 
  vec3 blackThickSmoke()
 {
 return new Vec3(	mixAPair(randNom(),0.4,0.1),
					mixAPair(randNom(),0.2,0.1),
					mixAPair(randNom(),0.2,0.1));
 }  
 
 vec3 greySmoke()
 {
 return new Vec3(	mixAPair(randNom(),0.5,0.7),
					mixAPair(randNom(),0.45,0.7),
					mixAPair(randNom(),0.54,0.7));
 }
 
 
 float mixAPair(float rand, valx, valy)
 {return valX*rand + valy*(1-rand);}