In the Environment, set Background > Mode to Canvas (env.background_mode = Environment.BG_CANVAS). In our Godot 4.7 test with a LUT that swaps red and blue, a red 3D quad came out blue, but a red 2D ColorRect stayed red at (204, 51, 25), on the main canvas and in a CanvasLayer. With Background Mode Canvas the same ColorRect came out blue, (15, 45, 209). CanvasLayers above layer 0 stay ungraded unless you raise Max Layer, which keeps a HUD's colors exact.
The code
For when you want a strength slider, exact colors, or to grade layers you choose: add_grade() adds a CanvasLayer with a full-screen ColorRect that looks every pixel below it up in your LUT, set to let clicks through. Save it as lut_2d.gd, then for example: const Lut2D := preload("res://lut_2d.gd") and Lut2D.add_grade(self, preload("res://my_lut.png"), 100, 0.8), where the PNG is a LUT imported as a Texture3D. HUD and menus on layers above 100 keep their own colors.
extends RefCounted
## LUT color grading for 2D games and 2D layers, with a strength setting.
## A full-screen ColorRect reads the screen and looks every pixel up in a 3D LUT.
## The built-in way is the Environment's Background Mode set to Canvas; this one also grades CanvasLayers you pick.
const SHADER := """shader_type canvas_item;
uniform sampler2D screen_tex : hint_screen_texture, filter_linear;
uniform sampler3D lut : filter_linear, repeat_disable;
uniform float amount : hint_range(0.0, 1.0) = 1.0;
void fragment() {
vec3 c = clamp(texture(screen_tex, SCREEN_UV).rgb, 0.0, 1.0);
float n = float(textureSize(lut, 0).x);
vec3 graded = texture(lut, c * (n - 1.0) / n + 0.5 / n).rgb; // sample texel centers
COLOR = vec4(mix(c, graded, amount), 1.0);
}
"""
## Adds a CanvasLayer at layer with a full-screen grade. Everything drawn below that layer is graded.
## Put HUD and menus on a higher layer to keep their colors exact.
static func add_grade(parent: Node, lut: Texture3D, layer := 100, amount := 1.0) -> CanvasLayer:
var cl := CanvasLayer.new()
cl.layer = layer
var rect := ColorRect.new()
rect.set_anchors_preset(Control.PRESET_FULL_RECT)
rect.mouse_filter = Control.MOUSE_FILTER_IGNORE # a full-screen ColorRect would block clicks
var sh := Shader.new()
sh.code = SHADER
var mat := ShaderMaterial.new()
mat.shader = sh
mat.set_shader_parameter("lut", lut)
mat.set_shader_parameter("amount", amount)
rect.material = mat
cl.add_child(rect)
parent.add_child(cl)
return cl
What we measured
A 16 x 16 x 16 LUT that swaps red and blue, set as the Environment's color correction with Adjustments on. We read the color at the middle of a ColorRect or quad colored (204, 51, 25). Two runs gave the same numbers.
- Unshaded 3D quad: (12, 44, 209), graded. Without the LUT: (204, 50, 22).
- 2D ColorRect on the main canvas: (204, 51, 25), not graded. In a CanvasLayer: (204, 51, 25).
- Background Mode Canvas: main canvas (15, 45, 209), graded. A CanvasLayer at layer 1: (204, 51, 25), not graded, because Max Layer starts at 0. With Max Layer 1: (15, 45, 209).
- add_grade(): (25, 51, 204), exactly red and blue swapped. A HUD ColorRect on layer 101: (204, 51, 25). Strength 0.5: (115, 51, 115). A blue (76, 153, 230): (230, 153, 76). White and black stayed white and black.
- The ColorRect add_grade() makes has Mouse Filter Ignore, so it does not block clicks.
Why it happens
Adjustments are applied to the 3D render, and 2D is drawn on top of it afterwards, so it misses them. Background Mode Canvas makes the canvas layers up to Max Layer the background of the 3D render, so they go through the Environment like a 3D scene does. Like the 3D quad, they came out a little off the plain swap. The shader in add_grade() reads the finished screen instead and gave the exact swapped values. We tested with the Compatibility renderer only.
What to change
- Max Layer: raise it to grade CanvasLayers too, and keep the HUD on a layer above it.
- A strip PNG that grades wrong: import a LUT strip as a Texture3D with the right slices.
- A full-screen overlay that blocks your buttons: set its Mouse Filter to Ignore.
Ready-made grades: 24 Game Genre LUTs has 24 color grades for horror, cyberpunk, cozy, fantasy, wasteland and retro games. Its Godot 4 version comes as 24 WorldEnvironment looks with each LUT already imported as a Texture3D, plus a script that copies just the grade, glow, fog and tonemap onto your own WorldEnvironment.
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 24 Godot 4 WorldEnvironment looks with each LUT already 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
- 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
- Use a LUT strip for color grading in Godot 4
- 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