Page 1 of 1
broken glass shader [solved]
Posted: Mon Apr 20, 2015 3:46 am
by Pat Howard
hey guys,
shader noob question here. i've been trying to figure this out but i can't find a specific example of this having been done before (or maybe i'm just not thinking creatively enough).
i'm trying to make a broken glass shader. i'd like the glass to be translucent, as in blendfunc filter, with an env map, but i also want to have an alpha channel where the hole in the glass is.
could someone help me modify this shader to include an alpha channel?
Code: Select all
textures/phdm5/glass_break1
{
qer_editorimage textures/phdm5/glass_break1.tga
qer_trans 0.9
surfaceparm nolightmap
surfaceparm nodlight
surfaceparm trans
{
map textures/phdm5/glass_break1.tga
blendfunc filter
}
{
map textures/phdm5/glass_env.tga
blendfunc add
rgbGen identity
tcGen environment
}
}
as it stands, the alpha channel is not showing up in game. i tried blendfunc blend and that got the alpha channel working, but i also lost the translucency of the glass. i also tried just using grey in the alpha channel for the glass and black in the alpha channel for the hole with blendfunc blend, but then the texture appeared overly bright compared to blendfunc filter.
any help appreciated. thanks,
pat
Re: broken glass shader
Posted: Mon Apr 20, 2015 11:36 am
by AndehX
I was going to say, as long as the alpha channel has grey for the glass and black for the hole, it should work theoretically. If it's appearing too bright in game, then try adding "rgbGen lightingDiffuse" under blendfunc blend
and if its still too bright, try changing glass_env to "rgbGen lightingDiffuse" aswell
Re: broken glass shader
Posted: Mon Apr 20, 2015 10:08 pm
by sst13
Code: Select all
textures/phdm5/glass_break1
{
qer_editorimage textures/phdm5/glass_break1.tga
qer_trans 0.9
surfaceparm nolightmap
surfaceparm nodlight
surfaceparm nomarks
surfaceparm trans
cull disable
{
map textures/phdm5/glass_break1.tga
blendfunc filter
rgbGen identity
depthWrite
alphaFunc GE128
}
{
map textures/phdm5/glass_env.tga
blendfunc add
rgbGen identity
tcGen environment
depthFunc equal
}
}
Or with a lightmap: (dark areas reflect more...)
Code: Select all
textures/phdm5/glass_break1
{
qer_editorimage textures/phdm5/glass_break1.tga
qer_trans 0.9
surfaceparm nodlight
surfaceparm nomarks
surfaceparm trans
cull disable
{
map textures/phdm5/glass_break1.tga
blendfunc filter
rgbGen identity
depthWrite
alphaFunc GE128
}
{
map $lightmap
blendfunc filter
rgbGen identity
tcGen lightmap
depthFunc equal
}
{
map textures/phdm5/glass_env.tga
blendfunc add
rgbGen identity
tcGen environment
depthFunc equal
}
}
Re: broken glass shader
Posted: Tue Apr 21, 2015 12:13 am
by Pat Howard
@sst13: thanks, but those shaders made the glass too dark.
[lvlshot]https://dl.dropboxusercontent.com/u/3305662/baseq3/screenshots/kara/shot0287.jpg[/lvlshot]
i'd like to have an alpha on the broken glass but still have it look similar to the surrounding unbroken glass. maybe it's not possible without using a grey alpha? i could do it this way but it seems a bit like a hack and it would take a bit of fiddling to get it to look like a standard blendfunc filter.
here are the textures i am using:
glass_break1.tga
glass_env.jpg
glass.jpg
Re: broken glass shader
Posted: Tue Apr 21, 2015 1:07 am
by Fjoggs
Instead of faking it, why not simply break the glass instead?

Re: broken glass shader
Posted: Tue Apr 21, 2015 2:49 am
by sst13
Note: Both of my test shaders got the same name. You maybe used the lightmapped one accidentally...
So if this is your glass shader:
Code: Select all
textures/phdm5/glass
{
qer_editorimage textures/phdm5/glass.tga
qer_trans 0.9
surfaceparm nolightmap
surfaceparm nodlight
surfaceparm trans
{
map textures/phdm5/glass.tga
blendfunc filter
rgbGen identity
}
{
map textures/phdm5/glass_env.tga
blendfunc add
rgbGen identity
tcGen environment
}
}
This should be the matching "broken" one:
Code: Select all
textures/phdm5/glass_break1
{
qer_editorimage textures/phdm5/glass_break1.tga
qer_trans 0.9
surfaceparm nolightmap
surfaceparm nodlight
surfaceparm trans
{
map textures/phdm5/glass_break1.tga
blendfunc filter
rgbGen identity
depthWrite
alphaFunc GE128
}
{
map textures/phdm5/glass_env.tga
blendfunc add
rgbGen identity
tcGen environment
depthFunc equal
}
}
Re: broken glass shader
Posted: Tue Apr 21, 2015 5:01 am
by Pat Howard
@sst13: thanks for your help again. both shaders appear darker like that. do you have a different result on your end?
@fjoggs: i could, but i thought the shapes would be more interesting and realistic this way.
Re: broken glass shader
Posted: Tue Apr 21, 2015 9:08 pm
by cityy
Pat Howard wrote:
@fjoggs: i could, but i thought the shapes would be more interesting and realistic this way.
It's also good from a tris count point of view. Though I don't know how much alpha channel shaders hit - in terms of performance, compared to say 100 more polygons.
Re: broken glass shader
Posted: Tue Apr 21, 2015 10:05 pm
by sst13
Pat Howard wrote:@sst13: thanks for your help again. both shaders appear darker like that. do you have a different result on your end?.
Looks pretty much ok on my end:
Pat, can you post your (unbroken) glass shader?
cityy wrote:Though I don't know how much alpha channel shaders hit - in terms of performance, compared to say 100 more polygons.
It depends on how much you can see through the alpha tested texture. In this case (only the skybox) it wouldn't eat up much performance.
A bad idea would be to view bigger parts of the map through such a shader. (using
this PC)

Re: broken glass shader
Posted: Wed Apr 22, 2015 4:23 am
by Pat Howard
sst13 wrote:Looks pretty much ok on my end
yeah, that is exactly what i'm after.
i'm using the both the shaders you posted, the unbroken and the matching broken one.

Re: broken glass shader
Posted: Wed Apr 22, 2015 8:27 am
by AndyW
Intresting Post!
Seems the Crack in Pats "Glass" goes up to the right - and in ssts "glass" it moves up to the left.
Maybe it make a difference which side oft the brush you put the texture on? In the 2 shots they display different/ mirrored.
Was just an idea

Re: broken glass shader
Posted: Wed Apr 22, 2015 9:16 pm
by Fjoggs
cityy wrote:Pat Howard wrote:
@fjoggs: i could, but i thought the shapes would be more interesting and realistic this way.
It's also good from a tris count point of view. Though I don't know how much alpha channel shaders hit - in terms of performance, compared to say 100 more polygons.
Yeah those 100 extra tris sure add up huh?

Re: broken glass shader
Posted: Thu Apr 23, 2015 12:37 am
by AndyW
I also think its better to get the Shader to work well, brushing out broken glass is soo Q2-style

Re: broken glass shader
Posted: Thu Apr 23, 2015 5:44 pm
by cityy
Fjoggs wrote:
Yeah those 100 extra tris sure add up huh?

Well, yea, in this particular case it is not very relevant but I think it's a good thing to be aware of the effect your decisions have on the polycount every time you make one. It's something I like to ignore a lot.
Re: broken glass shader
Posted: Thu Apr 23, 2015 9:17 pm
by Fjoggs
Shaders affect performance as well. The triscount from a broken glass like that would be as negligible on performance as the shader would be.
Re: broken glass shader
Posted: Fri Apr 24, 2015 4:28 am
by Pat Howard
@sst13: okay, i just realized what the problem is. it's actually the skybox behind the glass that is causing my problem!
[lvlshot]https://dl.dropboxusercontent.com/u/3305662/baseq3/screenshots/kara/shot0289.jpg[/lvlshot]
the broken glass shader only appears darker when viewing the skybox through it. the skybox is not visible at all and it also creates a very weird HOM effect that you can't quite see from the picture.
here is my sky shader, copied from the
shader manual:
Code: Select all
textures/kara/hip_miramar
{
skyparms env/hip_miramar/miramar - -
q3map_sunExt 1 1 .93 450 323 70.5 3 32
q3map_lightmapFilterRadius 0 8
q3map_skyLight 125 6
surfaceparm sky
surfaceparm noimpact
surfaceparm nolightmap
surfaceparm nodlight
nopicmip
nomipmaps
qer_editorimage env/hip_miramar/miramar_ft.tga
}
anyone know what causes this?
Re: broken glass shader
Posted: Fri Apr 24, 2015 2:40 pm
by CZghost
Detail the brush with glass shader? You said it's causing little HOM effect - blocking vis - repair with detail brush... I'm not sure if Radiant support also making brush nonsolid, which might make brush detail and compiler should not generate collision polygons for it... This could also help. If you use caulk for invisible faces, don't, use nodraw instead...
Also nopicmip and nomipmaps should not be in one shader... And I never seen sky shader with these options...
Re: broken glass shader
Posted: Fri Apr 24, 2015 5:53 pm
by Pat Howard
@czghost: i appreciate your desire to help on the forum, but none of the stuff you just said is true. it's no good to have that kind of false information floating around here. in the future, could you do me a favor and please only comment on technical topics when you have a strong knowledge of the subject?
@sst13: would you mind just trying the shader in front of a skybox? i'm getting this problem with any kind of skybox shader i try, but not with stock q3 skies.
Re: broken glass shader
Posted: Fri Apr 24, 2015 7:18 pm
by AndyW
Hmm.. Hard Words! So i wont post any Ideas too cause im a Noob...

I hope you will figure it out!
Re: broken glass shader
Posted: Fri Apr 24, 2015 10:34 pm
by sst13
Adding a higher sort value solves the problem with the skybox:
Code: Select all
textures/phdm5/glass_break1
{
qer_editorimage textures/phdm5/glass_break1.tga
qer_trans 0.9
surfaceparm nolightmap
surfaceparm nodlight
surfaceparm trans
sort additivie
{
map textures/phdm5/glass_break1.tga
blendfunc filter
rgbGen identity
depthWrite
alphaFunc GE128
}
{
map textures/phdm5/glass_env.tga
blendfunc add
rgbGen identity
tcGen environment
depthFunc equal
}
}
The sort value must be 7 or more to work well with a skybox.
For viewing health bubbles or torch fire through the broken glass shader at least 9 (additive).
PS: Add "r_clear 1" to your config. This helps a lot spotting this kind of errors including missing/untextured faces...
Re: broken glass shader
Posted: Sat Apr 25, 2015 1:43 am
by Pat Howard
@sst13: it works! thanks so much.
@andyw/czghost: no harshness intended, sorry if i was too blunt. guessing i'm feeling better now that i've got this bug out of my map
