Can you use multiple .fx file effects at the same spot?

Started by
2 comments, last by Aqua Costa 11 years, 11 months ago
For instance,using


glow->Begin(&numPasses,0);
glow->BeginPass(0);
opacity->Begin(&numPasses,0);
opacity->BeginPass(0);
myMesh->Render();
opacity->EndPass();
opacity->End();

glow->EndPass();
glow->End();


to make a semitransperent glowing mesh.I want to make different material types for my meshes and each material corresponding to a combination of effects.For instance a Metal material(metal has reflection - 1 effect) or Glass(glass has a little reflection,but is also transperent and also has difraction - 3 effects).Or do I have to make one huge material shader and use different techniques for the different effect combinations?
Advertisement
Probably, the most used approach is to write a huge shader (usually called uber-shader) and create different permutations using #if's #ifdef's, etc

For example:

float4 PS(PS_IN pIN) : SV_TARGET0
{
#ifdef REFLECTIVE
//reflection code here
#endif

#ifdef TRANSPARENT
//transparency code here
#endif

//and more #if's
}


Then you can generate the correct permutation needed for the material when you compile the shader by defining only the needed constants.

So to answer you question, you can't use multiple shaders (effects) at the same time, so you have to combine everything in a single shader to achieve the effect you want...

Probably, the most used approach is to write a huge shader (usually called uber-shader) and create different permutations using #if's #ifdef's, etc

For example:

float4 PS(PS_IN pIN) : SV_TARGET0
{
#ifdef REFLECTIVE
//reflection code here
#endif

#ifdef TRANSPARENT
//transparency code here
#endif

//and more #if's
}


Then you can generate the correct permutation needed for the material when you compile the shader by defining only the needed constants.

So to answer you question, you can't use multiple shaders (effects) at the same time, so you have to combine everything in a single shader to achieve the effect you want...

Probably, the most used approach is to write a huge shader (usually called uber-shader) and create different permutations using #if's #ifdef's, etc

For example:

float4 PS(PS_IN pIN) : SV_TARGET0
{
#ifdef REFLECTIVE
//reflection code here
#endif

#ifdef TRANSPARENT
//transparency code here
#endif

//and more #if's
}


Then you can generate the correct permutation needed for the material when you compile the shader by defining only the needed constants.

So to answer you question, you can't use multiple shaders (effects) at the same time, so you have to combine everything in a single shader to achieve the effect you want...


Don't if statements in the shader cause a huge fps drop?Maybe I should just make a seperate .fx file for each material,so I never have to use ifs in them.

Don't if statements in the shader cause a huge fps drop?Maybe I should just make a seperate .fx file for each material,so I never have to use ifs in them.


I'm talking about precompiler #if's. This kind of conditionals disappear after the shader is compiled. You pass the compiler the definitions you want and it will generate a shader without any #if.

You can pass the definitions in the pDefines argument of the D3DXCreateEffectFromFile function.

In my example above if you just define TRANSPARENT the compiled shader will only have the transparency related instructions... Check this link.

This topic is closed to new replies.

Advertisement