← Pixel Dreamer Studio

Use a LUT strip for color grading in Godot 4

Import the strip as a Texture3D with one row of slices, or build the 3D texture from the image in code.

Select the LUT PNG in the FileSystem dock, set Import As to Texture3D, set the horizontal slices to the strip's height (32 for a 1024 x 32 strip) and the vertical slices to 1, reimport, then put it in the Environment's adjustment_color_correction with Adjustments enabled. In our Godot 4.7 test with a LUT that swaps red and blue, the strip imported as a plain Texture2D left red as red and turned green black, and a Texture3D with Godot's default 8 x 8 slices gave wrong colors too. With 32 x 1 slices, or built with the script below, every color came out right.

The code

Use it when the LUT comes from a file at runtime, such as a look picked in a settings menu or a mod, or to skip the import settings. from_strip() takes any strip whose width is its height squared and returns an ImageTexture3D. apply() turns Adjustments on, sets the LUT and warns when it is given a Texture2D. Save it as lut_strip.gd, then for example: const LUT := preload("res://lut_strip.gd") and LUT.apply(env, LUT.from_strip(load("res://luts/warm.png").get_image())).

extends RefCounted
## Builds a real 3D LUT from a LUT strip image (N squares of N x N side by side, e.g. 1024 x 32)
## for Environment.adjustment_color_correction.


static func from_strip(strip: Image) -> ImageTexture3D:
	var img := strip.duplicate() as Image
	if img.is_compressed():
		img.decompress()
	img.convert(Image.FORMAT_RGBA8)
	var n := img.get_height()
	if img.get_width() != n * n:
		push_error("A LUT strip must be %d x %d pixels, this one is %d x %d" % [n * n, n, img.get_width(), n])
		return null
	var slices: Array[Image] = []
	for z in n:  # square z = blue level z
		slices.append(img.get_region(Rect2i(z * n, 0, n, n)))
	var tex := ImageTexture3D.new()
	tex.create(Image.FORMAT_RGBA8, n, n, n, false, slices)
	return tex


static func apply(env: Environment, lut: Texture) -> void:
	if lut is Texture2D:
		push_warning("A Texture2D here is read as a 1D gradient, not a 3D LUT. Reimport it as Texture3D or use from_strip().")
	env.adjustment_enabled = true
	env.adjustment_color_correction = lut

What we measured

Four unshaded squares, red, green, blue and orange (1, 0.5, 0), seen through a 32-step LUT that swaps red and blue. We read the screen pixel in the middle of each square. Two runs gave the same numbers.

Why the default import goes wrong

A LUT strip is a 3D table cut into squares: each square is one level of blue, red runs across the square and green runs down it. Imported as a Texture2D it is just a wide picture, and Godot reads a 2D texture in this slot as a 1D gradient, one lookup per channel, so the colors cannot mix the way a LUT needs. As a Texture3D, Godot has to be told how the picture is cut. With 8 x 8 it cut our 1024 x 32 strip into 64 pieces of 128 x 4 pixels, so most colors looked up the wrong cell.

What to change

24 ready-made looks: 24 Game Genre LUTs has cozy, cyberpunk, fantasy, horror, retro and wasteland grades as .cube files and strips, plus a Godot 4 version with every LUT already imported as a Texture3D with 32 x 1 slices and one Environment resource per look.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: 24 Game Genre LUTs has 24 color grades as .cube files and strips, plus a Godot 4 version with each LUT imported as a Texture3D.

More how-tos: Shaders, materials and lights