Rewriting node bump in unreal material graph

I’m working on a tool for blender and unreal but the bump node is not available in unreal.
So I’m trying to build it, based on the gpu_shader_material_bump.glsl from blender’s source.
There is two problems here :
1 - I have no idea what dHd parameter is for.
2 - the height parameter is not used in the code but works in blender :open_mouth:

Im not sure what you are exactly doing, but the equivalent of the bump node in unreal is in my opinion the normal from heightmap node

No. This node can’t make normals from procedural stuff, it needs a usual texture.
Blender’s bump can make normals with both and I’m interested by the procedural part.
I see no reason to generate the normals at runtime with a fixed texture. It’s better to build the normal map before.

I guess I should ask the question an other way : where is the real code used by the bump node ?

Bump mapping works based on modifying the shader graph, where the inputs get evaluated at 3 positions to compute a gradient. See ShaderGraph::refine_bump_nodes in Cycles. This may be difficult to replicate in another renderer.

An earlier version of Eevee used OpenGL support for computing partial derivatives instead, which may be easier replicate and more suitable for game engines, though fails for some types of shader graphs.

I recommend looking into this:
https://jcgt.org/published/0009/03/04/

2 Likes

There are 3 nodes in unreal for generating normal maps from height maps (bump mapping in the offline renderer sense):

  • PerturbNormalHQ
  • PerturbNormalLQ (This one is not available in the search, you first need to enable show engine content, and then search for it in the Engine content directory)
  • NormalFromHeightMap

PerturbNormalHQ requires PreparePerturbNormalHQ node, and will generate normal map out of any height input.

PerturbNormalLQ will do the same, much faster, but at the cost of lower, pixelated quality. Similar to what Eevee did when it had it’s very first bump mapping implementation

NormalFromHeightMap requires Texture2D asset reference, and does the texture sampling on its own, so it doesn’t take arbitrary height data, but has probably the best performance/quality ratio of all these options, in exchange for the Texture2D input limitation.

So you don’t have to implement it yourself.

3 Likes

Blockquote

  • PerturbNormalHQ
  • PerturbNormalLQ (This one is not available in the search, you first need to enable show engine

Blockquote

I searched all day long for this…
The first result is not perfect but I’m digging it.
Thank you very much.

1 Like

Using PerturbNormalHQ and PerturbNormalLQ require to uncheck TangentSpaceNoraml in material properties.
And now it looks way more like blender’s bump.

You may not need to. You should be able to just use Transform Node to transform from world space normal to tangent space or vice versa.