Modifying vertex normals & tangents in custom shader code

I want to port a Unity3D project that I created to UE4.

The game uses a custom vertex shader to modify positions, normals & tangents from the incoming vertices to bend them to form a sphere. The effect can be seen here: https://www.youtube.com/watch?v=CyTU03Ceo6I

I was able to modify the vertex positions with a custom node and put the result into the “World Position Offset”, while subtracting the world position at the same time to have a new unique vertex position.

My problem is that I have no idea how to modify the normals & tangets for correct lighting.

As I see this, the “World Position Offset” is the only node that is computed in the vertex shader part, but theree are no normal / tangent vertex nodes available.

I may be able to modify the interpolated vertex normal in the fragment shader part and modify the “Normal” node accordingly, but from a performance view, this would be a bad option.

For the tangent, there is no output node at all.

Hi Nils,

Tetrissphere ftw!

I have not much experience with the unreal material system.

But, afaik, you can access the normals as seen here:

For accessing tangent-space, perhaps this helps ?

Have fun & GL,

I am also interested in this topic. I’ve seen a lot of people posting examples where they have manually calculated normals inside of the vertex shader (or used other trickery, like binormals/tangents offsets), and are then passing those vertex-shader calculations through the CustomizedUV inputs (to avoid taxing the pixel-shader)… but I have yet to see any kind of in-depth discussion of how to handle those manual normal calculations.

Is there a universal approach that will work in most cases, or is it a unique case for each type of vertex shader? (depending on the offsets, etc).

Thanks in advance.

As i see it, the “real” method would be to create a custom shader (.usf file) to do what I want. But the documentation lacks a lot of things there:

https://docs.unrealengine.com/latest/INT/Programming/Rendering/ShaderDevelopment/index.html

Where do I have to put the .usf files to? Dragging them into the editor results in “unknown file format”. Is there a default folder for shaders? Lots of information is missing there at the moment.

Custom shaders go into the Engine\Shaders directory. What you will want to look into is Vertex factories. Take a look at my Fluid Surface plugin for an example of implementing a custom vertex factory that has its own USF shader. Make sure to be logged into your github account and that is linked to ur UE4 account before clicking the link (Otherwise u will get a 404 error): https://github.com/Ehamloptiran/UnrealEngine/releases/tag/FluidSurface-4.5

Hi Ehamloptiran, I tried clicking the link you provided while logged in and it still didn’t work. Is this code still available? I would be really grateful if I could have a look at it.

Nate is hosting the plugin here now:

After all this time since you asked this, not many things have changed in the engine. It’s not just putting the usf files somewhere. You have to create lots of classes and structures and overwrite stuff. You can see some help here, but it’s really complicated and needs a lot of graphics experience. Unreal Engine 4 Rendering Part 1: Introduction | by Matt Hoffman | Medium