Created
December 19, 2020 21:19
-
-
Save jjmontesl/16ca957bf3a39dda8a98063e6b7ae452 to your computer and use it in GitHub Desktop.
Godot Sprite with Parallax Shader
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
shader_type canvas_item; | |
//render_mode unshaded; | |
uniform float upScale = 1.0f; | |
uniform float bottomScale = 1.5f; | |
uniform float clampY = 0.0f; | |
uniform float expFactor = 0.0f; | |
void fragment(){ | |
float height = UV.y; | |
float heightClamped = clamp((height - clampY) / (1.0 - clampY), 0., 1.0); | |
float heightFactor = mix(upScale, bottomScale, heightClamped); | |
float textureOffsetXNorm = (UV.x - 0.5) * 2.; // from texture center better :? | |
float screenOffsetXNorm = ((SCREEN_UV.x - 0.5) * 2.); | |
float screenOffsetXNormParallax = screenOffsetXNorm * heightFactor; | |
float offsetX = screenOffsetXNorm - screenOffsetXNormParallax; | |
offsetX = offsetX * exp(heightFactor * expFactor); | |
vec4 color = texture(TEXTURE, vec2(mod(UV.x + offsetX, 1.0), UV.y)); | |
COLOR = color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment