Add an outline to the result preview
This commit is contained in:
parent
815ec239f6
commit
f069f2911f
8 changed files with 37 additions and 6 deletions
|
@ -1,13 +1,18 @@
|
||||||
[gd_scene load_steps=10 format=3 uid="uid://bjah7k4bxo044"]
|
[gd_scene load_steps=12 format=3 uid="uid://bjah7k4bxo044"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/Main.gd" id="1_2625y"]
|
[ext_resource type="Script" path="res://src/Main.gd" id="1_2625y"]
|
||||||
[ext_resource type="Script" path="res://src/ImageViewport.gd" id="2_hvo65"]
|
[ext_resource type="Script" path="res://src/ImageViewport.gd" id="2_hvo65"]
|
||||||
|
[ext_resource type="Shader" path="res://src/shader/ivd_outline.gdshader" id="3_6xihe"]
|
||||||
[ext_resource type="Script" path="res://src/ImageViewportDisplay.gd" id="3_n4itb"]
|
[ext_resource type="Script" path="res://src/ImageViewportDisplay.gd" id="3_n4itb"]
|
||||||
[ext_resource type="Shader" path="res://src/ui_background.gdshader" id="4_ty3qx"]
|
[ext_resource type="Shader" path="res://src/shader/ui_background.gdshader" id="4_ty3qx"]
|
||||||
[ext_resource type="Script" path="res://src/UIAppVersion.gd" id="5_o1ggv"]
|
[ext_resource type="Script" path="res://src/UIAppVersion.gd" id="5_o1ggv"]
|
||||||
[ext_resource type="Script" path="res://src/Editor.gd" id="7_g8bap"]
|
[ext_resource type="Script" path="res://src/Editor.gd" id="7_g8bap"]
|
||||||
[ext_resource type="Script" path="res://src/Camera.gd" id="8_mls06"]
|
[ext_resource type="Script" path="res://src/Camera.gd" id="8_mls06"]
|
||||||
|
|
||||||
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_y2ea0"]
|
||||||
|
shader = ExtResource("3_6xihe")
|
||||||
|
shader_parameter/zoom_level = Vector2(1, 1)
|
||||||
|
|
||||||
[sub_resource type="ViewportTexture" id="ViewportTexture_lct1c"]
|
[sub_resource type="ViewportTexture" id="ViewportTexture_lct1c"]
|
||||||
viewport_path = NodePath("ImageViewport")
|
viewport_path = NodePath("ImageViewport")
|
||||||
|
|
||||||
|
@ -30,6 +35,7 @@ unique_name_in_owner = true
|
||||||
|
|
||||||
[node name="ImageViewportDisplay" type="Sprite2D" parent="."]
|
[node name="ImageViewportDisplay" type="Sprite2D" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
material = SubResource("ShaderMaterial_y2ea0")
|
||||||
texture = SubResource("ViewportTexture_lct1c")
|
texture = SubResource("ViewportTexture_lct1c")
|
||||||
script = ExtResource("3_n4itb")
|
script = ExtResource("3_n4itb")
|
||||||
|
|
||||||
|
|
|
@ -29,17 +29,21 @@ func fit_image():
|
||||||
zoom = Vector2(zoomf, zoomf)
|
zoom = Vector2(zoomf, zoomf)
|
||||||
global_position = Vector2(-((ui_container_size.x) / 2 / zoom.x), 0)
|
global_position = Vector2(-((ui_container_size.x) / 2 / zoom.x), 0)
|
||||||
|
|
||||||
|
func update_viewport_display():
|
||||||
|
image_viewport_display.update_zoom_texture_filter(zoom)
|
||||||
|
image_viewport_display.material.set_shader_parameter("zoom_level", zoom)
|
||||||
|
|
||||||
func zoom_in():
|
func zoom_in():
|
||||||
var old_mouse_pos = get_global_mouse_position()
|
var old_mouse_pos = get_global_mouse_position()
|
||||||
zoom *= 1.2
|
zoom *= 1.2
|
||||||
global_position += old_mouse_pos - get_global_mouse_position()
|
global_position += old_mouse_pos - get_global_mouse_position()
|
||||||
image_viewport_display.update_zoom_texture_filter(zoom)
|
update_viewport_display()
|
||||||
|
|
||||||
func zoom_out():
|
func zoom_out():
|
||||||
var old_mouse_pos = get_global_mouse_position()
|
var old_mouse_pos = get_global_mouse_position()
|
||||||
zoom *= 1/1.2
|
zoom *= 1/1.2
|
||||||
global_position += old_mouse_pos - get_global_mouse_position()
|
global_position += old_mouse_pos - get_global_mouse_position()
|
||||||
image_viewport_display.update_zoom_texture_filter(zoom)
|
update_viewport_display()
|
||||||
|
|
||||||
func _on_fit_image_button_pressed():
|
func _on_fit_image_button_pressed():
|
||||||
fit_image()
|
fit_image()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
var camera_freeze = false
|
var camera_freeze = false
|
||||||
@onready var shader: Shader = load("res://src/shaders/empty.gdshader")
|
@onready var shader: Shader = load("res://src/shader/template.gdshader")
|
||||||
var target_viewport: SubViewport
|
var target_viewport: SubViewport
|
||||||
var cwd = "."
|
var cwd = "."
|
||||||
var last_image_savepath = ""
|
var last_image_savepath = ""
|
||||||
|
|
|
@ -2,6 +2,7 @@ extends SubViewport
|
||||||
|
|
||||||
@onready var camera = %Camera
|
@onready var camera = %Camera
|
||||||
@onready var image_sprite = %ImageSprite
|
@onready var image_sprite = %ImageSprite
|
||||||
|
@onready var image_viewport_display = %ImageViewportDisplay
|
||||||
|
|
||||||
var image_original_tex: ImageTexture
|
var image_original_tex: ImageTexture
|
||||||
var image_result: Image
|
var image_result: Image
|
||||||
|
@ -36,7 +37,7 @@ func update():
|
||||||
# load images from //!load directive -> TEXTURE
|
# load images from //!load directive -> TEXTURE
|
||||||
var regex_match = load_regex.search(Globals.shader.code)
|
var regex_match = load_regex.search(Globals.shader.code)
|
||||||
if regex_match == null: # Error!
|
if regex_match == null: # Error!
|
||||||
print("Didn't find any load directives!")
|
printerr("Didn't find any load directives!")
|
||||||
return
|
return
|
||||||
var tex_path = get_absolute_path(regex_match.strings[1])
|
var tex_path = get_absolute_path(regex_match.strings[1])
|
||||||
load_texture(tex_path) # load every time
|
load_texture(tex_path) # load every time
|
||||||
|
@ -66,6 +67,7 @@ func update():
|
||||||
image_result = get_texture().get_image()
|
image_result = get_texture().get_image()
|
||||||
image_sprite.material = null
|
image_sprite.material = null
|
||||||
image_sprite.texture = ImageTexture.create_from_image(image_result)
|
image_sprite.texture = ImageTexture.create_from_image(image_result)
|
||||||
|
image_viewport_display.show()
|
||||||
|
|
||||||
func get_result():
|
func get_result():
|
||||||
return image_result
|
return image_result
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
extends Sprite2D
|
extends Sprite2D
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
hide()
|
||||||
|
|
||||||
func update_zoom_texture_filter(zoom: Vector2):
|
func update_zoom_texture_filter(zoom: Vector2):
|
||||||
if zoom.x >= 1.5:
|
if zoom.x >= 1.5:
|
||||||
texture_filter = TEXTURE_FILTER_NEAREST_WITH_MIPMAPS
|
texture_filter = TEXTURE_FILTER_NEAREST_WITH_MIPMAPS
|
||||||
|
|
16
src/shader/ivd_outline.gdshader
Normal file
16
src/shader/ivd_outline.gdshader
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
shader_type canvas_item;
|
||||||
|
|
||||||
|
uniform vec2 zoom_level = vec2(1.0);
|
||||||
|
const float thickness = 3.0;
|
||||||
|
|
||||||
|
void fragment() {
|
||||||
|
vec2 t = thickness * TEXTURE_PIXEL_SIZE / zoom_level;
|
||||||
|
if (
|
||||||
|
UV.x < t.x ||
|
||||||
|
UV.y < t.y ||
|
||||||
|
UV.x > 1.0-t.x ||
|
||||||
|
UV.y > 1.0-t.y
|
||||||
|
) {
|
||||||
|
COLOR = mix(COLOR, vec4(1.0), 0.5);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue