Add slow skybox rotation to 3D scene and 2D scene backgrounds
3D (game_screen): _process increments env.sky_rotation.y at 0.026 rad/s (~4 min per full revolution) — works for all sky types (panoramic, animated panoramic, cubemap shader) via Godot's built-in EYEDIR transform. 2D (ContentCache): apply_scene_background attaches a canvas_item ShaderMaterial to the background TextureRect that horizontally scrolls UV.x using the built-in TIME uniform at 0.004 UV/s (matching the ~4 min cycle) — no GDScript tick needed. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -203,6 +203,7 @@ func load_texture_async(url: String, callback: Callable) -> void:
|
||||
|
||||
## Hides the first direct-child ColorRect of `parent` and injects a full-rect
|
||||
## TextureRect (from a random active skybox) as the new first child.
|
||||
## The texture slowly scrolls horizontally to match the 3D sky rotation feel.
|
||||
## Call from _ready() in any 2D scene that has a solid-color background.
|
||||
func apply_scene_background(parent: Control) -> void:
|
||||
var skybox := get_random_skybox()
|
||||
@@ -224,6 +225,12 @@ func apply_scene_background(parent: Control) -> void:
|
||||
tr.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED
|
||||
tr.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
tr.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
# Slowly scroll UV horizontally — same ~4-min revolution as the 3D sky rotation.
|
||||
var shader := Shader.new()
|
||||
shader.code = "shader_type canvas_item;\nvoid fragment() {\n\tvec2 uv = UV;\n\tuv.x = fract(uv.x + TIME * 0.004);\n\tCOLOR = texture(TEXTURE, uv);\n}\n"
|
||||
var mat := ShaderMaterial.new()
|
||||
mat.shader = shader
|
||||
tr.material = mat
|
||||
parent.add_child(tr)
|
||||
parent.move_child(tr, 0))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user