Implemented a basic Direct Wrap node.

Input an image, mask and angle - applying a wrap based on the inputs

- Need to cleanup stuff
- Based heavily on blur implementation, need to set the names to be more indicative and general
- Change the map source from file to color input
This commit is contained in:
Lidor Yosef
2020-10-01 01:21:25 +03:00
parent 2535966856
commit aaa679cdd3
4 changed files with 92 additions and 3 deletions
@@ -517,10 +517,43 @@ class MaterialParser {
var gamma = parse_value_input(node.inputs[1]);
return 'pow($out_col, ' + to_vec3('$gamma') + ")";
}
else if(node.type == "DIRECT_WARP"){
// Already fetched
if (parsed.indexOf(res_var_name(node, node.outputs[0])) >= 0) {
var varname = store_var_name(node);
}
// Load the warp mask
var mask_name = node_name(node);
var tex = make_texture(node, mask_name);
// Initialize the grayscale value in case no mask registered
curshader.write('float gray = 0;');
if (tex != null) {
var texstore = texture_store(node, tex, mask_name, true);
// Get the relevant mask-fragment grayscale value
curshader.write('vec3 color = texture($mask_name, texCoord).rgb;');
curshader.write('gray = dot(color, vec3(0.299, 0.587, 0.114));');
}
// Load the current exisitng material texture and transform it
if (blur_passthrough) return parse_vector_input(node.inputs[0]);
var strength = Std.parseFloat(parse_value_input(node.inputs[1])) * 500;
var tex_name = "texblur_" + node_name(node);
curshader.add_uniform("sampler2D " + tex_name, "_" + tex_name);
var angle_rad = Std.parseFloat(parse_value_input(node.inputs[2])) * (Math.PI / 180);
var x = Math.cos(angle_rad) * strength;
var y = Math.sin(angle_rad) * strength;
curshader.write('vec3 res1 = vec3(0.0, 0.0, 0.0);');
curshader.write('res1 += texture($tex_name, texCoord + vec2($x, $y) * gray / vec2(textureSize($tex_name, 0))).rgb;');
return "res1";
}
else if (node.type == "BLUR") {
if (blur_passthrough) return parse_vector_input(node.inputs[0]);
var strength = parse_value_input(node.inputs[1]);
if (strength == "0.0") return "vec3(0.0, 0.0, 0.0)";
if (strength == "0") return "vec3(0.0, 0.0, 0.0)";
var steps = 'int($strength * 10 + 1)';
var tex_name = "texblur_" + node_name(node);
curshader.add_uniform("sampler2D " + tex_name, "_" + tex_name);
@@ -1279,6 +1279,62 @@ class NodesMaterial {
}
],
[ // Color
{
id: 0,
name: _tr("Warp"),
type: "DIRECT_WARP", // extension
x: 0,
y: 0,
color: 0xff448c6d,
inputs: [
{
id: 0,
node_id: 0,
name: _tr("Color"),
type: "RGBA",
color: 0xffc7c729,
default_value: f32([0.8, 0.8, 0.8, 1.0])
},
{
id: 0,
node_id: 0,
name: _tr("Strength"),
type: "VALUE",
color: 0xffa1a1a1,
default_value: 0.5,
min: 0.0,
max: 1.0
},
{
id: 0,
node_id: 0,
name: _tr("Angle"),
type: "VALUE",
color: 0xffa1a1a1,
default_value: 0.0,
min: 0.0,
max: 360.0
}
],
outputs: [
{
id: 0,
node_id: 0,
name: _tr("Color"),
type: "RGBA",
color: 0xffc7c729,
default_value: f32([0.8, 0.8, 0.8, 1.0])
}
],
buttons: [
{
name: _tr("File"),
type: "ENUM",
default_value: 0,
data: ""
}
]
},
{
id: 0,
name: _tr("Blur"),
+1 -1
View File
@@ -571,7 +571,7 @@ class App {
}
public static function enumTexts(nodeType: String): Array<String> {
if (nodeType == "TEX_IMAGE") {
if (nodeType == "TEX_IMAGE" || nodeType == "DIRECT_WARP") {
return Project.assetNames.length > 0 ? Project.assetNames : [""];
}
else if (nodeType == "LAYER" || nodeType == "LAYER_MASK") {
+1 -1
View File
@@ -181,7 +181,7 @@ class MakeMaterial {
Context.nodePreviewsBlur = null;
}
for (node in UINodes.inst.getCanvasMaterial().nodes) {
if (node.type == "BLUR") {
if (node.type == "BLUR" || node.type == "DIRECT_WARP") {
if (Context.nodePreviewsBlur == null) {
Context.nodePreviewsBlur = new Map();
}