GodotComponentTest/materials/IslandColorRampShader.tres

60 lines
1.3 KiB
Plaintext

[gd_resource type="ShaderMaterial" load_steps=2 format=2]
[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
render_mode skip_vertex_transform;
void vertex() {
VERTEX = (WORLD_MATRIX * (EXTRA_MATRIX * vec4(VERTEX, 0.0, 1.0))).xy;
}
vec3 color_ramp(float h) {
if (h < 0.4f) {
return vec3(0, 0, 0.6);
} else if (h < 0.45f) {
return vec3(0, 0, 0.7);
} else if (h < 0.5f) {
return vec3(0, 0, 1);
} else if (h < 0.55){
return vec3(0.8, 0.8, 0.1);
} else if (h < 0.6){
return vec3(0, 0.6, 0);
} else if (h < 0.68){
return vec3(0, 0.4, 0);
} else if (h <= 0.78){
return vec3(0.6, 0.6, 0.6);
} else if (h < 1.0){
return vec3(0.8, 0.8, 0.8);
}
return vec3(1.0);
}
vec3 rgbToGrayscale(vec3 color) {
return vec3(dot(color.rgb, vec3(0.299, 0.587, 0.144)));
}
float borderFalloff(vec2 uv) {
return min(
(0.5 - abs(-uv.x + 0.5)) * 2.0,
(0.5 - abs(-uv.y + 0.5)) * 2.0);
}
float borderFalloffCircle(vec2 uv) {
return (0.5 - length(vec2(uv - vec2(0.5, 0.5)))) * 2.0;
}
void fragment() {
vec4 texture_color = texture(TEXTURE, UV);
COLOR.rgb = vec3(abs(UV.x - 0.5) * 2.0);
//COLOR.rgb = color_ramp(texture_color.r * borderFalloffCircle(UV) * 1.8);
COLOR.rgb = color_ramp(texture_color.r * borderFalloff(UV) * 1.8);
}
"
[resource]
shader = SubResource( 1 )