Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: Custom materials with X and FX files  (Read 9464 times)

0 Members and 1 Guest are viewing this topic.

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Custom materials with X and FX files
« on: May 16, 2006, 04:31:40 PM »

Hi,

I believe that .X files can contain some material definitions in .FX format (basically high level vertex and pixel programs)

Does WME support that feature ? We'd like to try a cartoon rendering and maybe other effects on our main character.

Additionally, has anyone here managed to export these effects from 3DS MAx with Pandasoft Exporter ? Everytime I open the resulting .X file in Direct X's viewer it says "No effect instance specified. Reverting to the default effect."

Thanks,
 Olivier
Logged
I am the Milkman. My milk is good.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Custom materials with X and FX files
« Reply #1 on: May 16, 2006, 05:37:19 PM »

No, it's not supported. But if you could provide me with some sample models, I might look into it. It's not exactly documented in DX 8 docs, they seem to have added the "standard" X file templates in DX9, but it should be loadable in DX8 too (I hope).
Not sure how exactly if works, though, since AFAIK the fx files are dependant on some parameters which are provided by the application, and those parameters can vary...
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Custom materials with X and FX files
« Reply #2 on: May 16, 2006, 06:10:53 PM »

There is a Microsoft standard called Standard Annotations and Semantics (SAS) that deals with the way parameters are passed between the application and the effect.  Oddly enough, no one seems to be using it in their FX files.

I've finally managed to export a .X file that uses materials stored in a .FX file, but the Direct X viewer won't open the FX file and falls back to default materials (it has something to do with SAS, I think). Once I get this to work in the viewer or the DX samples, I'll send you the data...

Thanks !
Logged
I am the Milkman. My milk is good.

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Custom materials with X and FX files
« Reply #3 on: May 17, 2006, 06:59:12 PM »

Ok, so after messing around with MAX and the Direct X viewer quite a bit and scratching my head a lot here's what I've figured out:

SAS is a new standard to pass transformation matrices and other parameters between an application and an effect FX file. There are other standards around and 3DS MAX 7 is using one of them.

I managed to hack an existing .FX file to make it compliant with both 3DS MAX and SAS. In MAX this file can be used in a "Direct X 9 Shader"-type material. If everything goes well you will be able to set the colour values for 'light specualr", "material ambient", "material diffuse" and other parameters in the material. Those are custom parameters in the FX file that MAX understand, and also the X file and the Direct X viewer that I used to render the file.

When selecting "Include .FX file" and "Include .FX parameters" in Pandasoft exporter, the "Direct X 9 Shader" materials are exported as effect instances, and the custom parameters are exported too in the .X file with their name and value. The actual .FX files need to be in the same directory as the .X file, pandasoft doesn't copy tehm for you.

Thanks to the custom parameters the effects do not need to be hard-coded. This allows us to reuse the .FX files between materials (for instance we can have a red cel-shaded material and a blue one that use the same effect file but have different parameters for the diffuse colour.), and that's pretty neat... I think that the goal here is to have programmers write customizable effects and let the artists use them and see the results directly in their modeling program.

I exported a simple scene with a teapot and the toon shader that I modified, you can find it here:
http://www.adonf.org/wme/toon_teapot.rar

The .X file is in text format. The most interesting part is around line 8988, that's where the custom parameters are passed by name to the .FX file.

Here's a custom material parameter called "I_s" in the .X file:

Code: [Select]
     EffectParamFloats {
      "I_s";
      4;
      0.600000,
      0.600000,
      0.600000,
      1.000000;
     }

and here's its counterpart in the .FX file:
Code: [Select]
float4 I_s
<
// parameter information for DX SAS
string SasUiLabel = "light specular";
string SasUiControl = "ColorPicker";
// parameter information for 3DS MAX
string UIName = "light specular";
> = { 0.6f, 0.6f, 0.6f, 1.0f };    // default value

I'm not actually sure that we need the SAS-style definitions here. But where we do need them is for the transformation matrices and lights, see line 70 for an example of how the effect fetches the light direction from the application.


Well I hope that you can do something with that. So maybe soon we'll all have fancy 3D effects like water ripples or reflexions in our games ;)



Thanks, and let me know if there's any way that I can help...

  Olivier
« Last Edit: May 17, 2006, 07:03:27 PM by adonf »
Logged
I am the Milkman. My milk is good.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Custom materials with X and FX files
« Reply #4 on: May 17, 2006, 07:44:24 PM »

I did some brief research and I'm afraid all of this is of no use in DX8. The effect files supported by DX8 are quite simplistic compared to DX9, so this toon shader wouldn't even compile. Similarly, there's a SAS supporting library in DX9c SDK, which in no way would compile against DX8.
So I'm sorry to say that, but I'm keeping this possibility open for future, when maybe one day WME will get ported to DX9 or later. Until then it's not viable, IMO.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Custom materials with X and FX files
« Reply #5 on: May 17, 2006, 10:17:06 PM »

Yeah, that's what I feared  :-\

But isn't there some kind of way that the engine could support vertex shaders ? I know that you want to keep it compatible with older video cards, but AFAIK DX8 supports software VS emulation for all cards (and that is basically just doing the math on the CPU, which is what you're already doing anyway) so it shouldn't change the hardware requirements. Is this something that you've considered ?

Cheers,
  Olivier
Logged
I am the Milkman. My milk is good.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Custom materials with X and FX files
« Reply #6 on: May 18, 2006, 07:28:00 AM »

It should be possible, in theory, but I think most people would be more interested in pixel shaders.. And again, there's the problem with parameters.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Custom materials with X and FX files
« Reply #7 on: May 18, 2006, 10:40:15 AM »

Quote from: Mnemonic
I think most people would be more interested in pixel shaders..

I doubt it. Vertex shaders offer much more possibilities than pixel shaders since you can do mesh deformations like lip synch or procedural water and also some nice rendering effects like toon shading.

And as I mentionned earlier they're also supported by all video cards though software emulation at almost no CPU cost...

But you're right, there's still the problem of the interface between the material in the modeler and the runtime. I'll have a look at DX8 effects and how they can be used in MAX... Maybe it's just a matter of rewriting the toon shader in assembly language.

Logged
I am the Milkman. My milk is good.

Orange Brat

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 112
    • View Profile
    • Orange Brat Shenanigans™
Re: Custom materials with X and FX files
« Reply #8 on: May 18, 2006, 10:49:07 AM »

I know that when 3D Gamestudio was still a DX8 engine, we had a working toon shader. Anyway, the DX8 version is near the bottom of the link below. I don't know if that will be of any use to you, but maybe it can serve some purpose:

http://www.coniserver.net/wiki/index.php/Simple_Toon_Shading
Logged
The Disenfranchised™ - coming later

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Custom materials with X and FX files
« Reply #9 on: May 18, 2006, 11:08:35 AM »

Thanks, I think that's going to be useful.
Logged
I am the Milkman. My milk is good.
 

Page created in 0.018 seconds with 19 queries.