# Creating normal map from Float

Hello everybody,

I am getting crazy in trying to do something in UE which seems to be really simple

I want to convert a black and white map into a normal map in the material editor
Normaly, when it is about converting a texture object into a normal, I use the NormalFromHeightmap function and everything works perfect
This time I’m trying to convert a GeneratedBand into and plug it into my normal slot (Of course it could be anything in greyscale such as a noise etc.)
As the NormalFromHeightmap only accepts textures objects (T2D) as an input I can’t do anything with my Vector3 output (except crying)

I searched for some information and the NormalFromFunction seems to be an option
Unfortunately, it is hard to find a tutorial about this function (event the UE doc doesn’t mention it)
It seems it can generate a normal if, for example, you generate 3 different GeneratedBands (or anything else such as noise) with a small offset variation
I’m sure I’m wrong somewhere as this process seems really tedious when you deal with complex procedural generated textures

I also searched a way to convert a Vector3 into a texture object but I didn’t find anything

For short I’m just looking for a NormalFromHeightmap function that accepts Float input

I hope some Unreal Genius will read my post and help me as I’m totaly desperate
Best,

1 Like

Well, NormalFromHeightmap function relies on sampling the heightmap with offset to determine slope, that is why it takes texture object as parameter. You cannot sample a float value or vector. So in your search for NormalFroMHeightmap function that accepts float, I’ll disappoint you. There is none.

What is your intended use with this setup? In overriding majority of cases there is either a better approach or workarounds.

As for, NormalFromFunction, it can generate normals from mathematical function, but its application is somewhat limited. It works by calculating a slope between offset versions of the same function, and should be used as follows, if i’m not mistaken:

• Function(UV1) input is your original function.
• Function(UV1) input is the same function, but it has to be offset by Height Map UV Offset value in R.
• Function(UV3) input is the same function, but it has to be offset by Height Map UV Offset value in G.

http://image.prntscr.com/image/7d2e15e8716b4471a8f797a947c5b1db.png

Thank you very much for you fast reply !!!
Indeed I’m really confused by the concept of Function, Float and Vector
I come from the 3dsMax / Vray world and there, when you create textures and materials, everything can be mixed together
A noise texture, for example, is considered as an RGB texture (as far as I know)
It’s really hard for me to understand the concept … I’m sure it is related to the way graphic cards deals with shading

In my case, I use a mix of procedural textures to animate a rain drops texture :

When I plug the result in any slot (Base Color, Emissive etc.) everything works as if it was an texture map … (it is really frustrating cause I only want to use it as a normal map)
My setup is really complex and I wish I can avoid multiply it by 3 just to be able to create a normal map
If only I could offset the texture just before pluging it into the NormalFromFunction box … here it seems I have to duplicate my whole graph 3 times

I thought I was close to the goal when I saw my animated black and white texture
I will try to replicate what you post on your screenshot and see what appens

Once again, thank you for your answer

I can’t say that it is completely not doable, the way you are approaching it now I mean. In the end it won’t matter that much if you are going for a still picture.

If that real-time playback you are after, I would probably suggest baking ripple wave normal map animation frames in your modelling package, packing it into sprite sheet, and using a flipbook material function to get animation frames inside your material.

Do you mind showing material function, that generates your ripples? Quite curious:cool:

Lastly, If you surely would like to have procedural ripple normal map, maybe it would be better to generate normal map right away, instead of trying to get it from height map ?

Ok thanks
I’ll try to find a way to solve the problem or I’ll restart from scratch with another strategy

Concerning the ripples, I was greatly inspired by this really cool tutorial : Raindrops Shader Tutorial - Unreal 4 - YouTube
I really loved the concept of “spreading” a lot of elements onto the texture using only one black and white texture and cycling through colors
Same effect with an animated texture must be way more expensive in terms of memory I think (let’s say at leat 50 frames of 1024 animated texture …)
Maybe You know how to randomly duplicate a large number of small animation onto a surface ? (same as creating a lot of decals of a simple ripple in my case)

I’ll let you know if it works
Thanks !

You would definitely use something more realistic, like one 2048x2048 that contains 64 frames,256x256 per frame, for example.

You can take a look at rendering your height map into render target. It should be avaliable from version 4.13 Then you can safely use NormalFromHeight function.

There is also a good paper about dynamic rain effects here. This one is my personal favorite.

Hi

A quick update concerning the shader
I followed your advice and restart from scratch
For short I created a simple ripple effect in After Effects then I applied this on multiple planes in 3dsmax and rendered an animation
Then I built a sprite sheet and used it in Unreal as a normal

It is just the begining but it works !!

I’ll now fine tune everything and I’ll post a video of the result as soon as it’s done

Good to hear that . Saving you some efferts, gotta say that you are likely to face two issues though.
First is occasional mismatched flipbook frames at texture seam. I think you have that one present in the screenshot. This is fixed by applying frac node to UV coordinates, that are fed to flipbook material function.

The second issue is caused by fixing the first and results in incorrect mip-map being selected. Dealing with it is described in this post.

There is method to make this same effect with using only single texture and animation is done procedurally with code.

You could also do rain drops using the new draw material to render target system. I created a rain material that should work with the content examples Draw to Render Target example level.

This works by basically jittering tiny forces within each grid. The controls are the density, drop size, and jitter speed.

You could just let this create a tiling texture without handling player input if you wanted to.

Custom node code:

``````
float2 noise = dot(pos.xy * pos.xy, float2(12.581057, 11.129465));
noise.y = dot(pos.xy * pos.xy/5, float2(46.538326, 11.057759));

return frac(noise);

``````

Also on the constantbiasscale, Bias= -0.5, scale = 2.

2 Likes

Wahoooo °____0
You all seems to know the material editor at a Jedi’s level
I’m really not into programing my own shaders but I’ll give it a try an see what happens
For sure your examples looks terrific and I hope I’ll get the same result
I’ll give you more information as soon as I implement everything in my material
Thanks a lot !!!

Ryan, but how you perform normal maps from that code? Using NormalFromFunction or something else?

p.s. 3 year necropost :eek:

1 Like