Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

tex2Dlod vs. tex2Dbias

Discussion in 'Shaders' started by metaleap, May 31, 2014.

  1. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    When specifying say a LOD-bias of 2.5, out of tex2Dlod and tex2Dbias which one blurs between MIP levels 2 and 3 with a lerper of 0.5 and which one rounds up or down to the nearest "hard integer" MIP level? The Cg specs say that tex2Dbias blurs and doesn't specify anything for tex2Dlod, but visual tests in Unity (GLES 3 with -force-opengl) seem to indicate the exact opposite, but maybe my eyes are tired.. :D
     
    Alexander_T_ likes this.
  2. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Yes it does.
    tex2Dlod
    tex2Dbias
     
  3. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Um, nope? As I said the spec for bias reads "Level-of-detail bias can be used to artificially blur or sharpen the result of texture sampling" BUT the spec for lod says nothing on the topic one way or the other. Which, OK, probably means as per spec there's no blurring. So what happens with a bias of 0.5? Sure I can try everything and their dog experimentally but some cold hard super-detailed specs ala Khronos wouldn't hurt I guess. OK gonna check the glsl/hlsl specs for the equivalent funcs.
     
  4. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Ohh, you're wondering if it applies texture filtering.
    Yeah, that appears to be broken in Deferred Lighting.
     
  5. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Nope, didn't mention filtering. Basically wondering, if bias with a 2.5 bias blurs between MIP 2 and 3, what does lod do with a 2.5 bias :D

    And how could texture filtering in any way possibly "appear broken in Deferred Lighting"? I'm not using Unity's Deferred but still that would seriously surprise me. Filtering is just "the basics".
     
  6. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Neither of these.

    Lod with 2.5 means "sample between mip levels 2 and 3". Whether it blurs or not depends on whether filter mode on the texture is set to bilinear or trilinear (by default textures have bilinear filter mode).

    Bias with 2.5 means "hey whatever mip level you would be normally using... add 2.5 to that". A bias of 2.5 would translate to something like "pretend the object is 6 times smaller on screen than it really is".
     
  7. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    As far as I'm aware, that's the main difference between bilinear and trilinear filtering. That's why I saw both pages as similar when they both indicated they could sample a different detail levels.

    Hold on, I'll try to do a quick test. I just remember losing filtering (it used point sampling) when sampling cubemaps at higher MIP levels, in Deferred Lighting. [Edit] Ah, nope, just for cubemaps, works fine for regular textures.

    [Edit] Ah, ninja'd by the ninja :D
     
    Last edited: May 31, 2014
  8. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    zOMG thanks dude, you're the hero the Cg documentation team needed, but apparently didn't deserve :D Crazy how I could misunderstand tex2Dbias so badly. But both doc articles sounding "basically-identical" did contribute to that. Thanks for enlightenment, much appreciated. This explains why my bicubic and bspline heightmap interpolation experiments "flattened" everything inexplicably. Calculating a LOD level and then giving it to tex2Dbias (thinking one gets a nice extra blur) would do that.
     
  9. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Again, I'm pretty confident cubemap sampling should happen the same in Forward and Deferred. It's always done in a shader, and the GPU-side shading level has no concept of Unity's different render-paths. Especially if you explicitly specify a MIP level. Maybe it works as you expect to and maybe it doesn't, but it should be the same behavior in Forward and Deferred theoretically.
     
  10. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    It knows when you tell it:
    Code (csharp):
    1. #define UNITY_PASS_FORWARDBASE
    which surface shaders do.

    But it turns out to be a problem with SampleLevel and the automatically generated SamplerStates, not tex2Dlod or tex2Dbias. Sorry for the confusion.
     
  11. Augunrik

    Augunrik

    Joined:
    Mar 4, 2018
    Posts:
    2
    They should write this sentence(s) into the function documentation...!