broken glass shader [solved]

Discussion for Level editing, modeling, programming, or any of the other technical aspects of Quake
Post Reply
Pat Howard
Posts: 494
Joined: Tue Mar 31, 2009 11:14 am

broken glass shader [solved]

Post 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
Last edited by Pat Howard on Sat Apr 25, 2015 1:43 am, edited 1 time in total.
AndehX
Posts: 137
Joined: Fri Apr 10, 2015 10:48 pm

Re: broken glass shader

Post 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
sst13
Posts: 298
Joined: Mon Feb 15, 2010 11:05 pm

Re: broken glass shader

Post 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
	}
}
[url=https://sst13.de]Q3A Maps - by sst13[/url]
[url=https://steamcommunity.com/id/_sst13_/myworkshopfiles]Quake Live Workshop[/url]
Pat Howard
Posts: 494
Joined: Tue Mar 31, 2009 11:14 am

Re: broken glass shader

Post 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
Fjoggs
Posts: 2555
Joined: Fri May 03, 2002 7:00 am

Re: broken glass shader

Post by Fjoggs »

Instead of faking it, why not simply break the glass instead? :)
sst13
Posts: 298
Joined: Mon Feb 15, 2010 11:05 pm

Re: broken glass shader

Post 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
	}
}
[url=https://sst13.de]Q3A Maps - by sst13[/url]
[url=https://steamcommunity.com/id/_sst13_/myworkshopfiles]Quake Live Workshop[/url]
Pat Howard
Posts: 494
Joined: Tue Mar 31, 2009 11:14 am

Re: broken glass shader

Post 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.
cityy
Posts: 1020
Joined: Mon Aug 10, 2009 8:23 am

Re: broken glass shader

Post 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.
www.ferdinandlist.de/leveldesign
sst13
Posts: 298
Joined: Mon Feb 15, 2010 11:05 pm

Re: broken glass shader

Post 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:
Image

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) :owned:
[url=https://sst13.de]Q3A Maps - by sst13[/url]
[url=https://steamcommunity.com/id/_sst13_/myworkshopfiles]Quake Live Workshop[/url]
Pat Howard
Posts: 494
Joined: Tue Mar 31, 2009 11:14 am

Re: broken glass shader

Post 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. :confused:
AndyW
Posts: 848
Joined: Wed Mar 11, 2015 3:23 pm

Re: broken glass shader

Post 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 :)
Die Vitamine sind in der Dose gefangen!!!
Fjoggs
Posts: 2555
Joined: Fri May 03, 2002 7:00 am

Re: broken glass shader

Post 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? :p
AndyW
Posts: 848
Joined: Wed Mar 11, 2015 3:23 pm

Re: broken glass shader

Post by AndyW »

I also think its better to get the Shader to work well, brushing out broken glass is soo Q2-style :(
Die Vitamine sind in der Dose gefangen!!!
cityy
Posts: 1020
Joined: Mon Aug 10, 2009 8:23 am

Re: broken glass shader

Post by cityy »

Fjoggs wrote: Yeah those 100 extra tris sure add up huh? :p
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.
www.ferdinandlist.de/leveldesign
Fjoggs
Posts: 2555
Joined: Fri May 03, 2002 7:00 am

Re: broken glass shader

Post 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.
Pat Howard
Posts: 494
Joined: Tue Mar 31, 2009 11:14 am

Re: broken glass shader

Post 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?
User avatar
CZghost
Posts: 1943
Joined: Wed Jun 22, 2011 1:45 pm
Location: Czechia
Contact:

Re: broken glass shader

Post 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...
[ Linktree | Twitch | YouTube | Instagram | Websites ]
When you feel the worst, turn to the sun and all the shadows will fall behind you.” - John Lennon
Pat Howard
Posts: 494
Joined: Tue Mar 31, 2009 11:14 am

Re: broken glass shader

Post 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.
AndyW
Posts: 848
Joined: Wed Mar 11, 2015 3:23 pm

Re: broken glass shader

Post by AndyW »

Hmm.. Hard Words! So i wont post any Ideas too cause im a Noob... :(
I hope you will figure it out!
Die Vitamine sind in der Dose gefangen!!!
sst13
Posts: 298
Joined: Mon Feb 15, 2010 11:05 pm

Re: broken glass shader

Post 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...
[url=https://sst13.de]Q3A Maps - by sst13[/url]
[url=https://steamcommunity.com/id/_sst13_/myworkshopfiles]Quake Live Workshop[/url]
Pat Howard
Posts: 494
Joined: Tue Mar 31, 2009 11:14 am

Re: broken glass shader

Post 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 :)
Post Reply