How do I add Tony McMapface tonemapper to UE 4.27?

Hello,

I got Tony McMapface tonemapper from Github.

It’s a .dds LUT file and a .HLSL file. I converted .dds to .tga since UE4 doesn’t recognize the format.

The custom node has this code

//Texture3D tony;
SamplerState sampler_linear_clamp;

// Apply a non-linear transform that the LUT is encoded with.
float3 encoded = stimulus / (stimulus + 1.0);

// Align the encoded range to texel centers.
float LUT_DIMS = 48.0;
float3 uv = encoded * ((LUT_DIMS - 1.0) / LUT_DIMS) + 0.5 / LUT_DIMS;

// Note: for OpenGL, do uv.y = 1.0 - uv.y

return tony.SampleLevel(sampler_linear_clamp, uv, 0);

And I’m getting a [SM5] D3DCompile exception error.

The issue is how you’re feeding the texture into the Custom node. You need to pass it as a Texture Object (not a Texture Sample). In the Custom node, add an input with type Texture3D — that’s what the tony.SampleLevel(…) call expects.

If you’re using a Texture Sample instead, the node receives already-sampled color data, not a texture resource the HLSL code can sample from with custom UVs.

Also, since the original LUT is a 48³ 3D DDS and you converted it to TGA, the volume texture data may have been lost in conversion — TGA doesn’t support 3D textures. I’m not sure about the best way to handle this in UE4, but you’ll need to make sure the texture is imported as a Volume Texture for the Texture3D sampling to work.

For the input color (stimulus), make sure you’re reading from PostProcessInput2 (not 0) — this gives you the scene color before engine tonemapping is applied, which is what you want for a custom tonemapper.

So the setup should be:

stimulus input ← SceneTexture: PostProcessInput2

tony input ← Texture Object (your imported LUT), with input type set to Texture3D, imported as a Volume Texture

1 Like

Thanks for the reply, I actually solved it a while ago by converting it to .dds and using some custom ChatGPT code for sampling.