This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
forked from godotengine/godot
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Rasterizer API for display color management.
Use VisualServer::set_screen_lut to set a 3D texture for color management. Its X, Y, Z axes correspond to R, G, B channels. LUT transformation happens in Rasterizer, ensuring that all content blitted to screen are processed exactly once. This implements part of godotengine#26826.
- Loading branch information
Showing
16 changed files
with
249 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* clang-format off */ | ||
[vertex] | ||
|
||
attribute highp vec4 vertex_attrib; // attrib:0 | ||
/* clang-format on */ | ||
|
||
attribute vec2 uv_in; // attrib:4 | ||
|
||
uniform highp vec4 screen_rect; | ||
|
||
varying vec2 uv_interp; | ||
|
||
void main() { | ||
uv_interp = uv_in; | ||
gl_Position = vec4(screen_rect.xy + vertex_attrib.xy * screen_rect.zw, vertex_attrib.zw); | ||
} | ||
|
||
/* clang-format off */ | ||
[fragment] | ||
|
||
uniform vec2 texel_count; | ||
uniform vec2 chunk_count; | ||
|
||
uniform sampler2D source; //texunit:0 | ||
uniform sampler2D lut; //texunit:1 | ||
/* clang-format on */ | ||
|
||
varying vec2 uv_interp; | ||
|
||
vec2 flatten_3d(vec2 chunk_size, vec2 texel_size, vec2 xy, float z_scaled) { | ||
float row = floor(z_scaled / chunk_count.x); | ||
float col = mod(z_scaled, chunk_count.x); | ||
return chunk_size * vec2(col, row) + (chunk_size - texel_size) * xy + texel_size * 0.5; | ||
} | ||
|
||
void main() { | ||
vec4 color = texture2D(source, uv_interp); | ||
vec3 clamped_rgb = clamp(color.rgb, 0.0, 1.0); | ||
|
||
vec2 texel_size = 1.0 / texel_count; | ||
vec2 chunk_size = 1.0 / chunk_count; | ||
|
||
float z_scaled = clamped_rgb.b * (chunk_count.x * chunk_count.y - 1.0); | ||
vec4 low = texture2D(lut, flatten_3d(chunk_size, texel_size, clamped_rgb.rg, floor(z_scaled))); | ||
vec4 high = texture2D(lut, flatten_3d(chunk_size, texel_size, clamped_rgb.rg, ceil(z_scaled))); | ||
|
||
gl_FragColor = vec4(mix(low.rgb, high.rgb, mod(z_scaled, 1.0)), color.a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* clang-format off */ | ||
[vertex] | ||
|
||
layout(location = 0) in highp vec4 vertex_attrib; | ||
/* clang-format on */ | ||
|
||
layout(location = 4) in vec2 uv_in; | ||
|
||
uniform highp vec4 screen_rect; | ||
|
||
out vec2 uv_interp; | ||
|
||
void main() { | ||
uv_interp = uv_in; | ||
gl_Position = vec4(screen_rect.xy + vertex_attrib.xy * screen_rect.zw, vertex_attrib.zw); | ||
} | ||
|
||
/* clang-format off */ | ||
[fragment] | ||
|
||
uniform vec3 texel_count; | ||
|
||
uniform sampler2D source; //texunit:0 | ||
uniform sampler3D lut; //texunit:1 | ||
/* clang-format on */ | ||
|
||
in vec2 uv_interp; | ||
|
||
layout(location = 0) out vec4 frag_color; | ||
|
||
void main() { | ||
vec4 color = texture(source, uv_interp); | ||
vec3 coords = clamp(color.rgb, 0.0, 1.0) * (1.0 - 1.0 / texel_count) + 0.5 / texel_count; | ||
frag_color = texture(lut, coords); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.