mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Auto invert preview colors based on the screen color
Basically, when the background color of the screen at certain points is dark, the preview at that spot is white, and when it is bright, the preview is white at that spot. This helps to keep the previews always distinguishable, regardless of the background color.
This commit is contained in:
parent
61e7633365
commit
6499c0d3d5
25
src/Shaders/AutoInvertColors.shader
Normal file
25
src/Shaders/AutoInvertColors.shader
Normal file
|
@ -0,0 +1,25 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
|
||||
vec3 rgb2hsb(vec3 c){
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = mix(vec4(c.bg, K.wz),
|
||||
vec4(c.gb, K.xy),
|
||||
step(c.b, c.g));
|
||||
vec4 q = mix(vec4(p.xyw, c.r),
|
||||
vec4(c.r, p.yzx),
|
||||
step(p.x, c.r));
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-10;
|
||||
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)),
|
||||
d / (q.x + e),
|
||||
q.x);
|
||||
}
|
||||
|
||||
|
||||
void fragment() {
|
||||
vec3 screen_color = rgb2hsb(textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb);
|
||||
if(screen_color.z < 0.5){
|
||||
COLOR.rgb = vec3(1.0) - COLOR.rgb;
|
||||
}
|
||||
}
|
|
@ -112,7 +112,7 @@ func draw_preview() -> void:
|
|||
canvas.draw_set_transform(start - t_offsetv, canvas.rotation, canvas.scale)
|
||||
|
||||
for line in _create_polylines(indicator):
|
||||
canvas.draw_polyline(PoolVector2Array(line), tool_slot.color)
|
||||
canvas.draw_polyline(PoolVector2Array(line), Color.black)
|
||||
|
||||
canvas.draw_set_transform(canvas.position, canvas.rotation, canvas.scale)
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ func draw_preview() -> void:
|
|||
canvas.draw_set_transform(rect.position - t_offsetv, canvas.rotation, canvas.scale)
|
||||
|
||||
for line in _create_polylines(indicator):
|
||||
canvas.draw_polyline(PoolVector2Array(line), tool_slot.color)
|
||||
canvas.draw_polyline(PoolVector2Array(line), Color.black)
|
||||
|
||||
canvas.draw_set_transform(canvas.position, canvas.rotation, canvas.scale)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=12 format=2]
|
||||
[gd_scene load_steps=14 format=2]
|
||||
|
||||
[ext_resource path="res://src/UI/Canvas/Canvas.gd" type="Script" id=1]
|
||||
[ext_resource path="res://src/UI/Canvas/Grid.gd" type="Script" id=2]
|
||||
|
@ -9,6 +9,7 @@
|
|||
[ext_resource path="res://src/UI/Canvas/Previews.gd" type="Script" id=7]
|
||||
[ext_resource path="res://src/UI/Canvas/Selection.gd" type="Script" id=8]
|
||||
[ext_resource path="res://src/Shaders/MarchingAntsOutline.shader" type="Shader" id=9]
|
||||
[ext_resource path="res://src/Shaders/AutoInvertColors.shader" type="Shader" id=10]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=1]
|
||||
blend_mode = 4
|
||||
|
@ -22,6 +23,9 @@ shader_param/width = 0.05
|
|||
shader_param/frequency = 200.0
|
||||
shader_param/stripe_direction = 0.5
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=4]
|
||||
shader = ExtResource( 10 )
|
||||
|
||||
[node name="Canvas" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
|
@ -58,4 +62,5 @@ centered = false
|
|||
script = ExtResource( 3 )
|
||||
|
||||
[node name="Previews" type="Node2D" parent="."]
|
||||
material = SubResource( 4 )
|
||||
script = ExtResource( 7 )
|
||||
|
|
Loading…
Reference in a new issue