Game Development Community

dev|Pro Game Development Curriculum

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...
Page «Previous 1 2 3 4 5 6 7 Last »
#1
09/14/2004 (6:28 pm)
Nice!!
#2
09/14/2004 (7:02 pm)
Ty Kev for the great Tut. I will try this out as soon as possible. As soon as the download link is working anyway.. :)
#3
09/14/2004 (7:06 pm)
The download link seems broken, when can it be ready again? Thanks.
#4
09/14/2004 (8:11 pm)
ok looks like the link works now. and the zip file updated.
#5
09/15/2004 (4:14 pm)
OK i got this up and running only thing is I only see it as the normal map overlayed on the regular image. It just looks like a flat dark blue version of the texture. I followed the tutorial all the way. Does someone know how to fix this. Also I was getting a similar problem with the detail texture tutorial. In that tutorial there was absolutely no blending is was just one texture layed over the other. Any help is more then appriciated...

EDIT: ok actually I am seeing bump on some of the surfaces. but the bricks show very little evidence of bump. (especially the ground). and the textures do appear almost like a glowing purple (just looks like it is glowing because it is so purple).

I think I will blindly play with the code a bit to see if I can figure the prob. please let me know if anyone else out there is having the same problem...
#6
09/15/2004 (8:39 pm)
what kind of video card are you using? put a breakpoint in and make sure its running the render_arb_fc function. If its not using that one you will need to move the code from render_arb_fc to whatever render loop your card is using. Also does the console log say anything during the CG initialization??

beyond that, i'm not sure. BUT one of my artists was experiencing the same thing on his gf2..but i attributed that to his card, as it looked fine on his roomate's computer..
#7
09/15/2004 (10:00 pm)
Well is there a way to make this universal (for most video cards anyway) I know that One of my computers is running an ATI 9600, the other is running Radeon 320m (laptop). both have run the cg demo on the web page that you first recomended fine. I didn't see anything that I know of on the console log (are you talking about when the black console is up or does it make a log file somewhere?) I am very glad that you are showing concern for my problem and thank you for your time. I will try to find out if it is running through arb loop. If you think of anything else please let me know. And If I find more info out I will let you know.
#8
09/15/2004 (10:06 pm)
This is my console.log says about cg

CG:callback set
CG:interior initShader started
#######CG ERROR:Failed to initialize Frag shader! Hardware doesn't support any of the Frag shading extensions!
-1
#9
09/15/2004 (10:33 pm)
OK I transfered it to my friend's computer. (Nvidia Gforce 5600 FX) and it runs great. (the crossbow and ammo look like they have a white layer on top of the texture but other then that great) So what do you think would be the best way to try to make it work on both systems. (ATI and NVidia support)
#10
09/16/2004 (6:20 am)
Matt, It should be selecting the CG_PROFILE_ARBFP1 profile on ati hardware (9500 +). Do you have the latest catalyst drivers? Does this mean you are volunteering to help me test this on ati hardware? If so send me an email and I'm sure we can make this happen.

also try adding this line to the top of the initshader function

Con::printf("CG: this hardware supports - %s", cgGetLatestProfile(CG_GL_FRAGMENT));

and post the output. It should say CG: this hardware supports - CG_PROFILE_ARBFP1
#11
09/16/2004 (8:40 am)
Ok well I have it workin on my Desktop now (although it has flicker, I will send you a screen ). but the laptop will not do it correctly at all. I guess this doesn't support the mobile ATI cards.

When I typed
Con::printf("CG: this hardware supports - %s", cgGetLatestProfile(CG_GL_FRAGMENT));

(i put this under Con::printf("CG:interior initShader started"); in interiorRender.cc)
the compiler says
error C3861: 'cgGetLatestProfile': identifier not found, even with argument-dependent lookup.....

Does this on both computers.
#12
09/16/2004 (12:01 pm)
[quote]
the compiler says
error C3861:
#13
09/18/2004 (5:03 am)
I'm also getting a glowing purplish look, which appears to be the normal map without the texture blended in.
I added this to both my code and a clean head. It works well in head, just not my base.
I verified I'm using the correct rendering loop, cg init is returning proper as well. The only glaring difference I can see in the two codes, is mine has trans_entity stuff, but I can't really see how that would interfere.

EDIT: Okay, I wasn't using the proper rendering loop. They look so much alike, it's tough telling where you're at :) After adding the code to the rest of the loops, all works well.
#14
09/19/2004 (3:06 pm)
Gforce or ATI erik? cause there seems to be an issue with some ATI cards showing bands
#15
09/19/2004 (6:42 pm)
Only a few ATI Cards support CG i believe, all of NVidia's do.
#16
09/20/2004 (2:11 am)
@Kevin I have a ge fx 5600

How do we control the lighting better? I don't see a glColor3f(1,1,1);
but there is a 4f.
After installing the lighting pack, I'm now playing with some very dark levels. Anything running through cg is fairly well lit, which looks very goofy combined with unlit surfaces.
I pretty much know my dynamic light values, I just don't know how to utilize them.

btw, combine this real bump with the lighting packs fake bump and you get very nice effects.
#17
09/20/2004 (6:16 am)
eric,

just encode the x,y, z of your light vector into the glColor4f with the fourth component being 1.0

change
glColor4f(1, 1, 1, baseLevel);
to
glColor4f(lightVextor.x,lightVector.y,lightVector.z, 1.0);


the shader should do the rest...:)
#18
09/20/2004 (10:41 am)
This seems interesting can some more screenshots be posted?
Also is it workin on all non-mobile ATI cards?
#20
09/20/2004 (12:06 pm)
heres a couple of shots from other posts
www.intersticesthegame.com/images/TGE-CG1.jpgwww.intersticesthegame.com/images/tgelpcg.jpg

edit:hehehe.. im baaaack (sorta)...
Page «Previous 1 2 3 4 5 6 7 Last »