Add rotating shine rays
This commit is contained in:
parent
0f8b314cdf
commit
0294800e6b
|
@ -11,6 +11,8 @@ extents = Vector3( 0.584547, 2.22627, 0.659734 )
|
||||||
|
|
||||||
code = "shader_type spatial;
|
code = "shader_type spatial;
|
||||||
|
|
||||||
|
uniform float PI = 3.1415;
|
||||||
|
|
||||||
// BILLBOARD_FIXED_Y
|
// BILLBOARD_FIXED_Y
|
||||||
// from: https://github.com/godotengine/godot/blob/master/scene/resources/material.cpp#L552
|
// from: https://github.com/godotengine/godot/blob/master/scene/resources/material.cpp#L552
|
||||||
void vertex() {
|
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));
|
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 shine_ray(vec2 center_coords, float time, float offset, float speed) {
|
||||||
// float pi = 3.14;
|
// atan() is in [-pi, pi[
|
||||||
// if (coords.x > 0.0) {
|
float angle = atan(center_coords.x, center_coords.y) + offset;
|
||||||
// return atan(coords.x, coords.y);
|
if (angle > PI) {
|
||||||
// } else if (coords.x < 0.0) {
|
angle -= 2.0 * PI;
|
||||||
// if (coords.y >= 0.0) {
|
}
|
||||||
// return atan(coords.x, coords.y) - pi;
|
if (angle < -PI) {
|
||||||
// } else {
|
angle += 2.0 * PI;
|
||||||
// return atan(coords.x, coords.y) + pi;
|
}
|
||||||
// }
|
float t = mod(-time * speed, 2.0 * PI) - PI; // [-pi, pi[
|
||||||
// } else if (coords.y > 0.0) {
|
bool on_ray = abs(angle - t) < 0.05;
|
||||||
// return pi / 2.0;
|
|
||||||
// } else {
|
if (!on_ray) {
|
||||||
// return - pi / 2.0;
|
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() {
|
void fragment() {
|
||||||
ALBEDO = vec3(1.0, 1.0, 0);
|
ALBEDO = vec3(1.0, 1.0, 0);
|
||||||
|
|
||||||
vec2 center_coords = vec2(UV.x - 0.5, UV.y - 0.5);
|
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
|
ALPHA = clamp(
|
||||||
// distance from the center, normalized on [0,1]
|
shine_ray(center_coords, TIME, 0.0, 0.3) +
|
||||||
float center_dist = sqrt(pow(center_coords.x, 2) + pow(center_coords.y, 2)) / max_dist;
|
shine_ray(center_coords, TIME, PI, 0.3) +
|
||||||
float angle = atan(center_coords.x, center_coords.y);
|
shine_ray(center_coords, TIME, 0.0, 0.5) +
|
||||||
|
shine_ray(center_coords, TIME, PI, 0.4),
|
||||||
bool on_ray = abs(angle - (sin(TIME) * 3.14)) < 0.1;// * (1.0 - center_dist);
|
0.0, 1.0);
|
||||||
|
|
||||||
if (on_ray) {
|
|
||||||
ALPHA = 1.0;
|
|
||||||
} else {
|
|
||||||
ALPHA = max(1.0 - center_dist, 0.0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
_sections_unfolded = [ "Resource" ]
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id=3]
|
[sub_resource type="ShaderMaterial" id=3]
|
||||||
|
|
||||||
render_priority = 0
|
render_priority = 0
|
||||||
shader = SubResource( 2 )
|
shader = SubResource( 2 )
|
||||||
|
shader_param/PI = null
|
||||||
|
|
||||||
[sub_resource type="Gradient" id=4]
|
[sub_resource type="Gradient" id=4]
|
||||||
|
|
||||||
|
@ -158,5 +161,8 @@ frame = 0
|
||||||
region_enabled = false
|
region_enabled = false
|
||||||
region_rect = Rect2( 0, 0, 0, 0 )
|
region_rect = Rect2( 0, 0, 0, 0 )
|
||||||
_sections_unfolded = [ "Animation", "Flags", "Geometry", "LOD", "Pause", "Region", "Transform", "Visibility" ]
|
_sections_unfolded = [ "Animation", "Flags", "Geometry", "LOD", "Pause", "Region", "Transform", "Visibility" ]
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_lock_": true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue