Game Development Community

TGE w/ Bumpmapped Interiors (using the CG runtime)

by Kevin Johnson · 09/20/2004 (12:57 am) · 122 comments

Download Code File

Hacking in CG

First let me start off by saying: THIS is not poor man's TSE.
Do some digging for Hobiticus' platformCG implimentation if you are looking for that .. :)

The code for this resource is NOT complete, and its mostly stolen from various elders in the community. Its the code from when i just got this working. As such there are demented comments, leftover variables, commented out sections of code and stuff that probably doesn't work like i thought it did, but hey.. ya get what ya pay for... What is shown here is a relatively painless way to add CG shader support to a Torque class, please forgive the messiness.
If you mess around/extend this please stick with TSE's model of material based shaders,
as it'll make porting go quicker.



In this resource we will be adding a dot3 bumpmapping fragment shader to the interrior class.
I picked CG because TGE is an openGL engine. It would be helpful if someone were to port this to GLslang..nudge, nudge,wink,wink.


PRELIMINARIES
1. Download and install the cg toolkit from developer.nvidia.com and set up your compiler for its use and Verify everything works
2. You should have a basc idea how cg works in relation to an opengl application.I have listed some great referneces below
3. download and unzip the archive into a temporary folder. It contains a hijacked version of this resource.
4. Grab a cup of your drink of choice, and get ready for some HOT TGE shader action

LETS GO

First thing you gotta hack is the CG includes. Open cgGL.h

and change

#include

to

#include


Now do a visual merge of your codebase with the ones from the archive, I AM NOT responsible for over-written files!!

(The ones in the archive are taken from 8/24 HEAD)
dgl\materialPropertyMap.cc
dgl\materialPropertyMap.h
interiors\interior.cc
interiors\interior.h
interiors\interiorInstance.cc
interiors\interiorRender.cc

When you finially get it to compile...

In your game directory (example) directory put CG\2TUfp20dot3.cg
I also have cgc.exe in that same directory


SCRIPT HOOKS
in data\init.cs
add:

exec("./interiors/propertyMap.cs");


and add propertyMap.cs and all the normal maps to the interiors directory
the normalmaps for the starter.fps demo can be found here

then fire it up and you should be (graphic card dependancies aside) drooling over TGE bump mapping...

NOTES
*Interior::renderARB_FC in interiorrender.cc is where all the magic happens.

*The effecting lightvector is hardcoded for simplicity at interiorrender.cc line#1147
glColor4f(1,1,1,baselevel);
you can change it to something like:

glColor4f(lightDir.x,lightDir.y,lightDir.z,1.0);

where lightDir = gClientSceneGraph->getLightManager()->getLight([whateverindex]).mPos -[objectposition] (or is it the other way around??)

then normalize

* running interiors through a normal map really darkens em up....but i think it looks cool..also since the shader is dealing with the basetexture + lightmap, you can come up with some real neat effects with pulse (entity)lights..


I think thats it.. Have fun and play with the shader (CG and HLSL share alot) and get ready for TSE.. its going to change the world..
This code released on the BGL (Ben Garney License.."if you use this in your game send me a copy")
also if your game is a MMO you owe my wife a free account..lol
oh and kudos to whoever did those textures..the textures really make it..

let the frenzy begin

References


www.nvidia.com/object/cg_toolkit.html

developer.nvidia.com/object/hello_cg_tutorial.html

www.fusionindustries.com/content/lore/code/articles/fi-faq-cg.php3

nehe.gamedev.net/data/lessons/lesson.asp?lesson=47

www.3ddrome.com/articles/cgshaders.php

www.gamedev.net/reference/articles/article1903.asp

www.codesampler.com/oglsrc.htm

www.ronfrazier.net/apparition/index.asp?appmain=research/advanced_per_pixel_ligh...
#81
06/20/2006 (7:45 am)
@T Squared,

Ok, I had that problem too. I'm using 1.4. I fired off an email to John Kabus to make sure I could upload to the private TLK forums my code. When I hear back from him I'll post a link. I've got them all zipped up and it's all the .cc and .h files needed for Torque 1.4, DRL 2.0, TLK 1.4, the Water Upgrade and DOT3 Bumpmapping to work together. With Winmerge it should only take a couple minutes to see what's not right and causing the purple color thing. It was a pain in the neck to figure that out as I recall, but I really don't remember what I finally did to fix it. Hopefully I'll have something for you by tomorrow. If I don't hear from him, I'll post it in the Private forums, I'm pretty sure he gave me the OK before, but I can't seem to find the correspondence...it may have been in the forums themselves I just can't remember.

- Alan
#82
06/20/2006 (9:02 am)
I see a couple of requests for normal maps.
Adobe Photoshop Normal Map and DDS Authoring Plug-ins Installer Version 7.83 (.exe) 3.8 MB
The xxxDOT3.jpg files are normal maps, DOT3 is the shader method used to display them.
This tool creates quick and dirty normal maps based off of a texture.
Be careful you keep the normal map "light" because the effect can greatly darken your texture.
A true normal map is calculated from a 3D render, I won't go into detail but ZBrush is my team's tool of choice.
For the sake of time, I use the plug-in above.
Normal maps are not a light subject and anyone seriously using this resource should research them in order to get the most "bang" out of the DOT3 shader.
It's great to get CG shaders in your game so you can post a link showing your cool screenies (like me) but it's very important to understand that shaders are a serious art.
The hardest part of this resource for me was to get past "Woot, it compiled!" and start using the property map script file in the interiors folder and chopping my playGUI to work with this and the water mod.
CG shaders are great and cross-platform but don't think it's a replacement for TSE.
Alot of work went into TSE to take advantage of the shaders it uses (and doesn't use CG AFAIK).
I own TSE but at this stage in my project, I'm not worried about shaders, eye candy doesn't make a game.
During my nub mission to get this in I left out the lines that unloaded the shader by accident.
The DOT3s began to show up on my DTS objects in a very odd manner.
With some work, applying the CG DOT3 shader to DTS objects should be fairly easy to an experienced coder.
Most of the ppl I have talked to (some wouldn't even respond) who have accomplished this are "hoarding" the code snippits.
If anyone knocks this piece out, please post it for the rest of us in the COMMUNITY. =)
If I complete it by some stroke of nub luck I will post it here on GG.
Thanks again for this resource!

Ari
"I see alot of indies forget where they come from after they succeed. Let's open up live beta, talk to our testers/players daily and keep it free as long as possible. We owe the community and indie is about fun and sharing. The minute it's not, you're not really an indie anymore." BrokeAss Games Mission Statement
#83
06/20/2006 (12:57 pm)
Alan, thanks it work great. Now I got do some reach to see how to build them good model. Thanks again.
#84
06/20/2006 (3:06 pm)
I find alot information on how to make normalmaps. I try to figure how to get them to show on the interriors. Do I apply them with the propertymap or you have apply them in the build process? There any tutorial on this.
#85
06/20/2006 (4:47 pm)
@BrokeAss Games
Thanks for the info about the plug in, but i already knew about that :P. And i also know how normal maps come from. After all i did go to a school based on that stuff :P. but thanks anyway for the info. But my request wasnt for the normal map specifically. it was for an interior with normal maps with them. At first i didnt understand how dif worked. whether it needed to know the corresponding normal map name to be applied. but now as i realize that you just attach the normal map to a texture.

But Doh!, i'm an idiot, i totally forgot to include the CG file! i placed the water cg, but i forgot to place the dot3 cg. it works great now. thanks guys.

Now, time to try to port this to 1.4

edit: it works but now i get this weird flickering bug.

www.geocities.com/tsune_l/s1.JPG
btw is there a way to add specularity to these dot3 bumpmap objects?
#86
06/20/2006 (6:10 pm)
@T Squared

Yeah, somethings still not right. I just sent my files off to John K. he's going to give them a once over and then if I haven't hosed too much stuff he will be posting them as a private resource. Here's what you should have in a clean build of Torque 1.4 w/TLK 1.4, DRL 2.0, CG Water and Bumps:

www.reallyreallygoodthings.com/screens/screenshotTLKDRLBUMP.jpg
- Alan
#87
06/20/2006 (7:10 pm)
@Alan,
nice!, thanks alot. Ya i got it to work with my CG water+DRL+bump, but the bumps now are even more screwy in 1.4 TLK. well from far away the bumps look fine, but as you go close up. the bumps look really wacked up. and funny colors.

So when should we be expecting this new updated resource?

BTW, if thats what it should look like in a clean build in tlk 1.4, why dont you post a resource of a cgwater+drl+dot3 resource?

edit:
okay i got it working on 1.4, but still have that flickering problem. but its not like it happens once in a while. it always happens.

here the source for just the Dot3 maps on a clean build of TLK 1.4. it works fine, but with that flickering problem. can you check it out and tell me what i may be doing wrong.

e2g.50webs.com/TLK1.4.DOT3.rar

www.geocities.com/tsune_l/1.4.jpg
#88
06/20/2006 (9:22 pm)
I think I have figure it out. I just want make sure this is correct. Build your normal map. Build your interrior with rock064 texture. Then add it to the propertyMap.cs like this

addMaterialMapping("rock064", "normal: starter.fps/data/interiors/rock064DOT3 0.5");

Please let me know if this is right.
#89
06/20/2006 (9:44 pm)
ya, thats correct Michael.
#90
06/21/2006 (12:42 am)
Arg. ran into another bug. what ever is being applied to the cg water, if being affected to the normal map interiors. i can see the sky reflection and the water color overlay on the boxes as soon as i merged it with cgwater+drl.

With Water texture.
www.geocities.com/tsune_l/s2.jpg
Without water texture
www.geocities.com/tsune_l/s3.jpg
But there still some weird looking transparency that bleeds through the texture
www.geocities.com/tsune_l/s4.jpg

EDIT:
IT works fine for me now :) thanks alan.
#91
07/01/2006 (10:50 am)
lol kinda cool though
I got this in but I cant see any difference in the textures, done the material mappings, exec'd it etc. Nothing wrong in log
#92
07/01/2006 (1:33 pm)
Where I could download textures?

http://www.intersticesthegame.com/~lagalot/images/normalmaps.zip - file not found
#94
07/07/2006 (6:18 am)
Gettign the flickering too:
ATI Radeon 9600XT
#95
07/07/2006 (6:38 am)
@Mincetro Deadalus Slayer
Ya, i've done many Testings, and I concluded to this. If you own an ATI card, it will flicker. If you own a Nvidia Card, it will work perfectly fine. I've tested it with an ATI x550, and Nvidia GF 5200, and a few other ATI's

This could be because CG is an Nvidia api.
#96
07/10/2006 (2:15 pm)
I haven't seen a flicker when it comes to the CG water resource and am using a ATI Radeon 9600. Is there something drastically different with this resource in the implementation of the API that would make such a difference in the effect of flicker towards ATI cards?

I have looked at the code and didn't really see anything horribly different.
#97
07/11/2006 (3:08 am)
@Ron
maybe you manage you fix the ati bug in your implementation. would you mind uploading it online for me to test out then?
#98
07/12/2006 (4:22 pm)
Yeah never mind, I loaded this up and the flicker you guys are seeing is now there, took back out your code and it is gone.

I also wanted to ask, is there someway to make interiors using this not have to have the additional CG file and still look normal? My buildings I had previously are mostly white until you are right next to them and then you can see a polygon or two with texture.
#99
07/12/2006 (9:53 pm)
You can turn bump off in your mission editor.
#100
07/13/2006 (7:38 am)
Is there any way to set up the DOT3 file so it would work well with a glass interior object that allows transparency?