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...
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...
#42
"First thing you gotta hack is the CG includes. Open cgGL.h
and change
#include
to
#include
" end quote
c:\torque\sdk\engine\interior\interior.cc(19) : fatal error C1083: Cannot open include file: 'sim/frameAllocator.h': No such file or directory
interiorCollision.cc
c:\torque\sdk\engine\interior\interiorcollision.cc(795) : error C2065: 'getFlippedPlane' : undeclared identifier
c:\torque\sdk\engine\interior\interiorcollision.cc(963) : error C2440: 'initializing' : cannot convert from 'int' to 'class PlaneF'
No constructor could take the source type, or constructor overload resolution was ambiguous
interiorInstance.cc
c:\torque\sdk\engine\interior\interiorinstance.cc(28) : fatal error C1083: Cannot open include file: 'sim/frameAllocator.h': No such file or directory
interiorRender.cc
sceneObject.cc
c:\torque\sdk\engine\sim\sceneobject.cc(1962) : error C2039: 'getFlippedPlane' : is not a member of 'Interior'
c:\torque\sdk\engine\interior\interior.h(151) : see declaration of 'Interior'
Error executing cl.exe.
still trying to figure it out.
05/29/2006 (11:20 am)
I've got the 8 errors like you had. but reduced it down to 5. by doing quote "First thing you gotta hack is the CG includes. Open cgGL.h
and change
#include
to
#include
" end quote
c:\torque\sdk\engine\interior\interior.cc(19) : fatal error C1083: Cannot open include file: 'sim/frameAllocator.h': No such file or directory
interiorCollision.cc
c:\torque\sdk\engine\interior\interiorcollision.cc(795) : error C2065: 'getFlippedPlane' : undeclared identifier
c:\torque\sdk\engine\interior\interiorcollision.cc(963) : error C2440: 'initializing' : cannot convert from 'int' to 'class PlaneF'
No constructor could take the source type, or constructor overload resolution was ambiguous
interiorInstance.cc
c:\torque\sdk\engine\interior\interiorinstance.cc(28) : fatal error C1083: Cannot open include file: 'sim/frameAllocator.h': No such file or directory
interiorRender.cc
sceneObject.cc
c:\torque\sdk\engine\sim\sceneobject.cc(1962) : error C2039: 'getFlippedPlane' : is not a member of 'Interior'
c:\torque\sdk\engine\interior\interior.h(151) : see declaration of 'Interior'
Error executing cl.exe.
still trying to figure it out.
#43
The location of "frameAllocator.h" is different than in this interior.cc include, you just have to modify the include to point to "core/frameAllocator.h".
On the other errors, that's a bit more tricky. Take a look at your backed up interiorCollision.cc, interiorinstance.cc, interiorRender.cc and sceneObject.cc files (You did back them up, right?) and do a diff with Winmerge comparing the backup to your new ones, with all of these resources in place it's a delicate process to get them working together happily. Just look for in particular blocks referencing "getFlippedPlane" that might have been romoved with the new merge and work them back in.
If I ever get a spare minute, I really am hoping to be able to upload to the TLK private forums all the modified cc & h files, but that might be a while...
- Alan
Really Really Good Things Studio
05/29/2006 (12:38 pm)
@Michael & T-Squared:The location of "frameAllocator.h" is different than in this interior.cc include, you just have to modify the include to point to "core/frameAllocator.h".
On the other errors, that's a bit more tricky. Take a look at your backed up interiorCollision.cc, interiorinstance.cc, interiorRender.cc and sceneObject.cc files (You did back them up, right?) and do a diff with Winmerge comparing the backup to your new ones, with all of these resources in place it's a delicate process to get them working together happily. Just look for in particular blocks referencing "getFlippedPlane" that might have been romoved with the new merge and work them back in.
If I ever get a spare minute, I really am hoping to be able to upload to the TLK private forums all the modified cc & h files, but that might be a while...
- Alan
Really Really Good Things Studio
#44
C:\Torque\SDK\engine\sim\sceneObject.cc(1962): error C2039: 'getFlippedPlane' : is not a member of 'Interior'
C:\Torque\SDK\engine\interior\interiorInstance.cc(189): error C2039: 'getServerConnection' : is not a member of 'NetConnection'
C:\Torque\SDK\engine\interior\interiorInstance.cc(189): error C3861: 'getServerConnection': identifier not found, even with argument-dependent lookup
max2dtsExporter Max4 fatal error LNK1181: cannot open input file 'engine.lib'
...
Any help apreceated.
06/01/2006 (4:16 am)
Is this working for 1.4? becauseim getting these errors:C:\Torque\SDK\engine\sim\sceneObject.cc(1962): error C2039: 'getFlippedPlane' : is not a member of 'Interior'
C:\Torque\SDK\engine\interior\interiorInstance.cc(189): error C2039: 'getServerConnection' : is not a member of 'NetConnection'
C:\Torque\SDK\engine\interior\interiorInstance.cc(189): error C3861: 'getServerConnection': identifier not found, even with argument-dependent lookup
max2dtsExporter Max4 fatal error LNK1181: cannot open input file 'engine.lib'
...
Any help apreceated.
#45
06/01/2006 (2:15 pm)
hey!.. did anyone ever fix the ati bug??
#46
06/01/2006 (3:51 pm)
Not yet, it seems. Alex Scarborough is porting the interior bump-mapping, DRL2.0 and water resource to GL, which will enable them to work properly on any video card supporting the extentions.
#47
does any one have the normap map of the interiors in starter.fps that can be uploaded ?
06/07/2006 (8:07 am)
the normalmaps.zip link is down does any one have the normap map of the interiors in starter.fps that can be uploaded ?
#48
06/07/2006 (10:50 am)
where did you find the normalmaps.zip resource?
#49
and add propertyMap.cs and all the normal maps to the interiors directory
the normalmaps for the starter.fps demo can be found here
and it appears that the link is down
I just want to give it a try and see how bump mapping in torque is like..
I hope I'm not interfering with anyone's intellectual property ..
06/07/2006 (10:08 pm)
There is a link on this page that says and add propertyMap.cs and all the normal maps to the interiors directory
the normalmaps for the starter.fps demo can be found here
and it appears that the link is down
I just want to give it a try and see how bump mapping in torque is like..
I hope I'm not interfering with anyone's intellectual property ..
#50
06/08/2006 (12:17 am)
Has anyone here tried to use this while having the water upgrade installed? Just noticing both are using the same system and most of the same functions.
#51
No, not yet, i'm probably going to try to get this resource working alone first. and as soon as i get that working, i will then try to implement with with it after. then i will release another resource with both cg water and drl 2.0 with this interior dot3 map with it as well. hopefully i will have it up in a week or so, when i have time.
@Kevin Johnson
BTW, did you happen to have a 1.4 version of this resource. i noticed with win merge, the code looks like it was design for 1.3.x TLK. if you happen to got it working on 1.4 can you post that resource. would make my life a little easier.
06/08/2006 (1:01 am)
@RonNo, not yet, i'm probably going to try to get this resource working alone first. and as soon as i get that working, i will then try to implement with with it after. then i will release another resource with both cg water and drl 2.0 with this interior dot3 map with it as well. hopefully i will have it up in a week or so, when i have time.
@Kevin Johnson
BTW, did you happen to have a 1.4 version of this resource. i noticed with win merge, the code looks like it was design for 1.3.x TLK. if you happen to got it working on 1.4 can you post that resource. would make my life a little easier.
#52
engine\interior\interiorRender.cc(52) : error C2146: syntax error : missing ';' before identifier 'cgInteriorContext'
engine\interior\interiorRender.cc(52) : error C2501: 'CGInteriorcontext' : missing storage-class or type specifiers
engine\interior\interiorRender.cc(52) : fatal error C1004: unexpected end of file found
Here the lines from the code
TextureHandle normalHandle; //line 51
CGInteriorcontext cgInteriorContext; //line 52
I have the cg water working.
06/08/2006 (7:22 am)
Yes I have been work this with TLK 1.4. I have three errors left but dont know what cause them.engine\interior\interiorRender.cc(52) : error C2146: syntax error : missing ';' before identifier 'cgInteriorContext'
engine\interior\interiorRender.cc(52) : error C2501: 'CGInteriorcontext' : missing storage-class or type specifiers
engine\interior\interiorRender.cc(52) : fatal error C1004: unexpected end of file found
Here the lines from the code
TextureHandle normalHandle; //line 51
CGInteriorcontext cgInteriorContext; //line 52
I have the cg water working.
#53
btw if you want a res of cg water +drl, i've posted a res up at
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10591
06/08/2006 (10:02 am)
oh, i've got cg water working with ease. this resource seems like its going to be a bit of work. but for 1.4, can you upload you your source someone, i'll take a look at it. btw if you want a res of cg water +drl, i've posted a res up at
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10591
#54
okay, to fix that problem, just include
in interiorRender.cc
Now the lib file compile, but i get this error when i compile the Torque app
06/10/2006 (12:43 pm)
@Michael Prewer okay, to fix that problem, just include
#include "cg\cg.h" #include "cg\cgGL.h"
in interiorRender.cc
Now the lib file compile, but i get this error when i compile the Torque app
interior.obj : error LNK2001: unresolved external symbol "public: static bool Interior::smRenderDetailMaps" (?smRenderDetailMaps@Interior@@2_NA) interiorInstance.obj : error LNK2001: unresolved external symbol "public: static bool Interior::smRenderDetailMaps" (?smRenderDetailMaps@Interior@@2_NA) interiorRender.obj : error LNK2001: unresolved external symbol "public: static bool Interior::smRenderDetailMaps" (?smRenderDetailMaps@Interior@@2_NA) ../example/TorqueLightingKit.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe.
#55
@Michael Prewer
I don't think that's a CGInteriorcontext type change line 52 to
06/10/2006 (12:48 pm)
Just a guest @Michael Prewer
I don't think that's a CGInteriorcontext type change line 52 to
CGcontex cgInteriorContext;
#56
06/10/2006 (6:58 pm)
Yes I would love to have this in my game please someone upload the 1.4 code
#57
06/16/2006 (8:37 am)
Hey guys, Looks like your getting close! I never really did anything more with this. Im sure the codebase was more like 1.2, i that. Ive been outta the torque loop for some time (been writting my own point and click style adventure engine - in managed directx no less) until TSE hits prime time.
#58
Could you port this to TGE 1.4? I've given up trying to get it to work. i dont know/understand how the engine really works to well. so its harder for me to debug anything.
06/16/2006 (10:02 am)
@KevinCould you port this to TGE 1.4? I've given up trying to get it to work. i dont know/understand how the engine really works to well. so its harder for me to debug anything.
#59
Screenshots
Worked great on a heavily modified TGE 1.3 w/ TLK 1.3.5 and CG water.
I had to wrench on it a little because I was using the water mod also.
Ari
06/16/2006 (2:36 pm)
Thanks for this resource!Screenshots
Worked great on a heavily modified TGE 1.3 w/ TLK 1.3.5 and CG water.
I had to wrench on it a little because I was using the water mod also.
Ari
#60
06/17/2006 (1:28 am)
arg!, okay i got it to compile no problem on 1.4 TLK, but it crashes everytime i load into a map.
Torque 3D Owner iHugMedia
I'm using TLK 1.4 and also have the CG water resource.