Scratch whirl effect

Acts just like the whirl effect from Scratch

NOTICE: This shader uses edited code from another source (Under GNU AFFERO GENERAL PUBLIC LICENSE)
Source: https://github.com/scratchfoundation/scratch-render/blob/develop/src/shaders/sprite.frag

Shader code
shader_type canvas_item;

uniform float amount = 0.0;

void fragment() {
	float newAmount = -amount/50.0;
	
	vec2 texcoord0 = UV;
	vec2 kCenter = vec2(0.5);
	
	const float kRadius = 0.5;
	vec2 offset = texcoord0 - kCenter;
	float offsetMagnitude = length(offset);
	float whirlFactor = max(1.0 - (offsetMagnitude / kRadius), 0.0);
	float whirlActual = newAmount * whirlFactor * whirlFactor;
	float sinWhirl = sin(whirlActual);
	float cosWhirl = cos(whirlActual);
	mat2 rotationMatrix = mat2(
		vec2(cosWhirl, -sinWhirl),
		vec2(sinWhirl, cosWhirl)
	);

	texcoord0 = rotationMatrix * offset + kCenter;
	
	COLOR = texture(TEXTURE, texcoord0);
}
Tags
Scratch
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from The2AndOnly

Fnaf / Clickteam perspective (displacement) – Godot 4.2

Scratch mosaic effect

Scratch brightness effect

Related shaders

Scratch mosaic effect

Scratch color effect

Scratch fisheye effect

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments