Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nearest neighbor filtering and QoL keys #636

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addons/material_maker/engine/gen_material.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const TEXTURE_SIZE_MAX : int = 13 # 8192x8192
const TEXTURE_SIZE_DEFAULT : int = 10 # 1024x1024

# The minimum allowed texture size as a power-of-two exponent
const TEXTURE_FILTERING_LIMIT : int = 256
#const TEXTURE_FILTERING_LIMIT : int = 8192

const EXPORT_OUTPUT_DEF_INDEX : int = 12345

Expand Down Expand Up @@ -148,7 +148,7 @@ func on_dep_update_buffer(buffer_name) -> bool:
renderer.copy_to_texture(preview_textures[texture_name].texture)
renderer.release(self)
mm_deps.dependency_update(preview_textures[texture_name].buffer, preview_textures[texture_name].texture, true)
if size <= TEXTURE_FILTERING_LIMIT:
if !mm_globals.get_config("ui_3d_preview_texture_filtering"):
preview_textures[texture_name].texture.flags &= ~Texture.FLAG_FILTER
else:
preview_textures[texture_name].texture.flags |= Texture.FLAG_FILTER
Expand Down
1 change: 1 addition & 0 deletions material_maker/globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const DEFAULT_CONFIG = {
ui_3d_preview_resolution = 2.0,
ui_3d_preview_tesselation_detail = 256,
ui_3d_preview_sun_shadow = false,
ui_3d_preview_texture_filtering = true,
ui_3d_preview_tonemap = 0,
bake_ray_count = 64,
bake_ao_ray_dist = 128.0,
Expand Down
1 change: 1 addition & 0 deletions material_maker/nodes/minimal.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class_name MMGraphNodeMinimal

var generator : MMGenBase = null setget set_generator
var disable_undoredo_for_offset : bool = false
var grab_offset : Vector2


func _ready() -> void:
Expand Down
19 changes: 18 additions & 1 deletion material_maker/panels/graph_edit/graph_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ signal graph_changed
signal view_updated
signal preview_changed

var grabbing = false

func _ready() -> void:
OS.low_processor_usage_mode = true
Expand Down Expand Up @@ -135,6 +136,8 @@ func _gui_input(event) -> void:
if selected_nodes.size() == 1 and selected_nodes[0].generator is MMGenGraph:
update_view(selected_nodes[0].generator)
elif event is InputEventMouseButton:
if event.is_pressed():
grabbing = false
# reverted to default GraphEdit behavior
if false and event.button_index == BUTTON_WHEEL_UP and event.is_pressed():
if event.control:
Expand Down Expand Up @@ -180,12 +183,14 @@ func _gui_input(event) -> void:
on_ButtonUp_pressed()
else:
process_port_click(event.is_pressed())
grabbing = false
call_deferred("check_previews")
elif event is InputEventKey:
if event.pressed:
grabbing = false
var scancode_with_modifiers = event.get_scancode_with_modifiers()
match scancode_with_modifiers:
KEY_DELETE,KEY_BACKSPACE:
KEY_DELETE,KEY_BACKSPACE,KEY_X:
remove_selection()
KEY_LEFT:
scroll_offset.x -= 0.5*rect_size.x
Expand All @@ -199,6 +204,13 @@ func _gui_input(event) -> void:
KEY_DOWN:
scroll_offset.y += 0.5*rect_size.y
accept_event()
KEY_G:
if !grabbing:
grabbing = true
for node in get_selected_nodes():
var mousepos = offset_from_global_position(get_global_mouse_position())
# note: get_offset() becomes get_offset_position() in Godot 4:
node.grab_offset = mousepos - node.get_offset()
match event.get_scancode():
KEY_SHIFT, KEY_CONTROL, KEY_ALT:
var found_tip : bool = false
Expand All @@ -209,6 +221,11 @@ func _gui_input(event) -> void:
if rect.has_point(get_global_mouse_position()):
found_tip = found_tip or c.set_slot_tip_text(get_global_mouse_position()-c.rect_global_position)
elif event is InputEventMouseMotion:
if grabbing:
for node in get_selected_nodes():
var mousepos = offset_from_global_position(get_global_mouse_position())
node.do_set_position(mousepos - node.grab_offset)

var found_tip : bool = false
for c in get_children():
if c.has_method("get_slot_tooltip"):
Expand Down
9 changes: 9 additions & 0 deletions material_maker/windows/preferences/preferences.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ Changes to this setting are only applied on application restart."
text = "3D preview sun shadow (requires restart)"
config_variable = "ui_3d_preview_sun_shadow"

[node name="Gui3DPreviewFiltering" parent="VBoxContainer/TabContainer/General" instance=ExtResource( 1 )]
margin_top = 192.0
margin_right = 296.0
margin_bottom = 216.0
hint_tooltip = "If disabled, the preview will be shown with nearest neighbor (point) filtering. Useful to disable when working on pixel art."
pressed = true
text = "3D preview use texture filtering (requires restart)"
config_variable = "ui_3d_preview_texture_filtering"

[node name="Space2" type="Control" parent="VBoxContainer/TabContainer/General"]
margin_top = 220.0
margin_right = 296.0
Expand Down