How do have skyshader show skybox but use fogvars?


(G0-Gerbil) #1

Title says it all, but to elaborate slightly:

I have a sky shader that I need to use fogvars.
The only problem is the skybox now becomes fogged, regardless of what I do to the shader, eg nofog or fog off in the layer stages like wot is in most of the SD sky shaders.

Anyone know what I’m doing wrong?

//////////////////////////////////////////////////////////////////////////
// Sky box
textures/fogtest/skybox
{
	qer_editorimage textures/mml_church_se_a1/mml_church_ft.tga

	surfaceparm noimpact
	surfaceparm nolightmap
	surfaceparm nodlight

	q3map_globaltexture
	q3map_lightsubdivide 512

	q3map_sun 1.0 1.0 0.9 120 220 60
	q3map_surfacelight 100

	fogvars ( 0.95 0.95 1.0 ) 4096

	skyparms textures/mml_church_se_a1/mml_church 128 -
	q3map_backsplash 0 0
	q3map_bounce 0

	nofog
	{
		fog off
		map textures/mml_church_se_a1/clouds.tga
		blendfunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA 
		tcMod scroll 0.005 0.002
		tcMod scale 3.0 3.0
	}
}

(Chruker) #2

I’m not entirely sure I understand what you are after.

But for good luck I copy-paste the sky shader from mp_ice / et_ice:


textures/mp_ice/mp_ice_sky
{
	qer_editorimage textures/skies/fueldump_clouds.tga
	surfaceparm noimpact
	surfaceparm nolightmap
	surfaceparm nodlight
	q3map_globaltexture
	q3map_lightsubdivide 2048
	q3map_sun	0.60 0.55 0.55 70 220 60
	q3map_surfacelight 70
	fogvars ( .4 .4 .46 ) .0001
	skyfogvars ( .23 .23 .24 ) .1

	skyparms full 200 -
	
	{
		map textures/mp_ice/newclouds.jpg
		tcMod scroll -0.003 -0.001
		tcMod scale 6 6
		depthWrite
	}
}


(G0-Gerbil) #3

Ah yeah but the fogvar line uses volumetric fogging so it won’t work.
Basically I was doing a bit of playing around with target_fog and found the only way to have level fogging that interacts properly with it is to use fogvars, but with values > 1. Now I needto find out how to merge that with a visible skybox.


(Chruker) #4

Are you using the _skybox entity?


(G0-Gerbil) #5

No not at all, just the normal: skyparms textures/mml_church_se_a1/mml_church 128 - method.
By _skybox entity do you mean the normal skyportal entity, or the ‘new’ fudged skybox for q3 and other games that don’t natively support skyportals?


(SCDS_reyalP) #6

Going from memory of RTCW here, so beware things could have changed, or I have forgotten a few things.

If you use distance fog (fog value greater than 1) then the sky will always be fully fogged, since it is effectively at max distance, and fogging is purely a function of distance. If you use density fog, (0 < fog value < 1) then you can use skyfogvars to control the sky fogging independent of the level fogging.

Also note that et adds the _fog worldspawn key. This post http://www.splashdamage.com/index.php?name=pnPHPbb2&file=viewtopic&t=8379&highlight=fog has some tangential description.


(G0-Gerbil) #7

I saw that thread but no-one appears to be using fogparms because quite simply they aren’t the best way to do fogging.
I think I may be forced to because target_fog only reacts normally to that style of fog.
Actually I don’t know that for sure because I only tried the target_fog using distance fog.

If density fog works, then I’ll have a whole set of other problems related to messing with fog, but the main hurdle would be overcome. Only one way to find out I suppose :slight_smile:


(G0-Gerbil) #8

I should have stated, the difference between what Ydnar offers here:

Battery is fogged using a worldspawn fog shader.

The sky shader has q3map_noFog and a mask image that matches the fog color.

This is the same hack that BF1942, MoH and COD use to have both sky and distance fogging

is that I want dynamic fog colour / distance :slight_smile:


(G0-Gerbil) #9

Nope, using density fog doesn’t work and even if I did I’d be dubious about using it - it’s ugly as hell :slight_smile:
I suppose final test is to set up a ‘standard’ ET fog using worldspawn values / shaders and see if that changes. Somehow I doubt it though.

Actually, I think I’ll also try a sky portal with the normal distance fogging - I could then fake my own skybox.


(G0-Gerbil) #10

OK a few tests and I believe I can do what I want.

The setup is:

Skybox shader with something like:

//////////////////////////////////////////////////////////////////////////
// Sky box
textures/fogtest/skybox
{
	qer_editorimage textures/mml_church_se_a1/mml_church_ft.tga

	surfaceparm noimpact
	surfaceparm nolightmap
	surfaceparm nodlight

	q3map_globaltexture
	q3map_lightsubdivide 512

	q3map_sun 1.0 1.0 0.9 120 220 60
	q3map_surfacelight 100

	fogvars ( 0.95 0.95 1.0 ) 8192

	skyparms - 128 -
	q3map_backsplash 0 0
	q3map_bounce 0
}

The idea is this never ever gets drawn, it’s purely for lighting.
Then you have a skyportal in the middle of a cube. Onto the faces of this cube you paint your skybox manually. For now I’ve dumped an extremely bright light in the middle so all the skybox textures are as bright as can be (obviously you wouldn’t want shading on the fake skybox!).

So now, quite happily, I can change my fog as I want and the skybox is always maximum brightness.

Two remaining issues:

  1. Seams on the faked skybox
  2. Far fog clips, so skybox can be right in front of you if you set fogfar near.

Solutions (to be tested but as ever the theory should be ‘fine’ ;)):

  1. Set the shaders to not repeat. Then either inset the UVs slightly (probably easiest to make cube they paint onto 512x512, stretch them all to fit, then shrink the box sides by 1 unit and disable mipmaps, or else use the method detailled in the clampMap help in the updated q3map2 shader - only reason I don’t like that is cos it limits the visible part of the texture to 256x256 pixels maximum)
  2. Set up an extremely big script_mover that matches the 4 sides of the faked skybox. Onto the insides of this new box paint a texture to fit. This texture will basically be an alpha’ed texture - the colour will match one of the destination fog colours, while the fade is from totally translucent to fully opaque. It’ll use polygonoffset. Then, when a fog change is triggered, I simply scroll this script_mover up and it will appear like the skybox is getting fogged. Top and bottom would work similarly.

The above is the only way I can think of of making a texture change to a solid colour under scripted control.
If anyone can prove me wrong, I’ll be grateful :slight_smile:

Overall the skybox being drawn shouldn’t be too slow. It means it’ll be a static skybox with no clouds (could put them in on the faked bit but quite frankly I need the skybox to take as little CPU as possible), but it’s only drawing at most the 6 faked skybox faces, and 6 very large brushfaces for the blend (which won’t be all the time) - 12 polygons should cull reasonably well.

Now of course I want to ask:

What’s so bad about distance fog that people stopped using it? This last question kinda worries me - if there’s inherent bugs then I will have to stop this method entirely and give up :frowning: