Game Development Community

TGE w/ Bumpmapped Interiors (using the CG runtime)

by Kevin Johnson · 09/19/2004 (5:57 pm) · 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...
#101
07/15/2006 (11:19 am)
Can someone answer this for me. If I am not having issues with CG water or CG DRL, why would I have problems with this?
#102
07/15/2006 (3:09 pm)
no, it shouldnt make a different. Why not try posting on the forum.
#103
07/16/2006 (3:50 pm)
Well T Squared I did my best to try to find any errors in your code that would lead to this issue. It seems your implementation to the updated version is about as accurate as you are going to get. Is this issued with the ATI cards something that existed in the original code?
#104
07/16/2006 (6:19 pm)
T Squared I ran this in debug and I believe this is where some of the problem is from my console.log

CG:callback set
CG: found frag profile...
CG:callback set
CG:interior initIntShader started
CG: found frag profile...
CG:interior InitIntShader() finished
0
#######CG ERROR: CG ERROR : The profile is not supported.
(null)
CG:callback2 set
CG: initializing
SceneGraph: InitScreenglow() finished
#105
07/17/2006 (1:13 pm)
Just a thought, that pattern looks similar to the pattern I used to see when I had detail mapping screwed up in my TLK. Also would make sense why it only happens at close range. Do you have a detail map defined for this texture already in another file?
#106
07/22/2006 (2:07 am)
@Dave - I am not really seeing anything, but I could be wrong. I am just using T Squared's work and trying to see if I can help. I am confused how it could possibly be an ATI issue considering I am using the CG DRL and the CG water upgrade and it looks flawless. Also, I had one of my freinds with a New Nvidia card try it and he sees the problem too.
#107
08/06/2006 (6:35 am)
Thank you for this ressource!

I just tested on nvidia work pretty good,
I tested on 2 ati models, the flickering problem appear.
Any fix are welcome ^^

------
I Managed to get the sunlight to act on the bump, but where should I look to make a mounted light(fxLight) acting on the bump ?
I am a novice but still I'd like to see what I can do... :)

thx
#108
11/21/2006 (11:09 pm)
Anyone have any luck with the ATI flicker problem yet? This would be an incredible thing if it would work for ATI as well.
#109
11/22/2006 (8:46 am)
Yes, I have.
#110
11/22/2006 (10:58 am)
Oh, would you mind sharing?
#111
11/22/2006 (2:41 pm)
@Fucifer
If you fixed the problem. it would be a great solution for the comunity.
#112
11/22/2006 (5:12 pm)
I am still test this but right it is working pretty good. I want make sure before I release it but I will release to the community.
#113
11/23/2006 (10:04 am)
was it just a shader script mod? or did you have to modify the actual engine code?
#114
12/08/2006 (4:14 pm)
Has anyone gotten this to work with TGE 1.5? It compiles without error for me, but does not render the bump map.
#115
01/12/2007 (1:07 pm)
Would anyone happen to have the DOT3 textures that are listed in the propertyMap.cs file?

addMaterialMapping("stonewall", "normal: starter.fps/data/interiors/stonewallDOT3 0.5");
addMaterialMapping("wall_panel01", "normal: starter.fps/data/interiors/wall_panel01dot3 0.5");
addMaterialMapping("Floor_slate01", "normal: starter.fps/data/interiors/Floor_slate01DOT3 0.5");
addMaterialMapping("oak2", "normal: starter.fps/data/interiors/oak2dot3 0.5");
addMaterialMapping("wall_block01", "normal: starter.fps/data/interiors/wall_block01DOT3 0.5");
addMaterialMapping("thatch", "normal: starter.fps/data/interiors/thatchDOT3 0.5");
addMaterialMapping("concrete", "normal: starter.fps/data/interiors/concreteDOT3 0.5");
addMaterialMapping("Floor_tile01", "normal: starter.fps/data/interiors/floor_tileDOT3 0.5");
addMaterialMapping("oak2_end", "normal: starter.fps/data/interiors/oak2_endDOT3 0.5");
addMaterialMapping("WallNoGroove", "normal: starter.fps/data/interiors/WallNoGrooveDOT3 0.5");

They weren't in the uploaded .zip file, and the web link hosting the files does not exist anymore.
#116
01/12/2007 (3:19 pm)
Yes, I have copy of them. I will email them to you.
#117
01/15/2007 (12:54 am)
Hi guys,

Fucifer, any dates on when your solution will be released? if it has could you post a link, I am really bad at using the Search tool and cant find it. Thanks.

This is great work, I didnt realise this was possible with TGE until I saw this thread. Exciting stuff indeed.
#118
01/15/2007 (5:01 am)
I should have it ready in about another month, I had to start over because my computer crash when someone try to hack it. But good news is had alot notes take so it just matter of time put it all back in and test it.
#119
12/16/2007 (6:22 pm)
Hello,

I've been experiencing a problem dumping this in with the CG water. I've got it to compile without error (had to change the names of the Cg Water profiles to get it to work). That solved all the linking errors, and now I have it running. The bumps work, and they look beautiful, but now the whole world went screwy. There seems to be a reflective surface underneath the character.

Photo Sharing and Video Hosting at Photobucket
#120
12/16/2007 (6:23 pm)
Dang, can't put the picture in. Here's the link:

http://s200.photobucket.com/albums/aa310/thehas1/?action=view¤t=cg.jpg