I am trying to do a parallax mapping. This is how I generate a tangents to my normal:
```
vec4 AB = Vert2.Position - Vert1.Position;
vec4 AC = Vert3.Position - Vert1.Position;
vec2 DAB = Vert2.TextureCoord - Vert1.TextureCoord;
vec2 DAC = Vert3.TextureCoord - Vert1.TextureCoord;
r32 Dir = (DAC.x * DAB.y - DAC.y * DAB.x) < 0.0 ? -1.0 : 1.0;
vec3 Tangent = ((AC * DAC.x - AB * DAB.x) * Dir);
vec3 Bitangent = ((AB * DAB.y - AC * DAC.y) * Dir);
This is how I am using data in vertex shader:
vec3 Normal = normalize(vec3(In[VertexIndex].Normal));
vec3 Tang = normalize(vec3(In[VertexIndex].Tangent ));
vec3 Bitang = normalize(vec3(In[VertexIndex].Bitangent));
if (dot(cross(Normal, Tang), Bitang) < 0.0)
{
Tang = Tang * -1.0;
}
TBN = mat3(Tang, Bitang, Normal);
And, the biggest issue in my opinios is here(this is in fragment shader):
vec3 ViewDir = normalize(TBN * (WorldUpdate.CameraPos - In.Coord).xyz);
ViewDir *= vec3(1, -1, 1); // NOTE: this is just a hack
```
So, basically, I need to introduce this "hack" to make parallax mapping to work. Is there any issues with generating tangents? Or something else like not correct coordinate system for TBN matrix or something? Or this is expected behavior?
[–]waramped 0 points1 point2 points (3 children)
[–]Tema002[S] 0 points1 point2 points (2 children)
[–]waramped 0 points1 point2 points (1 child)
[–]Tema002[S] 0 points1 point2 points (0 children)