Jump to content
  • Advertisement
Sign in to follow this  
Eric

HLSL and D3DXEffect are broken

This topic is 5470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is how you specify the MaxAnisotropy sampler state in HLSL:
sampler sampMaterialDetail0 = 
sampler_state
{
    Texture = <g_texMaterialDetail0>;
    MipFilter = LINEAR;
    MinFilter = ANISOTROPIC;
    MagFilter = ANISOTROPIC;
    MaxAnisotropy = 16;
    AddressU = Wrap;
    AddressV = Wrap;
};

Notice the problem here? MaxAnisotropy must be "hard-coded", so that D3DX can validate the HLSL technique at compile-time. Since different cards support different values for MaxAnisotropy, this is basically unworkable. The only "solutions" I can think of: 1. In my HLSL source, duplicate every technique n times, using n different values for MaxAnisotropy. This would be incredibly tedious, even for n=2. 2. "Manually" set the MaxAnisotropy value (via a SetSamplerState call) immediately after calling Effect::Pass(). This is a total hack -- the D3DXEffect interface won't tell me which HLSL sampler is assigned to which integer sampler stage, so I'd have to guess. 3. Use HLSL without using D3DXEffect. In other words, implement a D3DXEffect-like layer and fix the problem mentioned in 2. I would probably resort to the above hacks before resorting to this. I've only just started using HLSL and D3DXEffect, and I expect I'll eventually run into other render states besides MaxAnisotropy that pose the same problem. I'm hoping that I'm overlooking something here. Can anyone think of a real solution to this problem?

Share this post


Link to post
Share on other sites
Advertisement
Ok, the thing I was overlooking is D3DXMACRO [smile]. I am using D3DXCreateEffectFromFile at game-init-time, and D3DXMACROs allow me to adjust arguments like MaxAnisotropy at this point (without having to actually open the .fx file and modify its contents).

Hmmm, I wonder why I'm posting this reply instead of just deleting the thread...

Share this post


Link to post
Share on other sites
Quote:
Original post by Eric
Ok, the thing I was overlooking is D3DXMACRO [smile]. I am using D3DXCreateEffectFromFile at game-init-time, and D3DXMACROs allow me to adjust arguments like MaxAnisotropy at this point (without having to actually open the .fx file and modify its contents).

Hmmm, I wonder why I'm posting this reply instead of just deleting the thread...


You can also create an EffectCompiler and call the SetLiteral method, load a value into that parameter, and then compiler will in line it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!