Search Unity

Why does Z-scale of zero stop textures from being mapped?

Discussion in 'General Graphics' started by Stevens-R-Miller, Oct 24, 2021.

  1. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    676
    I have a quad with x, y, and z-scale of (16, 9, 1). When I drop a texture on it, it works as I expect:

    upload_2021-10-24_10-7-9.png

    When I set z-scale to zero, so the x, y, and z-scale is (16, 9, 0), the texture mapping stops, even though the quad is still visible:

    upload_2021-10-24_10-8-3.png

    It also turns black, which I guess means a z-scale of zero shuts down all lighting, not just texture mapping.

    Since the quad is of zero extent along the z-axis to begin with, I would not have expected setting its z-scale to zero to have these effects. Why does this happen?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    The texture mapping isn’t breaking, it’s just the lighting. If you use an unlit shader the quad will look the same regardless of if it’s scaled on that axis or not.

    The problem is when you scale the z axis down to 0.0, the vertex normals for the quad mesh shrink down to zero as well since the vertex normals for that mesh are all (0.0, 0.0, 1.0). Usually for lighting you normalize the normal vector after scaling to ensure they’re unit length, but normalizing a float3 of all zeros results in an error, and that results in the output of the shader breaking.
     
    Stevens-R-Miller likes this.
  3. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    676
    Ah! You're a genius, thanks!