khanat-client/scenes/game/sky.gd

72 lines
2 KiB
GDScript3
Raw Normal View History

2020-03-21 13:18:06 +00:00
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():
2021-01-21 21:03:44 +00:00
if !Engine.is_editor_hint():
editor_clouds_playing = true
2020-03-21 13:18:06 +00:00
var iTime = 0.0
var iFrame = 0
func _process( delta ):
2021-01-21 21:03:44 +00:00
iTime+=delta
iFrame+=1
if (Engine.is_editor_hint() and self.editor_clouds_playing) or !Engine.is_editor_hint():
self.material.set("shader_param/iTime", iTime)
self.material.set("shader_param/iFrame", iFrame)
2020-03-21 13:18:06 +00:00
# self.set_day_time_hours( self.day_time_hours + delta )
# if day_time_hours >= 24:
# self.set_day_time_hours( 0 )
2020-03-21 13:18:06 +00:00
func cov_scb(value):
2021-01-21 21:03:44 +00:00
self.material.set("shader_param/COVERAGE",float(value))
2020-03-21 13:18:06 +00:00
func thick_scb(value):
2021-01-21 21:03:44 +00:00
self.material.set("shader_param/THICKNESS",value)
2020-03-21 13:18:06 +00:00
func absb_scb(value):
2021-01-21 21:03:44 +00:00
self.material.set("shader_param/ABSORPTION",float(value))
2020-03-21 13:18:06 +00:00
func step_scb(value):
2021-01-21 21:03:44 +00:00
self.material.set("shader_param/STEPS",value)
2020-03-21 13:18:06 +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):
2021-01-21 21:03:44 +00:00
sun_position = new_position
if self.material:
self.material.set_shader_param("sun_pos", sun_position)
2020-03-21 13:18:06 +00:00
# _trigger_update_sky()
func get_sun_position():
2021-01-21 21:03:44 +00:00
return sun_position
2020-03-21 13:18:06 +00:00
func set_time_of_day(hours, directional_light, horizontal_angle = 0.0):
2021-01-21 21:03:44 +00:00
var new_position = Vector3(0.0, -100.0, 0.0)
new_position = new_position.rotated(Vector3(1.0, 0.0, 0.0), hours * PI / 12.0)
new_position = new_position.rotated(Vector3(0.0, 1.0, 0.0), horizontal_angle)
if directional_light:
var t = directional_light.transform
t.origin = new_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(new_position)
2020-03-21 13:18:06 +00:00
func set_day_time_hours(hours):
2021-01-21 21:03:44 +00:00
if directional_light_node_path:
set_time_of_day(hours, get_node(directional_light_node_path), 25.0)
day_time_hours = hours