frame-of-mind/src/logic-scenes/card_burner/card_fire.gdshader

54 lines
1.8 KiB
Plaintext

shader_type canvas_item;
render_mode blend_add;
uniform float fire_progression = 0;
uniform sampler2D flame_noise: repeat_enable;
uniform sampler2D flame_gradoent;
vec3 RNGV3(vec3 p) {
vec3 a = fract(sin(vec3(p.x, p.y, p.z)) * vec3(111.11,333.33,444.44));
a += dot(a, a+33.51);
return fract(vec3(a.x*a.y, a.y*a.z, a.z*a.x)); //outputs a random vec2 between 0 and 1
}
vec4 voronoy(vec3 loc, float scale){
loc = loc*scale;
vec4 output = vec4(0., 0., 0., 10.);
for(float y=-1.; y<=1.; y++){
for(float x=-1.; x<=1.; x++){
for(float z=-1.; z<=1.; z++){
vec3 offs = vec3(x,y,z);
vec3 n = RNGV3(floor(loc)+offs)*2.0-1.0;
vec3 p = offs+sin(n) * .5;
float d = length((fract(loc)-0.5)-p);
if(d<output.q){
vec3 rng = RNGV3(floor(loc)+offs);
output = vec4(rng.x, rng.y, rng.z, d);
}
}
}
}
return output;
}
vec4 smooth_voronoi(vec3 loc, float scale, int steps, float scatter){
vec4 result = vec4(.0);
scatter = scatter/float(steps)/scale;
for (float x = 0.0; x<float(steps); x++) {
for (float y = 0.0; y<float(steps); y++) {
for (float z = 0.0; z<float(steps); z++) {
result += voronoy(loc + vec3(x, y, z) * scatter, scale);
}
}
}
return result / pow(float(steps), 3.);
}
void fragment() {
vec2 flame_uv = UV * 2.0+ texture(flame_noise, UV+vec2(0, TIME*3.0) *.1).z*vec2(0.1, 0.7);
flame_uv = UV + pow(smooth_voronoi(vec3(flame_uv + vec2(.0, TIME*2.0) , TIME*1.0), 2.0, 3, .3).w, 1.5-voronoy(vec3(flame_uv, -TIME + COLOR.r*.5)*.7, 5.0).w) - 1.3 - COLOR.r*.5 + fire_progression;
COLOR = pow(texture(flame_gradoent, flame_uv.yx), vec4(2.2)) * sin((fire_progression)*(PI/2.0)) * pow(COLOR.r, 0.5) *3.0;
}