2019-10-09 18:39:37 +00:00
|
|
|
tool
|
2019-10-08 13:44:51 +00:00
|
|
|
extends Sprite
|
|
|
|
|
2019-10-09 19:29:18 +00:00
|
|
|
export(bool) var editor_clouds_playing = false
|
|
|
|
export(float, 0.0, 24.0) var day_time_hours = 12.0 setget set_day_time_hours
|
|
|
|
|
|
|
|
export(NodePath) var directional_light_node_path
|
2019-10-08 13:44:51 +00:00
|
|
|
|
|
|
|
func _ready():
|
2019-10-09 18:39:37 +00:00
|
|
|
if !Engine.is_editor_hint():
|
2019-10-09 19:29:18 +00:00
|
|
|
editor_clouds_playing = true
|
2019-10-09 18:39:37 +00:00
|
|
|
|
|
|
|
func _on_previewer_time_frame_changed(time, frame):
|
|
|
|
self.material.set("shader_param/iTime", time)
|
|
|
|
self.material.set("shader_param/iFrame", frame)
|
2019-10-08 13:44:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
func cov_scb(value):
|
2019-10-08 16:54:39 +00:00
|
|
|
self.material.set("shader_param/COVERAGE",float(value))
|
2019-10-08 13:44:51 +00:00
|
|
|
|
|
|
|
func thick_scb(value):
|
|
|
|
self.material.set("shader_param/THICKNESS",value)
|
|
|
|
|
2019-10-08 16:54:39 +00:00
|
|
|
func absb_scb(value):
|
|
|
|
self.material.set("shader_param/ABSORPTION",float(value))
|
|
|
|
|
2019-10-08 13:44:51 +00:00
|
|
|
func step_scb(value):
|
|
|
|
self.material.set("shader_param/STEPS",value)
|
2019-10-08 18:06:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
export var sun_position = Vector3(0.0, 1.0, 0.0) setget set_sun_position, get_sun_position
|
|
|
|
func set_sun_position(new_position):
|
|
|
|
sun_position = new_position
|
|
|
|
if self.material:
|
|
|
|
self.material.set_shader_param("sun_pos", sun_position)
|
|
|
|
# _trigger_update_sky()
|
|
|
|
func get_sun_position():
|
|
|
|
return sun_position
|
|
|
|
|
|
|
|
func set_time_of_day(hours, directional_light, horizontal_angle = 0.0):
|
|
|
|
var sun_position = Vector3(0.0, -100.0, 0.0)
|
|
|
|
sun_position = sun_position.rotated(Vector3(1.0, 0.0, 0.0), hours * PI / 12.0)
|
|
|
|
sun_position = sun_position.rotated(Vector3(0.0, 1.0, 0.0), horizontal_angle)
|
|
|
|
|
|
|
|
if directional_light:
|
|
|
|
var t = directional_light.transform
|
|
|
|
t.origin = sun_position
|
|
|
|
directional_light.transform = t.looking_at(Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0))
|
|
|
|
directional_light.light_energy = 1.0 - clamp(abs(hours - 12.0) / 6.0, 0.0, 1.0)
|
|
|
|
|
|
|
|
# and update our sky
|
2019-10-09 18:39:37 +00:00
|
|
|
set_sun_position(sun_position)
|
|
|
|
|
2019-10-09 19:29:18 +00:00
|
|
|
|
|
|
|
func set_day_time_hours(hours):
|
|
|
|
if directional_light_node_path:
|
|
|
|
set_time_of_day(hours, get_node(directional_light_node_path), 25.0)
|