Shader Help


(ACROBAT) #1

I wanted to do Alpha shadowing with glass instead of a grate. I mean the q3map2 specific shader that involves _castshadows and _receive shadows.

This is my glass shader

textures/e3/glass_security_hex
{
qer_editorimage textures/e3/sglass1
qer_trans 0.9
surfaceparm nonopaque
surfaceparm forcefield
surfaceparm trans
q3map_material Glass
q3map_nolightmap
{
map textures/e3/etest4
blendFunc GL_ONE GL_ONE
tcGen environment
}
{
map textures/e3/sglass1
blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
}
}

I need to change it somehow so light can go through it. Here is a grate shader that works great for alpha shadowing, but doesn’t look like glass :confused:
I’m not using this one, but posting it for reference on how I can change the previosu shader I posted.

textures/mymap/grate
{
qer_editorimage textures/imperial/grate02
surfaceparm nonopaque
surfaceparm trans
surfaceparm alphashadow
cull twosided
qer_trans 1.0
{
map textures/imperial/grate02
alphaFunc GE128
blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
depthWrite
}
{
map $lightmap
rgbGen identity
blendFunc GL_DST_COLOR GL_ZERO
depthFunc equal
}
}


(obsidian) #2

Hmm… so you want to have a grate that casts shadows with glass between the slits?

Instead of using alphashadow, try lightfilter instead. Your glass texture will need a proper alpha-channel.


(ACROBAT) #3

I was under the assumption that adding surfaceparm lightfilter to my tga file would use the color of the tga file for the color of the shadows?

Is it possible to actually make glass cast the shadow itself though?

What I’ve basically done is put a tga file in behind my glass that matches it so it kind of looks like the glass is casting a shadow but it’s really a tga file grate like texture.

Do you have any links about making the glass give off shadows?


(ACROBAT) #4

Here are some pictures of my problem


(obsidian) #5

Ah, I see…

Your first shader is almost correct, just add surfaceparm alphashadow.

textures/test/alpha
{
	cull none
	surfaceparm nomarks
	surfaceparm trans
	surfaceparm alphashadow
	qer_trans 0.5
	{
		map textures/test/shiny.tga
		tcGen environment
		blendfunc add
	}
	{
		map textures/test/alpha.tga
		blendFunc blend
	}
}

Then, duplicate the grate texture’s alpha channel and copy it into the environment map texture’s alpha channel (so they both have the same alpha channel).

Q3Map2 will use the alpha channel of both texture stages to generate the alpha shadow (which now happen to be the same).


(ACROBAT) #6

Hmmmm. What I found when I tried using the env map for a light emitting shader was that the light source was too wide and caused the alpha channels to become obscured so I made a light source that was very tiny, which worked in the past for szico.

Here are some radiant pics.

Should I move the skybox in close to the window right next to it, give it an alpha channel identical to the glass, and then add that key you mentioned to the glass shader?

Also I think I used the surface inspector on bother the grate.tga and my glass. What would be the solution to tha?


(obsidian) #7

Huh? By environment map, I mean the first stage of the shader containing tcGen environment. Not the sky shader’s cube map. The light source has nothing to do with it.

With my method, you only need 1 shader for both grate and glass.


(ACROBAT) #8

ahh Ok, so after I add that line to the glass shader and give the corresponding texture a alpha channel matching it’s texture, I can delete my grate shader entirely right?


(obsidian) #9

Yes. It’s all just one shader.

alpha.tga is the blue texture with black crosses (grate).
shiny.tga is the gray scale one (env. map).

Both textures need the same alpha channel.


(ACROBAT) #10

Looks great

I had to make the glass really thin though. It was ultra thick security glass. When I left it thick it did this. When I was using the tga grate shader instead of the glass, it was very skinnny, so when the glass was very thick it makes these double circles. Anyway around this?

If I make a map-craft tutorial on this, can I use your jpegs btw?

also is “q3map_alphashadow” more up to date the surfaceparm lightfilter?


(obsidian) #11

Umm… well… yes… It’s obvious to say that if you have a thick piece of glass with the same shader on both sides of the glass, then you’re going to end up with a double image.

Go ahead with the jpgs. Just some credit would be nice.

surfaceparm alphashadow and surfaceparm lightfilter are not the same thing. Read the Q3Map2 Shader Manual for details.


(ACROBAT) #12

oops typo, earlier you said “surfaceparm alphashadow” vs. q3map2_alphashadow

