Calculate TBN Matrix after modify position of vertex in vertex shader?

36 Views Asked by At

I tried to make swaying grass and i tried to calculate tbn according to this article : source

but i failed. I think I'm doing something wrong in the modified part. where i am making mistake?

void main()
{
    vec3 mod_Position = in_Position;
    vec3 posPlusTangent = mod_Position + in_Tangent  * 0.01;
    vec3 bitangent = normalize(cross(in_Normal, in_Tangent));
    vec3 posPlusBitangent = mod_Position + bitangent  * 0.01;
    
    vec4 mod_World_Position = model * vec4(mod_Position, 1.0);

    //i modified here
    float modify_Value=0.5;

    mod_Position.z += modify_Value * mod_Position.y;
    mod_World_Position.z += modify_Value * mod_Position.y;
    posPlusTangent.z += modify_Value * posPlusTangent.y;
    posPlusBitangent.z += modify_Value * posPlusBitangent.y;

    //after modified find modified tangent modified bitangent and modified normal
    vec3 mod_Tangent = posPlusTangent - mod_Position;
    vec3 mod_Bitangent = posPlusBitangent - mod_Position;

    vec3 mod_Normal = cross(mod_Tangent, mod_Bitangent);

    //and i calculate tbn with modified versions
    mat3 normalMatrix = transpose(inverse(mat3(model)));

    vec3 N = normalize(normalMatrix * mod_Normal);
    vec3 T = normalize(normalMatrix * mod_Tangent);

    T = normalize(T - dot(T, N) * N);
    vec3 B = cross(N, T);

    out_TBN = mat3(T, B, N);

    out_Position = mod_World_Position.xyz;
    gl_Position = proj * view * mod_World_Position;
}
0

There are 0 best solutions below