Glow sample in 1.5

I’m trying to understand the new shader generator. I think I understand the normal map and the gloss map- They seem like they are basically embedded in the egg file itself.

What I don’t understand is the glow function. Perhaps someone can explain the shader generator usage for glow a little bit better- I imagine that the code is also embedded in the model’s egg file but since this file isn’t human-readable I have no way of figure out how to code another model for glow.

The function seems like it could be very useful but when I copy out the tron model and put in my own, I get no glow effect.

Actually, the tron model does have something special in it. Look here:

<Texture> Tex1 {
  tronally.png
  <Scalar> format { rgba }
  <Scalar> alpha { off }
  <Scalar> wrapu { repeat }
  <Scalar> wrapv { repeat }
  <Scalar> minfilter { linear_mipmap_linear }
  <Scalar> magfilter { linear }
  <Scalar> envtype { modulate_glow }  // LOOK OVER HERE
}

That’s a modulate_glow map - meaning that the RGB channels contain a regular texture (modulated), and the alpha channel contains a glow map. A glow map shows where the object should glow.

So the rest of the magic is in the CommonFilters class. This moves the scene rendering into an offscreen buffer, and enables the shader generator for this offscreen render.

Then, it uses an AuxBitplaneAttrib to tell the shader generator to copy the glow map from the model into the alpha channel of the framebuffer.

Finally, the bloom filter produces halos where the framebuffer contains this glow-marker.

PS. I should mention that you don’t necessarily need to use glow maps to trigger the bloom effect. You can also have the bloom effect triggered by general brightness. There isn’t a sample program for that yet, though.

As ever, this was a more timely response than I expected.

Thanks. I decided to play around with the egg syntax and figured out some interesting behaviors.

I have been able to replicate the bloom effect on my own models by adding the line

<Scalar> envtype { glow }

to the Texture inside the egg file. This works great.

This will negate any texture on the model and make the bloom effect pure white. The color of the bloom can be changed by adjusting the

<Scalar> emitr {1.0}
  <Scalar> emitb {1.0}
  <Scalar> emitg {1.0}

until you get the color glow that you want.

Adding the lines:

<Scalar> envtype { modulate_glow }
<Scalar> format {rgba}

paints the regular texture to the model but makes it bloom as well.

I’ve noticed that trying to blend a cubemap on one model in the scene paints one of the render to texture images to the model instead of the cubemap- but I was warned that blending isn’t fully supported yet.

One final question Josh:

How big a performance hit is this? Is this essentially rendering the scene multiple times per frame?

Cube maps aren’t supported yet in the shader generator. It’s just unfinished code.

As for the performance hit: no, it’s not rendering the scene twice. But it is using shaders and per-pixel lighting on the whole scene. That is a performance hit. In general, I think it’s an acceptable performance hit: most games use per-pixel lighting these days.

It’s also doing an image postprocessing filter: that’s a performance hit too.