I see multiple problems with your code.
The line
vec2 uv=(COLOR.xy*2.0-SCREEN_UV.xy)/min(SCREEN_UV.x,SCREEN_UV.y)doesn't match the original code you've linked at all. Tryvec2 uv=(FRAGCOORD.xy*2.0-resolution.xy)/min(resolution.x,resolution.y)instead, and passresolutionas auniform vec2.Both the original code and your Godot port of it have an uninitialized variable
p. You could initializeptovec2(0.0), but the better solution in this case would be to just remove it from the right-hand side of the equations that setp. Even the original shader code doesn't work on my Mac in Safari because of this bug, although it works in Chrome on the same computer (that's the nature of uninitialized variables). Withpproperly initialized before use or removed from the right hand side of the equations that set it, the code works fine in Safari too.Your decomposed equations for
pdon't seem to match the original code. A direct port would be:p=.5+.35*sin(11.0*fract(sin((s+p+scale)*mat2(vec2(7.0,3.0),vec2(6.0,5.0)))*5.0))-fYou define
directionandintensity, but I don't see any references to them later in your code.You have the sign of the equation for
uv.yflipped.You've removed the original author's name. Although you do provide a link to the original work, considering people may copy the code directly from here, one should always make sure the code gives proper credit to the original author.
After all these corrections, I get proper snow effect in Godot 3.0 that matches the original at glslsandbox.com. Here's a final working code:
shader_type canvas_item;
//--- hatsuyuki ---
// by Catzpaw 2016
//
// Modified for Godot; original code can be found at http://www.glslsandbox.com/e#36547.0
//#extension GL_OES_standard_derivatives : enable
uniform vec2 resolution;
float snow(vec2 uv, float scale, float time)
{
float w=smoothstep(1.0,0.0,-uv.y*(scale/10.0));if(w<.1)return 0.0;
uv+=time/scale;uv.y+=time*2.0/scale;uv.x+=sin(uv.y+time*.5)/scale;
uv*=scale;vec2 s=floor(uv),f=fract(uv),p;float k=3.0,d;
p=.5+.35*sin(11.0*fract(sin((s+scale)*mat2(vec2(7,3),vec2(6,5)))*5.0))-f;d=length(p);k=min(d,k);
k=smoothstep(0.0,k,sin(f.x+f.y)*0.01);
return k*w;
}
void fragment( )
{
vec2 uv=(FRAGCOORD.xy*2.0-resolution.xy)/min(resolution.x,resolution.y);
vec3 finalColor=vec3(0);
float c=smoothstep(1.0,0.3,clamp(uv.y*.3+.8,0.0,.75));
c+=snow(uv,30.0,TIME)*.3;
c+=snow(uv,20.0,TIME)*.5;
c+=snow(uv,15.0,TIME)*.8;
c+=snow(uv,10.0,TIME);
c+=snow(uv,8.0,TIME);
c+=snow(uv,6.0,TIME);
c+=snow(uv,5.0,TIME);
finalColor=(vec3(c));
COLOR = vec4(finalColor,1.0);
}
The code above will create a parameter named resolution under the Shader Material settings in Godot. Be sure to set it to a reasonable value; otherwise the code won't work.
P.S. I've left the original author's formatting as is. As unreadable as their coding style is, this should allow the code to be compared to the original easily.