Skip to main content
added 385 characters in body
Source Link
Ghoul Fool
  • 301
  • 1
  • 3
  • 12

I'm currently stuck on trying to write a shader for Godot 4.x. and get it to look right.

I'd like to take an image, pixelate a bit so that particles are a bit chunky, and then explode it into component chunky pixels. So it looks like the sprite has broken apart.

pixels explosion slowed down

This is simple 3d animation which I mocked up in Blender to show what I want. It's basically a grid of 16 squares that shrink and fade as they move away from the centre. However they are all mapped so that together at the start they represent a whole image.

and being very new to shaders, this is what I've got so far in Godot:

pixel explosion shader

shader_type canvas_item;

uniform sampler2D tex_diffuse; // explosion image
uniform sampler2D tex_explode; // grayscale circle
uniform float progress : hint_range(0.0, 1.0);

void fragment() {
    vec2 direction = texture(tex_diffuse, UV).xy;
    direction = direction  * progress;
    
    // Get UV and step them up by 4
    vec2 tex_size = 1.0 / TEXTURE_PIXEL_SIZE; // texture size
    vec2 uv = floor(UV * tex_size/4.0) / (tex_size/4.0 - 1.0); // snap to step

    // Texture with exploded UV
    vec4 tex = texture(TEXTURE, uv); 
    
    // Dissolve with alpha
    float dissolve = texture(tex_explode, uv).x;
    dissolve = step(progress, dissolve);
    tex.a *= dissolve;
    
    // set tex 
    COLOR = tex;
}

tex_explode texture:

tex_explode image

As you can see from the two animations, I'm not quite there. This is where I need help. I need to divide the image up into pixelated chunks - let's call them pixel particles. "Move" those pixel particles apart from one another radiating from centre. scale down and fade out the pixel particles.

Just to be clear, I'm using a scale animation on the sprite (not yet included in shader)

I'm currently stuck on trying to write a shader for Godot 4.x. and get it to look right.

I'd like to take an image, pixelate a bit so that particles are a bit chunky, and then explode it into component chunky pixels. So it looks like the sprite has broken apart.

pixels explosion slowed down

and this is what I've got so far:

pixel explosion shader

shader_type canvas_item;

uniform sampler2D tex_diffuse; // explosion image
uniform sampler2D tex_explode; // grayscale circle
uniform float progress : hint_range(0.0, 1.0);

void fragment() {
    vec2 direction = texture(tex_diffuse, UV).xy;
    direction = direction  * progress;
    
    // Get UV and step them up by 4
    vec2 tex_size = 1.0 / TEXTURE_PIXEL_SIZE; // texture size
    vec2 uv = floor(UV * tex_size/4.0) / (tex_size/4.0 - 1.0); // snap to step

    // Texture with exploded UV
    vec4 tex = texture(TEXTURE, uv); 
    
    // Dissolve with alpha
    float dissolve = texture(tex_explode, uv).x;
    dissolve = step(progress, dissolve);
    tex.a *= dissolve;
    
    // set tex 
    COLOR = tex;
}

tex_explode texture:

tex_explode image

I need to divide the image up into pixelated chunks - let's call them pixel particles. "Move" those pixel particles apart from one another radiating from centre. scale down and fade out the pixel particles.

Just to be clear, I'm using a scale animation on the sprite (not yet included in shader)

I'm currently stuck on trying to write a shader for Godot 4.x. and get it to look right.

I'd like to take an image, pixelate a bit so that particles are a bit chunky, and then explode it into component chunky pixels. So it looks like the sprite has broken apart.

pixels explosion slowed down

This is simple 3d animation which I mocked up in Blender to show what I want. It's basically a grid of 16 squares that shrink and fade as they move away from the centre. However they are all mapped so that together at the start they represent a whole image.

and being very new to shaders, this is what I've got so far in Godot:

pixel explosion shader

shader_type canvas_item;

uniform sampler2D tex_diffuse; // explosion image
uniform sampler2D tex_explode; // grayscale circle
uniform float progress : hint_range(0.0, 1.0);

