2
$\begingroup$

I followed a parallax occlusion mapping tutorial on learnopengl.com and ported it into Unity and Blender. In Unity it worked fine, but when I tried it in blender it had a problem.

From the top the parallax worked as expected: enter image description here
But from the side:
Heres what I translated: picture of blender nodes
From:

{ 
    float height =  texture(depthMap, texCoords).r;    
    vec2 p = viewDir.xy / viewDir.z * (height * height_scale);
    return texCoords - p;    
}
$\endgroup$
8
  • $\begingroup$ I suspect your problem is due to the orientation of vectors. Your algorithm assumes alignment of the face with the world coordinates but that’s only the case with the top surface. $\endgroup$ Commented Nov 11, 2021 at 15:52
  • $\begingroup$ I tried to use the vector transform node to change the coordinates from World to Object but I don't know much about this. I'm guessing I'd have to transform it to be in the same space as the normal? $\endgroup$
    – garlfin
    Commented Nov 11, 2021 at 16:09
  • $\begingroup$ Yes - I think that’s exactly what you’d need to do, since the ‘surface offset’ is in the direction of the normal. You need to also be careful of rotation too - so the ‘up’ in relation to the texture matches the orientation of your UV face - otherwise your parallax adjustment will be in the wrong direction. It needs some complicated vector manipulation to get it just right. Maybe Unity does that for you somehow…? $\endgroup$ Commented Nov 11, 2021 at 16:17
  • $\begingroup$ Well, I was using the learnopengl tutorial and there was something about a TBN matrix. I did all the computations myself and the method I used multiplied the view vector by TBN (tangent bitangent normal). I tried to replicate the TBN matrix in blender but it didn't work. link $\endgroup$
    – garlfin
    Commented Nov 11, 2021 at 16:22
  • $\begingroup$ instead of z, what if you use the dot product of normal and incoming (from the geometry node)? $\endgroup$
    – lemon
    Commented Nov 11, 2021 at 16:56

1 Answer 1

2
$\begingroup$

Well the answer was simpler than I thought. To fix it you Dot Product the Incoming Vector with the TBN Matrix.

blender node group

To get the Bitangent you cross product the Tangent with the Normal

You don't need to do the mix node like I did, I just did that so it looked pretty on backfaces :)

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .