[SDF] Add keep alpha and invert properties.

This commit is contained in:
Tanasart 2024-08-30 08:59:20 +07:00
parent 3e06547c1e
commit 0f57d13ca0
5 changed files with 47 additions and 34 deletions

View file

@ -68,7 +68,7 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
} }
#endregion #endregion
static drawGizmoPosition = function(index, object, _vpos, active, params, _mx, _my, _snx, _sny, _panel) { #region static drawGizmoPosition = function(index, object, _vpos, active, params, _mx, _my, _snx, _sny, _panel) {
#region ---- main ---- #region ---- main ----
var _pos = inputs[index].getValue(,,, true); var _pos = inputs[index].getValue(,,, true);
var _qrot = object == noone? new BBMOD_Quaternion() : object.transform.rotation; var _qrot = object == noone? new BBMOD_Quaternion() : object.transform.rotation;
@ -278,9 +278,9 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
drag_val = _pos; drag_val = _pos;
drag_original = new __vec3(_pos); drag_original = new __vec3(_pos);
} #endregion } #endregion
} #endregion }
static drawGizmoRotation = function(index, object, _vpos, active, params, _mx, _my, _snx, _sny, _panel) { #region static drawGizmoRotation = function(index, object, _vpos, active, params, _mx, _my, _snx, _sny, _panel) {
#region ---- main ---- #region ---- main ----
var _rot = inputs[index].getValue(); var _rot = inputs[index].getValue();
var _qrot = object == noone? new BBMOD_Quaternion() : object.transform.rotation; var _qrot = object == noone? new BBMOD_Quaternion() : object.transform.rotation;
@ -389,9 +389,9 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
drag_rot_axis = undefined; drag_rot_axis = undefined;
} #endregion } #endregion
} #endregion }
static drawGizmoScale = function(index, object, _vpos, active, params, _mx, _my, _snx, _sny, _panel) { #region static drawGizmoScale = function(index, object, _vpos, active, params, _mx, _my, _snx, _sny, _panel) {
tool_attribute.context = 0; tool_attribute.context = 0;
#region ---- main ---- #region ---- main ----
var _sca = inputs[index].getValue(,,, true); var _sca = inputs[index].getValue(,,, true);
@ -581,7 +581,7 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
drag_val = [ _sca[0], _sca[1], _sca[2] ]; drag_val = [ _sca[0], _sca[1], _sca[2] ];
drag_original = new __vec3(_sca); drag_original = new __vec3(_sca);
} #endregion } #endregion
} #endregion }
static drawOverlay3D = function(active, params, _mx, _my, _snx, _sny, _panel) { static drawOverlay3D = function(active, params, _mx, _my, _snx, _sny, _panel) {
var _rot = inputs[1].display_data.angle_display; var _rot = inputs[1].display_data.angle_display;
@ -610,7 +610,7 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
static onDrawOverlay3D = function(active, params, _mx, _my, _snx, _sny, _panel) {} static onDrawOverlay3D = function(active, params, _mx, _my, _snx, _sny, _panel) {}
static setTransform = function(object, _data) { #region static setTransform = function(object, _data) {
if(object == noone) return; if(object == noone) return;
var _pos = _data[0]; var _pos = _data[0];
var _rot = _data[1]; var _rot = _data[1];
@ -632,9 +632,9 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
object.transform.scale.set( _sca[0], _sca[1], _sca[2]); object.transform.scale.set( _sca[0], _sca[1], _sca[2]);
return object; return object;
} #endregion }
static getObject = function(index, class = object_class) { #region static getObject = function(index, class = object_class) {
var _obj = array_safe_get_fast(cached_object, index, noone); var _obj = array_safe_get_fast(cached_object, index, noone);
if(_obj == noone) { if(_obj == noone) {
@ -646,7 +646,7 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
cached_object[index] = _obj; cached_object[index] = _obj;
return _obj; return _obj;
} #endregion }
static getPreviewObjects = function() { return [ getPreviewObject(), gizmo ]; } static getPreviewObjects = function() { return [ getPreviewObject(), gizmo ]; }
static getPreviewObjectOutline = function() { return [ getPreviewObject(), gizmo ]; } static getPreviewObjectOutline = function() { return [ getPreviewObject(), gizmo ]; }

View file

@ -39,7 +39,7 @@
LATEST_VERSION = 1_16_00; LATEST_VERSION = 1_16_00;
VERSION = 1_17_11_0; VERSION = 1_17_11_0;
SAVE_VERSION = 1_17_10_0; SAVE_VERSION = 1_17_10_0;
VERSION_STRING = "1.17.11.006"; VERSION_STRING = "1.17.11.007";
BUILD_NUMBER = 1_17_11_0; BUILD_NUMBER = 1_17_11_0;
HOTKEYS = ds_map_create(); HOTKEYS = ds_map_create();

View file

@ -113,6 +113,7 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
["%n", "File name"], ["%n", "File name"],
["%f", "Frame"], ["%f", "Frame"],
["%i", "Array index"], ["%i", "Array index"],
["%{i+1}", "Array index + 1"],
]; ];
export_template = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { export_template = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {

View file

@ -1,13 +1,6 @@
function Node_SDF(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { function Node_SDF(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "SDF"; name = "SDF";
uniform_sdf_dim = shader_get_uniform(sh_sdf, "dimension");
uniform_sdf_stp = shader_get_uniform(sh_sdf, "stepSize");
uniform_sdf_sid = shader_get_uniform(sh_sdf, "side");
uniform_dst_sid = shader_get_uniform(sh_sdf_dist, "side");
uniform_dst_dst = shader_get_uniform(sh_sdf_dist, "max_distance");
newInput(0, nodeValue_Surface("Surface in", self)); newInput(0, nodeValue_Surface("Surface in", self));
newInput(1, nodeValue_Bool("Active", self, true)); newInput(1, nodeValue_Bool("Active", self, true));
@ -18,21 +11,29 @@ function Node_SDF(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) const
newInput(3, nodeValue_Float("Max distance", self, 1)) newInput(3, nodeValue_Float("Max distance", self, 1))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 2, 0.01 ] }); .setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 2, 0.01 ] });
newInput(4, nodeValue_Bool("Keep Alpha", self, false));
newInput(5, nodeValue_Bool("Invert", self, false));
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone); outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
input_display_list = [ 1, input_display_list = [ 1,
["Surfaces", false], 0, ["Surfaces", false], 0,
["SDF", false], 2, 3, ["SDF", false], 2, 3,
["Render", false], 4, 5,
] ]
attribute_surface_depth(); attribute_surface_depth();
temp_surface = [ surface_create(1, 1), surface_create(1, 1) ]; temp_surface = [ surface_create(1, 1), surface_create(1, 1) ];
static processData = function(_outSurf, _data, _output_index, _array_index) { #region static processData = function(_outSurf, _data, _output_index, _array_index) {
var inSurf = _data[0]; var inSurf = _data[0];
var _side = _data[2]; var _side = _data[2];
var _dist = _data[3]; var _dist = _data[3];
var _alph = _data[4];
var _invt = _data[5];
var sw = surface_get_width_safe(inSurf); var sw = surface_get_width_safe(inSurf);
var sh = surface_get_height_safe(inSurf); var sh = surface_get_height_safe(inSurf);
var _n = max(sw, sh); var _n = max(sw, sh);
@ -55,19 +56,24 @@ function Node_SDF(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) const
bg = !bg; bg = !bg;
surface_set_shader(temp_surface[bg], sh_sdf); surface_set_shader(temp_surface[bg], sh_sdf);
shader_set_uniform_f(uniform_sdf_dim, _n, _n ); shader_set_f("dimension", _n, _n);
shader_set_uniform_f(uniform_sdf_stp, stepSize); shader_set_f("stepSize", stepSize);
shader_set_uniform_i(uniform_sdf_sid, _side); shader_set_i("side", _side);
draw_surface_safe(temp_surface[!bg]); draw_surface_safe(temp_surface[!bg]);
surface_reset_shader(); surface_reset_shader();
} }
surface_set_shader(_outSurf, sh_sdf_dist); surface_set_shader(_outSurf, sh_sdf_dist);
shader_set_uniform_i(uniform_dst_sid, _side); shader_set_surface("original", inSurf);
shader_set_uniform_f(uniform_dst_dst, _dist); shader_set_i("side", _side);
shader_set_f("max_distance", _dist);
shader_set_i("alpha", _alph);
shader_set_i("invert", _invt);
draw_surface_safe(temp_surface[bg]); draw_surface_safe(temp_surface[bg]);
surface_reset_shader(); surface_reset_shader();
return _outSurf; return _outSurf;
} #endregion }
} }

View file

@ -1,10 +1,11 @@
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord; varying vec2 v_vTexcoord;
varying vec4 v_vColour; varying vec4 v_vColour;
uniform sampler2D original;
uniform int side; uniform int side;
uniform int alpha;
uniform int invert;
uniform float max_distance; uniform float max_distance;
void main() { void main() {
@ -21,5 +22,10 @@ void main() {
return; return;
} }
gl_FragColor = vec4(vec3(dist), 1.); float aa = 1.;
if(alpha == 1) aa = texture2D( original, v_vTexcoord ).a;
if(invert == 1) dist = 1. - dist;
gl_FragColor = vec4(vec3(dist), aa);
} }