|
|
|
|
Reply From: |
MysteryGM |
This is a sharp Alpha cut off shader:
shader_type canvas_item;
uniform sampler2D Mask : hint_white;
uniform float Clip : hint_range(0.0, 8.0, 0.005) = 1.0;
void fragment(){
float AlphaCut = 1.0;
if (texture(Mask,UV).r < Clip) {
AlphaCut = 0.0;
}
COLOR = vec4(texture(TEXTURE,UV).rgb, AlphaCut);
}
Unfortunately “fringe effect” is a name used for so many effects I don’t really know what you want.
If you shared more details I could make you a example.
Thank you for answer.
I was talking about simple dissolve shader, something like this
dissolve shaded youtube
But the main question was can we do sick thing in visual shaded, because it has previews it is more convenient to wark in busal editor,
At least for me).
TEXTUS | 2018-11-27 19:38
I was talking about simple dissolve shader, something like this
What you have to realize is that the shader uses a trick. First it colors the object then it “cuts” a piece of it. Like this:
What that means is you need to do the edge calculation twice, once for color then again for alpha.
This is the code version:
shader_type canvas_item;
uniform sampler2D Mask : hint_white;
uniform float Clip : hint_range(0.0, 1.0, 0.005) = 1.0;
uniform float EdgeThickness = 0.05;
uniform vec4 EdgeColor : hint_color;
void fragment(){
float AlphaCut = 1.0;
vec3 color = texture(TEXTURE,UV).rgb;
//First we color the material
if (texture(Mask,UV).r < Clip) {
color = EdgeColor.rgb
}
//This is the transparent cut, it has to be a little above the color
//to get the edge
if (texture(Mask,UV).r +EdgeThickness < Clip) {
AlphaCut = 0.0;
}
COLOR = vec4(color, AlphaCut);
}
Very simple, However in a visual shader we have no control flow options like IF AND or LOOP. This is intentional as you need some kind of indication of how flow works, and visual shaders just don’t have that.
So we go old school, use math to solve the problem.
Once such formula is: The floor of Atan2, clamped to 1, then inverted with 1-X.
We do it twice to get the effect:
So much easier than just a few lines of code. Here is the shader:
AlphaCutVisual.tres - Google Drive
Here we can see the code and visual shader side by side:
As you can see both works. The visual shader replaces the complexity of code, with the complexity of math.
Godot’s developers will need to add flow options like Unreal’s blueprints.
It is actually possible to make a IF function using math, that is indeed how it works, so if you know Boolean math you could make it yourself.
MysteryGM | 2018-11-29 00:22