Skip to content

Commit

Permalink
shadergraph: dissolve map node
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoVgr committed Jan 23, 2024
1 parent e3cc2b0 commit c71355b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion hrt/shgraph/ShaderGraph.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,8 @@ class Graph {
// continue;
// }

if (Std.downcast(currentNode.instance, hrt.shgraph.nodes.Sampler) != null) {
if (Std.downcast(currentNode.instance, hrt.shgraph.nodes.Sampler) != null ||
Std.downcast(currentNode.instance, hrt.shgraph.nodes.Dissolve) != null) {
if (!allInputsVarsBound) {
expr = makeAssign(makeVar(nodeVar.v), makeVec([0.0,0.0,0.0,0.0]));
}
Expand Down
18 changes: 11 additions & 7 deletions hrt/shgraph/nodes/Dissolve.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ using hxsl.Ast;

@name("Dissolve")
@description("Dissolve input")
@width(150)
@width(180)
@group("Math")
class Dissolve extends ShaderNodeHxsl {

static var SRC = {
@sginput(1.0) var channel : Float;
@sginput(1.0) var progress : Float;
@sginput(0.0) var saturation : Float;
@sginput var rgba : Vec4;
@sginput(calculatedUV) var uv : Vec2;
@sginput var dissolveMap : Sampler2D;
@sginput(0.5) var progress : Float;
@sginput(0.5) var saturation : Float;
@sginput(1.0) var width : Float;
@sgoutput var output : Float;
@sgoutput var output : Vec4;

function fragment() {
var pix = dissolveMap.get(uv);
var edge = mix(1.0 + width, -width, progress);
var ramp = saturate((1.0 + saturation) * (width - abs(edge - channel)) / width);
output = channel * ramp;
var ramp = saturate((1.0 + saturation) * (width - abs(edge - pix.r)) / width);
output.rgb = rgba.rgb;
output.a = rgba.a * ramp * pix.a;
}
};
}

0 comments on commit c71355b

Please sign in to comment.