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...
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...
#63
Yeah, you have to give me a bit though, I'm kinda swamped and I have to rip it out of a little more than a stock TGE. ;)
Are you using CG water?
The biggest issue for me was duplicates from the water, all I had to do was rename some stuff.
Ari
06/17/2006 (9:50 am)
@T SquaredYeah, you have to give me a bit though, I'm kinda swamped and I have to rip it out of a little more than a stock TGE. ;)
Are you using CG water?
The biggest issue for me was duplicates from the water, all I had to do was rename some stuff.
Ari
#64
btw did you just drag and drop when you got it working? or did you use winmerge?
06/17/2006 (9:54 am)
no. i wasnt using the the water. just stock TLK. i am trying to first implement it on a stock TLK first before i attemp to get it working with cgwater.btw did you just drag and drop when you got it working? or did you use winmerge?
#66
06/17/2006 (10:05 am)
okay. i got it to finally stop crashing. on some maps. as soon as i merge it with cgwater and drl. but it still crashes everytime i got to relight a scene. when would you think you could post your code up?
#67
Feel free to email me, I'm pretty nub to CG but I'm learning.
Ari
06/17/2006 (10:20 am)
Maybe tommorow night, right now I'm in the middle of prepping another update for my game.Feel free to email me, I'm pretty nub to CG but I'm learning.
Ari
#68
06/17/2006 (10:31 am)
would you not be able to just post your interior.cc/h interiorRender.cc & interiorInstance.cc online?
#69
Visit my website and you'll understand why.
It's dirty (ie. not stock). ;)
Ari
06/17/2006 (10:36 am)
Nope.Visit my website and you'll understand why.
It's dirty (ie. not stock). ;)
Ari
#70
06/17/2006 (10:47 am)
ah. i see. thats understanable. well looking forward to your clean up/strip down source tomorrow :)
#71
06/18/2006 (4:03 am)
Hi, I final got this work with TLK 1.4. I wondering do anybody have the dot3 texture so I can do some testing. Thank you.
#72
Here you go. These are from a texture pack I have been working on. All original from digital camera work. Textures are great, DOT3 textures kinda suck at this point but should be ok for testing. enjoy.
woodCrates
-Alan
Really Really Good Things Studios
Edit: Added dif files.
06/18/2006 (4:24 am)
@MichaelHere you go. These are from a texture pack I have been working on. All original from digital camera work. Textures are great, DOT3 textures kinda suck at this point but should be ok for testing. enjoy.
woodCrates
-Alan
Really Really Good Things Studios
Edit: Added dif files.
#73
06/18/2006 (6:32 pm)
Thanks very much Alan. I will let you know how it thing work out.
#74
@Michael
Hey can you post your code online?
06/18/2006 (8:33 pm)
Ah. finally stop crashing, when relight a scene. thanks alan for the wood crate, but i dont seem to see a bumpmap. i think something was wrong in my code.@Michael
Hey can you post your code online?
#76
06/19/2006 (6:03 am)
cool thanks. i will try this out, and let you know how it goes.
#77
btw i had to comment out
06/19/2006 (5:41 pm)
okay, it compiles great in TLK 1.3.5, but i see no bumpmap. do you have a sample bumpmap i could use. alans one doesnt seem to work. btw i had to comment out
//Teleport GUI Mod
const char* InteriorInstance::getInteriorFileName(){
return mInteriorFileName;
}in interiorInstance.cc
#78
You for sure modified the "propertyMap.cs" addMaterialMapping to point to the directory where the .dif, texture and normal map are stored, right? Like:
addMaterialMapping("woodCrate034", "normal: starter.fps/data/interiors/industrial/woodCrate034H 0.5");
Obviously modified to your own directories. They should work. Thought they aren't very "steep" maps. Does the texture look normal, or does it look dark or what?
-Alan
06/20/2006 (4:54 am)
@T Squared,You for sure modified the "propertyMap.cs" addMaterialMapping to point to the directory where the .dif, texture and normal map are stored, right? Like:
addMaterialMapping("woodCrate034", "normal: starter.fps/data/interiors/industrial/woodCrate034H 0.5");
Obviously modified to your own directories. They should work. Thought they aren't very "steep" maps. Does the texture look normal, or does it look dark or what?
-Alan
#79
Alan, what version are you running your code in?
06/20/2006 (7:09 am)
no, i made sure they were in the right directory. no it just looks like there no bump map at all. looks very flat. i even took the jpg pic, and made it a flat color(red). and it just looks like a big red box. thats with BrokeAss Games code. When i tried it with 1.4 it just looked messed up. every texture just looks like its ofverlayed with the color purple but i think my 1.4 code is just messed as it is.Alan, what version are you running your code in?
#80
I've never seen any cg bump Map on torque 1.4..
mostly what I 've seen on the forums are torque 1.3
tought it would be good to have bump map on torque 1.4 ;)
06/20/2006 (7:15 am)
hmm....I've never seen any cg bump Map on torque 1.4..
mostly what I 've seen on the forums are torque 1.3
tought it would be good to have bump map on torque 1.4 ;)
Torque 3D Owner BrokeAss Games
TLK 1.3.5
Ari