Add rotating shine rays

master
Fabien Freling 2018-11-04 17:57:36 +01:00
parent 0f8b314cdf
commit 0294800e6b
1 changed files with 34 additions and 28 deletions

View File

@ -11,6 +11,8 @@ extents = Vector3( 0.584547, 2.22627, 0.659734 )
code = "shader_type spatial;
uniform float PI = 3.1415;
// BILLBOARD_FIXED_Y
// from: https://github.com/godotengine/godot/blob/master/scene/resources/material.cpp#L552
void vertex() {
@ -18,46 +20,47 @@ 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;
// }
//}
float shine_ray(vec2 center_coords, float time, float offset, float speed) {
// atan() is in [-pi, pi[
float angle = atan(center_coords.x, center_coords.y) + offset;
if (angle > PI) {
angle -= 2.0 * PI;
}
if (angle < -PI) {
angle += 2.0 * PI;
}
float t = mod(-time * speed, 2.0 * PI) - PI; // [-pi, pi[
bool on_ray = abs(angle - t) < 0.05;
if (!on_ray) {
return 0.0;
}
float max_dist = 0.5; // maximum orthogonal distance from center in a [0,1] rectangle
float center_dist = sqrt(pow(center_coords.x, 2) + pow(center_coords.y, 2)) / max_dist;
float intensity = 1.0;
return clamp((1.0 - center_dist) * intensity, 0.0, 1.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(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);
}
ALPHA = clamp(
shine_ray(center_coords, TIME, 0.0, 0.3) +
shine_ray(center_coords, TIME, PI, 0.3) +
shine_ray(center_coords, TIME, 0.0, 0.5) +
shine_ray(center_coords, TIME, PI, 0.4),
0.0, 1.0);
}
"
_sections_unfolded = [ "Resource" ]
[sub_resource type="ShaderMaterial" id=3]
render_priority = 0
shader = SubResource( 2 )
shader_param/PI = null
[sub_resource type="Gradient" id=4]
@ -158,5 +161,8 @@ frame = 0
region_enabled = false
region_rect = Rect2( 0, 0, 0, 0 )
_sections_unfolded = [ "Animation", "Flags", "Geometry", "LOD", "Pause", "Region", "Transform", "Visibility" ]
__meta__ = {
"_edit_lock_": true
}