# how can i gather few *.fx files in one?

## Recommended Posts

overr    122
How can i gather several *.fx files in one if each file produces single effect(vertex or pixel lighting, bump, morph etc). How can i get single effect from those files? Each object in the scene can contain any combination of available hlsl effects and i need to link them somehow together and render object with the result effect. Shall i use D3DXCreateFragmentLinker or smth else? Or maybe i get wrong the whole idea.. All I could find is that HL2 contains about 4000 shaders. And nothing about how to combine them.. [Edited by - overr on March 12, 2006 6:52:35 PM]

##### Share on other sites
You could combine different techniques into one .fx file by just adding techniques and their accompanying methods.
For example:

technique simpleDiffuse{    pass p0    {        vertexshader = compile vs_1_1 diffuseVertexShader();    }}technique perPixelDiffuse{    pass p0    {        vertexshader = compile vs_1_1 ppVertexShader();        vertexshader = compile vs_1_1 ppPixelShader();    }}

And when you are rendering you could just set the needed techniques and variables.

I hope this was what you were looking for.
Take care.

##### Share on other sites
Guimo    463
The odea behind having multiple techniques in a single FX file is not to put every possible shader in a sigle file but to provide a fallback mechanism.

Say you want to render a glod.fx with reflection and all. The idea is to put a technique for PS/VS 3.0 other for PS/VS 2.0, other for 1.4 and so on. Maybe even one for the FFP. So when you load this effect you ask for the first technique, if it doesn't validate on the current HW, ask for the second technique and so on. Of course each technique mey be a little less real than the previous one, but eventually the fallback mechanism will find an adequate technique.

Luck!
Guimo

##### Share on other sites
overr    122
multiple techniques its not what actually i need :(
can i combine for example bump.fx and ppl.fx in one renderable effect? and for another mesh bump.fx and pvl.fx?
each fx(bump.fx or ppl.fx) complete effects that can be rendered separetely.

i need gather those effects in one on level creation time.. so level designer can simply choose several effects from list and get a final one..

shall i use multiple techniques for that? or smth else?

or can someone advise any other posibility to do such thing?

##### Share on other sites
Guimo    463
Its not possible to mix two effects in a sigle one.

An FX file describes a complete visual effect. When the effect file is ready you may load it into the host application (you engine, FXComposer, 3DStudio, XSI or any other) and it should run provided the host application can understand all the variables. Your artists may load the effects (BRICK.FX, GOLD.FX, MIRROR.FX, WOOD.FX, STONE.FX or any other) and use each effect in order to texture an object so they look like WOOD, STONE or other. They may edit some parameters in the FX in order to get what they want.

The fact that an FX file describes a full rendering process for a effect file means they can't be combined.

Now, a solution would be to create an include file with many default lighting and transform functions. That way you may create a big function library and your artists may pick the functions they like and create their own FX files which you can load in your game.

Luck!
Guimo

##### Share on other sites
Hesterumpe    178
As said, I don't think you can combine complete shaders into one, but you can look into shader fragments. These are pieces (fragments) of shaders that implements one specific task in a shader, like light or bump-mapping. When you have a bunch of these you can compile them into a single effect.

Look up D3DXCreateFragmentLinker and D3DXGatherFragments (and others) in the SDK.

By the way, I have never used these, so don't ask me how they work :)

##### Share on other sites
Guest Anonymous Poster
You can't do it period. If you knew HLSL, you'd know that there are only 93 or something registers. If each shader does soemthing different you will easily eat up all the registers with state variables leading to FX compile errors.

##### Share on other sites
jollyjeffers    1570
Quote:
 Original post by Anonymous PosterYou can't do it period. If you knew HLSL, you'd know that there are only 93 or something registers. If each shader does soemthing different you will easily eat up all the registers with state variables leading to FX compile errors.
Please be helpful, or just don't bother to click that "reply" button. You, whomever you really are, have been making too many these sorts of comments - quite simply I'm not interested. This particular post is marginally more useful than your others, but for the most part it is and will be delete-on-sight.

More specifically...

Much of the reasoning behind High Level Shading Language is so that the author can forget the finer details of instruction counts and register allocations. Yes, there are still very real limitations that you have to consider, but not everyone has those limits memorized [wink]

Cheers,
Jack

##### Share on other sites
overr    122
Guimo, thanks, thats interesting idea.. but how it would be more efficiently? use fragments or just hlsl code?

jollyjeffers, limits.. but i guess 93 registers its enough for me if i cant combine shaders..

##### Share on other sites
jollyjeffers    1570
Quote:
 Original post by overrjollyjeffers, limits.. but i guess 93 registers its enough for me if i cant combine shaders..
As far as the Direct3D runtime (and hence the hardware driver) is concerned it sees a stream of VS/PS instructions. It has no knowledge where it came from - be it a stand alone HLSL file, an FX file or some more complex fragment linking setup...

There are a number of limitations - for ps_2_0 it's 64 arithmetic and 32 texture reads from a maximum of 16 unique samplers. ps_2_x is more liberal with upto D3DCAPS9::MaxPixelShaderInstructionSlots (between 96 and 512) allowed.

ps_1_x is more restrictive and ps_3_0 is substantially less restrictive.

All depends on what your target hardware level is! As a general rule of thumb, the less instructions the better - whatever shader model. Even under SM4 (Direct3D 10) that allows for an unlimited number of instructions there will be an optimal value (and a maximum where peformance will degrade)...

hth
Jack

##### Share on other sites
DXnut    262
I currently have one .fx files with 9 different passes defined for rendering meshes with various options. However, there are 6 vertex shaders (like ones for a mesh with or without a texture, and a skinned mesh with/without a texture) and 2 pixel shaders in the file. So each pass selects one of each and sets its required render states.

I kind of assumed that when I called the mEffect->BeginPass() function that DX would load the code for that pass into the GPU. Am I wrong about this? Does it put all the code onto the GPU? Since I am using version 2.0 for everything, and have a high end card myself (Radeon 800XT with 256M RAM) I may actually be unknowingly creating a problem for lower end cards?

Now, the fx file I wrote is pretty basic, and I am planning to change how I do effects for my program, but I would appreciate knowing more about how to make it more efficient. Would it be better to have different ID3DXEffect interfaces than to put a lot of functions in one fx file and use one interface for it?

Thanks.

##### Share on other sites
overr    122
jollyjeffers, target is nv 5900xt, so i guess it will be ps2.0

DXnut, dont know pass or all code.. but i figure out that i need some kind of effects system, which will contain ID3DXEffect interface in every instance, and effect itself will be created from pieces in level editor, but i still dont know what choose to use, fragment linker(directX) or pure hlsl (and combine it manually)..

*.fx with 9 passes may be powerful.. but i think more flexible way is to use fragments.. because when you add some new effects you don`t need to rewrite main.fx, you just link it with other and get effect which contains that part.

[Edited by - overr on March 16, 2006 4:55:41 PM]