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

Started by
1 comment, last by Tispe 11 years, 5 months ago
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?

Shine a light please :)
Advertisement
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.
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?

This topic is closed to new replies.

Advertisement