From bdda79179564a1b7ca29231790f8d051e12e0b6e Mon Sep 17 00:00:00 2001 From: LMW Date: Wed, 13 May 2026 23:57:29 +0800 Subject: [PATCH] Updated directional blur to not output black when sigma is zero --- .../nodes/directional_blur2.mmg | 285 ++++++++++++++++++ material_maker/library/base.json | 6 +- 2 files changed, 288 insertions(+), 3 deletions(-) create mode 100644 addons/material_maker/nodes/directional_blur2.mmg diff --git a/addons/material_maker/nodes/directional_blur2.mmg b/addons/material_maker/nodes/directional_blur2.mmg new file mode 100644 index 000000000..82282a9c1 --- /dev/null +++ b/addons/material_maker/nodes/directional_blur2.mmg @@ -0,0 +1,285 @@ +{ + "connections": [ + { + "from": "gen_inputs", + "from_port": 0, + "to": "buffer", + "to_port": 0 + }, + { + "from": "buffer", + "from_port": 0, + "to": "edge_detect_3_3_2", + "to_port": 0 + }, + { + "from": "edge_detect_3_3_2", + "from_port": 0, + "to": "gen_outputs", + "to_port": 0 + }, + { + "from": "gen_inputs", + "from_port": 1, + "to": "edge_detect_3_3_2", + "to_port": 1 + } + ], + "label": "Directional Blur", + "longdesc": "Applies a directional gaussian blur to its input", + "name": "directional_blur", + "node_position": { + "x": 0, + "y": 0 + }, + "nodes": [ + { + "name": "buffer", + "node_position": { + "x": -364.25, + "y": -255.75 + }, + "parameters": { + "lod": 0, + "size": 9 + }, + "seed": 20527, + "type": "buffer" + }, + { + "name": "gen_parameters", + "node_position": { + "x": -456.666626, + "y": -433.666656 + }, + "parameters": { + "param0": 9, + "param1": 50, + "param2": 45, + "param3": 0 + }, + "seed": 343, + "type": "remote", + "widgets": [ + { + "label": "Grid size", + "linked_widgets": [ + { + "node": "buffer", + "widget": "size" + }, + { + "node": "edge_detect_3_3_2", + "widget": "size" + } + ], + "longdesc": "The resolution of the input", + "name": "param0", + "shortdesc": "Size", + "type": "linked_control" + }, + { + "label": "Mode", + "linked_widgets": [ + { + "node": "edge_detect_3_3_2", + "widget": "mode" + } + ], + "longdesc": "Controls whether the blur moves in both directions or only in one.", + "name": "param3", + "shortdesc": "Mode", + "type": "linked_control" + }, + { + "label": "Sigma", + "linked_widgets": [ + { + "node": "edge_detect_3_3_2", + "widget": "sigma" + } + ], + "longdesc": "The strength of the blur filter", + "name": "param1", + "shortdesc": "Sigma", + "type": "linked_control" + }, + { + "label": "Angle", + "linked_widgets": [ + { + "node": "edge_detect_3_3_2", + "widget": "angle" + } + ], + "longdesc": "The angle of the directional blur effect", + "name": "param2", + "shortdesc": "Angle", + "type": "linked_control" + } + ] + }, + { + "name": "gen_inputs", + "node_position": { + "x": -779.666626, + "y": -247.392853 + }, + "parameters": { + + }, + "ports": [ + { + "group_size": 0, + "longdesc": "The input image", + "name": "in", + "shortdesc": "Input", + "type": "rgba" + }, + { + "group_size": 0, + "longdesc": "A map that controls the strength of the blur filter", + "name": "amount", + "shortdesc": "Strength map", + "type": "f" + } + ], + "seed": 91624, + "seed_locked": true, + "type": "ios" + }, + { + "name": "gen_outputs", + "node_position": { + "x": -45.452393, + "y": -195.392853 + }, + "parameters": { + + }, + "ports": [ + { + "group_size": 0, + "longdesc": "Shows the generated blurred image", + "name": "port0", + "shortdesc": "Output", + "type": "rgba" + } + ], + "seed": 30896, + "type": "ios" + }, + { + "name": "edge_detect_3_3_2", + "node_position": { + "x": -357.725464, + "y": -153.178955 + }, + "parameters": { + "angle": 45, + "mode": 0, + "sigma": 50, + "size": 9 + }, + "seed": -47470, + "seed_locked": true, + "shader_model": { + "code": "", + "global": "", + "inputs": [ + { + "default": "vec4(1.0)", + "function": true, + "label": "", + "name": "in", + "type": "rgba" + }, + { + "default": "1.0", + "function": true, + "label": "", + "name": "amount", + "type": "f" + } + ], + "instance": [ + "vec4 $(name)_fct(vec2 uv) {", + "\tvec2 e = vec2(cos($angle*0.01745329251), -sin($angle*0.01745329251))/$size;", + "\tvec4 rv = vec4(0.0);", + "\tfloat sum = 0.0;", + "\tfloat sigma = max($sigma*$amount(uv), 1e-5);", + "\tfor (float i = $mode; i <= 50.0; i += 1.0) {", + "\t\tfloat coef = exp(-0.5*(pow(i/sigma, 2.0)))/(6.28318530718*sigma*sigma);", + "\t\trv += $in(uv+i*e)*coef;", + "\t\tsum += coef;", + "\t}", + "\treturn rv/sum;", + "}" + ], + "name": "Directional Blur", + "outputs": [ + { + "rgba": "$(name)_fct($uv)", + "type": "rgba" + } + ], + "parameters": [ + { + "default": 9, + "first": 4, + "label": "Size", + "last": 12, + "name": "size", + "type": "size" + }, + { + "default": 0, + "label": "Mode", + "name": "mode", + "type": "enum", + "values": [ + { + "name": "Both", + "value": "-50.0" + }, + { + "name": "Single", + "value": "0.0" + } + ] + }, + { + "control": "None", + "default": 0.5, + "label": "Sigma", + "max": 50, + "min": 0, + "name": "sigma", + "step": 0.1, + "type": "float" + }, + { + "control": "None", + "default": 0, + "label": "Angle", + "max": 180, + "min": -180, + "name": "angle", + "step": 0.1, + "type": "float" + } + ] + }, + "type": "shader" + } + ], + "parameters": { + "param0": 9, + "param1": 50, + "param2": 45, + "param3": 0 + }, + "seed_int": 0, + "shortdesc": "Directional blur", + "type": "graph" +} diff --git a/material_maker/library/base.json b/material_maker/library/base.json index ab9f0cd72..b0be48169 100644 --- a/material_maker/library/base.json +++ b/material_maker/library/base.json @@ -2871,14 +2871,14 @@ "display_name": "Directional", "icon": "filter_blur_directional", "icon_data": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAB6ZJREFUeJztW2lP20oUPRPHdoAKGsi+dVGrtAhSSv//T2ihBRWqVl2yORukCRC8JXkfeNeaGGfxEiK9x5UijRJnPOfcM+fOeBIGYIz/cYRWPYBVxyMBqx7AquORgFUPYNXxSMCqB7DqCD/kzRhjkGUZjLHA+jRNE4ZheP7+gxHAGEM0GoUsy4H1aZomBoMBhsMhRqORpz4ehADGGOLxOGKxWGB9EnjTNGGaJjRN89TP0glgjCGVSuHFixcIh4O5nWEYuLq6suRvGAZM08RwOHTd11IJYIwhnU7j7du32NraCqRP0zRxdXVlgeYJGI1G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cAHkXngruz9+vULjUZjqeABj4ejTl4w7/m7m+h0OoEschYJz49q+MVRUJkH7spet9t9EPAAwODjb3OU/aCCfiHyUOABnwT8F+J//4+RRwJWPYBVxyMBqx7AquORgFUPYNXxD0AL6DP7CS8UAAAAAElFTkSuQmCC", - "name": "directional_blur", + "name": "directional_blur2", "parameters": { "param0": 9.0, "param1": 50.0, "param2": 45.0 }, "tree_item": "Filter/Blur/Directional", - "type": "directional_blur" + "type": "directional_blur2" }, { "display_name": "Slope", @@ -8093,4 +8093,4 @@ } ], "name": "Base library" -} \ No newline at end of file +}