5
\$\begingroup\$

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?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

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;
  }
\$\endgroup\$
0
\$\begingroup\$

You do have several alternatives which should be sufficient:

  • Use the mipmap lod bias render states, though this is more or less deprecated in modern APIs
  • Manually select the mipmap yourself in the shader with the functions like tex2dlod. You could simply set it to 0 and have it always select the highest rest mip (although this will cause some aliasing on-edge and in minification cases)
  • Don't upload a full mipmap chain for the image, just create the texture with 1 or only a few (2-3) of the mipmap levels.
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .