[FTEQW] Dynamic lights on transparent objects

Discuss the construction of maps and the tools to create maps for 3D games.
Post Reply
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

[FTEQW] Dynamic lights on transparent objects

Post by toneddu2000 »

Hi guys, I'm creating a tree branch shader with transparent leaves.

Code: Select all

textures/world/tree1leaves1
{
	program spike_rtlight

	cull none
	{
		map textures/world/tree1leaves1.tga
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		alphaFunc GT0
		depthWrite
		rgbGen identity
	}
	{
		map $lightmap
		rgbGen identity
		blendFunc GL_DST_COLOR GL_ZERO
		depthFunc equal
	}

}
I've used this guide (which it's overcopied all over the web) for the script creation. Leaves are cool, transparent and look fair.
The problem is tied to dynamic lights in FTEQW(trough dynamiclight_add function added in code, not with regular "light" entities in map editor). When lit by dynamic lights, object with above shader, rimain always fullbright.

I removed also glsl link but it shows a tremendous black silhouette around non-transparent edges, and still it's fullbright

Have someone figured out how to solve this issue?

Thanks a bunch!
Meadow Fun!! - my first commercial game, made with FTEQW game engine
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: [FTEQW] Dynamic lights on transparent objects

Post by toneddu2000 »

SOLVED! Thanks (obviously!) to a very interesting chat with Spike, he suggest me to look at discard keyword in glsl when alpha value is 0.
So I opened glsl file I was using (defaulwall.glsl generated by issueing in engine the r_dumpshaders command) and adding, at line 157, after gl_FragColor.rgb *= lightmaps.rgb;

Code: Select all

#ifdef ALPHAMASKED
	//toneddu2000: IMPORTANT!!As Spike (thankyou thankyou thankyou!) teached me, put this to discard non-masked elements, for alpha masked transparent textures
	if (gl_FragColor.a < 0.1){
		discard; // yes: discard this fragment
	}
#endif
Than, the shader looks like

Code: Select all

textures/world/tree1leaves1
{
	program spike_defaultwall#ALPHAMASKED
	diffusemap textures/world/tree1leaves1.tga
	{
		map $lightmap
	}
}
Now alpha textures are "perforated" correcly and lit also by dynamic lights! Cool! :biggrin:

Now, I'll try to more things
  1. Adding the discard keyword also in rtlights.glsl (for now I couldn't make it work)
  2. Making shadow maps discard alpha value too (I can't figure out how to override shadow pass. Spike told me that 2nd pass is the depthonly one, which generates shadcow, but I can't understand how to "intercept" it).
NOTE TO ADMINISTRATORS: could you please add edit post option to users? Because I can't re-tag 1st post as [SOLVED]
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Post Reply