Created
February 12, 2023 19:57
-
-
Save sloev/eb35aef2c316759d8d56941ce223bcf9 to your computer and use it in GitHub Desktop.
godot parallax
This file contains hidden or 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
| extends TextureRect | |
| var shader_material | |
| var screen_size | |
| func _ready(): | |
| screen_size = OS.get_screen_size() | |
| shader_material = self.material | |
| set_process_input(true) | |
| func _input(event): | |
| if event is InputEventMouseMotion: | |
| var norm_mouse = self.get_local_mouse_position()/screen_size | |
| # norm_mouse.y = 1.0-norm_mouse.y | |
| norm_mouse = (norm_mouse/2.0) | |
| print(norm_mouse) | |
| shader_material.set_shader_param("mouse_pos", norm_mouse) | |
This file contains hidden or 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
| shader_type canvas_item; | |
| uniform vec2 mouse_pos; | |
| uniform sampler2D dog; | |
| uniform sampler2D depth_map; | |
| void fragment(){ | |
| COLOR = texture(dog, UV+mouse_pos*(texture(depth_map, UV).r)); //read from texture | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment