Getting parameters through semantics(.fx file)

Started by
4 comments, last by Drakex 18 years, 8 months ago
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
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.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
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?
You can use Effect->GetParameterDesc . This returns a description, which contains, among other things, the parameter name.
Sirob Yes.» - status: Work-O-Rama.
oooh, I must have missed that function. many thanks :)
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 heretechnique 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.
_______________________________________________________________________Hoo-rah.

This topic is closed to new replies.

Advertisement