[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
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 ----
var _pos = inputs[index].getValue(,,, true);
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_original = new __vec3(_pos);
} #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 ----
var _rot = inputs[index].getValue();
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;
} #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;
#region ---- main ----
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_original = new __vec3(_sca);
} #endregion
} #endregion
}
static drawOverlay3D = function(active, params, _mx, _my, _snx, _sny, _panel) {
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 setTransform = function(object, _data) { #region
static setTransform = function(object, _data) {
if(object == noone) return;
var _pos = _data[0];
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]);
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);
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;
return _obj;
} #endregion
}
static getPreviewObjects = function() { return [ getPreviewObject(), gizmo ]; }
static getPreviewObjectOutline = function() { return [ getPreviewObject(), gizmo ]; }

View file

@ -39,7 +39,7 @@
LATEST_VERSION = 1_16_00;
VERSION = 1_17_11_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;
HOTKEYS = ds_map_create();

View file

@ -108,11 +108,12 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
outputs[0] = nodeValue_Output("Preview", self, VALUE_TYPE.surface, noone);
template_guide = [
["%d", "Directory"],
["%1d", "Goes up 1 level"],
["%n", "File name"],
["%f", "Frame"],
["%i", "Array index"],
["%d", "Directory"],
["%1d", "Goes up 1 level"],
["%n", "File name"],
["%f", "Frame"],
["%i", "Array index"],
["%{i+1}", "Array index + 1"],
];
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 {
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(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))
.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);
input_display_list = [ 1,
["Surfaces", false], 0,
["SDF", false], 2, 3,
["Render", false], 4, 5,
]
attribute_surface_depth();
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 _side = _data[2];
var _dist = _data[3];
var _alph = _data[4];
var _invt = _data[5];
var sw = surface_get_width_safe(inSurf);
var sh = surface_get_height_safe(inSurf);
var _n = max(sw, sh);
@ -55,19 +56,24 @@ function Node_SDF(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) const
bg = !bg;
surface_set_shader(temp_surface[bg], sh_sdf);
shader_set_uniform_f(uniform_sdf_dim, _n, _n );
shader_set_uniform_f(uniform_sdf_stp, stepSize);
shader_set_uniform_i(uniform_sdf_sid, _side);
shader_set_f("dimension", _n, _n);
shader_set_f("stepSize", stepSize);
shader_set_i("side", _side);
draw_surface_safe(temp_surface[!bg]);
surface_reset_shader();
}
surface_set_shader(_outSurf, sh_sdf_dist);
shader_set_uniform_i(uniform_dst_sid, _side);
shader_set_uniform_f(uniform_dst_dst, _dist);
shader_set_surface("original", inSurf);
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]);
surface_reset_shader();
return _outSurf;
} #endregion
}
}

View file

@ -1,10 +1,11 @@
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform sampler2D original;
uniform int side;
uniform int alpha;
uniform int invert;
uniform float max_distance;
void main() {
@ -21,5 +22,10 @@ void main() {
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);
}