# How do I calculate the mipmap LOD specified in t.w for tex2Dlod

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

## Recommended Posts

Hi

A simple vertex has a float4 position x, y and z, the w I don't really know what is for. The vertex also has a float2 U and V for a texture.

When finished transforming the vertex position
[CODE]
Out.Position = mul(In.Position, WorldViewProj);
Out.Texture = ?????
[/CODE]

Each fragment then gets interpolated values from its primitive(3 vertices).

What do you do to get the LOD for the t.w?

I know that if the top level gives a 1:1 mapping between screen pixels and texture pixels then the top surface is used. If the second top level gives a 1:1 mapping at some distance to the screen then that level is used. And in between you interpolate two levels, that is t.w is not an integer. But how do you know at what distance the second level gives 1:1 mapping. At what depth? You would think twice as far away then the first level. Does that mean if Out.Position.z = 1 then use top level, at Out.Position.z = 2 use the second level and that Out.Position.z = 4 use the third level. At Out.Position.z = 3 then the LOD t.w is 2.5?

##### Share on other sites
Mipmap selection is done based on the gradients (partial derivatives) of the texture coordinates in screen space. These gradients are usually calculated based on the difference between texture coordinates for a 2x2 quad of pixels (which is why you can only automatically select mip levels in a pixel shader). I'm not sure if D3D actually specifies the exact formula used for mip selection, or at least has it in public documentation. It is in Chapter 3.9 of the [url="http://www.opengl.org/registry/doc/glspec42.core.20120119.withchanges.pdf"]OpenGL spec[/url], if you care to read through that.

Why exactly are you using tex2Dlod in the shader? Usually you use that intrinsic when you want to manually specify the mip level, and not use the auto-calculated mip level.