Shadow-Casting Sky / ShadowMap


(Orange) #1

Hi, I’m working on my first ET map and I’ve created my terrain and textured it and even made a custom sky shader but that’s not important really…

My question is:
Can I somehow use a texture (the same texture I used for clouds in my skybox shader) to cast shadows on the whole terrain?
How much would it possibly affect fps?

It would give a much more realistic look and it’s also pretty cool…


(WolfWings) #2

Would impact the FPS a bit, but it’s doable. I looked over your thread on the ET forum also.

First, if you’re using indexmaps and so-forth, read up on AlphaMod brushwork here in the q3map2 forum for a much more straight-forward way of controlling the blending on the terrain.

Second, I’ll assume you’re using $lightmap-last terrain.

Third, yes, it’s possible to do what you’re asking about. I’d personally recommend using a ‘blendFunc detail’ pass after your $lightmap pass on your terrain shaders, with a copy of your cloud layer adjusted to 96->192, with the midpoint set to 128 in the Levels tool in Photoshop. This will allow it to act as 75%-150% brightness on the terrain, which should be conservative enough values your ‘static’ lighting will remain dominant, and the cloud layer effect won’t “blow out” your colours anywhere. If the above doesn’t make any sense, feel free to post the cloud layer you’re using, I’ll build a ‘blendFunc detail’ that I think will work. Unless your cloud layer is being applied with ‘blendFunc add’ currently, merge your cloud layers to a background of (128,128,128) first, also, as (128,128,128) is ‘fully transparent’ with ‘blendFunc detail’ on 99% of video cards.

Then you just need a tcGen/tcMod pass applying the cloud layer to all of your terrain shaders, as a final pass after the $lightmap pass. Matching it to the overhead cloud layer would be purely a matter of guess-and-try unfortunately though, the values for the “tcGen vector” and “tcMod scroll” will have to be found by experimentation.


(Orange) #3

It makes sense, but not enough…

  1. Where exactly should I type 96, 192 and 128 in the Levels tool?
  2. What?! Who?! Where?!
    Here’s a simple terrain shader and my skybox shader:

//simple terrain shader
textures/crash/terrain_2
{
	qer_editorimage textures/crash/grass1.jpg
	q3map_lightmapMergable //Thought this would help... (Newbs, go figure...)
	q3map_lightmapsamplesize 64
	q3map_lightmapaxis z
	q3map_texturesize 256 256
	q3map_tcGen ivector ( 64 0 0 ) ( 0 64 0 )
	surfaceparm grasssteps
	surfaceparm landmine
	{
		map textures/crash/grass1.jpg
	}
	{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
		tcGen lightmap
	}
}

//skybox shader
textures/crash/sky
{
	skyParms textures/crash/sky - -
	q3map_lightImage textures/crash/clouds.tga

	q3map_sun 1.000000 0.999527 0.919997 50 180 90
	q3map_skyLight 100 3
	q3map_nofog

	surfaceparm sky
	surfaceparm noimpact
	surfaceparm nolightmap
	surfaceparm nodlight
	
	nopicmip
	nomipmaps

	qer_editorimage textures/crash/sky.jpg

	{
		map textures/crash/clouds.tga
		tcMod scroll 0.01 0.01
		blendFunc GL_ONE GL_ONE_MINUS_SRC_COLOR
	}
}

Do whatever you want with this…

BTW:
All my sky textures (_up, _dn, etc…) are just dark blue.


(WolfWings) #4

Yes, you’re using $lightmap-last terrain.

Trying to put the $lightmap pass first instead of last like most shaders in Q3A did is only useful if you’re using lightstyles (light entities with the _style keyword pair set) to get, for example, flickering florouscent lights, or a burning fire that flickers, or lightning on a rainstorm-covered terrain map. Otherwise, it doesn’t matter.

To do so with blended terrain requires using one of the newer ‘dithered blending’ techniques, with alpha-masking. I’m writing up a tutorial on how properly lightstyled terrain is done, I’ll post it When It’s Done. ‘Dithered’ blending can look a lot better than Team Arena-style blending, BTW. :slight_smile:

And what I meant by post the cloud layer, was to post the actual clouds.tga file.

As for where to type in the values… unfortunately, I don’t have or use PhotoShop. I use The GIMP so I’m unsure of the layout of PS’s dialog boxes. =-.-= The tools are the same, but they’re layed out differently. :-/

The 96 is the minimum output value you want. The 192 is the maximum output value you want. The 128 is the ‘middle grey’ value you want. I dunno if that would help much. =-.-=


(Orange) #5

blendFunc detail? There’s such a thing?

And do you know any no-registration image upload site?


(WolfWings) #6

“blendFunc detail” is equivilant to “GL_DST_COLOR GL_SRC_COLOR” actually.

And just e-mail me the file. wolfwings@gmail.com


(Orange) #7

I’ve changed my sky shader:


textures/crash/sky
{
	skyParms textures/crash/sky - -
	// q3map_lightImage textures/crash/clouds.tga

	q3map_sun 1.000000 1.000000 1.000000 50 180 90
	q3map_skyLight 75 3
	q3map_nofog

	surfaceparm sky
	surfaceparm noimpact
	surfaceparm nolightmap
	surfaceparm nodlight
	
	nopicmip
	nomipmaps

	qer_editorimage textures/crash/sky.jpg

	{
		map textures/crash/clouds.tga
		tcMod scroll 0.01 0.01
		blendFunc GL_ONE GL_ONE_MINUS_SRC_COLOR
	}
}

And here’s the updated terrain shader from what I undestood…


textures/crash/terrain_2
{
	qer_editorimage textures/crash/grass1.jpg
	q3map_lightmapsamplesize 64
	q3map_lightmapaxis z
	q3map_texturesize 256 256
	q3map_tcGen ivector ( 64 0 0 ) ( 0 64 0 )
	surfaceparm grasssteps
	surfaceparm landmine
	{
		map textures/crash/grass1.jpg
	}
	{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
		tcGen lightmap
	}
	{
		map textures/crash/clouds.tga
		blendFunc GL_DST_COLOR GL_SRC_COLOR
	}
}

But all that happend is that everything looks blue and darker (because of the sky shader…)


(WolfWings) #8

Nono, you need a MODIFIED clouds.tga file.

Actually, now that I’ve seen your actual cloud layer, you don’t need to do the ‘Levels’ adjustment. Somehow I thought it was a full-spectrum ‘cloud layer’ with puffy white clouds, not the grayish streaky style of clouds you’re working with. =^.^=

Try this shader instead:

textures/crash/terrain_2
{
   qer_editorimage textures/crash/grass1.jpg
   q3map_lightmapsamplesize 64
   q3map_lightmapaxis z
   q3map_texturesize 256 256
   q3map_tcGen ivector ( 64 0 0 ) ( 0 64 0 )
   surfaceparm grasssteps
   surfaceparm landmine
   {
      map textures/crash/grass1.jpg
   }
   {
      map $lightmap
      blendFunc filter
      tcGen lightmap
   }
   {
      map textures/crash/clouds.tga
      tcGen vector ( 0.0009765625 0 0 ) ( 0 0.0009765625 0 )
      tcMod scroll 0.01 0.01
      blendFunc detail
   }
}

Fiddle with the ‘tcGen vector’ line as you wish. I plugged in the values for 1/1024 there, though you might want to replace them with 1/256 (0.00390625), 1/512 (0.001953125), or even 1/128 (0.0078125) depending on what looks best, or even some other value entirely.


(Orange) #9

Just from curiousity, is there a reason you use tcGen vector instead of tcGen ivector?
I mean, you’re the expert, and if the expert says “use this”, the newb (that’s me (-: ) should probably use it…


(WolfWings) #10

“tcGen ivector” isn’t valid so far as I know.
“q3map_tcGen ivector” is valid, but that’s a shader-wide keyword only. The stage-specifc is just “tcGen” which doesn’t support the “ivector” type as far as I know.


(Orange) #11

So that’s the reason all my textures has been replaced with yellow grid… :smiley:

Edit: Thanks for the help WolfWings, it works like magic… (and looks even better)