Is there a way to calculate the tangents of a model in the material editor?

I’m trying to hide the individual planes of my tree model when they reach a 70 degree angle relative to the camera and it works but since I have all my normals pointing out it gets applied to the whole tree instead of the individual planes:


The only way to make it work on the individual planes is to feed the tangents into the normal vector of the fresnel node but how do I calculate them?


(1,0,0) Transformed from Tangent space To World space gives you Tangent in world space.
This would be of little practical use for your actual problem though.

Can’t you rotate the leaves along with the camera view? There’s an example of that in the math hall in the content examples.

Thanks, but I’ve tried feeding it to the fresnel normal vector and it doesn’t do anything. Like I said the fresnel gets applied to the whole tree and not the individual planes. Do you know another way to do this?

No that’s not what I want, it makes the trees look strange.

Well, you could bake initial orientation of your leaf cards into something like additional UV channel or vertex color and use it instead of vertex normal.

I thought of that but because I use the same texture on all the leaf planes I have to overlap the UV’s in the first channel. If I flatten all the planes and put them in the second UV channel they don’t line up.

Anyone else have a solution?

Yeah, I know this thread is three years old, but I had to solve the exact same problem today and couldn’t find anything useful. So just for the record: get absolute world position DDX/DDY cross product, normalize it and plug the result into a dot product with camera vector.

What I do for foliage is set the face normals to a different direction than what’s automatically calculated, i.e. for a grass mesh, facing directly up. There might be a way to generate spherical normals for the bunches of leaves, but since most applications expect normals to be adjusted every time you make a change to the model, I’m not sure of the exact workflow to make sure the tree trunk doesn’t get affected and you get the right mesh for import.

If you can fix it in the application, then the engine won’t need to do so much work generating normals frame-by-frame: it will just work the way you expect.

EDIT - Sorry, rereading your post it seems you actually have done this and it’s messing with fresnel to cut out meshes at grazing angles. If there is a way to bake normals into vertex colors the way Deathrey described, that would be amazing! I know UE4 accepts multiple UV channels so you could bake to a texture, but it only accepts one set of vertex normals and one set of vertex colors.

The downside of baking tangents into a map is that it will not be as accurate when used with any wind function. The solution I posted above sure is more performance heavy, but it works fine :wink: Only unplug the Dither Temporal AA because it causes flickering on shadows.

That’s a great solution!
For the shadows problem, you can have a ShadowsPass node and use TAA only in the render pass.