How to Render Target as Normal?

Hi All,

I’m trying to Create a Render Target as a Normal Map. However, it doesn’t seem to change the compression settings to normalmap even though I’ve set them (they just save as HDR).

Here’s a little example to show what I mean. The Render Target isn’t changing to normal and when I export it the new .png file it creates still shows the compression settings as HDR.

Any help on how to properly change the Render Target to a Normal Map?

(Worth noting I’m trying to do this through code - I know I could save it to disk and manually change the format but that’s not what I’m looking for).

Huge Thanks!

Hi HappyKay100,

It’s probably saving as HDR because of the RTF_RGBA16F float format, try changing that to RTF_RGBA8…

@RecourseDesign Thanks for the suggestion.

Sadly changing it to RTF_RGBA8 saves it as DXT1 / Default format. For some reason it’s still not letting me change it to a normal programmatically??

The saved PNG will not remember what you set the compression type as - it uses the built in PNG compression and doesn’t have anywhere to store the UE compression type (That’s stored in the uasset files).

UE decides which compression type to use when importing PNGs depending on the color information - if the png file has the blue colors in it (dark blue to cyan to greenish) it will recognize it as a NormalMap and change the compression type to Normal then.

All you should need to do is to make sure that the rendertarget has the correct normal data in it - UE will do the rest…

Thanks @RecourseDesign, what you’re saying makes sense, but doesn’t seem to work.

I tried making a basic unlit texture and plugging the normal into the Emissive Color so it just sends the normal texture through…

Then I just render the material to a Render Target and export as .png…

…but the exported render target is still DXT1 / Default format. It doesn’t automatically recognize it as Normal. What am I doing wrong here??

(I also tried making the normal material lit and sending the normal map through the normal channel. It didn’t really make sense to do that and I can confirm that didn’t work either).

Try changing the “Clear Color” to 0.5,0.5,1.0 which is a Normal pointing towards the camera - I just tested it here by just saving that - and it imported it as a normal map…

If that imports as a normal for you, it will be something to do with the draw material - something else to check is to make sure “sRGB” is turned off…

If it doesn’t import as a normal with just the simple Clear Color - it could be that you need to choose a new name for your file - I don’t know if it works this way, but it’s possible you’ve clicked “revert” after UE has decided to import the file as a normal and it’s remembered that setting…

Thanks again @RecourseDesign. I can recreate your graph and it does import the png as a normal map when not using a material.

However, the minute I plug a material into the Render Target it doesn’t work. As you can see the material I’m testing with is super simple and is just an unlit shader with a normal plugged into the Emissive channel. Were you able to get it to work with a normal material plugged in?

I just tried and yes, I can see what is happening - you need to make a couple of changes to your material (atm it’s setting the alpha channel to 0 which UE then interprets as it NOT being a normal):

Set the Materials “Blend Mode” to “AlphaHoldout” and pass in a value of “0” to the Opacity pin:

That should be enough to fill the alpha channel with 1.0. It imports here as a normal…

Edit: actually this just blasts the alpha channel on the render target and doesn’t fill the diffuse - see the next post…

@RecourseDesign - Wow, I really appreciate you going the extra steps to help here - you truly are a great person! Thank you!

I can get it working like you with the Alpha holdout but that just gives me a blank normal map and I want to load in and then export a normal texture.

I tried plugging in a texture sample of a normal map into the opacity of my material to see what that would give but it doesn’t quite work…

Here’s the actual normal map…

Here’s what is created with the exported normal png…

Any ideas on how I can get it to export the proper normal map texture?

The way to get it working with a normal map passed in is to change the “Blend Mode” to “Additive” (make sure you’re clearing the render target to 0,0,0,1) - this seems to fill the alpha channel correctly.

Normal Maps are stored as values between -1.0 and 1.0 - so to get that information out from an “unlit” material - you need to multiple the normal value by 0.5, then add 0.5 to make it range between 0.0 and 1.0:

@RecourseDesign This did the trick!! Thank you so much! I would have never figured that out on my own.

1 Like

Dear @RecourseDesign , thanks for helping! But after I follow your instructions, I still get undesirable results, can you help me?

Here is the setting:

Here is the baking blueprint actor

This is the render target setting

As a result, you can see it seems not to convert to a common normal map, what I’m doing wrong?

I’m trying to bake out the MetaHuman normal map texture, I think it should output like this.

Hi Eugene_Lin,

The output looks like it’s correct - as in the colors look correct - I’m guess that the noise that you’re merging it with is the culprit - try adding a FlattenNormal node for the source of that one:

image

Dear @RecourseDesign ,
Thank you immensely for your prompt response! Following your suggestion, I connected the FlattenNormal node to where your arrow indicates.
Here is the full connection:

However, after executing the Baking blueprint’s compile, I still ended up with the exact same Normal image.
The result:

Moreover, when I tried to simply input a common Normal texture for baking, the result was quite peculiar. The details vanished, and the baked Normal texture became exceptionally bright.
The normal map I input:

Connect the normal map to MAT_Baking:

The result I got:

Thank you once again for taking the time out of your busy schedule to respond. Kindly review and clarify my confusion. Much appreciated!

Eugene

Ok - I see that the detail normal actually does a kind of flatten with the Lerp with 0,0,0.

Try taking out that flatten normal node again - and just change the “DetailAmount” value down to about 0.1 or so.

Try changing the Material Mode from “Multiply” to “Premultipled Alpha” - that may help with the brightness too.

I attempted to follow your instructions, but regrettably, the result still appears to be off. The “DetailAmount” parameter seems to merely adjust the Alpha of the Lerp, yet the final baked image doesn’t seem to be calculated correctly.
The node:

The Baking result:

But I tried changing the value of input A for Lerp from [0,0,1] to [0,0,0], and upon baking, there seemed to be some progress.
Adjust the input Lerp value:

The result:

I’m not entirely sure if the direction of my attempt is correct. Perhaps I could provide you with my UE file for easier testing on your end?
UE_file

Hi Eugene_Lin,

That’s close - you just need to add “Normalize” nodes after the “BlendAndleCorrectedNormals” - note that the “TeethSharpNormal” seems to be out of placement too - you may need to clean up that texture.

OMG! After I follow your instruction, add two normalize, and it works perfectly! And I also check the problem you mentioned, I found out there is one connection input in the Multiply node from the original Material Graph.

The original node connection in M_Teeth material:

Fix it in my MAT_Baking Material Graph and follow your instructions:


But this time I didn’t change the DetailAmount, I kept it to 1.0.

The Baking result:

I adjust the Texture Group option to “WorldNormalMap” and Compression Settings to “NormalMap (DXT5, BC5 onDX11)”, which seems to display more accurately.

But one thing I’m not sure about is the original normal map “Mip Gen Settings” is set to “FromTextureGroup”, but my Baking result is set to “NoMipmaps”, is there any difference between these two options?

The original normal map “Mip Gen Settings”:

Good to hear!

The default Compression settings for NormalMap is DXT5 - setting it there is a good idea to ensure it stays as a normalmap.

The “NoMipMap” setting will mean the texture is always stored in your GFX card at the full resolution - if you’re wanting top quality (and this isn’t in a game) then that’s a good setting to use - otherwise leaving it as “From Texture Group” is a good idea - that way it gets controlled from the “Scalability” settings.