Sign in to follow this  
CadeF

[Resolved]A few questions about selecting codepaths in HLSL

Recommended Posts

CadeF    421
Hey everyone, I've got a few questions. In my engine, I'm going to use a different shader for every shader level. What I mean is, Shader 1 has a SM 1 and 2 codepath Shader 2 has a SM 1, 2 and 3 codepath In my application, I want to define the highest shader codepath it will compile. Example, SM2 Shader 1 will compile the SM2 codepath Shader 2 will compile the SM3 codepath How would I go about doing that? I was thinking
technique RenderLightingPass
{
    pass p0
    {
        VertexShader = compile vs_1_1 LightingPassVS();
#IF shaderver >= 2
        PixelShader = compile ps_2_0 LightingPassPS_SM2();
#ELSEIF shaderver = 1
        PixelShader = compile ps_1_1 LightingPassPS_SM1();
#ENDIF
    }
}




But I don't know how to pass in shaderver. Anyone? [Edited by - CadeF on March 13, 2006 12:55:16 AM]

Share this post


Link to post
Share on other sites
Demirug    884
In the case you use the effect framework you should use different techniques for this.


technique ShaderModel1
{
pass p0
{
VertexShader = compile vs_1_1 LightingPassVS();
PixelShader = compile ps_1_1 LightingPassPS_SM1();
}
}

technique ShaderModel2
{
pass p0
{
VertexShader = compile vs_1_1 LightingPassVS();
PixelShader = compile ps_2_0 LightingPassPS_SM2();
}
}


You can now select the technique you want to use with “SetTechnique”. You will need some additional code that maps from the caps to the right Technique. The easiest way is to use always the same technique names. But with some additional code you can make it much more flexible and configurable.

Share this post


Link to post
Share on other sites
circlesoft    1178
Quote:
Original post by CadeF
Thanks, but I'm looking for other methods, in which no higher version is compiled.

I have found the easiest way to do this is to simply place the higher-profile techniques above the lower-profile techniques. This way, no compile errors are generated, but they aren't validated either. Then your application can simply use the first validated technique.

If you *really* want to avoid compiling them at all, you could just #define different identifiers from within the application (remember the effect compiler allows you to add in different defines at runtime). For example, #define SM_3_0 and whatnot.

Share this post


Link to post
Share on other sites
CadeF    421
In Direct3D.Effect.FromFile, where do I pass in "#define ShaderModel == 2;"?
Or, if not Effect.FromFile, which function?

[Edited by - CadeF on March 12, 2006 5:36:12 PM]

Share this post


Link to post
Share on other sites
circlesoft    1178
Quote:
Original post by CadeF
In Direct3D.Effect.FromFile, where do I pass in "#define ShaderModel == 2;"?
Or, if not Effect.FromFile, which function?

Well, I have only use the unmanaged version (D3DXCreateEffectFromFile()). There, you just specify a null-terminated array of defines for the pDefines structure.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this