Jump to content
  • Advertisement
Sign in to follow this  
gamerxr

Getting parameters through semantics(.fx file)

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been looking through the sdk documentation trying to see if there is a way to abstract the process of geting variable handles through either semantics or annotations. I know you can get variables based on their semantics,such as GetParameterBySemantic(), but I want to automate so I don't need to know what semantics are being used. I want to be able to export from a seperate program, such as FXComposer, and load directly into the game without adding any more code to get and set handles. I guess I would have the game engine(if DirectX doesn't do this), parse the effect file and get a list of semantics used, and then set the variables needed for that shader. Im wondering if DirectX provides anything to do this, or if I'm going to have to write a parser that looks for every semantic? If I went this route, every differnt type of parameter would have to have a unique semantic, wouldn't it? Is this a good or bad approach to the situation? Any sugested readings/advice is appreciated. :) thanks

Share this post


Link to post
Share on other sites
Advertisement
Microsoft recently collaborated with numerous IHV's and developers to create DXSAS, or DirectX Standard Annotations and Semantics. Since shader IDEs have been popping up all over the place, each with support for scene and UI scripting, it was a good idea create a standard set of annotations and semantics. Check out the docs on this - it will give you a list of semantics to both use and parse for.

An easy way to parse shaders is to iterate through every parameter (Effect::GetParameter()) and then match its semantic to an input. For example, if you find a parameter with a DIFFUSE semantic, match it to the diffuse texture. If you really want to make it completely data driven, it can get complicated very fast.

Share this post


Link to post
Share on other sites
I took your advice using the GetParameter (which worked very well, thank you) to get the handles to all of the top level parameters, which I then use to check their semantics against the list of semantics that could be used. My question now is, is there any way to get the name of a variable in the effect file. For example, if I have a float3 lightDir; is there any way to get the string "lightDir" by using any of the methods of the ID3DXEffectClass?

Share this post


Link to post
Share on other sites
You can use Effect->GetParameterDesc . This returns a description, which contains, among other things, the parameter name.

Share this post


Link to post
Share on other sites
The SAS system just defines a set of standardized annotations. This is all well and good, but without any kind of standardized framework, it's just some pretty annotations. If the D3DX Effect framework provided some automated way to deal with SAS effect parameters, it'd be useful, but there's no software support for it yet.

So, in my engine, for special parameters that will show up in several effects, I use shared parameters. I create an internal "dummy" effect whose sole purpose is to hold the parameters that I want to be shared. So my dummy effect looks like this:

shared float4x4 WorldMatrix : WORLD;
shared float4x4 ViewMatrix : VIEW;
// several other parameters here

technique t0
{
pass p0
{

}
}


I create an effect constant pool, and create this effect in that pool. Then, when I load any other effects, they use that pool as well. So the only thing I have to do to make an effect "compatible" with my engine is to define things like world, view, proj, etc. like so:

shared float4x4 WorldMatrix : WORLD;


Then, I only have to set these shared parameters once in the dummy effect, and they propagate to all the loaded effects. It works quite nicely, and is a good "replacement" for a unified SAS framework. Hopefully MS will make some kind of SAS framework over the next few updates to the SDK.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!