Found some HLSL code I'd love to use in a material. What's the best way to implement it? (Custom node seems too restrictive)

I have stumbled into a rabbit hole, it seems.

I have been using the FastNoiseLite library within my game in order to generate a voxel world. It’s been working really well on the CPP/Actor side of things, but I quickly realized that materials use a completely different workflow. So I can’t tap into the CPP version of the library.

After double-checking, I found that a part of the repository includes the library fully transposed into one large HLSL file:

How would I even begin to implement this so that I can play around with its features within a Material blueprint? I don’t mind putting in the work to transpose this into whatever variation of syntax that Unreal needs, but I don’t even know where to start.


Specific to my use-case, here is what I am trying to accomplish;

I am generating a 3D block word (think Minecraft), and instead of “Grass” or “Dirt”, I have one singular “Soil” tile which can have a Fertility value between 0-1.

This Fertility value is computable by the FastNoiseLite library, which is able to take the block’s world position and get some noise value for it. From there, I can use CPP & FColor to set that block’s color.

This has a very blocky effect.

On top of that, the implementation on the above screenshot is not performant in terms of vertex count. Since every Soil block is technically different, I can’t use a greedy algorithm to combine groups of Soil blocks together, otherwise I will get this artifacting:

So ultimately what I would love to do is:

  1. Use my Greedy Chunk generation logic
  2. Use a shader that uses the identical Noise algorithm to paint my Soil blocks’ faces at a per-pixel level. (Imagine the first image above, but perfectly smooth instead of blocky)

This is where I imagine a custom shader from the HLSL code comes into play. Does anyone have any pointers on how I could get started with this?

Here’s my reddit post asking the same question. Got some answers there, but haven’t had time to try any yet:

https://old.reddit.com/r/unrealengine/comments/1i0ogc6/found_some_hlsl_code_id_love_to_use_in_a_material/

Progress!

After stumbling around with the basics, I have verified that one of the solutions may work (but will require a MASSIVE amount of transposition)

//Woefully short of the 2300 lines I need to transpose

struct Functions
{
  //define the contents of a noise state struct
  struct fnl_state
  {
    float seed;
    //need to pass in all of the other struct variables
  };

  //create a struct containing all of the noise values
  fnl_state createState(float i)
  {
    fnl_state newState;
    newState.seed = i;
    //need to pass in all of the other struct variables
    return newState;
  }

  //placeholder noise functio
  float3 fnlGetNoise3D(fnl_state state)
  {
    return float3(0, state.seed, 0); //if Seed_In is 1, this will return green.
  }

};

Functions f;

return f.fnlGetNoise3D(f.createState(Seed_In));