Light Emitting Shaders

Discussion for Level editing, modeling, programming, or any of the other technical aspects of Quake
Post Reply
KillPixel
Posts: 49
Joined: Sun Jun 22, 2014 7:35 pm

Light Emitting Shaders

Post by KillPixel »

It seems the info I'm looking for is not yet in the manual:

http://q3map2.robotrenegade.com/docs/sh ... aders.html

Here are the textures and shaders I'm using for this example:

Image

Code: Select all

textures/tech/door
{  
	q3map_lightimage textures/tech/door_on.tga
	surfaceparm nodlight
	surfaceparm nomarks
	{
		map textures/tech/door.tga
	}
	{
		map $lightmap
		blendFunc filter
	}	
	{	
		map textures/tech/door_on.tga
		blendfunc blend
	}		
}
...and an example of them in action:
http://www.killpixel.com/kpcn/wide_door.jpg

The light emitted by the red lights on the door is from two red lights I placed in the editor, I'd like to do this via shaders if possible. I'm not very shader savvy, so example code that I can cannibalize would be great :)

I was hoping I could just add a few lines to the 3rd stage for it to work, but maybe I'm being naive.
[url=https://www.youtube.com/user/KillPixel]KillPixel@YouTube[/url]
User avatar
Theftbot
Posts: 483
Joined: Thu Oct 08, 2009 4:03 am

Re: Light Emitting Shaders

Post by Theftbot »

q3map_surfaceLight param.
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Light Emitting Shaders

Post by obsidian »

surfaceLight works well if you wanted the entire surface to emit light (like an actual light fixture texture), but not so well if you just have a tiny glowing texture.

Instead of creating a real light source, you probably want to fake it for small stuff like this with an additive blend (blendFunc add) on that last stage.

It would probably look better if that door_on.tga image had a slight blur/halo on it as well.

See here:
http://q3map2.robotrenegade.com/docs/sh ... #blendFunc

Optionally, you can also add a bit of a pulse to it by changing the vertex colour values with a waveform function:
http://q3map2.robotrenegade.com/docs/sh ... tml#rgbGen
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
KillPixel
Posts: 49
Joined: Sun Jun 22, 2014 7:35 pm

Re: Light Emitting Shaders

Post by KillPixel »

ok, using blendfunc add for the glow works, using this image:

Image

However, I don't know how to stack this on along with door_on. I can do each one separately, but having them both is tricky

EDIT: nvm, figured it out and it looks good! Thanks again, obsidian.
[url=https://www.youtube.com/user/KillPixel]KillPixel@YouTube[/url]
KillPixel
Posts: 49
Joined: Sun Jun 22, 2014 7:35 pm

Re: Light Emitting Shaders

Post by KillPixel »

Well, I thought I had it figured out...

Code: Select all

textures/tech/door
{  
	q3map_lightimage textures/tech/door_on.tga
	surfaceparm nodlight
	surfaceparm nomarks
	{
		map textures/tech/door.tga
	}
	{
		map $lightmap
		blendFunc filter
	}	
	{	
		map textures/tech/door_on.tga
		blendfunc blend
	}
	{	
		map textures/tech/door_light.tga
		blendfunc add
	}	
}
And the result:

http://www.killpixel.com/kpcn/wtf.jpg

As you can see, it makes the door bright. Would you show me the error of my ways?

EDIT: Nvm, again. I had to specify rgbGen identity

Code: Select all

textures/tech/door
{  
	surfaceparm nodlight
	surfaceparm nomarks
	{
		map textures/tech/door.tga
	}
	{
		map $lightmap
		rgbGen identity
		blendFunc filter
	}	
	{	
		map textures/tech/door_on.tga
		blendfunc blend
	}
	{	
		map textures/tech/door_light.tga
		blendfunc add
	}	
}
The manual led me astray:
rgbGen identity: Colors are assumed to be all white (1.0, 1.0, 1.0). All filters stages (lightmaps, etc) will get this by default.
[url=https://www.youtube.com/user/KillPixel]KillPixel@YouTube[/url]
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Light Emitting Shaders

Post by obsidian »

What's the second stage for? Why not just combine the textures for door_on and door_light?
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
User avatar
Theftbot
Posts: 483
Joined: Thu Oct 08, 2009 4:03 am

Re: Light Emitting Shaders

Post by Theftbot »

What engine is that?
KillPixel
Posts: 49
Joined: Sun Jun 22, 2014 7:35 pm

Re: Light Emitting Shaders

Post by KillPixel »

What's the second stage for? Why not just combine the textures for door_on and door_light?
Because I don't know wtf I'm doing :D

light_on needs to be fully opaque and fullbright, light_glow needs to be translucent. I don't know how to do that with one texture.
What engine is that?
FTE
[url=https://www.youtube.com/user/KillPixel]KillPixel@YouTube[/url]
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Light Emitting Shaders

Post by obsidian »

Textures should look something like this:

Image

Code: Select all

textures/tech/door
{
   surfaceparm nomarks
   {
      map textures/tech/door.tga
   }
   {
      map $lightmap
      rgbGen identity
      blendFunc filter
   }
   {   
      map textures/tech/obs_door_light.tga
      blendFunc add
   }   
}
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
KillPixel
Posts: 49
Joined: Sun Jun 22, 2014 7:35 pm

Re: Light Emitting Shaders

Post by KillPixel »

Awesome, much better. I was using an alpha channel and blendfunc blend for door_on because I thought blendfunc add would blend in the door texture... that would be the case if the door texture directly behind door_on wasn't black. Derp, that escaped me.

Sweet, less code, one less texture and no alpha channel. :cool: :up:

Thanks again.
[url=https://www.youtube.com/user/KillPixel]KillPixel@YouTube[/url]
Post Reply