void fragment() {
    vec2 direction = texture(tex_diffuse, UV).xy;
    direction = direction  * progress;
    
    // Get UV and step them up by 4
    vec2 tex_size = 1.0 / TEXTURE_PIXEL_SIZE; // texture size
    vec2 uv = floor(UV * tex_size/4.0) / (tex_size/4.0 - 1.0); // snap to step

    // Texture with exploded UV
    vec4 tex = texture(TEXTURE, uv); 
    
    // Dissolve with alpha
    float dissolve = texture(tex_explode, uv).x;
    dissolve = step(progress, dissolve);
    tex.a *= dissolve;
    
    // set tex 
    COLOR = tex;
}

tex_explode texture:

tex_explode image

As you can see from the two animations, I'm not quite there. This is where I need help. I need to divide the image up into pixelated chunks - let's call them pixel particles. "Move" those pixel particles apart from one another radiating from centre. scale down and fade out the pixel particles.

Just to be clear, I'm using a scale animation on the sprite (not yet included in shader)

Updated code
Source Link
Ghoul Fool
  • 301
  • 1
  • 3
  • 12

I'm currently stuck on trying to write a shader for Godot 4.x. and get it to look right.

I'd like to take an image, pixelate a bit so that particles are a bit chunky, and then explode it into component chunky pixels. So it looks like the sprite has broken apart.

pixels explosion slowed down

and this is what I've got so far:

pixel explosion shader

shader_type canvas_item;

float random(vec2 uv)uniform {
sampler2D tex_diffuse; // explosion returnimage
uniform fract(sin(dot(uv,sampler2D vec2(12.9898,tex_explode; 78.233)))// *grayscale 438.5453);
}
circle
uniform float sensitivityprogress : hint_range(0.0, 1.0) = .5;;

void fragment() {
    // Getvec2 sizedirection of= texture in(tex_diffuse, pixelsUV).xy;
    float size_xdirection = float(textureSize(TEXTURE,direction 0).x); * progress;
    float 
 size_y = float(textureSize(TEXTURE, 0).y);// Get UV and step them up by 4
    vec2 tex_size = 1.0 / TEXTURE_PIXEL_SIZE; // texture size
    vec4vec2 pixelColoruv = texturefloor(TEXTURE, UV);
  * tex_size/4.0) / (tex_size/4.0 Create- a1.0); new// "UV"snap whichto remapsstep

 every UV value to// aTexture snappedwith pixelexploded valueUV
    vec2vec4 UVrtex = vec2(floortexture(UV.x*size_x)/size_xTEXTURE, floor(UV.y*size_y)/size_yuv); 
    
    // DetermineDissolve whetherwith pixelalpha
 should be visible orfloat not
dissolve = texture(tex_explode, uv).x;
 float visible  dissolve = step(sensitivityprogress, random(UVr)dissolve);
    //tex.a Draw*= thedissolve;
 pixel, or not depending 
 on if it is// visibleset ortex not
    COLOR = vec4(pixelColor.r, pixelColor.g, pixelColor.b, min(visible, pixelColor.a));tex;
}

tex_explode texture:

tex_explode image

I need to divide the image up into pixelated chunks - let's call them pixel particles. "Move" those pixel particles apart from one another radiating from centre. scale down and fade out the pixel particles.

Just to be clear, I'm using a scale animation on the sprite (not yet included in shader)

I'm currently stuck on trying to write a shader for Godot 4.x. and get it to look right.

I'd like to take an image, pixelate a bit so that particles are a bit chunky, and then explode it into component chunky pixels. So it looks like the sprite has broken apart.

pixels explosion slowed down

and this is what I've got so far:

pixel explosion shader

shader_type canvas_item;

float random(vec2 uv) {
    return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 438.5453);
}

uniform float sensitivity : hint_range(0.0, 1.0) = .5;

void fragment() {
    // Get size of texture in pixels
    float size_x = float(textureSize(TEXTURE, 0).x);
    float size_y = float(textureSize(TEXTURE, 0).y);
    // 
    vec4 pixelColor = texture(TEXTURE, UV);
    // Create a new "UV" which remaps every UV value to a snapped pixel value
    vec2 UVr = vec2(floor(UV.x*size_x)/size_x, floor(UV.y*size_y)/size_y);
    // Determine whether pixel should be visible or not
    float visible = step(sensitivity, random(UVr));
    // Draw the pixel, or not depending on if it is visible or not
    COLOR = vec4(pixelColor.r, pixelColor.g, pixelColor.b, min(visible, pixelColor.a));
}

tex_explode texture:

tex_explode image

I need to divide the image up into pixelated chunks - let's call them pixel particles. "Move" those pixel particles apart from one another radiating from centre. scale down and fade out the pixel particles.

Just to be clear, I'm using a scale animation on the sprite (not yet included in shader)

I'm currently stuck on trying to write a shader for Godot 4.x. and get it to look right.

I'd like to take an image, pixelate a bit so that particles are a bit chunky, and then explode it into component chunky pixels. So it looks like the sprite has broken apart.

pixels explosion slowed down

and this is what I've got so far:

pixel explosion shader

shader_type canvas_item;

uniform sampler2D tex_diffuse; // explosion image
uniform sampler2D tex_explode; // grayscale circle
uniform float progress : hint_range(0.0, 1.0);

void fragment() {
    vec2 direction = texture(tex_diffuse, UV).xy;
    direction = direction  * progress;
     
    // Get UV and step them up by 4
    vec2 tex_size = 1.0 / TEXTURE_PIXEL_SIZE; // texture size
    vec2 uv = floor(UV * tex_size/4.0) / (tex_size/4.0 - 1.0); // snap to step

    // Texture with exploded UV
    vec4 tex = texture(TEXTURE, uv); 
    
    // Dissolve with alpha
    float dissolve = texture(tex_explode, uv).x;
    dissolve = step(progress, dissolve);
    tex.a *= dissolve;
     
    // set tex 
    COLOR = tex;
}

tex_explode texture:

tex_explode image

I need to divide the image up into pixelated chunks - let's call them pixel particles. "Move" those pixel particles apart from one another radiating from centre. scale down and fade out the pixel particles.

Just to be clear, I'm using a scale animation on the sprite (not yet included in shader)

Source Link
Ghoul Fool
  • 301
  • 1
  • 3
  • 12

Explode image into component pixels shader

I'm currently stuck on trying to write a shader for Godot 4.x. and get it to look right.

I'd like to take an image, pixelate a bit so that particles are a bit chunky, and then explode it into component chunky pixels. So it looks like the sprite has broken apart.

pixels explosion slowed down

and this is what I've got so far:

pixel explosion shader

shader_type canvas_item;

float random(vec2 uv) {
    return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 438.5453);
}

uniform float sensitivity : hint_range(0.0, 1.0) = .5;

void fragment() {
    // Get size of texture in pixels
    float size_x = float(textureSize(TEXTURE, 0).x);
    float size_y = float(textureSize(TEXTURE, 0).y);
    // 
    vec4 pixelColor = texture(TEXTURE, UV);
    // Create a new "UV" which remaps every UV value to a snapped pixel value
    vec2 UVr = vec2(floor(UV.x*size_x)/size_x, floor(UV.y*size_y)/size_y);
    // Determine whether pixel should be visible or not
    float visible = step(sensitivity, random(UVr));
    // Draw the pixel, or not depending on if it is visible or not
    COLOR = vec4(pixelColor.r, pixelColor.g, pixelColor.b, min(visible, pixelColor.a));
}

tex_explode texture:

tex_explode image

I need to divide the image up into pixelated chunks - let's call them pixel particles. "Move" those pixel particles apart from one another radiating from centre. scale down and fade out the pixel particles.

Just to be clear, I'm using a scale animation on the sprite (not yet included in shader)