Texture clamping in Direct3D shaders in Max2010

Just spent a few hours debugging this silly bug and thought I’d share what I found.

Brought over some working shaders from Max2008 to Max2010 and there were some new clamping issues with textures. In Max 2010, it appears that the AddressU and AddressV addressmodes are uninitialized. For me this has yielded erratic addressmode results, where textures wrap properly SOMETIMES, but on recompile they will often will be clamped :confused:

Make sure that you manually specify addressmodes for FX shaders in 2010:

sampler2D DiffuseTextureSampler = sampler_state
{
     Texture = <diffuseTexture>;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = None;

    AddressU = Wrap;
    AddressV = Wrap;
}; 

cheers~

One more reason to stay away from new max versions! :slight_smile:

Nice find. On a related note, the 2010 FX compiler also seems to handle vertex colors differently than 2008. If you use vertex coloring in a shader, it appears you will need to add “ShadeMode = GOURAUD;” to the technique, or the vertex color will not be interpolated properly across the face.

This has come up before, they are not uninitialized, they get set by the viewcube to clamp so if you dont set them specifically in your shaders inherits the state.