From 0f8b314cdff0a392c994732014f8412da9b41c4e Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Thu, 27 Sep 2018 15:00:23 +0200 Subject: [PATCH] Add ray in flag shader --- levels/Level_01.tscn | 2 +- scenes/Goal.tscn | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/levels/Level_01.tscn b/levels/Level_01.tscn index d1d6ce5..9639573 100644 --- a/levels/Level_01.tscn +++ b/levels/Level_01.tscn @@ -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"] diff --git a/scenes/Goal.tscn b/scenes/Goal.tscn index bc5d2bf..713136e 100644 --- a/scenes/Goal.tscn +++ b/scenes/Goal.tscn @@ -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 )