Search Unity

Resolved Question about mesh Tangent data

Discussion in 'General Graphics' started by DimitriX89, Aug 6, 2022.

  1. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    I'm curious if tangent data for deforming meshes can be stored in any way. I was trying to calculate tangents in Blender's Geometry Nodes (mostly failing miserably), and came to conclusion they have to be recalculated every frame based on vertex position changes
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    672
    I don't understand the question. Tangents for normal mapping are stored like normals as vertex attributes in object space. During skinned rendering tangent vectors are transformed just like normals.
     
    DimitriX89 likes this.
  3. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Okay, I got you. So skinning transformation is applied not only to points, but to tangents and normal vectors. For some reason, Blender doesnt expose tangent data in its Geometry Nodes, and it warped my understanding of the topic. (I am asking those questions because I hope to recreate my geonode tools in Unity one day)
     
  4. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    672
    Yes, you can download the built-in shaders to see how it is done. This is from Internal-Skinning.compute:

    Code (CSharp):
    1.     MeshVertex ouputVertex;
    2.  
    3.     ouputVertex.pos = mul(blendedMatrix, float4(vPos, 1)).xyz;
    4.  
    5. #if SKIN_NORM
    6.     ouputVertex.norm = mul(blendedMatrix, float4(vNorm, 0)).xyz;
    7. #endif
    8.  
    9. #if SKIN_TANG
    10.     ouputVertex.tang.xyz = mul(blendedMatrix, float4(vTang, 0)).xyz;
    11.     ouputVertex.tang.w = vert.tang.w;
    12. #endif
    13.  
    14.     StoreVert(outVertices, ouputVertex, t);
    It only needs a normal and a tangent. The bitangent (aka binormal) is calculated on the fly, it seems.

    By the way, the typo in ou(t)putVertex is not mine ;)

    Unfortunately, I know very little about Blender, so can't help you with that.
     
    DimitriX89 likes this.
  5. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    I see, understandable enough. I have another question. It seems that shader code in Unity supports matrices. Can we pass some custom matrix into surface shader directly (like, as there is input format for color, so there is for matrix), or it have to be reconstructed inside a shader from separate position, rotation and scale vectors?
     
  6. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    672
    DimitriX89 likes this.
  7. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Passing it from code this way works fine, thank you