Scratch whirl effect

Acts just like the whirl effect from Scratch

NOTICE: This shader uses edited code from another source (Under BSD-3-Clause license)
Source: https://github.com/scratchfoundation/scratch-render/blob/develop/src/shaders/sprite.frag

Copyright (c) 2016, Massachusetts Institute of Technology

All rights reserved.

 

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

 

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

 

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

 

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 

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

Scratch mosaic effect

Fnaf / Clickteam perspective (displacement) – Godot 4.2

Scratch color 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