Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to get instanced mesh local normal in material

I'm trying to get local normal per instanced static mesh in the material.

I've managed to get position, orientation and scale using the Object nodes and passing them through VertexInterpolator, so they're calculated in the vertex shader. The only one that didn't work was the ObjectOrientation node. But I can get the same result by passing a (0,0,1) vector to a TransformVector(Local to World) and then to the VertexInterpolator*.

But no matter what I do, I can't get any vector transformed from World to Local space nor Tangent to Local. See the setup below: Normal world to Local

For standard Static Meshes, it works with any of the TransformVector nodes connected. For instanced, though, it doesn't work either way!

Here's an example: Local normal examples

The left cylinder is an instanced mesh and the right one is a standard StaticMeshActor. Both using the same material. The StaticMeshActor (right) correctly displays its local normals, displaying as blue what would be its top side. But the instanced one doesn't, fading to blue on its world space top faces.

How can I do it? I'm almost thinking this is a bug.

Product Version: UE 4.17
capture.jpg (51.7 kB)
capture2.jpg (25.0 kB)
more ▼

asked Sep 16 '17 at 12:49 PM in Rendering

avatar image

1.1k 28 41 90

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Generally, this behavior of TransformVector material expression is unintended. It should provide proper per-instance transform when used in vertex shader. It can be filed as bug report in a relative section.

For a workaround ou might want to try using custom node like that: alt text

With the following code:

     return mul(InputVector,(MaterialFloat3x3)Parameters.InstanceLocalToWorld);
     return mul(InputVector,GetLocalToWorld3x3());

Again, it needs to be passed through vertex interpolator, otherwise compile error will be thrown.

more ▼

answered Sep 16 '17 at 01:39 PM

avatar image

7.9k 130 31 295

avatar image RVillani Sep 16 '17 at 02:34 PM

Thank you so much!!! You're awesome! From one of your previous posts in other question, I supposed it had to be some custom code, but I had no Idea what the existing functions and properties were.

Since it was from world to local, I had to invert the Matrix and Vector positions, but it's working!! :D

Thanks again! And here's the inverted multiplication for the next one who tries it:

     return mul((MaterialFloat3x3)Parameters.InstanceLocalToWorld, Vector);
     return mul(GetLocalToWorld3x3(), Vector);
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I ran into the same problem two years later but a new node called "pre-skinned local position" has been added and work

more ▼

answered Jun 06 '19 at 02:48 PM

avatar image

6 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question