57 lines
1.8 KiB
GDScript
57 lines
1.8 KiB
GDScript
tool
|
|
extends Sprite
|
|
|
|
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
|
|
|
|
func _ready():
|
|
if !Engine.is_editor_hint():
|
|
editor_clouds_playing = true
|
|
|
|
func _on_previewer_time_frame_changed(time, frame):
|
|
self.material.set("shader_param/iTime", time)
|
|
self.material.set("shader_param/iFrame", frame)
|
|
|
|
|
|
func cov_scb(value):
|
|
self.material.set("shader_param/COVERAGE",float(value))
|
|
|
|
func thick_scb(value):
|
|
self.material.set("shader_param/THICKNESS",value)
|
|
|
|
func absb_scb(value):
|
|
self.material.set("shader_param/ABSORPTION",float(value))
|
|
|
|
func step_scb(value):
|
|
self.material.set("shader_param/STEPS",value)
|
|
|
|
|
|
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
|
|
set_sun_position(sun_position)
|
|
|
|
|
|
func set_day_time_hours(hours):
|
|
if directional_light_node_path:
|
|
set_time_of_day(hours, get_node(directional_light_node_path), 25.0)
|