PDA

View Full Version : WINDOW_STYLE_DVAR_SHADER



Tally
29th October 2014, 10:22
I just discovered this. I didn't know of its existence until I saw it in COD1 (it's not used in COD2 at all, and there isn't any reference to it), so I thought I'd share:

If you want to show a shader image in a menu file, but you only want to show it on certain conditions, what I have been doing all these years is to put in a dvartest to only show the shader when the condition is right. This lead to quite a few different itemDef assets in the same menu file. By using the WINDOW_STYLE_DVAR_SHADER as the style setting, you only have to have 1 ItemDef and then set the dvar, either in the menu action, or by GSC script. That way you can show an unlimited number of different shaders on different occasions and keep your asset count down.

This is an example:


itemDef
{
name "soldier_image"
visible 1
rect 0 0 270 270
origin ORIGIN_TEAMIMAGE
style WINDOW_STYLE_CVAR_SHADER
cvar "ui_nation"
forecolor 1 1 1 1
backcolor 0 0 0 0.7975
decoration
}


So, that is an ItemDef in my teams menu. I set the "ui_nation" dvar according to which team they are on:


switch( game["allies"] )
{
case "american":
self setClientCvar( "ui_nation", "ui_mp/assets/hud@team_flags_americangerman.dds" );
break;

case "british":
self setClientCvar( "ui_nation", "ui_mp/assets/hud@team_flags_britishgerman.dds" );
break;

case "russian":
self setClientCvar( "ui_nation", "ui_mp/assets/hud@team_flags_russiangerman.dds" );
break;
}


NOTE - the dvar contains the full path to the file. The example above is from COD1, and so obviously as that game didn't use materials files, the path leads to the raw shader file.

Special Note for COD2 - If you want to keep switching the shader shown, to make the ItemDef "blank", you have to set the dvar to nothing. In COD1, that's fine - if it doesn't find a shader, it wont kick off. With COD2 however, you get the checkerboard missing image shader. So, create a blank/empty IWI file and materials, and call that to "blank" it out:


self setClientCvar( "ui_nation", "empty" );

Where "empty" is a 12 x 12 shader with a white alpha channel but nothing on its face (it is effectively "blank" or "empty").

php
29th October 2014, 11:03
You would be surprised how many unused/unreferenced features there are in the CoD engine.

Tally
29th October 2014, 11:12
You would be surprised how many unused/unreferenced features there are in the CoD engine.

Actually, no I wouldn't. Take the file functions we all take for granted these days. That was discovered late 2007, just before COD4 came out. Had we known about it in 2005/2006, it would have solved a lot of problems for us.

It always takes some inquisitive person to discover these things for us. That is why it is vital that the credits to these people is preserved. Modders today don't have a clue who they are indebted to for all the things they take for granted. It is up to us who remember to keep those credits alive.

IzNoGoD
29th October 2014, 13:13
You would be surprised how many unused/unreferenced features there are in the CoD engine.

You are ofcourse referring to my rotational hud element find 5 years after the release of the game?

Agree with tally though, nowadays most features are pretty well documented or at least quite well known

serthy
29th October 2014, 16:34
Agree with tally though, nowadays most features are pretty well documented or at least quite well known

I guess the only unknowns spots are the shader materials and custom player animations (without referring to the stock CoD2 joints).
I've managed to create some custom scrolling shaders like 2 years ago, but still dont really have a clue how they are working

Tally
29th October 2014, 17:34
I guess the only unknowns spots are the shader materials and custom player animations (without referring to the stock CoD2 joints).
I've managed to create some custom scrolling shaders like 2 years ago, but still dont really have a clue how they are working

The problem with the COD2 HLSL language files is that they aren't documented. So, no one knows much about them. I have been experimenting with them recently, and I found them quite easy to do once you understand the basic principles. I read a couple of online tutorials on HLSL and once I understood the basic principles, it became fairly easy to create my own technique sets.

Another problem with the language is that there are only so many template files. This means if you don't understand HLSL and there isn't a template for what you want to do, you are pretty much stuck. But as I say, once you learn a bit of HLSL and you get to understand the structure of the COD2 HLSL file system, it becomes quite clear what you can do with them.

The power of the COD2 HLSL language can be seen in successive COD games. All the developers had to do was program their shader needs and the basis to do it was already there. This is why COD:BO1 could do some pretty impressive approximations of FXAA a couple of years ahead of proper FXAA being implemented into graphics cards - it was the flexibility of the Programmable Graphics Pipeline built by IW for the COD2 engine. Once you see things like that, you begin to understand why IW dumped the very limited Fixed Function Graphics Pipeline of the old Quake 3 engine. It could not have possibly have stood the test of time, never mind the very bad bump mapping that the Q3 Gouraud shading engine does. Dumping that in favour of the Phong shading engine was also very much a far gone conclusion.

serthy
30th October 2014, 01:12
another thing to mention to MENU_STYLE_DVAR_SHADER:
- instead of an empty image you could use a dvartest + hidedvar{""}
- you can use a server cvar and call makeCvarServerInfo() on that cvar, so global vars will be recognized as client cvars in your menus

php
30th October 2014, 15:53
I was referring to a lot of things including rotational setClock hud element, but not one particular in mind.

IzNoGoD
9th January 2015, 11:29
Just succesfully tested this method.

Tiny note: in cod2 these 2 lines:


style WINDOW_STYLE_CVAR_SHADER
cvar "ui_nation"
should use dvar instead of cvar, thus changing them to


style WINDOW_STYLE_DVAR_SHADER
dvar "ui_nation"
works fine.

http://classic.xfire.com/video/63145d/

This is what's possible with it :)

It's only one menu, maplist is dynamically generated from a mysql table :)