Split gridline shader into its own file

This commit is contained in:
Luke Hubmayer-Werner 2020-05-23 13:44:55 +09:30
parent cc1fec841b
commit b8ab57f6ea
2 changed files with 32 additions and 33 deletions

30
GridLines.shader Normal file
View File

@ -0,0 +1,30 @@
shader_type canvas_item;
uniform float rows = 44.0; // Really int but don't want to recast all the time
uniform float cols = 63.0; // ^
void fragment(){
vec2 frag_pos = UV * vec2(cols, rows);
vec2 frag_marginal = fract(frag_pos+0.05);
vec2 frag_marginal_2 = fract(frag_pos-0.4);
vec2 grid_data = texture(TEXTURE, (frag_pos+0.05)/vec2(cols+1.0, rows+1.0)).rg;
COLOR = vec4(0.0);
if (frag_marginal.x < 0.1){
if (grid_data.g >= 0.99){
if (frag_marginal_2.y <= 0.2)
COLOR = vec4(1.0, 0.0, 0.0, 1.0);
}else if (grid_data.g >= 0.49){
COLOR = vec4(0.0, 0.0, 1.0, 1.0);
}else
COLOR = vec4(0.5, 0.5, 0.5, 1.0);
}
if (frag_marginal.y < 0.1){
if (grid_data.r >= 0.99){
if (frag_marginal_2.x <= 0.2)
COLOR = vec4(1.0, 0.0, 0.0, 1.0);
}else if (grid_data.r >= 0.49){
COLOR = vec4(0.0, 0.0, 1.0, 1.0);
}else
COLOR = vec4(0.5, 0.5, 0.5, 1.0);
}
}

View File

@ -1,41 +1,10 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://scripts/GameField.gd" type="Script" id=1]
[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
uniform float rows = 44.0; // Really int but don't want to recast all the time
uniform float cols = 63.0; // ^
void fragment(){
vec2 frag_pos = UV * vec2(cols, rows);
vec2 frag_marginal = fract(frag_pos+0.05);
vec2 frag_marginal_2 = fract(frag_pos-0.4);
vec2 grid_data = texture(TEXTURE, (frag_pos+0.05)/vec2(cols+1.0, rows+1.0)).rg;
COLOR = vec4(0.0);
if (frag_marginal.x < 0.1){
if (grid_data.g >= 0.99){
if (frag_marginal_2.y <= 0.2)
COLOR = vec4(1.0, 0.0, 0.0, 1.0);
}else if (grid_data.g >= 0.49){
COLOR = vec4(0.0, 0.0, 1.0, 1.0);
}else
COLOR = vec4(0.5, 0.5, 0.5, 1.0);
}
if (frag_marginal.y < 0.1){
if (grid_data.r >= 0.99){
if (frag_marginal_2.x <= 0.2)
COLOR = vec4(1.0, 0.0, 0.0, 1.0);
}else if (grid_data.r >= 0.49){
COLOR = vec4(0.0, 0.0, 1.0, 1.0);
}else
COLOR = vec4(0.5, 0.5, 0.5, 1.0);
}
}"
[ext_resource path="res://GridLines.shader" type="Shader" id=2]
[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
shader = ExtResource( 2 )
shader_param/rows = 44.0
shader_param/cols = 63.0