Hi there folks,
Since this is my first post on the forum I feel the obligation to briefly introduce myself.
INTRODUCTION
Let me start by confessing that I am new to game programming all together (if you don’t count some fiddling around with OpenGL about 15 years ago) and that’s why I am here. Being a veteran C# programmer, I initially started with Unity and spent some time with it in the past few months. During that time, I worked on a procedurally generated game which was a great learning exercise. However, in the end, I feel like I can do more with UE4 since it allows me to use C++ end-to-end by avoiding data marshaling and massive garbage collection overhead, while doing explicit vectorization. Given the fact that procedural generation I am doing is CPU bound, the performance gain I am hoping to get from this transition, from MONO (which is what Unity uses underneath) to C++, is substantial. And the first tests are quite encouraging; with explicit vectorization (AVX2) I achieved between 4x to 18x increase in performance in different parts of the game. And keep in mind that I am just learning C++ and SIMD programming whereas I am really, really good at C#. Moreover, these are not micro-benchmark style measurements but they reflect the gains in certain aspects of the actual game. To be more specific, generating noise for a 32x32x32 volume was 18 times faster on C++ after vectorizing the exact same noise function I am using in Unity. I did not modify the logic in the algorithm, it was just vectorized and the output from C++ and C# versions match one-to-one. As you can tell, I am really excited about the possibilities UE4 and C++ provides…
THE QUESTION:
I created a custom shader which works fine in Unity but I am having difficulty with translating it to UE4’s material format. The part that I couldn’t figure out is accessing the non-interpolated UV values within the Material Editor. The sample below shows how I do this in the custom shader I created;
void vertex(inout appdata_full v, out Input o)
{
...
o.texcoord1 = v.texcoord1; // Store the non-interpolated UV values.
}
void pixel(Input IN, inout SurfaceOutputStandard o)
{
// Grab the non-interpolated UV value from IN.texcoord1 and do some stuff with it.
...
}
I simply capture the non-interpolated UV values in the vertex shader and pass them to the pixel shader for consumption. However, I couldn’t find out how to access vertex shader data within the Material editor…
Any help would be greatly appreciated.
TL;DR: How do I access non-interpolated UV values in the Material Editor?
Note: Not sure if it makes a difference but the UV values I am trying to access are stored in the second UV channel, UV1, which I am able to pass to the vertex buffer after modifying the UProceduralMeshComponent class.