Game Development Community

dev|Pro Game Development Curriculum

TGE normal mapping

by Koushik · 06/16/2008 (6:22 am) · 47 comments

Download Code File

After being asked about this by a lot of people, I've released this code to the community, when I initially thought I'd polish it and make it part of my larger framework, and release the whole thing once it looks stunning... but that might take a while, and I think it best to satisfy hungry GGers...

You can find a manual outlining the exact procedure (along with some introduction on how to setup scripts and stuff) over Here

The corresponding shaders are attached with this resource. If you find any bugs, or have any suggestions, feel free to email me.

It is most likely that some of the parameters would need some tweaking based on your level lighting and textures. If you need any assistance with these, post a screen and I'd be able to help out.

Thanks to Jon and Ari of BrokeAss Games for trying this out first and giving me some feedback initially.

Cheers!

Koushik
Page «Previous 1 2 3 Last »
#1
06/16/2008 (7:37 am)
Thanks Koushik !

I did the easy part (binding the shaderMaterial of the MK) but hadn't time to learn shader programming yet !

You give me a good reason to do it now !

Nicolas Buquet
www.buquet-net.com/cv/
#2
06/16/2008 (10:09 am)
Excellent
#3
06/16/2008 (10:17 am)
It looks like it was a bit more than the three lines of code I said it would be, but not by much.
#4
06/16/2008 (1:56 pm)
A couple of tips I had to do to my AFX + TGE 1.5.2-3 hybrid:
Slightly more than double the ambient lighting of the level.
Adjust some DRL settings based off of Alex's early MK manuals.
Manually create a materials list because after a certain amount of auto-generation the script seems to break and be full of errors.

Other than that, all is well and I'm staring at normalized/specular abdominals like in the movie 300.
Way to go Koushik, you're a real trooper!
Thanks again Alex!
#5
06/17/2008 (6:24 am)
You win!
If it were mine to give, I would present you with the world. But it's not, so all you're getting is my admiration.

Compiles perfectly, nothing breaks... this is my kind of resource ;)

EDIT: Uh-oh. I copied your example shader, stuck it in player.cs (with the TSShapeConstructor), and changed the particulars to suit my directory structure, like so:
new SubShader(DTSBump20)
{
   VertexFile[0] = "Shaders/DTSBump/bumpV.glsl";
   PixelFile[0] = "Shaders/DTSBump/bumpP.glsl";
   ShaderQuality[0] = 200;
   ShaderType = $ShaderTypes::GLSLShaderType;
};

new Material()
{
   mapTo = "player";
   name = "myShader";
   Shader20 = DTSBump20;
   textures[0] = "starter.fps/data/shapes/player/player.png";
   textures[1] = "starter.fps/data/interiors/lightingPack/WALL_FILLER101M_height_auto.png";
   textures[2] = "starter.fps/data/shapes/player/player.png";
   samplers[0] = colorMap;
   samplers[1] = nrmMap;
   samplers[2] = specMap;
};
And yes, the glsl files do exist.

I get this in the console:
Loading compiled script starter.fps/server/scripts/player.cs.
Compiling starter.fps/data/shapes/player/player.cs...
Loading compiled script starter.fps/data/shapes/player/player.cs.
Checking for errors in Shaders/DTSBump/bumpV.glsl
Checking for errors in Shaders/DTSBump/bumpP.glsl
GLSL program failed to link!
GLSL program info log Fragment shader(s) failed to link,  vertex shader(s) linked. 
Fragment Shader not supported by HW 
GLSL program failed validation!
GLSL program info log Fragment shader(s) failed to link,  vertex shader(s) linked. 
Fragment Shader not supported by HW 
GLSL program info log Fragment shader(s) failed to link,  vertex shader(s) linked. 
Fragment Shader not supported by HW 
Checking for errors in Shaders/Debug/errorVert.glsl
Checking for errors in Shaders/Debug/errorPixl.glsl
GLSL program info log Fragment shader(s) linked, vertex shader(s) linked. 
 Validation successful.

My player is rendering as solid red.
#6
06/17/2008 (7:09 am)
@Daniel:
What card are you using? Maybe the instruction-set is too long for your card to handle...

EDIT: Ah, and yes... the red color is an indication that the shader either doesn't compile or isn't linking... just something for you to keep in mind...
#7
06/17/2008 (12:33 pm)
@Daniel:
As you can see on the 8th line of the log : "Fragment Shader not supported by HW".
It seems the hardware doesn't support fragment shaders.

On the other hand, I'm curious : can you tell me what happens? Does the program run, albeit less beautifully, or does it just bomb and doesn't wanna run at all due to this error?
#8
06/17/2008 (4:51 pm)
@David

I don't think that is the case because Daniel reported that the MK works on his system. I think the problem might just be that the fragment shader is too long. In fact, it is very generalized, handling multiple lights and multiple light-types. Some GPUs have limited instruction set lengths.

Besides, if your hardware didn't support the Fragment program extension, it wouldn't have compiled in the first place.
#9
06/18/2008 (6:14 am)
David: everything runs fine, but my shape renders as solid red.

Koushik: so to fix this, I'll need to write my own glsl files that are shorter? Is this something I can fix by updating drivers, or is it a problem with the hardware? If it's the latter, then I'll have a go at rewriting the shaders...
...or writing new ones, so someone with a better PC than me can use the full version. Ha.

And thanks for the speedy reply :)
#10
06/18/2008 (8:11 am)
Yeah, you might want to try updating drivers, that might solve the problem.

If it doesn't, well... then you have a bit of a problem. It's not as easy as rewriting the shader in a shorter version.

I think your light design and placement in the levels would be a little more tricky. It would be most likely that you'll need to strip off point lights and directional lights from your level, and remove support for those in the shader. I think that would be the only viable solution.
#11
06/18/2008 (6:56 pm)
The resource works, but I'm getting a see-through alpha transparency effect on my DTS models (which I don't want). My color skin is a 24-bit PNG. is that correct?
#12
06/19/2008 (2:06 am)
Transparency?? Thats very strange... The MK did not work with transparency as-is, and I ensured I removed all references to blend functions and stuff in the code...

I'm pretty certain that you're really missing something there... a screen-shot would also be helpful... so would your graphics card specs...
#13
06/19/2008 (12:41 pm)
Quote:It's not as easy as rewriting the shader in a shorter version.
Huh. I guess that explains why that didn't work.

I figured, with my guru-like knowledge of shaders, that if I just knocked out the directional and spotlight functions, and changed the for loop accordingly, it'd make the shader shorter :P
Meh. I'm gonna go learn me glsl.
Or get a better computer.
I've got no idea what my current GPU is, but if that's indeed the problem, what GPU are you using? Is it even possible to remake the shader to run on a worse GPU? I mean, my computer will run games like HL2 with no problems; I'm assuming their shaders aren't too simple...
#14
06/19/2008 (4:10 pm)
I'm using a GeForce FX 6200 for my shader programming stuff...

About rewriting the shader - I could give it a shot again, but will need more info.

Are you on windows?

If you are, you can check the device manager for your video adapter name, which would be your GPU's name.

Right click on My Computer->properties->hardware->devicemanager. Then check the video adapter name.
#15
06/19/2008 (5:07 pm)
Note the transparency:

img83.imageshack.us/img83/9313/screenshot02000001ak8.png
this is what is should look like:

img83.imageshack.us/img83/3908/screenshot02000002rr8.png(I reintegrated MK into my customized Torque (TGE 1.5.2+AFX+FGE+ a lot of other changes)

I'm thinking it could be a z-sorting issue.

Relevant video stuff:

Video Init:
   Accelerated OpenGL display device detected.
   Accelerated D3D device detected.
   Voodoo 2 display device not detected.

Activating the OpenGL display device...
Activating the OpenGL display device...
Setting screen mode to 640x480x32 (w)...
Creating a new window...
Acquiring a new device context...
Pixel format set:
  32 color bits, 24 depth bits, 8 stencil bits
Creating a new rendering context...
Making the new rendering context current...
Setting screen mode to 800x600x32 (fs)...
Killing the texture manager...
Making the rendering context not current...
Deleting the rendering context...
Releasing the device context...
Destroying the window...
Changing the display settings to 800x600x32...
Creating a new full-screen window...
Acquiring a new device context...
Pixel format set:
  32 color bits, 24 depth bits, 8 stencil bits
Creating a new rendering context...
Making the new rendering context current...
Resurrecting the texture manager...
OpenGL driver information:
  Vendor: NVIDIA Corporation
  Renderer: GeForce 7900 GT/GTO/PCI/SSE2
  Version: 2.1.2
OpenGL Init: Enabled Extensions
  ARB_multitexture (Max Texture Units: 4)
  EXT_blend_color
  EXT_blend_minmax
  EXT_blend_subtract
  EXT_compiled_vertex_array
  NV_vertex_array_range
  EXT_texture_env_combine
  EXT_packed_pixels
  EXT_fog_coord
  ARB_texture_compression
  EXT_texture_compression_s3tc
  (ARB|EXT)_texture_env_add
  EXT_texture_filter_anisotropic (Max anisotropy: 16)
  WGL_EXT_swap_control
  EXT_Cg_shader
  ARB_texture_rectangle
  ARB_vertex_program
  ARB_fragment_program
  ARB_shader_objects
  ARB_shading_language (version: 1.20 NVIDIA via Cg compiler)
  ARB_vertex_shader
  ARB_fragment_shader
  ARB_vertex_buffer_object
  EXT_framebuffer_object
ARB_vertex_program information
  Max vertex program instructions: 512
  Max vertex program native instructions: 512
  Max vertex program temporaries: 48
  Max vertex program native temporaries: 48
  Max vertex program parameters: 256
  Max vertex program native parameters: 256
  Max vertex program attributes: 16
  Max vertex program native attributes: 16
  Max vertex program address registers: 2
  Max vertex program native address registers: 2
  Max vertex program local parameters: 256
  Max vertex program env parameters: 256
  Max vertex attributes: 16
  Max vertex program matrices: 8
  Max vertex program matrix stack depth: 1
ARB_vertex_shader information
  Max vertex shader texture units: 4
  Max combined tex. image units: 16
  Max tex. image units: 16
  Max texture coords: 8
  Max uniform vertex components: 1024
  Max varying floats: 32
  Max vertex attribs: 16
ARB_fragment_program information
  Max fragment program parameters: 1024
  Max fragment program local parameters: 512
  Max fragment program env parameters: 256
  Max fragment program ALU instructions: 4096
  Max fragment program native ALU instructions: 4096
  Max fragment program texture instructions: 4096
  Max fragment program native texture instructions: 4096
  Max fragment program texture indirections: 4096
  Max fragment program native texture indirections: 4096
ARB_fragment_shader information
  Max fragment uniform components: 2048
OpenGL Init: Disabled Extensions
  EXT_paletted_texture
  3DFX_texture_compression_FXT1
  ATI_FSAA
  ATI_text_fragment_shader
#16
06/20/2008 (6:24 am)
In that case, I think I'm on a ATI Radeon X1300/X1600... and yep, Windows.
About rewriting the shaders - if it's a pain, please don't go out of your way to do it. I probably need to learn some of this stuff anyway, and shader programming is something that there's a LOT of resources out there for.

Cyberkada: yeah, that's z-sorting rather than transparency.
#17
07/04/2008 (10:10 am)
Hmmm.. from the ATI specs sheets, its says the Radeon X1300 is capable of rendering upto SM 3.0 (I've never owned a Radeon in my life though), so I'll just look into it.
#18
07/05/2008 (1:37 am)
holy shit i totally just creamed my pants..

babylon5 fucking rules
that series is why im getting back into game development ;)
#19
07/09/2008 (8:45 pm)
I implemented this and it worked great for the fps example. I tried using it on a model in the starter.raceing example and it ended up using the sky texture on the model like a environmental map.

As well if i press f11 to goto edit mode, it crashes torque. Anyone else have this problem, i'm using the latest version of mk with 1.52.

Another note would be spec does not seem to affect color in your shader, have you messed around with allowing spec to affect color per pixel (skin spec is blue, where light bright areas would be white)

Any ideals on how to implement glow, would this need multi pass, how far have you gotten with that (saw some fur shader tests).

Lastly, is there any way this would work with the terrain? A bit of normal mapping on the terrain would be amazing, well shader support at all :P.

Thanks for this great resource it will be nice to have shiny cars!!
#20
07/11/2008 (9:00 am)
Hmmm... you're right...It seems the environment map is creeping in somehow. I'll take a look at it and get back to you.
The editor was crashing for me as well, I thought it was because of something else I had added before (I have the uncanny knack of getting the editor to crash very frequently and for no apparent reason whatsoever) so I didn't take it seriously... I'll take a look at that one too...

About the spec map. The spec map exposes the power value of the exponential for calculating the specular term in the lighting equation. Specular colors are specifically not handled by TGE 1.5's default lighting system. The light's specular values are set to black by default. You can find this in around line 344 in sgLightingmodel.cc. The above shader takes the lighting values from the GL lighting system built-into torque and hence the spec color doesn't turn up.

Changing this would be pretty easy - Just find the specular equations for each of the light types (those would be the inout variables specular in each of the functions in the fragment shader). Then instead of using gl_LightSource[i].specular, use any other vec4(r,g,b,a).

If you want a red specular, set that line in each function to:

specular += vec4(1.0,0,0,0)*pf *attenuation; depending on whether the attenuation variable is used or not.

As far as glow goes, I've got a couple of really neat post-process screen-space glows going. If you're referring to per-object glow (as opposed to a scene-bloom), you would definitely need atleast two passes. The fur-shader uses 6 passes to achieve a decent-looking effect. As outlined in the plan, I've gotten it to work pretty decently, but I don't have a good enough GPU to test it out further. I plan to get one soon though, and once its here, you'll definitely be ogling at more screens ;)

Finally, I also worked on a car shader using spherical harmonics. It kinda came a little close to the famous ATI car-paint shader that comes with Rendermonkey, only it was a gazillion times faster... I'll probably come around to posting that one out too in the coming days...

Lastly, terrain, well as of now, its not really on the priority list... I've got a slew of effects lined up, including a new set of post-process shaders, after that I'll get to the terrain, I guess
Page «Previous 1 2 3 Last »