# 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.

## 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;
};


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 on other sites
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).

##### Share on other sites
Quote:
 Original post by EricOk, 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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 13
• 46