Add ray in flag shader

master
Fabien Freling 2018-09-27 15:00:23 +02:00
parent b67cbe9ba2
commit 0f8b314cdf
2 changed files with 32 additions and 5 deletions

View File

@ -5,7 +5,7 @@
[ext_resource path="res://scenes/Goal.tscn" type="PackedScene" id=3]
[ext_resource path="res://levels/Level_01_env.tres" type="Environment" id=4]
[node name="Level_01" type="Node" index="0"]
[node name="Level_01" type="Node"]
[node name="GridMap" type="GridMap" parent="." index="0"]

View File

@ -18,12 +18,39 @@ void vertex() {
MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz),0,0,0),vec4(0,1,0,0),vec4(0,0,length(WORLD_MATRIX[2].xyz),0),vec4(0,0,0,1));
}
//float atan2(vec2 coords) {
// float pi = 3.14;
// if (coords.x > 0.0) {
// return atan(coords.x, coords.y);
// } else if (coords.x < 0.0) {
// if (coords.y >= 0.0) {
// return atan(coords.x, coords.y) - pi;
// } else {
// return atan(coords.x, coords.y) + pi;
// }
// } else if (coords.y > 0.0) {
// return pi / 2.0;
// } else {
// return - pi / 2.0;
// }
//}
void fragment() {
ALBEDO = vec3(1.0, 1.0, 0);
vec2 center_coords = vec2(UV.x - 0.5, UV.y - 0.5);
float max_dist = 0.5; // maximum orthogonal distance from center in a [0,1] rectangle
// distance from the center, normalized on [0,1]
float center_dist = sqrt(pow(UV.x - 0.5, 2) + pow(UV.y - 0.5, 2)) / max_dist;
ALBEDO = vec3(1.0, 1.0, 0);
ALPHA = max(1.0 - center_dist, 0.0);
float center_dist = sqrt(pow(center_coords.x, 2) + pow(center_coords.y, 2)) / max_dist;
float angle = atan(center_coords.x, center_coords.y);
bool on_ray = abs(angle - (sin(TIME) * 3.14)) < 0.1;// * (1.0 - center_dist);
if (on_ray) {
ALPHA = 1.0;
} else {
ALPHA = max(1.0 - center_dist, 0.0);
}
}
"
@ -44,7 +71,7 @@ gradient = SubResource( 4 )
width = 2
_sections_unfolded = [ "Resource" ]
[node name="Scene Root" instance=ExtResource( 1 )]
[node name="Scene Root" index="0" instance=ExtResource( 1 )]
script = ExtResource( 2 )