Skip to content

Instantly share code, notes, and snippets.

@sloev
Created February 12, 2023 19:57
Show Gist options
  • Select an option

  • Save sloev/eb35aef2c316759d8d56941ce223bcf9 to your computer and use it in GitHub Desktop.

Select an option

Save sloev/eb35aef2c316759d8d56941ce223bcf9 to your computer and use it in GitHub Desktop.
godot parallax
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)
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