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

Started by
10 comments, last by overr 18 years, 1 month ago
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]
Advertisement
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.
What you are asking, while its possible its not advised.
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
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?
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

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 :)
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.
Quote:Original post by 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.
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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..
Quote:Original post by overr
jollyjeffers, 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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement