When it comes to textures they can be thought of the same thing. The texture’s mip and level of detail aren’t necessarily the same thing though. You’ll note I used the term “mip level”, which would more accurately be the “mip map level of detail”. I’ll explain a bit more, but first some additional information.
As stated the tex2D function calculates the texture’s mip level during the fragment shader stage. As such you only need to pass in the texture (in the form of a sampler2D) and the UV (in the form of a float2) to get an appropriately filtered color back.
The tex2Dlod function requires you define the mip level manually. As such you need to pass in the texture (a sampler2D again), and the uv (again a float2), but also an LOD value. Now if your examples above you’re using this example:
tex2Dlod(_SnowTrackTex, vertex.texcoord)
That vertex.texcoord
from appdata_full
is already a float4 value, so that works with out any error. By default most meshes are going to have the z and w components of the float4 be 0.0, which works out perfectly for this case. However you’re better off doing this:
tex2Dlod(_SnowTrackTex, float4(vertex.texcoord.xy, 0.0, 0.0));
That last zero is the mip level. If you change that to a 1.0 or 2.0 you’d use the first or second mip instead, assuming your texture has mip maps.
Note, if you pass a float4 as the UV for a tex2D it would automatically cull it down to a float2 on most platforms, but might also error on others and fail to compile. Be wary of this because a shader that compiles on your computer might not on someone else’s if you’re not careful!
So what’s the difference between mip maps and level of detail and why do I say “mip level” or “mip map level of detail”? Mip mapping refers to taking a texture and making successively smaller pre-filtered versions of the texture. Each texture is half the size of the previous mip, and each pixel is (usually) an average of the 4 pixels of the larger texture it’s a mip of. Now, when rendering a mesh using that texture it can pick the texture that’s closest in size to how it’s currently being rendered.
When the mip level is calculated by the GPU, it’s not going to always be whole numbers. Usually it’s going to come up with fractional numbers, ie: a mip level of 0.66. For point and bilinear filtering, this just gets pushed up to the next whole number mip. However for trilinear filtering it takes both mip 0 and mip 1 and blends between them, 34% of mip 0 and 66% of mip 1.
So the term mip mapping can refer to both the mip maps themselves and the basic idea of choosing a mip based on the viewed scale of the texture. It is one of many methods of doing level of detail for texturing, though it is by far and away the most common and also the only one really supported by current GPUs. Also, this all gets quite pedantic and most likely when people talk about mip mapping or level of detail, or anything else around this they’re probably talking about the same thing.