Applying glow to a texture

I have a game I’m working on that takes place in space. I wanted to add a sun, which I was able to do. I have a point light emitting from the sun, but I also want the visual appearance that the sun is glowing. I have tried using a glow map, but I wasn’t able to figure out how to use one successfully. I also tried an emissive, but that doesn’t seem to work with a texture. My code so far looks like this:

        self.modelNode.setPos(posVec)
        self.modelNode.setScale(scaleVec)
        self.modelNode.setName(nodeName)
        tex = loader.loadTexture(texPath)
        self.modelNode.setTexture(tex, 1)

        material = Material()
        material.setAmbient((1, 0.95, 0, 1))
        self.modelNode.setMaterial(material)

        plight = PointLight('plight')
        plight.setColor((0.8, 0.8, 0.8, 1))
        plnp = self.modelNode.attachNewNode(plight)
        parentNode.setLight(plnp)

Any help is appreciated. Thank you.

The appearance of the glow requires a screen-space effect. You can use the “bloom” shader in CommonFilters for that. The Glow sample program shows how to use it.

You can make it act based on a certain colour threshold (ie. everything brighter than a certain value will glow), or from a glow map that has been applied to the object. For the best realism, you should probably use high dynamic range rendering, assign a very high brightness to the sun (which you would do with setEmission, not setAmbient, since stars are emitting light), and set the glow filter to operate on that.

I was able to use the bloom shader to get bloom in general to work, but it seems to be applying to everything. I want the glow to work for just that one texture. What am I missing? Thank you for your help.

The way to limit it to just one object is to use a glow map:

  • Apply a glow map that is all-white in the alpha channel.
  • Make sure the shader generator is enabled on the object.
  • In the blend parameter in setBloom, set the r, g, b components to 0.0 and a positive component in the a channel.

The way this works is that the shader generator in conjunction with setBloom is writing the glow map to the (unused) alpha channel of the framebuffer, and then you’re using the setBloom call to apply the glow effect only to pixels that have a positive alpha component.

However, the more realistic way to tackle it is not to use glow maps, but instead enable HDR with setHighDynamicRange and set a ridiculously high emission value to the brightness of stars. With mintrigger in the setBloom you can then enable the bloom only on parts exceeding a certain brightness value.