From 9c94901006858c436bc0b20b468b5cc2c86c0506 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Sat, 20 Jul 2024 15:55:02 +0700 Subject: [PATCH] - [Preview Panel] SDF raymarcher now comes with it's own 3d settings with only related options. --- PixelComposer.resource_order | 1 + PixelComposer.yyp | 1 + scripts/__raymarching/__raymarching.gml | 5 +- .../node_rm_primitive/node_rm_primitive.gml | 6 +- scripts/panel_preview/panel_preview.gml | 54 ++++--- .../panel_console.gml | 73 ++++++++++ .../panel_preview_3d_sdf_setting.gml | 29 ++++ .../panel_preview_3d_sdf_setting.yy | 13 ++ .../panel_preview_3d_setting.gml | 136 +++++++++--------- 9 files changed, 227 insertions(+), 91 deletions(-) create mode 100644 scripts/panel_preview_3d_sdf_setting/panel_console.gml create mode 100644 scripts/panel_preview_3d_sdf_setting/panel_preview_3d_sdf_setting.gml create mode 100644 scripts/panel_preview_3d_sdf_setting/panel_preview_3d_sdf_setting.yy diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index 1f10cc778..d0ea3e659 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -1218,6 +1218,7 @@ {"name":"panel_notification","order":2,"path":"scripts/panel_notification/panel_notification.yy",}, {"name":"panel_palette_mixer","order":3,"path":"scripts/panel_palette_mixer/panel_palette_mixer.yy",}, {"name":"panel_patreon","order":2,"path":"scripts/panel_patreon/panel_patreon.yy",}, + {"name":"panel_preview_3d_sdf_setting","order":10,"path":"scripts/panel_preview_3d_sdf_setting/panel_preview_3d_sdf_setting.yy",}, {"name":"panel_preview_3d_setting","order":2,"path":"scripts/panel_preview_3d_setting/panel_preview_3d_setting.yy",}, {"name":"panel_preview_grid_setting","order":4,"path":"scripts/panel_preview_grid_setting/panel_preview_grid_setting.yy",}, {"name":"panel_preview_histogram","order":8,"path":"scripts/panel_preview_histogram/panel_preview_histogram.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index 7fea2725f..3fd38ef2c 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -1653,6 +1653,7 @@ {"id":{"name":"panel_palette_mixer","path":"scripts/panel_palette_mixer/panel_palette_mixer.yy",},}, {"id":{"name":"panel_palette","path":"scripts/panel_palette/panel_palette.yy",},}, {"id":{"name":"panel_patreon","path":"scripts/panel_patreon/panel_patreon.yy",},}, + {"id":{"name":"panel_preview_3d_sdf_setting","path":"scripts/panel_preview_3d_sdf_setting/panel_preview_3d_sdf_setting.yy",},}, {"id":{"name":"panel_preview_3d_setting","path":"scripts/panel_preview_3d_setting/panel_preview_3d_setting.yy",},}, {"id":{"name":"panel_preview_grid_setting","path":"scripts/panel_preview_grid_setting/panel_preview_grid_setting.yy",},}, {"id":{"name":"panel_preview_histogram","path":"scripts/panel_preview_histogram/panel_preview_histogram.yy",},}, diff --git a/scripts/__raymarching/__raymarching.gml b/scripts/__raymarching/__raymarching.gml index d36fe4c79..26aea20d6 100644 --- a/scripts/__raymarching/__raymarching.gml +++ b/scripts/__raymarching/__raymarching.gml @@ -43,6 +43,7 @@ function RM_Object() constructor { texture = []; useTexture = []; + textureFilter = []; textureScale = []; triplanar = []; @@ -56,7 +57,7 @@ function RM_Object() constructor { "tileActive", "tileAmount", "tileSpace", "tilePos", "tileRot", "tileSca", "diffuseColor", "reflective", "volumetric", "volumeDensity", - "texture", "useTexture", "textureScale", "triplanar" + "texture", "textureFilter", "useTexture", "textureScale", "triplanar" ]; textureAtl = noone; @@ -67,7 +68,9 @@ function RM_Object() constructor { surface_set_shader(textureAtlas); for (var i = 0; i < shapeAmount; i++) { + gpu_set_tex_filter(textureFilter[i]); draw_surface_stretched_safe(texture[i], tx * (i % 8), tx * floor(i / 8), tx, tx); + gpu_set_tex_filter(false); } surface_reset_shader(); diff --git a/scripts/node_rm_primitive/node_rm_primitive.gml b/scripts/node_rm_primitive/node_rm_primitive.gml index 96eddb914..cf32611f5 100644 --- a/scripts/node_rm_primitive/node_rm_primitive.gml +++ b/scripts/node_rm_primitive/node_rm_primitive.gml @@ -165,6 +165,8 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con inputs[| 49] = nodeValue("Env Interpolation", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false); + inputs[| 50] = nodeValue("Texture Interpolation", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false); + outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); outputs[| 1] = nodeValue("Shape Data", self, JUNCTION_CONNECT.output, VALUE_TYPE.sdf, noone); @@ -175,7 +177,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con ["Deform", true], 15, 16, 17, 18, 19, ["Transform", false], 2, 3, 4, ["Tile", false, 45], 20, 29, /*46, 47, 48,*/ - ["Material", false], 9, 36, 35, 37, 38, + ["Material", false], 9, 36, 50, 35, 37, 38, ["Camera", false], 42, 43, 13, 14, 5, 6, ["Render", false, 44], 31, 30, 34, 49, 10, 7, 8, @@ -588,6 +590,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con var _tileSca = _data[48]; var _eint = _data[49]; + var _textFilter = _data[50]; _outSurf = surface_verify(_outSurf, _dim[0], _dim[1]); @@ -673,6 +676,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con object.volumeDensity = _vden; object.texture = [ _text ]; + object.textureFilter = [ _textFilter ]; object.useTexture = is_surface(_text); object.textureScale = _texs; object.triplanar = _triS; diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index 2e1fd0a5a..2ab65e948 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -166,6 +166,7 @@ function Panel_Preview() : PanelContent() constructor { d3_preview_channel = 0; d3_deferData = noone; + d3_drawBG = false; global.SKY_SPHERE = new __3dUVSphere(0.5, 16, 8, true); @@ -308,19 +309,30 @@ function Panel_Preview() : PanelContent() constructor { toolbars_3d = [ [ THEME.d3d_preview_settings, - function() { return 0; }, - function() { return __txt("3D Preview Settings") }, - function(param) { - var dia = dialogPanelCall(new Panel_Preview_3D_Setting(self), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left }); - } + function() /*=>*/ {return 0}, + function() /*=>*/ {return __txt("3D Preview Settings")}, + function(param) /*=>*/ { dialogPanelCall(new Panel_Preview_3D_Setting(self), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left }); } ], [ THEME.d3d_snap_settings, - function() { return 0; }, - function() { return __txt("3D Snap Settings") }, - function(param) { - var dia = dialogPanelCall(new Panel_Preview_Snap_Setting(self), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left }); - } + function() /*=>*/ {return 0}, + function() /*=>*/ {return __txt("3D Snap Settings")}, + function(param) /*=>*/ { dialogPanelCall(new Panel_Preview_Snap_Setting(self), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left }); } + ], + ]; + + toolbars_3d_sdf = [ + [ + THEME.d3d_preview_settings, + function() /*=>*/ {return 0}, + function() /*=>*/ {return __txt("3D SDF Preview Settings")}, + function(param) /*=>*/ { dialogPanelCall(new Panel_Preview_3D_SDF_Setting(self), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left }); } + ], + [ + THEME.d3d_snap_settings, + function() /*=>*/ {return 0}, + function() /*=>*/ {return __txt("3D Snap Settings")}, + function(param) /*=>*/ { dialogPanelCall(new Panel_Preview_Snap_Setting(self), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left }); } ], ]; @@ -1202,7 +1214,7 @@ function Panel_Preview() : PanelContent() constructor { _env.apply(); if(_obj) _obj.apply(); - shader_set_i("drawBg", 0); + shader_set_i("drawBg", d3_drawBG); shader_set_f("depthInt", 0); var _scale = zm / 2; @@ -1795,13 +1807,13 @@ function Panel_Preview() : PanelContent() constructor { } } #endregion - function drawToolBar(_tool) { #region + function drawToolBar(_tool, _node) { #region var ty = h - toolbar_height; var aa = d3_active? 0.8 : 1; draw_sprite_stretched_ext(THEME.toolbar, 1, 0, 0, w, topbar_height, c_white, aa); draw_sprite_stretched_ext(THEME.toolbar, 0, 0, ty, w, toolbar_height, c_white, aa); - if(_tool && tool_current != noone) { #region tool settings + if(_tool && tool_current != noone) { // tool settings var settings = array_merge(_tool.getToolSettings(), tool_current.settings); tool_x = lerp_float(tool_x, tool_x_to, 5); @@ -1873,8 +1885,8 @@ function Panel_Preview() : PanelContent() constructor { if(mouse_wheel_up()) tool_x_to = clamp(tool_x_to + ui(64) * SCROLL_SPEED, -tol_max_w, 0); if(mouse_wheel_down()) tool_x_to = clamp(tool_x_to - ui(64) * SCROLL_SPEED, -tol_max_w, 0); } - #endregion - } else { #region color sampler + + } else { // color sampler var cx = ui(8); var cy = ui(8); var cw = ui(32); @@ -1899,13 +1911,19 @@ function Panel_Preview() : PanelContent() constructor { draw_set_color(COLORS._main_text_sub); draw_text(tx, cy + ch / 2, $"({color_get_alpha(sample_color)})"); } - #endregion } var tbx = toolbar_height / 2; var tby = ty + toolbar_height / 2; - var _toolbars = d3_active? toolbars_3d : toolbars; + var _toolbars = toolbars; + + if(_node) + switch(_node.is_3D) { + case NODE_3D.none : _toolbars = toolbars; break; + case NODE_3D.polygon : _toolbars = toolbars_3d; break; + case NODE_3D.sdf : _toolbars = toolbars_3d_sdf; break; + } for( var i = 0, n = array_length(_toolbars); i < n; i++ ) { var tb = _toolbars[i]; @@ -2056,7 +2074,7 @@ function Panel_Preview() : PanelContent() constructor { if(!d3_active) drawSplitView(); - drawToolBar(tool); + drawToolBar(tool, _prev_node); if(mouse_on_preview && mouse_press(mb_right, pFOCUS) && !key_mod_press(SHIFT)) { menuCall("preview_context_menu",,, [ diff --git a/scripts/panel_preview_3d_sdf_setting/panel_console.gml b/scripts/panel_preview_3d_sdf_setting/panel_console.gml new file mode 100644 index 000000000..5dff86a32 --- /dev/null +++ b/scripts/panel_preview_3d_sdf_setting/panel_console.gml @@ -0,0 +1,73 @@ +function Panel_Console() : PanelContent() constructor { + title = "Console"; + w = ui(640); + h = ui(320); + + command = ""; + history = []; + cmd_history = []; + + cmd_index = 0; + + keyboard_string = ""; + + static submit_command = function() { + if(command == "") return; + array_push(history, { txt: command, color: COLORS._main_text_sub }); + array_push(cmd_history, command); + + var cmd = string_splice(command, " "); + + switch(cmd[0]) { + case "flag": + if(array_length(cmd) < 2) break; + var flg = array_safe_get(cmd, 1, ""); + global.FLAG[$ flg] = !global.FLAG[$ flg]; + + array_push(history, { txt: $"Toggled debug flag: {flg} = {global.FLAG[$ flg]? "True" : "False"}", color: COLORS._main_value_positive }); + break; + } + + keyboard_string = ""; + command = ""; + } + + function drawContent(panel) { + HOTKEY_BLOCK = true; + command = keyboard_string; + + draw_clear_alpha(CDEF.main_dkblack, 1); + + draw_set_color(c_black); + draw_set_alpha(0.75); + draw_rectangle(0, h - ui(28), w, h, false); + draw_set_alpha(1); + + draw_set_text(f_code, fa_left, fa_bottom, COLORS._main_text); + draw_text(ui(8), h - ui(4), command); + draw_set_color(COLORS._main_text_sub); + draw_text(ui(8) + string_width(command), h - ui(4), "_"); + + var hy = h - ui(32); + for( var i = 0; i < array_length(history); i++ ) { + var his = history[array_length(history) - i - 1]; + var txt = his.txt; + + draw_set_color(his.color); + draw_text_ext(ui(8), hy, txt, -1, w - ui(16)); + hy -= string_height_ext(txt, -1, w - ui(16)); + + if(hy <= 0) break; + } + + if(keyboard_check_pressed(vk_enter)) + submit_command(); + + if(keyboard_check_pressed(vk_up)) { + cmd_index = max(0, cmd_index - 1); + keyboard_string = array_safe_get(cmd_history, cmd_index, ""); + command = keyboard_string; + } else if(keyboard_check_pressed(vk_anykey)) + cmd_index = array_length(cmd_history); + } +} \ No newline at end of file diff --git a/scripts/panel_preview_3d_sdf_setting/panel_preview_3d_sdf_setting.gml b/scripts/panel_preview_3d_sdf_setting/panel_preview_3d_sdf_setting.gml new file mode 100644 index 000000000..15bc663f5 --- /dev/null +++ b/scripts/panel_preview_3d_sdf_setting/panel_preview_3d_sdf_setting.gml @@ -0,0 +1,29 @@ +function Panel_Preview_3D_SDF_Setting(panel) : Panel_Linear_Setting() constructor { + title = __txtx("preview_3d_settings", "3D SDF Preview Settings"); + + w = ui(380); + preview_panel = panel; + + properties_default = [ + new __Panel_Linear_Setting_Item( + __txt("View Plane"), + new vectorBox(2, function(value, index) /*=>*/ { + if(index == 0) preview_panel.d3_view_camera.view_near = value; + else if(index == 1) preview_panel.d3_view_camera.view_far = value; + }), + function( ) /*=>*/ {return [ preview_panel.d3_view_camera.view_near, preview_panel.d3_view_camera.view_far ]}, + function(val) /*=>*/ { preview_panel.d3_view_camera.view_near = val[0]; preview_panel.d3_view_camera.view_far = val[1] }, + [ 0.01, 50 ], + ), + new __Panel_Linear_Setting_Item( + __txt("Draw BG"), + new checkBox(function() /*=>*/ { preview_panel.d3_drawBG = !preview_panel.d3_drawBG; }), + function( ) /*=>*/ {return preview_panel.d3_drawBG}, + function(val) /*=>*/ { preview_panel.d3_drawBG = val; }, + false, + ), + ] + + properties = properties_default; + setHeight(); +} \ No newline at end of file diff --git a/scripts/panel_preview_3d_sdf_setting/panel_preview_3d_sdf_setting.yy b/scripts/panel_preview_3d_sdf_setting/panel_preview_3d_sdf_setting.yy new file mode 100644 index 000000000..f17e2aa08 --- /dev/null +++ b/scripts/panel_preview_3d_sdf_setting/panel_preview_3d_sdf_setting.yy @@ -0,0 +1,13 @@ +{ + "$GMScript":"", + "%Name":"panel_preview_3d_sdf_setting", + "isCompatibility":false, + "isDnD":false, + "name":"panel_preview_3d_sdf_setting", + "parent":{ + "name":"preview", + "path":"folders/panels/preview.yy", + }, + "resourceType":"GMScript", + "resourceVersion":"2.0", +} \ No newline at end of file diff --git a/scripts/panel_preview_3d_setting/panel_preview_3d_setting.gml b/scripts/panel_preview_3d_setting/panel_preview_3d_setting.gml index 1df530026..9b119f1ac 100644 --- a/scripts/panel_preview_3d_setting/panel_preview_3d_setting.gml +++ b/scripts/panel_preview_3d_setting/panel_preview_3d_setting.gml @@ -4,76 +4,70 @@ function Panel_Preview_3D_Setting(panel) : Panel_Linear_Setting() constructor { w = ui(380); preview_panel = panel; - #region data - properties_default = [ - new __Panel_Linear_Setting_Item( - __txt("Preview Light"), - new checkBox(function() { preview_panel.d3_scene_light_enabled = !preview_panel.d3_scene_light_enabled; }), - function() { return preview_panel.d3_scene_light_enabled }, - function(val) { preview_panel.d3_scene_light_enabled = val; }, - true, - ), - new __Panel_Linear_Setting_Item( - __txt("Ambient Color"), - new buttonColor(function(col) { preview_panel.d3_scene.lightAmbient = col; }), - function() { return preview_panel.d3_scene.lightAmbient }, - function(val) { preview_panel.d3_scene.lightAmbient = val; }, - $404040, - ), - new __Panel_Linear_Setting_Item( - __txt("Light Intensity"), - slider(0, 1, 0.01, function(val) { - preview_panel.d3_scene_light0.intensity = val; - preview_panel.d3_scene_light1.intensity = val; - }), - function() { return preview_panel.d3_scene_light0.intensity }, - function(val) { preview_panel.d3_scene_light0.intensity = val; }, - 1, - ), - new __Panel_Linear_Setting_Item( - __txt("Shadow"), - new checkBox(function() { preview_panel.d3_scene_light0.shadow_active = !preview_panel.d3_scene_light0.shadow_active; }), - function() { return preview_panel.d3_scene_light0.shadow_active }, - function(val) { preview_panel.d3_scene_light0.shadow_active = val; }, - false, - ), - new __Panel_Linear_Setting_Item( - __txt("View Plane"), - new vectorBox(2, function(value, index) { - if(index == 0) preview_panel.d3_view_camera.view_near = value; - else if(index == 1) preview_panel.d3_view_camera.view_far = value; - }), - function() { return [ preview_panel.d3_view_camera.view_near, preview_panel.d3_view_camera.view_far ] }, - function(val) { preview_panel.d3_view_camera.view_near = val[0]; preview_panel.d3_view_camera.view_far = val[1] }, - [ 0.01, 50 ], - ), - new __Panel_Linear_Setting_Item( - __txt("Gamma Correct"), - new checkBox(function() { preview_panel.d3_scene.gammaCorrection = !preview_panel.d3_scene.gammaCorrection; }), - function() { return preview_panel.d3_scene.gammaCorrection }, - function(val) { preview_panel.d3_scene.gammaCorrection = val; }, - true, - ), - new __Panel_Linear_Setting_Item( - __txt("Normal"), - new checkBox(function() { preview_panel.d3_scene.show_normal = !preview_panel.d3_scene.show_normal; }), - function() { return preview_panel.d3_scene.show_normal }, - function(val) { preview_panel.d3_scene.show_normal = val; }, - false, - ), - ] - - var scene_camera = [ - new __Panel_Linear_Setting_Label( "Currently using camera node settings", THEME.noti_icon_warning, 1, COLORS._main_accent ), - ]; - - properties_camera = array_append(scene_camera, properties_default); - properties = preview_panel.d3_scene_preview == preview_panel.d3_scene? properties_default : properties_camera; - - setHeight(); - #endregion + properties_default = [ + new __Panel_Linear_Setting_Item( + __txt("Preview Light"), + new checkBox(function() { preview_panel.d3_scene_light_enabled = !preview_panel.d3_scene_light_enabled; }), + function() { return preview_panel.d3_scene_light_enabled }, + function(val) { preview_panel.d3_scene_light_enabled = val; }, + true, + ), + new __Panel_Linear_Setting_Item( + __txt("Ambient Color"), + new buttonColor(function(col) { preview_panel.d3_scene.lightAmbient = col; }), + function() { return preview_panel.d3_scene.lightAmbient }, + function(val) { preview_panel.d3_scene.lightAmbient = val; }, + $404040, + ), + new __Panel_Linear_Setting_Item( + __txt("Light Intensity"), + slider(0, 1, 0.01, function(val) { + preview_panel.d3_scene_light0.intensity = val; + preview_panel.d3_scene_light1.intensity = val; + }), + function() { return preview_panel.d3_scene_light0.intensity }, + function(val) { preview_panel.d3_scene_light0.intensity = val; }, + 1, + ), + new __Panel_Linear_Setting_Item( + __txt("Shadow"), + new checkBox(function() { preview_panel.d3_scene_light0.shadow_active = !preview_panel.d3_scene_light0.shadow_active; }), + function() { return preview_panel.d3_scene_light0.shadow_active }, + function(val) { preview_panel.d3_scene_light0.shadow_active = val; }, + false, + ), + new __Panel_Linear_Setting_Item( + __txt("View Plane"), + new vectorBox(2, function(value, index) { + if(index == 0) preview_panel.d3_view_camera.view_near = value; + else if(index == 1) preview_panel.d3_view_camera.view_far = value; + }), + function() { return [ preview_panel.d3_view_camera.view_near, preview_panel.d3_view_camera.view_far ] }, + function(val) { preview_panel.d3_view_camera.view_near = val[0]; preview_panel.d3_view_camera.view_far = val[1] }, + [ 0.01, 50 ], + ), + new __Panel_Linear_Setting_Item( + __txt("Gamma Correct"), + new checkBox(function() { preview_panel.d3_scene.gammaCorrection = !preview_panel.d3_scene.gammaCorrection; }), + function() { return preview_panel.d3_scene.gammaCorrection }, + function(val) { preview_panel.d3_scene.gammaCorrection = val; }, + true, + ), + new __Panel_Linear_Setting_Item( + __txt("Normal"), + new checkBox(function() { preview_panel.d3_scene.show_normal = !preview_panel.d3_scene.show_normal; }), + function() { return preview_panel.d3_scene.show_normal }, + function(val) { preview_panel.d3_scene.show_normal = val; }, + false, + ), + ] - function drawContent(panel) { - drawSettings(panel); - } + var scene_camera = [ + new __Panel_Linear_Setting_Label( "Currently using camera node settings", THEME.noti_icon_warning, 1, COLORS._main_accent ), + ]; + + properties_camera = array_append(scene_camera, properties_default); + properties = preview_panel.d3_scene_preview == preview_panel.d3_scene? properties_default : properties_camera; + + setHeight(); } \ No newline at end of file