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.
- No LUT: red, green, blue and orange as made.
- Texture3D with 32 x 1 slices: blue, green, red and (0, 0.5, 1). Correct.
- Texture3D with the import defaults Godot filled in, 8 x 8 slices: the texture came out 64 slices deep. Red read (0.12, 0, 0.99), close enough to look right, but green read (0.02, 0.09, 0.07), almost black, and blue read (0.84, 0.92, 0), yellow.
- Texture2D, the default import: red stayed red, green turned black and orange turned red.
- The script, from that same Texture2D's image: 32 x 32 x 32, all four colors correct. An identity LUT built the same way left all four unchanged.
- The correct LUT with Adjustments switched off: no change at all.
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
- Other strip sizes work the same way: a 256 x 16 strip needs 16 x 1 slices. The script reads the size from the image height.
- We imported with Lossless compression and no mipmaps. The script builds an uncompressed texture.
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
- A 3D outline that stays the same width on screen
- Find and fix the seam in a repeating texture
- PS1 vertex wobble that is the same near and far
- Snow that stays on the roofs
- Packed ORM maps on a StandardMaterial3D
- Neon signs that share a material but not a colour
- A MatCap that stays the right way up from every side
- Scroll or tile a 2D texture without stretched edge lines
- Keep floors, roads and roofs sharp when the camera looks along them
- Make WorldEnvironment color grading apply to a 2D game
- Get a hard cel-shaded light edge from StandardMaterial3D's Toon mode
- Make metallic materials stop looking black or flat
- Make a glowing sign or screen actually light the wall around it
- Tiling textures that keep their size on any mesh
- A sharp low-resolution PS1 look
- Only 8 lights show on a long wall in Compatibility
- Hit flash shader for 2D sprites
- Flash a 3D enemy white when it takes a hit
- Dissolve shader for 3D models
- 2D outline shader that is not cut off
- 3D outline shader without gaps at the corners
- A force field shield with a hit ripple
- Normal map inverted: DirectX vs OpenGL
- Full-screen post-process shader in 3D
- Scroll a shader texture for hours without the once-an-hour jump