How to effect Vertex positions of StaticMeshComponents inside Vertex Shader?


I am new to writing shaders in Unreal, and was following this tutorialby Temaran. I got it to successfully run on UE4.24.1 that I build from source, and my goal is to learn how to edit the custom shaders in this tutorial in order to make a water surface wave effect by moving the vertices of a plane StaticMeshComponent.

I was playing around with the Vertex Shader inside PixelShader.usf, but I realized that the actual vertices of the StaticMeshComponents in the scene do not get effected at all. It seems that only the vertices of the texture that is applied to the StaticMeshComponents are effected.

I was able to achieve a basic wave effect fairly easily with the Material Editor by affecting the World Position Offset, but am having a lot of trouble figuring out how to edit the code of Temaran’s tutorial to pass in the vertex positions into the Vertex Shader in order to achieve a similar effect.

What I’ve learned from my research so far is that a Vertex Factory can pass in vertex information into the Vertex Shader, but the documentation about how to implement a Vertex Factory seems to be very limited.

Does anyone have any leads about how to approach this? If someone knows where to find a tutorial (preferably for beginners) about how to do something like this, that would be really helpful!

Thank you!

Hello! What I am attempting now to send vertex position data of StaticMeshComponents to the Vertex Shader is to follow this tutorialby Rama, but I am stuck trying to compile PhysX.

My first error in terms of compiling PhysX was “**Failed to get Visual Studio Install directory.” **I solved this by following JollyNox’s advice in this forum (I changed the 15.0 key in the Registry Editor to 14.0 since apparently UE4.24.1 only accesses 14.0). Now the errors I am getting are **“No CMAKE_C_COMPILER could be found.” **and **“Unable to generate projects for PhysX, Win64-VS2015.” **I am trying to solve these issues by following this advice in this stackoverflow post, but to no avail.

I was wondering if anyone has had luck with this? And, before spending more time trying to solve this PhysX issue, I was wondering if anyone knows if this is even the correct approach to sending vertex position data of StaticMeshComponents to the Vertex Shader?

Thank you!

Hi Allan,

Let me tell you that I’ve been working on c++ shader development too, so I understand your frustration. So far, I also found this good series of blog posts about Unreal Engine 4 Rendering, which covers shaders, vertex factories and drawing policies. I’ve also been trying to modify the vertex positions in a static mesh based on the Temaran’s tutorial you pointed out, but I’ve had no luck. I understood that the different vertex factories determine the data that is passed through the vertex shader. The way to determine which vertex factory should be used for each mesh class is determined by a proxy. So for example, for a InstancedStaticMesh you’ll see that it uses a struct FInstancedStaticMeshVertexFactory derived from the FLocalVertexFactory (this dictates the ATTRIBUTES[n] that are passed in). However I haven’t managed to edit the the position of the vertices. I’ll keep posting here if I get to understand this better.

Good luck