Negative values in Render Target

Hello,
I’m currently using a Render Target for various rendering purposes (capture and export in .HDR files). I have several different passes made with the Render Target (standard passe, passe with only the ambient occlusion, etc).

I also have a “World Position passe”. The goal is to render each pixel’s position, in the world, into the Render Target, so that a software like Nuke can read the color as a coordinate ((-127, 3, 890) for example). Here is the issue : with a standard post process material, where I plug “Absolute World Position” into “Emission”, all the negative values are clamped to 0.

My guess is that the OpenGL texture uses a normalized format, and I would need to change it into something that’s signed. Is it possible via the Editor ? And if it’s not, is it possible in the engine code ? I’ve found Engine/Source/Runtime/OpenGLDrv/OpenGLRenderTarget.cpp which seems to create the textures, but I can’t find where it gets the format exactly, and how to influence said format.

I also tried offsetting the pixel value, for example adding 32 500 to the value. The issue is that, once again, I can’t get under 0, and my values rise fast enough to reach 65 000, the maximum value. Is it possible to put another, larger format ?

Thanks in advance

This may be a bit late, but for anyone searching for the answer it was addressed here: Reddit - Dive into anything

Essentially, there’s a check box in the material editor called “Allow Negative Emissive Color”. It only works for Unlit, but that shouldn’t be a problem for most people needing this.

[Edit] LOL this definitely is late, didn’t realize it was 7 years old. Better late than never, I guess.

To write negative values into render targets, its format has to support it. As of UE 5.3, with these formats it’s possible to set negative values on the render target:

  • RTF R16f
  • RTF RG16f
  • RTF RGBA16f
  • RTF R32f
  • RTF RG32f
  • RTF RGBA32f

That’s at least true on Windows, with DirectX.

If it changes, or to figure it out for a different target RHI, follow these steps:

  1. Go to the source of GetPixelformatFromRenderTargetFormat, in TextureRenderTarget2D.h as of UE 5.3.
  2. See what pixel format the RTF you’re looking for converts into and look for its usages (using an IDE like Visual Studio or Rider).
    • One of the usages will look like this:
    GPixelformats[PF_A2B10G10R10].PlatformFormat = // Some RHI specific format
    
  3. Note that “RHI specific format” down and research it online to see if it’s signed (can be negative).
    • For DirectX formats, starting with DXGI, this page details each of them. As a tell, the ones with SNORM and FLOAT suffix can be negative. The UNORM ones, can’t. I’m not sure about TYPELESS, but I believe it can (I didn’t include the TYPELESS ones in the formats list above though).

One would assume Epic uses similar types on each RHI, with similar capabilities, but you never know. Platforms may have different limitations.