Also I used you invisble light emitting shader that I found on an old forum as follows:

textures/e3/lightbox
{
qer_editorimage textures/e3/whitelight
q3map_lightRGB 1.00 0.86 0.31
q3map_surfacelight 50000
surfaceparm nolightmap
surfaceparm nonsolid
surfaceparm trans
{
map $whiteimage
alphaFunc GE128
alphaGen const 0
}
}

I started writing a tutorial on this, and I’m not sure what acutally makes it invisible. I’m confused about lines 11 and 12 since those two lines probably make the shader invisible somewhere. I looked at the shader manuel but, I am unsure how to explain the two lines.


(Shallow) #13

It’s easiest to look at those in reverse order.

alphagen const 0
Tells the engine to treat the texture as if it has a pure black alpha channel - if it said 1 it would be pure white, anything in between shades of grey.

alphaFunc GE128
Cutout transparency like that used for grates. GE128 means anything with an alpha value Greater than or Equal to 128 (out of 256) will be rendered, anything less that that won’t. Or in normalised terms like we set with alphagen const, anything with an alpha less than half isn’t rendered.

So you set the alpha channel to black, with an alpha function applied that won’t render pixels that have a black alpha channel.

You have to do this because you can only emit light from renderable surfaces. You can’t just set it as non-drawing with surfaceparms unfortunately.

@obsidian - I’m curious, why do you recommend putting the alpha channel in both stages? Unless it’s been changed at some point, isn’t the compiler supposed to use the q3map_lightimage or qer_editorimage (whichever it finds first) as the source for alpha shadow or lightfilter?


(ACROBAT) #14

Can you please explain lines 14 and 15 of this shader also?

"textures/e3/glass_security_hex
{
cull none
surfaceparm nomarks
surfaceparm trans
surfaceparm alphashadow
qer_trans 0.5
{
map textures/e3/etest4
tcGen environment
blendfunc add
}
{
map textures/e3/sglass1
blendFunc blend
}
}
"


(Shallow) #15

blendfunc blend is just a shorthand way of writing a more complex alpha-blending instruction like the one in your original shader. Those two lines say “for each pixel draw an amount of the RGB data from this texture, depending on how white the alpha channel is there”


(obsidian) #16

Actually, yes… that would be the smarter way. Thanks.

Although a slight correction, it will prefer to use the alpha channel of q3map_lightImage if it finds it, otherwise falling back to qer_editorImage and lastly the texture stages itself.

textures/test/alpha
{
	cull none
	surfaceparm nomarks
	surfaceparm trans
	surfaceparm alphashadow
	qer_trans 0.5
	//q3map_lightImage textures/test/lightimage.tga    //use this...
	qer_editorImage texutres/test/alpha.tga            //or this for alphashadow
	{
		map textures/test/shiny2.tga
		tcGen environment
		blendfunc add
	}
	{
		map textures/test/alpha.tga
		blendFunc blend
	}
}

In this example shader, qer_editorImage is used instead of q3map_lightImage since you can save some texture memory by skipping the need for an additional texture.


(Shallow) #17

Yes, that is the expected behaviour, but there was a bug where q3map2 would use the editorimage if it was in the shader before the lightimage. Of course that was aaages ago, so it might be OK now: I have no idea whether ydnar fixed it before the final build though. I guess if you’re messin’ with this stuff you’ll find out!


(ACROBAT) #18
textures/test/alpha
{
   cull none
   surfaceparm nomarks
   surfaceparm trans
   surfaceparm alphashadow
   qer_trans 0.5
   {
      map textures/test/shiny.tga
      tcGen environment
      blendfunc add
   }
   {
      map textures/test/alpha.tga
      blendFunc blend
   } 

So in the previous example you gave, the first one you posted I mean, it’s also falling back on its third resource, which are the textures themselves?

I should make a third image then that is just a white image with alpha channels or…?


(obsidian) #19

You can think of it as this…

Q3Map2 will use the texture stage alpha by default, which works fine for grates since there is only 1 texture stage.

But because you have two stages, you need to tell Q3Map2 which alpha channel to use for the light-filter.

You can make both textures have the same alpha channel (as in my first example) so light “shines through” both textures…

… or specify exactly which alpha channel to use with either a qer_editorImage or q3map_lightImage.

Since your texture already has an alpha channel, you’re probably best off just using that with the qer_editorImage.