Godot Version
4.4
Question
how can i apply this shader to tile? not per tile, but as a unified texture,
this shader that i want to put in in tile
shader_type canvas_item;
// Use a NoiseTexture2D
uniform sampler2D noise_texture;
// Use a GradientTexture1D
uniform sampler2D burn_texture;
// Change this value to dissolve the object
uniform float integrity: hint_range(0.0, 1.0) = 1.0;
// How large the burn is
uniform float burn_size: hint_range(1.0, 5.0) = 1.3;
// Inverse lerp function
// Converts the value v from the range [a, b] to the range [0, 1]
float inverse_lerp(float a, float b, float v) {
return (v - a) / (b - a);
}
void fragment() {
float noise = texture(noise_texture, UV).r;
vec4 tex_color = texture(TEXTURE, UV);
// Base color fades in based on noise threshold
vec4 base_color = tex_color * step(noise, integrity);
// Burn effect sampling
vec2 burn_uv = vec2(inverse_lerp(integrity, integrity * burn_size, noise), 0.0);
vec4 burn_color = texture(burn_texture, burn_uv) * step(noise, integrity * burn_size);
// Mix burn and base color, then multiply alpha by texture shape
vec4 final_color = mix(burn_color, base_color, base_color.a);
final_color.a *= tex_color.a; // Smooth fade based on texture alpha
COLOR = final_color;
}
when i put like this , i get line like img below
uniform sampler2D noise_texture;
// Use a GradientTexture1D
uniform sampler2D burn_texture;
// Change this value to dissolve the object
uniform float integrity: hint_range(0.0, 1.0) = 1.0;
// How large the burn is
uniform float burn_size: hint_range(1.0, 5.0) = 1.3;
varying vec2 world_position;
// Size of the whole tilemap layer in pixels (you must set this via script)
uniform vec2 map_pixel_size = vec2(512.0, 512.0);
void vertex(){
// calculate the world position for use in the fragment shader
world_position = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
}
// Converts a world position to a normalized UV in the tilemap's bounds
vec2 get_global_uv() {
// Normalize world position to 0–1 range within the tilemap size
return (world_position.xy - vec2(0.0)) / map_pixel_size;
}
float inverse_lerp(float a, float b, float v) {
return (v - a) / (b - a);
}
void fragment() {
vec2 global_uv = get_global_uv(); // stable, world-based UV
float noise = texture(noise_texture, global_uv).r;
vec4 tex_color = texture(TEXTURE, UV);
vec4 base_color = tex_color * step(noise, integrity);
vec2 burn_uv = vec2(inverse_lerp(integrity, integrity * burn_size, noise), 0.0);
vec4 burn_color = texture(burn_texture, burn_uv) * step(noise, integrity * burn_size);
vec4 final_color = mix(burn_color, base_color, base_color.a);
final_color.a *= tex_color.a;
COLOR = final_color;
}