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...
#122
http://www.wizzo-inc.co.uk/downloads/bump_diff_1.5.2.rar
the download is 2.15mb, it includes two screenshots.
i took the materialPropertyMap.cc and materialPropertyMap.h from the resources above..
09/20/2008 (4:14 pm)
i have updated this resource to 1.5.2, it can be downloaded from the address below.http://www.wizzo-inc.co.uk/downloads/bump_diff_1.5.2.rar
the download is 2.15mb, it includes two screenshots.
i took the materialPropertyMap.cc and materialPropertyMap.h from the resources above..
Torque Owner Ron Nelson
I have only had minor issues with it. Do a search for it on the forums.