Is there a way to do this in pixel shader 2.0/3.0? I've got on or off transparency so when the mipmapping level is different the transparency can take up too much of the texture and make it invisible. Or is there a way to manually create the mip maps in XNA 4.0?
Answer
Regarding your Mip selection, I am using a custom texture atlas shader. In my case, the following snippet is accurate enough. You do have to provide it your own texture size.. i.e. you need to know the width X height parameters of the texture you want to "mip". In my case, these are just defines.. If you use dds textures, direct x compatible, they should already have mip levels embedded.
#define SUB_TEXTURE_SIZE 128.0
#define SUB_TEXTURE_MIPCOUNT 8
float MipLevel( float2 uv )
{
float2 dx = ddx( uv * SUB_TEXTURE_SIZE );
float2 dy = ddy( uv * SUB_TEXTURE_SIZE );
float d = max( dot( dx, dx ), dot( dy, dy ) );
// Clamp the value to the max mip level counts
const float rangeClamp = pow(2.0, (SUB_TEXTURE_MIPCOUNT - 1) * 2.0);
d = clamp(d, 1.0, rangeClamp);
float mipLevel = 0.5 * log2(d);
mipLevel = floor(mipLevel);
return mipLevel;
}
No comments:
Post a Comment