# Negative values in Render Target

**URL:** <https://forums.unrealengine.com/t/negative-values-in-render-target/330638>\
**Category:** C++\
**Tags:** rendertarget, opengl, unreal-engine, UE4, CPP, question\
**Created:** [September 1, 2015, 4:51pm UTC](https://forums.unrealengine.com/t/negative-values-in-render-target/330638 "2015-09-01T16:51:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_f50088e8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f50088e8](https://forums.unrealengine.com/u/anonymous_user_f50088e8)\
**Post date:** [September 1, 2015, 4:51pm UTC](https://forums.unrealengine.com/t/negative-values-in-render-target/330638/1 "2015-09-01T16:51:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ryguydavis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ryguydavis](https://forums.unrealengine.com/u/ryguydavis)\
**Post date:** [October 20, 2022, 4:32pm UTC](https://forums.unrealengine.com/t/negative-values-in-render-target/330638/2 "2022-10-20T16:32:21Z")

</div>

> [@anonymous\_user\_f50088e8](#):
>
> sses 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 h

This may be a bit late, but for anyone searching for the answer it was addressed here: [Reddit - Dive into anything](https://www.reddit.com/r/unrealengine/comments/513p1s/enable_negative_values_in_render_targets/)

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.

---

<div class="post-metadata">

**Author:** ![RVillani](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rvillani/32/1194572_2.png) [@RVillani](https://forums.unrealengine.com/u/RVillani)\
**Post date:** [October 14, 2023, 1:11am UTC](https://forums.unrealengine.com/t/negative-values-in-render-target/330638/3 "2023-10-14T01:11:27Z")

</div>

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:

```cpp
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](https://learn.microsoft.com/en-us/windows/win32/api/dxgiformat/ne-dxgiformat-dxgi_format) 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.

---

<div class="post-metadata">

**Author:** ![Pulas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pulas](https://forums.unrealengine.com/u/Pulas)\
**Post date:** [September 13, 2024, 12:08pm UTC](https://forums.unrealengine.com/t/negative-values-in-render-target/330638/4 "2024-09-13T12:08:33Z")

</div>

Thanks for your reply. Now I can output negative values into the rgb channel into a render target, but the opacity gets clamped to zero. Is there any way to remove the limitation of opacity range (0 - 1)? I wanna render negative values for opacity to TextureRenderTarget2D.

---

<div class="post-metadata">

**Author:** ![RVillani](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rvillani/32/1194572_2.png) [@RVillani](https://forums.unrealengine.com/u/RVillani)\
**Post date:** [September 25, 2024, 5:41am UTC](https://forums.unrealengine.com/t/negative-values-in-render-target/330638/5 "2024-09-25T05:41:12Z")

</div>

You can’t store the negative opacity values, or they just don’t render the way you expect them to?  
If it’s the first, I don’t know what to say. But if it’s the latter, I believe blending function don’t expect negative alpha values at all.
