• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Tispe  Members

Posted 04 November 2012 - 07:23 AM

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
Out.Position = mul(In.Position, WorldViewProj);
Out.Texture = ?????


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?

### #2MJP  Moderators

Posted 04 November 2012 - 05:54 PM

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 OpenGL spec, 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.

### #3Tispe  Members

Posted 05 November 2012 - 01:14 AM

I did not know that tex2D() would automatically select the right mipmap if there was a chain present. I assumed that it only was tex2Dlod that gave the option to utalize mipmaps. So I guess I kinda rushed into this writing this topic

When that is said, and I degress, what is the .w component of a position vector used for?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.