Created
October 12, 2019 21:53
-
-
Save regakakobigman/d7dab152d70fce012f030e9b9b6d0d90 to your computer and use it in GitHub Desktop.
MeshInstance that animates its UV offset for a trippy visual effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tool | |
extends MeshInstance | |
class_name MeshInstanceUV | |
var _time := Vector2() | |
export var speed := Vector2(1.0, 1.0) | |
export var sinusoid_factor := Vector2(1.0, 1.0) | |
export var linear_factor := Vector2(1.0, 1.0) | |
func _ready() -> void: | |
_time += Vector2(1, 1) * randf() | |
if not owner and get_surface_material_count() > 0: | |
var material: SpatialMaterial = get_surface_material(0) | |
if not material: return | |
material.uv1_offset = Vector3() | |
func _process(delta: float) -> void: | |
if not owner or get_surface_material_count() == 0: return | |
_time += delta * speed | |
var material: SpatialMaterial = get_surface_material(0) | |
if not material: return | |
material.uv1_offset.x = (sin(_time.x * 2 * PI) / (2 * PI)) * sinusoid_factor.x + _time.x * linear_factor.x | |
material.uv1_offset.y = (sin(_time.y * 2 * PI) / (2 * PI)) * sinusoid_factor.y + _time.y * linear_factor.y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment