Working on Implementing Glow Effect (Cg) on TGE
by Pisal Setthawong · 06/14/2006 (11:20 am) · 20 comments
During the last few weeks, I've been working with proping up my TGE so that I could use Cg to prop up the graphical engine. I'm completely aware that TSE would potentially be a better choice if I wanted to use Shaders, but as the project I'm working on is rather crucial, I need to be sure the game could be delivered as promised. That is why I stuck with TGE and tried to do the best with what tools I had at disposal.
Let me show you the original game screenshots that I've used TGE in:

I do find the results to be pretty decent. Though not state of the art graphics, it wasn't shabby, and looked good to my early trial with a number of casual game players (relatives, friends popping by my home :P).
After presenting that to my customers, I've found the major comment is that they wanted the scene to look more surreal. After talking through it, they wanted some sort of glow effect to make the scene look unreal or like in the game scenes from heaven or hell. Though I attached lights to my player character, that light wasn't enough glow.
I had a few workarounds that I thought about doing. The major problem is that I can't implement things that require too many CPU cycles considering the huge demand at the present. The first I thought to do was to was to add particle effects to the player. That was kind of taking the focus off the point I didn't implement the glow-effect. The other is to double render the player and use different blending options to get the player glow. This method requires more rendering passes, and since the current game is extremely taxing on the CPU/memory, I've decided not to do this. I remember I used to use the DRL resource, and I liked it extremely. However as my game is already using too much CPU, I didn't think I should use it with this project. The last idea that came to mind is to use Cg to implement the glow effect. This is an ideal solution as it places less stress on the CPU as the extra processing is sent to the GPU.
On a side note, I could always simply ignore the request, but since I had time (was a few weeks ahead of schedule) I decided to try to experiment by adding Cg support to TGE.
The first part of was easy. Integrating Cg to any program is easy. There are many resources that point to that in the Internet. I myself also did write a few DirectX + Cg programs before. The next point is to write some vertex/pixel shader programs to create the glow. In this part I used to work with my own Glow effect in RenderMonkey before so that was a huge help. On a sidenote, there are also many useful resources that is useful on this topic and the one that I liked was from the following url: (collective.valve-erc.com/index.php?go=tron1). As I had some parts of this done already, the rest was for me to figure a way to merge it with TGE which seem quite a difficult task at the beginning.
During the first few days of implementing, I had a torrid time getting things right. At times, everything crashed, at times I get things opposite of what I wanted. As noted, the following picture shows alittle about some of the things gone wrong:

After a little more probing, I managed to fix a few more things, though unfortuantely I had the whole picture oversaturated instead of making it look like glowing. Also there were many rendering problems like when the scene became too saturated, the characters all disappeared! Now that is what I call bad programming on my part :P

However after a period of debugging, and going through the rendering engine TGE, things were dawning. The TGE rendering engine is rather decentralized so it takes some time to go through the different parts of the engine to find what I wanted. Anyway, after another sleepless night, programming along with watching the WorldCup, somehow I managed to get things alittle like what I wanted.

From the last pic, there is a slight glow effect with the whole scene which is basically the effect I wanted. Though the effect was created, I don't think it is adequate yet. I believe I need to tweak things comprehensively to make it look better. However, I was more preoccupied of getting things done than actually making it look good since the start, so I guess within the short period of time, that was good enough :P
Anyway, for the future plan, I think about making the Cg support tool I use a little more customizable as I would have to create 2 major themes for the game (heaven scene and hell scene) and it won't be the best of idea to hardcode everything when I need to change parameters and shader programs for every stage.
Thinking about it, I haven't been putting much thought in that... and my code is a freaking mess, much like a huge bandage wrapper attached with chewing gum to the Torque engine. Hmm... that isn't good is it?
I got to think more about it soon, but considering the Germany vs Poland match is starting soon, I guess I'll postpone that to sometime in the future :P
Let me show you the original game screenshots that I've used TGE in:

I do find the results to be pretty decent. Though not state of the art graphics, it wasn't shabby, and looked good to my early trial with a number of casual game players (relatives, friends popping by my home :P).
After presenting that to my customers, I've found the major comment is that they wanted the scene to look more surreal. After talking through it, they wanted some sort of glow effect to make the scene look unreal or like in the game scenes from heaven or hell. Though I attached lights to my player character, that light wasn't enough glow.
I had a few workarounds that I thought about doing. The major problem is that I can't implement things that require too many CPU cycles considering the huge demand at the present. The first I thought to do was to was to add particle effects to the player. That was kind of taking the focus off the point I didn't implement the glow-effect. The other is to double render the player and use different blending options to get the player glow. This method requires more rendering passes, and since the current game is extremely taxing on the CPU/memory, I've decided not to do this. I remember I used to use the DRL resource, and I liked it extremely. However as my game is already using too much CPU, I didn't think I should use it with this project. The last idea that came to mind is to use Cg to implement the glow effect. This is an ideal solution as it places less stress on the CPU as the extra processing is sent to the GPU.
On a side note, I could always simply ignore the request, but since I had time (was a few weeks ahead of schedule) I decided to try to experiment by adding Cg support to TGE.
The first part of was easy. Integrating Cg to any program is easy. There are many resources that point to that in the Internet. I myself also did write a few DirectX + Cg programs before. The next point is to write some vertex/pixel shader programs to create the glow. In this part I used to work with my own Glow effect in RenderMonkey before so that was a huge help. On a sidenote, there are also many useful resources that is useful on this topic and the one that I liked was from the following url: (collective.valve-erc.com/index.php?go=tron1). As I had some parts of this done already, the rest was for me to figure a way to merge it with TGE which seem quite a difficult task at the beginning.
During the first few days of implementing, I had a torrid time getting things right. At times, everything crashed, at times I get things opposite of what I wanted. As noted, the following picture shows alittle about some of the things gone wrong:

After a little more probing, I managed to fix a few more things, though unfortuantely I had the whole picture oversaturated instead of making it look like glowing. Also there were many rendering problems like when the scene became too saturated, the characters all disappeared! Now that is what I call bad programming on my part :P

However after a period of debugging, and going through the rendering engine TGE, things were dawning. The TGE rendering engine is rather decentralized so it takes some time to go through the different parts of the engine to find what I wanted. Anyway, after another sleepless night, programming along with watching the WorldCup, somehow I managed to get things alittle like what I wanted.

From the last pic, there is a slight glow effect with the whole scene which is basically the effect I wanted. Though the effect was created, I don't think it is adequate yet. I believe I need to tweak things comprehensively to make it look better. However, I was more preoccupied of getting things done than actually making it look good since the start, so I guess within the short period of time, that was good enough :P
Anyway, for the future plan, I think about making the Cg support tool I use a little more customizable as I would have to create 2 major themes for the game (heaven scene and hell scene) and it won't be the best of idea to hardcode everything when I need to change parameters and shader programs for every stage.
Thinking about it, I haven't been putting much thought in that... and my code is a freaking mess, much like a huge bandage wrapper attached with chewing gum to the Torque engine. Hmm... that isn't good is it?
I got to think more about it soon, but considering the Germany vs Poland match is starting soon, I guess I'll postpone that to sometime in the future :P
About the author
An Educator moonlighting as the Technical Lead at the indie game development studio called Flying Pig Game Studio
#2
06/14/2006 (11:39 am)
Very nice .plan! From customer feedback to visual glory.
#3
06/14/2006 (11:42 am)
looks pretty sweet, but did you know theres already a game called Heaven and Hell?
#4
Thanks for the tip.
Actually the game is supposed to be called "Tribuum Kran PajonPai Daeng Narong La Sawang" which is like translated to "The Three Kingdoms and the Adventure Through Heaven and Hell". I have to admit that I have trouble calling that name (or I might even have got the name wrong O_o), that our team just used the nick of it as Heaven and Hell (or Hell and Heaven). To make it even more brief, called it HELL, but that is only a joke - the project isn't that bad and doing something that deals with Good Karma is good for a change :P
06/14/2006 (11:52 am)
@ JosephThanks for the tip.
Actually the game is supposed to be called "Tribuum Kran PajonPai Daeng Narong La Sawang" which is like translated to "The Three Kingdoms and the Adventure Through Heaven and Hell". I have to admit that I have trouble calling that name (or I might even have got the name wrong O_o), that our team just used the nick of it as Heaven and Hell (or Hell and Heaven). To make it even more brief, called it HELL, but that is only a joke - the project isn't that bad and doing something that deals with Good Karma is good for a change :P
#6
Below is the original StrongHold with the normal TGE:

Attached next is the TGE with my own Glow Effects appended on:

Hmm... I'm getting color blind O_o
06/14/2006 (1:01 pm)
I happen to test my modifications with the original StrongHold example. Below is the original StrongHold with the normal TGE:

Attached next is the TGE with my own Glow Effects appended on:

Hmm... I'm getting color blind O_o
#7
The glow effect has definitely stepped it up a notch, although I do think it could use some more teaking. Still looks a bit oversaturated to me - almost to bright, I want to squint :D
06/14/2006 (1:20 pm)
I thought the first screenshot looked really great - reminds of me of Banjo Kazooie and other worlds that Rare develops.The glow effect has definitely stepped it up a notch, although I do think it could use some more teaking. Still looks a bit oversaturated to me - almost to bright, I want to squint :D
#9
It would be great if you find time to write a small tutorial how to ad such things to the TGE rendering pipeline, or even release it as a pack - I'm willing to pay for one. ;)
06/14/2006 (2:14 pm)
Great work, Pisal!It would be great if you find time to write a small tutorial how to ad such things to the TGE rendering pipeline, or even release it as a pack - I'm willing to pay for one. ;)
#10
06/14/2006 (2:24 pm)
Yes, a resource (similar to the Cg water resource) would be very nice. I'm loving those screenshots. :)
#11
What I really want to work in is this: http://developer.nvidia.com/object/convolution_filters.html
The demo is nvidia hardware only, so thats gotta get knocked out of it, but after that, it could replace DRL 2.0 easily.
06/14/2006 (4:18 pm)
Grin - been working on working in the cg sample from that url for a while now, and good lord its messy. Their blending step initializes 2 pipelines, but their cg code calls for 4. I mostly have it working except the blur step has a tendency to explode into sudden bursts of pure color - I think its because it tries to sample pixels outside the texture area. What I really want to work in is this: http://developer.nvidia.com/object/convolution_filters.html
The demo is nvidia hardware only, so thats gotta get knocked out of it, but after that, it could replace DRL 2.0 easily.
#12
I know you're focussing on glow, but this is where my brain started to go. Keep up the good work.
Hall Of Worlds - For Gamers
EdM|GPGT
PS - I also noticed the counter from the GPGT lesson kit. I'm glad to see that stuff getting used. :)
06/14/2006 (4:36 pm)
Nice. I found the images inspirational. That is, as I looked at the last image (in original post), your textures with the little squigly lines started me thinking about dynamic texturing effects and how it would be cool to associate them with an enemy or NPC. Then as that enemy/NPC approached you would see this effect start up in the terrain. Sort of like an advance warning system.I know you're focussing on glow, but this is where my brain started to go. Keep up the good work.
Hall Of Worlds - For GamersEdM|GPGT
PS - I also noticed the counter from the GPGT lesson kit. I'm glad to see that stuff getting used. :)
#13
http://www.gamasutra.com/features/20040526/james_pfv.htm
06/14/2006 (5:21 pm)
One note about glow - the very excellent tron implementation uses an alpha channel to render only the glow sources.http://www.gamasutra.com/features/20040526/james_pfv.htm
#14
@Paul: Making the DRL bloom (and DRL in general really) use shaders massively improves FPS. Try it out. It makes a fun weekend project. As for using alpha channel as a mask for a glow shader, keep in mind that on nVidia cards you must specifically request destination alpha, and you'll need to do a bit of tweaking in winWindow.cc to prevent Torque from overriding your pixel format with destination alpha.
06/14/2006 (7:13 pm)
@Pisal: Starter.fps will look better with glow if you disable the TLK overbright.@Paul: Making the DRL bloom (and DRL in general really) use shaders massively improves FPS. Try it out. It makes a fun weekend project. As for using alpha channel as a mask for a glow shader, keep in mind that on nVidia cards you must specifically request destination alpha, and you'll need to do a bit of tweaking in winWindow.cc to prevent Torque from overriding your pixel format with destination alpha.
#15
For some reason the half-life version is using vertexs to perform the blur step, and I could only get texcoord0 to work, not texcoord1+. So I scrapped their blur cg code and built my own.
Also with all the cg work that people are doing, there needs to be a generic resource for loading cg - theres a lot of copy, paste and rename going on.

With glow

Without glow
06/14/2006 (8:32 pm)
I finally got my version of the glow effect working. Right now with a quartersize buffer its a 25% fps hit.For some reason the half-life version is using vertexs to perform the blur step, and I could only get texcoord0 to work, not texcoord1+. So I scrapped their blur cg code and built my own.
Also with all the cg work that people are doing, there needs to be a generic resource for loading cg - theres a lot of copy, paste and rename going on.

With glow

Without glow
#17
The resource isn't complete at the moment. Its still in the early beta stages and is rather dangerous to implement considering that I haven't tested it in thouroughly. Anyway once it is done and after some little more strenous testing, I plan to release the resource soon.
@ Aaron Ellis
I believe the Water resource for TGE is done with Cg also if I'm not mistaken. If I'm not mistaken there is a person who has integrated the Water Resource with DRL 2.0 resource that Alex "Delerium" Scarborough worked with and that could be a winning combo for your project :)
@Paul Jan
Thanks for the tip on Cg! Regarding Cg resources, haven't put much thought in it. I was just thinking about proping up my engine and figuring how to make it easier for me customize things on my project.
@Edward F. Maurina III
The book was great reference guide to Torque! Tells everyone here to buy a copy!
p.s. I was hoping someday for an autographed copy of the Game Programmer's Guide to Torque :P
@ Alex "Delerium" Scarborough
Thanks for the tip! I haven't thought much about the TLK, will make sure to go through it :)
06/15/2006 (2:13 am)
@Alexander "taualex" Gaevoy The resource isn't complete at the moment. Its still in the early beta stages and is rather dangerous to implement considering that I haven't tested it in thouroughly. Anyway once it is done and after some little more strenous testing, I plan to release the resource soon.
@ Aaron Ellis
I believe the Water resource for TGE is done with Cg also if I'm not mistaken. If I'm not mistaken there is a person who has integrated the Water Resource with DRL 2.0 resource that Alex "Delerium" Scarborough worked with and that could be a winning combo for your project :)
@Paul Jan
Thanks for the tip on Cg! Regarding Cg resources, haven't put much thought in it. I was just thinking about proping up my engine and figuring how to make it easier for me customize things on my project.
@Edward F. Maurina III
The book was great reference guide to Torque! Tells everyone here to buy a copy!
p.s. I was hoping someday for an autographed copy of the Game Programmer's Guide to Torque :P
@ Alex "Delerium" Scarborough
Thanks for the tip! I haven't thought much about the TLK, will make sure to go through it :)
#18
@ Alex "Delerium" Scarborough
Is DRL now shader driven? I wonder if it will be possible to have a shader bloom and motion blur effects?
06/15/2006 (2:18 pm)
@Pisal: Thanks. @ Alex "Delerium" Scarborough
Is DRL now shader driven? I wonder if it will be possible to have a shader bloom and motion blur effects?
#19
06/15/2006 (4:07 pm)
@Alexander "taualex" Gaevoy: No, DRL isn't shader driven. However, making it shader driven would drastically improve performance and open the door to a lot of cool effects.
#20
06/17/2006 (7:55 am)
Dear Paul Jan, I was planning to have a chat with you. I was wondering how could I contact you considering there are no public details that I can contact you? Could you email me your contact? Thanks!
Torque 3D Owner Rubes