0 votes

For quick prototyping I like to add a checker board parallax layer in order to make it easier to perceive distances and speed, but parallax layers don't work well when changing the zoom and I also have to manually readjust it whenever I want to change window sizes.

Recently I'm starting to learn about shaders and after watching this video I'm sure that there has to be a way to make what I'm trying to do with that but instead of being an auto-scrolling texture it just adjusts to the player's movement, that way I can easily dynamically resize the region rect whenever I want to change window size or zoom. Unfortunately I can't figure out how to make it work because it's hard to find a lot of information about shaders, I'd love to get some help!

Godot version 3.3.3.stable
in Engine by (21 points)

1 Answer

+1 vote
Best answer

I assume you mean something like this?

shader_type canvas_item;

uniform float offset = 0.0;
uniform float multiplier;

void fragment() {
    float u = offset * multiplier * TEXTURE_PIXEL_SIZE.x;
    COLOR = texture(TEXTURE, vec2(UV.x + u, UV.y));
}

Make sure you enable the "repeat" flag on the texture (or you could also mod(u, 1.0) in the shader) and set the shader parameters with process_material.set_shader_param(). Offset is the "real world" offset and multiplier is the speed of the parallax.

by (913 points)
selected by

yeah that's exactly what I was trying to do, I mostly do top-down games instead of side scrollers but I was able to easily figure out what I had to edit in order to make it work top down, thanks!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.