Skip to content

Instantly share code, notes, and snippets.

@andrew-wilkes
Last active November 22, 2022 11:18
Show Gist options
  • Save andrew-wilkes/aab1d9e066cf19bc336bbbb0d940c648 to your computer and use it in GitHub Desktop.
Save andrew-wilkes/aab1d9e066cf19bc336bbbb0d940c648 to your computer and use it in GitHub Desktop.
Grid Shader for Godot
shader_type canvas_item;
uniform float cell_size = 16;
uniform float cell_spacing = 2;
uniform vec4 line_color : hint_color; //Now called source_color in Godot 4
varying vec2 v;
void vertex() {
v = VERTEX;
}
void fragment() {
COLOR.a = 0.;
float step_size = cell_size + cell_spacing;
float ratio = cell_spacing / step_size;
// Grid
if (fract(v.x / step_size) < ratio || fract(v.y / step_size) < ratio) COLOR = line_color;
}
@OrangeRevolt
Copy link

Thanks for the the example. While using it in Godot 4 i noticed hint_color has been changed to "source_color" i suggest in making a comment with "//Now called source_color in Godot 4". Also the size variable does nothing it seems.

@andrew-wilkes
Copy link
Author

@OrangeRevolt Thanks for your feedback. I updated the script accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment