How should I use glow map?

Hello there,

I’m trying to use glow map with the bloom effect provided with Commonfilters. But, even if I have set the blend coeff to (0,0,0,1), the bloom effect stil take into account the vertex colors, and not the glow map.

Let see a simple example program:

import direct.directbase.DirectStart
from direct.filter.CommonFilters import CommonFilters
from pandac.PandaModules import *

import sys, dircache, os.path, imp, shutil
rootDir = os.path.abspath(os.path.dirname(sys.argv[0]))
loadPrcFile(os.path.join(rootDir, "config.prc"))


#setting up the bloom effect
filters = CommonFilters(,
filters.setBloom(blend=(0.0,0.0,0.0,1.0), mintrigger = 0.9, desat=-0.5, intensity=8.0, size="small")

#creating the card without glow map
cardMaker = CardMaker("cubemaker")
card =  render.attachNewNode(cardMaker.generate())

#creating the card with glowmap
card2 =  render.attachNewNode(cardMaker.generate())

#adding the glow texture to card2
glowTexture = loader.loadTexture("/usr/share/panda3d/samples/Glow-Filter/models/tron-glow.png")
glowTexturetureStage = TextureStage('glow')
card2.setTexture(glowTexturetureStage, glowTexture),-5,0.5)

This program use the textures from the Glow-Filter Sample.
If you test it, you’ll see that both cards have same bloom effect, but only the card on the left has a glow map.

It seems I’ve forgotten something, but I don’t know what. I’ve searched into the manual, forum and sample for a few days, but I didn’t find anything about this.

Does somebody has a hint about this?



Yes. The post-processing filter reads the amount of glow from an auxilliary buffer or from the alpha channel of the framebuffer, and the data from the glow maps is only put there by the shader generator.

Long story short, call setShaderAuto().

Thanks for your answer pro-rsoft.

I’ve just add render.setShaderAuto() to the example, and now the bloom has dissapeared. I was wondering what exactly should the glow map be.

The tron-glow.png from the sample is made into grey and white colors, and doesn’t have alpha channel. Shouldn’t it have one? but this works for the Glow-Filter sample.

Another issue is that the fog isn’t supported when I use setShaderAuto. I will replace this fog by some fadeIn Sequences, but I will lose some FPS.


It should be in the alpha channel. The glow example puts it in the alpha channel along the color texture and uses MModulateGlow mode (meaning color texture in RGB channels and Glow in Alpha channel).
MGlow expects the glow map to be in the alpha channel, too, I think.

You can implement fog and even gain FPS by doing fog as a screen-space postprocessing filter.


After a lots of tests, and with case’s help, I’ve managed to do a shader for fog and glow at the same time.


void vshader(float4 vtx_position : 	POSITION, 
             float2 vtx_texcoord0 : TEXCOORD0,
             float4 vtx_color: 		COLOR,
     uniform float4x4 mat_modelproj,
     uniform float4x4 trans_model_to_apiview,
     	 out float4 l_position : 	POSITION,
	     out float2 l_texcoord0 : 	TEXCOORD0,
		 out float4 l_color0 : 		COLOR0)
	float3 eyePos = mul(trans_model_to_apiview, vtx_position).xyz;
	float coeff;
	l_position = mul(mat_modelproj, vtx_position);
	l_texcoord0 = vtx_texcoord0;
	coeff = 1.2 - length(eyePos)/200.0;
	l_color0 = float4(, coeff);

void fshader(float2 l_texcoord0 : 	TEXCOORD0,
			 float4 l_color0 :		COLOR,
     uniform sampler2D tex_1: 		TEXUNIT1,
     uniform sampler2D tex_0: 		TEXUNIT0,
	 uniform float4 attr_color,
	 uniform float4 attr_colorscale,
         out float4 o_color : 		COLOR)
	float4 texColor = tex2D(tex_0, l_texcoord0);
	float4 glowColor = tex2D(tex_1, l_texcoord0);
	o_color = texColor * attr_color * attr_colorscale;
	o_color = .1 * o_color + .9 * glowColor;
	o_color = o_color * l_color0.w;

I also use a blur shader, which is inspired by the sample Glow-filter:

//Cg profile arbvp1 arbfp1

void vshader(float4 vtx_position : POSITION, 
             float2 vtx_texcoord0 : TEXCOORD0,
	     out float4 l_position : POSITION,
	     out float2 l_texcoord0 : TEXCOORD0,
	 uniform float4x4 mat_modelproj)
  l_position=mul(mat_modelproj, vtx_position);

void fshader(float2 l_texcoord0 : TEXCOORD0,
         out float4 o_color : COLOR,
     uniform sampler2D tex_0 : TEXUNIT1)
	float lightcoeff;
	for (int i = -3; i < 4; i++) {
		for (int j = -3; j < 4; j++) {
			if (i!=0 || j!=0) {
				lightcoeff = 1.0 / (i * i + j * j);
				o_color += tex2D(tex_0, float2(l_texcoord0.x + 2 * i / 1024.0, l_texcoord0.y + 2 * j / 1024.0)) * lightcoeff;
	o_color = o_color * 0.1;

Of course, this is not perfect yet, but it seems quite pretty. I’ll ask my boss if I can show some results of my work:)

if you have some questions, or remarks, please tell me.