Created
          June 9, 2024 04:10 
        
      - 
      
- 
        Save levidavidmurray/57cd71d79c8593e9b12cce4eaa768153 to your computer and use it in GitHub Desktop. 
Revisions
- 
        levidavidmurray created this gist Jun 9, 2024 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ shader_type spatial; render_mode unshaded; uniform vec2 target_uv = vec2(0.5, 0.5); // The UV coordinate to affect uniform float radius = 0.265; // Radius of the effect uniform float min_cell_size = 0.02; // Minimum cell size uniform float max_cell_size = 0.07; // Maximum cell size uniform float falloff = 1.0; // Falloff factor for the size transition uniform vec4 grid_color : source_color = vec4(1.0, 1.0, 1.0, 1.0); uniform vec4 background_color : source_color = vec4(0.0, 0.0, 0.0, 1.0); void fragment() { // Calculate the center of the current cell based on the max cell size vec2 cell_coord = floor(UV / max_cell_size); vec2 cell_center = cell_coord * max_cell_size + max_cell_size * 0.5; // Calculate the distance from the cell center to the target UV float dist = distance(cell_center, target_uv); float dist_t = dist / radius; // Determine the cell size based on the distance float cell_size = (dist < radius) ? mix(min_cell_size, max_cell_size, dist_t) : max_cell_size; // Calculate the scaled UV coordinates based on the max cell size for alignment vec2 aligned_uv = UV / max_cell_size; vec2 grid_uv = fract(aligned_uv); // Adjust the grid UV based on the calculated cell size to maintain uniform scaling vec2 adjusted_uv = (grid_uv - 0.5) * (max_cell_size / cell_size) + 0.5; // Define the gutter size relative to the cell size float gutter_size = 0.1 * max_cell_size / cell_size; float gutter_half = gutter_size * 0.5; // Determine the color based on the position within the cell if (adjusted_uv.x < gutter_half || adjusted_uv.x > 1.0 - gutter_half || adjusted_uv.y < gutter_half || adjusted_uv.y > 1.0 - gutter_half) { ALBEDO = grid_color.rgb; } else { ALBEDO = background_color.rgb; } }